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

Annotation of OpenXM/src/ox_toolkit/dump.c, Revision 1.2

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.2     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/dump.c,v 1.1 2000/10/10 05:23:20 ohara Exp $ */
1.1       ohara       3:
                      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.
                      8: */
                      9:
                     10: #include <stdio.h>
                     11: #include <stdlib.h>
                     12: #include <sys/param.h>
                     13: #include "ox_toolkit.h"
                     14:
                     15: static void dump_cmo_int32(cmo_int32* m);
                     16: static void dump_cmo_list(cmo_list* m);
                     17: static void dump_cmo_mathcap(cmo_mathcap* m);
                     18: static void dump_cmo_null(cmo_null* m);
                     19: static void dump_cmo_string(cmo_string* m);
                     20: static void dump_cmo_monomial32(cmo_monomial32* c);
1.2     ! ohara      21: #if defined(WITH_GMP)
1.1       ohara      22: static void dump_cmo_zz(cmo_zz* c);
1.2     ! ohara      23: static void dump_mpz(mpz_ptr mpz);
        !            24: #endif /* WITH_GMP */
1.1       ohara      25: static void dump_string(void *s, int len);
                     26: static void dump_integer(int x);
                     27:
                     28: /* functions encoding cmo to binary */
                     29:
                     30: static int  d_ptr;
                     31: static char *d_buf;
                     32:
                     33: void dump_buffer_init(char *s)
                     34: {
                     35:     d_buf = s;
                     36:     d_ptr = 0;
                     37: }
                     38:
                     39: static void dump_string(void *s, int len)
                     40: {
                     41:     memcpy(&d_buf[d_ptr], s, len);
                     42:     d_ptr += len;
                     43: }
                     44:
                     45: static void dump_integer(int x)
                     46: {
                     47:     x = htonl(x);
                     48:     dump_string(&x, sizeof(int));
                     49: }
                     50:
1.2     ! ohara      51: #if defined(WITH_GMP)
1.1       ohara      52: static void dump_mpz(mpz_ptr mpz)
                     53: {
                     54:     int i;
                     55:     int len = abs(mpz->_mp_size);
                     56:     dump_integer(mpz->_mp_size);
                     57:     for(i=0; i<len; i++) {
                     58:         dump_integer(mpz->_mp_d[i]);
                     59:     }
                     60: }
1.2     ! ohara      61: #endif /* WITH_GMP */
1.1       ohara      62:
                     63: __inline__
                     64: static void dump_cmo_null(cmo_null* m)
                     65: {
                     66:     return;
                     67: }
                     68:
                     69: static void dump_cmo_int32(cmo_int32* m)
                     70: {
                     71:     dump_integer(m->i);
                     72: }
                     73:
                     74: static void dump_cmo_string(cmo_string* m)
                     75: {
                     76:     int len = strlen(m->s);
                     77:     dump_integer(len);
                     78:     dump_string(m->s, len);
                     79: }
                     80:
                     81: static void dump_cmo_mathcap(cmo_mathcap* c)
                     82: {
                     83:     dump_cmo(c->ob);
                     84: }
                     85:
                     86: static void dump_cmo_list(cmo_list* m)
                     87: {
                     88:     cell* cp = list_first(m);
                     89:     int len  = list_length(m);
                     90:     dump_integer(len);
                     91:     while(!list_endof(m, cp)) {
                     92:         dump_cmo(cp->cmo);
                     93:         cp = list_next(cp);
                     94:     }
                     95: }
                     96:
                     97: static void dump_cmo_monomial32(cmo_monomial32* c)
                     98: {
                     99:     int i;
                    100:     int length = c->length;
                    101:     dump_integer(c->length);
                    102:     for(i=0; i<length; i++) {
                    103:         dump_integer(c->exps[i]);
                    104:     }
                    105:     dump_cmo(c->coef);
                    106: }
                    107:
1.2     ! ohara     108: #if defined(WITH_GMP)
1.1       ohara     109: static void dump_cmo_zz(cmo_zz* c)
                    110: {
                    111:     dump_mpz(c->mpz);
                    112: }
1.2     ! ohara     113: #endif /* WITH_GMP */
1.1       ohara     114:
                    115: static void dump_cmo_distributed_polynomial(cmo_distributed_polynomial* m)
                    116: {
                    117:     cell* cp;
                    118:     dump_integer(list_length(m));
                    119:     dump_cmo(m->ringdef);
                    120:     for(cp = list_first(m); !list_endof(m, cp); cp = list_next(cp)) {
                    121:         dump_cmo(cp->cmo);
                    122:     }
                    123: }
                    124:
                    125: /* after its tag is sent, we invoke each functions. */
                    126: void dump_cmo(cmo* m)
                    127: {
                    128:     dump_integer(m->tag);
                    129:     switch(m->tag) {
                    130:     case CMO_NULL:
                    131:     case CMO_ZERO:
                    132:     case CMO_DMS_GENERIC:
                    133:         dump_cmo_null(m);
                    134:         break;
                    135:     case CMO_INT32:
                    136:         dump_cmo_int32((cmo_int32 *)m);
                    137:         break;
                    138:     case CMO_STRING:
                    139:         dump_cmo_string((cmo_string *)m);
                    140:         break;
                    141:     case CMO_MATHCAP:
                    142:     case CMO_RING_BY_NAME:
                    143:     case CMO_INDETERMINATE:
                    144:     case CMO_ERROR2:
                    145:         dump_cmo_mathcap((cmo_mathcap *)m);
                    146:         break;
                    147:     case CMO_LIST:
                    148:         dump_cmo_list((cmo_list *)m);
                    149:         break;
                    150:     case CMO_MONOMIAL32:
                    151:         dump_cmo_monomial32((cmo_monomial32 *)m);
                    152:         break;
1.2     ! ohara     153: #if defined(WITH_GMP)
1.1       ohara     154:     case CMO_ZZ:
                    155:         dump_cmo_zz((cmo_zz *)m);
                    156:         break;
1.2     ! ohara     157: #endif /* WITH_GMP */
1.1       ohara     158:     case CMO_DISTRIBUTED_POLYNOMIAL:
                    159:         dump_cmo_distributed_polynomial((cmo_distributed_polynomial *)m);
                    160:         break;
                    161:     default:
                    162:     }
                    163: }
                    164:
                    165: void dump_ox_data(ox_data* m)
                    166: {
                    167:     dump_integer(OX_DATA);
                    168:     dump_integer(-1);
                    169:     dump_cmo(m->cmo);
                    170: }
                    171:
                    172: void dump_ox_command(ox_command* m)
                    173: {
                    174:     dump_integer(OX_COMMAND);
                    175:     dump_integer(-1);
                    176:     dump_integer(m->command);
                    177: }
                    178:
                    179:

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