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