Annotation of OpenXM/src/ox_toolkit/ox.c, Revision 1.22
1.1 ohara 1: /* -*- mode: C; coding: euc-japan -*- */
1.22 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.21 2003/02/04 20:43:55 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>
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);
36: static cmo_error2* receive_cmo_error2(OXFILE *oxfp);
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);
1.22 ! ohara 44: static int send_cmo_error2(OXFILE *oxfp, cmo_error2* c);
! 45: static int send_cmo_distributed_polynomial(OXFILE *oxfp, cmo_distributed_polynomial* c);
! 46:
! 47: #if defined(WITH_GMP)
! 48: static cmo_zz* receive_cmo_zz(OXFILE *oxfp);
! 49: static void receive_mpz(OXFILE *oxfp, mpz_ptr mpz);
1.13 ohara 50: static int send_cmo_zz(OXFILE *oxfp, cmo_zz* c);
51: static int send_mpz(OXFILE *oxfp, mpz_ptr mpz);
1.22 ! ohara 52: #endif /* WITH_GMP */
1.3 ohara 53:
1.8 ohara 54: /* hook functions. (yet not implemented) */
1.2 ohara 55: static hook_t hook_before_send_cmo = NULL;
56: static hook_t hook_after_send_cmo = NULL;
57:
58: int add_hook_before_send_cmo(hook_t func)
59: {
1.13 ohara 60: hook_before_send_cmo = func;
61: return 0;
1.2 ohara 62: }
63:
64: int add_hook_after_send_cmo(hook_t func)
65: {
1.13 ohara 66: hook_after_send_cmo = func;
67: return 0;
1.2 ohara 68: }
69:
1.13 ohara 70: static cmo *call_hook_before_send_cmo(OXFILE *oxfp, cmo *c)
1.2 ohara 71: {
1.13 ohara 72: if (hook_before_send_cmo != NULL) {
73: return hook_before_send_cmo(oxfp, c);
74: }
75: return c;
1.2 ohara 76: }
77:
1.13 ohara 78: static cmo *call_hook_after_send_cmo(OXFILE *oxfp, cmo *c)
1.2 ohara 79: {
1.13 ohara 80: if (hook_after_send_cmo != NULL) {
81: return hook_after_send_cmo(oxfp, c);
82: }
83: return c;
1.2 ohara 84: }
1.1 ohara 85:
1.7 ohara 86: /* Handling an error. */
1.1 ohara 87: static int current_received_serial = 0;
88:
1.7 ohara 89: /* If an error object be needed, then a server call the following function. */
1.1 ohara 90: cmo_error2* make_error_object(int err_code, cmo *ob)
91: {
92: cmo_list* li = new_cmo_list();
1.13 ohara 93: list_append(li, (cmo *)new_cmo_int32(current_received_serial));
94: list_append(li, (cmo *)new_cmo_int32(err_code));
95: list_append(li, ob);
1.1 ohara 96: return new_cmo_error2((cmo *)li);
97: }
98:
1.7 ohara 99: /* getting a next serial number. */
1.13 ohara 100: int next_serial(OXFILE *oxfp)
1.1 ohara 101: {
1.13 ohara 102: return oxfp->serial_number++;
1.1 ohara 103: }
104:
1.7 ohara 105: /* sending an object of int32 type. (not equal to cmo_int32 type) */
1.13 ohara 106: int send_int32(OXFILE *oxfp, int int32)
1.1 ohara 107: {
1.13 ohara 108: return oxfp->send_int32(oxfp, int32);
1.1 ohara 109: }
110:
1.13 ohara 111: /* receiving an object of int32 type. (not equal to cmo_int32 type) */
112: int receive_int32(OXFILE *oxfp)
1.1 ohara 113: {
1.13 ohara 114: return oxfp->receive_int32(oxfp);
1.1 ohara 115: }
116:
1.13 ohara 117: /* receiving an (OX_tag, serial number) */
118: int receive_ox_tag(OXFILE *oxfp)
1.1 ohara 119: {
1.13 ohara 120: int tag = receive_int32(oxfp);
1.16 ohara 121: oxfp->received_serial_number = receive_int32(oxfp);
1.13 ohara 122: return tag;
1.1 ohara 123: }
124:
1.13 ohara 125: /* sending an (OX_tag, serial number) */
126: int send_ox_tag(OXFILE *oxfp, int tag)
1.3 ohara 127: {
1.13 ohara 128: send_int32(oxfp, tag);
129: return send_int32(oxfp, next_serial(oxfp));
1.1 ohara 130: }
131:
1.7 ohara 132: /* functions named receive_cmo_*. */
1.13 ohara 133: static cmo_null* receive_cmo_null(OXFILE *oxfp)
1.1 ohara 134: {
135: return new_cmo_null();
136: }
137:
1.13 ohara 138: static cmo_int32* receive_cmo_int32(OXFILE *oxfp)
1.1 ohara 139: {
1.13 ohara 140: int i = receive_int32(oxfp);
1.1 ohara 141: return new_cmo_int32(i);
142: }
143:
1.13 ohara 144: static cmo_string* receive_cmo_string(OXFILE *oxfp)
1.1 ohara 145: {
1.13 ohara 146: int len = receive_int32(oxfp);
1.1 ohara 147: char* s = malloc(len+1);
148: memset(s, '\0', len+1);
149: if (len > 0) {
1.13 ohara 150: oxf_read(s, 1, len, oxfp);
1.1 ohara 151: }
152: return new_cmo_string(s);
153: }
154:
1.13 ohara 155: static cmo_mathcap* receive_cmo_mathcap(OXFILE *oxfp)
1.1 ohara 156: {
1.13 ohara 157: cmo* ob = receive_cmo(oxfp);
1.1 ohara 158: return new_cmo_mathcap(ob);
159: }
160:
1.13 ohara 161: static cmo_list* receive_cmo_list(OXFILE *oxfp)
1.1 ohara 162: {
163: cmo* ob;
164: cmo_list* c = new_cmo_list();
1.13 ohara 165: int len = receive_int32(oxfp);
1.1 ohara 166:
167: while (len>0) {
1.13 ohara 168: ob = receive_cmo(oxfp);
169: list_append(c, ob);
1.1 ohara 170: len--;
171: }
172: return c;
173: }
174:
1.13 ohara 175: static cmo_monomial32* receive_cmo_monomial32(OXFILE *oxfp)
1.1 ohara 176: {
177: int i;
1.13 ohara 178: int len = receive_int32(oxfp);
1.1 ohara 179: cmo_monomial32* c = new_cmo_monomial32(len);
180:
181: for(i=0; i<len; i++) {
1.13 ohara 182: c->exps[i] = receive_int32(oxfp);
1.1 ohara 183: }
1.13 ohara 184: c->coef = receive_cmo(oxfp);
1.1 ohara 185: return c;
186: }
187:
1.22 ! ohara 188: #if defined(WITH_GMP)
1.13 ohara 189: static cmo_zz* receive_cmo_zz(OXFILE *oxfp)
1.1 ohara 190: {
191: cmo_zz* c = new_cmo_zz();
1.13 ohara 192: receive_mpz(oxfp, c->mpz);
1.1 ohara 193: return c;
194: }
1.22 ! ohara 195: #endif /* WITH_GMP */
1.1 ohara 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.13 ohara 214: static cmo_distributed_polynomial* receive_cmo_distributed_polynomial(OXFILE *oxfp)
1.1 ohara 215: {
216: cmo* ob;
217: cmo_distributed_polynomial* c = new_cmo_distributed_polynomial();
1.13 ohara 218: int len = receive_int32(oxfp);
219: c->ringdef = receive_cmo(oxfp);
1.1 ohara 220:
221: while (len>0) {
1.13 ohara 222: ob = receive_cmo(oxfp);
223: list_append((cmo_list *)c, ob);
1.1 ohara 224: len--;
225: }
226: return c;
227: }
228:
1.13 ohara 229: static cmo_error2* receive_cmo_error2(OXFILE *oxfp)
1.1 ohara 230: {
1.13 ohara 231: cmo* ob = receive_cmo(oxfp);
1.1 ohara 232: return new_cmo_error2(ob);
233: }
234:
1.17 ohara 235: /* receive_cmo() is called after receive_ox_tag(). */
1.13 ohara 236: cmo* receive_cmo(OXFILE *oxfp)
1.1 ohara 237: {
238: cmo* m;
1.13 ohara 239: int tag = receive_int32(oxfp);
1.1 ohara 240: switch(tag) {
241: case CMO_NULL:
1.13 ohara 242: m = receive_cmo_null(oxfp);
1.1 ohara 243: break;
244: case CMO_INT32:
1.13 ohara 245: m = (cmo *)receive_cmo_int32(oxfp);
1.1 ohara 246: break;
247: case CMO_STRING:
1.13 ohara 248: m = (cmo *)receive_cmo_string(oxfp);
1.1 ohara 249: break;
250: case CMO_MATHCAP:
1.13 ohara 251: m = (cmo *)receive_cmo_mathcap(oxfp);
1.1 ohara 252: break;
253: case CMO_LIST:
1.13 ohara 254: m = (cmo *)receive_cmo_list(oxfp);
1.1 ohara 255: break;
256: case CMO_MONOMIAL32:
1.13 ohara 257: m = (cmo *)receive_cmo_monomial32(oxfp);
1.1 ohara 258: break;
1.22 ! ohara 259: #if defined(WITH_GMP)
1.1 ohara 260: case CMO_ZZ:
1.13 ohara 261: m = (cmo *)receive_cmo_zz(oxfp);
1.1 ohara 262: break;
1.22 ! ohara 263: #endif /* WITH_GMP */
1.1 ohara 264: case CMO_ZERO:
1.13 ohara 265: m = (cmo *)receive_cmo_zero(oxfp);
1.1 ohara 266: break;
267: case CMO_DMS_GENERIC:
1.13 ohara 268: m = (cmo *)receive_cmo_dms_generic(oxfp);
1.1 ohara 269: break;
270: case CMO_RING_BY_NAME:
1.13 ohara 271: m = (cmo *)receive_cmo_ring_by_name(oxfp);
1.1 ohara 272: break;
273: case CMO_DISTRIBUTED_POLYNOMIAL:
1.13 ohara 274: m = (cmo *)receive_cmo_distributed_polynomial(oxfp);
1.1 ohara 275: break;
276: case CMO_ERROR2:
1.13 ohara 277: m = (cmo *)receive_cmo_error2(oxfp);
1.1 ohara 278: break;
279: case CMO_DATUM:
280: case CMO_QQ:
281: default:
1.13 ohara 282: m = NULL;
1.20 ohara 283: ox_printf("the CMO (%d) is not implemented.\n", tag);
1.1 ohara 284: }
285: return m;
286: }
287:
1.22 ! ohara 288: #if defined(WITH_GMP)
1.13 ohara 289: static void receive_mpz(OXFILE *oxfp, mpz_ptr mpz)
1.1 ohara 290: {
291: int i;
1.13 ohara 292: int size = receive_int32(oxfp);
1.1 ohara 293: int len = abs(size);
294: resize_mpz(mpz, size);
295:
296: for(i=0; i<len; i++) {
1.13 ohara 297: mpz->_mp_d[i] = receive_int32(oxfp);
1.1 ohara 298: }
299: }
1.22 ! ohara 300: #endif /* WITH_GMP */
1.1 ohara 301:
1.13 ohara 302: void send_ox_command(OXFILE *oxfp, int sm_command)
1.1 ohara 303: {
1.13 ohara 304: send_ox_tag(oxfp, OX_COMMAND);
305: send_int32(oxfp, sm_command);
306: oxf_flush(oxfp);
1.1 ohara 307: }
308:
1.13 ohara 309: void ox_close(OXFILE *sv)
1.1 ohara 310: {
1.13 ohara 311: send_ox_command(oxf_control(sv), SM_control_kill);
1.7 ohara 312: sleep(2);
1.13 ohara 313: /* We wait thar an OpenXM server terminates. */
1.20 ohara 314: ox_printf("I have closed the connection to an Open XM server.\n");
1.1 ohara 315: }
316:
1.13 ohara 317: void ox_shutdown(OXFILE *sv)
1.3 ohara 318: {
1.13 ohara 319: /* We need to use SM_shutdown but yet ... */
320: ox_close(sv);
1.3 ohara 321: }
322:
1.13 ohara 323: void ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[])
1.3 ohara 324: {
1.13 ohara 325: int i = argc;
326: while(i-- > 0) {
327: send_ox_cmo(sv, argv[i]);
328: }
329: send_ox_cmo(sv, (cmo *)new_cmo_int32(argc));
330: send_ox_cmo(sv, (cmo *)new_cmo_string(function));
331: send_ox_command(sv, SM_executeFunction);
1.3 ohara 332: }
333:
1.13 ohara 334: void ox_execute_string(OXFILE *sv, char* s)
1.3 ohara 335: {
1.13 ohara 336: send_ox_cmo(sv, (cmo *)new_cmo_string(s));
337: send_ox_command(sv, SM_executeStringByLocalParser);
1.3 ohara 338: }
339:
1.13 ohara 340: void ox_push_cmd(OXFILE *sv, int sm_code)
1.1 ohara 341: {
1.13 ohara 342: send_ox_command(sv, sm_code);
1.1 ohara 343: }
344:
1.13 ohara 345: cmo_mathcap* ox_mathcap(OXFILE *sv)
1.1 ohara 346: {
1.13 ohara 347: send_ox_command(sv, SM_mathcap);
348: send_ox_command(sv, SM_popCMO);
349: receive_ox_tag(sv); /* OX_DATA */
350: return (cmo_mathcap *)receive_cmo(sv);
1.1 ohara 351: }
352:
1.13 ohara 353: char* ox_popString(OXFILE *sv)
1.1 ohara 354: {
355: cmo_string* m = NULL;
356:
1.13 ohara 357: send_ox_command(sv, SM_popString);
358: receive_ox_tag(sv); /* OX_DATA */
359: m = (cmo_string *)receive_cmo(sv);
1.1 ohara 360: return m->s;
361: }
362:
1.13 ohara 363: void ox_pops(OXFILE *sv, int num)
1.3 ohara 364: {
1.13 ohara 365: send_ox_cmo(sv, (cmo *)new_cmo_int32(num));
366: send_ox_command(sv, SM_pops);
1.3 ohara 367: }
368:
1.13 ohara 369: cmo* ox_pop_cmo(OXFILE *sv)
1.3 ohara 370: {
1.13 ohara 371: send_ox_command(sv, SM_popCMO);
372: receive_ox_tag(sv); /* OX_DATA */
373: return receive_cmo(sv);
1.3 ohara 374: }
375:
1.13 ohara 376: void ox_push_cmo(OXFILE *sv, cmo *c)
1.3 ohara 377: {
1.13 ohara 378: send_ox_cmo(sv, c);
1.3 ohara 379: }
380:
1.7 ohara 381: /* a dummy function for flushing a connection. */
1.13 ohara 382: int ox_flush(OXFILE *sv)
1.5 ohara 383: {
1.13 ohara 384: return 1;
1.5 ohara 385: }
386:
1.13 ohara 387: void ox_reset(OXFILE *sv)
1.1 ohara 388: {
1.13 ohara 389: send_ox_command(oxf_control(sv), SM_control_reset_connection);
390: while(receive_ox_tag(sv) != OX_SYNC_BALL) {
391: receive_cmo(sv); /* skipping a message. */
1.1 ohara 392: }
393:
1.13 ohara 394: send_ox_tag(sv, OX_SYNC_BALL);
1.20 ohara 395: ox_printf("I have reset an Open XM server.\n");
1.1 ohara 396: }
397:
1.13 ohara 398: void send_ox(OXFILE *oxfp, ox *m)
1.1 ohara 399: {
400: switch(m->tag) {
1.13 ohara 401: case OX_DATA:
402: send_ox_cmo(oxfp, ((ox_data *)m)->cmo);
1.1 ohara 403: break;
1.13 ohara 404: case OX_COMMAND:
405: send_ox_command(oxfp, ((ox_command *)m)->command);
1.1 ohara 406: break;
407: default:
408: /* CMO?? */
1.13 ohara 409: send_ox_cmo(oxfp, (cmo *)m);
1.1 ohara 410: }
411: }
412:
1.13 ohara 413: void send_ox_cmo(OXFILE *oxfp, cmo* m)
1.1 ohara 414: {
1.13 ohara 415: send_ox_tag(oxfp, OX_DATA);
416: send_cmo(oxfp, m);
417: oxf_flush(oxfp);
1.1 ohara 418: }
419:
1.8 ohara 420: /* send_cmo_* functions */
1.13 ohara 421: static int send_cmo_null(OXFILE *oxfp, cmo_null* c)
1.1 ohara 422: {
423: return 0;
424: }
425:
1.13 ohara 426: static int send_cmo_int32(OXFILE *oxfp, cmo_int32* m)
1.1 ohara 427: {
1.13 ohara 428: return send_int32(oxfp, m->i);
1.1 ohara 429: }
430:
1.13 ohara 431: static int send_cmo_string(OXFILE *oxfp, cmo_string* m)
1.1 ohara 432: {
433: int len = (m->s != NULL)? strlen(m->s): 0;
1.13 ohara 434: send_int32(oxfp, len);
1.1 ohara 435: if (len > 0) {
1.13 ohara 436: oxf_write(m->s, 1, len, oxfp);
1.1 ohara 437: }
438: return 0;
439: }
440:
1.13 ohara 441: static int send_cmo_mathcap(OXFILE *oxfp, cmo_mathcap* c)
1.1 ohara 442: {
1.13 ohara 443: send_cmo(oxfp, c->ob);
1.1 ohara 444: return 0;
445: }
446:
1.13 ohara 447: static int send_cmo_list(OXFILE *oxfp, cmo_list* c)
1.1 ohara 448: {
1.13 ohara 449: cell* el = list_first(c);
450: int len = list_length(c);
451: send_int32(oxfp, len);
452:
453: while(!list_endof(c, el)) {
454: send_cmo(oxfp, el->cmo);
455: el = list_next(el);
1.1 ohara 456: }
457: return 0;
458: }
459:
1.13 ohara 460: static int send_cmo_distributed_polynomial(OXFILE *oxfp, cmo_distributed_polynomial* c)
1.1 ohara 461: {
1.13 ohara 462: cell* el = list_first((cmo_list *)c);
463: int len = list_length((cmo_list *)c);
464: send_int32(oxfp, len);
465: send_cmo(oxfp, c->ringdef);
466: while(!list_endof((cmo_list *)c, el)) {
467: send_cmo(oxfp, el->cmo);
468: el = list_next(el);
1.1 ohara 469: }
470: return 0;
471: }
472:
1.13 ohara 473: static int send_cmo_monomial32(OXFILE *oxfp, cmo_monomial32* c)
1.1 ohara 474: {
475: int i;
476: int len = c->length;
1.13 ohara 477: send_int32(oxfp, len);
1.1 ohara 478: for(i=0; i<len; i++) {
1.13 ohara 479: send_int32(oxfp, c->exps[i]);
1.1 ohara 480: }
1.13 ohara 481: send_cmo(oxfp, c->coef);
1.1 ohara 482: return 0;
483: }
484:
1.22 ! ohara 485: #if defined(WITH_GMP)
1.13 ohara 486: static int send_cmo_zz(OXFILE *oxfp, cmo_zz* c)
1.1 ohara 487: {
1.13 ohara 488: send_mpz(oxfp, c->mpz);
1.1 ohara 489: return 0;
490: }
1.22 ! ohara 491: #endif /* WITH_GMP */
1.1 ohara 492:
1.13 ohara 493: static int send_cmo_error2(OXFILE *oxfp, cmo_error2* c)
1.1 ohara 494: {
1.13 ohara 495: send_cmo(oxfp, c->ob);
1.1 ohara 496: return 0;
497: }
498:
1.8 ohara 499: /* sending a CMO. (Remarks: OX_tag is already sent.) */
1.13 ohara 500: void send_cmo(OXFILE *oxfp, cmo* c)
1.1 ohara 501: {
502: int tag = c->tag;
503:
1.13 ohara 504: c = call_hook_before_send_cmo(oxfp, c);
1.2 ohara 505:
1.13 ohara 506: send_int32(oxfp, tag);
1.1 ohara 507: switch(tag) {
508: case CMO_NULL:
509: case CMO_ZERO:
510: case CMO_DMS_GENERIC:
1.13 ohara 511: send_cmo_null(oxfp, c); /* empty function. */
1.1 ohara 512: break;
513: case CMO_INT32:
1.13 ohara 514: send_cmo_int32(oxfp, (cmo_int32 *)c);
1.1 ohara 515: break;
516: case CMO_STRING:
1.13 ohara 517: send_cmo_string(oxfp, (cmo_string *)c);
1.1 ohara 518: break;
519: case CMO_MATHCAP:
520: case CMO_ERROR2:
521: case CMO_RING_BY_NAME:
522: case CMO_INDETERMINATE:
1.13 ohara 523: send_cmo_mathcap(oxfp, (cmo_mathcap *)c);
1.1 ohara 524: break;
525: case CMO_LIST:
1.13 ohara 526: send_cmo_list(oxfp, (cmo_list *)c);
1.1 ohara 527: break;
528: case CMO_MONOMIAL32:
1.13 ohara 529: send_cmo_monomial32(oxfp, (cmo_monomial32 *)c);
1.1 ohara 530: break;
1.22 ! ohara 531: #if defined(WITH_GMP)
1.1 ohara 532: case CMO_ZZ:
1.13 ohara 533: send_cmo_zz(oxfp, (cmo_zz *)c);
1.1 ohara 534: break;
1.22 ! ohara 535: #endif /* WITH_GMP */
1.1 ohara 536: case CMO_DISTRIBUTED_POLYNOMIAL:
1.13 ohara 537: send_cmo_distributed_polynomial(oxfp, (cmo_distributed_polynomial *)c);
1.1 ohara 538: break;
539: default:
1.13 ohara 540: call_hook_after_send_cmo(oxfp, c);
1.1 ohara 541: }
542: }
543:
1.22 ! ohara 544: #if defined(WITH_GMP)
1.13 ohara 545: static int send_mpz(OXFILE *oxfp, mpz_ptr mpz)
1.1 ohara 546: {
547: int i;
548: int len = abs(mpz->_mp_size);
1.13 ohara 549: send_int32(oxfp, mpz->_mp_size);
1.1 ohara 550: for(i=0; i<len; i++) {
1.13 ohara 551: send_int32(oxfp, mpz->_mp_d[i]);
1.1 ohara 552: }
553: return 0;
554: }
1.22 ! ohara 555: #endif /* WITH_GMP */
1.1 ohara 556:
557: ox_data* new_ox_data(cmo* c)
558: {
559: ox_data* m = malloc(sizeof(ox_data));
560: m->tag = OX_DATA;
561: m->cmo = c;
562: return m;
563: }
564:
565: ox_command* new_ox_command(int sm_code)
566: {
567: ox_command* m = malloc(sizeof(ox_command));
568: m->tag = OX_COMMAND;
569: m->command = sm_code;
570: return m;
571: }
572:
573: ox_sync_ball* new_ox_sync_ball()
574: {
575: ox_sync_ball *m = malloc(sizeof(ox_sync_ball));
576: m->tag = OX_SYNC_BALL;
577: return m;
1.19 ohara 578: }
579:
580: int ox_stderr_init(FILE *fp)
581: {
1.21 ohara 582: ox_stderr = fp;
583: if (ox_stderr != NULL) {
584: setbuf(ox_stderr, NULL);
585: }
1.20 ohara 586: }
587:
588: int ox_printf(char *format, ...)
589: {
1.21 ohara 590: if (ox_stderr != NULL) {
591: va_list ap;
592: va_start(ap, format);
593: vfprintf(ox_stderr, format, ap);
594: }
1.1 ohara 595: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>