Annotation of OpenXM/src/ox_toolkit/ox.c, Revision 1.14
1.1 ohara 1: /* -*- mode: C; coding: euc-japan -*- */
1.14 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.13 2000/10/10 05:23:20 ohara 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>
12: #include <string.h>
13: #include <unistd.h>
14: #include <fcntl.h>
1.5 ohara 15: #include <sys/file.h>
1.13 ohara 16: #include <time.h>
1.1 ohara 17:
18: #include "mysocket.h"
1.12 ohara 19: #include "ox_toolkit.h"
1.1 ohara 20: #include "parse.h"
21:
1.3 ohara 22: /* CMO_xxx の値の順にならべること(デバッグのため) */
1.13 ohara 23: static cmo_null* receive_cmo_null(OXFILE *oxfp);
24: static cmo_int32* receive_cmo_int32(OXFILE *oxfp);
25: static cmo_string* receive_cmo_string(OXFILE *oxfp);
26: static cmo_mathcap* receive_cmo_mathcap(OXFILE *oxfp);
27: static cmo_list* receive_cmo_list(OXFILE *oxfp);
28: static cmo_monomial32* receive_cmo_monomial32(OXFILE *oxfp);
29: static cmo_zz* receive_cmo_zz(OXFILE *oxfp);
30: static cmo_zero* receive_cmo_zero(OXFILE *oxfp);
31: static cmo_dms_generic* receive_cmo_dms_generic(OXFILE *oxfp);
32: static cmo_ring_by_name* receive_cmo_ring_by_name(OXFILE *oxfp);
33: static cmo_distributed_polynomial* receive_cmo_distributed_polynomial(OXFILE *oxfp);
34:
35: static cmo_error2* receive_cmo_error2(OXFILE *oxfp);
36: static void receive_mpz(OXFILE *oxfp, mpz_ptr mpz);
37:
38: static int send_cmo_null(OXFILE *oxfp, cmo_null* c);
39: static int send_cmo_int32(OXFILE *oxfp, cmo_int32* m);
40: static int send_cmo_string(OXFILE *oxfp, cmo_string* m);
41: static int send_cmo_mathcap(OXFILE *oxfp, cmo_mathcap* c);
42: static int send_cmo_list(OXFILE *oxfp, cmo_list* c);
43: static int send_cmo_monomial32(OXFILE *oxfp, cmo_monomial32* c);
44: static int send_cmo_zz(OXFILE *oxfp, cmo_zz* c);
45: static int send_cmo_error2(OXFILE *oxfp, cmo_error2* c);
46: static int send_mpz(OXFILE *oxfp, mpz_ptr mpz);
47: static int send_cmo_distributed_polynomial(OXFILE *oxfp, cmo_distributed_polynomial* c);
1.3 ohara 48:
1.11 ohara 49: int ssh_ox_server(char *, char *, char *, short, short);
50:
1.13 ohara 51: OXFILE *current_fd = NULL;
52: void set_current_fd(OXFILE *oxfp)
1.2 ohara 53: {
1.13 ohara 54: current_fd = oxfp;
1.2 ohara 55: }
56:
1.8 ohara 57: /* hook functions. (yet not implemented) */
1.2 ohara 58: static hook_t hook_before_send_cmo = NULL;
59: static hook_t hook_after_send_cmo = NULL;
60:
61: int add_hook_before_send_cmo(hook_t func)
62: {
1.13 ohara 63: hook_before_send_cmo = func;
64: return 0;
1.2 ohara 65: }
66:
67: int add_hook_after_send_cmo(hook_t func)
68: {
1.13 ohara 69: hook_after_send_cmo = func;
70: return 0;
1.2 ohara 71: }
72:
1.13 ohara 73: static cmo *call_hook_before_send_cmo(OXFILE *oxfp, cmo *c)
1.2 ohara 74: {
1.13 ohara 75: if (hook_before_send_cmo != NULL) {
76: return hook_before_send_cmo(oxfp, c);
77: }
78: return c;
1.2 ohara 79: }
80:
1.13 ohara 81: static cmo *call_hook_after_send_cmo(OXFILE *oxfp, cmo *c)
1.2 ohara 82: {
1.13 ohara 83: if (hook_after_send_cmo != NULL) {
84: return hook_after_send_cmo(oxfp, c);
85: }
86: return c;
1.2 ohara 87: }
1.1 ohara 88:
1.7 ohara 89: /* Handling an error. */
1.1 ohara 90: static int current_received_serial = 0;
91:
1.7 ohara 92: /* If an error object be needed, then a server call the following function. */
1.1 ohara 93: cmo_error2* make_error_object(int err_code, cmo *ob)
94: {
95: cmo_list* li = new_cmo_list();
1.13 ohara 96: list_append(li, (cmo *)new_cmo_int32(current_received_serial));
97: list_append(li, (cmo *)new_cmo_int32(err_code));
98: list_append(li, ob);
1.1 ohara 99: /* 他の情報を加えるならココ */
100: return new_cmo_error2((cmo *)li);
101: }
102:
103: #define DEFAULT_SERIAL_NUMBER 0x0000ffff
1.13 ohara 104: #define receive_serial_number(x) (receive_int32((x)))
1.1 ohara 105:
1.7 ohara 106: /* getting a next serial number. */
1.13 ohara 107: int next_serial(OXFILE *oxfp)
1.1 ohara 108: {
1.13 ohara 109: /*
1.1 ohara 110: static int serial_number = DEFAULT_SERIAL_NUMBER;
1.13 ohara 111: */
112: return oxfp->serial_number++;
1.1 ohara 113: }
114:
1.7 ohara 115: /* sending an object of int32 type. (not equal to cmo_int32 type) */
1.13 ohara 116: int send_int32(OXFILE *oxfp, int int32)
1.1 ohara 117: {
1.13 ohara 118: return oxfp->send_int32(oxfp, int32);
1.1 ohara 119: }
120:
1.13 ohara 121: /* sending an object of int32 type with Network Byte Order.
122: (not equal to cmo_int32 type) */
123: int send_int32_nbo(OXFILE *oxfp, int int32)
1.1 ohara 124: {
1.13 ohara 125: int32 = htonl(int32);
126: return oxf_write(&int32, sizeof(int), 1, oxfp);
1.1 ohara 127: }
128:
1.13 ohara 129: /* sending an object of int32 type with Local Byte Order.
130: (not equal to cmo_int32 type) */
131: int send_int32_lbo(OXFILE *oxfp, int int32)
1.1 ohara 132: {
1.13 ohara 133: return oxf_write(&int32, sizeof(int), 1, oxfp);
1.1 ohara 134: }
135:
1.13 ohara 136: /* receiving an object of int32 type. (not equal to cmo_int32 type) */
137: int receive_int32(OXFILE *oxfp)
1.1 ohara 138: {
1.13 ohara 139: return oxfp->receive_int32(oxfp);
1.1 ohara 140: }
141:
1.13 ohara 142: /* receiving an object of int32 type with Network Byte Order.
143: (not equal to cmo_int32 type) */
144: int receive_int32_nbo(OXFILE *oxfp)
1.1 ohara 145: {
1.13 ohara 146: int tag;
147: oxf_read(&tag, sizeof(int), 1, oxfp);
148: return ntohl(tag);
1.1 ohara 149: }
150:
1.13 ohara 151: /* receiving an object of int32 type with Local Byte Order.
152: (not equal to cmo_int32 type) */
153: int receive_int32_lbo(OXFILE *oxfp)
1.1 ohara 154: {
1.13 ohara 155: int tag;
156: oxf_read(&tag, sizeof(int), 1, oxfp);
157: return tag;
1.1 ohara 158: }
159:
1.13 ohara 160: /* socket システムコールなどで socket を開いたのち、
161: fdopen(sd, "a+") でバッファリングする。("w+" ではない)
162: バッファリングの後、バイトオーダを決定し、
163: oxf_setopt() で関数ポインタを設定し直す。*/
1.1 ohara 164:
1.13 ohara 165: /* receiving an (OX_tag, serial number) */
166: int receive_ox_tag(OXFILE *oxfp)
1.1 ohara 167: {
1.13 ohara 168: int tag = receive_int32(oxfp);
169: current_received_serial = receive_serial_number(oxfp);
170: return tag;
1.1 ohara 171: }
172:
1.13 ohara 173: /* sending an (OX_tag, serial number) */
174: int send_ox_tag(OXFILE *oxfp, int tag)
1.3 ohara 175: {
1.13 ohara 176: send_int32(oxfp, tag);
177: return send_int32(oxfp, next_serial(oxfp));
1.1 ohara 178: }
179:
1.7 ohara 180: /* functions named receive_cmo_*. */
1.13 ohara 181: static cmo_null* receive_cmo_null(OXFILE *oxfp)
1.1 ohara 182: {
183: return new_cmo_null();
184: }
185:
1.13 ohara 186: static cmo_int32* receive_cmo_int32(OXFILE *oxfp)
1.1 ohara 187: {
1.13 ohara 188: int i = receive_int32(oxfp);
1.1 ohara 189: return new_cmo_int32(i);
190: }
191:
1.13 ohara 192: static cmo_string* receive_cmo_string(OXFILE *oxfp)
1.1 ohara 193: {
1.13 ohara 194: int len = receive_int32(oxfp);
1.1 ohara 195: char* s = malloc(len+1);
196: memset(s, '\0', len+1);
197: if (len > 0) {
1.13 ohara 198: oxf_read(s, 1, len, oxfp);
1.1 ohara 199: }
200: return new_cmo_string(s);
201: }
202:
1.13 ohara 203: static cmo_mathcap* receive_cmo_mathcap(OXFILE *oxfp)
1.1 ohara 204: {
1.13 ohara 205: cmo* ob = receive_cmo(oxfp);
1.1 ohara 206: return new_cmo_mathcap(ob);
207: }
208:
1.13 ohara 209: static cmo_list* receive_cmo_list(OXFILE *oxfp)
1.1 ohara 210: {
211: cmo* ob;
212: cmo_list* c = new_cmo_list();
1.13 ohara 213: int len = receive_int32(oxfp);
1.1 ohara 214:
215: while (len>0) {
1.13 ohara 216: ob = receive_cmo(oxfp);
217: list_append(c, ob);
1.1 ohara 218: len--;
219: }
220: return c;
221: }
222:
1.13 ohara 223: static cmo_monomial32* receive_cmo_monomial32(OXFILE *oxfp)
1.1 ohara 224: {
225: int i;
1.13 ohara 226: int len = receive_int32(oxfp);
1.1 ohara 227: cmo_monomial32* c = new_cmo_monomial32(len);
228:
229: for(i=0; i<len; i++) {
1.13 ohara 230: c->exps[i] = receive_int32(oxfp);
1.1 ohara 231: }
1.13 ohara 232: c->coef = receive_cmo(oxfp);
1.1 ohara 233: return c;
234: }
235:
1.13 ohara 236: static cmo_zz* receive_cmo_zz(OXFILE *oxfp)
1.1 ohara 237: {
238: cmo_zz* c = new_cmo_zz();
1.13 ohara 239: receive_mpz(oxfp, c->mpz);
1.1 ohara 240: return c;
241: }
242:
1.13 ohara 243: static cmo_zero* receive_cmo_zero(OXFILE *oxfp)
1.1 ohara 244: {
245: return new_cmo_zero();
246: }
247:
1.13 ohara 248: static cmo_dms_generic* receive_cmo_dms_generic(OXFILE *oxfp)
1.1 ohara 249: {
250: return new_cmo_dms_generic();
251: }
252:
1.13 ohara 253: static cmo_ring_by_name* receive_cmo_ring_by_name(OXFILE *oxfp)
1.1 ohara 254: {
1.13 ohara 255: cmo* ob = receive_cmo(oxfp);
256: /* We need to check semantics but yet ... */
1.1 ohara 257: return new_cmo_ring_by_name(ob);
258: }
259:
1.13 ohara 260: static cmo_distributed_polynomial* receive_cmo_distributed_polynomial(OXFILE *oxfp)
1.1 ohara 261: {
262: cmo* ob;
263: cmo_distributed_polynomial* c = new_cmo_distributed_polynomial();
1.13 ohara 264: int len = receive_int32(oxfp);
265: c->ringdef = receive_cmo(oxfp);
1.1 ohara 266:
267: while (len>0) {
1.13 ohara 268: ob = receive_cmo(oxfp);
269: list_append((cmo_list *)c, ob);
1.1 ohara 270: len--;
271: }
272: return c;
273: }
274:
1.13 ohara 275: static cmo_error2* receive_cmo_error2(OXFILE *oxfp)
1.1 ohara 276: {
1.13 ohara 277: cmo* ob = receive_cmo(oxfp);
1.1 ohara 278: return new_cmo_error2(ob);
279: }
280:
281: /* receive_ox_tag() == OX_DATA の後に呼び出される */
282: /* 関数ポインタを使った方がきれいに書けるような気がする. */
1.13 ohara 283: /* if (foo[tag] != NULL) foo[tag](oxfp); とか */
1.1 ohara 284:
1.13 ohara 285: cmo* receive_cmo(OXFILE *oxfp)
1.1 ohara 286: {
287: cmo* m;
1.13 ohara 288: int tag = receive_int32(oxfp);
1.1 ohara 289: switch(tag) {
290: case CMO_NULL:
1.13 ohara 291: m = receive_cmo_null(oxfp);
1.1 ohara 292: break;
293: case CMO_INT32:
1.13 ohara 294: m = (cmo *)receive_cmo_int32(oxfp);
1.1 ohara 295: break;
296: case CMO_STRING:
1.13 ohara 297: m = (cmo *)receive_cmo_string(oxfp);
1.1 ohara 298: break;
299: case CMO_MATHCAP:
1.13 ohara 300: m = (cmo *)receive_cmo_mathcap(oxfp);
1.1 ohara 301: break;
302: case CMO_LIST:
1.13 ohara 303: m = (cmo *)receive_cmo_list(oxfp);
1.1 ohara 304: break;
305: case CMO_MONOMIAL32:
1.13 ohara 306: m = (cmo *)receive_cmo_monomial32(oxfp);
1.1 ohara 307: break;
308: case CMO_ZZ:
1.13 ohara 309: m = (cmo *)receive_cmo_zz(oxfp);
1.1 ohara 310: break;
311: case CMO_ZERO:
1.13 ohara 312: m = (cmo *)receive_cmo_zero(oxfp);
1.1 ohara 313: break;
314: case CMO_DMS_GENERIC:
1.13 ohara 315: m = (cmo *)receive_cmo_dms_generic(oxfp);
1.1 ohara 316: break;
317: case CMO_RING_BY_NAME:
1.13 ohara 318: m = (cmo *)receive_cmo_ring_by_name(oxfp);
1.1 ohara 319: break;
320: case CMO_DISTRIBUTED_POLYNOMIAL:
1.13 ohara 321: m = (cmo *)receive_cmo_distributed_polynomial(oxfp);
1.1 ohara 322: break;
323: case CMO_ERROR2:
1.13 ohara 324: m = (cmo *)receive_cmo_error2(oxfp);
1.1 ohara 325: break;
326: case CMO_DATUM:
327: case CMO_QQ:
328: default:
1.13 ohara 329: m = NULL;
330: fprintf(stderr, "the CMO (%d) is not implemented.\n", tag);
1.1 ohara 331: }
332: return m;
333: }
334:
1.13 ohara 335: static void receive_mpz(OXFILE *oxfp, mpz_ptr mpz)
1.1 ohara 336: {
337: int i;
1.13 ohara 338: int size = receive_int32(oxfp);
1.1 ohara 339: int len = abs(size);
340: resize_mpz(mpz, size);
341:
342: for(i=0; i<len; i++) {
1.13 ohara 343: mpz->_mp_d[i] = receive_int32(oxfp);
1.1 ohara 344: }
345: }
346:
1.13 ohara 347: void send_ox_command(OXFILE *oxfp, int sm_command)
1.1 ohara 348: {
1.13 ohara 349: send_ox_tag(oxfp, OX_COMMAND);
350: send_int32(oxfp, sm_command);
351: oxf_flush(oxfp);
1.1 ohara 352: }
353:
1.13 ohara 354: void ox_close(OXFILE *sv)
1.1 ohara 355: {
1.13 ohara 356: send_ox_command(oxf_control(sv), SM_control_kill);
1.1 ohara 357: #ifdef DEBUG
1.7 ohara 358: sleep(2);
1.13 ohara 359: /* We wait thar an OpenXM server terminates. */
1.1 ohara 360: fprintf(stderr, "I have closed the connection to an Open XM server.\n");
361: #endif
362: }
363:
1.13 ohara 364: void ox_shutdown(OXFILE *sv)
1.3 ohara 365: {
1.13 ohara 366: /* We need to use SM_shutdown but yet ... */
367: ox_close(sv);
1.3 ohara 368: }
369:
1.13 ohara 370: void ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[])
1.3 ohara 371: {
1.13 ohara 372: int i = argc;
373: while(i-- > 0) {
374: send_ox_cmo(sv, argv[i]);
375: }
376: send_ox_cmo(sv, (cmo *)new_cmo_int32(argc));
377: send_ox_cmo(sv, (cmo *)new_cmo_string(function));
378: send_ox_command(sv, SM_executeFunction);
1.3 ohara 379: }
380:
1.13 ohara 381: void ox_execute_string(OXFILE *sv, char* s)
1.3 ohara 382: {
1.13 ohara 383: send_ox_cmo(sv, (cmo *)new_cmo_string(s));
384: send_ox_command(sv, SM_executeStringByLocalParser);
1.3 ohara 385: }
386:
1.13 ohara 387: void ox_push_cmd(OXFILE *sv, int sm_code)
1.1 ohara 388: {
1.13 ohara 389: send_ox_command(sv, sm_code);
1.1 ohara 390: }
391:
1.13 ohara 392: cmo_mathcap* ox_mathcap(OXFILE *sv)
1.1 ohara 393: {
1.13 ohara 394: send_ox_command(sv, SM_mathcap);
395: send_ox_command(sv, SM_popCMO);
396: receive_ox_tag(sv); /* OX_DATA */
397: return (cmo_mathcap *)receive_cmo(sv);
1.1 ohara 398: }
399:
1.13 ohara 400: char* ox_popString(OXFILE *sv)
1.1 ohara 401: {
402: cmo_string* m = NULL;
403:
1.13 ohara 404: send_ox_command(sv, SM_popString);
405: receive_ox_tag(sv); /* OX_DATA */
406: m = (cmo_string *)receive_cmo(sv);
1.1 ohara 407: return m->s;
408: }
409:
1.13 ohara 410: void ox_pops(OXFILE *sv, int num)
1.3 ohara 411: {
1.13 ohara 412: send_ox_cmo(sv, (cmo *)new_cmo_int32(num));
413: send_ox_command(sv, SM_pops);
1.3 ohara 414: }
415:
1.13 ohara 416: cmo* ox_pop_cmo(OXFILE *sv)
1.3 ohara 417: {
1.13 ohara 418: send_ox_command(sv, SM_popCMO);
419: receive_ox_tag(sv); /* OX_DATA */
420: return receive_cmo(sv);
1.3 ohara 421: }
422:
1.13 ohara 423: void ox_push_cmo(OXFILE *sv, cmo *c)
1.3 ohara 424: {
1.13 ohara 425: send_ox_cmo(sv, c);
1.3 ohara 426: }
427:
1.7 ohara 428: /* a dummy function for flushing a connection. */
1.13 ohara 429: int ox_flush(OXFILE *sv)
1.5 ohara 430: {
1.13 ohara 431: return 1;
1.5 ohara 432: }
433:
1.13 ohara 434: void ox_reset(OXFILE *sv)
1.1 ohara 435: {
1.13 ohara 436: send_ox_command(oxf_control(sv), SM_control_reset_connection);
1.1 ohara 437:
1.13 ohara 438: receive_ox_tag(oxf_control(sv)); /* OX_DATA */
439: receive_cmo(oxf_control(sv)); /* (CMO_INT32, 0) */
1.1 ohara 440:
1.13 ohara 441: while(receive_ox_tag(sv) != OX_SYNC_BALL) {
442: receive_cmo(sv); /* skipping a message. */
1.1 ohara 443: }
444:
1.13 ohara 445: send_ox_tag(sv, OX_SYNC_BALL);
1.1 ohara 446: #ifdef DEBUG
447: fprintf(stderr, "I have reset an Open XM server.\n");
448: #endif
449: }
450:
1.13 ohara 451: void send_ox(OXFILE *oxfp, ox *m)
1.1 ohara 452: {
453: switch(m->tag) {
1.13 ohara 454: case OX_DATA:
455: send_ox_cmo(oxfp, ((ox_data *)m)->cmo);
1.1 ohara 456: break;
1.13 ohara 457: case OX_COMMAND:
458: send_ox_command(oxfp, ((ox_command *)m)->command);
1.1 ohara 459: break;
460: default:
461: /* CMO?? */
1.13 ohara 462: send_ox_cmo(oxfp, (cmo *)m);
1.1 ohara 463: }
464: }
465:
1.13 ohara 466: void send_ox_cmo(OXFILE *oxfp, cmo* m)
1.1 ohara 467: {
1.13 ohara 468: send_ox_tag(oxfp, OX_DATA);
469: send_cmo(oxfp, m);
470: oxf_flush(oxfp);
1.1 ohara 471: }
472:
1.8 ohara 473: /* send_cmo_* functions */
1.13 ohara 474: static int send_cmo_null(OXFILE *oxfp, cmo_null* c)
1.1 ohara 475: {
476: return 0;
477: }
478:
1.13 ohara 479: static int send_cmo_int32(OXFILE *oxfp, cmo_int32* m)
1.1 ohara 480: {
1.13 ohara 481: return send_int32(oxfp, m->i);
1.1 ohara 482: }
483:
1.13 ohara 484: static int send_cmo_string(OXFILE *oxfp, cmo_string* m)
1.1 ohara 485: {
486: int len = (m->s != NULL)? strlen(m->s): 0;
1.13 ohara 487: send_int32(oxfp, len);
1.1 ohara 488: if (len > 0) {
1.13 ohara 489: oxf_write(m->s, 1, len, oxfp);
1.1 ohara 490: }
491: return 0;
492: }
493:
1.13 ohara 494: static int send_cmo_mathcap(OXFILE *oxfp, cmo_mathcap* c)
1.1 ohara 495: {
1.13 ohara 496: send_cmo(oxfp, c->ob);
1.1 ohara 497: return 0;
498: }
499:
1.13 ohara 500: static int send_cmo_list(OXFILE *oxfp, cmo_list* c)
1.1 ohara 501: {
1.13 ohara 502: cell* el = list_first(c);
503: int len = list_length(c);
504: send_int32(oxfp, len);
505:
506: while(!list_endof(c, el)) {
507: send_cmo(oxfp, el->cmo);
508: el = list_next(el);
1.1 ohara 509: }
510: return 0;
511: }
512:
1.13 ohara 513: static int send_cmo_distributed_polynomial(OXFILE *oxfp, cmo_distributed_polynomial* c)
1.1 ohara 514: {
1.13 ohara 515: cell* el = list_first((cmo_list *)c);
516: int len = list_length((cmo_list *)c);
517: send_int32(oxfp, len);
518: send_cmo(oxfp, c->ringdef);
519: while(!list_endof((cmo_list *)c, el)) {
520: send_cmo(oxfp, el->cmo);
521: el = list_next(el);
1.1 ohara 522: }
523: return 0;
524: }
525:
1.13 ohara 526: static int send_cmo_monomial32(OXFILE *oxfp, cmo_monomial32* c)
1.1 ohara 527: {
528: int i;
529: int len = c->length;
1.13 ohara 530: send_int32(oxfp, len);
1.1 ohara 531: for(i=0; i<len; i++) {
1.13 ohara 532: send_int32(oxfp, c->exps[i]);
1.1 ohara 533: }
1.13 ohara 534: send_cmo(oxfp, c->coef);
1.1 ohara 535: return 0;
536: }
537:
1.13 ohara 538: static int send_cmo_zz(OXFILE *oxfp, cmo_zz* c)
1.1 ohara 539: {
1.13 ohara 540: send_mpz(oxfp, c->mpz);
1.1 ohara 541: return 0;
542: }
543:
1.13 ohara 544: static int send_cmo_error2(OXFILE *oxfp, cmo_error2* c)
1.1 ohara 545: {
1.13 ohara 546: send_cmo(oxfp, c->ob);
1.1 ohara 547: return 0;
548: }
549:
1.8 ohara 550: /* sending a CMO. (Remarks: OX_tag is already sent.) */
1.13 ohara 551: void send_cmo(OXFILE *oxfp, cmo* c)
1.1 ohara 552: {
553: int tag = c->tag;
554:
1.13 ohara 555: c = call_hook_before_send_cmo(oxfp, c);
1.2 ohara 556:
1.13 ohara 557: send_int32(oxfp, tag);
1.1 ohara 558: switch(tag) {
559: case CMO_NULL:
560: case CMO_ZERO:
561: case CMO_DMS_GENERIC:
1.13 ohara 562: send_cmo_null(oxfp, c); /* empty function. */
1.1 ohara 563: break;
564: case CMO_INT32:
1.13 ohara 565: send_cmo_int32(oxfp, (cmo_int32 *)c);
1.1 ohara 566: break;
567: case CMO_STRING:
1.13 ohara 568: send_cmo_string(oxfp, (cmo_string *)c);
1.1 ohara 569: break;
570: case CMO_MATHCAP:
571: case CMO_ERROR2:
572: case CMO_RING_BY_NAME:
573: case CMO_INDETERMINATE:
1.13 ohara 574: send_cmo_mathcap(oxfp, (cmo_mathcap *)c);
1.1 ohara 575: break;
576: case CMO_LIST:
1.13 ohara 577: send_cmo_list(oxfp, (cmo_list *)c);
1.1 ohara 578: break;
579: case CMO_MONOMIAL32:
1.13 ohara 580: send_cmo_monomial32(oxfp, (cmo_monomial32 *)c);
1.1 ohara 581: break;
582: case CMO_ZZ:
1.13 ohara 583: send_cmo_zz(oxfp, (cmo_zz *)c);
1.1 ohara 584: break;
585: case CMO_DISTRIBUTED_POLYNOMIAL:
1.13 ohara 586: send_cmo_distributed_polynomial(oxfp, (cmo_distributed_polynomial *)c);
1.1 ohara 587: break;
588: default:
1.13 ohara 589: call_hook_after_send_cmo(oxfp, c);
1.1 ohara 590: }
591: }
592:
1.13 ohara 593: static int send_mpz(OXFILE *oxfp, mpz_ptr mpz)
1.1 ohara 594: {
595: int i;
596: int len = abs(mpz->_mp_size);
1.13 ohara 597: send_int32(oxfp, mpz->_mp_size);
1.1 ohara 598: for(i=0; i<len; i++) {
1.13 ohara 599: send_int32(oxfp, mpz->_mp_d[i]);
1.1 ohara 600: }
601: return 0;
602: }
603:
604: ox_data* new_ox_data(cmo* c)
605: {
606: ox_data* m = malloc(sizeof(ox_data));
607: m->tag = OX_DATA;
608: m->cmo = c;
609: return m;
610: }
611:
612: ox_command* new_ox_command(int sm_code)
613: {
614: ox_command* m = malloc(sizeof(ox_command));
615: m->tag = OX_COMMAND;
616: m->command = sm_code;
617: return m;
618: }
619:
620: ox_sync_ball* new_ox_sync_ball()
621: {
622: ox_sync_ball *m = malloc(sizeof(ox_sync_ball));
623: m->tag = OX_SYNC_BALL;
624: return m;
625: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>