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

Annotation of OpenXM_contrib2/asir2000/io/cpexpr.c, Revision 1.19

1.3       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.4       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.3       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.
1.19    ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2000/io/cpexpr.c,v 1.18 2004/03/03 09:25:30 noro Exp $
1.3       noro       48: */
1.1       noro       49: #include "ca.h"
                     50: #include "parse.h"
1.2       noro       51: #include "al.h"
1.1       noro       52: #include "base.h"
1.16      noro       53: #if PARI
                     54: #include "genpari.h"
                     55: #endif
1.1       noro       56:
1.8       noro       57: extern int hex_output,fortran_output,double_output,real_digit;
1.2       noro       58:
                     59: #define PRINTHAT (fortran_output?PUTS("**"):PUTS("^"))
                     60:
1.1       noro       61: #define TAIL
                     62: #define PUTS(s) (total_length+=strlen(s))
                     63: #define PRINTN length_n
1.2       noro       64: #define PRINTBF length_bf
1.1       noro       65: #define PRINTCPLX length_cplx
1.2       noro       66: #define PRINTLM length_lm
                     67: #define PRINTUP2 length_up2
1.1       noro       68: #define PRINTV length_v
                     69: #define PRINTEXPR length_expr
                     70: #define PRINTNUM length_num
                     71: #define PRINTP length_p
                     72: #define PRINTR length_r
                     73: #define PRINTLIST length_list
                     74: #define PRINTVECT length_vect
                     75: #define PRINTMAT length_mat
                     76: #define PRINTSTR length_str
                     77: #define PRINTCOMP length_comp
                     78: #define PRINTDP length_dp
1.2       noro       79: #define PRINTUI length_ui
                     80: #define PRINTGF2MAT length_gf2mat
                     81: #define PRINTGFMMAT length_gfmmat
1.5       noro       82: #define PRINTBYTEARRAY length_bytearray
1.11      noro       83: #define PRINTQUOTE length_QUOTE
1.17      noro       84: #define PRINTSYMBOL length_SYMBOL
                     85: #define PRINTRANGE length_RANGE
1.18      noro       86: #define PRINTTB length_TB
1.2       noro       87: #define PRINTERR length_err
                     88: #define PRINTLF length_lf
                     89: #define PRINTLOP length_lop
                     90: #define PRINTFOP length_fop
                     91: #define PRINTEOP length_eop
                     92: #define PRINTQOP length_qop
                     93: #define PRINTUP length_up
1.12      noro       94: #define PRINTUM length_um
                     95: #define PRINTSF length_sf
1.19    ! noro       96: #define PRINTFARGS length_fargs
        !            97: #define PRINTFNODENODE length_fnodenode
        !            98: #define PRINTFNODE length_fnode
1.1       noro       99:
                    100: void PRINTEXPR();
                    101: void PRINTNUM();
1.2       noro      102: void PRINTN();
1.1       noro      103: void PRINTV();
                    104: void PRINTP();
                    105: void PRINTR();
                    106: void PRINTLIST();
                    107: void PRINTVECT();
                    108: void PRINTMAT();
                    109: void PRINTSTR();
                    110: void PRINTCOMP();
                    111: void PRINTDP();
1.2       noro      112: void PRINTUI();
                    113: void PRINTGF2MAT();
                    114: void PRINTGFMMAT();
1.5       noro      115: void PRINTBYTEARRAY();
1.11      noro      116: void PRINTQUOTE();
1.17      noro      117: void PRINTSYMBOL();
                    118: void PRINTRANGE();
1.18      noro      119: void PRINTTB();
1.2       noro      120: void PRINTERR();
1.1       noro      121: void PRINTCPLX();
1.2       noro      122: void PRINTLM();
                    123: void PRINTLF();
1.13      noro      124: void PRINTUP();
                    125: void PRINTUM();
1.2       noro      126: void PRINTUP2();
1.13      noro      127: void PRINTFOP();
                    128: void PRINTEOP();
                    129: void PRINTLOP();
                    130: void PRINTQOP();
                    131: void PRINTSF();
1.19    ! noro      132: void PRINTFNODE();
1.1       noro      133:
                    134: static int total_length;
                    135:
1.13      noro      136: int estimate_length(VL vl,pointer p)
1.1       noro      137: {
                    138:        total_length = 0;
                    139:        PRINTEXPR(vl,p);
                    140:        return total_length;
                    141: }
                    142:
1.15      ohara     143: #if defined(PARI)
1.13      noro      144: void PRINTBF(BF a)
1.2       noro      145: {
                    146:        char *str;
1.7       noro      147:        char *GENtostr0();
                    148:        void myoutbrute();
1.2       noro      149:
1.7       noro      150:        if ( double_output ) {
                    151:                str = GENtostr0(a->body,myoutbrute);
                    152:        } else {
                    153:                str = GENtostr(a->body);
                    154:        }
1.2       noro      155:        total_length += strlen(str);
                    156:        free(str);
                    157: }
                    158: #endif
                    159:
1.13      noro      160: void PRINTEXPR(VL vl,pointer p)
1.1       noro      161: {
                    162:        if ( !p ) {
                    163:                total_length++;
                    164:                return;
                    165:        }
                    166:
                    167:        switch ( OID(p) ) {
                    168:                case O_N:
                    169:                        PRINTNUM((Num)p); break;
                    170:                case O_P:
                    171:                        PRINTP(vl,(P)p); break;
                    172:                case O_R:
                    173:                        PRINTR(vl,(R)p); break;
                    174:                case O_LIST:
                    175:                        PRINTLIST(vl,(LIST)p); break;
                    176:                case O_VECT:
                    177:                        PRINTVECT(vl,(VECT)p); break;
                    178:                case O_MAT:
                    179:                        PRINTMAT(vl,(MAT)p); break;
                    180:                case O_STR:
                    181:                        PRINTSTR((STRING)p); break;
                    182:                case O_COMP:
                    183:                        PRINTCOMP(vl,(COMP)p); break;
                    184:                case O_DP:
                    185:                        PRINTDP(vl,(DP)p); break;
1.2       noro      186:                case O_USINT:
                    187:                        PRINTUI(vl,(USINT)p); break;
                    188:                case O_GF2MAT:
                    189:                        PRINTGF2MAT(vl,(GF2MAT)p); break;
                    190:                case O_ERR:
                    191:                        PRINTERR(vl,(ERR)p); break;
                    192:                case O_MATHCAP:
                    193:                        PRINTLIST(vl,((MATHCAP)p)->body); break;
                    194:                case O_F:
                    195:                        PRINTLF(vl,(F)p); break;
                    196:                case O_GFMMAT:
                    197:                        PRINTGFMMAT(vl,(GFMMAT)p); break;
1.5       noro      198:                case O_BYTEARRAY:
                    199:                        PRINTBYTEARRAY(vl,(BYTEARRAY)p); break;
1.11      noro      200:                case O_QUOTE:
                    201:                        PRINTQUOTE(vl,(QUOTE)p); break;
1.17      noro      202:                case O_SYMBOL:
                    203:                        PRINTSYMBOL((SYMBOL)p); break;
                    204:                case O_RANGE:
                    205:                        PRINTRANGE(vl,(RANGE)p); break;
1.18      noro      206:                case O_TB:
                    207:                        PRINTTB(vl,(TB)p); break;
1.1       noro      208:                default:
                    209:                        break;
                    210:        }
                    211: }
                    212:
1.13      noro      213: void PRINTN(N n)
1.1       noro      214: {
                    215:        double ceil();
                    216:
                    217:        if ( !n )
                    218:                PUTS("0");
1.2       noro      219:        else if ( hex_output )
                    220:                total_length += 2+(int)(PL(n)*8);
1.1       noro      221:        else
                    222:                total_length += (int)(ceil(0.31*((double)(BSH*PL(n))))+1);
                    223: }
                    224:
1.13      noro      225: void PRINTNUM(Num q)
1.1       noro      226: {
                    227:        if ( !q ) {
                    228:                PUTS("0");
                    229:                return;
                    230:        }
                    231:        switch ( NID(q) ) {
                    232:                case N_Q:
                    233:                        if ( SGN((Q)q) == -1 )
                    234:                                PUTS("-");
                    235:                        PRINTN(NM((Q)q));
                    236:                        if ( !INT((Q)q) ) {
                    237:                                PUTS("/"); PRINTN(DN((Q)q));
                    238:                        }
                    239:                        break;
                    240:                case N_R:
1.7       noro      241:                        if ( double_output )
1.8       noro      242:                                total_length += 400+real_digit; /* XXX */
1.7       noro      243:                        else
1.8       noro      244:                                total_length += 20+real_digit; /* XXX */
1.1       noro      245:                        break;
                    246:                case N_A:
                    247:                        PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")");
                    248:                        break;
1.15      ohara     249: #if defined(PARI)
1.1       noro      250:                case N_B:
                    251:                        PRINTBF((BF)q); break;
                    252: #endif
                    253:                case N_C:
                    254:                        PRINTCPLX((C)q); break;
                    255:                case N_M:
1.2       noro      256:                        total_length += 11; /* XXX */
                    257:                        break;
                    258:                case N_LM:
                    259:                        PRINTN(((LM)q)->body); break;
                    260:                case N_GF2N:
                    261:                        if ( hex_output )
                    262:                                PRINTN((N)(((GF2N)q)->body));
                    263:                        else
                    264:                                PRINTUP2(((GF2N)q)->body);
                    265:                        break;
                    266:                case N_GFPN:
                    267:                        PRINTUP((UP)(((GFPN)q)->body));
1.9       noro      268:                        break;
                    269:                case N_GFS:
1.10      noro      270:                        total_length += 13; /* XXX */
1.2       noro      271:                        break;
1.12      noro      272:                case N_GFSN:
                    273:                        PRINTUM(BDY((GFSN)q));
                    274:                        break;
1.2       noro      275:                default:
1.1       noro      276:                        break;
                    277:        }
                    278: }
                    279:
1.13      noro      280: void PRINTCPLX(C a)
1.1       noro      281: {
                    282:        PUTS("(");
                    283:        if ( a->r )
                    284:                PRINTNUM(a->r);
                    285:        if ( a->i ) {
                    286:                if ( a->r && (compnum(0,a->i,0) > 0) )
                    287:                        PUTS("+");
                    288:                PRINTNUM(a->i); PUTS("*@i");
                    289:        }
                    290:        PUTS(")");
                    291: }
                    292:
1.13      noro      293: void PRINTP(VL vl,P p)
1.1       noro      294: {
                    295:        V v;
                    296:        DCP dc;
                    297:
                    298:        if ( !p )
                    299:                PUTS("0");
                    300:        else if ( NUM(p) )
                    301:                PRINTNUM((Num)p);
                    302:        else
                    303:                for ( dc = DC(p), v = VR(p); dc; dc = NEXT(dc) ) {
                    304:                        if ( !DEG(dc) )
                    305:                                PRINTP(vl,COEF(dc));
                    306:                        else {
                    307:                                if ( NUM(COEF(dc)) && UNIQ((Q)COEF(dc)) ) {
                    308:                                        ;
                    309:                                } else if ( NUM(COEF(dc)) && MUNIQ((Q)COEF(dc)) )
                    310:                                        PUTS("-");
                    311:                                else if ( NUM(COEF(dc)) || !NEXT(DC(COEF(dc)))) {
                    312:                                        PRINTP(vl,COEF(dc)); PUTS("*");
                    313:                                } else {
                    314:                                        PUTS("("); PRINTP(vl,COEF(dc)); PUTS(")*");
                    315:                                }
                    316:                                PRINTV(vl,v);
                    317:                                if ( cmpq(DEG(dc),ONE) ) {
1.2       noro      318:                                        PRINTHAT;
1.1       noro      319:                                        if ( INT(DEG(dc)) && SGN(DEG(dc))>0 )
                    320:                                                PRINTNUM((Num)DEG(dc));
                    321:                                        else {
                    322:                                                PUTS("("); PRINTNUM((Num)DEG(dc)); PUTS(")");
                    323:                                        }
                    324:                                }
                    325:                        }
                    326:                        if ( NEXT(dc) ) {
                    327:                                P t;
                    328:
                    329:                                t = COEF(NEXT(dc));
                    330:                                if (!DEG(NEXT(dc))) {
                    331:                                        if ( NUM(t) ) {
                    332:                                                if ( !mmono(t) )
                    333:                                                        PUTS("+");
                    334:                                        } else {
                    335:                                                if (!mmono(COEF(DC(t))))
                    336:                                                        PUTS("+");
                    337:                                        }
                    338:                                } else {
                    339:                                        if ( !mmono(t) )
                    340:                                                PUTS("+");
                    341:                                }
                    342:                        }
                    343:                }
                    344: }
                    345:
1.2       noro      346: extern int hideargs;
                    347:
1.13      noro      348: void PRINTV(VL vl,V v)
1.1       noro      349: {
                    350:        PF pf;
                    351:        PFAD ad;
                    352:        int i;
                    353:
                    354:        if ( NAME(v) )
                    355:                PUTS(NAME(v));
                    356:        else if ( (vid)v->attr == V_PF ) {
                    357:                pf = ((PFINS)v->priv)->pf; ad = ((PFINS)v->priv)->ad;
                    358:                if ( !strcmp(NAME(pf),"pow") ) {
1.14      noro      359:                        PUTS("(("); PRINTR(vl,(R)ad[0].arg); PUTS(")"); PRINTHAT; PUTS("(");
                    360:                        PRINTR(vl,(R)ad[1].arg); PUTS("))");
1.1       noro      361:                } else if ( !pf->argc )
                    362:                        PUTS(NAME(pf));
                    363:                else {
1.2       noro      364:                        if ( hideargs ) {
                    365:                                for ( i = 0; i < pf->argc; i++ )
                    366:                                        if ( ad[i].d )
                    367:                                                break;
                    368:                                if ( i < pf->argc ) {
                    369:                                        PUTS(NAME(pf));
1.1       noro      370:                                        total_length += 11; /* XXX */
1.2       noro      371:                                        for ( i = 1; i < pf->argc; i++ ) {
                    372:                                                total_length += 11; /* XXX */
                    373:                                        }
                    374:                                        PUTS("}");
                    375:                                } else {
                    376:                                        PUTS(NAME(pf));
                    377:                                        total_length += 1; /* XXX */
1.1       noro      378:                                }
                    379:                        } else {
1.2       noro      380:                                for ( i = 0; i < pf->argc; i++ )
                    381:                                        if ( ad[i].d )
                    382:                                                break;
                    383:                                if ( i < pf->argc ) {
                    384:                                        PUTS(NAME(pf));
                    385:                                        total_length += 11; /* XXX */
                    386:                                        for ( i = 1; i < pf->argc; i++ ) {
                    387:                                                total_length += 11; /* XXX */
                    388:                                        }
                    389:                                        PUTS(")(");
                    390:                                } else {
                    391:                                        PUTS(NAME(pf));
                    392:                                        total_length += 1; /* XXX */
                    393:                                }
                    394:                                PRINTR(vl,(R)ad[0].arg);
                    395:                                for ( i = 1; i < pf->argc; i++ ) {
                    396:                                        PUTS(","); PRINTR(vl,(R)ad[i].arg);
                    397:                                }
                    398:                                PUTS(")");
1.1       noro      399:                        }
                    400:                }
                    401:        }
                    402: }
                    403:
1.13      noro      404: void PRINTR(VL vl,R a)
1.1       noro      405: {
                    406:        if ( !a )
                    407:                PUTS("0");
                    408:        else
                    409:                switch (OID(a)) {
                    410:                        case O_N: case O_P:
                    411:                                PRINTP(vl,(P)a); break;
                    412:                        default:
                    413:                                PUTS("("); PRINTP(vl,NM((R)a)); PUTS(")/("); PRINTP(vl,DN((R)a)); PUTS(")");
                    414:                                break;
                    415:                }
                    416: }
                    417:
1.13      noro      418: void PRINTVECT(VL vl,VECT vect)
1.1       noro      419: {
                    420:        int i;
                    421:        pointer *ptr;
                    422:
                    423:        PUTS("[ ");
                    424:        for ( i = 0, ptr = BDY(vect); i < vect->len; i++ ) {
                    425:                PRINTEXPR(vl,ptr[i]); PUTS(" ");
                    426:        }
                    427:        PUTS("]");
                    428: }
                    429:
1.13      noro      430: void PRINTMAT(VL vl,MAT mat)
1.1       noro      431: {
                    432:        int i,j,r,c;
                    433:        pointer *ptr;
                    434:
                    435:        for ( i = 0, r = mat->row, c = mat->col; i < r; i++ ) {
                    436:                PUTS("[ ");
                    437:                for ( j = 0, ptr = BDY(mat)[i]; j < c; j++ ) {
                    438:                        PRINTEXPR(vl,ptr[j]); PUTS(" ");
                    439:                }
                    440:                PUTS("]");
                    441:                if ( i < r - 1 )
                    442:                        PUTS("\n");
                    443:        }
                    444: }
                    445:
1.13      noro      446: void PRINTLIST(VL vl,LIST list)
1.1       noro      447: {
                    448:        NODE tnode;
                    449:
                    450:        PUTS("[");
                    451:        for ( tnode = (NODE)list->body; tnode; tnode = NEXT(tnode) ) {
                    452:                PRINTEXPR(vl,tnode->body);
                    453:                if ( NEXT(tnode) )
                    454:                        PUTS(",");
                    455:        }
                    456:        PUTS("]");
                    457: }
                    458:
1.13      noro      459: void PRINTSTR(STRING str)
1.1       noro      460: {
                    461:        char *p;
                    462:
                    463:        for ( p = BDY(str); *p; p++ )
                    464:                if ( *p == '"' )
                    465:                        PUTS("\"");
                    466:                else {
                    467:                        total_length += 1;
                    468:                }
                    469: }
                    470:
1.13      noro      471: void PRINTCOMP(VL vl,COMP c)
1.1       noro      472: {
                    473:        int n,i;
                    474:
                    475:        n = getcompsize((int)c->type);
                    476:        PUTS("{");
                    477:        for ( i = 0; i < n; i++ ) {
                    478:                PRINTEXPR(vl,(pointer)c->member[i]);
                    479:                if ( i < n-1 )
                    480:                        PUTS(",");
                    481:        }
                    482:        PUTS("}");
                    483: }
                    484:
1.13      noro      485: void PRINTDP(VL vl,DP d)
1.1       noro      486: {
                    487:        int n,i;
                    488:        MP m;
                    489:        DL dl;
                    490:
                    491:        for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {
                    492:                PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");
                    493:                for ( i = 0, dl = m->dl; i < n-1; i++ ) {
                    494:                        total_length += 11;
                    495:                }
                    496:                total_length += 10;
                    497:                PUTS(">>");
                    498:                if ( NEXT(m) )
                    499:                        PUTS("+");
1.2       noro      500:        }
                    501: }
                    502:
1.13      noro      503: void PRINTUI(VL vl,USINT u)
1.2       noro      504: {
                    505:        total_length += 10;
                    506: }
                    507:
1.13      noro      508: void PRINTGF2MAT(VL vl,GF2MAT mat)
1.2       noro      509: {
                    510:        int row,col,w,i,j,k,m;
                    511:        unsigned int t;
                    512:        unsigned int **b;
                    513:
                    514:        row = mat->row;
                    515:        col = mat->col;
                    516:        w = (col+BSH-1)/BSH;
                    517:        b = mat->body;
                    518:        for ( i = 0; i < row; i++ ) {
                    519:                for ( j = 0, m = 0; j < w; j++ ) {
                    520:                        t = b[i][j];
                    521:                        for ( k = 0; m < col && k < BSH; k++, m++ )
                    522:                                if ( t & (1<<k) )
                    523:                                        PUTS("1");
                    524:                                else
                    525:                                        PUTS("0");
                    526:                }
                    527:                PUTS("\n");
                    528:        }
                    529: }
                    530:
1.13      noro      531: void PRINTGFMMAT(VL vl,GFMMAT mat)
1.2       noro      532: {
                    533:        int row,col,i,j;
                    534:        unsigned int **b;
                    535:
                    536:        row = mat->row;
                    537:        col = mat->col;
                    538:        b = mat->body;
                    539:        for ( i = 0; i < row; i++ ) {
                    540:                PUTS("[");
                    541:                for ( j = 0; j < col; j++ ) {
                    542:                        total_length += 10; /* XXX */
                    543:                }
                    544:                PUTS("]\n");
                    545:        }
1.5       noro      546: }
                    547:
1.13      noro      548: void PRINTBYTEARRAY(VL vl,BYTEARRAY array)
1.5       noro      549: {
                    550:        /* |xx xx ... xx| */
1.6       noro      551:        total_length += 1+3*array->len;
1.11      noro      552: }
                    553:
1.19    ! noro      554: extern int print_quote;
        !           555:
1.13      noro      556: void PRINTQUOTE(VL vl,QUOTE quote)
1.11      noro      557: {
1.19    ! noro      558:        LIST list;
        !           559:
        !           560:        if ( print_quote == 2 ) {
        !           561:                PRINTFNODE(BDY(quote));
        !           562:        } else if ( print_quote == 1 ) {
        !           563:                /* XXX */
        !           564:                fnodetotree(BDY(quote),&list);
        !           565:                PRINTEXPR(vl,(Obj)list);
        !           566:        } else {
        !           567:                /* <...quoted...> */
        !           568:                total_length += 20;
        !           569:        }
1.17      noro      570: }
                    571:
                    572: void PRINTSYMBOL(SYMBOL sym)
                    573: {
                    574:        total_length += strlen(sym->name);
                    575: }
                    576:
                    577: void PRINTRANGE(VL vl,RANGE r)
                    578: {
                    579:        PUTS("range("); PRINTEXPR(vl,r->start);
                    580:        PUTS(","); PRINTEXPR(vl,r->end); PUTS(")");
1.18      noro      581: }
                    582:
                    583: void PRINTTB(VL vl,TB p)
                    584: {
                    585:        int i;
                    586:
                    587:        for ( i = 0; i < p->next; i++ ) {
                    588:                total_length += strlen(p->body[i]);
                    589:        }
1.2       noro      590: }
                    591:
1.13      noro      592: void PRINTERR(VL vl,ERR e)
1.2       noro      593: {
                    594:        PUTS("error("); PRINTEXPR(vl,e->body); PUTS(")");
                    595: }
                    596:
1.13      noro      597: void PRINTUP2(UP2 p)
1.2       noro      598: {
                    599:        int d,i;
                    600:
                    601:        if ( !p ) {
                    602:                PUTS("0");
                    603:        } else {
                    604:                d = degup2(p);
                    605:                PUTS("(");
                    606:                if ( !d ) {
                    607:                        PUTS("1");
                    608:                } else if ( d == 1 ) {
                    609:                        PUTS("@");
                    610:                } else {
                    611:                        PRINTHAT;
                    612:                        total_length += 11;
                    613:                }
                    614:                for ( i = d-1; i >= 0; i-- ) {
                    615:                        if ( p->b[i/BSH] & (1<<(i%BSH)) )
                    616:                                if ( !i ) {
                    617:                                        PUTS("+1");
                    618:                                } else if ( i == 1 ) {
                    619:                                        PUTS("+@");
                    620:                                } else {
                    621:                                        PRINTHAT;
                    622:                                        total_length += 12;
                    623:                                }
                    624:                }
                    625:                PUTS(")");
                    626:        }
                    627: }
                    628:
1.13      noro      629: void PRINTLF(VL vl,F f)
1.2       noro      630: {
                    631:        switch ( FOP(f) ) {
                    632:                case AL_TRUE:
                    633:                        PUTS("@true");
                    634:                        break;
                    635:                case AL_FALSE:
                    636:                        PUTS("@false");
                    637:                        break;
                    638:
                    639:                case AL_OR: case AL_AND:
                    640:                        PRINTFOP(vl,f); break;
                    641:                case AL_NOT: case AL_IMPL: case AL_REPL: case AL_EQUIV:
                    642:                        PRINTEOP(vl,f); break;
                    643:
                    644:                case AL_EQUAL: case AL_NEQ: case AL_LESSP:
                    645:                case AL_GREATERP: case AL_LEQ: case AL_GEQ:
                    646:                        PRINTLOP(vl,f); break;
                    647:
                    648:                case AL_EX: case AL_ALL:
                    649:                        PRINTQOP(vl,f); break;
                    650:                default:
                    651:                        break;
                    652:        }
                    653: }
                    654:
1.13      noro      655: void PRINTFOP(VL vl,F f)
1.2       noro      656: {
                    657:        char *op;
                    658:        NODE n;
                    659:
                    660:        op = FOP(f)==AL_OR?" @|| ":" @&& ";
                    661:        n = FJARG(f);
                    662:        PUTS("("); PRINTEXPR(vl,BDY(n)); PUTS(")");
                    663:        for ( n = NEXT(n); n; n = NEXT(n) ) {
                    664:                PUTS(op); PUTS("("); PRINTEXPR(vl,BDY(n)); PUTS(")");
                    665:        }
                    666: }
                    667:
1.13      noro      668: void PRINTEOP(VL vl,F f)
1.2       noro      669: {
                    670:        oFOP op;
                    671:        char *sop;
                    672:
                    673:        if ( (op = FOP(f)) == AL_NOT ) {
                    674:                PUTS("(@! "); PRINTEXPR(vl,(Obj)FARG(f)); PUTS(")"); return;
                    675:        }
                    676:        switch ( op ) {
                    677:                case AL_IMPL:
                    678:                        sop = " @impl "; break;
                    679:                case AL_REPL:
                    680:                        sop = " @repl "; break;
                    681:                case AL_EQUIV:
                    682:                        sop = " @equiv "; break;
                    683:                default:
                    684:                        break;
                    685:        }
                    686:        PUTS("(");
                    687:        PRINTEXPR(vl,(Obj)FLHS(f));
                    688:        PUTS(sop);
                    689:        PRINTEXPR(vl,(Obj)FRHS(f));
                    690:        PUTS(")");
                    691: }
                    692:
1.13      noro      693: void PRINTLOP(VL vl,F f)
1.2       noro      694: {
                    695:        char *op;
                    696:
                    697:        switch ( FOP(f) ) {
                    698:                case AL_EQUAL:
                    699:                        op = " @== "; break;
                    700:                case AL_NEQ:
                    701:                        op = " @!= "; break;
                    702:                case AL_LESSP:
                    703:                        op = " @< "; break;
                    704:                case AL_GREATERP:
                    705:                        op = " @> "; break;
                    706:                case AL_LEQ:
                    707:                        op = " @<= "; break;
                    708:                case AL_GEQ:
                    709:                        op = " @>= "; break;
                    710:                default:
                    711:                        error("PRINTLOP : invalid operator");
                    712:                        break;
                    713:        }
                    714:        PRINTEXPR(vl,(Obj)FPL(f)); PUTS(op); PUTS("0");
                    715: }
                    716:
1.13      noro      717: void PRINTQOP(VL vl,F f)
1.2       noro      718: {
                    719:        char *op;
                    720:
                    721:        op = FOP(f)==AL_EX?"ex":"all";
                    722:        PUTS(op); PUTS(NAME(FQVR(f)));
                    723:        total_length += 2;
                    724:        PRINTEXPR(vl,(Obj)FQMAT(f)); PUTS(")");
                    725: }
                    726:
1.13      noro      727: void PRINTUP(UP n)
1.2       noro      728: {
                    729:        int i,d;
                    730:
                    731:        if ( !n )
                    732:                PUTS("0");
                    733:        else if ( !n->d )
                    734:                PRINTNUM(n->c[0]);
                    735:        else {
                    736:                d = n->d;
                    737:                PUTS("(");
                    738:                if ( !d ) {
                    739:                        PRINTNUM(n->c[d]);
                    740:                } else if ( d == 1 ) {
                    741:                        PRINTNUM(n->c[d]);
                    742:                        PUTS("*@p");
                    743:                } else {
                    744:                        PRINTNUM(n->c[d]);
                    745:                        PRINTHAT;
                    746:                        total_length += 13;
                    747:                }
                    748:                for ( i = d-1; i >= 0; i-- ) {
                    749:                        if ( n->c[i] ) {
                    750:                                PUTS("+("); PRINTNUM(n->c[i]); PUTS(")");
                    751:                                if ( i >= 2 ) {
                    752:                                        PRINTHAT;
                    753:                                        total_length += 13;
                    754:                                } else if ( i == 1 )
                    755:                                        PUTS("*@p");
                    756:                        }
                    757:                }
                    758:                PUTS(")");
1.1       noro      759:        }
1.12      noro      760: }
                    761:
1.13      noro      762: void PRINTUM(UM n)
1.12      noro      763: {
                    764:        int i,d;
                    765:
                    766:        if ( !n )
                    767:                PUTS("0");
                    768:        else if ( !n->d )
                    769:                PRINTSF(n->c[0]);
                    770:        else {
                    771:                d = n->d;
                    772:                PUTS("(");
                    773:                if ( !d ) {
                    774:                        PRINTSF(n->c[d]);
                    775:                } else if ( d == 1 ) {
                    776:                        PRINTSF(n->c[d]);
                    777:                        PUTS("*@s");
                    778:                } else {
                    779:                        PRINTSF(n->c[d]);
                    780:                        PUTS("*@s"); PRINTHAT; total_length += 13;
                    781:                }
                    782:                for ( i = d-1; i >= 0; i-- ) {
                    783:                        if ( n->c[i] ) {
                    784:                                PUTS("+("); PRINTSF(n->c[i]); PUTS(")");
                    785:                                if ( i >= 2 ) {
                    786:                                        PUTS("*@s"); PRINTHAT; total_length += 13;
                    787:                                } else if ( i == 1 )
                    788:                                        PUTS("*@s");
                    789:                        }
                    790:                }
                    791:                PUTS(")");
                    792:        }
                    793: }
                    794:
1.13      noro      795: void PRINTSF(unsigned int i)
1.12      noro      796: {
                    797:        if ( !i ) {
                    798:                PUTS("0");
                    799:        } else
                    800:                total_length += 15;
1.19    ! noro      801: }
        !           802:
        !           803:
        !           804: void PRINTFNODENODE(NODE n)
        !           805: {
        !           806:        for ( ; n; n = NEXT(n) ) {
        !           807:                PRINTFNODE((FNODE)BDY(n),0);
        !           808:                if ( NEXT(n) ) PUTS(",");
        !           809:        }
        !           810: }
        !           811:
        !           812: void PRINTFARGS(FNODE f)
        !           813: {
        !           814:        NODE n;
        !           815:
        !           816:        if ( f->id == I_LIST ) {
        !           817:                n = (NODE)FA0(f);
        !           818:                PRINTFNODENODE(n);
        !           819:        } else
        !           820:                PRINTFNODE(f,0);
        !           821: }
        !           822:
        !           823: void PRINTFNODE(FNODE f,int paren)
        !           824: {
        !           825:        NODE n,t,t0;
        !           826:        char vname[BUFSIZ],prefix[BUFSIZ];
        !           827:        char *opname,*vname_conv,*prefix_conv;
        !           828:        Obj obj;
        !           829:        int i,len,allzero,elen,elen2;
        !           830:        C cplx;
        !           831:        char *r;
        !           832:        FNODE fi,f2;
        !           833:
        !           834:        if ( !f ) {
        !           835:                PUTS("(0)");
        !           836:                return;
        !           837:        }
        !           838:        if ( paren ) PUTS("(");
        !           839:        switch ( f->id ) {
        !           840:                /* unary operators */
        !           841:                case I_NOT: PRINTFNODE((FNODE)FA0(f),1); break;
        !           842:                case I_PAREN: PRINTFNODE((FNODE)FA0(f),0); break;
        !           843:                case I_MINUS: PUTS("-"); PRINTFNODE((FNODE)FA0(f),1); break;
        !           844:                /* binary operators */
        !           845:                /* arg list */
        !           846:                /* I_AND, I_OR => FA0(f), FA1(f) */
        !           847:                /* otherwise   => FA1(f), FA2(f) */
        !           848:                case I_BOP:
        !           849:                        PRINTFNODE((FNODE)FA1(f),1);
        !           850:                        PUTS(((ARF)FA0(f))->name);
        !           851:                        PRINTFNODE((FNODE)FA2(f),1);
        !           852:                        break;
        !           853:                case I_COP:
        !           854:                        switch( (cid)FA0(f) ) {
        !           855:                                case C_EQ: opname = ("=="); break;
        !           856:                                case C_NE: opname = ("!="); break;
        !           857:                                case C_GT: opname = (">"); break;
        !           858:                                case C_LT: opname = ("<"); break;
        !           859:                                case C_GE: opname = (">="); break;
        !           860:                                case C_LE: opname = ("<="); break;
        !           861:                        }
        !           862:                        PRINTFNODE((FNODE)FA1(f),1);
        !           863:                        PUTS(opname);
        !           864:                        PRINTFNODE((FNODE)FA2(f),1);
        !           865:                        break;
        !           866:                case I_LOP:
        !           867:                        switch( (lid)FA0(f) ) {
        !           868:                                case L_EQ: opname = ("@=="); break;
        !           869:                                case L_NE: opname = ("@!="); break;
        !           870:                                case L_GT: opname = ("@>"); break;
        !           871:                                case L_LT: opname = ("@<"); break;
        !           872:                                case L_GE: opname = ("@>="); break;
        !           873:                                case L_LE: opname = ("@<="); break;
        !           874:                                case L_AND: opname = ("@&&"); break;
        !           875:                                case L_OR: opname = ("@||"); break;
        !           876:                                case L_NOT: opname = ("@!"); break;
        !           877:                        }
        !           878:                        if ( (lid)FA0(f)==L_NOT ) {
        !           879:                                PUTS(opname); PRINTFNODE((FNODE)FA1(f),1);
        !           880:                        } else {
        !           881:                                PRINTFNODE((FNODE)FA1(f),1);
        !           882:                                PUTS(opname);
        !           883:                                PRINTFNODE((FNODE)FA2(f),1);
        !           884:                        }
        !           885:                        break;
        !           886:                case I_AND:
        !           887:                        PRINTFNODE((FNODE)FA0(f),1);
        !           888:                        PUTS("&&");
        !           889:                        PRINTFNODE((FNODE)FA1(f),1);
        !           890:                        break;
        !           891:                case I_OR:
        !           892:                        PRINTFNODE((FNODE)FA0(f),1);
        !           893:                        PUTS("!!");
        !           894:                        PRINTFNODE((FNODE)FA1(f),1);
        !           895:                        break;
        !           896:                /* ternary operators */
        !           897:                case I_CE:
        !           898:                        PRINTFNODE((FNODE)FA0(f),1); PUTS("?"); PRINTFNODE((FNODE)FA1(f),1);
        !           899:                        PUTS(":"); PRINTFNODE((FNODE)FA2(f),1);
        !           900:                        break;
        !           901:                /* lists */
        !           902:                case I_LIST: PUTS("["); PRINTFNODENODE((NODE)FA0(f)); PUTS("]"); break;
        !           903:                /* function */
        !           904:                case I_FUNC:
        !           905:                        if ( !strcmp(((FUNC)FA0(f))->name,"@pi") ) PUTS("@pi");
        !           906:                        else if ( !strcmp(((FUNC)FA0(f))->name,"@e") ) PUTS("@e");
        !           907:                        else {
        !           908:                                PUTS(((FUNC)FA0(f))->name);
        !           909:                                PUTS("("); PRINTFARGS(FA1(f)); PUTS(")");
        !           910:                        }
        !           911:                        break;
        !           912:                /* XXX */
        !           913:                case I_CAR: PUTS("car("); PRINTFNODE(FA0(f),0); PUTS(")"); break;
        !           914:                case I_CDR: PUTS("cdr("); PRINTFNODE(FA0(f),0); PUTS(")"); break;
        !           915:                /* exponent vector */
        !           916:                case I_EV: PUTS("<<"); PRINTFNODENODE((NODE)FA0(f)); PUTS(">>"); break;
        !           917:                /* string */
        !           918:                case I_STR: PUTS((char *)FA0(f)); break;
        !           919:                /* internal object */
        !           920:                case I_FORMULA: obj = (Obj)FA0(f); PRINTEXPR(CO,obj); break;
        !           921:                /* program variable */
        !           922:                case I_PVAR:
        !           923:                        if ( FA1(f) )
        !           924:                                error("length_fnode : not implemented yet");
        !           925:                        GETPVNAME(FA0(f),opname);
        !           926:                        PUTS(opname);
        !           927:                        break;
        !           928:                default: error("length_fnode : not implemented yet");
        !           929:        }
        !           930:        if ( paren ) PUTS(")");
1.1       noro      931: }

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