version 1.26, 2004/03/05 01:47:19 |
version 1.41, 2004/03/12 02:06:48 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.25 2004/03/05 01:34:24 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.40 2004/03/11 07:40:41 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 77 void Pquotetotex(); |
|
Line 77 void Pquotetotex(); |
|
void Pquotetotex_env(); |
void Pquotetotex_env(); |
void fnodetotex_tb(FNODE f,TB tb); |
void fnodetotex_tb(FNODE f,TB tb); |
char *symbol_name(char *name); |
char *symbol_name(char *name); |
|
char *conv_rule(char *name); |
|
char *conv_subs(char *name); |
|
char *call_convfunc(char *name); |
void tb_to_string(TB tb,STRING *rp); |
void tb_to_string(TB tb,STRING *rp); |
void fnodenodetotex_tb(NODE n,TB tb); |
void fnodenodetotex_tb(NODE n,TB tb); |
void fargstotex_tb(char *opname,FNODE f,TB tb); |
void fargstotex_tb(char *opname,FNODE f,TB tb); |
|
int top_is_minus(FNODE f); |
|
|
struct ftab str_tab[] = { |
struct ftab str_tab[] = { |
{"rtostr",Prtostr,1}, |
{"rtostr",Prtostr,1}, |
Line 112 void write_tb(char *s,TB tb) |
|
Line 116 void write_tb(char *s,TB tb) |
|
|
|
int register_symbol_table(Obj arg); |
int register_symbol_table(Obj arg); |
int register_conv_rule(Obj arg); |
int register_conv_rule(Obj arg); |
|
int register_conv_func(Obj arg); |
int register_dp_vars(Obj arg); |
int register_dp_vars(Obj arg); |
int register_dp_vars_prefix(Obj arg); |
int register_dp_vars_prefix(Obj arg); |
|
int register_dp_vars_hweyl(Obj arg); |
|
int register_show_lt(Obj arg); |
|
char *objtostr(Obj obj); |
static struct TeXSymbol *user_texsymbol; |
static struct TeXSymbol *user_texsymbol; |
static char *(*conv_rule)(char *); |
|
static char **dp_vars; |
static char **dp_vars; |
static int dp_vars_len; |
static int dp_vars_len; |
static char *dp_vars_prefix; |
static char *dp_vars_prefix; |
|
static int show_lt; |
static FUNC convfunc; |
static FUNC convfunc; |
|
static int is_lt; |
|
static int conv_flag; |
|
static int dp_vars_hweyl; |
|
|
|
#define CONV_TABLE (1U<<0) |
|
#define CONV_SUBS (1U<<1) |
|
#define CONV_DMODE (1U<<2) |
|
|
static struct { |
static struct { |
char *name; |
char *name; |
Obj value; |
Obj value; |
|
|
} qtot_env[] = { |
} qtot_env[] = { |
{"symbol_table",0,register_symbol_table}, |
{"symbol_table",0,register_symbol_table}, |
{"conv_rule",0,register_conv_rule}, |
{"conv_rule",0,register_conv_rule}, |
|
{"conv_func",0,register_conv_func}, |
{"dp_vars",0,register_dp_vars}, |
{"dp_vars",0,register_dp_vars}, |
{"dp_vars_prefix",0,register_dp_vars_prefix}, |
{"dp_vars_prefix",0,register_dp_vars_prefix}, |
|
{"dp_vars_hweyl",0,register_dp_vars_hweyl}, |
|
{"show_lt",0,register_show_lt}, |
{0,0,0}, |
{0,0,0}, |
}; |
}; |
|
|
#define PARTIAL "\\partial" |
#define PARTIAL "\\partial" |
char *conv_rule_d(char *name) |
|
|
char *conv_rule(char *name) |
{ |
{ |
int l,i,j,alpha,start; |
char *body,*r; |
char *b,*r; |
int len; |
l = strlen(name); |
|
|
|
if ( name[0] == 'd' ) { |
if ( convfunc ) |
/* 3 : _{} */ |
name = call_convfunc(name); |
b = (char *)ALLOCA((2*l+1+strlen(PARTIAL)+3)*sizeof(char)); |
if ( conv_flag & CONV_TABLE ) { |
sprintf(b,"%s_{",PARTIAL); |
r = symbol_name(name); |
i = 1; |
if ( r ) return r; |
j = strlen(b); |
|
} else { |
|
b = (char *)ALLOCA((2*l+1)*sizeof(char)); |
|
i = j = 0; |
|
} |
} |
for ( ; i < l && name[i] == '_'; i++); |
if ( (conv_flag & CONV_DMODE) && *name == 'd' ) { |
for ( ; i < l; ) { |
body = conv_rule(name+1); |
if ( !isalpha(name[i]) ) |
r = MALLOC_ATOMIC((strlen(PARTIAL)+strlen(body)+5)*sizeof(char)); |
break; |
if ( !body || !(len=strlen(body)) ) |
|
strcpy(r,PARTIAL); |
|
else if ( len == 1 ) |
|
sprintf(r,"%s_%s",PARTIAL,body); |
else |
else |
b[j++] = name[i++]; |
sprintf(r,"%s_{%s}",PARTIAL,body); |
} |
return r; |
if ( i == l ) |
} else |
if ( name[0] == 'd' ) |
return conv_subs(name); |
goto END; |
} |
else |
|
return name; |
int _is_delimiter(char c) |
/* we found a digit or '_' */ |
{ |
b[j++] = '_'; b[j++] = '{'; |
if ( (c == ' ' || c == '_' || c == ',') ) return 1; |
if ( name[i] == '_' ) i++; |
else return 0; |
for ( start = 1; i < l; ) { |
} |
if ( name[i] == '{' || name[i] == '}' || name[i] == ' ' ) |
|
b[j++] = name[i++]; |
int _is_alpha(char c) |
else if ( name[i] == '_' ) { |
{ |
i++; |
if ( isdigit(c) || c == '{' || _is_delimiter(c) ) return 0; |
start = 1; |
else return 1; |
b[j++] = ','; |
} |
} else if ( start ) { |
|
alpha = isalpha(name[i])?1:0; |
char *conv_subs(char *name) |
b[j++] = name[i++]; |
{ |
start = 0; |
int i,j,k,len,clen,slen,start,level; |
} else if ( alpha ) { |
char *buf,*head,*r,*h,*brace,*buf_conv; |
if ( isalpha(name[i]) ) |
char **subs; |
b[j++] = name[i++]; |
|
else { |
if ( !name || !(len=strlen(name)) ) return ""; |
alpha = 0; |
if ( !(conv_flag&CONV_SUBS) ) return name; |
start = 1; |
subs = (char **)ALLOCA(len*sizeof(char* )); |
b[j++] = ','; |
for ( i = 0, j = 0, start = i; ; j++ ) { |
|
while ( (i < len) && _is_delimiter(name[i]) ) i++; |
|
start = i; |
|
if ( i == len ) break; |
|
if ( name[i] == '{' ) { |
|
for ( level = 1, i++; i < len && level; i++ ) { |
|
if ( name[i] == '{' ) level++; |
|
else if ( name[i] == '}' ) level--; |
} |
} |
|
slen = i-start; |
|
if ( slen >= 3 ) { |
|
brace = (char *)ALLOCA((slen+1)*sizeof(char)); |
|
strncpy(brace,name+start+1,slen-2); |
|
brace[slen-2] = 0; |
|
buf = conv_subs(brace); |
|
subs[j] = (char *)ALLOCA((strlen(buf)+3)*sizeof(char)); |
|
if ( strlen(buf) == 1 ) |
|
strcpy(subs[j],buf); |
|
else |
|
sprintf(subs[j],"{%s}",buf); |
|
} else |
|
subs[j] = "{}"; |
} else { |
} else { |
if ( isdigit(name[i]) ) |
if ( isdigit(name[i]) ) |
b[j++] = name[i++]; |
while ( i < len && isdigit(name[i]) ) i++; |
else { |
else |
alpha = 1; |
while ( i < len && _is_alpha(name[i]) ) i++; |
start = 1; |
slen = i-start; |
b[j++] = ','; |
buf = (char *)ALLOCA((slen+1)*sizeof(char)); |
} |
strncpy(buf,name+start,slen); buf[slen] = 0; |
|
buf_conv = symbol_name(buf); |
|
subs[j] = buf_conv?buf_conv:buf; |
} |
} |
} |
} |
b[j++] = '}'; |
for ( k = 0, clen = 0; k < j; k++ ) clen += strlen(subs[k]); |
END: |
/* {subs(0)}_{{subs(1)},...,{subs(j-1)}} => {}:j+1 _:1 ,:j-2 */ |
if ( name[0] == 'd' ) b[j++] = '}'; |
h = r = MALLOC_ATOMIC((clen+(j+1)*2+1+(j-2)+1)*sizeof(char)); |
b[j++] = 0; |
if ( j == 1 ) |
r = (char *)MALLOC_ATOMIC((j+1)*sizeof(char)); |
sprintf(h,"{%s}",subs[0]); |
strcpy(r,b); |
else { |
|
sprintf(h,"{%s}_{%s",subs[0],subs[1]); |
|
h += strlen(h); |
|
for ( k = 2; k < j; k++ ) { |
|
sprintf(h,",%s",subs[k]); |
|
h += strlen(h); |
|
} |
|
strcpy(h,"}"); |
|
} |
return r; |
return r; |
} |
} |
|
|
Line 262 int register_symbol_table(Obj arg) |
|
Line 309 int register_symbol_table(Obj arg) |
|
return 1; |
return 1; |
} |
} |
|
|
|
int register_dp_vars_hweyl(Obj arg) |
|
{ |
|
if ( INT(arg) ) { |
|
dp_vars_hweyl = QTOS((Q)arg); |
|
return 1; |
|
} else return 0; |
|
} |
|
|
|
int register_show_lt(Obj arg) |
|
{ |
|
if ( INT(arg) ) { |
|
show_lt = QTOS((Q)arg); |
|
return 1; |
|
} else return 0; |
|
} |
|
|
int register_conv_rule(Obj arg) |
int register_conv_rule(Obj arg) |
{ |
{ |
if ( INT(arg) ) { |
if ( INT(arg) ) { |
switch ( QTOS((Q)arg) ) { |
conv_flag = QTOS((Q)arg); |
case 0: |
convfunc = 0; |
conv_rule = 0; |
return 1; |
return 1; |
} else return 0; |
break; |
} |
case 1: |
|
conv_rule = conv_rule_d; |
int register_conv_func(Obj arg) |
return 1; |
{ |
break; |
if ( OID(arg) == O_P && (int)(VR((P)arg))->attr == V_SR ) { |
default: |
|
return 0; |
|
break; |
|
} |
|
} else if ( OID(arg) == O_P && |
|
(int)(VR((P)arg))->attr == V_SR ) { |
|
convfunc = (FUNC)(VR((P)arg)->priv); |
convfunc = (FUNC)(VR((P)arg)->priv); |
/* f must be a function which takes single argument */ |
/* f must be a function which takes single argument */ |
conv_rule = call_convfunc; |
|
return 1; |
return 1; |
} else return 0; |
} else return 0; |
} |
} |
Line 353 void Pquotetotex_env(NODE arg,Obj *rp) |
|
Line 408 void Pquotetotex_env(NODE arg,Obj *rp) |
|
NEXT(n) = 0; |
NEXT(n) = 0; |
MKLIST(l,n0); |
MKLIST(l,n0); |
*rp = (Obj)l; |
*rp = (Obj)l; |
|
} else if ( ac == 1 && !ARG0(arg) ) { |
|
/* set to default */ |
|
for ( i = 0; qtot_env[i].name; i++ ) |
|
qtot_env[i].value = 0; |
|
*rp = 0; |
} else if ( ac == 1 || ac == 2 ) { |
} else if ( ac == 1 || ac == 2 ) { |
asir_assert(ARG0(arg),O_STR,"quotetotex_env"); |
asir_assert(ARG0(arg),O_STR,"quotetotex_env"); |
name = BDY((STRING)ARG0(arg)); |
name = BDY((STRING)ARG0(arg)); |
Line 397 void Pquotetotex(NODE arg,STRING *rp) |
|
Line 457 void Pquotetotex(NODE arg,STRING *rp) |
|
TB tb; |
TB tb; |
|
|
NEWTB(tb); |
NEWTB(tb); |
|
/* XXX for DP */ |
|
is_lt = 1; |
fnodetotex_tb(BDY((QUOTE)ARG0(arg)),tb); |
fnodetotex_tb(BDY((QUOTE)ARG0(arg)),tb); |
tb_to_string(tb,rp); |
tb_to_string(tb,rp); |
} |
} |
Line 407 void Pquotetotex_tb(NODE arg,Q *rp) |
|
Line 469 void Pquotetotex_tb(NODE arg,Q *rp) |
|
TB tb; |
TB tb; |
|
|
asir_assert(ARG1(arg),O_TB,"quotetotex_tb"); |
asir_assert(ARG1(arg),O_TB,"quotetotex_tb"); |
|
/* XXX for DP */ |
|
is_lt = 1; |
fnodetotex_tb(BDY((QUOTE)ARG0(arg)),ARG1(arg)); |
fnodetotex_tb(BDY((QUOTE)ARG0(arg)),ARG1(arg)); |
*rp = 0; |
*rp = 0; |
} |
} |
Line 714 char *symbol_name(char *name) |
|
Line 778 char *symbol_name(char *name) |
|
{ |
{ |
int i; |
int i; |
|
|
|
if ( !name || strlen(name) == 0 ) |
|
return ""; |
|
if ( !(conv_flag & CONV_TABLE) ) |
|
return name; |
|
|
if ( user_texsymbol ) |
if ( user_texsymbol ) |
for ( i = 0; user_texsymbol[i].text; i++ ) |
for ( i = 0; user_texsymbol[i].text; i++ ) |
if ( !strcmp(user_texsymbol[i].text,name) ) |
if ( !strcmp(user_texsymbol[i].text,name) ) |
Line 721 char *symbol_name(char *name) |
|
Line 790 char *symbol_name(char *name) |
|
for ( i = 0; texsymbol[i].text; i++ ) |
for ( i = 0; texsymbol[i].text; i++ ) |
if ( !strcmp(texsymbol[i].text,name) ) |
if ( !strcmp(texsymbol[i].text,name) ) |
return texsymbol[i].symbol; |
return texsymbol[i].symbol; |
if ( conv_rule ) |
return 0; |
return (*conv_rule)(name); |
|
else |
|
return name; |
|
} |
} |
|
|
void fnodetotex_tb(FNODE f,TB tb) |
void fnodetotex_tb(FNODE f,TB tb) |
{ |
{ |
NODE n,t,t0; |
NODE n,t,t0; |
char vname[BUFSIZ]; |
char vname[BUFSIZ],prefix[BUFSIZ]; |
char *opname,*vname_conv; |
char *opname,*vname_conv,*prefix_conv; |
Obj obj; |
Obj obj; |
int i,len,allzero; |
int i,len,allzero,elen,elen2; |
|
C cplx; |
|
char *r; |
FNODE fi,f2; |
FNODE fi,f2; |
|
|
write_tb(" ",tb); |
write_tb(" ",tb); |
Line 766 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 834 void fnodetotex_tb(FNODE f,TB tb) |
|
opname = ((ARF)FA0(f))->name; |
opname = ((ARF)FA0(f))->name; |
if ( !strcmp(opname,"+") ) { |
if ( !strcmp(opname,"+") ) { |
fnodetotex_tb((FNODE)FA1(f),tb); |
fnodetotex_tb((FNODE)FA1(f),tb); |
write_tb(opname,tb); |
if ( !top_is_minus((FNODE)FA2(f)) ) write_tb(opname,tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
} else if ( !strcmp(opname,"-") ) { |
} else if ( !strcmp(opname,"-") ) { |
if ( FA1(f) ) fnodetotex_tb((FNODE)FA1(f),tb); |
if ( FA1(f) ) fnodetotex_tb((FNODE)FA1(f),tb); |
Line 920 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 988 void fnodetotex_tb(FNODE f,TB tb) |
|
|
|
/* function */ |
/* function */ |
case I_FUNC: |
case I_FUNC: |
opname = symbol_name(((FUNC)FA0(f))->name); |
if ( !strcmp(((FUNC)FA0(f))->name,"@pi") ) |
write_tb(opname,tb); |
write_tb("\\pi",tb); |
write_tb("(",tb); |
else if ( !strcmp(((FUNC)FA0(f))->name,"@e") ) |
fargstotex_tb(opname,FA1(f),tb); |
write_tb("e",tb); |
write_tb(")",tb); |
else { |
|
opname = conv_rule(((FUNC)FA0(f))->name); |
|
write_tb(opname,tb); |
|
write_tb("(",tb); |
|
fargstotex_tb(opname,FA1(f),tb); |
|
write_tb(")",tb); |
|
} |
break; |
break; |
|
|
/* XXX */ |
/* XXX */ |
case I_CAR: |
case I_CAR: |
opname = symbol_name("car"); |
opname = conv_rule("car"); |
write_tb(opname,tb); |
write_tb(opname,tb); |
write_tb("(",tb); |
write_tb("(",tb); |
fargstotex_tb(opname,FA0(f),tb); |
fargstotex_tb(opname,FA0(f),tb); |
Line 937 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1011 void fnodetotex_tb(FNODE f,TB tb) |
|
break; |
break; |
|
|
case I_CDR: |
case I_CDR: |
opname = symbol_name("cdr"); |
opname = conv_rule("cdr"); |
write_tb(opname,tb); |
write_tb(opname,tb); |
write_tb("(",tb); |
write_tb("(",tb); |
fargstotex_tb(opname,FA0(f),tb); |
fargstotex_tb(opname,FA0(f),tb); |
Line 947 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1021 void fnodetotex_tb(FNODE f,TB tb) |
|
/* exponent vector */ |
/* exponent vector */ |
case I_EV: |
case I_EV: |
n = (NODE)FA0(f); |
n = (NODE)FA0(f); |
|
if ( dp_vars_hweyl ) { |
|
elen = length(n); |
|
elen2 = elen>>1; |
|
elen = elen2<<1; |
|
} |
allzero = 1; |
allzero = 1; |
|
if ( show_lt && is_lt ) |
|
write_tb("\\underline{",tb); |
for ( t0 = 0, i = 0; n; n = NEXT(n), i++ ) { |
for ( t0 = 0, i = 0; n; n = NEXT(n), i++ ) { |
fi = (FNODE)BDY(n); |
fi = (FNODE)BDY(n); |
if ( fi->id == I_FORMULA && !FA0(fi) ) continue; |
if ( fi->id == I_FORMULA && !FA0(fi) ) continue; |
allzero = 0; |
allzero = 0; |
if ( dp_vars && i < dp_vars_len ) |
if ( dp_vars && i < dp_vars_len ) { |
strcpy(vname,dp_vars[i]); |
strcpy(vname,dp_vars[i]); |
else if ( dp_vars_prefix ) |
vname_conv = conv_rule(vname); |
sprintf(vname,"%s_{%d}",dp_vars_prefix,i); |
} else { |
else |
if ( dp_vars_hweyl ) { |
sprintf(vname,"x_{%d}",i); |
if ( i < elen2 ) |
vname_conv = symbol_name(vname); |
strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x"); |
|
else if ( i < elen ) |
|
strcpy(prefix,"\\partial"); |
|
else |
|
strcpy(prefix,"h"); |
|
} else |
|
strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x"); |
|
prefix_conv = conv_rule(prefix); |
|
vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50); |
|
if ( i < 10 ) |
|
sprintf(vname_conv,"%s_%d",prefix_conv,i); |
|
else |
|
sprintf(vname_conv,"%s_{%d}",prefix_conv,i); |
|
} |
if ( fi->id == I_FORMULA && UNIQ(FA0(fi)) ) { |
if ( fi->id == I_FORMULA && UNIQ(FA0(fi)) ) { |
len = strlen(vname_conv); |
len = strlen(vname_conv); |
opname = MALLOC_ATOMIC(len+2); |
opname = MALLOC_ATOMIC(len+2); |
Line 977 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1071 void fnodetotex_tb(FNODE f,TB tb) |
|
/* XXX */ |
/* XXX */ |
if ( allzero ) |
if ( allzero ) |
write_tb(" 1 ",tb); |
write_tb(" 1 ",tb); |
|
if ( show_lt && is_lt ) { |
|
write_tb("}",tb); |
|
is_lt = 0; |
|
} |
break; |
break; |
|
|
/* string */ |
/* string */ |
Line 987 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1085 void fnodetotex_tb(FNODE f,TB tb) |
|
/* internal object */ |
/* internal object */ |
case I_FORMULA: |
case I_FORMULA: |
obj = (Obj)FA0(f); |
obj = (Obj)FA0(f); |
if ( obj && OID(obj) == O_P ) { |
if ( !obj ) |
opname = symbol_name(VR((P)obj)->name); |
opname = "0"; |
} else { |
else if ( OID(obj) == O_N && NID(obj) == N_C ) { |
len = estimate_length(CO,obj); |
cplx = (C)obj; |
opname = (char *)MALLOC_ATOMIC(len+1); |
write_tb("(",tb); |
soutput_init(opname); |
if ( cplx->r ) { |
sprintexpr(CO,obj); |
r = objtostr((Obj)cplx->r); write_tb(r,tb); |
} |
} |
write_tb(opname,tb); |
if ( cplx->i ) { |
|
if ( cplx->r && compnum(0,cplx->i,0) > 0 ) { |
|
write_tb("+",tb); |
|
if ( !UNIQ(cplx->i) ) { |
|
r = objtostr((Obj)cplx->i); write_tb(r,tb); |
|
} |
|
} else if ( MUNIQ(cplx->i) ) |
|
write_tb("-",tb); |
|
else if ( !UNIQ(cplx->i) ) { |
|
r = objtostr((Obj)cplx->i); write_tb(r,tb); |
|
} |
|
write_tb("\\sqrt{-1}",tb); |
|
} |
|
write_tb(")",tb); |
|
} else if ( OID(obj) == O_P ) |
|
write_tb(conv_rule(VR((P)obj)->name),tb); |
|
else |
|
write_tb(objtostr(obj),tb); |
break; |
break; |
|
|
/* program variable */ |
/* program variable */ |
Line 1011 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1126 void fnodetotex_tb(FNODE f,TB tb) |
|
} |
} |
} |
} |
|
|
|
char *objtostr(Obj obj) |
|
{ |
|
int len; |
|
char *r; |
|
|
|
len = estimate_length(CO,obj); |
|
r = (char *)MALLOC_ATOMIC(len+1); |
|
soutput_init(r); |
|
sprintexpr(CO,obj); |
|
return r; |
|
} |
|
|
void fnodenodetotex_tb(NODE n,TB tb) |
void fnodenodetotex_tb(NODE n,TB tb) |
{ |
{ |
for ( ; n; n = NEXT(n) ) { |
for ( ; n; n = NEXT(n) ) { |
|
is_lt = 1; |
fnodetotex_tb((FNODE)BDY(n),tb); |
fnodetotex_tb((FNODE)BDY(n),tb); |
if ( NEXT(n) ) write_tb(", ",tb); |
if ( NEXT(n) ) write_tb(", ",tb); |
} |
} |
Line 1033 void fargstotex_tb(char *name,FNODE f,TB tb) |
|
Line 1161 void fargstotex_tb(char *name,FNODE f,TB tb) |
|
fnodenodetotex_tb(n,tb); |
fnodenodetotex_tb(n,tb); |
} else |
} else |
fnodetotex_tb(f,tb); |
fnodetotex_tb(f,tb); |
|
} |
|
} |
|
|
|
int top_is_minus(FNODE f) |
|
{ |
|
char *opname; |
|
int len; |
|
Obj obj; |
|
|
|
if ( !f ) |
|
return 0; |
|
switch ( f->id ) { |
|
case I_MINUS: |
|
return 1; |
|
case I_BOP: |
|
opname = ((ARF)FA0(f))->name; |
|
switch ( opname[0] ) { |
|
case '+': case '*': case '/': case '^': case '%': |
|
return top_is_minus((FNODE)FA1(f)); |
|
case '-': |
|
if ( FA1(f) ) |
|
return top_is_minus((FNODE)FA1(f)); |
|
else |
|
return 1; |
|
default: |
|
return 0; |
|
} |
|
break; |
|
case I_COP: |
|
return top_is_minus((FNODE)FA1(f)); |
|
case I_LOP: |
|
if ( (lid)FA0(f) == L_NOT ) return 0; |
|
else return top_is_minus((FNODE)FA1(f)); |
|
case I_AND: case I_OR: |
|
return top_is_minus((FNODE)FA0(f)); |
|
case I_FORMULA: |
|
obj = (Obj)FA0(f); |
|
if ( !obj ) |
|
return 0; |
|
else { |
|
switch ( OID(obj) ) { |
|
case O_N: |
|
return mmono((P)obj); |
|
case O_P: |
|
/* must be a variable */ |
|
opname = conv_rule(VR((P)obj)->name); |
|
return opname[0]=='-'; |
|
default: |
|
/* ??? */ |
|
len = estimate_length(CO,obj); |
|
opname = (char *)MALLOC_ATOMIC(len+1); |
|
soutput_init(opname); |
|
sprintexpr(CO,obj); |
|
return opname[0]=='-'; |
|
} |
|
} |
|
default: |
|
return 0; |
} |
} |
} |
} |