version 1.39, 2004/03/11 04:52:17 |
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.38 2004/03/11 03:39:39 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); |
Line 101 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 118 int register_symbol_table(Obj arg); |
|
Line 120 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_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_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; |
|
|
{"conv_func",0,register_conv_func}, |
{"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}, |
{"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 ( convfunc ) |
if ( convfunc ) |
name = call_convfunc(name); |
name = call_convfunc(name); |
if ( conv_flag & CONV_DMODE ) { |
if ( conv_flag & CONV_TABLE ) { |
if ( *name == 'd' ) { |
r = symbol_name(name); |
body = conv_flag&CONV_SUBS?conv_subs(name+1):symbol_name(name+1); |
if ( r ) return r; |
if ( !body ) { |
} |
r = MALLOC_ATOMIC((strlen(PARTIAL)+1)*sizeof(char)); |
if ( (conv_flag & CONV_DMODE) && *name == 'd' ) { |
strcpy(r,PARTIAL); |
body = conv_rule(name+1); |
} else { |
r = MALLOC_ATOMIC((strlen(PARTIAL)+strlen(body)+5)*sizeof(char)); |
r = MALLOC_ATOMIC((strlen(PARTIAL)+strlen(body)+5) |
if ( !body || !(len=strlen(body)) ) |
*sizeof(char)); |
strcpy(r,PARTIAL); |
sprintf(r,strlen(body)==1?"{%s}_%s":"{%s}_{%s}",PARTIAL,body); |
else if ( len == 1 ) |
} |
sprintf(r,"%s_%s",PARTIAL,body); |
return r; |
else |
} else |
sprintf(r,"%s_{%s}",PARTIAL,body); |
return conv_flag&CONV_SUBS?conv_subs(name):symbol_name(name); |
return r; |
} else |
} else |
return conv_flag&CONV_SUBS?conv_subs(name):symbol_name(name); |
return conv_subs(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) |
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,*brace; |
char *buf,*head,*r,*h,*brace,*buf_conv; |
char **subs; |
char **subs; |
|
|
len = strlen(name); |
if ( !name || !(len=strlen(name)) ) return ""; |
if ( !len ) return 0; |
if ( !(conv_flag&CONV_SUBS) ) return name; |
subs = (char **)ALLOCA(len*sizeof(char* )); |
subs = (char **)ALLOCA(len*sizeof(char* )); |
for ( i = 0, j = 0, start = i; ; j++ ) { |
for ( i = 0, j = 0, start = i; ; j++ ) { |
while ( (i < len) && |
while ( (i < len) && _is_delimiter(name[i]) ) i++; |
(name[i] == ' ' || name[i] == '_' || name[i] == ',') ) i++; |
|
start = i; |
start = i; |
if ( i == len ) break; |
if ( i == len ) break; |
if ( name[i] == '{' ) { |
if ( name[i] == '{' ) { |
Line 212 char *conv_subs(char *name) |
|
Line 236 char *conv_subs(char *name) |
|
if ( isdigit(name[i]) ) |
if ( isdigit(name[i]) ) |
while ( i < len && isdigit(name[i]) ) i++; |
while ( i < len && isdigit(name[i]) ) i++; |
else |
else |
while ( i < len && (isalpha(name[i]) || name[i] == '\\') ) i++; |
while ( i < len && _is_alpha(name[i]) ) i++; |
slen = i-start; |
slen = i-start; |
buf = (char *)ALLOCA((slen+1)*sizeof(char)); |
buf = (char *)ALLOCA((slen+1)*sizeof(char)); |
strncpy(buf,name+start,slen); buf[slen] = 0; |
strncpy(buf,name+start,slen); buf[slen] = 0; |
subs[j] = symbol_name(buf); |
buf_conv = symbol_name(buf); |
|
subs[j] = buf_conv?buf_conv:buf; |
} |
} |
} |
} |
for ( k = 0, clen = 0; k < j; k++ ) clen += strlen(subs[k]); |
for ( k = 0, clen = 0; k < j; k++ ) clen += strlen(subs[k]); |
Line 295 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) |
int register_dp_vars_hweyl(Obj arg) |
{ |
{ |
if ( INT(arg) ) { |
if ( INT(arg) ) { |
Line 322 int register_conv_rule(Obj arg) |
|
Line 363 int register_conv_rule(Obj arg) |
|
|
|
int register_conv_func(Obj arg) |
int register_conv_func(Obj arg) |
{ |
{ |
if ( OID(arg) == O_P && (int)(VR((P)arg))->attr == V_SR ) { |
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 376 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 396 void Pquotetotex_env(NODE arg,Obj *rp) |
|
Line 454 void Pquotetotex_env(NODE arg,Obj *rp) |
|
*rp = (Obj)l; |
*rp = (Obj)l; |
} else if ( ac == 1 && !ARG0(arg) ) { |
} else if ( ac == 1 && !ARG0(arg) ) { |
/* set to default */ |
/* set to default */ |
for ( i = 0; qtot_env[i].name; i++ ) |
for ( i = 0; qtot_env[i].name; i++ ) { |
|
(qtot_env[i].reg)(0); |
qtot_env[i].value = 0; |
qtot_env[i].value = 0; |
|
} |
*rp = 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"); |
Line 764 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) ) |
if ( !(conv_flag & CONV_TABLE) ) |
return name; |
return name; |
|
|
Line 774 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) |
Line 783 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 845 void fnodetotex_tb(FNODE f,TB tb) |
|
char vname[BUFSIZ],prefix[BUFSIZ]; |
char vname[BUFSIZ],prefix[BUFSIZ]; |
char *opname,*vname_conv,*prefix_conv; |
char *opname,*vname_conv,*prefix_conv; |
Obj obj; |
Obj obj; |
int i,len,allzero,elen,elen2; |
int i,len,allzero,elen,elen2,si; |
|
C cplx; |
|
char *r; |
FNODE fi,f2; |
FNODE fi,f2; |
|
|
write_tb(" ",tb); |
write_tb(" ",tb); |
Line 871 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 906 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 970 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 1014 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1084 void fnodetotex_tb(FNODE f,TB tb) |
|
vname_conv = conv_rule(vname); |
vname_conv = conv_rule(vname); |
} else { |
} else { |
if ( dp_vars_hweyl ) { |
if ( dp_vars_hweyl ) { |
if ( i < elen2 ) |
if ( i < elen2 ) { |
strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x"); |
strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x"); |
else if ( i < elen ) |
prefix_conv = conv_rule(prefix); |
strcpy(prefix,"\\partial"); |
vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50); |
else |
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"); |
strcpy(prefix,"h"); |
} else |
vname_conv = conv_rule(prefix); |
|
} |
|
} else { |
strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x"); |
strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x"); |
prefix_conv = conv_rule(prefix); |
prefix_conv = conv_rule(prefix); |
vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50); |
vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50); |
if ( i < 10 ) |
si = i+dp_vars_origin; |
sprintf(vname_conv,"%s_%d",prefix_conv,i); |
sprintf(vname_conv,(si>=0&&si<10)?"%s_%d":"%s_{%d}", |
else |
prefix_conv,si); |
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); |
Line 1061 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 1085 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 1167 int top_is_minus(FNODE f) |
|
Line 1279 int top_is_minus(FNODE f) |
|
default: |
default: |
return 0; |
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; |
} |
} |