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

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

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