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