[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.18

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.18    ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2000/io/cpexpr.c,v 1.17 2004/02/09 08:23: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.1       noro       96:
                     97: void PRINTEXPR();
                     98: void PRINTNUM();
1.2       noro       99: void PRINTN();
1.1       noro      100: void PRINTV();
                    101: void PRINTP();
                    102: void PRINTR();
                    103: void PRINTLIST();
                    104: void PRINTVECT();
                    105: void PRINTMAT();
                    106: void PRINTSTR();
                    107: void PRINTCOMP();
                    108: void PRINTDP();
1.2       noro      109: void PRINTUI();
                    110: void PRINTGF2MAT();
                    111: void PRINTGFMMAT();
1.5       noro      112: void PRINTBYTEARRAY();
1.11      noro      113: void PRINTQUOTE();
1.17      noro      114: void PRINTSYMBOL();
                    115: void PRINTRANGE();
1.18    ! noro      116: void PRINTTB();
1.2       noro      117: void PRINTERR();
1.1       noro      118: void PRINTCPLX();
1.2       noro      119: void PRINTLM();
                    120: void PRINTLF();
1.13      noro      121: void PRINTUP();
                    122: void PRINTUM();
1.2       noro      123: void PRINTUP2();
1.13      noro      124: void PRINTFOP();
                    125: void PRINTEOP();
                    126: void PRINTLOP();
                    127: void PRINTQOP();
                    128: void PRINTSF();
1.1       noro      129:
                    130: static int total_length;
                    131:
1.13      noro      132: int estimate_length(VL vl,pointer p)
1.1       noro      133: {
                    134:        total_length = 0;
                    135:        PRINTEXPR(vl,p);
                    136:        return total_length;
                    137: }
                    138:
1.15      ohara     139: #if defined(PARI)
1.13      noro      140: void PRINTBF(BF a)
1.2       noro      141: {
                    142:        char *str;
1.7       noro      143:        char *GENtostr0();
                    144:        void myoutbrute();
1.2       noro      145:
1.7       noro      146:        if ( double_output ) {
                    147:                str = GENtostr0(a->body,myoutbrute);
                    148:        } else {
                    149:                str = GENtostr(a->body);
                    150:        }
1.2       noro      151:        total_length += strlen(str);
                    152:        free(str);
                    153: }
                    154: #endif
                    155:
1.13      noro      156: void PRINTEXPR(VL vl,pointer p)
1.1       noro      157: {
                    158:        if ( !p ) {
                    159:                total_length++;
                    160:                return;
                    161:        }
                    162:
                    163:        switch ( OID(p) ) {
                    164:                case O_N:
                    165:                        PRINTNUM((Num)p); break;
                    166:                case O_P:
                    167:                        PRINTP(vl,(P)p); break;
                    168:                case O_R:
                    169:                        PRINTR(vl,(R)p); break;
                    170:                case O_LIST:
                    171:                        PRINTLIST(vl,(LIST)p); break;
                    172:                case O_VECT:
                    173:                        PRINTVECT(vl,(VECT)p); break;
                    174:                case O_MAT:
                    175:                        PRINTMAT(vl,(MAT)p); break;
                    176:                case O_STR:
                    177:                        PRINTSTR((STRING)p); break;
                    178:                case O_COMP:
                    179:                        PRINTCOMP(vl,(COMP)p); break;
                    180:                case O_DP:
                    181:                        PRINTDP(vl,(DP)p); break;
1.2       noro      182:                case O_USINT:
                    183:                        PRINTUI(vl,(USINT)p); break;
                    184:                case O_GF2MAT:
                    185:                        PRINTGF2MAT(vl,(GF2MAT)p); break;
                    186:                case O_ERR:
                    187:                        PRINTERR(vl,(ERR)p); break;
                    188:                case O_MATHCAP:
                    189:                        PRINTLIST(vl,((MATHCAP)p)->body); break;
                    190:                case O_F:
                    191:                        PRINTLF(vl,(F)p); break;
                    192:                case O_GFMMAT:
                    193:                        PRINTGFMMAT(vl,(GFMMAT)p); break;
1.5       noro      194:                case O_BYTEARRAY:
                    195:                        PRINTBYTEARRAY(vl,(BYTEARRAY)p); break;
1.11      noro      196:                case O_QUOTE:
                    197:                        PRINTQUOTE(vl,(QUOTE)p); break;
1.17      noro      198:                case O_SYMBOL:
                    199:                        PRINTSYMBOL((SYMBOL)p); break;
                    200:                case O_RANGE:
                    201:                        PRINTRANGE(vl,(RANGE)p); break;
1.18    ! noro      202:                case O_TB:
        !           203:                        PRINTTB(vl,(TB)p); break;
1.1       noro      204:                default:
                    205:                        break;
                    206:        }
                    207: }
                    208:
1.13      noro      209: void PRINTN(N n)
1.1       noro      210: {
                    211:        double ceil();
                    212:
                    213:        if ( !n )
                    214:                PUTS("0");
1.2       noro      215:        else if ( hex_output )
                    216:                total_length += 2+(int)(PL(n)*8);
1.1       noro      217:        else
                    218:                total_length += (int)(ceil(0.31*((double)(BSH*PL(n))))+1);
                    219: }
                    220:
1.13      noro      221: void PRINTNUM(Num q)
1.1       noro      222: {
                    223:        if ( !q ) {
                    224:                PUTS("0");
                    225:                return;
                    226:        }
                    227:        switch ( NID(q) ) {
                    228:                case N_Q:
                    229:                        if ( SGN((Q)q) == -1 )
                    230:                                PUTS("-");
                    231:                        PRINTN(NM((Q)q));
                    232:                        if ( !INT((Q)q) ) {
                    233:                                PUTS("/"); PRINTN(DN((Q)q));
                    234:                        }
                    235:                        break;
                    236:                case N_R:
1.7       noro      237:                        if ( double_output )
1.8       noro      238:                                total_length += 400+real_digit; /* XXX */
1.7       noro      239:                        else
1.8       noro      240:                                total_length += 20+real_digit; /* XXX */
1.1       noro      241:                        break;
                    242:                case N_A:
                    243:                        PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")");
                    244:                        break;
1.15      ohara     245: #if defined(PARI)
1.1       noro      246:                case N_B:
                    247:                        PRINTBF((BF)q); break;
                    248: #endif
                    249:                case N_C:
                    250:                        PRINTCPLX((C)q); break;
                    251:                case N_M:
1.2       noro      252:                        total_length += 11; /* XXX */
                    253:                        break;
                    254:                case N_LM:
                    255:                        PRINTN(((LM)q)->body); break;
                    256:                case N_GF2N:
                    257:                        if ( hex_output )
                    258:                                PRINTN((N)(((GF2N)q)->body));
                    259:                        else
                    260:                                PRINTUP2(((GF2N)q)->body);
                    261:                        break;
                    262:                case N_GFPN:
                    263:                        PRINTUP((UP)(((GFPN)q)->body));
1.9       noro      264:                        break;
                    265:                case N_GFS:
1.10      noro      266:                        total_length += 13; /* XXX */
1.2       noro      267:                        break;
1.12      noro      268:                case N_GFSN:
                    269:                        PRINTUM(BDY((GFSN)q));
                    270:                        break;
1.2       noro      271:                default:
1.1       noro      272:                        break;
                    273:        }
                    274: }
                    275:
1.13      noro      276: void PRINTCPLX(C a)
1.1       noro      277: {
                    278:        PUTS("(");
                    279:        if ( a->r )
                    280:                PRINTNUM(a->r);
                    281:        if ( a->i ) {
                    282:                if ( a->r && (compnum(0,a->i,0) > 0) )
                    283:                        PUTS("+");
                    284:                PRINTNUM(a->i); PUTS("*@i");
                    285:        }
                    286:        PUTS(")");
                    287: }
                    288:
1.13      noro      289: void PRINTP(VL vl,P p)
1.1       noro      290: {
                    291:        V v;
                    292:        DCP dc;
                    293:
                    294:        if ( !p )
                    295:                PUTS("0");
                    296:        else if ( NUM(p) )
                    297:                PRINTNUM((Num)p);
                    298:        else
                    299:                for ( dc = DC(p), v = VR(p); dc; dc = NEXT(dc) ) {
                    300:                        if ( !DEG(dc) )
                    301:                                PRINTP(vl,COEF(dc));
                    302:                        else {
                    303:                                if ( NUM(COEF(dc)) && UNIQ((Q)COEF(dc)) ) {
                    304:                                        ;
                    305:                                } else if ( NUM(COEF(dc)) && MUNIQ((Q)COEF(dc)) )
                    306:                                        PUTS("-");
                    307:                                else if ( NUM(COEF(dc)) || !NEXT(DC(COEF(dc)))) {
                    308:                                        PRINTP(vl,COEF(dc)); PUTS("*");
                    309:                                } else {
                    310:                                        PUTS("("); PRINTP(vl,COEF(dc)); PUTS(")*");
                    311:                                }
                    312:                                PRINTV(vl,v);
                    313:                                if ( cmpq(DEG(dc),ONE) ) {
1.2       noro      314:                                        PRINTHAT;
1.1       noro      315:                                        if ( INT(DEG(dc)) && SGN(DEG(dc))>0 )
                    316:                                                PRINTNUM((Num)DEG(dc));
                    317:                                        else {
                    318:                                                PUTS("("); PRINTNUM((Num)DEG(dc)); PUTS(")");
                    319:                                        }
                    320:                                }
                    321:                        }
                    322:                        if ( NEXT(dc) ) {
                    323:                                P t;
                    324:
                    325:                                t = COEF(NEXT(dc));
                    326:                                if (!DEG(NEXT(dc))) {
                    327:                                        if ( NUM(t) ) {
                    328:                                                if ( !mmono(t) )
                    329:                                                        PUTS("+");
                    330:                                        } else {
                    331:                                                if (!mmono(COEF(DC(t))))
                    332:                                                        PUTS("+");
                    333:                                        }
                    334:                                } else {
                    335:                                        if ( !mmono(t) )
                    336:                                                PUTS("+");
                    337:                                }
                    338:                        }
                    339:                }
                    340: }
                    341:
1.2       noro      342: extern int hideargs;
                    343:
1.13      noro      344: void PRINTV(VL vl,V v)
1.1       noro      345: {
                    346:        PF pf;
                    347:        PFAD ad;
                    348:        int i;
                    349:
                    350:        if ( NAME(v) )
                    351:                PUTS(NAME(v));
                    352:        else if ( (vid)v->attr == V_PF ) {
                    353:                pf = ((PFINS)v->priv)->pf; ad = ((PFINS)v->priv)->ad;
                    354:                if ( !strcmp(NAME(pf),"pow") ) {
1.14      noro      355:                        PUTS("(("); PRINTR(vl,(R)ad[0].arg); PUTS(")"); PRINTHAT; PUTS("(");
                    356:                        PRINTR(vl,(R)ad[1].arg); PUTS("))");
1.1       noro      357:                } else if ( !pf->argc )
                    358:                        PUTS(NAME(pf));
                    359:                else {
1.2       noro      360:                        if ( hideargs ) {
                    361:                                for ( i = 0; i < pf->argc; i++ )
                    362:                                        if ( ad[i].d )
                    363:                                                break;
                    364:                                if ( i < pf->argc ) {
                    365:                                        PUTS(NAME(pf));
1.1       noro      366:                                        total_length += 11; /* XXX */
1.2       noro      367:                                        for ( i = 1; i < pf->argc; i++ ) {
                    368:                                                total_length += 11; /* XXX */
                    369:                                        }
                    370:                                        PUTS("}");
                    371:                                } else {
                    372:                                        PUTS(NAME(pf));
                    373:                                        total_length += 1; /* XXX */
1.1       noro      374:                                }
                    375:                        } else {
1.2       noro      376:                                for ( i = 0; i < pf->argc; i++ )
                    377:                                        if ( ad[i].d )
                    378:                                                break;
                    379:                                if ( i < pf->argc ) {
                    380:                                        PUTS(NAME(pf));
                    381:                                        total_length += 11; /* XXX */
                    382:                                        for ( i = 1; i < pf->argc; i++ ) {
                    383:                                                total_length += 11; /* XXX */
                    384:                                        }
                    385:                                        PUTS(")(");
                    386:                                } else {
                    387:                                        PUTS(NAME(pf));
                    388:                                        total_length += 1; /* XXX */
                    389:                                }
                    390:                                PRINTR(vl,(R)ad[0].arg);
                    391:                                for ( i = 1; i < pf->argc; i++ ) {
                    392:                                        PUTS(","); PRINTR(vl,(R)ad[i].arg);
                    393:                                }
                    394:                                PUTS(")");
1.1       noro      395:                        }
                    396:                }
                    397:        }
                    398: }
                    399:
1.13      noro      400: void PRINTR(VL vl,R a)
1.1       noro      401: {
                    402:        if ( !a )
                    403:                PUTS("0");
                    404:        else
                    405:                switch (OID(a)) {
                    406:                        case O_N: case O_P:
                    407:                                PRINTP(vl,(P)a); break;
                    408:                        default:
                    409:                                PUTS("("); PRINTP(vl,NM((R)a)); PUTS(")/("); PRINTP(vl,DN((R)a)); PUTS(")");
                    410:                                break;
                    411:                }
                    412: }
                    413:
1.13      noro      414: void PRINTVECT(VL vl,VECT vect)
1.1       noro      415: {
                    416:        int i;
                    417:        pointer *ptr;
                    418:
                    419:        PUTS("[ ");
                    420:        for ( i = 0, ptr = BDY(vect); i < vect->len; i++ ) {
                    421:                PRINTEXPR(vl,ptr[i]); PUTS(" ");
                    422:        }
                    423:        PUTS("]");
                    424: }
                    425:
1.13      noro      426: void PRINTMAT(VL vl,MAT mat)
1.1       noro      427: {
                    428:        int i,j,r,c;
                    429:        pointer *ptr;
                    430:
                    431:        for ( i = 0, r = mat->row, c = mat->col; i < r; i++ ) {
                    432:                PUTS("[ ");
                    433:                for ( j = 0, ptr = BDY(mat)[i]; j < c; j++ ) {
                    434:                        PRINTEXPR(vl,ptr[j]); PUTS(" ");
                    435:                }
                    436:                PUTS("]");
                    437:                if ( i < r - 1 )
                    438:                        PUTS("\n");
                    439:        }
                    440: }
                    441:
1.13      noro      442: void PRINTLIST(VL vl,LIST list)
1.1       noro      443: {
                    444:        NODE tnode;
                    445:
                    446:        PUTS("[");
                    447:        for ( tnode = (NODE)list->body; tnode; tnode = NEXT(tnode) ) {
                    448:                PRINTEXPR(vl,tnode->body);
                    449:                if ( NEXT(tnode) )
                    450:                        PUTS(",");
                    451:        }
                    452:        PUTS("]");
                    453: }
                    454:
1.13      noro      455: void PRINTSTR(STRING str)
1.1       noro      456: {
                    457:        char *p;
                    458:
                    459:        for ( p = BDY(str); *p; p++ )
                    460:                if ( *p == '"' )
                    461:                        PUTS("\"");
                    462:                else {
                    463:                        total_length += 1;
                    464:                }
                    465: }
                    466:
1.13      noro      467: void PRINTCOMP(VL vl,COMP c)
1.1       noro      468: {
                    469:        int n,i;
                    470:
                    471:        n = getcompsize((int)c->type);
                    472:        PUTS("{");
                    473:        for ( i = 0; i < n; i++ ) {
                    474:                PRINTEXPR(vl,(pointer)c->member[i]);
                    475:                if ( i < n-1 )
                    476:                        PUTS(",");
                    477:        }
                    478:        PUTS("}");
                    479: }
                    480:
1.13      noro      481: void PRINTDP(VL vl,DP d)
1.1       noro      482: {
                    483:        int n,i;
                    484:        MP m;
                    485:        DL dl;
                    486:
                    487:        for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {
                    488:                PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");
                    489:                for ( i = 0, dl = m->dl; i < n-1; i++ ) {
                    490:                        total_length += 11;
                    491:                }
                    492:                total_length += 10;
                    493:                PUTS(">>");
                    494:                if ( NEXT(m) )
                    495:                        PUTS("+");
1.2       noro      496:        }
                    497: }
                    498:
1.13      noro      499: void PRINTUI(VL vl,USINT u)
1.2       noro      500: {
                    501:        total_length += 10;
                    502: }
                    503:
1.13      noro      504: void PRINTGF2MAT(VL vl,GF2MAT mat)
1.2       noro      505: {
                    506:        int row,col,w,i,j,k,m;
                    507:        unsigned int t;
                    508:        unsigned int **b;
                    509:
                    510:        row = mat->row;
                    511:        col = mat->col;
                    512:        w = (col+BSH-1)/BSH;
                    513:        b = mat->body;
                    514:        for ( i = 0; i < row; i++ ) {
                    515:                for ( j = 0, m = 0; j < w; j++ ) {
                    516:                        t = b[i][j];
                    517:                        for ( k = 0; m < col && k < BSH; k++, m++ )
                    518:                                if ( t & (1<<k) )
                    519:                                        PUTS("1");
                    520:                                else
                    521:                                        PUTS("0");
                    522:                }
                    523:                PUTS("\n");
                    524:        }
                    525: }
                    526:
1.13      noro      527: void PRINTGFMMAT(VL vl,GFMMAT mat)
1.2       noro      528: {
                    529:        int row,col,i,j;
                    530:        unsigned int **b;
                    531:
                    532:        row = mat->row;
                    533:        col = mat->col;
                    534:        b = mat->body;
                    535:        for ( i = 0; i < row; i++ ) {
                    536:                PUTS("[");
                    537:                for ( j = 0; j < col; j++ ) {
                    538:                        total_length += 10; /* XXX */
                    539:                }
                    540:                PUTS("]\n");
                    541:        }
1.5       noro      542: }
                    543:
1.13      noro      544: void PRINTBYTEARRAY(VL vl,BYTEARRAY array)
1.5       noro      545: {
                    546:        /* |xx xx ... xx| */
1.6       noro      547:        total_length += 1+3*array->len;
1.11      noro      548: }
                    549:
1.13      noro      550: void PRINTQUOTE(VL vl,QUOTE quote)
1.11      noro      551: {
                    552:        /* <...quoted...> */
                    553:        total_length += 20;
1.17      noro      554: }
                    555:
                    556: void PRINTSYMBOL(SYMBOL sym)
                    557: {
                    558:        total_length += strlen(sym->name);
                    559: }
                    560:
                    561: void PRINTRANGE(VL vl,RANGE r)
                    562: {
                    563:        PUTS("range("); PRINTEXPR(vl,r->start);
                    564:        PUTS(","); PRINTEXPR(vl,r->end); PUTS(")");
1.18    ! noro      565: }
        !           566:
        !           567: void PRINTTB(VL vl,TB p)
        !           568: {
        !           569:        int i;
        !           570:
        !           571:        for ( i = 0; i < p->next; i++ ) {
        !           572:                total_length += strlen(p->body[i]);
        !           573:        }
1.2       noro      574: }
                    575:
1.13      noro      576: void PRINTERR(VL vl,ERR e)
1.2       noro      577: {
                    578:        PUTS("error("); PRINTEXPR(vl,e->body); PUTS(")");
                    579: }
                    580:
1.13      noro      581: void PRINTUP2(UP2 p)
1.2       noro      582: {
                    583:        int d,i;
                    584:
                    585:        if ( !p ) {
                    586:                PUTS("0");
                    587:        } else {
                    588:                d = degup2(p);
                    589:                PUTS("(");
                    590:                if ( !d ) {
                    591:                        PUTS("1");
                    592:                } else if ( d == 1 ) {
                    593:                        PUTS("@");
                    594:                } else {
                    595:                        PRINTHAT;
                    596:                        total_length += 11;
                    597:                }
                    598:                for ( i = d-1; i >= 0; i-- ) {
                    599:                        if ( p->b[i/BSH] & (1<<(i%BSH)) )
                    600:                                if ( !i ) {
                    601:                                        PUTS("+1");
                    602:                                } else if ( i == 1 ) {
                    603:                                        PUTS("+@");
                    604:                                } else {
                    605:                                        PRINTHAT;
                    606:                                        total_length += 12;
                    607:                                }
                    608:                }
                    609:                PUTS(")");
                    610:        }
                    611: }
                    612:
1.13      noro      613: void PRINTLF(VL vl,F f)
1.2       noro      614: {
                    615:        switch ( FOP(f) ) {
                    616:                case AL_TRUE:
                    617:                        PUTS("@true");
                    618:                        break;
                    619:                case AL_FALSE:
                    620:                        PUTS("@false");
                    621:                        break;
                    622:
                    623:                case AL_OR: case AL_AND:
                    624:                        PRINTFOP(vl,f); break;
                    625:                case AL_NOT: case AL_IMPL: case AL_REPL: case AL_EQUIV:
                    626:                        PRINTEOP(vl,f); break;
                    627:
                    628:                case AL_EQUAL: case AL_NEQ: case AL_LESSP:
                    629:                case AL_GREATERP: case AL_LEQ: case AL_GEQ:
                    630:                        PRINTLOP(vl,f); break;
                    631:
                    632:                case AL_EX: case AL_ALL:
                    633:                        PRINTQOP(vl,f); break;
                    634:                default:
                    635:                        break;
                    636:        }
                    637: }
                    638:
1.13      noro      639: void PRINTFOP(VL vl,F f)
1.2       noro      640: {
                    641:        char *op;
                    642:        NODE n;
                    643:
                    644:        op = FOP(f)==AL_OR?" @|| ":" @&& ";
                    645:        n = FJARG(f);
                    646:        PUTS("("); PRINTEXPR(vl,BDY(n)); PUTS(")");
                    647:        for ( n = NEXT(n); n; n = NEXT(n) ) {
                    648:                PUTS(op); PUTS("("); PRINTEXPR(vl,BDY(n)); PUTS(")");
                    649:        }
                    650: }
                    651:
1.13      noro      652: void PRINTEOP(VL vl,F f)
1.2       noro      653: {
                    654:        oFOP op;
                    655:        char *sop;
                    656:
                    657:        if ( (op = FOP(f)) == AL_NOT ) {
                    658:                PUTS("(@! "); PRINTEXPR(vl,(Obj)FARG(f)); PUTS(")"); return;
                    659:        }
                    660:        switch ( op ) {
                    661:                case AL_IMPL:
                    662:                        sop = " @impl "; break;
                    663:                case AL_REPL:
                    664:                        sop = " @repl "; break;
                    665:                case AL_EQUIV:
                    666:                        sop = " @equiv "; break;
                    667:                default:
                    668:                        break;
                    669:        }
                    670:        PUTS("(");
                    671:        PRINTEXPR(vl,(Obj)FLHS(f));
                    672:        PUTS(sop);
                    673:        PRINTEXPR(vl,(Obj)FRHS(f));
                    674:        PUTS(")");
                    675: }
                    676:
1.13      noro      677: void PRINTLOP(VL vl,F f)
1.2       noro      678: {
                    679:        char *op;
                    680:
                    681:        switch ( FOP(f) ) {
                    682:                case AL_EQUAL:
                    683:                        op = " @== "; break;
                    684:                case AL_NEQ:
                    685:                        op = " @!= "; break;
                    686:                case AL_LESSP:
                    687:                        op = " @< "; break;
                    688:                case AL_GREATERP:
                    689:                        op = " @> "; break;
                    690:                case AL_LEQ:
                    691:                        op = " @<= "; break;
                    692:                case AL_GEQ:
                    693:                        op = " @>= "; break;
                    694:                default:
                    695:                        error("PRINTLOP : invalid operator");
                    696:                        break;
                    697:        }
                    698:        PRINTEXPR(vl,(Obj)FPL(f)); PUTS(op); PUTS("0");
                    699: }
                    700:
1.13      noro      701: void PRINTQOP(VL vl,F f)
1.2       noro      702: {
                    703:        char *op;
                    704:
                    705:        op = FOP(f)==AL_EX?"ex":"all";
                    706:        PUTS(op); PUTS(NAME(FQVR(f)));
                    707:        total_length += 2;
                    708:        PRINTEXPR(vl,(Obj)FQMAT(f)); PUTS(")");
                    709: }
                    710:
1.13      noro      711: void PRINTUP(UP n)
1.2       noro      712: {
                    713:        int i,d;
                    714:
                    715:        if ( !n )
                    716:                PUTS("0");
                    717:        else if ( !n->d )
                    718:                PRINTNUM(n->c[0]);
                    719:        else {
                    720:                d = n->d;
                    721:                PUTS("(");
                    722:                if ( !d ) {
                    723:                        PRINTNUM(n->c[d]);
                    724:                } else if ( d == 1 ) {
                    725:                        PRINTNUM(n->c[d]);
                    726:                        PUTS("*@p");
                    727:                } else {
                    728:                        PRINTNUM(n->c[d]);
                    729:                        PRINTHAT;
                    730:                        total_length += 13;
                    731:                }
                    732:                for ( i = d-1; i >= 0; i-- ) {
                    733:                        if ( n->c[i] ) {
                    734:                                PUTS("+("); PRINTNUM(n->c[i]); PUTS(")");
                    735:                                if ( i >= 2 ) {
                    736:                                        PRINTHAT;
                    737:                                        total_length += 13;
                    738:                                } else if ( i == 1 )
                    739:                                        PUTS("*@p");
                    740:                        }
                    741:                }
                    742:                PUTS(")");
1.1       noro      743:        }
1.12      noro      744: }
                    745:
1.13      noro      746: void PRINTUM(UM n)
1.12      noro      747: {
                    748:        int i,d;
                    749:
                    750:        if ( !n )
                    751:                PUTS("0");
                    752:        else if ( !n->d )
                    753:                PRINTSF(n->c[0]);
                    754:        else {
                    755:                d = n->d;
                    756:                PUTS("(");
                    757:                if ( !d ) {
                    758:                        PRINTSF(n->c[d]);
                    759:                } else if ( d == 1 ) {
                    760:                        PRINTSF(n->c[d]);
                    761:                        PUTS("*@s");
                    762:                } else {
                    763:                        PRINTSF(n->c[d]);
                    764:                        PUTS("*@s"); PRINTHAT; total_length += 13;
                    765:                }
                    766:                for ( i = d-1; i >= 0; i-- ) {
                    767:                        if ( n->c[i] ) {
                    768:                                PUTS("+("); PRINTSF(n->c[i]); PUTS(")");
                    769:                                if ( i >= 2 ) {
                    770:                                        PUTS("*@s"); PRINTHAT; total_length += 13;
                    771:                                } else if ( i == 1 )
                    772:                                        PUTS("*@s");
                    773:                        }
                    774:                }
                    775:                PUTS(")");
                    776:        }
                    777: }
                    778:
1.13      noro      779: void PRINTSF(unsigned int i)
1.12      noro      780: {
                    781:        if ( !i ) {
                    782:                PUTS("0");
                    783:        } else
                    784:                total_length += 15;
1.1       noro      785: }

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