version 1.1, 2000/10/10 05:23:20 |
version 1.8, 2003/02/03 23:13:23 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/ox_toolkit/cmo.c,v 1.7 2003/01/17 07:40:10 ohara Exp $ */ |
|
|
/* |
/* |
This module includes functions for sending/receiveng CMO's. |
This module includes functions for sending/receiveng CMO's. |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdarg.h> |
#include <stdarg.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
|
#include <errno.h> |
|
#include <fcntl.h> |
|
#include <sys/file.h> |
|
|
|
#include "mysocket.h" |
|
#include "ox_toolkit.h" |
#include "ox_toolkit.h" |
#include "parse.h" |
#include "parse.h" |
|
|
static cell* new_cell(); |
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); |
static char* new_string_set_cmo_zz(cmo_zz *c); |
static char* new_string_set_cmo_zz(cmo_zz *c); |
|
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 80 cmo_list *list_appendl(cmo_list* this, ...) |
|
Line 74 cmo_list *list_appendl(cmo_list* this, ...) |
|
cmo *ob; |
cmo *ob; |
va_list ap; |
va_list ap; |
va_start(ap, this); |
va_start(ap, this); |
|
if (this == NULL) { |
|
this = new_cmo_list(); |
|
} |
while((ob = va_arg(ap, cmo *)) != NULL) { |
while((ob = va_arg(ap, cmo *)) != NULL) { |
list_append(this, ob); |
list_append(this, ob); |
} |
} |
Line 227 cmo_zero* new_cmo_zero() |
|
Line 224 cmo_zero* new_cmo_zero() |
|
return m; |
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* new_cmo_dms_generic() |
{ |
{ |
cmo_dms_generic* m = malloc(sizeof(cmo_dms_generic)); |
cmo_dms_generic* m = malloc(sizeof(cmo_dms_generic)); |
Line 269 cmo_error2* new_cmo_error2(cmo* ob) |
|
Line 274 cmo_error2* new_cmo_error2(cmo* ob) |
|
return c; |
return c; |
} |
} |
|
|
/* cmo と string (ここではC言語のstring) の変換関数群 */ |
|
|
/* 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); |
Line 319 static char *new_string_set_cmo_list(cmo_list *m) |
|
Line 325 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) { |
case CMO_ZZ: |
case CMO_ZZ: |
return new_string_set_cmo_zz((cmo_zz *)m); |
return new_string_set_cmo_zz((cmo_zz *)m); |
Line 333 char *new_string_set_cmo(cmo *m) |
|
Line 350 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); |
|
fprintf(stderr, "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; |
} |
} |
} |
} |
|
|