| version 1.2, 1999/11/02 06:11:57 |
version 1.4, 1999/11/02 21:15:02 |
|
|
| /* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
| /* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/ox_math/ox.c,v 1.3 1999/11/02 18:58:25 ohara Exp $ */ |
| /* $Id$ */ |
/* $Id$ */ |
| |
|
| /* |
/* |
| Line 45 static int cmolen_cmo_string(cmo_string* c); |
|
| Line 45 static int cmolen_cmo_string(cmo_string* c); |
|
| static int cmolen_cmo_zz(cmo_zz* c); |
static int cmolen_cmo_zz(cmo_zz* c); |
| static int cmolen_cmo_monomial32(cmo_monomial32* c); |
static int cmolen_cmo_monomial32(cmo_monomial32* c); |
| |
|
| static char* dump_cmo_int32(char* array, cmo_int32* m); |
static int dump_cmo_int32(cmo_int32* m); |
| static char* dump_cmo_list(char* array, cmo_list* m); |
static int dump_cmo_list(cmo_list* m); |
| static char* dump_cmo_mathcap(char* array, cmo_mathcap* m); |
static int dump_cmo_mathcap(cmo_mathcap* m); |
| static char* dump_cmo_null(char* array, cmo_null* m); |
static int dump_cmo_null(cmo_null* m); |
| static char* dump_cmo_string(char* array, cmo_string* m); |
static int dump_cmo_string(cmo_string* m); |
| static char* dump_cmo_monomial32(char* array, cmo_monomial32* c); |
static int dump_cmo_monomial32(cmo_monomial32* c); |
| static char* dump_cmo_zz(char* array, cmo_zz* c); |
static int dump_cmo_zz(cmo_zz* c); |
| static char* dump_integer(char* array, int x); |
static int dump_string(char *s, int len); |
| static char* dump_mpz(char* array, mpz_ptr mpz); |
static int dump_integer(int x); |
| |
static int dump_mpz(mpz_ptr mpz); |
| |
|
| static int funcs(int cmo_type); |
static int funcs(int cmo_type); |
| |
|
| Line 384 cmo_indeterminate* new_cmo_indeterminate(cmo* ob) |
|
| Line 385 cmo_indeterminate* new_cmo_indeterminate(cmo* ob) |
|
| return c; |
return c; |
| } |
} |
| |
|
| |
cmo_distributed_polynomial* new_cmo_distributed_polynomial() |
| |
{ |
| |
cmo_distributed_polynomial* c = malloc(sizeof(cmo_distributed_polynomial)); |
| |
c->tag = CMO_DISTRIBUTED_POLYNOMIAL; |
| |
c->length = 0; |
| |
c->head = NULL; |
| |
c->ringdef = NULL; |
| |
return c; |
| |
} |
| |
|
| cmo_error2* new_cmo_error2(cmo* ob) |
cmo_error2* new_cmo_error2(cmo* ob) |
| { |
{ |
| cmo_error2* c = malloc(sizeof(cmo_error2)); |
cmo_error2* c = malloc(sizeof(cmo_error2)); |
| Line 493 int print_cmo_string(cmo_string* c) |
|
| Line 504 int print_cmo_string(cmo_string* c) |
|
| } |
} |
| |
|
| /* ox_start() から呼び出す */ |
/* ox_start() から呼び出す */ |
| |
/* OneTimePassword の処理 */ |
| static int read_password(int fd, char* passwd) |
static int read_password(int fd, char* passwd) |
| { |
{ |
| char buff[1024]; |
char buff[1024]; |
| Line 579 ox_file_t ox_start(char* host, char* prog1, char* prog |
|
| Line 591 ox_file_t ox_start(char* host, char* prog1, char* prog |
|
| } |
} |
| |
|
| sv->control = mysocketAccept(sv->control); |
sv->control = mysocketAccept(sv->control); |
| read_password(sv->control, pass); |
decideByteOrderWithReadPasswd(sv->control, sv->control, 0, pass); |
| decideByteOrder(sv->control, sv->control, 0); |
|
| usleep(10); |
usleep(10); |
| sv->stream = mysocketAccept(sv->stream); |
sv->stream = mysocketAccept(sv->stream); |
| read_password(sv->stream, pass); |
decideByteOrderWithReadPasswd(sv->control, sv->control, 0, pass); |
| decideByteOrder(sv->stream, sv->stream, 0); |
|
| |
|
| return sv; |
return sv; |
| } |
} |
| Line 655 static int cmolen_cmo_zz(cmo_zz* c) |
|
| Line 665 static int cmolen_cmo_zz(cmo_zz* c) |
|
| return sizeof(len) + len*sizeof(int); |
return sizeof(len) + len*sizeof(int); |
| } |
} |
| |
|
| |
static int cmolen_cmo_distributed_polynomial(cmo_distributed_polynomial* c) |
| |
{ |
| |
return cmolen_cmo_list((cmo_list *)c) + cmolen_cmo(c->ringdef); |
| |
} |
| |
|
| /* CMO がバイトエンコードされた場合のバイト列の長さを求める */ |
/* CMO がバイトエンコードされた場合のバイト列の長さを求める */ |
| int cmolen_cmo(cmo* c) |
int cmolen_cmo(cmo* c) |
| { |
{ |
| Line 686 int cmolen_cmo(cmo* c) |
|
| Line 701 int cmolen_cmo(cmo* c) |
|
| case CMO_ZZ: |
case CMO_ZZ: |
| size += cmolen_cmo_zz((cmo_zz *)c); |
size += cmolen_cmo_zz((cmo_zz *)c); |
| break; |
break; |
| |
case CMO_DISTRIBUTED_POLYNOMIAL: |
| |
size += cmolen_cmo_distributed_polynomial((cmo_distributed_polynomial *)c); |
| |
break; |
| default: |
default: |
| } |
} |
| return size; |
return size; |
| } |
} |
| |
|
| static char* dump_cmo_null(char* array, cmo_null* m) |
static int d_ptr; |
| |
static char *d_buf; |
| |
|
| |
int init_dump_buffer(char *s) |
| { |
{ |
| return array; |
d_buf = s; |
| |
d_ptr = 0; |
| } |
} |
| |
|
| static char* dump_cmo_int32(char* array, cmo_int32* m) |
static int dump_cmo_null(cmo_null* m) |
| { |
{ |
| return dump_integer(array, m->i); |
return 0; |
| } |
} |
| |
|
| static char* dump_cmo_string(char* array, cmo_string* m) |
static int dump_cmo_int32(cmo_int32* m) |
| { |
{ |
| |
dump_integer(m->i); |
| |
} |
| |
|
| |
static int dump_cmo_string(cmo_string* m) |
| |
{ |
| int len = strlen(m->s); |
int len = strlen(m->s); |
| array = dump_integer(array, len); |
dump_integer(len); |
| memcpy(array, m->s, len); |
dump_string(m->s, len); |
| return array + len; |
|
| } |
} |
| |
|
| static char* dump_cmo_mathcap(char* array, cmo_mathcap* c) |
static int dump_cmo_mathcap(cmo_mathcap* c) |
| { |
{ |
| return dump_cmo(array, c->ob); |
dump_cmo(c->ob); |
| } |
} |
| |
|
| static char* dump_cmo_list(char* array, cmo_list* m) |
static int dump_cmo_list(cmo_list* m) |
| { |
{ |
| cell* cp = m->head; |
cell* cp = m->head; |
| int len = length_cmo_list(m); |
int len = length_cmo_list(m); |
| array = dump_integer(array, len); |
dump_integer(len); |
| |
|
| while(cp != NULL) { |
while(cp != NULL) { |
| array = dump_cmo(array, cp->cmo); |
dump_cmo(cp->cmo); |
| cp = cp->next; |
cp = cp->next; |
| } |
} |
| return array; |
|
| } |
} |
| |
|
| static char* dump_cmo_monomial32(char* array, cmo_monomial32* c) |
static int dump_cmo_monomial32(cmo_monomial32* c) |
| { |
{ |
| int i; |
int i; |
| int length = c->length; |
int length = c->length; |
| array = dump_integer(array, c->length); |
dump_integer(c->length); |
| for(i=0; i<length; i++) { |
for(i=0; i<length; i++) { |
| array = dump_integer(array, c->exps[i]); |
dump_integer(c->exps[i]); |
| } |
} |
| array = dump_cmo(array, c->coef); |
dump_cmo(c->coef); |
| return array; |
|
| } |
} |
| |
|
| static char* dump_cmo_zz(char* array, cmo_zz* c) |
static int dump_cmo_zz(cmo_zz* c) |
| { |
{ |
| return dump_mpz(array, c->mpz); |
dump_mpz(c->mpz); |
| } |
} |
| |
|
| |
static int dump_cmo_distributed_polynomial(cmo_distributed_polynomial* m) |
| |
{ |
| |
cell* cp = m->head; |
| |
int len = length_cmo_list((cmo_list *)m); |
| |
dump_integer(len); |
| |
dump_cmo(m->ringdef); |
| |
while(cp != NULL) { |
| |
dump_cmo(cp->cmo); |
| |
cp = cp->next; |
| |
} |
| |
} |
| |
|
| /* タグを書き出してから、各関数を呼び出す */ |
/* タグを書き出してから、各関数を呼び出す */ |
| char* dump_cmo(char* array, cmo* m) |
int dump_cmo(cmo* m) |
| { |
{ |
| array = dump_integer(array, m->tag); |
dump_integer(m->tag); |
| switch(m->tag) { |
switch(m->tag) { |
| case CMO_NULL: |
case CMO_NULL: |
| case CMO_ZERO: |
case CMO_ZERO: |
| case CMO_DMS_GENERIC: |
case CMO_DMS_GENERIC: |
| return dump_cmo_null(array, m); |
dump_cmo_null(m); |
| |
break; |
| case CMO_INT32: |
case CMO_INT32: |
| return dump_cmo_int32(array, (cmo_int32 *)m); |
dump_cmo_int32((cmo_int32 *)m); |
| |
break; |
| case CMO_STRING: |
case CMO_STRING: |
| return dump_cmo_string(array, (cmo_string *)m); |
dump_cmo_string((cmo_string *)m); |
| |
break; |
| case CMO_MATHCAP: |
case CMO_MATHCAP: |
| case CMO_RING_BY_NAME: |
case CMO_RING_BY_NAME: |
| case CMO_ERROR2: |
case CMO_ERROR2: |
| return dump_cmo_mathcap(array, (cmo_mathcap *)m); |
dump_cmo_mathcap((cmo_mathcap *)m); |
| |
break; |
| case CMO_LIST: |
case CMO_LIST: |
| return dump_cmo_list(array, (cmo_list *)m); |
dump_cmo_list((cmo_list *)m); |
| |
break; |
| case CMO_MONOMIAL32: |
case CMO_MONOMIAL32: |
| return dump_cmo_monomial32(array, (cmo_monomial32 *)m); |
dump_cmo_monomial32((cmo_monomial32 *)m); |
| |
break; |
| case CMO_ZZ: |
case CMO_ZZ: |
| return dump_cmo_zz(array, (cmo_zz *)m); |
dump_cmo_zz((cmo_zz *)m); |
| |
break; |
| |
case CMO_DISTRIBUTED_POLYNOMIAL: |
| |
dump_cmo_distributed_polynomial((cmo_distributed_polynomial *)m); |
| |
break; |
| default: |
default: |
| return NULL; |
|
| } |
} |
| } |
} |
| |
|
| static char* dump_integer(char* array, int x) |
static int dump_mpz(mpz_ptr mpz) |
| { |
{ |
| int nx = htonl(x); |
|
| memcpy(array, &nx, sizeof(int)); |
|
| return array + sizeof(int); |
|
| } |
|
| |
|
| static char* dump_mpz(char* array, mpz_ptr mpz) |
|
| { |
|
| int i; |
int i; |
| int len = abs(mpz->_mp_size); |
int len = abs(mpz->_mp_size); |
| array = dump_integer(array, mpz->_mp_size); |
dump_integer(mpz->_mp_size); |
| for(i=0; i<len; i++) { |
for(i=0; i<len; i++) { |
| array = dump_integer(array, mpz->_mp_d[i]); |
dump_integer(mpz->_mp_d[i]); |
| } |
} |
| return array; |
return; |
| } |
} |
| |
|
| |
static int dump_string(char *s, int len) |
| |
{ |
| |
memcpy(&d_buf[d_ptr], s, len); |
| |
d_ptr += len; |
| |
} |
| |
|
| |
static int dump_integer(int x) |
| |
{ |
| |
int nx = htonl(x); |
| |
dump_string((char *)&nx, sizeof(int)); |
| |
} |
| |
|
| |
int dump_ox_data(ox_data* m) |
| |
{ |
| |
dump_integer(OX_DATA); |
| |
dump_integer(-1); |
| |
dump_cmo(m->cmo); |
| |
} |
| |
|
| |
int dump_ox_command(ox_command* m) |
| |
{ |
| |
dump_integer(OX_COMMAND); |
| |
dump_integer(-1); |
| |
dump_integer(m->command); |
| |
} |
| |
|
| int send_ox(ox_file_t s, ox *m) |
int send_ox(ox_file_t s, ox *m) |
| { |
{ |
| int tag = m->tag; |
int tag = m->tag; |
| Line 927 ox_command* new_ox_command(int sm_code) |
|
| Line 990 ox_command* new_ox_command(int sm_code) |
|
| return m; |
return m; |
| } |
} |
| |
|
| char* dump_ox_data(char* array, ox_data* m) |
|
| { |
|
| array = dump_integer(array, OX_DATA); |
|
| array = dump_integer(array, -1); |
|
| return dump_cmo(array, m->cmo); |
|
| } |
|
| |
|
| char* dump_ox_command(char* array, ox_command* m) |
|
| { |
|
| array = dump_integer(array, OX_COMMAND); |
|
| array = dump_integer(array, -1); |
|
| return dump_integer(array, m->command); |
|
| } |
|
| |
|
| #define MAX_TYPES 8 |
#define MAX_TYPES 8 |
| static int known_types[] = { |
static int known_types[] = { |
| -1, /* gate keeper */ |
-1, /* gate keeper */ |
| Line 1028 cmo* receive_cmo2(int fd) |
|
| Line 1077 cmo* receive_cmo2(int fd) |
|
| return foo(fd); |
return foo(fd); |
| } |
} |
| } |
} |
| #endif |
#endif |
| |
|
| /* ファイルディスクリプタ fd の通信路での integer の byte order を決定する */ |
/* ファイルディスクリプタ fd の通信路での integer の byte order を決定する */ |
| /* 実際には order (0,1,or 0xFF)をみてはいない */ |
/* 実際には order (0,1,or 0xFF)をみてはいない */ |
| |
int decideByteOrderWithReadPasswd(int fd_read, int fd_write, int order, char* passwd) |
| |
{ |
| |
char zero = OX_BYTE_NETWORK_BYTE_ORDER; |
| |
char dest; |
| |
read_password(fd_read, passwd); |
| |
write(fd_write, &zero, sizeof(char)); |
| |
read(fd_read, &dest, sizeof(char)); |
| |
return 0; |
| |
} |
| |
|
| |
/* ファイルディスクリプタ fd の通信路での integer の byte order を決定する */ |
| |
/* 実際には order (0,1,or 0xFF)をみてはいない */ |
| int decideByteOrder(int fd_read, int fd_write, int order) |
int decideByteOrder(int fd_read, int fd_write, int order) |
| { |
{ |
| char zero = '\0'; |
char zero = OX_BYTE_NETWORK_BYTE_ORDER; |
| char dest; |
char dest; |
| write(fd_write, &zero, 1); |
write(fd_write, &zero, sizeof(char)); |
| read(fd_read, &dest, 1); |
read(fd_read, &dest, sizeof(char)); |
| return 0; |
return 0; |
| } |
} |
| |
|
| /* Server 側ではこちらを用いる */ |
/* Server 側ではこちらを用いる */ |
| int decideByteOrder2(int fd_read, int fd_write, int order) |
int decideByteOrder2(int fd_read, int fd_write, int order) |
| { |
{ |
| char zero = '\0'; |
char zero = OX_BYTE_NETWORK_BYTE_ORDER; |
| char dest; |
char dest; |
| read(fd_read, &dest, 1); |
read(fd_read, &dest, sizeof(char)); |
| write(fd_write, &zero, 1); |
write(fd_write, &zero, sizeof(char)); |
| return 0; |
return 0; |
| } |
} |
| |
|