version 1.26, 2004/03/05 01:47:19 |
version 1.50, 2004/07/13 10:57:26 |
|
|
* 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.49 2004/07/13 09:10:38 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 65 struct TeXSymbol { |
|
Line 65 struct TeXSymbol { |
|
|
|
extern char *parse_strp; |
extern char *parse_strp; |
|
|
|
void Psprintf(); |
void Prtostr(), Pstrtov(), Peval_str(); |
void Prtostr(), Pstrtov(), Peval_str(); |
void Pstrtoascii(), Pasciitostr(); |
void Pstrtoascii(), Pasciitostr(); |
void Pstr_len(), Pstr_chr(), Psub_str(); |
void Pstr_len(), Pstr_chr(), Psub_str(); |
Line 75 void Pstring_to_tb(); |
|
Line 76 void Pstring_to_tb(); |
|
void Pquotetotex_tb(); |
void Pquotetotex_tb(); |
void Pquotetotex(); |
void Pquotetotex(); |
void Pquotetotex_env(); |
void Pquotetotex_env(); |
|
void Pflatten_quote(); |
|
void Pquote_to_funargs(),Pfunargs_to_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[] = { |
|
{"sprintf",Psprintf,-99999999}, |
{"rtostr",Prtostr,1}, |
{"rtostr",Prtostr,1}, |
{"strtov",Pstrtov,1}, |
{"strtov",Pstrtov,1}, |
{"eval_str",Peval_str,1}, |
{"eval_str",Peval_str,1}, |
Line 97 struct ftab str_tab[] = { |
|
Line 105 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}, |
|
{"quote_to_funargs",Pquote_to_funargs,1}, |
|
{"funargs_to_quote",Pfunargs_to_quote,1}, |
{0,0,0}, |
{0,0,0}, |
}; |
}; |
|
|
Line 112 void write_tb(char *s,TB tb) |
|
Line 123 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); |
|
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 char *dp_dvars_prefix; |
|
static int dp_vars_origin; |
|
static int dp_dvars_origin; |
|
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_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] == '{' || 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 325 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; |
} else return 0; |
break; |
} |
case 1: |
|
conv_rule = conv_rule_d; |
int register_conv_func(Obj arg) |
return 1; |
{ |
break; |
if ( !arg ) { |
default: |
convfunc = 0; |
return 0; |
return 1; |
break; |
} else if ( OID(arg) == O_P && (int)(VR((P)arg))->attr == V_SR ) { |
} |
|
} 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 335 int register_dp_vars_prefix(Obj arg) |
|
Line 425 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 353 void Pquotetotex_env(NODE arg,Obj *rp) |
|
Line 457 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 397 void Pquotetotex(NODE arg,STRING *rp) |
|
Line 508 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 520 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 829 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 841 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 766 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 885 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 821 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 940 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 856 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 975 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 920 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1039 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 1062 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 1072 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"); |
|
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 977 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1135 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 1149 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 1011 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1190 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 Psprintf(NODE arg,STRING *rp) |
|
{ |
|
STRING string; |
|
char *s,*t,*r; |
|
int argc,n,len; |
|
NODE node; |
|
|
|
string = (STRING)ARG0(arg); |
|
asir_assert(string,O_STR,"sprintf"); |
|
s = BDY(string); |
|
for(n = 0, t = s; *t; t++) { |
|
if (*t=='%' && *(t+1)=='a') { |
|
n++; |
|
} |
|
} |
|
for(node = NEXT(arg), argc = 0, len = strlen(s); node; node = NEXT(node), argc++) { |
|
len += estimate_length(CO,BDY(node)); |
|
} |
|
if (argc < n) { |
|
error("sprintf: invalid argument"); |
|
} |
|
r = (char *)MALLOC_ATOMIC(len); |
|
for(node = NEXT(arg), t = r; *s; s++) { |
|
if (*s=='%' && *(s+1)=='a') { |
|
strcpy(t,objtostr(BDY(node))); |
|
node = NEXT(node); |
|
t = strchr(t,0); |
|
s++; |
|
}else { |
|
*t++ = *s; |
|
} |
|
} |
|
*t = 0; |
|
MKSTR(*rp,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 1034 void fargstotex_tb(char *name,FNODE f,TB tb) |
|
Line 1262 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,Obj *rp) |
|
{ |
|
FNODE f; |
|
QUOTE q; |
|
|
|
if ( !ARG0(arg) || OID((Obj)ARG0(arg)) != O_QUOTE ) |
|
*rp = (Obj)ARG0(arg); |
|
else { |
|
f = flatten_fnode(BDY((QUOTE)ARG0(arg)),BDY((STRING)ARG1(arg))); |
|
MKQUOTE(q,f); |
|
*rp = (Obj)q; |
|
} |
|
} |
|
|
|
void Pquote_to_funargs(NODE arg,LIST *rp) |
|
{ |
|
fid_spec_p spec; |
|
QUOTE q; |
|
QUOTEARG qa; |
|
FNODE f; |
|
STRING s; |
|
QUOTE r; |
|
int i; |
|
Q id,a; |
|
LIST l; |
|
NODE t0,t,w,u,u0; |
|
|
|
q = (QUOTE)ARG0(arg); |
|
if ( !q || OID(q) != O_QUOTE ) |
|
error("quote_to_funargs : invalid argument"); |
|
f = BDY(q); |
|
if ( !f ) { |
|
MKLIST(*rp,0); |
|
return; |
|
} |
|
get_fid_spec(f->id,&spec); |
|
if ( !spec ) |
|
error("quote_to_funargs : not supported yet"); |
|
t0 = 0; |
|
STOQ((int)f->id,id); |
|
NEXTNODE(t0,t); |
|
BDY(t) = (pointer)id; |
|
for ( i = 0; spec->type[i] != A_end; i++ ) { |
|
NEXTNODE(t0,t); |
|
switch ( spec->type[i] ) { |
|
case A_fnode: |
|
MKQUOTE(r,(FNODE)f->arg[i]); |
|
BDY(t) = (pointer)r; |
|
break; |
|
case A_int: |
|
STOQ((int)f->arg[i],a); |
|
BDY(t) = (pointer)a; |
|
break; |
|
case A_str: |
|
MKSTR(s,(char *)f->arg[i]); |
|
BDY(t) = (pointer)s; |
|
break; |
|
case A_internal: |
|
BDY(t) = (pointer)f->arg[i]; |
|
break; |
|
case A_node: |
|
w = (NODE)f->arg[i]; |
|
for ( u0 = 0; w; w = NEXT(w) ){ |
|
NEXTNODE(u0,u); |
|
MKQUOTE(r,(FNODE)BDY(w)); |
|
BDY(u) = (pointer)r; |
|
} |
|
if ( u0 ) NEXT(u) = 0; |
|
MKLIST(l,u0); |
|
BDY(t) = (pointer)l; |
|
break; |
|
default: |
|
MKQUOTEARG(qa,spec->type[i],f->arg[i]); |
|
BDY(t) = (pointer)qa; |
|
break; |
|
} |
|
} |
|
if ( t0 ) NEXT(t) = 0; |
|
MKLIST(*rp,t0); |
|
} |
|
|
|
void Pfunargs_to_quote(NODE arg,QUOTE *rp) |
|
{ |
|
fid_spec_p spec; |
|
QUOTE q; |
|
QUOTEARG qa; |
|
FNODE f; |
|
STRING s; |
|
QUOTE r,b; |
|
int i; |
|
LIST l; |
|
fid id; |
|
Obj a; |
|
NODE t0,t,u0,u,w; |
|
|
|
l = (LIST)ARG0(arg); |
|
if ( !l || OID(l) != O_LIST || !(t=BDY(l)) ) |
|
error("funargs_to_quote : invalid argument"); |
|
t = BDY(l); |
|
id = (fid)QTOS((Q)BDY(t)); t = NEXT(t); |
|
get_fid_spec(id,&spec); |
|
if ( !spec ) |
|
error("funargs_to_quote : not supported yet"); |
|
for ( i = 0; spec->type[i] != A_end; i++ ); |
|
NEWFNODE(f,i); |
|
f->id = id; |
|
for ( i = 0; spec->type[i] != A_end; i++, t = NEXT(t) ) { |
|
if ( !t ) |
|
error("funargs_to_quote : argument mismatch"); |
|
a = (Obj)BDY(t); |
|
switch ( spec->type[i] ) { |
|
case A_fnode: |
|
if ( !a || OID(a) != O_QUOTE ) |
|
error("funargs_to_quote : invalid argument"); |
|
f->arg[i] = BDY((QUOTE)a); |
|
break; |
|
case A_int: |
|
if ( !INT(a) ) |
|
error("funargs_to_quote : invalid argument"); |
|
f->arg[i] = (pointer)QTOS((Q)a); |
|
break; |
|
case A_str: |
|
if ( !a || OID(a) != O_STR ) |
|
error("funargs_to_quote : invalid argument"); |
|
f->arg[i] = (pointer)BDY((STRING)a); |
|
break; |
|
case A_internal: |
|
f->arg[i] = (pointer)a; |
|
break; |
|
case A_node: |
|
if ( !a || OID(a) != O_LIST ) |
|
error("funargs_to_quote : invalid argument"); |
|
u0 = 0; |
|
for ( w = BDY((LIST)a); w; w = NEXT(w) ) { |
|
NEXTNODE(u0,u); |
|
b = (QUOTE)BDY(w); |
|
if ( !b || OID(b) != O_QUOTE ) |
|
error("funargs_to_quote : invalid argument"); |
|
BDY(u) = BDY(b); |
|
} |
|
if ( u0 ) NEXT(u) = 0; |
|
f->arg[i] = (pointer)u0; |
|
break; |
|
default: |
|
if ( !a || OID(a) != O_QUOTEARG || |
|
((QUOTEARG)a)->type != spec->type[i] ) |
|
error("funargs_to_quote : invalid argument"); |
|
f->arg[i] = BDY((QUOTEARG)a); |
|
break; |
|
} |
|
} |
|
MKQUOTE(*rp,f); |
} |
} |