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

Annotation of OpenXM_contrib2/asir2000/io/pexpr.c, Revision 1.8

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.8     ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2000/io/pexpr.c,v 1.7 2000/12/15 05:30:08 noro Exp $
1.3       noro       48: */
1.1       noro       49: #include "ca.h"
                     50: #include "al.h"
                     51: #include "parse.h"
                     52: #include "comp.h"
                     53: #include "base.h"
                     54:
                     55: #ifndef FPRINT
                     56: #define FPRINT
                     57: #endif
                     58:
1.2       noro       59: #define PRINTHAT (fortran_output?PUTS("**"):PUTS("^"))
1.1       noro       60:
                     61: #ifdef FPRINT
                     62: FILE *asir_out;
                     63: #define OUT asir_out
                     64: char DFORMAT[BUFSIZ];
1.2       noro       65: int hex_output;
                     66: int fortran_output;
1.6       noro       67: int double_output;
1.1       noro       68:
                     69: #define TAIL
                     70: #define PUTS(s) fputs(s,OUT)
                     71: #define PRINTF fprintf
                     72: #define PRINTN printn
                     73: #define PRINTBF printbf
                     74: #define PRINTCPLX printcplx
                     75: #define PRINTLM printlm
                     76: #define PRINTUP2 printup2
                     77: #define PRINTV printv
                     78: #define PRINTEXPR printexpr
                     79: #define PRINTNUM printnum
                     80: #define PRINTP printp
                     81: #define PRINTR printr
                     82: #define PRINTLIST printlist
                     83: #define PRINTVECT printvect
                     84: #define PRINTMAT printmat
                     85: #define PRINTSTR printstr
                     86: #define PRINTCOMP printcomp
                     87: #define PRINTDP printdp
                     88: #define PRINTUI printui
                     89: #define PRINTGF2MAT printgf2mat
                     90: #define PRINTGFMMAT printgfmmat
1.5       noro       91: #define PRINTBYTEARRAY printbytearray
1.1       noro       92: #define PRINTERR printerr
                     93: #define PRINTLF printlf
                     94: #define PRINTLOP printlop
                     95: #define PRINTFOP printfop
                     96: #define PRINTEOP printeop
                     97: #define PRINTQOP printqop
                     98: #define PRINTUP printup
                     99: #endif
                    100:
                    101: #ifdef SPRINT
                    102: static char *buf;
                    103: #define OUT buf
                    104: extern char DFORMAT[BUFSIZ];
1.2       noro      105: extern int hex_output;
                    106: extern int fortran_output;
1.1       noro      107:
                    108: #define TAIL while ( *OUT ) OUT++;
                    109: #define PUTS(s) strcat(OUT,s)
                    110: #define PRINTF sprintf
                    111: #define PRINTN sprintn
                    112: #define PRINTBF sprintbf
                    113: #define PRINTCPLX sprintcplx
                    114: #define PRINTLM sprintlm
                    115: #define PRINTUP2 sprintup2
                    116: #define PRINTV sprintv
                    117: #define PRINTEXPR sprintexpr
                    118: #define PRINTNUM sprintnum
                    119: #define PRINTP sprintp
                    120: #define PRINTR sprintr
                    121: #define PRINTLIST sprintlist
                    122: #define PRINTVECT sprintvect
                    123: #define PRINTMAT sprintmat
                    124: #define PRINTSTR sprintstr
                    125: #define PRINTCOMP sprintcomp
                    126: #define PRINTDP sprintdp
                    127: #define PRINTUI sprintui
                    128: #define PRINTGF2MAT sprintgf2mat
                    129: #define PRINTGFMMAT sprintgfmmat
1.5       noro      130: #define PRINTBYTEARRAY sprintbytearray
1.1       noro      131: #define PRINTERR sprinterr
                    132: #define PRINTLF sprintlf
                    133: #define PRINTLOP sprintlop
                    134: #define PRINTFOP sprintfop
                    135: #define PRINTEOP sprinteop
                    136: #define PRINTQOP sprintqop
1.2       noro      137: #define PRINTUP sprintup
1.1       noro      138: #endif
                    139:
                    140: void PRINTEXPR();
                    141: void PRINTNUM();
                    142: void PRINTN();
                    143: void PRINTV();
                    144: void PRINTP();
                    145: void PRINTR();
                    146: void PRINTLIST();
                    147: void PRINTVECT();
                    148: void PRINTMAT();
                    149: void PRINTSTR();
                    150: void PRINTCOMP();
                    151: void PRINTDP();
                    152: void PRINTUI();
                    153: void PRINTGF2MAT();
                    154: void PRINTGFMMAT();
1.5       noro      155: void PRINTBYTEARRAY();
1.1       noro      156: void PRINTERR();
                    157: void PRINTCPLX();
                    158: void PRINTLM();
                    159: void PRINTLF();
1.2       noro      160: void PRINTUP2();
1.1       noro      161:
                    162: #ifdef FPRINT
                    163: void output_init() {
                    164:        OUT = stdout;
                    165:        sprintf(DFORMAT,"%%0%dd",DLENGTH);
                    166: }
                    167:
                    168: int mmono(p)
                    169: P p;
                    170: {
                    171:        if ( NUM(p) )
                    172:                if ( compnum(CO,(Num)p,0) < 0 )
                    173:                        return ( 1 );
                    174:                else
                    175:                        return ( 0 );
                    176:        else if ( NEXT(DC(p)) )
                    177:                return ( 0 );
                    178:        else
                    179:                return (mmono(COEF(DC(p))));
                    180: }
                    181:
                    182: #if PARI
                    183: void printbf(a)
                    184: BF a;
                    185: {
1.8     ! noro      186:        sor(a->body,double_output ? 'f' : 'g',-1,0);
1.1       noro      187: }
                    188: #endif
                    189: #endif
                    190:
                    191: #ifdef SPRINT
                    192: void soutput_init(s)
                    193: char *s;
                    194: {
                    195:        s[0] = 0; buf = s;
                    196: }
                    197:
                    198: #if PARI
1.8     ! noro      199: #include "genpari.h"
        !           200:
        !           201: void myoutbrute(g)
        !           202: GEN g;
        !           203: {
        !           204:        bruteall(g,'f',-1,1);
        !           205: }
        !           206:
1.1       noro      207: void sprintbf(a)
                    208: BF a;
                    209: {
1.2       noro      210:        char *str;
                    211:        char *GENtostr();
1.8     ! noro      212:        char *GENtostr0();
1.2       noro      213:
1.8     ! noro      214:        if ( double_output ) {
        !           215:                str = GENtostr0(a->body,myoutbrute);
        !           216:        } else {
        !           217:                str = GENtostr(a->body);
        !           218:        }
1.2       noro      219:        TAIL PRINTF(OUT,"%s",str);
                    220:        free(str);
1.1       noro      221: }
                    222: #endif
                    223: #endif
                    224:
                    225: void PRINTEXPR(vl,p)
                    226: VL vl;
                    227: Obj p;
                    228: {
                    229:        if ( !p ) {
                    230:                PRINTR(vl,(R)p);
                    231:                return;
                    232:        }
                    233:
                    234:        switch ( OID(p) ) {
                    235:                case O_N:
                    236:                        PRINTNUM((Num)p); break;
                    237:                case O_P:
                    238:                        PRINTP(vl,(P)p); break;
                    239:                case O_R:
                    240:                        PRINTR(vl,(R)p); break;
                    241:                case O_LIST:
                    242:                        PRINTLIST(vl,(LIST)p); break;
                    243:                case O_VECT:
                    244:                        PRINTVECT(vl,(VECT)p); break;
                    245:                case O_MAT:
                    246:                        PRINTMAT(vl,(MAT)p); break;
                    247:                case O_STR:
                    248:                        PRINTSTR((STRING)p); break;
                    249:                case O_COMP:
                    250:                        PRINTCOMP(vl,(COMP)p); break;
                    251:                case O_DP:
                    252:                        PRINTDP(vl,(DP)p); break;
                    253:                case O_USINT:
                    254:                        PRINTUI(vl,(USINT)p); break;
                    255:                case O_GF2MAT:
                    256:                        PRINTGF2MAT(vl,(GF2MAT)p); break;
                    257:                case O_ERR:
                    258:                        PRINTERR(vl,(ERR)p); break;
                    259:                case O_MATHCAP:
                    260:                        PRINTLIST(vl,((MATHCAP)p)->body); break;
                    261:                case O_F:
                    262:                        PRINTLF(vl,(F)p); break;
                    263:                case O_GFMMAT:
                    264:                        PRINTGFMMAT(vl,(GFMMAT)p); break;
1.5       noro      265:                case O_BYTEARRAY:
                    266:                        PRINTBYTEARRAY(vl,(BYTEARRAY)p); break;
1.1       noro      267:                default:
                    268:                        break;
                    269:        }
                    270: }
                    271:
                    272: void PRINTN(n)
                    273: N n;
                    274: {
                    275:        register int i,*ptr;
                    276:        N tn;
                    277:
                    278:        if ( !n ) {
                    279:                PUTS("0");
                    280:                return;
                    281:        }
                    282:        if ( hex_output ) {
                    283:                ptr = BD(n);
                    284:                TAIL PRINTF(OUT,"0x%x",ptr[PL(n)-1]);
                    285:                if ( hex_output < 0 )
                    286:                        for ( i = PL(n) - 2; i >= 0; i-- ) {
                    287:                                TAIL PRINTF(OUT,"|%08x",ptr[i]);
                    288:                        }
                    289:                else
                    290:                        for ( i = PL(n) - 2; i >= 0; i-- ) {
                    291:                                TAIL PRINTF(OUT,"%08x",ptr[i]);
                    292:                        }
                    293:        } else {
                    294:                ntobn(DBASE,n,&tn);
                    295:                ptr = BD(tn);
                    296:                TAIL PRINTF(OUT,"%d",ptr[PL(tn) - 1]);
                    297:                for ( i = PL(tn) - 2; i >= 0; i-- ) {
                    298:                        TAIL PRINTF(OUT,DFORMAT,ptr[i]);
                    299:                }
                    300:        }
                    301: }
                    302:
                    303: void PRINTNUM(q)
                    304: Num q;
                    305: {
                    306:        if ( !q ) {
                    307:                PUTS("0");
                    308:                return;
                    309:        }
                    310:        switch ( NID(q) ) {
                    311:                case N_Q:
                    312:                        if ( SGN((Q)q) == -1 )
                    313:                                PUTS("-");
                    314:                        PRINTN(NM((Q)q));
                    315:                        if ( !INT((Q)q) ) {
                    316:                                PUTS("/"); PRINTN(DN((Q)q));
                    317:                        }
                    318:                        break;
                    319:                case N_R:
1.6       noro      320:                        TAIL PRINTF(OUT,double_output?"%f":"%g",BDY((Real)q));
1.1       noro      321:                        break;
                    322:                case N_A:
                    323:                        PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")");
                    324:                        break;
                    325: #if PARI
                    326:                case N_B:
                    327:                        PRINTBF((BF)q); break;
                    328: #endif
                    329:                case N_C:
                    330:                        PRINTCPLX((C)q); break;
                    331:                case N_M:
                    332:                        TAIL PRINTF(OUT,"%d",CONT((MQ)q)); break;
                    333:                case N_LM:
                    334:                        PRINTN(((LM)q)->body); break;
                    335:                case N_GF2N:
                    336:                        if ( hex_output )
                    337:                                PRINTN((N)(((GF2N)q)->body));
                    338:                        else
                    339:                                PRINTUP2(((GF2N)q)->body);
                    340:                        break;
                    341:                case N_GFPN:
                    342:                        PRINTUP((UP)(((GFPN)q)->body));
                    343:                        break;
                    344:        }
                    345: }
                    346:
                    347: void PRINTCPLX(a)
                    348: C a;
                    349: {
                    350:        PUTS("(");
                    351:        if ( a->r )
                    352:                PRINTNUM(a->r);
                    353:        if ( a->i ) {
                    354:                if ( a->r && (compnum(0,a->i,0) > 0) )
                    355:                        PUTS("+");
                    356:                PRINTNUM(a->i); PUTS("*@i");
                    357:        }
                    358:        PUTS(")");
                    359: }
                    360:
                    361: void PRINTP(vl,p)
                    362: VL vl;
                    363: P p;
                    364: {
                    365:        V v;
                    366:        DCP dc;
                    367:
                    368:        if ( !p )
                    369:                PUTS("0");
                    370:        else if ( NUM(p) )
                    371:                PRINTNUM((Num)p);
                    372:        else
                    373:                for ( dc = DC(p), v = VR(p); dc; dc = NEXT(dc) ) {
                    374:                        if ( !DEG(dc) )
                    375:                                PRINTP(vl,COEF(dc));
                    376:                        else {
                    377:                                if ( NUM(COEF(dc)) && UNIQ((Q)COEF(dc)) ) {
                    378:                                        ;
                    379:                                } else if ( NUM(COEF(dc)) && MUNIQ((Q)COEF(dc)) )
                    380:                                        PUTS("-");
                    381:                                else if ( NUM(COEF(dc)) || !NEXT(DC(COEF(dc)))) {
                    382:                                        PRINTP(vl,COEF(dc)); PUTS("*");
                    383:                                } else {
                    384:                                        PUTS("("); PRINTP(vl,COEF(dc)); PUTS(")*");
                    385:                                }
                    386:                                PRINTV(vl,v);
                    387:                                if ( cmpq(DEG(dc),ONE) ) {
1.2       noro      388:                                        PRINTHAT;
1.1       noro      389:                                        if ( INT(DEG(dc)) && SGN(DEG(dc))>0 )
                    390:                                                PRINTNUM((Num)DEG(dc));
                    391:                                        else {
                    392:                                                PUTS("("); PRINTNUM((Num)DEG(dc)); PUTS(")");
                    393:                                        }
                    394:                                }
                    395:                        }
                    396:                        if ( NEXT(dc) ) {
                    397:                                P t;
                    398:
                    399:                                t = COEF(NEXT(dc));
                    400:                                if (!DEG(NEXT(dc))) {
                    401:                                        if ( NUM(t) ) {
                    402:                                                if ( !mmono(t) )
                    403:                                                        PUTS("+");
                    404:                                        } else {
                    405:                                                if (!mmono(COEF(DC(t))))
                    406:                                                        PUTS("+");
                    407:                                        }
                    408:                                } else {
                    409:                                        if ( !mmono(t) )
                    410:                                                PUTS("+");
                    411:                                }
                    412:                        }
                    413:                }
                    414: }
                    415:
                    416: int hideargs;
                    417:
                    418: void PRINTV(vl,v)
                    419: VL vl;
                    420: V v;
                    421: {
                    422:        PF pf;
                    423:        PFAD ad;
                    424:        int i;
                    425:
                    426:        if ( NAME(v) )
                    427:                PUTS(NAME(v));
                    428:        else if ( (vid)v->attr == V_PF ) {
                    429:                pf = ((PFINS)v->priv)->pf; ad = ((PFINS)v->priv)->ad;
                    430:                if ( !strcmp(NAME(pf),"pow") ) {
1.2       noro      431:                        PUTS("("); PRINTR(vl,(R)ad[0].arg); PUTS(")"); PRINTHAT; PUTS("(");
1.1       noro      432:                        PRINTR(vl,(R)ad[1].arg); PUTS(")");
                    433:                } else if ( !pf->argc ) {
                    434:                        TAIL PRINTF(OUT,"%s",NAME(pf));
                    435:                } else {
                    436:                        if ( hideargs ) {
                    437:                                for ( i = 0; i < pf->argc; i++ )
                    438:                                        if ( ad[i].d )
                    439:                                                break;
                    440:                                if ( i < pf->argc ) {
                    441:                                        TAIL PRINTF(OUT,"%s{%d",NAME(pf),ad[0].d);
                    442:                                        for ( i = 1; i < pf->argc; i++ ) {
                    443:                                                TAIL PRINTF(OUT,",%d",ad[i].d);
                    444:                                        }
                    445:                                        PUTS("}");
                    446:                                } else {
                    447:                                        TAIL PRINTF(OUT,"%s",NAME(pf));
                    448:                                }
                    449:                        } else {
                    450:                                for ( i = 0; i < pf->argc; i++ )
                    451:                                        if ( ad[i].d )
                    452:                                                break;
                    453:                                if ( i < pf->argc ) {
                    454:                                        TAIL PRINTF(OUT,"%s{%d",NAME(pf),ad[0].d);
                    455:                                        for ( i = 1; i < pf->argc; i++ ) {
                    456:                                                TAIL PRINTF(OUT,",%d",ad[i].d);
                    457:                                        }
                    458:                                        PUTS("}(");
                    459:                                } else {
                    460:                                        TAIL PRINTF(OUT,"%s(",NAME(pf));
                    461:                                }
                    462:                                PRINTR(vl,(R)ad[0].arg);
                    463:                                for ( i = 1; i < pf->argc; i++ ) {
                    464:                                        PUTS(","); PRINTR(vl,(R)ad[i].arg);
                    465:                                }
                    466:                                PUTS(")");
                    467:                        }
                    468:                }
                    469:        }
                    470: }
                    471:
                    472: void PRINTR(vl,a)
                    473: VL vl;
                    474: R a;
                    475: {
                    476:        if ( !a )
                    477:                PUTS("0");
                    478:        else
                    479:                switch (OID(a)) {
                    480:                        case O_N: case O_P:
                    481:                                PRINTP(vl,(P)a); break;
                    482:                        default:
                    483:                                PUTS("("); PRINTP(vl,NM((R)a)); PUTS(")/("); PRINTP(vl,DN((R)a)); PUTS(")");
                    484:                                break;
                    485:                }
                    486: }
                    487:
                    488: void PRINTVECT(vl,vect)
                    489: VL vl;
                    490: VECT vect;
                    491: {
                    492:        int i;
                    493:        pointer *ptr;
                    494:
                    495:        PUTS("[ ");
                    496:        for ( i = 0, ptr = BDY(vect); i < vect->len; i++ ) {
                    497:                PRINTEXPR(vl,ptr[i]); PUTS(" ");
                    498:        }
                    499:        PUTS("]");
                    500: }
                    501:
                    502: void PRINTMAT(vl,mat)
                    503: VL vl;
                    504: MAT mat;
                    505: {
                    506:        int i,j,r,c;
                    507:        pointer *ptr;
                    508:
                    509:        for ( i = 0, r = mat->row, c = mat->col; i < r; i++ ) {
                    510:                PUTS("[ ");
                    511:                for ( j = 0, ptr = BDY(mat)[i]; j < c; j++ ) {
                    512:                        PRINTEXPR(vl,ptr[j]); PUTS(" ");
                    513:                }
                    514:                PUTS("]");
                    515:                if ( i < r - 1 )
                    516:                        PUTS("\n");
                    517:        }
                    518: }
                    519:
                    520: void PRINTLIST(vl,list)
                    521: VL vl;
                    522: LIST list;
                    523: {
                    524:        NODE tnode;
                    525:
                    526:        PUTS("[");
                    527:        for ( tnode = (NODE)list->body; tnode; tnode = NEXT(tnode) ) {
                    528:                PRINTEXPR(vl,tnode->body);
                    529:                if ( NEXT(tnode) )
                    530:                        PUTS(",");
                    531:        }
                    532:        PUTS("]");
                    533: }
                    534:
                    535: void PRINTSTR(str)
                    536: STRING str;
                    537: {
                    538:        char *p;
                    539:
                    540:        for ( p = BDY(str); *p; p++ )
                    541:                if ( *p == '"' )
                    542:                        PUTS("\"");
                    543:                else {
                    544:                        TAIL PRINTF(OUT,"%c",*p);
                    545:                }
                    546: }
                    547:
                    548: void PRINTCOMP(vl,c)
                    549: VL vl;
                    550: COMP c;
                    551: {
                    552:        int n,i;
                    553:
                    554:        n = getcompsize((int)c->type);
                    555:        PUTS("{");
                    556:        for ( i = 0; i < n; i++ ) {
                    557:                PRINTEXPR(vl,(pointer)c->member[i]);
                    558:                if ( i < n-1 )
                    559:                        PUTS(",");
                    560:        }
                    561:        PUTS("}");
                    562: }
                    563:
                    564: void PRINTDP(vl,d)
                    565: VL vl;
                    566: DP d;
                    567: {
                    568:        int n,i;
                    569:        MP m;
                    570:        DL dl;
                    571:
                    572:        for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {
                    573:                PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");
                    574:                for ( i = 0, dl = m->dl; i < n-1; i++ ) {
                    575:                        TAIL PRINTF(OUT,"%d,",dl->d[i]);
                    576:                }
                    577:                TAIL PRINTF(OUT,"%d",dl->d[i]);
                    578:                PUTS(">>");
                    579:                if ( NEXT(m) )
                    580:                        PUTS("+");
                    581:        }
                    582: }
                    583:
                    584: void PRINTUI(vl,u)
                    585: VL vl;
                    586: USINT u;
                    587: {
                    588:        TAIL PRINTF(OUT,"%u",BDY(u));
                    589: }
                    590:
                    591: void PRINTGF2MAT(vl,mat)
                    592: VL vl;
                    593: GF2MAT mat;
                    594: {
                    595:        int row,col,w,i,j,k,m;
                    596:        unsigned int t;
                    597:        unsigned int **b;
                    598:
                    599:        row = mat->row;
                    600:        col = mat->col;
                    601:        w = (col+BSH-1)/BSH;
                    602:        b = mat->body;
                    603:        for ( i = 0; i < row; i++ ) {
                    604:                for ( j = 0, m = 0; j < w; j++ ) {
                    605:                        t = b[i][j];
                    606:                        for ( k = 0; m < col && k < BSH; k++, m++ )
                    607:                                if ( t & (1<<k) )
                    608:                                        PUTS("1");
                    609:                                else
                    610:                                        PUTS("0");
                    611:                }
                    612:                PUTS("\n");
                    613:        }
                    614: }
                    615:
                    616: void PRINTGFMMAT(vl,mat)
                    617: VL vl;
                    618: GFMMAT mat;
                    619: {
                    620:        int row,col,i,j;
                    621:        unsigned int t;
                    622:        unsigned int **b;
                    623:
                    624:        row = mat->row;
                    625:        col = mat->col;
                    626:        b = mat->body;
                    627:        for ( i = 0; i < row; i++ ) {
                    628:                PUTS("[");
                    629:                for ( j = 0; j < col; j++ ) {
                    630:                        TAIL PRINTF(OUT,"%8d",b[i][j]);
                    631:                }
                    632:                PUTS("]\n");
                    633:        }
1.5       noro      634: }
                    635:
                    636: void PRINTBYTEARRAY(vl,array)
                    637: VL vl;
                    638: BYTEARRAY array;
                    639: {
                    640:        int len,i;
                    641:        unsigned int t;
                    642:        unsigned char *b;
                    643:
                    644:        len = array->len;
                    645:        b = array->body;
                    646:        PUTS("|");
                    647:        for ( i = 0; i < len-1; i++ ) {
                    648:                TAIL PRINTF(OUT,"%02x ",(unsigned int)b[i]);
                    649:        }
                    650:        TAIL PRINTF(OUT,"%02x",(unsigned int)b[i]);
                    651:        PUTS("|");
1.1       noro      652: }
                    653:
                    654: void PRINTERR(vl,e)
                    655: VL vl;
                    656: ERR e;
                    657: {
                    658:        PUTS("error("); PRINTEXPR(vl,e->body); PUTS(")");
                    659: }
                    660:
                    661: void PRINTUP2(p)
                    662: UP2 p;
                    663: {
                    664:        int d,i;
                    665:
1.2       noro      666:        if ( !p ) {
                    667:                TAIL PRINTF(OUT,"0");
                    668:        } else {
1.1       noro      669:                d = degup2(p);
1.2       noro      670:                TAIL PRINTF(OUT,"(");
                    671:                if ( !d ) {
                    672:                        TAIL PRINTF(OUT,"1");
                    673:                } else if ( d == 1 ) {
                    674:                        TAIL PRINTF(OUT,"@");
                    675:                } else {
                    676:                        PUTS("@"); PRINTHAT; TAIL PRINTF(OUT,"%d",d);
                    677:                }
1.1       noro      678:                for ( i = d-1; i >= 0; i-- ) {
                    679:                        if ( p->b[i/BSH] & (1<<(i%BSH)) )
1.2       noro      680:                                if ( !i ) {
                    681:                                        TAIL PRINTF(OUT,"+1");
                    682:                                } else if ( i == 1 ) {
                    683:                                        TAIL PRINTF(OUT,"+@");
                    684:                                } else {
                    685:                                        PUTS("+@"); PRINTHAT; TAIL PRINTF(OUT,"%d",i);
                    686:                                }
1.1       noro      687:                }
1.2       noro      688:                TAIL PRINTF(OUT,")");
1.1       noro      689:        }
                    690: }
                    691:
                    692: void PRINTLF(vl,f)
                    693: VL vl;
                    694: F f;
                    695: {
                    696:        switch ( FOP(f) ) {
                    697:                case AL_TRUE:
                    698:                        TAIL PRINTF(OUT,"@true");
                    699:                        break;
                    700:                case AL_FALSE:
                    701:                        TAIL PRINTF(OUT,"@false");
                    702:                        break;
                    703:
                    704:                case AL_OR: case AL_AND:
                    705:                        PRINTFOP(vl,f); break;
                    706:                case AL_NOT: case AL_IMPL: case AL_REPL: case AL_EQUIV:
                    707:                        PRINTEOP(vl,f); break;
                    708:
                    709:                case AL_EQUAL: case AL_NEQ: case AL_LESSP:
                    710:                case AL_GREATERP: case AL_LEQ: case AL_GEQ:
                    711:                        PRINTLOP(vl,f); break;
                    712:
                    713:                case AL_EX: case AL_ALL:
                    714:                        PRINTQOP(vl,f); break;
                    715:                default:
                    716:                        break;
                    717:        }
                    718: }
                    719:
                    720: PRINTFOP(vl,f)
                    721: VL vl;
                    722: F f;
                    723: {
                    724:        char *op;
                    725:        NODE n;
                    726:
                    727:        op = FOP(f)==AL_OR?" @|| ":" @&& ";
                    728:        n = FJARG(f);
                    729:        PUTS("("); PRINTEXPR(vl,BDY(n)); PUTS(")");
                    730:        for ( n = NEXT(n); n; n = NEXT(n) ) {
                    731:                PUTS(op); PUTS("("); PRINTEXPR(vl,BDY(n)); PUTS(")");
                    732:        }
                    733: }
                    734:
                    735: PRINTEOP(vl,f)
                    736: VL vl;
                    737: F f;
                    738: {
                    739:        oFOP op;
                    740:        char *sop;
                    741:
                    742:        if ( (op = FOP(f)) == AL_NOT ) {
                    743:                PUTS("(@! "); PRINTEXPR(vl,(Obj)FARG(f)); PUTS(")"); return;
                    744:        }
                    745:        switch ( op ) {
                    746:                case AL_IMPL:
                    747:                        sop = " @impl "; break;
                    748:                case AL_REPL:
                    749:                        sop = " @repl "; break;
                    750:                case AL_EQUIV:
                    751:                        sop = " @equiv "; break;
                    752:                default:
                    753:                        break;
                    754:        }
                    755:        PUTS("(");
                    756:        PRINTEXPR(vl,(Obj)FLHS(f));
                    757:        PUTS(sop);
                    758:        PRINTEXPR(vl,(Obj)FRHS(f));
                    759:        PUTS(")");
                    760: }
                    761:
                    762: PRINTLOP(vl,f)
                    763: VL vl;
                    764: F f;
                    765: {
                    766:        char *op;
                    767:
                    768:        switch ( FOP(f) ) {
                    769:                case AL_EQUAL:
                    770:                        op = " @== "; break;
                    771:                case AL_NEQ:
                    772:                        op = " @!= "; break;
                    773:                case AL_LESSP:
                    774:                        op = " @< "; break;
                    775:                case AL_GREATERP:
                    776:                        op = " @> "; break;
                    777:                case AL_LEQ:
                    778:                        op = " @<= "; break;
                    779:                case AL_GEQ:
                    780:                        op = " @>= "; break;
                    781:                default:
                    782:                        error("PRINTLOP : invalid operator");
                    783:                        break;
                    784:        }
                    785:        PRINTEXPR(vl,(Obj)FPL(f)); PUTS(op); PUTS("0");
                    786: }
                    787:
                    788: PRINTQOP(vl,f)
                    789: VL vl;
                    790: F f;
                    791: {
                    792:        char *op;
                    793:
                    794:        op = FOP(f)==AL_EX?"ex":"all";
                    795:        TAIL PRINTF(OUT,"%s(%s,",op,NAME(FQVR(f)));
                    796:        PRINTEXPR(vl,(Obj)FQMAT(f)); PUTS(")");
                    797: }
                    798:
                    799: PRINTUP(n)
                    800: UP n;
                    801: {
                    802:        int i,d;
                    803:
                    804:        if ( !n )
                    805:                PUTS("0");
                    806:        else if ( !n->d )
                    807:                PRINTNUM(n->c[0]);
                    808:        else {
                    809:                d = n->d;
                    810:                PUTS("(");
                    811:                if ( !d ) {
                    812:                        PRINTNUM(n->c[d]);
                    813:                } else if ( d == 1 ) {
                    814:                        PRINTNUM(n->c[d]);
                    815:                        PUTS("*@p");
                    816:                } else {
                    817:                        PRINTNUM(n->c[d]);
1.2       noro      818:                        PUTS("*@p"); PRINTHAT; TAIL PRINTF(OUT,"%d",d);
1.1       noro      819:                }
                    820:                for ( i = d-1; i >= 0; i-- ) {
                    821:                        if ( n->c[i] ) {
                    822:                                PUTS("+("); PRINTNUM(n->c[i]); PUTS(")");
                    823:                                if ( i >= 2 ) {
1.2       noro      824:                                        PUTS("*@p"); PRINTHAT; TAIL PRINTF(OUT,"%d",i);
1.1       noro      825:                                } else if ( i == 1 )
                    826:                                        PUTS("*@p");
                    827:                        }
                    828:                }
                    829:                PUTS(")");
                    830:        }
                    831: }

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