[BACK]Return to strobj.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / builtin

Annotation of OpenXM_contrib2/asir2000/builtin/strobj.c, Revision 1.55

1.6       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.7       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.6       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.55    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.54 2005/07/15 00:23:26 noro Exp $
1.6       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52: #include "ctype.h"
1.10      ohara      53: #if defined(PARI)
1.1       noro       54: #include "genpari.h"
1.11      saito      55: #  if !(PARI_VERSION_CODE > 131588)
1.1       noro       56: extern jmp_buf environnement;
1.11      saito      57: #  endif
1.1       noro       58: #endif
1.5       noro       59: #include <string.h>
                     60:
1.18      noro       61: struct TeXSymbol {
                     62:        char *text;
                     63:        char *symbol;
                     64: };
                     65:
1.1       noro       66: extern char *parse_strp;
                     67:
1.50      ohara      68: void Psprintf();
1.1       noro       69: void Prtostr(), Pstrtov(), Peval_str();
1.3       noro       70: void Pstrtoascii(), Pasciitostr();
1.5       noro       71: void Pstr_len(), Pstr_chr(), Psub_str();
1.14      noro       72: void Pwrite_to_tb();
                     73: void Ptb_to_string();
                     74: void Pclear_tb();
                     75: void Pstring_to_tb();
                     76: void Pquotetotex_tb();
                     77: void Pquotetotex();
1.24      noro       78: void Pquotetotex_env();
1.47      noro       79: void Pflatten_quote();
1.52      noro       80: void Pquote_to_funargs(),Pfunargs_to_quote(),Pget_function_name();
1.53      noro       81: void Pquote_unify();
1.14      noro       82: void fnodetotex_tb(FNODE f,TB tb);
                     83: char *symbol_name(char *name);
1.28      noro       84: char *conv_rule(char *name);
1.38      noro       85: char *conv_subs(char *name);
1.28      noro       86: char *call_convfunc(char *name);
1.14      noro       87: void tb_to_string(TB tb,STRING *rp);
                     88: void fnodenodetotex_tb(NODE n,TB tb);
                     89: void fargstotex_tb(char *opname,FNODE f,TB tb);
1.35      noro       90: int top_is_minus(FNODE f);
1.53      noro       91: NODE quote_unify(Obj f,Obj pat);
1.1       noro       92:
                     93: struct ftab str_tab[] = {
1.50      ohara      94:        {"sprintf",Psprintf,-99999999},
1.1       noro       95:        {"rtostr",Prtostr,1},
                     96:        {"strtov",Pstrtov,1},
                     97:        {"eval_str",Peval_str,1},
1.3       noro       98:        {"strtoascii",Pstrtoascii,1},
                     99:        {"asciitostr",Pasciitostr,1},
1.5       noro      100:        {"str_len",Pstr_len,1},
                    101:        {"str_chr",Pstr_chr,3},
                    102:        {"sub_str",Psub_str,3},
1.14      noro      103:        {"write_to_tb",Pwrite_to_tb,2},
                    104:        {"clear_tb",Pclear_tb,1},
                    105:        {"tb_to_string",Ptb_to_string,1},
                    106:        {"string_to_tb",Pstring_to_tb,1},
                    107:        {"quotetotex_tb",Pquotetotex_tb,2},
                    108:        {"quotetotex",Pquotetotex,1},
1.24      noro      109:        {"quotetotex_env",Pquotetotex_env,-99999999},
1.47      noro      110:        {"flatten_quote",Pflatten_quote,2},
1.48      noro      111:        {"quote_to_funargs",Pquote_to_funargs,1},
1.53      noro      112:        {"quote_unify",Pquote_unify,2},
1.48      noro      113:        {"funargs_to_quote",Pfunargs_to_quote,1},
1.52      noro      114:        {"get_function_name",Pget_function_name,1},
1.1       noro      115:        {0,0,0},
                    116: };
1.13      noro      117:
1.14      noro      118: void write_tb(char *s,TB tb)
                    119: {
                    120:        if ( tb->next == tb->size ) {
                    121:                tb->size *= 2;
                    122:                tb->body = (char **)REALLOC(tb->body,tb->size*sizeof(char *));
                    123:        }
                    124:        tb->body[tb->next] = s;
                    125:        tb->next++;
                    126: }
1.13      noro      127:
1.18      noro      128: int register_symbol_table(Obj arg);
                    129: int register_conv_rule(Obj arg);
1.38      noro      130: int register_conv_func(Obj arg);
1.23      noro      131: int register_dp_vars(Obj arg);
1.46      noro      132: int register_dp_vars_origin(Obj arg);
                    133: int register_dp_dvars_origin(Obj arg);
                    134: int register_dp_dvars_prefix(Obj arg);
1.25      noro      135: int register_dp_vars_prefix(Obj arg);
1.31      noro      136: int register_dp_vars_hweyl(Obj arg);
1.27      noro      137: int register_show_lt(Obj arg);
1.40      noro      138: char *objtostr(Obj obj);
1.18      noro      139: static struct TeXSymbol *user_texsymbol;
1.23      noro      140: static char **dp_vars;
1.25      noro      141: static int dp_vars_len;
                    142: static char *dp_vars_prefix;
1.46      noro      143: static char *dp_dvars_prefix;
                    144: static int dp_vars_origin;
                    145: static int dp_dvars_origin;
1.27      noro      146: static int show_lt;
1.26      noro      147: static FUNC convfunc;
1.27      noro      148: static int is_lt;
1.28      noro      149: static int conv_flag;
1.31      noro      150: static int dp_vars_hweyl;
1.28      noro      151:
1.38      noro      152: #define CONV_TABLE (1U<<0)
                    153: #define CONV_SUBS (1U<<1)
                    154: #define CONV_DMODE (1U<<2)
1.18      noro      155:
                    156: static struct {
                    157:        char *name;
                    158:        Obj value;
                    159:        int (*reg)();
                    160: } qtot_env[] = {
                    161:        {"symbol_table",0,register_symbol_table},
                    162:        {"conv_rule",0,register_conv_rule},
1.38      noro      163:        {"conv_func",0,register_conv_func},
1.23      noro      164:        {"dp_vars",0,register_dp_vars},
1.25      noro      165:        {"dp_vars_prefix",0,register_dp_vars_prefix},
1.46      noro      166:        {"dp_dvars_prefix",0,register_dp_dvars_prefix},
                    167:        {"dp_vars_origin",0,register_dp_vars_origin},
                    168:        {"dp_dvars_origin",0,register_dp_dvars_origin},
1.31      noro      169:        {"dp_vars_hweyl",0,register_dp_vars_hweyl},
1.27      noro      170:        {"show_lt",0,register_show_lt},
1.18      noro      171:        {0,0,0},
                    172: };
                    173:
1.20      noro      174: #define PARTIAL "\\partial"
1.28      noro      175:
                    176: char *conv_rule(char *name)
                    177: {
                    178:        char *body,*r;
1.41      noro      179:        int len;
1.28      noro      180:
1.38      noro      181:        if ( convfunc )
                    182:                name = call_convfunc(name);
1.41      noro      183:        if ( conv_flag & CONV_TABLE ) {
                    184:                r = symbol_name(name);
                    185:                if ( r ) return r;
                    186:        }
                    187:        if ( (conv_flag & CONV_DMODE) && *name == 'd' ) {
                    188:                body = conv_rule(name+1);
                    189:                r = MALLOC_ATOMIC((strlen(PARTIAL)+strlen(body)+5)*sizeof(char));
                    190:                if ( !body || !(len=strlen(body)) )
                    191:                        strcpy(r,PARTIAL);
                    192:                else if ( len == 1 )
                    193:                        sprintf(r,"%s_%s",PARTIAL,body);
                    194:                else
                    195:                        sprintf(r,"%s_{%s}",PARTIAL,body);
                    196:                return r;
                    197:        } else
                    198:                return conv_subs(name);
1.28      noro      199: }
                    200:
1.40      noro      201: int _is_delimiter(char c)
                    202: {
                    203:        if ( (c == ' ' || c == '_' || c == ',') ) return 1;
                    204:        else return 0;
                    205: }
                    206:
                    207: int _is_alpha(char c)
                    208: {
                    209:        if ( isdigit(c) || c == '{' || _is_delimiter(c) ) return 0;
                    210:        else return 1;
                    211: }
                    212:
1.38      noro      213: char *conv_subs(char *name)
1.19      noro      214: {
1.29      noro      215:        int i,j,k,len,clen,slen,start,level;
1.41      noro      216:        char *buf,*head,*r,*h,*brace,*buf_conv;
1.28      noro      217:        char **subs;
                    218:
1.41      noro      219:        if ( !name || !(len=strlen(name)) ) return "";
                    220:        if ( !(conv_flag&CONV_SUBS) ) return name;
1.28      noro      221:        subs = (char **)ALLOCA(len*sizeof(char* ));
1.32      noro      222:        for ( i = 0, j = 0, start = i; ; j++ ) {
1.40      noro      223:                while ( (i < len) && _is_delimiter(name[i]) ) i++;
1.32      noro      224:                start = i;
1.28      noro      225:                if ( i == len ) break;
1.29      noro      226:                if ( name[i] == '{' ) {
                    227:                        for ( level = 1, i++; i < len && level; i++ ) {
                    228:                                if ( name[i] == '{' ) level++;
                    229:                                else if ( name[i] == '}' ) level--;
                    230:                        }
1.32      noro      231:                        slen = i-start;
1.37      noro      232:                        if ( slen >= 3 ) {
                    233:                                brace = (char *)ALLOCA((slen+1)*sizeof(char));
                    234:                                strncpy(brace,name+start+1,slen-2);
                    235:                                brace[slen-2] = 0;
1.38      noro      236:                                buf = conv_subs(brace);
1.37      noro      237:                                subs[j] = (char *)ALLOCA((strlen(buf)+3)*sizeof(char));
1.38      noro      238:                                if ( strlen(buf) == 1 )
                    239:                                        strcpy(subs[j],buf);
                    240:                                else
                    241:                                        sprintf(subs[j],"{%s}",buf);
1.37      noro      242:                        } else
                    243:                                subs[j] = "{}";
1.32      noro      244:                } else {
                    245:                        if ( isdigit(name[i]) )
                    246:                                while ( i < len && isdigit(name[i]) ) i++;
                    247:                        else
1.40      noro      248:                                while ( i < len && _is_alpha(name[i]) ) i++;
1.32      noro      249:                        slen = i-start;
                    250:                        buf = (char *)ALLOCA((slen+1)*sizeof(char));
                    251:                        strncpy(buf,name+start,slen); buf[slen] = 0;
1.41      noro      252:                        buf_conv = symbol_name(buf);
                    253:                        subs[j] = buf_conv?buf_conv:buf;
1.32      noro      254:                }
1.28      noro      255:        }
1.32      noro      256:        for ( k = 0, clen = 0; k < j; k++ ) clen += strlen(subs[k]);
                    257:        /* {subs(0)}_{{subs(1)},...,{subs(j-1)}} => {}:j+1 _:1 ,:j-2 */
                    258:        h = r = MALLOC_ATOMIC((clen+(j+1)*2+1+(j-2)+1)*sizeof(char));
                    259:        if ( j == 1 )
                    260:                sprintf(h,"{%s}",subs[0]);
1.28      noro      261:        else {
1.38      noro      262:                sprintf(h,"{%s}_{%s",subs[0],subs[1]);
1.28      noro      263:                h += strlen(h);
1.32      noro      264:                for ( k = 2; k < j; k++ ) {
1.38      noro      265:                        sprintf(h,",%s",subs[k]);
1.28      noro      266:                        h += strlen(h);
1.19      noro      267:                }
1.28      noro      268:                strcpy(h,"}");
1.20      noro      269:        }
                    270:        return r;
1.19      noro      271: }
                    272:
1.26      noro      273: char *call_convfunc(char *name)
                    274: {
                    275:        STRING str,r;
                    276:        NODE arg;
                    277:
                    278:        MKSTR(str,name);
                    279:        arg = mknode(1,str);
                    280:        r = (STRING)bevalf(convfunc,arg);
                    281:        if ( !r || OID(r) != O_STR )
                    282:                error("call_convfunc : invalid result");
                    283:        return BDY(r);
                    284: }
                    285:
1.18      noro      286: int register_symbol_table(Obj arg)
                    287: {
                    288:        NODE n,t;
                    289:        Obj b;
                    290:        STRING a0,a1;
                    291:        struct TeXSymbol *uts;
                    292:        int i,len;
                    293:
                    294:        /* check */
                    295:        if ( !arg ) {
                    296:                user_texsymbol = 0;
                    297:                return 1;
                    298:        }
                    299:        if ( OID(arg) != O_LIST ) return 0;
                    300:
                    301:        n = BDY((LIST)arg);
                    302:        len = length(n);
                    303:        uts = (struct TeXSymbol *)MALLOC((len+1)*sizeof(struct TeXSymbol));
                    304:        for ( i = 0; n; n = NEXT(n), i++ ) {
                    305:                b = (Obj)BDY(n);
                    306:                if ( !b || OID(b) != O_LIST ) return 0;
                    307:                t = BDY((LIST)b);
                    308:                if ( !t || !NEXT(t) ) return 0;
                    309:                a0 = (STRING)BDY(t);
                    310:                a1 = (STRING)BDY(NEXT(t));
1.23      noro      311:                if ( !a0 ) return 0;
                    312:                if ( OID(a0) == O_STR )
                    313:                        uts[i].text = BDY(a0);
                    314:                else if ( OID(a0) == O_P )
                    315:                        uts[i].text = NAME(VR((P)a0));
                    316:                else
                    317:                        return 0;
                    318:                if ( !a1 ) return 0;
                    319:                if ( OID(a1) == O_STR )
                    320:                        uts[i].symbol = BDY(a1);
                    321:                else if ( OID(a1) == O_P )
                    322:                        uts[i].symbol = NAME(VR((P)a1));
                    323:                else
                    324:                        return 0;
1.18      noro      325:        }
                    326:        uts[i].text = 0;
                    327:        uts[i].symbol = 0;
                    328:        user_texsymbol = uts;
                    329:        return 1;
                    330: }
                    331:
1.46      noro      332: int register_dp_vars_origin(Obj arg)
                    333: {
                    334:        if ( INT(arg) ) {
                    335:                dp_vars_origin = QTOS((Q)arg);
                    336:                return 1;
                    337:        } else return 0;
                    338: }
                    339:
                    340: int register_dp_dvars_origin(Obj arg)
                    341: {
                    342:        if ( INT(arg) ) {
                    343:                dp_dvars_origin = QTOS((Q)arg);
                    344:                return 1;
                    345:        } else return 0;
                    346: }
                    347:
1.31      noro      348: int register_dp_vars_hweyl(Obj arg)
                    349: {
                    350:        if ( INT(arg) ) {
                    351:                dp_vars_hweyl = QTOS((Q)arg);
                    352:                return 1;
                    353:        } else return 0;
                    354: }
                    355:
1.27      noro      356: int register_show_lt(Obj arg)
                    357: {
                    358:        if ( INT(arg) ) {
                    359:                show_lt = QTOS((Q)arg);
                    360:                return 1;
                    361:        } else return 0;
                    362: }
1.26      noro      363:
1.18      noro      364: int register_conv_rule(Obj arg)
                    365: {
1.19      noro      366:        if ( INT(arg) ) {
1.28      noro      367:                conv_flag = QTOS((Q)arg);
                    368:                convfunc = 0;
                    369:                return 1;
1.38      noro      370:        } else return 0;
                    371: }
                    372:
                    373: int register_conv_func(Obj arg)
                    374: {
1.43      noro      375:        if ( !arg ) {
                    376:                convfunc = 0;
                    377:                return 1;
                    378:        } else if ( OID(arg) == O_P && (int)(VR((P)arg))->attr == V_SR ) {
1.26      noro      379:                convfunc = (FUNC)(VR((P)arg)->priv);
                    380:                /* f must be a function which takes single argument */
                    381:                return 1;
1.19      noro      382:        } else return 0;
1.18      noro      383: }
                    384:
1.23      noro      385: int register_dp_vars(Obj arg)
                    386: {
                    387:        int l,i;
                    388:        char **r;
                    389:        NODE n;
                    390:        STRING a;
                    391:
                    392:        if ( !arg ) {
                    393:                dp_vars = 0;
                    394:                dp_vars_len = 0;
1.25      noro      395:                return 1;
1.23      noro      396:        } else if ( OID(arg) != O_LIST )
                    397:                return 0;
                    398:        else {
                    399:                n = BDY((LIST)arg);
                    400:                l = length(n);
                    401:                r = (char **)MALLOC_ATOMIC(l*sizeof(char *));
                    402:                for ( i = 0; i < l; i++, n = NEXT(n) ) {
                    403:                        a = (STRING)BDY(n);
                    404:                        if ( !a ) return 0;
                    405:                        if ( OID(a) == O_STR )
                    406:                                r[i] = BDY(a);
                    407:                        else if ( OID(a) == O_P )
                    408:                                r[i] = NAME(VR((P)a));
                    409:                        else
                    410:                                return 0;
                    411:                }
                    412:                dp_vars = r;
                    413:                dp_vars_len = l;
                    414:                return 1;
                    415:        }
                    416: }
                    417:
1.25      noro      418: int register_dp_vars_prefix(Obj arg)
                    419: {
                    420:        if ( !arg ) {
                    421:                dp_vars_prefix = 0;
                    422:                return 1;
                    423:        } else if ( OID(arg) == O_STR ) {
                    424:                dp_vars_prefix = BDY((STRING)arg);
                    425:                return 1;
                    426:        } else if ( OID(arg) == O_P ) {
                    427:                dp_vars_prefix = NAME(VR((P)arg));
                    428:                return 1;
                    429:        } else return 0;
                    430: }
                    431:
1.46      noro      432: int register_dp_dvars_prefix(Obj arg)
                    433: {
                    434:        if ( !arg ) {
                    435:                dp_dvars_prefix = 0;
                    436:                return 1;
                    437:        } else if ( OID(arg) == O_STR ) {
                    438:                dp_dvars_prefix = BDY((STRING)arg);
                    439:                return 1;
                    440:        } else if ( OID(arg) == O_P ) {
                    441:                dp_dvars_prefix = NAME(VR((P)arg));
                    442:                return 1;
                    443:        } else return 0;
                    444: }
                    445:
1.24      noro      446: void Pquotetotex_env(NODE arg,Obj *rp)
1.18      noro      447: {
                    448:        int ac,i;
                    449:        char *name;
                    450:        NODE n,n0;
                    451:        STRING s;
                    452:        LIST l;
                    453:
                    454:        ac = argc(arg);
                    455:        if ( !ac ) {
                    456:                n0 = 0;
                    457:                for ( i = 0; qtot_env[i].name; i++ ) {
                    458:                        NEXTNODE(n0,n); MKSTR(s,qtot_env[i].name); BDY(n) = (pointer)s;
                    459:                        NEXTNODE(n0,n); BDY(n) = (Q)qtot_env[i].value;
                    460:                }
                    461:                NEXT(n) = 0;
                    462:                MKLIST(l,n0);
                    463:                *rp = (Obj)l;
1.34      noro      464:        } else if ( ac == 1 && !ARG0(arg) ) {
                    465:                /* set to default */
1.43      noro      466:                for ( i = 0; qtot_env[i].name; i++ ) {
                    467:                        (qtot_env[i].reg)(0);
1.34      noro      468:                        qtot_env[i].value = 0;
1.43      noro      469:                }
1.34      noro      470:                *rp = 0;
1.18      noro      471:        } else if ( ac == 1 || ac == 2 ) {
1.24      noro      472:                asir_assert(ARG0(arg),O_STR,"quotetotex_env");
1.18      noro      473:                name = BDY((STRING)ARG0(arg));
                    474:                for ( i = 0; qtot_env[i].name; i++ )
                    475:                        if ( !strcmp(qtot_env[i].name,name) ) {
                    476:                                if ( ac == 2 ) {
                    477:                                        if ( (qtot_env[i].reg)((Obj)ARG1(arg)) )
                    478:                                                qtot_env[i].value = (Obj)ARG1(arg);
                    479:                                        else
1.24      noro      480:                                                error("quotetotex_env : invalid argument");
1.18      noro      481:                                }
                    482:                                *rp = qtot_env[i].value;
                    483:                                return;
                    484:                        }
                    485:                *rp = 0;
                    486:        } else
                    487:                *rp = 0;
                    488: }
                    489:
1.14      noro      490: void Pwrite_to_tb(NODE arg,Q *rp)
1.13      noro      491: {
                    492:        int i;
1.16      noro      493:        Obj obj;
                    494:        TB tb;
1.13      noro      495:
1.14      noro      496:        asir_assert(ARG1(arg),O_TB,"write_to_tb");
1.16      noro      497:        obj = ARG0(arg);
                    498:        if ( !obj )
                    499:                write_tb("",ARG1(arg));
                    500:        else if ( OID(obj) == O_STR )
                    501:                write_tb(BDY((STRING)obj),ARG1(arg));
                    502:        else if ( OID(obj) == O_TB ) {
                    503:                tb = (TB)obj;
                    504:                for ( i = 0; i < tb->next; i++ )
                    505:                        write_tb(tb->body[i],ARG1(arg));
                    506:        }
1.14      noro      507:        *rp = 0;
1.53      noro      508: }
                    509:
                    510: void Pquote_unify(NODE arg,LIST *rp)
                    511: {
                    512:        NODE r;
                    513:
                    514:        r = quote_unify((Obj)ARG0(arg),(Obj)ARG1(arg));
                    515:        MKLIST(*rp,r);
                    516: }
                    517:
                    518: /*
                    519: /* consistency check and merge */
                    520:
                    521: NODE merge_matching_node(NODE n,NODE a)
                    522: {
                    523:        NODE ta,ba,tn,bn;
                    524:        QUOTE pa,va,pn,vn;
                    525:
                    526:        if ( !n )
                    527:                return a;
                    528:        for ( ta = a; ta; ta = NEXT(ta) ) {
                    529:                ba = BDY((LIST)BDY(ta));
1.55    ! noro      530:                if ( !ba ) continue;
1.53      noro      531:                pa = (QUOTE)BDY(ba); va = (QUOTE)BDY(NEXT(ba));
                    532:                for ( tn = n; tn; tn = NEXT(tn) ) {
                    533:                        bn = BDY((LIST)BDY(tn));
1.55    ! noro      534:                        if ( !bn ) continue;
1.53      noro      535:                        pn = (QUOTE)BDY(bn); vn = (QUOTE)BDY(NEXT(bn));
1.55    ! noro      536:                        if ( !compquote(CO,pa,pn) ) {
        !           537:                                if ( !compquote(CO,va,vn) ) break;
        !           538:                                else return 0;
        !           539:                        }
1.53      noro      540:                }
                    541:                if ( !tn ) {
                    542:                        MKNODE(tn,(pointer)BDY(ta),n);
                    543:                        n = tn;
                    544:                }
                    545:        }
                    546:        return n;
                    547: }
                    548:
                    549: NODE quote_unify_node(NODE f,NODE pat) {
                    550:        NODE r,a,tf,tp;
                    551:
                    552:        if ( length(f) != length(pat) ) return 0;
                    553:        r = 0;
                    554:        for ( tf = f, tp = pat; tf; tf = NEXT(tf), tp = NEXT(tp) ) {
                    555:                a = quote_unify((Obj)BDY(tf),(Obj)BDY(tp));
1.55    ! noro      556:                if ( !a ) return 0;
1.53      noro      557:                r = merge_matching_node(r,a);
                    558:                if ( !r ) return 0;
                    559:        }
                    560:        return r;
                    561: }
                    562:
                    563: void get_quote_id_arg(QUOTE f,int *id,NODE *r)
                    564: {
                    565:        LIST fa;
                    566:        NODE arg,fab;
                    567:
                    568:        arg = mknode(1,f); Pquote_to_funargs(arg,&fa); fab = BDY((LIST)fa);
                    569:        *id = QTOS((Q)BDY(fab)); *r = NEXT(fab);
                    570: }
                    571:
                    572: /* ret : [[quote(A),quote(1)],...] */
                    573:
                    574: NODE quote_unify(Obj f, Obj pat)
                    575: {
                    576:        NODE tf,tp,head,body;
                    577:        NODE parg,farg,r;
                    578:        LIST fa,l;
                    579:        int pid,id;
1.55    ! noro      580:        FUNC ff,pf;
1.53      noro      581:
                    582:        if ( OID(pat) == O_LIST ) {
                    583:                if ( OID(f) == O_LIST )
                    584:                        return quote_unify_node(BDY((LIST)f),BDY((LIST)pat));
                    585:                else
                    586:                        return 0;
                    587:        } else if ( OID(pat) == O_QUOTE ) {
                    588:                if ( OID(f) != O_QUOTE ) return 0;
                    589:                get_quote_id_arg((QUOTE)pat,&pid,&parg);
                    590:                get_quote_id_arg((QUOTE)f,&id,&farg);
                    591:                switch ( pid ) {
1.55    ! noro      592:                        case I_FORMULA:
        !           593:                                if ( compquote(CO,f,pat) )
        !           594:                                        return 0;
        !           595:                                else {
        !           596:                                        MKLIST(l,0);
        !           597:                                        return mknode(1,l);
        !           598:                                }
        !           599:                                break;
        !           600:                        case I_LIST:
        !           601:                                return quote_unify_node(BDY((LIST)BDY(farg)),BDY((LIST)BDY(parg)));
1.53      noro      602:                        case I_PVAR:
                    603:                                /* [[pat,f]] */
                    604:                                r = mknode(2,pat,f); MKLIST(l,r);
                    605:                                return mknode(1,l);
                    606:                        case I_IFUNC:
                    607:                                /* F(X,Y,...) = ... */
                    608:                                if ( id == I_FUNC ) {
1.54      noro      609:                                        r = mknode(2,BDY(parg),BDY(farg)); MKLIST(l,r);
                    610:                                        head = mknode(1,l);
1.53      noro      611:                                        body = quote_unify(BDY(NEXT(farg)),BDY(NEXT(parg)));
                    612:                                        if ( !body ) return 0;
                    613:                                        return merge_matching_node(head,body);
                    614:                                } else
                    615:                                        return 0;
                    616:                        case I_BOP:
1.55    ! noro      617:                        case I_FUNC:
1.53      noro      618:                                /* X+Y = ... */
1.55    ! noro      619:                                /* f(...) = ... */
1.53      noro      620:                                if ( compqa(CO,BDY(farg),BDY(parg)) ) return 0;
                    621:                                return quote_unify_node(NEXT(farg),NEXT(parg));
1.55    ! noro      622:                                break;
1.53      noro      623:                        default:
                    624:                                if ( pid == id )
                    625:                                        return quote_unify_node(farg,parg);
                    626:                                else
                    627:                                        return 0;
                    628:                }
                    629:        }
1.13      noro      630: }
                    631:
1.14      noro      632: void Pquotetotex(NODE arg,STRING *rp)
1.13      noro      633: {
1.14      noro      634:        TB tb;
1.13      noro      635:
1.14      noro      636:        NEWTB(tb);
1.27      noro      637:        /* XXX for DP */
                    638:        is_lt = 1;
1.14      noro      639:        fnodetotex_tb(BDY((QUOTE)ARG0(arg)),tb);
                    640:        tb_to_string(tb,rp);
1.13      noro      641: }
                    642:
1.14      noro      643: void Pquotetotex_tb(NODE arg,Q *rp)
1.13      noro      644: {
                    645:        int i;
1.14      noro      646:        TB tb;
1.13      noro      647:
1.14      noro      648:        asir_assert(ARG1(arg),O_TB,"quotetotex_tb");
1.27      noro      649:        /* XXX for DP */
                    650:        is_lt = 1;
1.14      noro      651:        fnodetotex_tb(BDY((QUOTE)ARG0(arg)),ARG1(arg));
1.13      noro      652:        *rp = 0;
                    653: }
                    654:
1.14      noro      655: void Pstring_to_tb(NODE arg,TB *rp)
                    656: {
                    657:        TB tb;
                    658:
                    659:        asir_assert(ARG0(arg),O_STR,"string_to_tb");
                    660:        NEWTB(tb);
                    661:        tb->body[0] = BDY((STRING)ARG0(arg));
                    662:        tb->next++;
                    663:        *rp = tb;
                    664: }
                    665:
                    666: void Ptb_to_string(NODE arg,STRING *rp)
                    667: {
                    668:        TB tb;
                    669:
                    670:        asir_assert(ARG0(arg),O_TB,"tb_to_string");
                    671:        tb = (TB)ARG0(arg);
                    672:        tb_to_string(tb,rp);
                    673: }
                    674:
                    675: void tb_to_string(TB tb,STRING *rp)
1.13      noro      676: {
1.14      noro      677:        int j,len;
1.13      noro      678:        char *all,*p,*q;
                    679:
1.14      noro      680:        for ( j = 0, len = 0; j < tb->next; j++ )
                    681:                len += strlen(tb->body[j]);
                    682:        all = (char *)MALLOC_ATOMIC((len+1)*sizeof(char));
                    683:        for ( j = 0, p = all; j < tb->next; j++ )
                    684:                for ( q = tb->body[j]; *q; *p++ = *q++ );
                    685:        *p = 0;
                    686:        MKSTR(*rp,all);
                    687: }
                    688:
                    689: void Pclear_tb(NODE arg,Q *rp)
                    690: {
                    691:        TB tb;
                    692:        int j;
                    693:
                    694:        asir_assert(ARG0(arg),O_TB,"clear_tb");
                    695:        tb = (TB)ARG0(arg);
                    696:        for ( j = 0; j < tb->next; j++ )
                    697:                tb->body[j] = 0;
                    698:        tb->next = 0;
                    699:        *rp = 0;
1.13      noro      700: }
1.5       noro      701:
                    702: void Pstr_len(arg,rp)
                    703: NODE arg;
                    704: Q *rp;
                    705: {
1.16      noro      706:        Obj obj;
                    707:        TB tb;
                    708:        int r,i;
1.5       noro      709:
1.16      noro      710:        obj = (Obj)ARG0(arg);
                    711:        if ( !obj || (OID(obj) != O_STR && OID(obj) != O_TB) )
                    712:                error("str_len : invalid argument");
                    713:        if ( OID(obj) == O_STR)
                    714:                r = strlen(BDY((STRING)obj));
                    715:        else if ( OID(obj) == O_TB ) {
                    716:                tb = (TB)obj;
                    717:                for ( r = i = 0; i < tb->next; i++ )
                    718:                        r += strlen(tb->body[i]);
                    719:        }
1.5       noro      720:        STOQ(r,*rp);
                    721: }
                    722:
                    723: void Pstr_chr(arg,rp)
                    724: NODE arg;
                    725: Q *rp;
                    726: {
                    727:        STRING str,terminator;
                    728:        Q start;
                    729:        char *p,*ind;
                    730:        int chr,spos,r;
                    731:
                    732:        str = (STRING)ARG0(arg);
                    733:        start = (Q)ARG1(arg);
                    734:        terminator = (STRING)ARG2(arg);
                    735:        asir_assert(str,O_STR,"str_chr");
                    736:        asir_assert(start,O_N,"str_chr");
                    737:        asir_assert(terminator,O_STR,"str_chr");
                    738:        p = BDY(str);
                    739:        spos = QTOS(start);
                    740:        chr = BDY(terminator)[0];
1.8       noro      741:        if ( spos > (int)strlen(p) )
1.5       noro      742:                r = -1;
                    743:        else {
                    744:                ind = strchr(p+spos,chr);
                    745:                if ( ind )
                    746:                        r = ind-p;
                    747:                else
                    748:                        r = -1;
                    749:        }
                    750:        STOQ(r,*rp);
                    751: }
                    752:
                    753: void Psub_str(arg,rp)
                    754: NODE arg;
                    755: STRING *rp;
                    756: {
                    757:        STRING str;
                    758:        Q head,tail;
                    759:        char *p,*r;
                    760:        int spos,epos,len;
                    761:
                    762:        str = (STRING)ARG0(arg);
                    763:        head = (Q)ARG1(arg);
                    764:        tail = (Q)ARG2(arg);
                    765:        asir_assert(str,O_STR,"sub_str");
                    766:        asir_assert(head,O_N,"sub_str");
                    767:        asir_assert(tail,O_N,"sub_str");
                    768:        p = BDY(str);
                    769:        spos = QTOS(head);
                    770:        epos = QTOS(tail);
                    771:        len = strlen(p);
                    772:        if ( (spos >= len) || (epos < spos) ) {
                    773:                *rp = 0; return;
                    774:        }
                    775:        if ( epos >= len )
                    776:                epos = len-1;
                    777:        len = epos-spos+1;
                    778:        r = (char *)MALLOC(len+1);
                    779:        strncpy(r,p+spos,len);
                    780:        r[len] = 0;
                    781:        MKSTR(*rp,r);
                    782: }
1.3       noro      783:
                    784: void Pstrtoascii(arg,rp)
                    785: NODE arg;
                    786: LIST *rp;
                    787: {
                    788:        STRING str;
                    789:        unsigned char *p;
                    790:        int len,i;
                    791:        NODE n,n1;
                    792:        Q q;
                    793:
                    794:        str = (STRING)ARG0(arg);
                    795:        asir_assert(str,O_STR,"strtoascii");
                    796:        p = BDY(str);
                    797:        len = strlen(p);
                    798:        for ( i = len-1, n = 0; i >= 0; i-- ) {
                    799:                UTOQ((unsigned int)p[i],q);
                    800:                MKNODE(n1,q,n);
                    801:                n = n1;
                    802:        }
                    803:        MKLIST(*rp,n);
                    804: }
                    805:
                    806: void Pasciitostr(arg,rp)
                    807: NODE arg;
                    808: STRING *rp;
                    809: {
                    810:        LIST list;
                    811:        unsigned char *p;
                    812:        int len,i,j;
                    813:        NODE n;
                    814:        Q q;
                    815:
                    816:        list = (LIST)ARG0(arg);
                    817:        asir_assert(list,O_LIST,"asciitostr");
                    818:        n = BDY(list);
                    819:        len = length(n);
                    820:        p = MALLOC_ATOMIC(len+1);
                    821:        for ( i = 0; i < len; i++, n = NEXT(n) ) {
                    822:                q = (Q)BDY(n);
                    823:                asir_assert(q,O_N,"asciitostr");
                    824:                j = QTOS(q);
1.4       noro      825:                if ( j >= 256 || j <= 0 )
1.3       noro      826:                        error("asciitostr : argument out of range");
                    827:                p[i] = j;
                    828:        }
                    829:        p[i] = 0;
                    830:        MKSTR(*rp,(char *)p);
                    831: }
1.1       noro      832:
                    833: void Peval_str(arg,rp)
                    834: NODE arg;
                    835: Obj *rp;
                    836: {
                    837:        FNODE fnode;
                    838:        char *cmd;
1.10      ohara     839: #if defined(PARI)
1.8       noro      840:        void recover(int);
                    841:
1.1       noro      842:        recover(0);
1.11      saito     843: #  if !(PARI_VERSION_CODE > 131588)
1.1       noro      844:        if ( setjmp(environnement) ) {
                    845:                avma = top; recover(1);
                    846:                resetenv("");
                    847:        }
1.11      saito     848: #  endif
1.1       noro      849: #endif
                    850:        cmd = BDY((STRING)ARG0(arg));
1.9       noro      851:        exprparse_create_var(0,cmd,&fnode);
1.1       noro      852:        *rp = eval(fnode);
                    853: }
                    854:
                    855: void Prtostr(arg,rp)
                    856: NODE arg;
                    857: STRING *rp;
                    858: {
                    859:        char *b;
                    860:        int len;
                    861:
1.2       noro      862:        len = estimate_length(CO,ARG0(arg));
1.12      noro      863:        b = (char *)MALLOC_ATOMIC(len+1);
1.1       noro      864:        soutput_init(b);
                    865:        sprintexpr(CO,ARG0(arg));
                    866:        MKSTR(*rp,b);
                    867: }
                    868:
                    869: void Pstrtov(arg,rp)
                    870: NODE arg;
                    871: P *rp;
                    872: {
1.8       noro      873:        char *p;
1.1       noro      874:
                    875:        p = BDY((STRING)ARG0(arg));
                    876: #if 0
                    877:        if ( !islower(*p) )
                    878:                *rp = 0;
                    879:        else {
                    880:                for ( t = p+1; t && (isalnum(*t) || *t == '_'); t++ );
                    881:                if ( *t )
                    882:                        *rp = 0;
                    883:                else
                    884:                        makevar(p,rp);
                    885:        }
                    886: #else
                    887:        makevar(p,rp);
                    888: #endif
1.14      noro      889: }
                    890:
1.15      noro      891: static struct TeXSymbol texsymbol[] = {
                    892:  {"sin","\\sin"},
                    893:  {"cos","\\cos"},
                    894:  {"tan","\\tan"},
                    895:  {"sinh","\\sinh"},
                    896:  {"cosh","\\cosh"},
                    897:  {"tanh","\\tanh"},
                    898:  {"exp","\\exp"},
                    899:  {"log","\\log"},
                    900:
                    901: /* Greek Letters (lower case) */
                    902:  {"alpha","\\alpha"},
                    903:  {"beta","\\beta"},
                    904:  {"gamma","\\gamma"},
                    905:  {"delta","\\delta"},
                    906:  {"epsilon","\\epsilon"},
                    907:  {"varepsilon","\\varepsilon"},
                    908:  {"zeta","\\zeta"},
                    909:  {"eta","\\eta"},
                    910:  {"theta","\\theta"},
                    911:  {"vartheta","\\vartheta"},
                    912:  {"iota","\\iota"},
                    913:  {"kappa","\\kappa"},
                    914:  {"lambda","\\lambda"},
                    915:  {"mu","\\mu"},
                    916:  {"nu","\\nu"},
                    917:  {"xi","\\xi"},
                    918:  {"pi","\\pi"},
                    919:  {"varpi","\\varpi"},
                    920:  {"rho","\\rho"},
                    921:  {"sigma","\\sigma"},
                    922:  {"varsigma","\\varsigma"},
                    923:  {"tau","\\tau"},
                    924:  {"upsilon","\\upsilon"},
                    925:  {"phi","\\phi"},
                    926:  {"varphi","\\varphi"},
                    927:  {"chi","\\chi"},
                    928:  {"omega","\\omega"},
                    929:
                    930: /* Greek Letters, (upper case) */
                    931:  {"ggamma","\\Gamma"},
                    932:  {"ddelta","\\Delta"},
                    933:  {"ttheta","\\Theta"},
                    934:  {"llambda","\\Lambda"},
                    935:  {"xxi","\\Xi"},
                    936:  {"ppi","\\Pi"},
                    937:  {"ssigma","\\Sigma"},
                    938:  {"uupsilon","\\Upsilon"},
                    939:  {"pphi","\\Phi"},
                    940:  {"ppsi","\\Psi"},
                    941:  {"oomega","\\Omega"},
                    942:
                    943:  /* Our own mathematical functions */
                    944:  {"algebra_tensor","\\otimes"},
                    945:  {"base_where","{\\rm \\ where \\ }"},
                    946:  /* Mathematical constants */
                    947:  {"c_pi","\\pi"},
                    948:  {"c_i","\\sqrt{-1}"},
                    949:
                    950:  /* Temporary  */
                    951:  {0,0}
                    952: };
                    953:
1.14      noro      954: char *symbol_name(char *name)
                    955: {
1.15      noro      956:        int i;
                    957:
1.41      noro      958:        if ( !name || strlen(name) == 0 )
                    959:                return "";
1.38      noro      960:        if ( !(conv_flag & CONV_TABLE) )
                    961:                return name;
                    962:
1.18      noro      963:        if ( user_texsymbol )
                    964:                for ( i = 0; user_texsymbol[i].text; i++ )
                    965:                        if ( !strcmp(user_texsymbol[i].text,name) )
                    966:                                return user_texsymbol[i].symbol;
1.15      noro      967:        for ( i = 0; texsymbol[i].text; i++ )
                    968:                if ( !strcmp(texsymbol[i].text,name) )
                    969:                        return texsymbol[i].symbol;
1.41      noro      970:        return 0;
1.52      noro      971: }
                    972:
                    973: void Pget_function_name(NODE arg,STRING *rp)
                    974: {
                    975:                QUOTEARG qa;
                    976:                ARF f;
                    977:                char *opname;
                    978:
                    979:                qa = (QUOTEARG)BDY(arg);
                    980:                if ( !qa || OID(qa) != O_QUOTEARG || qa->type != A_arf )
                    981:                        *rp = 0;
                    982:                else {
                    983:                        f = (ARF)BDY(qa);
                    984:                        opname = f->name;
                    985:                        MKSTR(*rp,opname);
                    986:                }
1.14      noro      987: }
                    988:
1.51      noro      989: FNODE strip_paren(FNODE);
                    990:
1.14      noro      991: void fnodetotex_tb(FNODE f,TB tb)
                    992: {
                    993:        NODE n,t,t0;
1.38      noro      994:        char vname[BUFSIZ],prefix[BUFSIZ];
                    995:        char *opname,*vname_conv,*prefix_conv;
1.14      noro      996:        Obj obj;
1.46      noro      997:        int i,len,allzero,elen,elen2,si;
1.40      noro      998:        C cplx;
                    999:        char *r;
1.17      noro     1000:        FNODE fi,f2;
1.14      noro     1001:
                   1002:        write_tb(" ",tb);
                   1003:        if ( !f ) {
                   1004:                write_tb("0",tb);
                   1005:                return;
                   1006:        }
                   1007:        switch ( f->id ) {
                   1008:                /* unary operators */
1.23      noro     1009:                case I_NOT:
                   1010:                        write_tb("\\neg (",tb);
                   1011:                        fnodetotex_tb((FNODE)FA0(f),tb);
                   1012:                        write_tb(")",tb);
                   1013:                        break;
                   1014:                case I_PAREN:
                   1015:                        write_tb("(",tb);
                   1016:                        fnodetotex_tb((FNODE)FA0(f),tb);
                   1017:                        write_tb(")",tb);
                   1018:                        break;
                   1019:                case I_MINUS:
                   1020:                        write_tb("-",tb);
                   1021:                        fnodetotex_tb((FNODE)FA0(f),tb);
                   1022:                        break;
                   1023:
                   1024:                /* binary operators */
                   1025:                /* arg list */
                   1026:                /* I_AND, I_OR => FA0(f), FA1(f) */
                   1027:                /* otherwise   => FA1(f), FA2(f) */
                   1028:                case I_BOP:
                   1029:                        opname = ((ARF)FA0(f))->name;
                   1030:                        if ( !strcmp(opname,"+") ) {
                   1031:                                fnodetotex_tb((FNODE)FA1(f),tb);
1.35      noro     1032:                                if ( !top_is_minus((FNODE)FA2(f)) ) write_tb(opname,tb);
1.23      noro     1033:                                fnodetotex_tb((FNODE)FA2(f),tb);
                   1034:                        } else if ( !strcmp(opname,"-") ) {
                   1035:                                if ( FA1(f) ) fnodetotex_tb((FNODE)FA1(f),tb);
                   1036:                                write_tb(opname,tb);
                   1037:                                fnodetotex_tb((FNODE)FA2(f),tb);
                   1038:                        } else if ( !strcmp(opname,"*") ) {
                   1039:                                fnodetotex_tb((FNODE)FA1(f),tb);
                   1040:                                write_tb(" ",tb);
                   1041:                                /* XXX special care for DP */
                   1042:                                f2 = (FNODE)FA2(f);
                   1043:                                if ( f2->id == I_EV ) {
                   1044:                                        n = (NODE)FA0(f2);
                   1045:                                        for ( i = 0; n; n = NEXT(n), i++ ) {
                   1046:                                                fi = (FNODE)BDY(n);
                   1047:                                                if ( fi->id != I_FORMULA || FA0(fi) )
                   1048:                                                        break;
                   1049:                                        }
                   1050:                                        if ( n )
                   1051:                                                fnodetotex_tb((FNODE)FA2(f),tb);
                   1052:                                } else
                   1053:                                        fnodetotex_tb((FNODE)FA2(f),tb);
                   1054:                        } else if ( !strcmp(opname,"/") ) {
                   1055:                                write_tb("\\frac{",tb);
                   1056:                                fnodetotex_tb((FNODE)FA1(f),tb);
                   1057:                                write_tb("} {",tb);
                   1058:                                fnodetotex_tb((FNODE)FA2(f),tb);
                   1059:                                write_tb("}",tb);
                   1060:                        } else if ( !strcmp(opname,"^") ) {
                   1061:                                fnodetotex_tb((FNODE)FA1(f),tb);
                   1062:                                write_tb("^{",tb);
1.51      noro     1063:                                fnodetotex_tb(strip_paren((FNODE)FA2(f)),tb);
1.23      noro     1064:                                write_tb("} ",tb);
                   1065:                        } else if ( !strcmp(opname,"%") ) {
                   1066:                                fnodetotex_tb((FNODE)FA1(f),tb);
                   1067:                                write_tb(" {\\rm mod}\\, ",tb);
                   1068:                                fnodetotex_tb((FNODE)FA2(f),tb);
                   1069:                        } else
                   1070:                                error("invalid binary operator");
                   1071:                        break;
                   1072:
                   1073:                case I_COP:
                   1074:                        switch( (cid)FA0(f) ) {
                   1075:                                case C_EQ:
                   1076:                                        fnodetotex_tb((FNODE)FA1(f),tb);
                   1077:                                        write_tb(" = ",tb);
                   1078:                                        fnodetotex_tb((FNODE)FA2(f),tb);
                   1079:                                        break;
                   1080:                                case C_NE:
                   1081:                                        fnodetotex_tb((FNODE)FA1(f),tb);
                   1082:                                        write_tb(" \\neq ",tb);
                   1083:                                        fnodetotex_tb((FNODE)FA2(f),tb);
                   1084:                                        break;
                   1085:                                case C_GT:
                   1086:                                        fnodetotex_tb((FNODE)FA1(f),tb);
1.45      noro     1087:                                        write_tb(" > ",tb);
1.23      noro     1088:                                        fnodetotex_tb((FNODE)FA2(f),tb);
                   1089:                                        break;
                   1090:                                case C_LT:
                   1091:                                        fnodetotex_tb((FNODE)FA1(f),tb);
1.45      noro     1092:                                        write_tb(" < ",tb);
1.23      noro     1093:                                        fnodetotex_tb((FNODE)FA2(f),tb);
1.14      noro     1094:                                        break;
1.23      noro     1095:                                case C_GE:
                   1096:                                        fnodetotex_tb((FNODE)FA1(f),tb);
                   1097:                                        write_tb(" \\geq ",tb);
                   1098:                                        fnodetotex_tb((FNODE)FA2(f),tb);
1.14      noro     1099:                                        break;
1.23      noro     1100:                                case C_LE:
                   1101:                                        fnodetotex_tb((FNODE)FA1(f),tb);
                   1102:                                        write_tb(" \\leq ",tb);
                   1103:                                        fnodetotex_tb((FNODE)FA2(f),tb);
1.14      noro     1104:                                        break;
                   1105:                        }
                   1106:                        break;
                   1107:
1.23      noro     1108:                case I_LOP:
                   1109:                        switch( (lid)FA0(f) ) {
                   1110:                                case L_EQ:
                   1111:                                        fnodetotex_tb((FNODE)FA1(f),tb);
                   1112:                                        write_tb(" = ",tb);
                   1113:                                        fnodetotex_tb((FNODE)FA2(f),tb);
                   1114:                                        break;
                   1115:                                case L_NE:
                   1116:                                        fnodetotex_tb((FNODE)FA1(f),tb);
                   1117:                                        write_tb(" \\neq ",tb);
                   1118:                                        fnodetotex_tb((FNODE)FA2(f),tb);
                   1119:                                        break;
                   1120:                                case L_GT:
                   1121:                                        fnodetotex_tb((FNODE)FA1(f),tb);
1.45      noro     1122:                                        write_tb(" > ",tb);
1.23      noro     1123:                                        fnodetotex_tb((FNODE)FA2(f),tb);
                   1124:                                        break;
                   1125:                                case L_LT:
                   1126:                                        fnodetotex_tb((FNODE)FA1(f),tb);
1.45      noro     1127:                                        write_tb(" < ",tb);
1.23      noro     1128:                                        fnodetotex_tb((FNODE)FA2(f),tb);
                   1129:                                        break;
                   1130:                                case L_GE:
                   1131:                                        fnodetotex_tb((FNODE)FA1(f),tb);
                   1132:                                        write_tb(" \\geq ",tb);
                   1133:                                        fnodetotex_tb((FNODE)FA2(f),tb);
1.14      noro     1134:                                        break;
1.23      noro     1135:                                case L_LE:
                   1136:                                        fnodetotex_tb((FNODE)FA1(f),tb);
                   1137:                                        write_tb(" \\leq ",tb);
                   1138:                                        fnodetotex_tb((FNODE)FA2(f),tb);
1.14      noro     1139:                                        break;
1.23      noro     1140:                                case L_AND:
                   1141:                                        fnodetotex_tb((FNODE)FA1(f),tb);
1.14      noro     1142:                                        write_tb(" {\\rm \\ and\\ } ",tb);
1.23      noro     1143:                                        fnodetotex_tb((FNODE)FA2(f),tb);
                   1144:                                        break;
                   1145:                                case L_OR:
1.14      noro     1146:                                        fnodetotex_tb((FNODE)FA1(f),tb);
1.23      noro     1147:                                        write_tb(" {\\rm \\ or\\ } ",tb);
                   1148:                                        fnodetotex_tb((FNODE)FA2(f),tb);
1.14      noro     1149:                                        break;
1.23      noro     1150:                                case L_NOT:
                   1151:                                        /* XXX : L_NOT is a unary operator */
                   1152:                                        write_tb("\\neg (",tb);
1.14      noro     1153:                                        fnodetotex_tb((FNODE)FA1(f),tb);
1.23      noro     1154:                                        write_tb(")",tb);
                   1155:                                        return;
1.14      noro     1156:                        }
                   1157:                        break;
                   1158:
1.23      noro     1159:                case I_AND:
                   1160:                        fnodetotex_tb((FNODE)FA0(f),tb);
                   1161:                        write_tb(" {\\rm \\ and\\ } ",tb);
                   1162:                        fnodetotex_tb((FNODE)FA1(f),tb);
                   1163:                        break;
                   1164:
                   1165:                case I_OR:
                   1166:                        fnodetotex_tb((FNODE)FA0(f),tb);
                   1167:                        write_tb(" {\\rm \\ or\\ } ",tb);
                   1168:                        fnodetotex_tb((FNODE)FA1(f),tb);
                   1169:                        break;
                   1170:
1.14      noro     1171:                /* ternary operators */
                   1172:                case I_CE:
                   1173:                        error("fnodetotex_tb : not implemented yet");
                   1174:                        break;
                   1175:
                   1176:                /* lists */
                   1177:                case I_LIST:
                   1178:                        write_tb(" [ ",tb);
                   1179:                        n = (NODE)FA0(f);
                   1180:                        fnodenodetotex_tb(n,tb);
                   1181:                        write_tb("]",tb);
                   1182:                        break;
                   1183:
                   1184:                /* function */
1.23      noro     1185:                case I_FUNC:
1.40      noro     1186:                        if ( !strcmp(((FUNC)FA0(f))->name,"@pi") )
                   1187:                                write_tb("\\pi",tb);
                   1188:                        else if ( !strcmp(((FUNC)FA0(f))->name,"@e") )
                   1189:                                write_tb("e",tb);
                   1190:                        else {
                   1191:                                opname = conv_rule(((FUNC)FA0(f))->name);
                   1192:                                write_tb(opname,tb);
                   1193:                                write_tb("(",tb);
                   1194:                                fargstotex_tb(opname,FA1(f),tb);
                   1195:                                write_tb(")",tb);
                   1196:                        }
1.23      noro     1197:                        break;
                   1198:
                   1199:                /* XXX */
                   1200:                case I_CAR:
1.28      noro     1201:                        opname = conv_rule("car");
1.23      noro     1202:                        write_tb(opname,tb);
                   1203:                        write_tb("(",tb);
                   1204:                        fargstotex_tb(opname,FA0(f),tb);
                   1205:                        write_tb(")",tb);
                   1206:                        break;
                   1207:
                   1208:                case I_CDR:
1.28      noro     1209:                        opname = conv_rule("cdr");
1.23      noro     1210:                        write_tb(opname,tb);
                   1211:                        write_tb("(",tb);
                   1212:                        fargstotex_tb(opname,FA0(f),tb);
                   1213:                        write_tb(")",tb);
                   1214:                        break;
                   1215:
                   1216:                /* exponent vector */
                   1217:                case I_EV:
                   1218:                        n = (NODE)FA0(f);
1.31      noro     1219:                        if ( dp_vars_hweyl ) {
                   1220:                                elen = length(n);
                   1221:                                elen2 = elen>>1;
                   1222:                                elen = elen2<<1;
                   1223:                        }
1.23      noro     1224:                        allzero = 1;
1.27      noro     1225:                        if ( show_lt && is_lt )
                   1226:                                write_tb("\\underline{",tb);
1.23      noro     1227:                        for ( t0 = 0, i = 0; n; n = NEXT(n), i++ ) {
                   1228:                                fi = (FNODE)BDY(n);
                   1229:                                if ( fi->id == I_FORMULA && !FA0(fi) ) continue;
                   1230:                                allzero = 0;
1.38      noro     1231:                                if ( dp_vars && i < dp_vars_len ) {
                   1232:                                        strcpy(vname,dp_vars[i]);
                   1233:                                        vname_conv = conv_rule(vname);
                   1234:                                } else {
                   1235:                                        if ( dp_vars_hweyl ) {
1.44      noro     1236:                                                if ( i < elen2 ) {
1.38      noro     1237:                                                        strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x");
1.44      noro     1238:                                                        prefix_conv = conv_rule(prefix);
                   1239:                                                        vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50);
1.46      noro     1240:                                                        si = i+dp_vars_origin;
                   1241:                                                        sprintf(vname_conv,(si>=0&&si<10)?"%s_%d":"%s_{%d}",
                   1242:                                                                prefix_conv,si);
1.44      noro     1243:                                                } else if ( i < elen ) {
1.46      noro     1244:                                                        strcpy(prefix,
                   1245:                                                                dp_dvars_prefix?dp_dvars_prefix:"\\partial");
1.44      noro     1246:                                                        prefix_conv = conv_rule(prefix);
                   1247:                                                        vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50);
1.46      noro     1248:                                                        si = i+dp_dvars_origin-elen2;
                   1249:                                                        sprintf(vname_conv,(si>=0&&si<10)?"%s_%d":"%s_{%d}",
                   1250:                                                                prefix_conv,si);
1.44      noro     1251:                                                } else {
1.38      noro     1252:                                                        strcpy(prefix,"h");
1.44      noro     1253:                                                        vname_conv = conv_rule(prefix);
                   1254:                                                }
                   1255:                                        } else {
1.38      noro     1256:                                                strcpy(prefix,dp_vars_prefix?dp_vars_prefix:"x");
1.44      noro     1257:                                                prefix_conv = conv_rule(prefix);
                   1258:                                                vname_conv = (char *)ALLOCA(strlen(prefix_conv)+50);
1.46      noro     1259:                                                si = i+dp_vars_origin;
                   1260:                                                sprintf(vname_conv,(si>=0&&si<10)?"%s_%d":"%s_{%d}",
                   1261:                                                        prefix_conv,si);
1.44      noro     1262:                                        }
1.38      noro     1263:                                }
1.23      noro     1264:                                if ( fi->id == I_FORMULA && UNIQ(FA0(fi)) ) {
                   1265:                                        len = strlen(vname_conv);
                   1266:                                        opname = MALLOC_ATOMIC(len+2);
                   1267:                                        sprintf(opname,"%s ",vname_conv);
1.14      noro     1268:                                        write_tb(opname,tb);
1.23      noro     1269:                                } else {
                   1270:                                        len = strlen(vname_conv);
                   1271:                                        /* 2: ^{ */
                   1272:                                        opname = MALLOC_ATOMIC(len+1+2);
                   1273:                                        sprintf(opname,"%s^{",vname_conv);
1.14      noro     1274:                                        write_tb(opname,tb);
1.23      noro     1275:                                        fnodetotex_tb((FNODE)BDY(n),tb);
                   1276:                                        write_tb("} ",tb);
                   1277:                                }
1.14      noro     1278:                        }
1.23      noro     1279:                        /* XXX */
                   1280:                        if ( allzero )
                   1281:                                write_tb(" 1 ",tb);
1.27      noro     1282:                        if ( show_lt && is_lt ) {
                   1283:                                write_tb("}",tb);
                   1284:                                is_lt = 0;
                   1285:                        }
1.14      noro     1286:                        break;
                   1287:
1.23      noro     1288:                /* string */
1.14      noro     1289:                case I_STR:
                   1290:                        write_tb((char *)FA0(f),tb);
                   1291:                        break;
                   1292:
1.23      noro     1293:                /* internal object */
1.14      noro     1294:                case I_FORMULA:
                   1295:                        obj = (Obj)FA0(f);
1.40      noro     1296:                        if ( !obj )
1.42      noro     1297:                                write_tb("0",tb);
1.40      noro     1298:                        else if ( OID(obj) == O_N && NID(obj) == N_C ) {
                   1299:                                cplx = (C)obj;
                   1300:                                write_tb("(",tb);
                   1301:                                if ( cplx->r ) {
                   1302:                                        r = objtostr((Obj)cplx->r); write_tb(r,tb);
                   1303:                                }
                   1304:                                if ( cplx->i ) {
                   1305:                                        if ( cplx->r && compnum(0,cplx->i,0) > 0 ) {
                   1306:                                                write_tb("+",tb);
                   1307:                                                if ( !UNIQ(cplx->i) ) {
                   1308:                                                        r = objtostr((Obj)cplx->i); write_tb(r,tb);
                   1309:                                                }
                   1310:                                        } else if ( MUNIQ(cplx->i) )
                   1311:                                                write_tb("-",tb);
                   1312:                                        else if ( !UNIQ(cplx->i) ) {
                   1313:                                                r = objtostr((Obj)cplx->i); write_tb(r,tb);
                   1314:                                        }
                   1315:                                        write_tb("\\sqrt{-1}",tb);
                   1316:                                }
                   1317:                                write_tb(")",tb);
                   1318:                        } else if ( OID(obj) == O_P )
                   1319:                                write_tb(conv_rule(VR((P)obj)->name),tb);
                   1320:                        else
                   1321:                                write_tb(objtostr(obj),tb);
1.14      noro     1322:                        break;
                   1323:
1.23      noro     1324:                /* program variable */
1.14      noro     1325:                case I_PVAR:
                   1326:                        if ( FA1(f) )
                   1327:                                error("fnodetotex_tb : not implemented yet");
                   1328:                        GETPVNAME(FA0(f),opname);
                   1329:                        write_tb(opname,tb);
                   1330:                        break;
                   1331:
                   1332:                default:
                   1333:                        error("fnodetotex_tb : not implemented yet");
                   1334:        }
1.40      noro     1335: }
                   1336:
                   1337: char *objtostr(Obj obj)
                   1338: {
                   1339:        int len;
                   1340:        char *r;
                   1341:
                   1342:        len = estimate_length(CO,obj);
                   1343:        r = (char *)MALLOC_ATOMIC(len+1);
                   1344:        soutput_init(r);
                   1345:        sprintexpr(CO,obj);
                   1346:        return r;
1.50      ohara    1347: }
                   1348:
                   1349: void Psprintf(NODE arg,STRING *rp)
                   1350: {
                   1351:     STRING string;
                   1352:     char *s,*t,*r;
                   1353:     int argc,n,len;
                   1354:     NODE node;
                   1355:
                   1356:     string = (STRING)ARG0(arg);
                   1357:     asir_assert(string,O_STR,"sprintf");
                   1358:     s = BDY(string);
                   1359:     for(n = 0, t = s; *t; t++) {
                   1360:         if (*t=='%' && *(t+1)=='a') {
                   1361:             n++;
                   1362:         }
                   1363:     }
                   1364:     for(node = NEXT(arg), argc = 0, len = strlen(s); node; node = NEXT(node), argc++) {
                   1365:         len += estimate_length(CO,BDY(node));
                   1366:     }
                   1367:     if (argc < n) {
                   1368:         error("sprintf: invalid argument");
                   1369:     }
                   1370:     r = (char *)MALLOC_ATOMIC(len);
                   1371:     for(node = NEXT(arg), t = r; *s; s++) {
                   1372:         if (*s=='%' && *(s+1)=='a') {
                   1373:             strcpy(t,objtostr(BDY(node)));
                   1374:             node = NEXT(node);
                   1375:             t = strchr(t,0);
                   1376:             s++;
                   1377:         }else {
                   1378:             *t++ = *s;
                   1379:         }
                   1380:     }
                   1381:     *t = 0;
                   1382:     MKSTR(*rp,r);
1.14      noro     1383: }
                   1384:
                   1385: void fnodenodetotex_tb(NODE n,TB tb)
                   1386: {
                   1387:        for ( ; n; n = NEXT(n) ) {
1.27      noro     1388:                is_lt = 1;
1.14      noro     1389:                fnodetotex_tb((FNODE)BDY(n),tb);
                   1390:                if ( NEXT(n) ) write_tb(", ",tb);
                   1391:        }
                   1392: }
                   1393:
                   1394: void fargstotex_tb(char *name,FNODE f,TB tb)
                   1395: {
                   1396:        NODE n;
                   1397:
                   1398:        if ( !strcmp(name,"matrix") ) {
                   1399:                error("fargstotex_tb : not implemented yet");
                   1400:        } else if ( !strcmp(name,"vector") ) {
                   1401:                error("fargstotex_tb : not implemented yet");
                   1402:        } else {
                   1403:                if ( f->id == I_LIST ) {
                   1404:                        n = (NODE)FA0(f);
                   1405:                        fnodenodetotex_tb(n,tb);
                   1406:                } else
                   1407:                        fnodetotex_tb(f,tb);
1.35      noro     1408:        }
                   1409: }
                   1410:
                   1411: int top_is_minus(FNODE f)
                   1412: {
                   1413:        char *opname;
                   1414:        int len;
                   1415:        Obj obj;
                   1416:
                   1417:        if ( !f )
                   1418:                return 0;
                   1419:        switch ( f->id ) {
                   1420:                case I_MINUS:
                   1421:                        return 1;
                   1422:                case I_BOP:
                   1423:                        opname = ((ARF)FA0(f))->name;
                   1424:                        switch ( opname[0] ) {
                   1425:                                case '+': case '*': case '/': case '^': case '%':
                   1426:                                        return top_is_minus((FNODE)FA1(f));
                   1427:                                case '-':
                   1428:                                        if ( FA1(f) )
                   1429:                                                return top_is_minus((FNODE)FA1(f));
                   1430:                                        else
                   1431:                                                return 1;
                   1432:                                default:
                   1433:                                        return 0;
                   1434:                        }
                   1435:                        break;
                   1436:                case I_COP:
                   1437:                        return top_is_minus((FNODE)FA1(f));
                   1438:                case I_LOP:
                   1439:                        if ( (lid)FA0(f) == L_NOT ) return 0;
                   1440:                        else return top_is_minus((FNODE)FA1(f));
                   1441:                case I_AND: case I_OR:
                   1442:                        return top_is_minus((FNODE)FA0(f));
                   1443:                case I_FORMULA:
                   1444:                        obj = (Obj)FA0(f);
1.36      noro     1445:                        if ( !obj )
                   1446:                                return 0;
                   1447:                        else {
                   1448:                                switch ( OID(obj) ) {
                   1449:                                        case O_N:
                   1450:                                                return mmono((P)obj);
                   1451:                                        case O_P:
                   1452:                                                /* must be a variable */
                   1453:                                                opname = conv_rule(VR((P)obj)->name);
                   1454:                                                return opname[0]=='-';
                   1455:                                        default:
                   1456:                                                /* ??? */
                   1457:                                                len = estimate_length(CO,obj);
                   1458:                                                opname = (char *)MALLOC_ATOMIC(len+1);
                   1459:                                                soutput_init(opname);
                   1460:                                                sprintexpr(CO,obj);
                   1461:                                                return opname[0]=='-';
                   1462:                                }
1.35      noro     1463:                        }
                   1464:                default:
                   1465:                        return 0;
1.14      noro     1466:        }
1.47      noro     1467: }
                   1468:
                   1469: FNODE flatten_fnode(FNODE,char *);
                   1470:
1.48      noro     1471: void Pflatten_quote(NODE arg,Obj *rp)
1.47      noro     1472: {
                   1473:        FNODE f;
                   1474:        QUOTE q;
                   1475:
1.48      noro     1476:        if ( !ARG0(arg) || OID((Obj)ARG0(arg)) != O_QUOTE )
                   1477:                *rp = (Obj)ARG0(arg);
                   1478:        else {
                   1479:                f = flatten_fnode(BDY((QUOTE)ARG0(arg)),BDY((STRING)ARG1(arg)));
                   1480:                MKQUOTE(q,f);
                   1481:                *rp = (Obj)q;
                   1482:        }
                   1483: }
                   1484:
                   1485: void Pquote_to_funargs(NODE arg,LIST *rp)
                   1486: {
                   1487:        fid_spec_p spec;
                   1488:        QUOTE q;
                   1489:        QUOTEARG qa;
                   1490:        FNODE f;
                   1491:        STRING s;
                   1492:        QUOTE r;
                   1493:        int i;
                   1494:        Q id,a;
1.49      noro     1495:        LIST l;
                   1496:        NODE t0,t,w,u,u0;
1.48      noro     1497:
                   1498:        q = (QUOTE)ARG0(arg);
                   1499:        if ( !q || OID(q) != O_QUOTE )
                   1500:                error("quote_to_funargs : invalid argument");
                   1501:        f = BDY(q);
                   1502:        if ( !f ) {
                   1503:                MKLIST(*rp,0);
                   1504:                return;
                   1505:        }
                   1506:        get_fid_spec(f->id,&spec);
                   1507:        if ( !spec )
                   1508:                error("quote_to_funargs : not supported yet");
                   1509:        t0 = 0;
                   1510:        STOQ((int)f->id,id);
                   1511:        NEXTNODE(t0,t);
                   1512:        BDY(t) = (pointer)id;
                   1513:        for ( i = 0; spec->type[i] != A_end; i++ ) {
                   1514:                NEXTNODE(t0,t);
                   1515:                switch ( spec->type[i] ) {
                   1516:                        case A_fnode:
                   1517:                                MKQUOTE(r,(FNODE)f->arg[i]);
                   1518:                                BDY(t) = (pointer)r;
                   1519:                                break;
                   1520:                        case A_int:
                   1521:                                STOQ((int)f->arg[i],a);
                   1522:                                BDY(t) = (pointer)a;
                   1523:                                break;
                   1524:                        case A_str:
                   1525:                                MKSTR(s,(char *)f->arg[i]);
                   1526:                                BDY(t) = (pointer)s;
                   1527:                                break;
                   1528:                        case A_internal:
                   1529:                                BDY(t) = (pointer)f->arg[i];
                   1530:                                break;
1.49      noro     1531:                        case A_node:
                   1532:                                w = (NODE)f->arg[i];
                   1533:                                for ( u0 = 0; w; w = NEXT(w) ){
                   1534:                                        NEXTNODE(u0,u);
                   1535:                                        MKQUOTE(r,(FNODE)BDY(w));
                   1536:                                        BDY(u) = (pointer)r;
                   1537:                                }
                   1538:                                if ( u0 ) NEXT(u) = 0;
                   1539:                                MKLIST(l,u0);
                   1540:                                BDY(t) = (pointer)l;
                   1541:                                break;
1.48      noro     1542:                        default:
                   1543:                                MKQUOTEARG(qa,spec->type[i],f->arg[i]);
                   1544:                                BDY(t) = (pointer)qa;
                   1545:                                break;
                   1546:                }
                   1547:        }
                   1548:        if ( t0 ) NEXT(t) = 0;
                   1549:        MKLIST(*rp,t0);
                   1550: }
                   1551:
                   1552: void Pfunargs_to_quote(NODE arg,QUOTE *rp)
                   1553: {
                   1554:        fid_spec_p spec;
                   1555:        QUOTE q;
                   1556:        QUOTEARG qa;
                   1557:        FNODE f;
                   1558:        STRING s;
1.49      noro     1559:        QUOTE r,b;
1.48      noro     1560:        int i;
                   1561:        LIST l;
                   1562:        fid id;
                   1563:        Obj a;
1.49      noro     1564:        NODE t0,t,u0,u,w;
1.48      noro     1565:
                   1566:        l = (LIST)ARG0(arg);
                   1567:        if ( !l || OID(l) != O_LIST || !(t=BDY(l)) )
                   1568:                error("funargs_to_quote : invalid argument");
                   1569:        t = BDY(l);
                   1570:        id = (fid)QTOS((Q)BDY(t)); t = NEXT(t);
                   1571:        get_fid_spec(id,&spec);
                   1572:        if ( !spec )
                   1573:                error("funargs_to_quote : not supported yet");
                   1574:        for ( i = 0; spec->type[i] != A_end; i++ );
                   1575:        NEWFNODE(f,i);
                   1576:        f->id = id;
                   1577:        for ( i = 0; spec->type[i] != A_end; i++, t = NEXT(t) ) {
                   1578:                if ( !t )
                   1579:                        error("funargs_to_quote : argument mismatch");
                   1580:                a = (Obj)BDY(t);
                   1581:                switch ( spec->type[i] ) {
                   1582:                        case A_fnode:
                   1583:                                if ( !a || OID(a) != O_QUOTE )
                   1584:                                        error("funargs_to_quote : invalid argument");
                   1585:                                f->arg[i] = BDY((QUOTE)a);
                   1586:                                break;
                   1587:                        case A_int:
                   1588:                                if ( !INT(a) )
                   1589:                                        error("funargs_to_quote : invalid argument");
                   1590:                                f->arg[i] = (pointer)QTOS((Q)a);
                   1591:                                break;
                   1592:                        case A_str:
                   1593:                                if ( !a || OID(a) != O_STR )
                   1594:                                        error("funargs_to_quote : invalid argument");
                   1595:                                f->arg[i] = (pointer)BDY((STRING)a);
                   1596:                                break;
                   1597:                        case A_internal:
                   1598:                                f->arg[i] = (pointer)a;
1.49      noro     1599:                                break;
                   1600:                        case A_node:
                   1601:                                if ( !a || OID(a) != O_LIST )
                   1602:                                        error("funargs_to_quote : invalid argument");
                   1603:                                u0 = 0;
                   1604:                                for ( w = BDY((LIST)a); w; w = NEXT(w) ) {
                   1605:                                        NEXTNODE(u0,u);
                   1606:                                        b = (QUOTE)BDY(w);
                   1607:                                        if ( !b || OID(b) != O_QUOTE )
                   1608:                                                error("funargs_to_quote : invalid argument");
                   1609:                                        BDY(u) = BDY(b);
                   1610:                                }
                   1611:                                if ( u0 ) NEXT(u) = 0;
                   1612:                                f->arg[i] = (pointer)u0;
1.48      noro     1613:                                break;
                   1614:                        default:
                   1615:                                if ( !a || OID(a) != O_QUOTEARG ||
                   1616:                                        ((QUOTEARG)a)->type != spec->type[i] )
                   1617:                                        error("funargs_to_quote : invalid argument");
                   1618:                                f->arg[i] = BDY((QUOTEARG)a);
                   1619:                                break;
                   1620:                }
                   1621:        }
                   1622:        MKQUOTE(*rp,f);
1.1       noro     1623: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>