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

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

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