Annotation of OpenXM/src/ox_toolkit/ox.c, Revision 1.31
1.1 ohara 1: /* -*- mode: C; coding: euc-japan -*- */
1.31 ! iwane 2: /* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.30 2003/11/09 01:48:01 iwane Exp $ */
1.1 ohara 3:
1.8 ohara 4: /*
5: This module includes functions for sending/receiveng CMO's.
6: Some commnets is written in Japanese by the EUC-JP coded
7: character set.
1.1 ohara 8: */
9:
10: #include <stdio.h>
11: #include <stdlib.h>
1.20 ohara 12: #include <stdarg.h>
1.1 ohara 13: #include <string.h>
14: #include <unistd.h>
15: #include <fcntl.h>
1.5 ohara 16: #include <sys/file.h>
1.13 ohara 17: #include <time.h>
1.1 ohara 18:
19: #include "mysocket.h"
1.12 ohara 20: #include "ox_toolkit.h"
1.1 ohara 21: #include "parse.h"
22:
1.20 ohara 23: static FILE *ox_stderr = NULL;
24:
1.17 ohara 25: /* sorting by the value of CMO_xxx. (for debugging) */
1.13 ohara 26: static cmo_null* receive_cmo_null(OXFILE *oxfp);
27: static cmo_int32* receive_cmo_int32(OXFILE *oxfp);
28: static cmo_string* receive_cmo_string(OXFILE *oxfp);
29: static cmo_mathcap* receive_cmo_mathcap(OXFILE *oxfp);
30: static cmo_list* receive_cmo_list(OXFILE *oxfp);
31: static cmo_monomial32* receive_cmo_monomial32(OXFILE *oxfp);
32: static cmo_zero* receive_cmo_zero(OXFILE *oxfp);
33: static cmo_dms_generic* receive_cmo_dms_generic(OXFILE *oxfp);
34: static cmo_ring_by_name* receive_cmo_ring_by_name(OXFILE *oxfp);
35: static cmo_distributed_polynomial* receive_cmo_distributed_polynomial(OXFILE *oxfp);
1.26 ohara 36: static cmo_recursive_polynomial* receive_cmo_recursive_polynomial(OXFILE *oxfp);
37: static cmo_polynomial_in_one_variable* receive_cmo_polynomial_in_one_variable(OXFILE *oxfp);
1.13 ohara 38: static cmo_error2* receive_cmo_error2(OXFILE *oxfp);
39:
40: static int send_cmo_null(OXFILE *oxfp, cmo_null* c);
41: static int send_cmo_int32(OXFILE *oxfp, cmo_int32* m);
42: static int send_cmo_string(OXFILE *oxfp, cmo_string* m);
43: static int send_cmo_mathcap(OXFILE *oxfp, cmo_mathcap* c);
44: static int send_cmo_list(OXFILE *oxfp, cmo_list* c);
45: static int send_cmo_monomial32(OXFILE *oxfp, cmo_monomial32* c);
1.22 ohara 46: static int send_cmo_error2(OXFILE *oxfp, cmo_error2* c);
47: static int send_cmo_distributed_polynomial(OXFILE *oxfp, cmo_distributed_polynomial* c);
1.26 ohara 48: static int send_cmo_polynomial_in_one_variable(OXFILE *oxfp, cmo_polynomial_in_one_variable* c);
49: static int send_cmo_recursive_polynomial(OXFILE *oxfp, cmo_recursive_polynomial* c);
1.22 ohara 50:
51: static cmo_zz* receive_cmo_zz(OXFILE *oxfp);
52: static void receive_mpz(OXFILE *oxfp, mpz_ptr mpz);
1.13 ohara 53: static int send_cmo_zz(OXFILE *oxfp, cmo_zz* c);
54: static int send_mpz(OXFILE *oxfp, mpz_ptr mpz);
1.3 ohara 55:
1.8 ohara 56: /* hook functions. (yet not implemented) */
1.2 ohara 57: static hook_t hook_before_send_cmo = NULL;
58: static hook_t hook_after_send_cmo = NULL;
59:
60: int add_hook_before_send_cmo(hook_t func)
61: {
1.13 ohara 62: hook_before_send_cmo = func;
63: return 0;
1.2 ohara 64: }
65:
66: int add_hook_after_send_cmo(hook_t func)
67: {
1.13 ohara 68: hook_after_send_cmo = func;
69: return 0;
1.2 ohara 70: }
71:
1.13 ohara 72: static cmo *call_hook_before_send_cmo(OXFILE *oxfp, cmo *c)
1.2 ohara 73: {
1.13 ohara 74: if (hook_before_send_cmo != NULL) {
75: return hook_before_send_cmo(oxfp, c);
76: }
77: return c;
1.2 ohara 78: }
79:
1.13 ohara 80: static cmo *call_hook_after_send_cmo(OXFILE *oxfp, cmo *c)
1.2 ohara 81: {
1.13 ohara 82: if (hook_after_send_cmo != NULL) {
83: return hook_after_send_cmo(oxfp, c);
84: }
85: return c;
1.2 ohara 86: }
1.1 ohara 87:
1.7 ohara 88: /* Handling an error. */
1.1 ohara 89: static int current_received_serial = 0;
90:
1.7 ohara 91: /* If an error object be needed, then a server call the following function. */
1.1 ohara 92: cmo_error2* make_error_object(int err_code, cmo *ob)
93: {
94: cmo_list* li = new_cmo_list();
1.13 ohara 95: list_append(li, (cmo *)new_cmo_int32(current_received_serial));
96: list_append(li, (cmo *)new_cmo_int32(err_code));
97: list_append(li, ob);
1.1 ohara 98: return new_cmo_error2((cmo *)li);
99: }
100:
1.7 ohara 101: /* getting a next serial number. */
1.13 ohara 102: int next_serial(OXFILE *oxfp)
1.1 ohara 103: {
1.13 ohara 104: return oxfp->serial_number++;
1.1 ohara 105: }
106:
1.7 ohara 107: /* sending an object of int32 type. (not equal to cmo_int32 type) */
1.13 ohara 108: int send_int32(OXFILE *oxfp, int int32)
1.1 ohara 109: {
1.13 ohara 110: return oxfp->send_int32(oxfp, int32);
1.1 ohara 111: }
112:
1.13 ohara 113: /* receiving an object of int32 type. (not equal to cmo_int32 type) */
114: int receive_int32(OXFILE *oxfp)
1.1 ohara 115: {
1.13 ohara 116: return oxfp->receive_int32(oxfp);
1.1 ohara 117: }
118:
1.13 ohara 119: /* receiving an (OX_tag, serial number) */
120: int receive_ox_tag(OXFILE *oxfp)
1.1 ohara 121: {
1.13 ohara 122: int tag = receive_int32(oxfp);
1.16 ohara 123: oxfp->received_serial_number = receive_int32(oxfp);
1.13 ohara 124: return tag;
1.1 ohara 125: }
126:
1.13 ohara 127: /* sending an (OX_tag, serial number) */
128: int send_ox_tag(OXFILE *oxfp, int tag)
1.3 ohara 129: {
1.13 ohara 130: send_int32(oxfp, tag);
131: return send_int32(oxfp, next_serial(oxfp));
1.1 ohara 132: }
133:
1.7 ohara 134: /* functions named receive_cmo_*. */
1.13 ohara 135: static cmo_null* receive_cmo_null(OXFILE *oxfp)
1.1 ohara 136: {
137: return new_cmo_null();
138: }
139:
1.13 ohara 140: static cmo_int32* receive_cmo_int32(OXFILE *oxfp)
1.1 ohara 141: {
1.13 ohara 142: int i = receive_int32(oxfp);
1.1 ohara 143: return new_cmo_int32(i);
144: }
145:
1.13 ohara 146: static cmo_string* receive_cmo_string(OXFILE *oxfp)
1.1 ohara 147: {
1.13 ohara 148: int len = receive_int32(oxfp);
1.25 ohara 149: char* s = MALLOC(len+1);
1.1 ohara 150: memset(s, '\0', len+1);
151: if (len > 0) {
1.13 ohara 152: oxf_read(s, 1, len, oxfp);
1.1 ohara 153: }
154: return new_cmo_string(s);
155: }
156:
1.13 ohara 157: static cmo_mathcap* receive_cmo_mathcap(OXFILE *oxfp)
1.1 ohara 158: {
1.13 ohara 159: cmo* ob = receive_cmo(oxfp);
1.1 ohara 160: return new_cmo_mathcap(ob);
161: }
162:
1.13 ohara 163: static cmo_list* receive_cmo_list(OXFILE *oxfp)
1.1 ohara 164: {
165: cmo* ob;
166: cmo_list* c = new_cmo_list();
1.13 ohara 167: int len = receive_int32(oxfp);
1.1 ohara 168:
169: while (len>0) {
1.13 ohara 170: ob = receive_cmo(oxfp);
171: list_append(c, ob);
1.1 ohara 172: len--;
173: }
174: return c;
175: }
176:
1.13 ohara 177: static cmo_monomial32* receive_cmo_monomial32(OXFILE *oxfp)
1.1 ohara 178: {
179: int i;
1.13 ohara 180: int len = receive_int32(oxfp);
1.1 ohara 181: cmo_monomial32* c = new_cmo_monomial32(len);
182:
183: for(i=0; i<len; i++) {
1.13 ohara 184: c->exps[i] = receive_int32(oxfp);
1.1 ohara 185: }
1.13 ohara 186: c->coef = receive_cmo(oxfp);
1.1 ohara 187: return c;
188: }
189:
1.13 ohara 190: static cmo_zz* receive_cmo_zz(OXFILE *oxfp)
1.1 ohara 191: {
192: cmo_zz* c = new_cmo_zz();
1.13 ohara 193: receive_mpz(oxfp, c->mpz);
1.1 ohara 194: return c;
195: }
196:
1.13 ohara 197: static cmo_zero* receive_cmo_zero(OXFILE *oxfp)
1.1 ohara 198: {
199: return new_cmo_zero();
200: }
201:
1.13 ohara 202: static cmo_dms_generic* receive_cmo_dms_generic(OXFILE *oxfp)
1.1 ohara 203: {
204: return new_cmo_dms_generic();
205: }
206:
1.13 ohara 207: static cmo_ring_by_name* receive_cmo_ring_by_name(OXFILE *oxfp)
1.1 ohara 208: {
1.13 ohara 209: cmo* ob = receive_cmo(oxfp);
210: /* We need to check semantics but yet ... */
1.1 ohara 211: return new_cmo_ring_by_name(ob);
212: }
213:
1.26 ohara 214: static cmo_recursive_polynomial* receive_cmo_recursive_polynomial(OXFILE *oxfp)
215: {
1.27 ohara 216: cmo_list* ringdef = (cmo_list *)receive_cmo(oxfp);
217: cmo* coef = receive_cmo(oxfp);
1.26 ohara 218: return new_cmo_recursive_polynomial(ringdef, coef);
219: }
220:
1.13 ohara 221: static cmo_distributed_polynomial* receive_cmo_distributed_polynomial(OXFILE *oxfp)
1.1 ohara 222: {
223: cmo* ob;
224: cmo_distributed_polynomial* c = new_cmo_distributed_polynomial();
1.13 ohara 225: int len = receive_int32(oxfp);
226: c->ringdef = receive_cmo(oxfp);
1.1 ohara 227:
228: while (len>0) {
1.13 ohara 229: ob = receive_cmo(oxfp);
230: list_append((cmo_list *)c, ob);
1.1 ohara 231: len--;
232: }
233: return c;
234: }
235:
1.26 ohara 236: static cmo_polynomial_in_one_variable* receive_cmo_polynomial_in_one_variable(OXFILE *oxfp)
237: {
238: cmo* coef;
239: cmo_polynomial_in_one_variable* c;
240: int len = receive_int32(oxfp);
241: int var = receive_int32(oxfp);
242: int exp;
243: c = new_cmo_polynomial_in_one_variable(var);
244: while (len>0) {
245: exp = receive_int32(oxfp);
246: coef = receive_cmo(oxfp);
1.27 ohara 247: list_append_monomial((cmo_list *)c, coef, exp);
1.26 ohara 248: len--;
249: }
250: return c;
251: }
252:
1.29 ohara 253: static cmo_indeterminate* receive_cmo_indeterminate(OXFILE *oxfp)
254: {
255: cmo* ob = receive_cmo(oxfp);
256: return new_cmo_indeterminate(ob);
257: }
258:
1.28 ohara 259: static cmo_tree* receive_cmo_tree(OXFILE *oxfp)
260: {
261: cmo_string* name = (cmo_string *)receive_cmo(oxfp);
262: cmo_list* attrib = (cmo_list *)receive_cmo(oxfp);
263: cmo_list* leaves = (cmo_list *)receive_cmo(oxfp);
264: return new_cmo_tree(name, attrib, leaves);
265: }
266:
267: static cmo_lambda* receive_cmo_lambda(OXFILE *oxfp)
268: {
269: cmo_list* args = (cmo_list *)receive_cmo(oxfp);
270: cmo_tree* body = (cmo_tree *)receive_cmo(oxfp);
271: return new_cmo_lambda(args, body);
272: }
273:
1.13 ohara 274: static cmo_error2* receive_cmo_error2(OXFILE *oxfp)
1.1 ohara 275: {
1.13 ohara 276: cmo* ob = receive_cmo(oxfp);
1.1 ohara 277: return new_cmo_error2(ob);
278: }
279:
1.17 ohara 280: /* receive_cmo() is called after receive_ox_tag(). */
1.13 ohara 281: cmo* receive_cmo(OXFILE *oxfp)
1.1 ohara 282: {
1.24 ohara 283: int tag = receive_int32(oxfp);
284: return receive_cmo_tag(oxfp, tag);
285: }
286:
287: cmo *receive_cmo_tag(OXFILE *oxfp, int tag)
288: {
1.1 ohara 289: cmo* m;
290: switch(tag) {
291: case CMO_NULL:
1.13 ohara 292: m = receive_cmo_null(oxfp);
1.1 ohara 293: break;
294: case CMO_INT32:
1.13 ohara 295: m = (cmo *)receive_cmo_int32(oxfp);
1.1 ohara 296: break;
297: case CMO_STRING:
1.13 ohara 298: m = (cmo *)receive_cmo_string(oxfp);
1.1 ohara 299: break;
300: case CMO_MATHCAP:
1.13 ohara 301: m = (cmo *)receive_cmo_mathcap(oxfp);
1.1 ohara 302: break;
303: case CMO_LIST:
1.13 ohara 304: m = (cmo *)receive_cmo_list(oxfp);
1.1 ohara 305: break;
306: case CMO_MONOMIAL32:
1.13 ohara 307: m = (cmo *)receive_cmo_monomial32(oxfp);
1.1 ohara 308: break;
309: case CMO_ZZ:
1.13 ohara 310: m = (cmo *)receive_cmo_zz(oxfp);
1.1 ohara 311: break;
312: case CMO_ZERO:
1.13 ohara 313: m = (cmo *)receive_cmo_zero(oxfp);
1.1 ohara 314: break;
315: case CMO_DMS_GENERIC:
1.13 ohara 316: m = (cmo *)receive_cmo_dms_generic(oxfp);
1.1 ohara 317: break;
318: case CMO_RING_BY_NAME:
1.13 ohara 319: m = (cmo *)receive_cmo_ring_by_name(oxfp);
1.1 ohara 320: break;
321: case CMO_DISTRIBUTED_POLYNOMIAL:
1.13 ohara 322: m = (cmo *)receive_cmo_distributed_polynomial(oxfp);
1.1 ohara 323: break;
1.26 ohara 324: case CMO_RECURSIVE_POLYNOMIAL:
325: m = (cmo *)receive_cmo_recursive_polynomial(oxfp);
326: break;
327: case CMO_POLYNOMIAL_IN_ONE_VARIABLE:
328: m = (cmo *)receive_cmo_polynomial_in_one_variable(oxfp);
1.29 ohara 329: break;
330: case CMO_INDETERMINATE:
331: m = (cmo *)receive_cmo_indeterminate(oxfp);
1.28 ohara 332: break;
333: case CMO_TREE:
334: m = (cmo *)receive_cmo_tree(oxfp);
335: break;
336: case CMO_LAMBDA:
337: m = (cmo *)receive_cmo_lambda(oxfp);
338: break;
1.1 ohara 339: case CMO_ERROR2:
1.13 ohara 340: m = (cmo *)receive_cmo_error2(oxfp);
1.1 ohara 341: break;
342: case CMO_DATUM:
343: case CMO_QQ:
344: default:
1.13 ohara 345: m = NULL;
1.20 ohara 346: ox_printf("the CMO (%d) is not implemented.\n", tag);
1.1 ohara 347: }
348: return m;
349: }
350:
1.13 ohara 351: static void receive_mpz(OXFILE *oxfp, mpz_ptr mpz)
1.1 ohara 352: {
353: int i;
1.13 ohara 354: int size = receive_int32(oxfp);
1.1 ohara 355: int len = abs(size);
356: resize_mpz(mpz, size);
357:
358: for(i=0; i<len; i++) {
1.13 ohara 359: mpz->_mp_d[i] = receive_int32(oxfp);
1.1 ohara 360: }
361: }
362:
1.13 ohara 363: void send_ox_command(OXFILE *oxfp, int sm_command)
1.1 ohara 364: {
1.13 ohara 365: send_ox_tag(oxfp, OX_COMMAND);
366: send_int32(oxfp, sm_command);
367: oxf_flush(oxfp);
1.1 ohara 368: }
369:
1.13 ohara 370: void ox_close(OXFILE *sv)
1.1 ohara 371: {
1.13 ohara 372: send_ox_command(oxf_control(sv), SM_control_kill);
1.7 ohara 373: sleep(2);
1.13 ohara 374: /* We wait thar an OpenXM server terminates. */
1.20 ohara 375: ox_printf("I have closed the connection to an Open XM server.\n");
1.1 ohara 376: }
377:
1.13 ohara 378: void ox_shutdown(OXFILE *sv)
1.3 ohara 379: {
1.13 ohara 380: /* We need to use SM_shutdown but yet ... */
381: ox_close(sv);
1.3 ohara 382: }
383:
1.13 ohara 384: void ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[])
1.3 ohara 385: {
1.13 ohara 386: int i = argc;
387: while(i-- > 0) {
388: send_ox_cmo(sv, argv[i]);
389: }
390: send_ox_cmo(sv, (cmo *)new_cmo_int32(argc));
391: send_ox_cmo(sv, (cmo *)new_cmo_string(function));
392: send_ox_command(sv, SM_executeFunction);
1.3 ohara 393: }
394:
1.13 ohara 395: void ox_execute_string(OXFILE *sv, char* s)
1.3 ohara 396: {
1.13 ohara 397: send_ox_cmo(sv, (cmo *)new_cmo_string(s));
398: send_ox_command(sv, SM_executeStringByLocalParser);
1.3 ohara 399: }
400:
1.13 ohara 401: void ox_push_cmd(OXFILE *sv, int sm_code)
1.1 ohara 402: {
1.13 ohara 403: send_ox_command(sv, sm_code);
1.1 ohara 404: }
405:
1.13 ohara 406: cmo_mathcap* ox_mathcap(OXFILE *sv)
1.1 ohara 407: {
1.13 ohara 408: send_ox_command(sv, SM_mathcap);
409: send_ox_command(sv, SM_popCMO);
410: receive_ox_tag(sv); /* OX_DATA */
411: return (cmo_mathcap *)receive_cmo(sv);
1.1 ohara 412: }
413:
1.13 ohara 414: char* ox_popString(OXFILE *sv)
1.1 ohara 415: {
416: cmo_string* m = NULL;
417:
1.13 ohara 418: send_ox_command(sv, SM_popString);
419: receive_ox_tag(sv); /* OX_DATA */
420: m = (cmo_string *)receive_cmo(sv);
1.1 ohara 421: return m->s;
422: }
423:
1.13 ohara 424: void ox_pops(OXFILE *sv, int num)
1.3 ohara 425: {
1.13 ohara 426: send_ox_cmo(sv, (cmo *)new_cmo_int32(num));
427: send_ox_command(sv, SM_pops);
1.3 ohara 428: }
429:
1.13 ohara 430: cmo* ox_pop_cmo(OXFILE *sv)
1.3 ohara 431: {
1.13 ohara 432: send_ox_command(sv, SM_popCMO);
433: receive_ox_tag(sv); /* OX_DATA */
434: return receive_cmo(sv);
1.3 ohara 435: }
436:
1.13 ohara 437: void ox_push_cmo(OXFILE *sv, cmo *c)
1.3 ohara 438: {
1.13 ohara 439: send_ox_cmo(sv, c);
1.3 ohara 440: }
441:
1.7 ohara 442: /* a dummy function for flushing a connection. */
1.13 ohara 443: int ox_flush(OXFILE *sv)
1.5 ohara 444: {
1.13 ohara 445: return 1;
1.5 ohara 446: }
447:
1.13 ohara 448: void ox_reset(OXFILE *sv)
1.1 ohara 449: {
1.13 ohara 450: send_ox_command(oxf_control(sv), SM_control_reset_connection);
1.31 ! iwane 451: while(receive_ox_tag(sv) != OX_SYNC_BALL) {
! 452: receive_cmo(sv); /* skipping a message. */
1.1 ohara 453: }
454:
1.13 ohara 455: send_ox_tag(sv, OX_SYNC_BALL);
1.20 ohara 456: ox_printf("I have reset an Open XM server.\n");
1.1 ohara 457: }
458:
1.13 ohara 459: void send_ox(OXFILE *oxfp, ox *m)
1.1 ohara 460: {
461: switch(m->tag) {
1.13 ohara 462: case OX_DATA:
463: send_ox_cmo(oxfp, ((ox_data *)m)->cmo);
1.1 ohara 464: break;
1.13 ohara 465: case OX_COMMAND:
466: send_ox_command(oxfp, ((ox_command *)m)->command);
1.1 ohara 467: break;
468: default:
469: /* CMO?? */
1.13 ohara 470: send_ox_cmo(oxfp, (cmo *)m);
1.1 ohara 471: }
472: }
473:
1.13 ohara 474: void send_ox_cmo(OXFILE *oxfp, cmo* m)
1.1 ohara 475: {
1.13 ohara 476: send_ox_tag(oxfp, OX_DATA);
477: send_cmo(oxfp, m);
478: oxf_flush(oxfp);
1.1 ohara 479: }
480:
1.8 ohara 481: /* send_cmo_* functions */
1.13 ohara 482: static int send_cmo_null(OXFILE *oxfp, cmo_null* c)
1.1 ohara 483: {
484: return 0;
485: }
486:
1.13 ohara 487: static int send_cmo_int32(OXFILE *oxfp, cmo_int32* m)
1.1 ohara 488: {
1.13 ohara 489: return send_int32(oxfp, m->i);
1.1 ohara 490: }
491:
1.13 ohara 492: static int send_cmo_string(OXFILE *oxfp, cmo_string* m)
1.1 ohara 493: {
494: int len = (m->s != NULL)? strlen(m->s): 0;
1.13 ohara 495: send_int32(oxfp, len);
1.1 ohara 496: if (len > 0) {
1.13 ohara 497: oxf_write(m->s, 1, len, oxfp);
1.1 ohara 498: }
499: return 0;
500: }
501:
1.13 ohara 502: static int send_cmo_mathcap(OXFILE *oxfp, cmo_mathcap* c)
1.1 ohara 503: {
1.13 ohara 504: send_cmo(oxfp, c->ob);
1.1 ohara 505: return 0;
506: }
507:
1.13 ohara 508: static int send_cmo_list(OXFILE *oxfp, cmo_list* c)
1.1 ohara 509: {
1.13 ohara 510: cell* el = list_first(c);
511: int len = list_length(c);
512: send_int32(oxfp, len);
513:
514: while(!list_endof(c, el)) {
515: send_cmo(oxfp, el->cmo);
516: el = list_next(el);
1.1 ohara 517: }
518: return 0;
519: }
520:
1.13 ohara 521: static int send_cmo_distributed_polynomial(OXFILE *oxfp, cmo_distributed_polynomial* c)
1.1 ohara 522: {
1.13 ohara 523: cell* el = list_first((cmo_list *)c);
524: int len = list_length((cmo_list *)c);
525: send_int32(oxfp, len);
526: send_cmo(oxfp, c->ringdef);
527: while(!list_endof((cmo_list *)c, el)) {
528: send_cmo(oxfp, el->cmo);
529: el = list_next(el);
1.1 ohara 530: }
531: return 0;
532: }
533:
1.26 ohara 534: static int send_cmo_polynomial_in_one_variable(OXFILE *oxfp, cmo_polynomial_in_one_variable* c)
535: {
1.27 ohara 536: cell* el = list_first((cmo_list *)c);
537: int len = list_length((cmo_list *)c);
1.26 ohara 538: send_int32(oxfp, len);
539: send_int32(oxfp, c->var);
540:
1.27 ohara 541: while(!list_endof((cmo_list *)c, el)) {
542: send_int32(oxfp, el->exp);
1.26 ohara 543: send_cmo(oxfp, el->cmo);
544: el = list_next(el);
545: }
546: return 0;
547: }
548:
1.13 ohara 549: static int send_cmo_monomial32(OXFILE *oxfp, cmo_monomial32* c)
1.1 ohara 550: {
551: int i;
552: int len = c->length;
1.13 ohara 553: send_int32(oxfp, len);
1.1 ohara 554: for(i=0; i<len; i++) {
1.13 ohara 555: send_int32(oxfp, c->exps[i]);
1.1 ohara 556: }
1.13 ohara 557: send_cmo(oxfp, c->coef);
1.1 ohara 558: return 0;
559: }
560:
1.13 ohara 561: static int send_cmo_zz(OXFILE *oxfp, cmo_zz* c)
1.1 ohara 562: {
1.13 ohara 563: send_mpz(oxfp, c->mpz);
1.1 ohara 564: return 0;
565: }
566:
1.26 ohara 567: static int send_cmo_recursive_polynomial(OXFILE *oxfp, cmo_recursive_polynomial* c)
568: {
1.27 ohara 569: send_cmo(oxfp, (cmo *)c->ringdef);
1.26 ohara 570: send_cmo(oxfp, c->coef);
571: return 0;
572: }
573:
1.28 ohara 574: static int send_cmo_tree(OXFILE *oxfp, cmo_tree *c)
575: {
576: send_cmo(oxfp, (cmo *)c->name);
577: send_cmo(oxfp, (cmo *)c->attributes);
578: send_cmo(oxfp, (cmo *)c->leaves);
579: return 0;
580: }
581:
582: static int send_cmo_lambda(OXFILE *oxfp, cmo_lambda *c)
583: {
584: send_cmo(oxfp, (cmo *)c->args);
585: send_cmo(oxfp, (cmo *)c->body);
586: return 0;
587: }
588:
1.13 ohara 589: static int send_cmo_error2(OXFILE *oxfp, cmo_error2* c)
1.1 ohara 590: {
1.13 ohara 591: send_cmo(oxfp, c->ob);
1.1 ohara 592: return 0;
593: }
594:
1.8 ohara 595: /* sending a CMO. (Remarks: OX_tag is already sent.) */
1.13 ohara 596: void send_cmo(OXFILE *oxfp, cmo* c)
1.1 ohara 597: {
598: int tag = c->tag;
599:
1.13 ohara 600: c = call_hook_before_send_cmo(oxfp, c);
1.2 ohara 601:
1.13 ohara 602: send_int32(oxfp, tag);
1.1 ohara 603: switch(tag) {
604: case CMO_NULL:
605: case CMO_ZERO:
606: case CMO_DMS_GENERIC:
1.13 ohara 607: send_cmo_null(oxfp, c); /* empty function. */
1.1 ohara 608: break;
609: case CMO_INT32:
1.13 ohara 610: send_cmo_int32(oxfp, (cmo_int32 *)c);
1.1 ohara 611: break;
612: case CMO_STRING:
1.13 ohara 613: send_cmo_string(oxfp, (cmo_string *)c);
1.1 ohara 614: break;
615: case CMO_MATHCAP:
616: case CMO_ERROR2:
617: case CMO_RING_BY_NAME:
618: case CMO_INDETERMINATE:
1.13 ohara 619: send_cmo_mathcap(oxfp, (cmo_mathcap *)c);
1.1 ohara 620: break;
621: case CMO_LIST:
1.13 ohara 622: send_cmo_list(oxfp, (cmo_list *)c);
1.1 ohara 623: break;
624: case CMO_MONOMIAL32:
1.13 ohara 625: send_cmo_monomial32(oxfp, (cmo_monomial32 *)c);
1.1 ohara 626: break;
627: case CMO_ZZ:
1.13 ohara 628: send_cmo_zz(oxfp, (cmo_zz *)c);
1.1 ohara 629: break;
630: case CMO_DISTRIBUTED_POLYNOMIAL:
1.13 ohara 631: send_cmo_distributed_polynomial(oxfp, (cmo_distributed_polynomial *)c);
1.26 ohara 632: break;
633: case CMO_RECURSIVE_POLYNOMIAL:
634: send_cmo_recursive_polynomial(oxfp, (cmo_recursive_polynomial *)c);
635: break;
636: case CMO_POLYNOMIAL_IN_ONE_VARIABLE:
637: send_cmo_polynomial_in_one_variable(oxfp, (cmo_polynomial_in_one_variable *)c);
1.28 ohara 638: break;
639: case CMO_TREE:
640: send_cmo_tree(oxfp, (cmo_tree *)c);
641: break;
642: case CMO_LAMBDA:
643: send_cmo_lambda(oxfp, (cmo_lambda *)c);
1.1 ohara 644: break;
645: default:
1.13 ohara 646: call_hook_after_send_cmo(oxfp, c);
1.1 ohara 647: }
648: }
649:
1.13 ohara 650: static int send_mpz(OXFILE *oxfp, mpz_ptr mpz)
1.1 ohara 651: {
652: int i;
653: int len = abs(mpz->_mp_size);
1.13 ohara 654: send_int32(oxfp, mpz->_mp_size);
1.1 ohara 655: for(i=0; i<len; i++) {
1.13 ohara 656: send_int32(oxfp, mpz->_mp_d[i]);
1.1 ohara 657: }
658: return 0;
659: }
660:
661: ox_data* new_ox_data(cmo* c)
662: {
1.25 ohara 663: ox_data* m = MALLOC(sizeof(ox_data));
1.1 ohara 664: m->tag = OX_DATA;
665: m->cmo = c;
666: return m;
667: }
668:
669: ox_command* new_ox_command(int sm_code)
670: {
1.25 ohara 671: ox_command* m = MALLOC(sizeof(ox_command));
1.1 ohara 672: m->tag = OX_COMMAND;
673: m->command = sm_code;
674: return m;
675: }
676:
677: ox_sync_ball* new_ox_sync_ball()
678: {
1.25 ohara 679: ox_sync_ball *m = MALLOC(sizeof(ox_sync_ball));
1.1 ohara 680: m->tag = OX_SYNC_BALL;
681: return m;
1.19 ohara 682: }
683:
684: int ox_stderr_init(FILE *fp)
685: {
1.21 ohara 686: ox_stderr = fp;
687: if (ox_stderr != NULL) {
688: setbuf(ox_stderr, NULL);
689: }
1.27 ohara 690: return 0;
1.20 ohara 691: }
692:
693: int ox_printf(char *format, ...)
694: {
1.21 ohara 695: if (ox_stderr != NULL) {
696: va_list ap;
697: va_start(ap, format);
698: vfprintf(ox_stderr, format, ap);
699: }
1.27 ohara 700: return 0;
1.1 ohara 701: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>