Annotation of OpenXM_contrib2/asir2000/io/cio.c, Revision 1.11
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.11 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/cio.c,v 1.10 2001/08/31 09:17:13 noro Exp $
1.3 noro 48: */
1.1 noro 49: #include "ca.h"
50: #include "parse.h"
51: #include "ox.h"
52:
53: #define ISIZ sizeof(int)
54:
1.11 ! noro 55: int valid_as_cmo(Obj obj)
1.1 noro 56: {
57: NODE m;
58:
59: if ( !obj )
60: return 1;
61: switch ( OID(obj) ) {
62: case O_MATHCAP: case O_P: case O_R: case O_DP: case O_STR:
1.6 noro 63: case O_ERR: case O_USINT: case O_BYTEARRAY: case O_VOID:
1.1 noro 64: return 1;
65: case O_N:
1.2 noro 66: if ( NID((Num)obj) == N_Q || NID((Num)obj) == N_R )
1.1 noro 67: return 1;
68: else
69: return 0;
70: case O_LIST:
71: for ( m = BDY((LIST)obj); m; m = NEXT(m) )
72: if ( !valid_as_cmo(BDY(m)) )
73: return 0;
74: return 1;
1.7 noro 75: case O_QUOTE:
76: return 1;
1.1 noro 77: default:
78: return 0;
79: }
80: }
81:
1.11 ! noro 82: void write_cmo(FILE *s,Obj obj)
1.1 noro 83: {
84: int r;
85: char errmsg[BUFSIZ];
1.10 noro 86: LIST l;
1.1 noro 87:
88: if ( !obj ) {
89: r = CMO_NULL; write_int(s,&r);
90: return;
91: }
92: switch ( OID(obj) ) {
93: case O_N:
1.2 noro 94: switch ( NID((Num)obj) ) {
95: case N_Q:
96: write_cmo_q(s,(Q)obj);
97: break;
98: case N_R:
99: write_cmo_real(s,(Real)obj);
100: break;
101: default:
102: sprintf(errmsg, "write_cmo : number id=%d not implemented.",
103: NID((Num)obj));
104: error(errmsg);
105: break;
106: }
1.1 noro 107: break;
108: case O_P:
1.11 ! noro 109: write_cmo_p(s,(P)obj);
1.1 noro 110: break;
111: case O_R:
1.11 ! noro 112: write_cmo_r(s,(R)obj);
1.1 noro 113: break;
114: case O_DP:
1.11 ! noro 115: write_cmo_dp(s,(DP)obj);
1.1 noro 116: break;
117: case O_LIST:
1.11 ! noro 118: write_cmo_list(s,(LIST)obj);
1.1 noro 119: break;
120: case O_STR:
1.11 ! noro 121: write_cmo_string(s,(STRING)obj);
1.1 noro 122: break;
123: case O_USINT:
1.11 ! noro 124: write_cmo_uint(s,(USINT)obj);
1.1 noro 125: break;
126: case O_MATHCAP:
1.11 ! noro 127: write_cmo_mathcap(s,(MATHCAP)obj);
1.1 noro 128: break;
129: case O_ERR:
1.11 ! noro 130: write_cmo_error(s,(ERR)obj);
1.1 noro 131: break;
1.6 noro 132: case O_BYTEARRAY:
1.11 ! noro 133: write_cmo_bytearray(s,(BYTEARRAY)obj);
1.6 noro 134: break;
1.1 noro 135: case O_VOID:
136: r = ((USINT)obj)->body; write_int(s,&r);
137: break;
1.7 noro 138: case O_QUOTE:
1.10 noro 139: fnodetotree(BDY((QUOTE)obj),&l);
140: write_cmo_tree(s,l);
1.7 noro 141: break;
1.1 noro 142: default:
143: sprintf(errmsg, "write_cmo : id=%d not implemented.",OID(obj));
144: error(errmsg);
145: break;
146: }
1.5 noro 147: }
148:
1.11 ! noro 149: int cmo_tag(Obj obj,int *tag)
1.5 noro 150: {
151: if ( !valid_as_cmo(obj) )
152: return 0;
153: if ( !obj ) {
154: *tag = CMO_NULL;
155: return 1;
156: }
157: switch ( OID(obj) ) {
158: case O_N:
159: switch ( NID((Num)obj) ) {
160: case N_Q:
161: *tag = DN((Q)obj) ? CMO_QQ : CMO_ZZ; break;
162: case N_R:
163: *tag = CMO_IEEE_DOUBLE_FLOAT; break;
164: default:
165: return 0;
166: }
167: break;
168: case O_P:
169: *tag = CMO_RECURSIVE_POLYNOMIAL; break;
170: case O_R:
171: *tag = CMO_RATIONAL; break;
172: case O_DP:
173: *tag = CMO_DISTRIBUTED_POLYNOMIAL; break;
174: case O_LIST:
175: *tag = CMO_LIST; break;
176: case O_STR:
177: *tag = CMO_STRING; break;
178: case O_USINT:
179: *tag = CMO_INT32; break;
180: case O_MATHCAP:
181: *tag = CMO_MATHCAP; break;
182: case O_ERR:
183: *tag = CMO_ERROR2; break;
1.7 noro 184: case O_QUOTE:
185: *tag = CMO_TREE; break; break;
1.5 noro 186: default:
187: return 0;
188: }
189: return 1;
1.1 noro 190: }
191:
1.11 ! noro 192: void write_cmo_mathcap(FILE *s,MATHCAP mc)
1.1 noro 193: {
194: unsigned int r;
195:
196: r = CMO_MATHCAP; write_int(s,&r);
1.11 ! noro 197: write_cmo(s,(Obj)BDY(mc));
1.1 noro 198: }
199:
1.11 ! noro 200: void write_cmo_uint(FILE *s,USINT ui)
1.1 noro 201: {
202: unsigned int r;
203:
204: r = CMO_INT32; write_int(s,&r);
205: r = ui->body; write_int(s,&r);
206: }
207:
1.11 ! noro 208: void write_cmo_q(FILE *s,Q q)
1.1 noro 209: {
210: int r;
211:
212: if ( q && DN(q) ) {
213: r = CMO_QQ; write_int(s,&r);
214: write_cmo_zz(s,SGN(q),NM(q));
215: write_cmo_zz(s,1,DN(q));
216: } else {
217: r = CMO_ZZ; write_int(s,&r);
218: write_cmo_zz(s,SGN(q),NM(q));
219: }
220: }
221:
1.11 ! noro 222: void write_cmo_real(FILE *s,Real real)
1.2 noro 223: {
224: unsigned int r;
225: double dbl;
226:
227: r = CMO_IEEE_DOUBLE_FLOAT; write_int(s,&r);
228: dbl = real->body; write_double(s,&dbl);
229: }
230:
1.11 ! noro 231: void write_cmo_zz(FILE *s,int sgn,N n)
1.1 noro 232: {
1.11 ! noro 233: int l,bytes;
1.1 noro 234:
235: #if 1
236: l = PL(n);
237: bytes = sgn*l;
238: write_int(s,&bytes);
239: write_intarray(s,BD(n),l);
240: #else
241: l = PL(n); b = (unsigned int *)BD(n);
242: bytes = sgn*4*l;
243: write_int(s,&bytes);
244: for ( i = l-1; i >= 0; i-- ) {
245: t = b[i];
246: c = t>>24; write_char(s,&c);
247: c = (t>>16)&0xff; write_char(s,&c);
248: c = (t>>8)&0xff; write_char(s,&c);
249: c = t&0xff; write_char(s,&c);
250: }
251: #endif
252: }
253:
1.11 ! noro 254: void write_cmo_p(FILE *s,P p)
1.1 noro 255: {
256: int r,i;
257: VL t,vl;
258: char *namestr;
259: STRING name;
260:
261: r = CMO_RECURSIVE_POLYNOMIAL; write_int(s,&r);
262: get_vars((Obj)p,&vl);
263:
264: /* indeterminate list */
265: r = CMO_LIST; write_int(s,&r);
266: for ( t = vl, i = 0; t; t = NEXT(t), i++ );
267: write_int(s,&i);
268: r = CMO_INDETERMINATE;
269: for ( t = vl; t; t = NEXT(t) ) {
270: write_int(s,&r);
271: /* localname_to_cmoname(NAME(t->v),&namestr); */
272: namestr = NAME(t->v);
273: MKSTR(name,namestr);
1.11 ! noro 274: write_cmo(s,(Obj)name);
1.1 noro 275: }
276:
277: /* body */
278: write_cmo_upoly(s,vl,p);
279: }
280:
1.11 ! noro 281: void write_cmo_upoly(FILE *s,VL vl,P p)
1.1 noro 282: {
283: int r,i;
284: V v;
285: DCP dc,dct;
286: VL vlt;
287:
288: if ( NUM(p) )
1.11 ! noro 289: write_cmo(s,(Obj)p);
1.1 noro 290: else {
291: r = CMO_UNIVARIATE_POLYNOMIAL; write_int(s,&r);
292: v = VR(p);
293: dc = DC(p);
294: for ( i = 0, dct = dc; dct; dct = NEXT(dct), i++ );
295: write_int(s,&i);
296: for ( i = 0, vlt = vl; vlt->v != v; vlt = NEXT(vlt), i++ );
297: write_int(s,&i);
298: for ( dct = dc; dct; dct = NEXT(dct) ) {
299: i = QTOS(DEG(dct)); write_int(s,&i);
300: write_cmo_upoly(s,vl,COEF(dct));
301: }
302: }
303: }
304:
1.11 ! noro 305: void write_cmo_r(FILE *s,R f)
1.1 noro 306: {
307: int r;
308:
309: r = CMO_RATIONAL; write_int(s,&r);
1.11 ! noro 310: write_cmo(s,(Obj)NM(f));
! 311: write_cmo(s,(Obj)DN(f));
1.1 noro 312: }
313:
1.11 ! noro 314: void write_cmo_dp(FILE *s,DP dp)
1.1 noro 315: {
316: int i,n,nv,r;
317: MP m;
318:
319: for ( n = 0, m = BDY(dp); m; m = NEXT(m), n++ );
320: r = CMO_DISTRIBUTED_POLYNOMIAL; write_int(s,&r);
321: r = n; write_int(s,&r);
322: r = CMO_DMS_GENERIC; write_int(s,&r);
323: nv = dp->nv;
324: for ( i = 0, m = BDY(dp); i < n; i++, m = NEXT(m) )
325: write_cmo_monomial(s,m,nv);
326: }
327:
1.11 ! noro 328: void write_cmo_monomial(FILE *s,MP m,int n)
1.1 noro 329: {
330: int i,r;
331: int *p;
332:
333: r = CMO_MONOMIAL32; write_int(s,&r);
334: write_int(s,&n);
335: for ( i = 0, p = m->dl->d; i < n; i++ ) {
336: write_int(s,p++);
337: }
1.11 ! noro 338: write_cmo_q(s,(Q)m->c);
1.1 noro 339: }
340:
1.11 ! noro 341: void write_cmo_list(FILE *s,LIST list)
1.1 noro 342: {
343: NODE m;
344: int i,n,r;
345:
346: for ( n = 0, m = BDY(list); m; m = NEXT(m), n++ );
347: r = CMO_LIST; write_int(s,&r);
348: write_int(s,&n);
349: for ( i = 0, m = BDY(list); i < n; i++, m = NEXT(m) )
350: write_cmo(s,BDY(m));
351: }
352:
1.11 ! noro 353: void write_cmo_string(FILE *s,STRING str)
1.1 noro 354: {
355: int r;
356:
357: r = CMO_STRING; write_int(s,&r);
358: savestr(s,BDY(str));
359: }
360:
1.11 ! noro 361: void write_cmo_bytearray(FILE *s,BYTEARRAY array)
1.6 noro 362: {
363: int r;
364:
365: r = CMO_DATUM; write_int(s,&r);
366: write_int(s,&array->len);
367: write_string(s,array->body,array->len);
368: }
369:
1.11 ! noro 370: void write_cmo_error(FILE *s,ERR e)
1.1 noro 371: {
372: int r;
373:
374: r = CMO_ERROR2; write_int(s,&r);
375: write_cmo(s,BDY(e));
376: }
377:
1.7 noro 378: /* XXX */
379:
1.10 noro 380: /*
381: * BDY(l) = treenode
382: * treenode = [property,(name,)arglist]
383: * arglist = list of treenode
384: */
385:
1.11 ! noro 386: void write_cmo_tree(FILE *s,LIST l)
1.7 noro 387: {
1.10 noro 388: NODE n;
389: int r;
390: STRING prop,name,key;
1.7 noro 391:
1.10 noro 392: /* (CMO_TREE (CMO_LIST,n,key1,attr1,...,keyn,attn),(CMO_LIST,m,arg1,...,argm)) */
393: n = BDY(l);
394: prop = (STRING)BDY(n); n = NEXT(n);
395: if ( !strcmp(BDY(prop),"internal") ) {
396: write_cmo(s,(Obj)BDY(n));
397: } else {
398: if ( strcmp(BDY(prop),"list") ) {
399: r = CMO_TREE; write_int(s,&r);
400: name = (STRING)BDY(n);
401: n = NEXT(n);
402: /* function name */
1.11 ! noro 403: write_cmo(s,(Obj)name);
1.8 noro 404:
1.10 noro 405: /* attribute list */
1.7 noro 406: r = CMO_LIST; write_int(s,&r);
1.10 noro 407: r = 2; write_int(s,&r);
408: MKSTR(key,"asir");
1.11 ! noro 409: write_cmo(s,(Obj)key);
! 410: write_cmo(s,(Obj)prop);
1.10 noro 411: }
412:
413: /* argument list */
414: r = CMO_LIST; write_int(s,&r);
415: /* len = number of arguments */
416: r = length(n); write_int(s,&r);
417: while ( n ) {
418: write_cmo_tree(s,BDY(n));
419: n = NEXT(n);
420: }
1.7 noro 421: }
422: }
423:
1.11 ! noro 424: void read_cmo(FILE *s,Obj *rp)
1.1 noro 425: {
426: int id;
1.11 ! noro 427: int sgn,dummy;
! 428: Q q;
1.1 noro 429: N nm,dn;
430: P p,pnm,pdn;
1.2 noro 431: Real real;
432: double dbl;
1.1 noro 433: STRING str;
434: USINT t;
435: DP dp;
436: Obj obj;
437: ERR e;
438: MATHCAP mc;
1.6 noro 439: BYTEARRAY array;
1.10 noro 440: LIST list;
1.1 noro 441:
442: read_int(s,&id);
443: switch ( id ) {
444: /* level 0 objects */
445: case CMO_NULL:
446: *rp = 0;
447: break;
448: case CMO_INT32:
1.11 ! noro 449: read_cmo_uint(s,&t); *rp = (Obj)t;
1.1 noro 450: break;
451: case CMO_DATUM:
1.6 noro 452: loadbytearray(s,&array); *rp = (Obj)array;
453: break;
1.1 noro 454: case CMO_STRING:
455: loadstring(s,&str); *rp = (Obj)str;
456: break;
457: case CMO_MATHCAP:
458: read_cmo(s,&obj); MKMATHCAP(mc,(LIST)obj);
459: *rp = (Obj)mc;
460: break;
461: case CMO_ERROR:
462: MKERR(e,0); *rp = (Obj)e;
463: break;
464: case CMO_ERROR2:
465: read_cmo(s,&obj); MKERR(e,obj); *rp = (Obj)e;
466: break;
467: /* level 1 objects */
468: case CMO_LIST:
469: read_cmo_list(s,rp);
470: break;
471: case CMO_MONOMIAL32:
1.11 ! noro 472: read_cmo_monomial(s,&dp); *rp = (Obj)dp;
1.1 noro 473: break;
474: case CMO_ZZ:
475: read_cmo_zz(s,&sgn,&nm);
476: NTOQ(nm,sgn,q); *rp = (Obj)q;
477: break;
478: case CMO_QQ:
479: read_cmo_zz(s,&sgn,&nm);
480: read_cmo_zz(s,&dummy,&dn);
481: NDTOQ(nm,dn,sgn,q); *rp = (Obj)q;
1.2 noro 482: break;
483: case CMO_IEEE_DOUBLE_FLOAT:
484: read_double(s,&dbl); MKReal(dbl,real); *rp = (Obj)real;
1.1 noro 485: break;
486: case CMO_DISTRIBUTED_POLYNOMIAL:
487: read_cmo_dp(s,&dp); *rp = (Obj)dp;
488: break;
489: case CMO_RECURSIVE_POLYNOMIAL:
490: read_cmo_p(s,&p); *rp = (Obj)p;
491: break;
492: case CMO_UNIVARIATE_POLYNOMIAL:
493: read_cmo_upoly(s,&p); *rp = (Obj)p;
494: break;
495: case CMO_INDETERMINATE:
1.11 ! noro 496: read_cmo(s,rp);
1.1 noro 497: break;
498: case CMO_RATIONAL:
1.11 ! noro 499: read_cmo(s,&obj); pnm = (P)obj;
! 500: read_cmo(s,&obj); pdn = (P)obj;
1.1 noro 501: divr(CO,(Obj)pnm,(Obj)pdn,rp);
502: break;
503: case CMO_ZERO:
504: *rp = 0;
505: break;
506: case CMO_DMS_OF_N_VARIABLES:
507: read_cmo(s,rp);
508: break;
509: case CMO_RING_BY_NAME:
510: read_cmo(s,rp);
511: break;
1.7 noro 512: case CMO_TREE:
1.10 noro 513: read_cmo_tree_as_list(s,&list);
514: #if 0
515: treetofnode(list,&fn);
1.8 noro 516: MKQUOTE(quote,fn);
517: *rp = (Obj)quote;
1.10 noro 518: #else
1.11 ! noro 519: *rp = (Obj)list;
1.10 noro 520: #endif
1.7 noro 521: break;
1.1 noro 522: default:
523: MKUSINT(t,id);
524: t->id = O_VOID;
525: *rp = (Obj)t;
526: break;
527: }
528: }
529:
1.11 ! noro 530: void read_cmo_uint(FILE *s,USINT *rp)
1.1 noro 531: {
532: unsigned int body;
533:
534: read_int(s,&body);
535: MKUSINT(*rp,body);
536: }
537:
1.11 ! noro 538: void read_cmo_zz(FILE *s,int *sgn,N *rp)
1.1 noro 539: {
1.11 ! noro 540: int l;
1.1 noro 541: N n;
542:
543: read_int(s,&l);
544: if ( l == 0 ) {
545: *sgn = 0;
546: *rp = 0;
547: return;
548: }
549: if ( l < 0 ) {
550: *sgn = -1; l = -l;
551: } else
552: *sgn = 1;
553: #if 1
554: *rp = n = NALLOC(l); PL(n) = l;
555: read_intarray(s,BD(n),l);
556: #else
557: words = (l+3)/4;
558: *rp = n = NALLOC(words); PL(n) = words; b = BD(n);
559: h = 0;
560: switch ( l % 4 ) {
561: case 0:
562: read_char(s,&c); h = c;
563: case 3:
564: read_char(s,&c); h = (h<<8)|c;
565: case 2:
566: read_char(s,&c); h = (h<<8)|c;
567: case 1:
568: read_char(s,&c); h = (h<<8)|c;
569: }
570: b[words-1] = h;
571: for ( i = words-2; i >= 0; i-- ) {
572: read_char(s,&c); h = c;
573: read_char(s,&c); h = (h<<8)|c;
574: read_char(s,&c); h = (h<<8)|c;
575: read_char(s,&c); h = (h<<8)|c;
576: b[i] = h;
577: }
578: #endif
579: }
580:
1.11 ! noro 581: void read_cmo_list(FILE *s,Obj *rp)
1.1 noro 582: {
583: int len;
584: Obj *w;
585: int i;
586: NODE n0,n1;
587: LIST list;
588:
589: read_int(s,&len);
590: w = (Obj *)ALLOCA(len*sizeof(Obj));
591: for ( i = 0; i < len; i++ )
592: read_cmo(s,&w[i]);
593: for ( i = len-1, n0 = 0; i >= 0; i-- ) {
594: MKNODE(n1,w[i],n0); n0 = n1;
595: }
596: MKLIST(list,n0);
597: *rp = (Obj)list;
598: }
599:
1.11 ! noro 600: void read_cmo_dp(FILE *s,DP *rp)
1.1 noro 601: {
602: int len;
603: int i;
604: MP mp0,mp;
605: int nv,d;
606: DP dp;
607: Obj obj;
608:
609: read_int(s,&len);
610: /* skip the ring definition */
611: read_cmo(s,&obj);
612: for ( mp0 = 0, i = 0, d = 0; i < len; i++ ) {
1.11 ! noro 613: read_cmo(s,&obj); dp = (DP)obj;
1.1 noro 614: if ( !mp0 ) {
615: nv = dp->nv;
616: mp0 = dp->body;
617: mp = mp0;
618: } else {
619: NEXT(mp) = dp->body;
620: mp = NEXT(mp);
621: }
622: d = MAX(d,dp->sugar);
623: }
624: MKDP(nv,mp0,dp);
625: dp->sugar = d; *rp = dp;
626: }
627:
1.11 ! noro 628: void read_cmo_monomial(FILE *s,DP *rp)
1.1 noro 629: {
1.11 ! noro 630: Obj obj;
1.1 noro 631: MP m;
632: DP dp;
633: int i,sugar,n;
634: DL dl;
635:
636: read_int(s,&n);
637: NEWMP(m); NEWDL(dl,n); m->dl = dl;
638: read_intarray(s,dl->d,n);
639: for ( sugar = 0, i = 0; i < n; i++ )
640: sugar += dl->d[i];
641: dl->td = sugar;
1.11 ! noro 642: read_cmo(s,&obj); m->c = (P)obj;
1.1 noro 643: NEXT(m) = 0; MKDP(n,m,dp); dp->sugar = sugar; *rp = dp;
644: }
645:
646: static V *remote_vtab;
647:
1.11 ! noro 648: void read_cmo_p(FILE *s,P *rp)
1.1 noro 649: {
1.11 ! noro 650: Obj obj;
1.1 noro 651: LIST vlist;
652: int nv,i;
653: V *vtab;
654: V v1,v2;
655: NODE t;
656: P v,p;
657: VL tvl,rvl;
658: char *name;
659:
1.11 ! noro 660: read_cmo(s,&obj); vlist = (LIST)obj;
1.1 noro 661: nv = length(BDY(vlist));
662: vtab = (V *)ALLOCA(nv*sizeof(V));
663: for ( i = 0, t = BDY(vlist); i < nv; t = NEXT(t), i++ ) {
664: /* cmoname_to_localname(BDY((STRING)BDY(t)),&name); */
665: name = BDY((STRING)BDY(t));
666: makevar(name,&v); vtab[i] = VR(v);
667: }
668: remote_vtab = vtab;
1.11 ! noro 669: read_cmo(s,&obj); p = (P)obj;
1.1 noro 670: for ( i = 0; i < nv-1; i++ ) {
671: v1 = vtab[i]; v2 = vtab[i+1];
672: for ( tvl = CO; tvl->v != v1 && tvl->v != v2; tvl = NEXT(tvl) );
673: if ( tvl->v == v2 )
674: break;
675: }
676: if ( i < nv-1 ) {
677: for ( i = nv-1, rvl = 0; i >= 0; i-- ) {
678: NEWVL(tvl); tvl->v = vtab[i]; NEXT(tvl) = rvl; rvl = tvl;
679: }
680: reorderp(CO,rvl,p,rp);
681: } else
682: *rp = p;
683: }
684:
1.11 ! noro 685: void read_cmo_upoly(FILE *s,P *rp)
1.1 noro 686: {
687: int n,ind,i,d;
1.11 ! noro 688: Obj obj;
1.1 noro 689: P c;
690: Q q;
691: DCP dc0,dc;
692:
693: read_int(s,&n);
694: read_int(s,&ind);
695: for ( i = 0, dc0 = 0; i < n; i++ ) {
696: read_int(s,&d);
1.11 ! noro 697: read_cmo(s,&obj); c = (P)obj;
1.1 noro 698: if ( c ) {
699: if ( OID(c) == O_USINT ) {
700: UTOQ(((USINT)c)->body,q); c = (P)q;
701: }
702: NEXTDC(dc0,dc);
703: STOQ(d,q);
704: dc->c = c; dc->d = q;
705: }
706: }
707: if ( dc0 )
708: NEXT(dc) = 0;
709: MKP(remote_vtab[ind],dc0,*rp);
1.7 noro 710: }
711:
712: /* XXX */
713:
714: extern struct oARF arf[];
715:
716: struct operator_tab {
717: char *name;
718: fid id;
719: ARF arf;
720: cid cid;
721: };
722:
723: static struct operator_tab optab[] = {
724: {"+",I_BOP,&arf[0],0}, /* XXX */
725: {"-",I_BOP,&arf[1],0},
726: {"*",I_BOP,&arf[2],0},
727: {"/",I_BOP,&arf[3],0},
728: {"%",I_BOP,&arf[4],0},
729: {"^",I_BOP,&arf[5],0},
730: {"==",I_COP,0,C_EQ},
731: {"!=",I_COP,0,C_NE},
732: {"<",I_COP,0,C_LT},
733: {"<=",I_COP,0,C_LE},
734: {">",I_COP,0,C_GT},
735: {">=",I_COP,0,C_GE},
736: {"&&",I_AND,0,0},
737: {"||",I_OR,0,0},
738: {"!",I_NOT,0,0},
739: };
740:
741: static int optab_len = sizeof(optab)/sizeof(struct operator_tab);
742:
1.10 noro 743: #if 0
744: /* old code */
1.11 ! noro 745: void read_cmo_tree(s,rp)
1.7 noro 746: FILE *s;
1.8 noro 747: FNODE *rp;
1.7 noro 748: {
749: int r,i,n;
750: char *opname;
751: STRING name,cd;
752: int op;
1.8 noro 753: pointer *arg;
1.7 noro 754: QUOTE quote;
755: FNODE fn;
1.8 noro 756: NODE t,t1;
1.7 noro 757: fid id;
1.8 noro 758: Obj expr;
759: FUNC func;
1.7 noro 760:
761: read_cmo(s,&name);
1.10 noro 762: read_cmo(s,&attr);
1.7 noro 763: for ( i = 0; i < optab_len; i++ )
764: if ( !strcmp(optab[i].name,BDY(name)) )
765: break;
766: if ( i == optab_len ) {
767: /* may be a function name */
1.8 noro 768: n = read_cmo_tree_arg(s,&arg);
769: for ( i = n-1, t = 0; i >= 0; i-- ) {
770: MKNODE(t1,arg[i],t); t = t1;
771: }
772: searchf(sysf,BDY(name),&func);
773: if ( !func )
774: searchf(ubinf,BDY(name),&func);
775: if ( !func )
776: searchpf(BDY(name),&func);
777: if ( !func )
778: searchf(usrf,BDY(name),&func);
779: if ( !func )
780: appenduf(BDY(name),&func);
781: *rp = mkfnode(2,I_FUNC,func,mkfnode(1,I_LIST,t));
1.7 noro 782: } else {
783: opname = optab[i].name;
784: id = optab[i].id;
785: switch ( id ) {
786: case I_BOP:
1.8 noro 787: read_cmo_tree_arg(s,&arg);
788: *rp = mkfnode(3,I_BOP,optab[i].arf,arg[0],arg[1]);
789: return;
1.7 noro 790: case I_COP:
1.8 noro 791: read_cmo_tree_arg(s,&arg);
792: *rp = mkfnode(3,I_COP,optab[i].cid,arg[0],arg[0]);
793: return;
1.7 noro 794: case I_AND:
1.8 noro 795: read_cmo_tree_arg(s,&arg);
796: *rp = mkfnode(2,I_AND,arg[0],arg[1]);
797: return;
1.7 noro 798: case I_OR:
1.8 noro 799: read_cmo_tree_arg(s,&arg);
800: *rp = mkfnode(2,I_OR,arg[0],arg[1]);
801: return;
1.7 noro 802: case I_NOT:
1.8 noro 803: read_cmo_tree_arg(s,&arg);
804: *rp = mkfnode(1,I_OR,arg[0]);
805: return;
1.7 noro 806: }
807: }
1.8 noro 808: }
809:
810: int read_cmo_tree_arg(s,argp)
811: FILE *s;
812: pointer **argp;
813: {
814: int id,n,i;
815: pointer *ap;
816: Obj t;
817:
818: read_int(s,&id); /* id = CMO_LIST */
819: read_int(s,&n); /* n = the number of args */
820: *argp = ap = (pointer *) MALLOC(n*sizeof(pointer));
821: for ( i = 0; i < n; i++ ) {
822: read_cmo(s,&t);
823: if ( !t || (OID(t) != O_QUOTE) )
824: ap[i] = mkfnode(1,I_FORMULA,t);
825: else
826: ap[i] = BDY((QUOTE)t);
827: }
828: return n;
1.1 noro 829: }
1.10 noro 830: #else
1.11 ! noro 831: void read_cmo_tree_as_list(FILE *s,LIST *rp)
1.10 noro 832: {
1.11 ! noro 833: Obj obj;
1.10 noro 834: STRING name;
835: LIST attr,args;
836: NODE t0,t1;
837:
1.11 ! noro 838: read_cmo(s,&obj); name = (STRING)obj;
! 839: read_cmo(s,&obj); attr = (LIST)obj;
! 840: read_cmo(s,&obj); args = (LIST)obj;
1.10 noro 841: MKNODE(t1,name,BDY(args));
842: MKNODE(t0,attr,t1);
843: MKLIST(*rp,t0);
844: }
845: #endif
1.1 noro 846:
1.11 ! noro 847: void localname_to_cmoname(char *a,char **b)
1.1 noro 848: {
849: int l;
850: char *t;
851:
852: l = strlen(a);
853: if ( l >= 2 && a[0] == '@' && isupper(a[1]) ) {
854: t = *b = (char *)MALLOC_ATOMIC(l);
855: strcpy(t,a+1);
856: } else {
857: t = *b = (char *)MALLOC_ATOMIC(l+1);
858: strcpy(t,a);
859: }
860: }
861:
1.11 ! noro 862: void cmoname_to_localname(char *a,char **b)
1.1 noro 863: {
864: int l;
865: char *t;
866:
867: l = strlen(a);
868: if ( isupper(a[0]) ) {
869: t = *b = (char *)MALLOC_ATOMIC(l+2);
870: strcpy(t+1,a);
871: t[0] = '@';
872: } else {
873: t = *b = (char *)MALLOC_ATOMIC(l+1);
874: strcpy(t,a);
875: }
876: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>