=================================================================== RCS file: /home/cvs/OpenXM/src/ox_toolkit/cmo.c,v retrieving revision 1.4 retrieving revision 1.9 diff -u -p -r1.4 -r1.9 --- OpenXM/src/ox_toolkit/cmo.c 2003/01/11 11:42:31 1.4 +++ OpenXM/src/ox_toolkit/cmo.c 2003/03/23 20:17:34 1.9 @@ -1,5 +1,5 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM: OpenXM/src/ox_toolkit/cmo.c,v 1.3 2000/12/14 01:39:31 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_toolkit/cmo.c,v 1.8 2003/02/03 23:13:23 ohara Exp $ */ /* This module includes functions for sending/receiveng CMO's. @@ -18,7 +18,10 @@ static cell* new_cell(); static char* new_string_set_cmo_null(); static char* new_string_set_cmo_int32(int integer); static char* new_string_set_cmo_list(cmo_list *c); +#if defined(WITH_GMP) static char* new_string_set_cmo_zz(cmo_zz *c); +#endif /* WITH_GMP */ +static char* new_string_set_cmo_double(cmo_double *m); /* functions for a cmo_list */ static cell* new_cell(cmo *ob) @@ -101,12 +104,14 @@ cmo *list_nth(cmo_list* this, int n) return NULL; } +#if defined(WITH_GMP) /* for GNU mpz */ void resize_mpz(mpz_ptr mpz, int size) { _mpz_realloc(mpz, abs(size)); mpz->_mp_size = size; } +#endif /* WITH_GMP */ /* functions named new_cmo_*. */ cmo_null* new_cmo_null() @@ -173,6 +178,7 @@ cmo_monomial32* new_cmo_monomial32_size(int size) return c; } +#if defined(WITH_GMP) cmo_zz* new_cmo_zz() { cmo_zz* c = malloc(sizeof(cmo_zz)); @@ -215,6 +221,7 @@ cmo_zz* new_cmo_zz_size(int size) resize_mpz(c->mpz, size); return c; } +#endif /* WITH_GMP */ cmo_zero* new_cmo_zero() { @@ -223,6 +230,14 @@ cmo_zero* new_cmo_zero() return m; } +cmo_double *new_cmo_double(double d) +{ + cmo_double* m = malloc(sizeof(cmo_double)); + m->tag = CMO_64BIT_MACHINE_DOUBLE; + m->d = d; + return m; +} + cmo_dms_generic* new_cmo_dms_generic() { cmo_dms_generic* m = malloc(sizeof(cmo_dms_generic)); @@ -266,11 +281,13 @@ cmo_error2* new_cmo_error2(cmo* ob) } +#if defined(WITH_GMP) /* Following functions translate cmo's to (asciiz) strings. */ static char *new_string_set_cmo_zz(cmo_zz *c) { return mpz_get_str(NULL, 10, c->mpz); } +#endif /* WITH_GMP */ static char *new_string_set_cmo_null() { @@ -316,12 +333,25 @@ static char *new_string_set_cmo_list(cmo_list *m) return s; } +static char *new_string_set_cmo_double(cmo_double *m) +{ + char buff[1024]; + char *s; + + sprintf(buff, "%lf", m->d); + s = malloc(strlen(buff)+1); + strcpy(s, buff); + + return s; +} + char *new_string_set_cmo(cmo *m) { - symbol_t symp; switch(m->tag) { +#if defined(WITH_GMP) case CMO_ZZ: return new_string_set_cmo_zz((cmo_zz *)m); +#endif /* WITH_GMP */ case CMO_INT32: return new_string_set_cmo_int32(((cmo_int32 *)m)->i); case CMO_STRING: @@ -330,13 +360,11 @@ char *new_string_set_cmo(cmo *m) return new_string_set_cmo_null(); case CMO_LIST: return new_string_set_cmo_list((cmo_list *)m); + case CMO_64BIT_MACHINE_DOUBLE: + return new_string_set_cmo_int32(m); default: -#ifdef DEBUG - symp = lookup_by_tag(m->tag); - fprintf(ox_stderr, "I do not know how to convert %s to a string.\n", symp->key); -#endif + ox_printf("unconvertible <%s>\n", get_symbol_by_tag(m->tag)); /* yet not implemented. */ return NULL; } } -