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