version 1.24, 2004/03/05 01:19:09 |
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.23 2004/03/05 01:15:48 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_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 97 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 112 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_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; |
int dp_vars_len; |
static int dp_vars_len; |
|
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 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_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}, |
{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] == '_' ) { |
|
i++; |
int _is_alpha(char c) |
start = 1; |
{ |
b[j++] = ','; |
if ( isdigit(c) || c == '{' || _is_delimiter(c) ) return 0; |
} else if ( start ) { |
else return 1; |
alpha = isalpha(name[i])?1:0; |
} |
b[j++] = name[i++]; |
|
start = 0; |
char *conv_subs(char *name) |
} else if ( alpha ) { |
{ |
if ( isalpha(name[i]) ) |
int i,j,k,len,clen,slen,start,level; |
b[j++] = name[i++]; |
char *buf,*head,*r,*h,*brace,*buf_conv; |
else { |
char **subs; |
alpha = 0; |
|
start = 1; |
if ( !name || !(len=strlen(name)) ) return ""; |
b[j++] = ','; |
if ( !(conv_flag&CONV_SUBS) ) return name; |
|
subs = (char **)ALLOCA(len*sizeof(char* )); |
|
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; |
} |
} |
|
|
|
char *call_convfunc(char *name) |
|
{ |
|
STRING str,r; |
|
NODE arg; |
|
|
|
MKSTR(str,name); |
|
arg = mknode(1,str); |
|
r = (STRING)bevalf(convfunc,arg); |
|
if ( !r || OID(r) != O_STR ) |
|
error("call_convfunc : invalid result"); |
|
return BDY(r); |
|
} |
|
|
int register_symbol_table(Obj arg) |
int register_symbol_table(Obj arg) |
{ |
{ |
NODE n,t; |
NODE n,t; |
Line 243 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) |
|
{ |
|
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; |
|
break; |
|
case 1: |
|
conv_rule = conv_rule_d; |
|
return 1; |
|
break; |
|
default: |
|
return 0; |
|
break; |
|
} |
|
} else return 0; |
} else return 0; |
} |
} |
|
|
|
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); |
|
/* f must be a function which takes single argument */ |
|
return 1; |
|
} else return 0; |
|
} |
|
|
int register_dp_vars(Obj arg) |
int register_dp_vars(Obj arg) |
{ |
{ |
int l,i; |
int l,i; |
Line 272 int register_dp_vars(Obj arg) |
|
Line 383 int register_dp_vars(Obj arg) |
|
if ( !arg ) { |
if ( !arg ) { |
dp_vars = 0; |
dp_vars = 0; |
dp_vars_len = 0; |
dp_vars_len = 0; |
|
return 1; |
} else if ( OID(arg) != O_LIST ) |
} else if ( OID(arg) != O_LIST ) |
return 0; |
return 0; |
else { |
else { |
Line 294 int register_dp_vars(Obj arg) |
|
Line 406 int register_dp_vars(Obj arg) |
|
} |
} |
} |
} |
|
|
|
int register_dp_vars_prefix(Obj arg) |
|
{ |
|
if ( !arg ) { |
|
dp_vars_prefix = 0; |
|
return 1; |
|
} else if ( OID(arg) == O_STR ) { |
|
dp_vars_prefix = BDY((STRING)arg); |
|
return 1; |
|
} else if ( OID(arg) == O_P ) { |
|
dp_vars_prefix = NAME(VR((P)arg)); |
|
return 1; |
|
} 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 312 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 356 void Pquotetotex(NODE arg,STRING *rp) |
|
Line 503 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 366 void Pquotetotex_tb(NODE arg,Q *rp) |
|
Line 515 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 673 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 680 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; |
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,si; |
|
C cplx; |
|
char *r; |
FNODE fi,f2; |
FNODE fi,f2; |
|
|
write_tb(" ",tb); |
write_tb(" ",tb); |
Line 725 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 780 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 815 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 879 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 = 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 896 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1057 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 906 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 ) |
|
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 |
vname_conv = conv_rule(vname); |
sprintf(vname,"x_{%d}",i); |
} else { |
vname_conv = symbol_name(vname); |
if ( dp_vars_hweyl ) { |
|
if ( i < elen2 ) { |
|
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 934 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1130 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 944 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 = symbol_name(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 968 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) ) { |
|
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 991 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; |
} |
} |