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

Annotation of OpenXM_contrib2/asir2000/io/cpexpr.c, Revision 1.22

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.22    ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2000/io/cpexpr.c,v 1.21 2004/03/17 03:22:47 noro Exp $
1.3       noro       48: */
1.1       noro       49: #include "ca.h"
                     50: #include "parse.h"
1.2       noro       51: #include "al.h"
1.1       noro       52: #include "base.h"
1.16      noro       53: #if PARI
                     54: #include "genpari.h"
                     55: #endif
1.1       noro       56:
1.21      noro       57: #ifndef CPRINT
                     58: #define CPRINT
                     59: #endif
                     60:
1.8       noro       61: extern int hex_output,fortran_output,double_output,real_digit;
1.21      noro       62: extern int hideargs,outputstyle;
                     63: static int total_length;
1.2       noro       64:
1.1       noro       65: #define TAIL
                     66: #define PUTS(s) (total_length+=strlen(s))
                     67: #define PRINTN length_n
1.2       noro       68: #define PRINTBF length_bf
1.1       noro       69: #define PRINTCPLX length_cplx
1.2       noro       70: #define PRINTLM length_lm
                     71: #define PRINTUP2 length_up2
1.1       noro       72: #define PRINTV length_v
                     73: #define PRINTEXPR length_expr
                     74: #define PRINTNUM length_num
                     75: #define PRINTP length_p
                     76: #define PRINTR length_r
                     77: #define PRINTLIST length_list
                     78: #define PRINTVECT length_vect
                     79: #define PRINTMAT length_mat
                     80: #define PRINTSTR length_str
                     81: #define PRINTCOMP length_comp
                     82: #define PRINTDP length_dp
1.2       noro       83: #define PRINTUI length_ui
                     84: #define PRINTGF2MAT length_gf2mat
                     85: #define PRINTGFMMAT length_gfmmat
1.5       noro       86: #define PRINTBYTEARRAY length_bytearray
1.11      noro       87: #define PRINTQUOTE length_QUOTE
1.17      noro       88: #define PRINTSYMBOL length_SYMBOL
                     89: #define PRINTRANGE length_RANGE
1.18      noro       90: #define PRINTTB length_TB
1.22    ! noro       91: #define PRINTDPV length_DPV
1.2       noro       92: #define PRINTERR length_err
                     93: #define PRINTLF length_lf
                     94: #define PRINTLOP length_lop
                     95: #define PRINTFOP length_fop
                     96: #define PRINTEOP length_eop
                     97: #define PRINTQOP length_qop
                     98: #define PRINTUP length_up
1.12      noro       99: #define PRINTUM length_um
                    100: #define PRINTSF length_sf
1.19      noro      101: #define PRINTFARGS length_fargs
                    102: #define PRINTFNODENODE length_fnodenode
                    103: #define PRINTFNODE length_fnode
1.1       noro      104:
1.21      noro      105: #include "pexpr_body.c"
                    106:
                    107: /* special functions for estimating length */
1.1       noro      108:
                    109: static int total_length;
                    110:
1.13      noro      111: int estimate_length(VL vl,pointer p)
1.1       noro      112: {
                    113:        total_length = 0;
                    114:        PRINTEXPR(vl,p);
                    115:        return total_length;
                    116: }
                    117:
1.15      ohara     118: #if defined(PARI)
1.13      noro      119: void PRINTBF(BF a)
1.2       noro      120: {
                    121:        char *str;
1.7       noro      122:        char *GENtostr0();
                    123:        void myoutbrute();
1.2       noro      124:
1.7       noro      125:        if ( double_output ) {
                    126:                str = GENtostr0(a->body,myoutbrute);
                    127:        } else {
                    128:                str = GENtostr(a->body);
                    129:        }
1.2       noro      130:        total_length += strlen(str);
                    131:        free(str);
                    132: }
                    133: #endif
                    134:
1.13      noro      135: void PRINTNUM(Num q)
1.1       noro      136: {
                    137:        if ( !q ) {
                    138:                PUTS("0");
                    139:                return;
                    140:        }
                    141:        switch ( NID(q) ) {
                    142:                case N_Q:
                    143:                        if ( SGN((Q)q) == -1 )
                    144:                                PUTS("-");
                    145:                        PRINTN(NM((Q)q));
                    146:                        if ( !INT((Q)q) ) {
                    147:                                PUTS("/"); PRINTN(DN((Q)q));
                    148:                        }
                    149:                        break;
                    150:                case N_R:
1.7       noro      151:                        if ( double_output )
1.8       noro      152:                                total_length += 400+real_digit; /* XXX */
1.7       noro      153:                        else
1.8       noro      154:                                total_length += 20+real_digit; /* XXX */
1.1       noro      155:                        break;
                    156:                case N_A:
                    157:                        PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")");
                    158:                        break;
1.15      ohara     159: #if defined(PARI)
1.1       noro      160:                case N_B:
                    161:                        PRINTBF((BF)q); break;
                    162: #endif
                    163:                case N_C:
                    164:                        PRINTCPLX((C)q); break;
                    165:                case N_M:
1.2       noro      166:                        total_length += 11; /* XXX */
                    167:                        break;
                    168:                case N_LM:
                    169:                        PRINTN(((LM)q)->body); break;
                    170:                case N_GF2N:
                    171:                        if ( hex_output )
                    172:                                PRINTN((N)(((GF2N)q)->body));
                    173:                        else
                    174:                                PRINTUP2(((GF2N)q)->body);
                    175:                        break;
                    176:                case N_GFPN:
                    177:                        PRINTUP((UP)(((GFPN)q)->body));
1.9       noro      178:                        break;
                    179:                case N_GFS:
1.10      noro      180:                        total_length += 13; /* XXX */
1.2       noro      181:                        break;
1.12      noro      182:                case N_GFSN:
                    183:                        PRINTUM(BDY((GFSN)q));
                    184:                        break;
1.2       noro      185:                default:
1.1       noro      186:                        break;
                    187:        }
                    188: }
                    189:
1.13      noro      190: void PRINTV(VL vl,V v)
1.1       noro      191: {
                    192:        PF pf;
                    193:        PFAD ad;
                    194:        int i;
                    195:
                    196:        if ( NAME(v) )
                    197:                PUTS(NAME(v));
                    198:        else if ( (vid)v->attr == V_PF ) {
                    199:                pf = ((PFINS)v->priv)->pf; ad = ((PFINS)v->priv)->ad;
                    200:                if ( !strcmp(NAME(pf),"pow") ) {
1.14      noro      201:                        PUTS("(("); PRINTR(vl,(R)ad[0].arg); PUTS(")"); PRINTHAT; PUTS("(");
                    202:                        PRINTR(vl,(R)ad[1].arg); PUTS("))");
1.1       noro      203:                } else if ( !pf->argc )
                    204:                        PUTS(NAME(pf));
                    205:                else {
1.2       noro      206:                        if ( hideargs ) {
                    207:                                for ( i = 0; i < pf->argc; i++ )
                    208:                                        if ( ad[i].d )
                    209:                                                break;
                    210:                                if ( i < pf->argc ) {
                    211:                                        PUTS(NAME(pf));
1.1       noro      212:                                        total_length += 11; /* XXX */
1.2       noro      213:                                        for ( i = 1; i < pf->argc; i++ ) {
                    214:                                                total_length += 11; /* XXX */
                    215:                                        }
                    216:                                        PUTS("}");
                    217:                                } else {
                    218:                                        PUTS(NAME(pf));
                    219:                                        total_length += 1; /* XXX */
1.1       noro      220:                                }
                    221:                        } else {
1.2       noro      222:                                for ( i = 0; i < pf->argc; i++ )
                    223:                                        if ( ad[i].d )
                    224:                                                break;
                    225:                                if ( i < pf->argc ) {
                    226:                                        PUTS(NAME(pf));
                    227:                                        total_length += 11; /* XXX */
                    228:                                        for ( i = 1; i < pf->argc; i++ ) {
                    229:                                                total_length += 11; /* XXX */
                    230:                                        }
                    231:                                        PUTS(")(");
                    232:                                } else {
                    233:                                        PUTS(NAME(pf));
                    234:                                        total_length += 1; /* XXX */
                    235:                                }
                    236:                                PRINTR(vl,(R)ad[0].arg);
                    237:                                for ( i = 1; i < pf->argc; i++ ) {
                    238:                                        PUTS(","); PRINTR(vl,(R)ad[i].arg);
                    239:                                }
                    240:                                PUTS(")");
1.1       noro      241:                        }
                    242:                }
                    243:        }
                    244: }
                    245:
1.21      noro      246: void PRINTN(N n)
1.1       noro      247: {
1.21      noro      248:        double ceil();
                    249:
                    250:        if ( !n )
1.1       noro      251:                PUTS("0");
1.21      noro      252:        else if ( hex_output )
                    253:                total_length += 2+(int)(PL(n)*8);
1.1       noro      254:        else
1.21      noro      255:                total_length += (int)(ceil(0.31*((double)(BSH*PL(n))))+1);
1.1       noro      256: }
                    257:
1.13      noro      258: void PRINTSTR(STRING str)
1.1       noro      259: {
                    260:        char *p;
                    261:
                    262:        for ( p = BDY(str); *p; p++ )
                    263:                if ( *p == '"' )
                    264:                        PUTS("\"");
                    265:                else {
                    266:                        total_length += 1;
                    267:                }
                    268: }
                    269:
1.13      noro      270: void PRINTDP(VL vl,DP d)
1.1       noro      271: {
                    272:        int n,i;
                    273:        MP m;
                    274:        DL dl;
                    275:
                    276:        for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {
                    277:                PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");
                    278:                for ( i = 0, dl = m->dl; i < n-1; i++ ) {
                    279:                        total_length += 11;
                    280:                }
                    281:                total_length += 10;
                    282:                PUTS(">>");
                    283:                if ( NEXT(m) )
                    284:                        PUTS("+");
1.2       noro      285:        }
                    286: }
                    287:
1.13      noro      288: void PRINTUI(VL vl,USINT u)
1.2       noro      289: {
                    290:        total_length += 10;
                    291: }
                    292:
1.13      noro      293: void PRINTGFMMAT(VL vl,GFMMAT mat)
1.2       noro      294: {
                    295:        int row,col,i,j;
                    296:        unsigned int **b;
                    297:
                    298:        row = mat->row;
                    299:        col = mat->col;
                    300:        b = mat->body;
                    301:        for ( i = 0; i < row; i++ ) {
                    302:                PUTS("[");
                    303:                for ( j = 0; j < col; j++ ) {
                    304:                        total_length += 10; /* XXX */
                    305:                }
                    306:                PUTS("]\n");
                    307:        }
1.5       noro      308: }
                    309:
1.13      noro      310: void PRINTBYTEARRAY(VL vl,BYTEARRAY array)
1.5       noro      311: {
                    312:        /* |xx xx ... xx| */
1.6       noro      313:        total_length += 1+3*array->len;
1.11      noro      314: }
                    315:
1.19      noro      316: extern int print_quote;
                    317:
1.13      noro      318: void PRINTQUOTE(VL vl,QUOTE quote)
1.11      noro      319: {
1.19      noro      320:        LIST list;
                    321:
                    322:        if ( print_quote == 2 ) {
1.21      noro      323:                PRINTFNODE(BDY(quote),0);
1.19      noro      324:        } else if ( print_quote == 1 ) {
                    325:                /* XXX */
                    326:                fnodetotree(BDY(quote),&list);
                    327:                PRINTEXPR(vl,(Obj)list);
                    328:        } else {
                    329:                /* <...quoted...> */
                    330:                total_length += 20;
                    331:        }
1.17      noro      332: }
                    333:
                    334: void PRINTSYMBOL(SYMBOL sym)
                    335: {
                    336:        total_length += strlen(sym->name);
                    337: }
                    338:
1.18      noro      339: void PRINTTB(VL vl,TB p)
                    340: {
                    341:        int i;
                    342:
                    343:        for ( i = 0; i < p->next; i++ ) {
                    344:                total_length += strlen(p->body[i]);
                    345:        }
1.2       noro      346: }
                    347:
1.13      noro      348: void PRINTUP2(UP2 p)
1.2       noro      349: {
                    350:        int d,i;
                    351:
                    352:        if ( !p ) {
                    353:                PUTS("0");
                    354:        } else {
                    355:                d = degup2(p);
                    356:                PUTS("(");
                    357:                if ( !d ) {
                    358:                        PUTS("1");
                    359:                } else if ( d == 1 ) {
                    360:                        PUTS("@");
                    361:                } else {
                    362:                        PRINTHAT;
                    363:                        total_length += 11;
                    364:                }
                    365:                for ( i = d-1; i >= 0; i-- ) {
                    366:                        if ( p->b[i/BSH] & (1<<(i%BSH)) )
                    367:                                if ( !i ) {
                    368:                                        PUTS("+1");
                    369:                                } else if ( i == 1 ) {
                    370:                                        PUTS("+@");
                    371:                                } else {
                    372:                                        PRINTHAT;
                    373:                                        total_length += 12;
                    374:                                }
                    375:                }
                    376:                PUTS(")");
                    377:        }
                    378: }
                    379:
1.13      noro      380: void PRINTQOP(VL vl,F f)
1.2       noro      381: {
                    382:        char *op;
                    383:
                    384:        op = FOP(f)==AL_EX?"ex":"all";
                    385:        PUTS(op); PUTS(NAME(FQVR(f)));
                    386:        total_length += 2;
                    387:        PRINTEXPR(vl,(Obj)FQMAT(f)); PUTS(")");
                    388: }
                    389:
1.13      noro      390: void PRINTUP(UP n)
1.2       noro      391: {
                    392:        int i,d;
                    393:
                    394:        if ( !n )
                    395:                PUTS("0");
                    396:        else if ( !n->d )
                    397:                PRINTNUM(n->c[0]);
                    398:        else {
                    399:                d = n->d;
                    400:                PUTS("(");
                    401:                if ( !d ) {
                    402:                        PRINTNUM(n->c[d]);
                    403:                } else if ( d == 1 ) {
                    404:                        PRINTNUM(n->c[d]);
                    405:                        PUTS("*@p");
                    406:                } else {
                    407:                        PRINTNUM(n->c[d]);
                    408:                        PRINTHAT;
                    409:                        total_length += 13;
                    410:                }
                    411:                for ( i = d-1; i >= 0; i-- ) {
                    412:                        if ( n->c[i] ) {
                    413:                                PUTS("+("); PRINTNUM(n->c[i]); PUTS(")");
                    414:                                if ( i >= 2 ) {
                    415:                                        PRINTHAT;
                    416:                                        total_length += 13;
                    417:                                } else if ( i == 1 )
                    418:                                        PUTS("*@p");
                    419:                        }
                    420:                }
                    421:                PUTS(")");
1.1       noro      422:        }
1.12      noro      423: }
                    424:
1.13      noro      425: void PRINTUM(UM n)
1.12      noro      426: {
                    427:        int i,d;
                    428:
                    429:        if ( !n )
                    430:                PUTS("0");
                    431:        else if ( !n->d )
                    432:                PRINTSF(n->c[0]);
                    433:        else {
                    434:                d = n->d;
                    435:                PUTS("(");
                    436:                if ( !d ) {
                    437:                        PRINTSF(n->c[d]);
                    438:                } else if ( d == 1 ) {
                    439:                        PRINTSF(n->c[d]);
                    440:                        PUTS("*@s");
                    441:                } else {
                    442:                        PRINTSF(n->c[d]);
                    443:                        PUTS("*@s"); PRINTHAT; total_length += 13;
                    444:                }
                    445:                for ( i = d-1; i >= 0; i-- ) {
                    446:                        if ( n->c[i] ) {
                    447:                                PUTS("+("); PRINTSF(n->c[i]); PUTS(")");
                    448:                                if ( i >= 2 ) {
                    449:                                        PUTS("*@s"); PRINTHAT; total_length += 13;
                    450:                                } else if ( i == 1 )
                    451:                                        PUTS("*@s");
                    452:                        }
                    453:                }
                    454:                PUTS(")");
                    455:        }
                    456: }
                    457:
1.13      noro      458: void PRINTSF(unsigned int i)
1.12      noro      459: {
                    460:        if ( !i ) {
                    461:                PUTS("0");
                    462:        } else
                    463:                total_length += 15;
1.19      noro      464:
1.21      noro      465: #ifndef CPRINT
                    466: #define CPRINT
                    467: #endif
1.1       noro      468: }

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