version 1.26, 2004/03/05 01:47:19 |
version 1.33, 2004/03/09 07:25:35 |
|
|
* 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.32 2004/03/09 07:18:26 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_subscript(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); |
Line 114 int register_symbol_table(Obj arg); |
|
Line 117 int register_symbol_table(Obj arg); |
|
int register_conv_rule(Obj arg); |
int register_conv_rule(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); |
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_SUBSCRIPT (1U<<0) |
|
#define CONV_DMODE (1U<<1) |
|
#define CONV_USERFUNC (1U<<31) |
|
|
static struct { |
static struct { |
char *name; |
char *name; |
Obj value; |
Obj value; |
|
|
{"conv_rule",0,register_conv_rule}, |
{"conv_rule",0,register_conv_rule}, |
{"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; |
|
l = strlen(name); |
|
|
|
if ( name[0] == 'd' ) { |
if ( conv_flag & CONV_DMODE ) { |
/* 3 : _{} */ |
if ( *name == 'd' ) { |
b = (char *)ALLOCA((2*l+1+strlen(PARTIAL)+3)*sizeof(char)); |
if ( conv_flag & CONV_SUBSCRIPT ) |
sprintf(b,"%s_{",PARTIAL); |
body = conv_subscript(name+1); |
i = 1; |
else |
j = strlen(b); |
body = name+1; |
} else { |
r = MALLOC_ATOMIC((strlen(PARTIAL)+strlen(body)+5)*sizeof(char)); |
b = (char *)ALLOCA((2*l+1)*sizeof(char)); |
sprintf(r,"{%s}_{%s}",PARTIAL,body); |
i = j = 0; |
return r; |
} |
} else { |
for ( ; i < l && name[i] == '_'; i++); |
if ( conv_flag & CONV_SUBSCRIPT ) |
for ( ; i < l; ) { |
body = conv_subscript(name); |
if ( !isalpha(name[i]) ) |
else |
break; |
body = name; |
else |
} |
b[j++] = name[i++]; |
} else if ( conv_flag & CONV_SUBSCRIPT ) |
} |
return conv_subscript(name); |
if ( i == l ) |
else if ( conv_flag & CONV_USERFUNC && convfunc ) |
if ( name[0] == 'd' ) |
return call_convfunc(name); |
goto END; |
else |
else |
return name; |
return name; |
} |
/* we found a digit or '_' */ |
|
b[j++] = '_'; b[j++] = '{'; |
char *conv_subscript(char *name) |
if ( name[i] == '_' ) i++; |
{ |
for ( start = 1; i < l; ) { |
int i,j,k,len,clen,slen,start,level; |
if ( name[i] == '{' || name[i] == '}' || name[i] == ' ' ) |
char *buf,*head,*r,*h,*brace; |
b[j++] = name[i++]; |
char **subs; |
else if ( name[i] == '_' ) { |
|
i++; |
len = strlen(name); |
start = 1; |
subs = (char **)ALLOCA(len*sizeof(char* )); |
b[j++] = ','; |
for ( i = 0, j = 0, start = i; ; j++ ) { |
} else if ( start ) { |
while ( (i < len) && |
alpha = isalpha(name[i])?1:0; |
(name[i] == ' ' || name[i] == '_' || name[i] == ',') ) i++; |
b[j++] = name[i++]; |
start = i; |
start = 0; |
if ( i == len ) break; |
} else if ( alpha ) { |
if ( name[i] == '{' ) { |
if ( isalpha(name[i]) ) |
for ( level = 1, i++; i < len && level; i++ ) { |
b[j++] = name[i++]; |
if ( name[i] == '{' ) level++; |
else { |
else if ( name[i] == '}' ) level--; |
alpha = 0; |
|
start = 1; |
|
b[j++] = ','; |
|
} |
} |
|
slen = i-start; |
|
brace = (char *)ALLOCA((slen+1)*sizeof(char)); |
|
strncpy(brace,name+start+1,slen-2); |
|
brace[slen-2] = 0; |
|
buf = conv_subscript(brace); |
|
subs[j] = (char *)ALLOCA((strlen(buf)+3)*sizeof(char)); |
|
sprintf(subs[j],"{%s}",buf); |
} 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 && (isalpha(name[i]) || 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; |
|
subs[j] = symbol_name(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 288 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; |
|
break; |
|
case 1: |
|
conv_rule = conv_rule_d; |
|
return 1; |
|
break; |
|
default: |
|
return 0; |
|
break; |
|
} |
|
} else if ( OID(arg) == O_P && |
} else if ( OID(arg) == O_P && |
(int)(VR((P)arg))->attr == V_SR ) { |
(int)(VR((P)arg))->attr == V_SR ) { |
|
conv_flag = CONV_USERFUNC; |
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 397 void Pquotetotex(NODE arg,STRING *rp) |
|
Line 428 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 440 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 721 char *symbol_name(char *name) |
|
Line 756 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 name; |
return (*conv_rule)(name); |
|
else |
|
return name; |
|
} |
} |
|
|
void fnodetotex_tb(FNODE f,TB tb) |
void fnodetotex_tb(FNODE f,TB tb) |
Line 733 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 765 void fnodetotex_tb(FNODE f,TB tb) |
|
char vname[BUFSIZ]; |
char vname[BUFSIZ]; |
char *opname,*vname_conv; |
char *opname,*vname_conv; |
Obj obj; |
Obj obj; |
int i,len,allzero; |
int i,len,allzero,elen,elen2; |
FNODE fi,f2; |
FNODE fi,f2; |
|
|
write_tb(" ",tb); |
write_tb(" ",tb); |
Line 920 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 952 void fnodetotex_tb(FNODE f,TB tb) |
|
|
|
/* function */ |
/* function */ |
case I_FUNC: |
case I_FUNC: |
opname = symbol_name(((FUNC)FA0(f))->name); |
opname = conv_rule(((FUNC)FA0(f))->name); |
write_tb(opname,tb); |
write_tb(opname,tb); |
write_tb("(",tb); |
write_tb("(",tb); |
fargstotex_tb(opname,FA1(f),tb); |
fargstotex_tb(opname,FA1(f),tb); |
Line 929 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 961 void fnodetotex_tb(FNODE f,TB tb) |
|
|
|
/* 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 969 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 979 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_hweyl ) { |
|
if ( i < elen2 ) |
|
if ( dp_vars_prefix ) |
|
sprintf(vname,"%s_{%d}",dp_vars_prefix,i); |
|
else |
|
sprintf(vname,"x_{%d}",i); |
|
else if ( i < elen ) |
|
sprintf(vname,"{\\partial}_{%d}",i-elen2); |
|
else |
|
strcpy(vname,"h"); |
|
} else if ( dp_vars && i < dp_vars_len ) |
strcpy(vname,dp_vars[i]); |
strcpy(vname,dp_vars[i]); |
else if ( dp_vars_prefix ) |
else if ( dp_vars_prefix ) |
sprintf(vname,"%s_{%d}",dp_vars_prefix,i); |
sprintf(vname,"%s_{%d}",dp_vars_prefix,i); |
else |
else |
sprintf(vname,"x_{%d}",i); |
sprintf(vname,"x_{%d}",i); |
vname_conv = symbol_name(vname); |
vname_conv = conv_rule(vname); |
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 1026 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 988 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1041 void fnodetotex_tb(FNODE f,TB tb) |
|
case I_FORMULA: |
case I_FORMULA: |
obj = (Obj)FA0(f); |
obj = (Obj)FA0(f); |
if ( obj && OID(obj) == O_P ) { |
if ( obj && OID(obj) == O_P ) { |
opname = symbol_name(VR((P)obj)->name); |
opname = conv_rule(VR((P)obj)->name); |
} else { |
} else { |
len = estimate_length(CO,obj); |
len = estimate_length(CO,obj); |
opname = (char *)MALLOC_ATOMIC(len+1); |
opname = (char *)MALLOC_ATOMIC(len+1); |
Line 1014 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1067 void fnodetotex_tb(FNODE f,TB tb) |
|
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); |
} |
} |