[BACK]Return to ox.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/ox.c, Revision 1.15

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.15    ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.14 2000/10/11 06:56:02 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.8       ohara      49: /* hook functions. (yet not implemented) */
1.2       ohara      50: static hook_t hook_before_send_cmo = NULL;
                     51: static hook_t hook_after_send_cmo  = NULL;
                     52:
                     53: int add_hook_before_send_cmo(hook_t func)
                     54: {
1.13      ohara      55:     hook_before_send_cmo = func;
                     56:     return 0;
1.2       ohara      57: }
                     58:
                     59: int add_hook_after_send_cmo(hook_t func)
                     60: {
1.13      ohara      61:     hook_after_send_cmo = func;
                     62:     return 0;
1.2       ohara      63: }
                     64:
1.13      ohara      65: static cmo *call_hook_before_send_cmo(OXFILE *oxfp, cmo *c)
1.2       ohara      66: {
1.13      ohara      67:     if (hook_before_send_cmo != NULL) {
                     68:         return hook_before_send_cmo(oxfp, c);
                     69:     }
                     70:     return c;
1.2       ohara      71: }
                     72:
1.13      ohara      73: static cmo *call_hook_after_send_cmo(OXFILE *oxfp, cmo *c)
1.2       ohara      74: {
1.13      ohara      75:     if (hook_after_send_cmo != NULL) {
                     76:         return hook_after_send_cmo(oxfp, c);
                     77:     }
                     78:     return c;
1.2       ohara      79: }
1.1       ohara      80:
1.7       ohara      81: /* Handling an error. */
1.1       ohara      82: static int current_received_serial = 0;
                     83:
1.7       ohara      84: /* If an error object be needed, then a server call the following function. */
1.1       ohara      85: cmo_error2* make_error_object(int err_code, cmo *ob)
                     86: {
                     87:     cmo_list* li = new_cmo_list();
1.13      ohara      88:     list_append(li, (cmo *)new_cmo_int32(current_received_serial));
                     89:     list_append(li, (cmo *)new_cmo_int32(err_code));
                     90:     list_append(li, ob);
1.1       ohara      91:     /* 他の情報を加えるならココ */
                     92:     return new_cmo_error2((cmo *)li);
                     93: }
                     94:
                     95: #define DEFAULT_SERIAL_NUMBER 0x0000ffff
1.13      ohara      96: #define receive_serial_number(x)   (receive_int32((x)))
1.1       ohara      97:
1.7       ohara      98: /* getting a next serial number. */
1.13      ohara      99: int next_serial(OXFILE *oxfp)
1.1       ohara     100: {
1.13      ohara     101: /*
1.1       ohara     102:     static int serial_number = DEFAULT_SERIAL_NUMBER;
1.13      ohara     103: */
                    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);
                    123:     current_received_serial = receive_serial_number(oxfp);
                    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.1       ohara     149:     char* s = malloc(len+1);
                    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.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:
                    235: /* receive_ox_tag() == OX_DATA の後に呼び出される */
                    236: /* 関数ポインタを使った方がきれいに書けるような気がする.  */
1.13      ohara     237: /* if (foo[tag] != NULL) foo[tag](oxfp); とか */
1.1       ohara     238:
1.13      ohara     239: cmo* receive_cmo(OXFILE *oxfp)
1.1       ohara     240: {
                    241:     cmo* m;
1.13      ohara     242:     int tag = receive_int32(oxfp);
1.1       ohara     243:     switch(tag) {
                    244:     case CMO_NULL:
1.13      ohara     245:         m = receive_cmo_null(oxfp);
1.1       ohara     246:         break;
                    247:     case CMO_INT32:
1.13      ohara     248:         m = (cmo *)receive_cmo_int32(oxfp);
1.1       ohara     249:         break;
                    250:     case CMO_STRING:
1.13      ohara     251:         m = (cmo *)receive_cmo_string(oxfp);
1.1       ohara     252:         break;
                    253:     case CMO_MATHCAP:
1.13      ohara     254:         m = (cmo *)receive_cmo_mathcap(oxfp);
1.1       ohara     255:         break;
                    256:     case CMO_LIST:
1.13      ohara     257:         m = (cmo *)receive_cmo_list(oxfp);
1.1       ohara     258:         break;
                    259:     case CMO_MONOMIAL32:
1.13      ohara     260:         m = (cmo *)receive_cmo_monomial32(oxfp);
1.1       ohara     261:         break;
                    262:     case CMO_ZZ:
1.13      ohara     263:         m = (cmo *)receive_cmo_zz(oxfp);
1.1       ohara     264:         break;
                    265:     case CMO_ZERO:
1.13      ohara     266:         m = (cmo *)receive_cmo_zero(oxfp);
1.1       ohara     267:         break;
                    268:     case CMO_DMS_GENERIC:
1.13      ohara     269:         m = (cmo *)receive_cmo_dms_generic(oxfp);
1.1       ohara     270:         break;
                    271:     case CMO_RING_BY_NAME:
1.13      ohara     272:         m = (cmo *)receive_cmo_ring_by_name(oxfp);
1.1       ohara     273:         break;
                    274:     case CMO_DISTRIBUTED_POLYNOMIAL:
1.13      ohara     275:         m = (cmo *)receive_cmo_distributed_polynomial(oxfp);
1.1       ohara     276:         break;
                    277:     case CMO_ERROR2:
1.13      ohara     278:         m = (cmo *)receive_cmo_error2(oxfp);
1.1       ohara     279:         break;
                    280:     case CMO_DATUM:
                    281:     case CMO_QQ:
                    282:     default:
1.13      ohara     283:         m = NULL;
                    284:         fprintf(stderr, "the CMO (%d) is not implemented.\n", tag);
1.1       ohara     285:     }
                    286:     return m;
                    287: }
                    288:
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: }
                    300:
1.13      ohara     301: void send_ox_command(OXFILE *oxfp, int sm_command)
1.1       ohara     302: {
1.13      ohara     303:     send_ox_tag(oxfp, OX_COMMAND);
                    304:     send_int32(oxfp, sm_command);
                    305:     oxf_flush(oxfp);
1.1       ohara     306: }
                    307:
1.13      ohara     308: void ox_close(OXFILE *sv)
1.1       ohara     309: {
1.13      ohara     310:     send_ox_command(oxf_control(sv), SM_control_kill);
1.1       ohara     311: #ifdef DEBUG
1.7       ohara     312:     sleep(2);
1.13      ohara     313:     /* We wait thar an OpenXM server terminates. */
1.1       ohara     314:     fprintf(stderr, "I have closed the connection to an Open XM server.\n");
                    315: #endif
                    316: }
                    317:
1.13      ohara     318: void ox_shutdown(OXFILE *sv)
1.3       ohara     319: {
1.13      ohara     320:     /* We need to use SM_shutdown but yet ... */
                    321:     ox_close(sv);
1.3       ohara     322: }
                    323:
1.13      ohara     324: void ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[])
1.3       ohara     325: {
1.13      ohara     326:     int i = argc;
                    327:     while(i-- > 0) {
                    328:         send_ox_cmo(sv, argv[i]);
                    329:     }
                    330:     send_ox_cmo(sv, (cmo *)new_cmo_int32(argc));
                    331:     send_ox_cmo(sv, (cmo *)new_cmo_string(function));
                    332:     send_ox_command(sv, SM_executeFunction);
1.3       ohara     333: }
                    334:
1.13      ohara     335: void ox_execute_string(OXFILE *sv, char* s)
1.3       ohara     336: {
1.13      ohara     337:     send_ox_cmo(sv, (cmo *)new_cmo_string(s));
                    338:     send_ox_command(sv, SM_executeStringByLocalParser);
1.3       ohara     339: }
                    340:
1.13      ohara     341: void ox_push_cmd(OXFILE *sv, int sm_code)
1.1       ohara     342: {
1.13      ohara     343:     send_ox_command(sv, sm_code);
1.1       ohara     344: }
                    345:
1.13      ohara     346: cmo_mathcap* ox_mathcap(OXFILE *sv)
1.1       ohara     347: {
1.13      ohara     348:     send_ox_command(sv, SM_mathcap);
                    349:     send_ox_command(sv, SM_popCMO);
                    350:     receive_ox_tag(sv);          /* OX_DATA */
                    351:     return (cmo_mathcap *)receive_cmo(sv);
1.1       ohara     352: }
                    353:
1.13      ohara     354: char* ox_popString(OXFILE *sv)
1.1       ohara     355: {
                    356:     cmo_string* m = NULL;
                    357:
1.13      ohara     358:     send_ox_command(sv, SM_popString);
                    359:     receive_ox_tag(sv); /* OX_DATA */
                    360:     m = (cmo_string *)receive_cmo(sv);
1.1       ohara     361:     return m->s;
                    362: }
                    363:
1.13      ohara     364: void ox_pops(OXFILE *sv, int num)
1.3       ohara     365: {
1.13      ohara     366:     send_ox_cmo(sv, (cmo *)new_cmo_int32(num));
                    367:     send_ox_command(sv, SM_pops);
1.3       ohara     368: }
                    369:
1.13      ohara     370: cmo* ox_pop_cmo(OXFILE *sv)
1.3       ohara     371: {
1.13      ohara     372:     send_ox_command(sv, SM_popCMO);
                    373:     receive_ox_tag(sv); /* OX_DATA */
                    374:     return receive_cmo(sv);
1.3       ohara     375: }
                    376:
1.13      ohara     377: void ox_push_cmo(OXFILE *sv, cmo *c)
1.3       ohara     378: {
1.13      ohara     379:     send_ox_cmo(sv, c);
1.3       ohara     380: }
                    381:
1.7       ohara     382: /* a dummy function for flushing a connection. */
1.13      ohara     383: int ox_flush(OXFILE *sv)
1.5       ohara     384: {
1.13      ohara     385:     return 1;
1.5       ohara     386: }
                    387:
1.13      ohara     388: void ox_reset(OXFILE *sv)
1.1       ohara     389: {
1.13      ohara     390:     send_ox_command(oxf_control(sv), SM_control_reset_connection);
1.1       ohara     391:
1.13      ohara     392:     receive_ox_tag(oxf_control(sv));      /* OX_DATA */
                    393:     receive_cmo(oxf_control(sv));         /* (CMO_INT32, 0) */
1.1       ohara     394:
1.13      ohara     395:     while(receive_ox_tag(sv) != OX_SYNC_BALL) {
                    396:         receive_cmo(sv); /* skipping a message. */
1.1       ohara     397:     }
                    398:
1.13      ohara     399:     send_ox_tag(sv, OX_SYNC_BALL);
1.1       ohara     400: #ifdef DEBUG
                    401:     fprintf(stderr, "I have reset an Open XM server.\n");
                    402: #endif
                    403: }
                    404:
1.13      ohara     405: void send_ox(OXFILE *oxfp, ox *m)
1.1       ohara     406: {
                    407:     switch(m->tag) {
1.13      ohara     408:     case OX_DATA:
                    409:         send_ox_cmo(oxfp, ((ox_data *)m)->cmo);
1.1       ohara     410:         break;
1.13      ohara     411:     case OX_COMMAND:
                    412:         send_ox_command(oxfp, ((ox_command *)m)->command);
1.1       ohara     413:         break;
                    414:     default:
                    415:         /* CMO?? */
1.13      ohara     416:         send_ox_cmo(oxfp, (cmo *)m);
1.1       ohara     417:     }
                    418: }
                    419:
1.13      ohara     420: void send_ox_cmo(OXFILE *oxfp, cmo* m)
1.1       ohara     421: {
1.13      ohara     422:     send_ox_tag(oxfp, OX_DATA);
                    423:     send_cmo(oxfp, m);
                    424:     oxf_flush(oxfp);
1.1       ohara     425: }
                    426:
1.8       ohara     427: /* send_cmo_* functions */
1.13      ohara     428: static int send_cmo_null(OXFILE *oxfp, cmo_null* c)
1.1       ohara     429: {
                    430:     return 0;
                    431: }
                    432:
1.13      ohara     433: static int send_cmo_int32(OXFILE *oxfp, cmo_int32* m)
1.1       ohara     434: {
1.13      ohara     435:     return send_int32(oxfp, m->i);
1.1       ohara     436: }
                    437:
1.13      ohara     438: static int send_cmo_string(OXFILE *oxfp, cmo_string* m)
1.1       ohara     439: {
                    440:     int len = (m->s != NULL)? strlen(m->s): 0;
1.13      ohara     441:     send_int32(oxfp, len);
1.1       ohara     442:     if (len > 0) {
1.13      ohara     443:         oxf_write(m->s, 1, len, oxfp);
1.1       ohara     444:     }
                    445:     return 0;
                    446: }
                    447:
1.13      ohara     448: static int send_cmo_mathcap(OXFILE *oxfp, cmo_mathcap* c)
1.1       ohara     449: {
1.13      ohara     450:     send_cmo(oxfp, c->ob);
1.1       ohara     451:     return 0;
                    452: }
                    453:
1.13      ohara     454: static int send_cmo_list(OXFILE *oxfp, cmo_list* c)
1.1       ohara     455: {
1.13      ohara     456:     cell* el = list_first(c);
                    457:     int len = list_length(c);
                    458:     send_int32(oxfp, len);
                    459:
                    460:     while(!list_endof(c, el)) {
                    461:         send_cmo(oxfp, el->cmo);
                    462:         el = list_next(el);
1.1       ohara     463:     }
                    464:     return 0;
                    465: }
                    466:
1.13      ohara     467: static int send_cmo_distributed_polynomial(OXFILE *oxfp, cmo_distributed_polynomial* c)
1.1       ohara     468: {
1.13      ohara     469:     cell* el = list_first((cmo_list *)c);
                    470:     int len = list_length((cmo_list *)c);
                    471:     send_int32(oxfp, len);
                    472:     send_cmo(oxfp, c->ringdef);
                    473:     while(!list_endof((cmo_list *)c, el)) {
                    474:         send_cmo(oxfp, el->cmo);
                    475:         el = list_next(el);
1.1       ohara     476:     }
                    477:     return 0;
                    478: }
                    479:
1.13      ohara     480: static int send_cmo_monomial32(OXFILE *oxfp, cmo_monomial32* c)
1.1       ohara     481: {
                    482:     int i;
                    483:     int len = c->length;
1.13      ohara     484:     send_int32(oxfp, len);
1.1       ohara     485:     for(i=0; i<len; i++) {
1.13      ohara     486:         send_int32(oxfp, c->exps[i]);
1.1       ohara     487:     }
1.13      ohara     488:     send_cmo(oxfp, c->coef);
1.1       ohara     489:     return 0;
                    490: }
                    491:
1.13      ohara     492: static int send_cmo_zz(OXFILE *oxfp, cmo_zz* c)
1.1       ohara     493: {
1.13      ohara     494:     send_mpz(oxfp, c->mpz);
1.1       ohara     495:     return 0;
                    496: }
                    497:
1.13      ohara     498: static int send_cmo_error2(OXFILE *oxfp, cmo_error2* c)
1.1       ohara     499: {
1.13      ohara     500:     send_cmo(oxfp, c->ob);
1.1       ohara     501:     return 0;
                    502: }
                    503:
1.8       ohara     504: /* sending a CMO.  (Remarks: OX_tag is already sent.) */
1.13      ohara     505: void send_cmo(OXFILE *oxfp, cmo* c)
1.1       ohara     506: {
                    507:     int tag = c->tag;
                    508:
1.13      ohara     509:     c = call_hook_before_send_cmo(oxfp, c);
1.2       ohara     510:
1.13      ohara     511:     send_int32(oxfp, tag);
1.1       ohara     512:     switch(tag) {
                    513:     case CMO_NULL:
                    514:     case CMO_ZERO:
                    515:     case CMO_DMS_GENERIC:
1.13      ohara     516:         send_cmo_null(oxfp, c);  /* empty function. */
1.1       ohara     517:         break;
                    518:     case CMO_INT32:
1.13      ohara     519:         send_cmo_int32(oxfp, (cmo_int32 *)c);
1.1       ohara     520:         break;
                    521:     case CMO_STRING:
1.13      ohara     522:         send_cmo_string(oxfp, (cmo_string *)c);
1.1       ohara     523:         break;
                    524:     case CMO_MATHCAP:
                    525:     case CMO_ERROR2:
                    526:     case CMO_RING_BY_NAME:
                    527:     case CMO_INDETERMINATE:
1.13      ohara     528:         send_cmo_mathcap(oxfp, (cmo_mathcap *)c);
1.1       ohara     529:         break;
                    530:     case CMO_LIST:
1.13      ohara     531:         send_cmo_list(oxfp, (cmo_list *)c);
1.1       ohara     532:         break;
                    533:     case CMO_MONOMIAL32:
1.13      ohara     534:         send_cmo_monomial32(oxfp, (cmo_monomial32 *)c);
1.1       ohara     535:         break;
                    536:     case CMO_ZZ:
1.13      ohara     537:         send_cmo_zz(oxfp, (cmo_zz *)c);
1.1       ohara     538:         break;
                    539:     case CMO_DISTRIBUTED_POLYNOMIAL:
1.13      ohara     540:         send_cmo_distributed_polynomial(oxfp, (cmo_distributed_polynomial *)c);
1.1       ohara     541:         break;
                    542:     default:
1.13      ohara     543:         call_hook_after_send_cmo(oxfp, c);
1.1       ohara     544:     }
                    545: }
                    546:
1.13      ohara     547: static int send_mpz(OXFILE *oxfp, mpz_ptr mpz)
1.1       ohara     548: {
                    549:     int i;
                    550:     int len = abs(mpz->_mp_size);
1.13      ohara     551:     send_int32(oxfp, mpz->_mp_size);
1.1       ohara     552:     for(i=0; i<len; i++) {
1.13      ohara     553:         send_int32(oxfp, mpz->_mp_d[i]);
1.1       ohara     554:     }
                    555:     return 0;
                    556: }
                    557:
                    558: ox_data* new_ox_data(cmo* c)
                    559: {
                    560:     ox_data* m = malloc(sizeof(ox_data));
                    561:     m->tag = OX_DATA;
                    562:     m->cmo = c;
                    563:     return m;
                    564: }
                    565:
                    566: ox_command* new_ox_command(int sm_code)
                    567: {
                    568:     ox_command* m = malloc(sizeof(ox_command));
                    569:     m->tag = OX_COMMAND;
                    570:     m->command = sm_code;
                    571:     return m;
                    572: }
                    573:
                    574: ox_sync_ball* new_ox_sync_ball()
                    575: {
                    576:     ox_sync_ball *m = malloc(sizeof(ox_sync_ball));
                    577:     m->tag = OX_SYNC_BALL;
                    578:     return m;
                    579: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>