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