=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/builtin/strobj.c,v retrieving revision 1.42 retrieving revision 1.48 diff -u -p -r1.42 -r1.48 --- OpenXM_contrib2/asir2000/builtin/strobj.c 2004/03/12 02:15:23 1.42 +++ OpenXM_contrib2/asir2000/builtin/strobj.c 2004/07/13 07:59:53 1.48 @@ -45,7 +45,7 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.41 2004/03/12 02:06:48 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.47 2004/07/07 07:40:19 noro Exp $ */ #include "ca.h" #include "parse.h" @@ -75,6 +75,8 @@ void Pstring_to_tb(); void Pquotetotex_tb(); void Pquotetotex(); void Pquotetotex_env(); +void Pflatten_quote(); +void Pquote_to_funargs(),Pfunargs_to_quote(); void fnodetotex_tb(FNODE f,TB tb); char *symbol_name(char *name); char *conv_rule(char *name); @@ -101,6 +103,9 @@ struct ftab str_tab[] = { {"quotetotex_tb",Pquotetotex_tb,2}, {"quotetotex",Pquotetotex,1}, {"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}, }; @@ -118,6 +123,9 @@ int register_symbol_table(Obj arg); int register_conv_rule(Obj arg); int register_conv_func(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); @@ -126,6 +134,9 @@ static struct TeXSymbol *user_texsymbol; static char **dp_vars; 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; @@ -146,6 +157,9 @@ static struct { {"conv_func",0,register_conv_func}, {"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}, @@ -309,6 +323,22 @@ int register_symbol_table(Obj arg) 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) ) { @@ -336,7 +366,10 @@ int register_conv_rule(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); /* f must be a function which takes single argument */ return 1; @@ -390,6 +423,20 @@ int register_dp_vars_prefix(Obj arg) } 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) { int ac,i; @@ -410,8 +457,10 @@ void Pquotetotex_env(NODE arg,Obj *rp) *rp = (Obj)l; } else if ( ac == 1 && !ARG0(arg) ) { /* 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; + } *rp = 0; } else if ( ac == 1 || ac == 2 ) { asir_assert(ARG0(arg),O_STR,"quotetotex_env"); @@ -799,7 +848,7 @@ void fnodetotex_tb(FNODE f,TB tb) char vname[BUFSIZ],prefix[BUFSIZ]; char *opname,*vname_conv,*prefix_conv; Obj obj; - int i,len,allzero,elen,elen2; + int i,len,allzero,elen,elen2,si; C cplx; char *r; FNODE fi,f2; @@ -889,12 +938,12 @@ void fnodetotex_tb(FNODE f,TB tb) break; case C_GT: fnodetotex_tb((FNODE)FA1(f),tb); - write_tb(" \\gt ",tb); + write_tb(" > ",tb); fnodetotex_tb((FNODE)FA2(f),tb); break; case C_LT: fnodetotex_tb((FNODE)FA1(f),tb); - write_tb(" \\lt ",tb); + write_tb(" < ",tb); fnodetotex_tb((FNODE)FA2(f),tb); break; case C_GE: @@ -924,12 +973,12 @@ void fnodetotex_tb(FNODE f,TB tb) break; case L_GT: fnodetotex_tb((FNODE)FA1(f),tb); - write_tb(" \\gt ",tb); + write_tb(" > ",tb); fnodetotex_tb((FNODE)FA2(f),tb); break; case L_LT: fnodetotex_tb((FNODE)FA1(f),tb); - write_tb(" \\lt ",tb); + write_tb(" < ",tb); fnodetotex_tb((FNODE)FA2(f),tb); break; case L_GE: @@ -1038,20 +1087,33 @@ void fnodetotex_tb(FNODE f,TB tb) vname_conv = conv_rule(vname); } else { if ( dp_vars_hweyl ) { - if ( i < elen2 ) + if ( i < elen2 ) { strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x"); - else if ( i < elen ) - strcpy(prefix,"\\partial"); - else + 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"); - } else + 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); - if ( i < 10 ) - sprintf(vname_conv,"%s_%d",prefix_conv,i); - else - sprintf(vname_conv,"%s_{%d}",prefix_conv,i); + 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)) ) { len = strlen(vname_conv); @@ -1220,4 +1282,134 @@ int top_is_minus(FNODE f) 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; + NODE t0,t; + + 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; + 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; + int i; + LIST l; + fid id; + Obj a; + NODE t0,t; + + 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; + 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); }