version 1.30, 2004/03/09 03:14:24 |
version 1.47, 2004/07/07 07:40:19 |
|
|
* 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.29 2004/03/09 02:51:36 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.46 2004/03/25 01:56:00 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 75 void Pstring_to_tb(); |
|
Line 75 void Pstring_to_tb(); |
|
void Pquotetotex_tb(); |
void Pquotetotex_tb(); |
void Pquotetotex(); |
void Pquotetotex(); |
void Pquotetotex_env(); |
void Pquotetotex_env(); |
|
void Pflatten_quote(); |
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_rule(char *name); |
char *conv_subscript(char *name); |
char *conv_subs(char *name); |
char *call_convfunc(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 100 struct ftab str_tab[] = { |
|
Line 102 struct ftab str_tab[] = { |
|
{"quotetotex_tb",Pquotetotex_tb,2}, |
{"quotetotex_tb",Pquotetotex_tb,2}, |
{"quotetotex",Pquotetotex,1}, |
{"quotetotex",Pquotetotex,1}, |
{"quotetotex_env",Pquotetotex_env,-99999999}, |
{"quotetotex_env",Pquotetotex_env,-99999999}, |
|
{"flatten_quote",Pflatten_quote,2}, |
{0,0,0}, |
{0,0,0}, |
}; |
}; |
|
|
Line 115 void write_tb(char *s,TB tb) |
|
Line 118 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_origin(Obj arg); |
|
int register_dp_dvars_origin(Obj arg); |
|
int register_dp_dvars_prefix(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); |
int register_show_lt(Obj arg); |
|
char *objtostr(Obj obj); |
static struct TeXSymbol *user_texsymbol; |
static struct TeXSymbol *user_texsymbol; |
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 char *dp_dvars_prefix; |
|
static int dp_vars_origin; |
|
static int dp_dvars_origin; |
static int show_lt; |
static int show_lt; |
static FUNC convfunc; |
static FUNC convfunc; |
static int is_lt; |
static int is_lt; |
static int conv_flag; |
static int conv_flag; |
|
static int dp_vars_hweyl; |
|
|
#define CONV_SUBSCRIPT (1U<<0) |
#define CONV_TABLE (1U<<0) |
#define CONV_DMODE (1U<<1) |
#define CONV_SUBS (1U<<1) |
#define CONV_USERFUNC (1U<<31) |
#define CONV_DMODE (1U<<2) |
|
|
static struct { |
static struct { |
char *name; |
char *name; |
|
|
} 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_dvars_prefix",0,register_dp_dvars_prefix}, |
|
{"dp_vars_origin",0,register_dp_vars_origin}, |
|
{"dp_dvars_origin",0,register_dp_dvars_origin}, |
|
{"dp_vars_hweyl",0,register_dp_vars_hweyl}, |
{"show_lt",0,register_show_lt}, |
{"show_lt",0,register_show_lt}, |
{0,0,0}, |
{0,0,0}, |
}; |
}; |
|
|
char *conv_rule(char *name) |
char *conv_rule(char *name) |
{ |
{ |
char *body,*r; |
char *body,*r; |
|
int len; |
|
|
if ( conv_flag & CONV_DMODE ) { |
if ( convfunc ) |
if ( *name == 'd' ) { |
name = call_convfunc(name); |
if ( conv_flag & CONV_SUBSCRIPT ) |
if ( conv_flag & CONV_TABLE ) { |
body = conv_subscript(name+1); |
r = symbol_name(name); |
else |
if ( r ) return r; |
body = name+1; |
} |
r = MALLOC_ATOMIC((strlen(PARTIAL)+strlen(body)+5)*sizeof(char)); |
if ( (conv_flag & CONV_DMODE) && *name == 'd' ) { |
sprintf(r,"{%s}_{%s}",PARTIAL,body); |
body = conv_rule(name+1); |
return r; |
r = MALLOC_ATOMIC((strlen(PARTIAL)+strlen(body)+5)*sizeof(char)); |
} else { |
if ( !body || !(len=strlen(body)) ) |
if ( conv_flag & CONV_SUBSCRIPT ) |
strcpy(r,PARTIAL); |
body = conv_subscript(name); |
else if ( len == 1 ) |
else |
sprintf(r,"%s_%s",PARTIAL,body); |
body = name; |
else |
} |
sprintf(r,"%s_{%s}",PARTIAL,body); |
} else if ( conv_flag & CONV_SUBSCRIPT ) |
return r; |
return conv_subscript(name); |
} else |
else if ( conv_flag & CONV_USERFUNC && convfunc ) |
return conv_subs(name); |
return call_convfunc(name); |
|
else |
|
return name; |
|
} |
} |
|
|
char *conv_subscript(char *name) |
int _is_delimiter(char c) |
{ |
{ |
|
if ( (c == ' ' || c == '_' || c == ',') ) return 1; |
|
else return 0; |
|
} |
|
|
|
int _is_alpha(char c) |
|
{ |
|
if ( isdigit(c) || c == '{' || _is_delimiter(c) ) return 0; |
|
else return 1; |
|
} |
|
|
|
char *conv_subs(char *name) |
|
{ |
int i,j,k,len,clen,slen,start,level; |
int i,j,k,len,clen,slen,start,level; |
char *buf,*head,*r,*h; |
char *buf,*head,*r,*h,*brace,*buf_conv; |
char **subs; |
char **subs; |
|
|
len = strlen(name); |
if ( !name || !(len=strlen(name)) ) return ""; |
for ( i = 0; i < len && (isalpha(name[i]) || name[i]=='\\'); i++ ); |
if ( !(conv_flag&CONV_SUBS) ) return name; |
if ( i == len ) return symbol_name(name); |
|
buf = (char *)ALLOCA((i+1)*sizeof(char)); |
|
strncpy(buf,name,i); buf[i] = 0; |
|
head = symbol_name(buf); |
|
subs = (char **)ALLOCA(len*sizeof(char* )); |
subs = (char **)ALLOCA(len*sizeof(char* )); |
for ( j = 0, start = i; ; j++ ) { |
for ( i = 0, j = 0, start = i; ; j++ ) { |
while ( (i < len) && (name[i] == '_' || name[i] == ',') ) i++; |
while ( (i < len) && _is_delimiter(name[i]) ) i++; |
if ( i == len ) break; |
|
start = i; |
start = i; |
|
if ( i == len ) break; |
if ( name[i] == '{' ) { |
if ( name[i] == '{' ) { |
for ( level = 1, i++; i < len && level; i++ ) { |
for ( level = 1, i++; i < len && level; i++ ) { |
if ( name[i] == '{' ) level++; |
if ( name[i] == '{' ) level++; |
else if ( name[i] == '}' ) level--; |
else if ( name[i] == '}' ) level--; |
} |
} |
} else if ( isdigit(name[i]) ) |
slen = i-start; |
while ( i < len && isdigit(name[i]) ) i++; |
if ( slen >= 3 ) { |
else |
brace = (char *)ALLOCA((slen+1)*sizeof(char)); |
while ( i < len && (isalpha(name[i]) || name[i] == '\\') ) i++; |
strncpy(brace,name+start+1,slen-2); |
slen = i-start; |
brace[slen-2] = 0; |
buf = (char *)ALLOCA((slen+1)*sizeof(char)); |
buf = conv_subs(brace); |
strncpy(buf,name+start,slen); buf[slen] = 0; |
subs[j] = (char *)ALLOCA((strlen(buf)+3)*sizeof(char)); |
subs[j] = symbol_name(buf); |
if ( strlen(buf) == 1 ) |
|
strcpy(subs[j],buf); |
|
else |
|
sprintf(subs[j],"{%s}",buf); |
|
} else |
|
subs[j] = "{}"; |
|
} else { |
|
if ( isdigit(name[i]) ) |
|
while ( i < len && isdigit(name[i]) ) i++; |
|
else |
|
while ( i < len && _is_alpha(name[i]) ) i++; |
|
slen = i-start; |
|
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; |
|
} |
} |
} |
for ( k = 0, clen = strlen(head); k < j; k++ ) clen += strlen(subs[k]); |
for ( k = 0, clen = 0; k < j; k++ ) clen += strlen(subs[k]); |
/* {head}_{{subs(0)},...,{subs(j-1)}} => {}:j+2 _:1 ,:j-1 */ |
/* {subs(0)}_{{subs(1)},...,{subs(j-1)}} => {}:j+1 _:1 ,:j-2 */ |
h = r = MALLOC_ATOMIC((clen+(j+2)*2+1+(j-1)+1)*sizeof(char)); |
h = r = MALLOC_ATOMIC((clen+(j+1)*2+1+(j-2)+1)*sizeof(char)); |
if ( !j ) |
if ( j == 1 ) |
sprintf(h,"{%s}",head); |
sprintf(h,"{%s}",subs[0]); |
else { |
else { |
sprintf(h,"{%s}_{{%s}",head,subs[0]); |
sprintf(h,"{%s}_{%s",subs[0],subs[1]); |
h += strlen(h); |
h += strlen(h); |
for ( k = 1; k < j; k++ ) { |
for ( k = 2; k < j; k++ ) { |
sprintf(h,",{%s}",subs[k]); |
sprintf(h,",%s",subs[k]); |
h += strlen(h); |
h += strlen(h); |
} |
} |
strcpy(h,"}"); |
strcpy(h,"}"); |
Line 280 int register_symbol_table(Obj arg) |
|
Line 320 int register_symbol_table(Obj arg) |
|
return 1; |
return 1; |
} |
} |
|
|
|
int register_dp_vars_origin(Obj arg) |
|
{ |
|
if ( INT(arg) ) { |
|
dp_vars_origin = QTOS((Q)arg); |
|
return 1; |
|
} else return 0; |
|
} |
|
|
|
int register_dp_dvars_origin(Obj arg) |
|
{ |
|
if ( INT(arg) ) { |
|
dp_dvars_origin = QTOS((Q)arg); |
|
return 1; |
|
} else return 0; |
|
} |
|
|
|
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) |
int register_show_lt(Obj arg) |
{ |
{ |
if ( INT(arg) ) { |
if ( INT(arg) ) { |
Line 294 int register_conv_rule(Obj arg) |
|
Line 358 int register_conv_rule(Obj arg) |
|
conv_flag = QTOS((Q)arg); |
conv_flag = QTOS((Q)arg); |
convfunc = 0; |
convfunc = 0; |
return 1; |
return 1; |
} else if ( OID(arg) == O_P && |
} else return 0; |
(int)(VR((P)arg))->attr == V_SR ) { |
} |
conv_flag = CONV_USERFUNC; |
|
|
int register_conv_func(Obj arg) |
|
{ |
|
if ( !arg ) { |
|
convfunc = 0; |
|
return 1; |
|
} 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 */ |
return 1; |
return 1; |
Line 350 int register_dp_vars_prefix(Obj arg) |
|
Line 420 int register_dp_vars_prefix(Obj arg) |
|
} else return 0; |
} else return 0; |
} |
} |
|
|
|
int register_dp_dvars_prefix(Obj arg) |
|
{ |
|
if ( !arg ) { |
|
dp_dvars_prefix = 0; |
|
return 1; |
|
} else if ( OID(arg) == O_STR ) { |
|
dp_dvars_prefix = BDY((STRING)arg); |
|
return 1; |
|
} else if ( OID(arg) == O_P ) { |
|
dp_dvars_prefix = NAME(VR((P)arg)); |
|
return 1; |
|
} else return 0; |
|
} |
|
|
void Pquotetotex_env(NODE arg,Obj *rp) |
void Pquotetotex_env(NODE arg,Obj *rp) |
{ |
{ |
int ac,i; |
int ac,i; |
Line 368 void Pquotetotex_env(NODE arg,Obj *rp) |
|
Line 452 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].reg)(0); |
|
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 733 char *symbol_name(char *name) |
|
Line 824 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 740 char *symbol_name(char *name) |
|
Line 836 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; |
return name; |
return 0; |
} |
} |
|
|
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,si; |
|
C cplx; |
|
char *r; |
FNODE fi,f2; |
FNODE fi,f2; |
|
|
write_tb(" ",tb); |
write_tb(" ",tb); |
Line 782 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 880 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 837 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 935 void fnodetotex_tb(FNODE f,TB tb) |
|
break; |
break; |
case C_GT: |
case C_GT: |
fnodetotex_tb((FNODE)FA1(f),tb); |
fnodetotex_tb((FNODE)FA1(f),tb); |
write_tb(" \\gt ",tb); |
write_tb(" > ",tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
break; |
break; |
case C_LT: |
case C_LT: |
fnodetotex_tb((FNODE)FA1(f),tb); |
fnodetotex_tb((FNODE)FA1(f),tb); |
write_tb(" \\lt ",tb); |
write_tb(" < ",tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
break; |
break; |
case C_GE: |
case C_GE: |
Line 872 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 970 void fnodetotex_tb(FNODE f,TB tb) |
|
break; |
break; |
case L_GT: |
case L_GT: |
fnodetotex_tb((FNODE)FA1(f),tb); |
fnodetotex_tb((FNODE)FA1(f),tb); |
write_tb(" \\gt ",tb); |
write_tb(" > ",tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
break; |
break; |
case L_LT: |
case L_LT: |
fnodetotex_tb((FNODE)FA1(f),tb); |
fnodetotex_tb((FNODE)FA1(f),tb); |
write_tb(" \\lt ",tb); |
write_tb(" < ",tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
fnodetotex_tb((FNODE)FA2(f),tb); |
break; |
break; |
case L_GE: |
case L_GE: |
Line 936 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1034 void fnodetotex_tb(FNODE f,TB tb) |
|
|
|
/* function */ |
/* function */ |
case I_FUNC: |
case I_FUNC: |
opname = conv_rule(((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 */ |
Line 963 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1067 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 ) |
if ( show_lt && is_lt ) |
write_tb("\\underline{",tb); |
write_tb("\\underline{",tb); |
Line 970 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1079 void fnodetotex_tb(FNODE f,TB tb) |
|
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 = conv_rule(vname); |
strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x"); |
|
prefix_conv = conv_rule(prefix); |
|
vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50); |
|
si = i+dp_vars_origin; |
|
sprintf(vname_conv,(si>=0&&si<10)?"%s_%d":"%s_{%d}", |
|
prefix_conv,si); |
|
} else if ( i < elen ) { |
|
strcpy(prefix, |
|
dp_dvars_prefix?dp_dvars_prefix:"\\partial"); |
|
prefix_conv = conv_rule(prefix); |
|
vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50); |
|
si = i+dp_dvars_origin-elen2; |
|
sprintf(vname_conv,(si>=0&&si<10)?"%s_%d":"%s_{%d}", |
|
prefix_conv,si); |
|
} else { |
|
strcpy(prefix,"h"); |
|
vname_conv = conv_rule(prefix); |
|
} |
|
} else { |
|
strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x"); |
|
prefix_conv = conv_rule(prefix); |
|
vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50); |
|
si = i+dp_vars_origin; |
|
sprintf(vname_conv,(si>=0&&si<10)?"%s_%d":"%s_{%d}", |
|
prefix_conv,si); |
|
} |
|
} |
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 1009 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1144 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 = conv_rule(VR((P)obj)->name); |
write_tb("0",tb); |
} 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 1033 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1185 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) ) { |
Line 1057 void fargstotex_tb(char *name,FNODE f,TB tb) |
|
Line 1221 void fargstotex_tb(char *name,FNODE f,TB 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; |
|
} |
|
} |
|
|
|
FNODE flatten_fnode(FNODE,char *); |
|
|
|
void Pflatten_quote(NODE arg,QUOTE *rp) |
|
{ |
|
FNODE f; |
|
QUOTE q; |
|
|
|
f = flatten_fnode(BDY((QUOTE)ARG0(arg)),BDY((STRING)ARG1(arg))); |
|
MKQUOTE(q,f); |
|
*rp = q; |
} |
} |