version 1.6, 2003/01/17 06:49:53 |
version 1.9, 2003/03/23 20:17:34 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM: OpenXM/src/ox_toolkit/cmo.c,v 1.5 2003/01/13 12:03:12 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. |
This module includes functions for sending/receiveng CMO's. |
Line 18 static cell* new_cell(); |
|
Line 18 static cell* new_cell(); |
|
static char* new_string_set_cmo_null(); |
static char* new_string_set_cmo_null(); |
static char* new_string_set_cmo_int32(int integer); |
static char* new_string_set_cmo_int32(int integer); |
static char* new_string_set_cmo_list(cmo_list *c); |
static char* new_string_set_cmo_list(cmo_list *c); |
|
#if defined(WITH_GMP) |
static char* new_string_set_cmo_zz(cmo_zz *c); |
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 */ |
/* functions for a cmo_list */ |
static cell* new_cell(cmo *ob) |
static cell* new_cell(cmo *ob) |
Line 101 cmo *list_nth(cmo_list* this, int n) |
|
Line 104 cmo *list_nth(cmo_list* this, int n) |
|
return NULL; |
return NULL; |
} |
} |
|
|
|
#if defined(WITH_GMP) |
/* for GNU mpz */ |
/* for GNU mpz */ |
void resize_mpz(mpz_ptr mpz, int size) |
void resize_mpz(mpz_ptr mpz, int size) |
{ |
{ |
_mpz_realloc(mpz, abs(size)); |
_mpz_realloc(mpz, abs(size)); |
mpz->_mp_size = size; |
mpz->_mp_size = size; |
} |
} |
|
#endif /* WITH_GMP */ |
|
|
/* functions named new_cmo_*. */ |
/* functions named new_cmo_*. */ |
cmo_null* new_cmo_null() |
cmo_null* new_cmo_null() |
Line 173 cmo_monomial32* new_cmo_monomial32_size(int size) |
|
Line 178 cmo_monomial32* new_cmo_monomial32_size(int size) |
|
return c; |
return c; |
} |
} |
|
|
|
#if defined(WITH_GMP) |
cmo_zz* new_cmo_zz() |
cmo_zz* new_cmo_zz() |
{ |
{ |
cmo_zz* c = malloc(sizeof(cmo_zz)); |
cmo_zz* c = malloc(sizeof(cmo_zz)); |
Line 215 cmo_zz* new_cmo_zz_size(int size) |
|
Line 221 cmo_zz* new_cmo_zz_size(int size) |
|
resize_mpz(c->mpz, size); |
resize_mpz(c->mpz, size); |
return c; |
return c; |
} |
} |
|
#endif /* WITH_GMP */ |
|
|
cmo_zero* new_cmo_zero() |
cmo_zero* new_cmo_zero() |
{ |
{ |
Line 274 cmo_error2* new_cmo_error2(cmo* ob) |
|
Line 281 cmo_error2* new_cmo_error2(cmo* ob) |
|
} |
} |
|
|
|
|
|
#if defined(WITH_GMP) |
/* Following functions translate cmo's to (asciiz) strings. */ |
/* Following functions translate cmo's to (asciiz) strings. */ |
static char *new_string_set_cmo_zz(cmo_zz *c) |
static char *new_string_set_cmo_zz(cmo_zz *c) |
{ |
{ |
return mpz_get_str(NULL, 10, c->mpz); |
return mpz_get_str(NULL, 10, c->mpz); |
} |
} |
|
#endif /* WITH_GMP */ |
|
|
static char *new_string_set_cmo_null() |
static char *new_string_set_cmo_null() |
{ |
{ |
Line 324 static char *new_string_set_cmo_list(cmo_list *m) |
|
Line 333 static char *new_string_set_cmo_list(cmo_list *m) |
|
return s; |
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) |
char *new_string_set_cmo(cmo *m) |
{ |
{ |
symbol_t symp; |
|
switch(m->tag) { |
switch(m->tag) { |
|
#if defined(WITH_GMP) |
case CMO_ZZ: |
case CMO_ZZ: |
return new_string_set_cmo_zz((cmo_zz *)m); |
return new_string_set_cmo_zz((cmo_zz *)m); |
|
#endif /* WITH_GMP */ |
case CMO_INT32: |
case CMO_INT32: |
return new_string_set_cmo_int32(((cmo_int32 *)m)->i); |
return new_string_set_cmo_int32(((cmo_int32 *)m)->i); |
case CMO_STRING: |
case CMO_STRING: |
Line 338 char *new_string_set_cmo(cmo *m) |
|
Line 360 char *new_string_set_cmo(cmo *m) |
|
return new_string_set_cmo_null(); |
return new_string_set_cmo_null(); |
case CMO_LIST: |
case CMO_LIST: |
return new_string_set_cmo_list((cmo_list *)m); |
return new_string_set_cmo_list((cmo_list *)m); |
|
case CMO_64BIT_MACHINE_DOUBLE: |
|
return new_string_set_cmo_int32(m); |
default: |
default: |
#ifdef DEBUG |
ox_printf("unconvertible <%s>\n", get_symbol_by_tag(m->tag)); |
symp = lookup_by_tag(m->tag); |
|
ox_printf("I do not know how to convert %s to a string.\n", symp->key); |
|
#endif |
|
/* yet not implemented. */ |
/* yet not implemented. */ |
return NULL; |
return NULL; |
} |
} |
} |
} |
|
|