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