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