[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.20

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

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