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

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

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