=================================================================== RCS file: /home/cvs/OpenXM/src/ox_toolkit/mathcap.c,v retrieving revision 1.5 retrieving revision 1.17 diff -u -p -r1.5 -r1.17 --- OpenXM/src/ox_toolkit/mathcap.c 2000/11/24 05:49:26 1.5 +++ OpenXM/src/ox_toolkit/mathcap.c 2016/08/23 02:24:19 1.17 @@ -1,5 +1,5 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM: OpenXM/src/ox_toolkit/mathcap.c,v 1.4 2000/11/21 07:59:08 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_toolkit/mathcap.c,v 1.16 2016/06/29 05:07:23 ohara Exp $ */ /* This module includes functions for handling mathcap databases. */ @@ -10,16 +10,6 @@ #define MATHCAP_FLAG_DENY 0 #define MATHCAP_FLAG_ALLOW 1 -typedef struct { - int tag; - int flag; -} table; - -typedef struct mathcap { - table *cmotbl; - table *smtbl; -} mathcap; - static void table_init(table *m, int key); static table *new_table(int *src); static table *table_lookup(table *tbl, int tag); @@ -49,11 +39,17 @@ static int cmotbl_a[] = { CMO_LIST, CMO_MONOMIAL32, CMO_ZZ, + CMO_QQ, + CMO_BIGFLOAT32, + CMO_COMPLEX, + CMO_IEEE_DOUBLE_FLOAT, CMO_ZERO, CMO_DMS_GENERIC, CMO_RING_BY_NAME, CMO_INDETERMINATE, CMO_DISTRIBUTED_POLYNOMIAL, + CMO_RECURSIVE_POLYNOMIAL, + CMO_POLYNOMIAL_IN_ONE_VARIABLE, CMO_ERROR2, 0, }; @@ -81,7 +77,8 @@ static struct { char *hosttype; int *cmo_tags; int *sm_cmds; -} sysinfo = {0, "NO VERSION", "NONAME", "UNKNOWN", cmotbl_a, smtbl_a}; + char **opts; +} sysinfo = {0, "NO VERSION", "NONAME", "UNKNOWN", cmotbl_a, smtbl_a, NULL}; __inline__ static void table_init(table *m, int key) @@ -97,14 +94,14 @@ static table *new_table(int *src) int i; while (src[len++] != 0) { } - new = malloc(sizeof(table)*len); + new = MALLOC(sizeof(table)*len); for(i=0; itag != 0) { @@ -116,7 +113,7 @@ static table *table_lookup(table *tbl, int tag) return NULL; } -/* tag に対する送信制御 */ +/* controller about a cmo identified by the tag */ static void table_ctl(table *tbl, int tag, int flag) { table *e = table_lookup(tbl, tag); @@ -125,7 +122,7 @@ static void table_ctl(table *tbl, int tag, int flag) } } -/* 全データに対する送信制御 */ +/* controller about all CMObjects */ static void table_ctl_all(table *tbl, int flag) { while (tbl->tag != 0) { @@ -134,7 +131,7 @@ static void table_ctl_all(table *tbl, int flag) } } -/* 送信許可されている tag のリストを得る */ +/* getting the list of tags of all allowed objects */ static cmo_list *table_get_all(table *tbl) { cmo_list *list = new_cmo_list(); @@ -147,14 +144,14 @@ static cmo_list *table_get_all(table *tbl) return list; } -/* 次の tag をもつ cmo or sm_cmd の送信を許可する */ +/* giving a permssion to send objects identified by the tag. */ __inline__ static void table_allow(table *tbl, int tag) { table_ctl(tbl, tag, MATHCAP_FLAG_ALLOW); } -/* 次の tag をもつ cmo or sm_cmd の送信を不許可にする */ +/* taking a permssion to send objects identified by the tag. */ __inline__ static void table_deny(table *tbl, int tag) { @@ -174,7 +171,7 @@ static void table_update(table *cmotbl, cmo_list* type } } -/* 次の tag をもつ cmo or sm_cmd の送信が許可されているかを調べる */ +/* getting a permission to send objects identified by the tag. */ static int table_allowQ_tag(table *tbl, int tag) { while (tbl->tag != 0 && tbl->tag != tag) { @@ -213,7 +210,7 @@ static int table_allowQ_cmo_mathcap(table *cmotbl, cmo && table_allowQ_cmo(cmotbl, ob->ob); } -/* 次の cmo の送信が許可されているかを調べる */ +/* getting a permission to send the following object. */ static int table_allowQ_cmo(table *cmotbl, cmo *ob) { int tag = ob->tag; @@ -233,7 +230,7 @@ static int table_allowQ_cmo(table *cmotbl, cmo *ob) } } -/* システム情報を得る */ +/* getting the System Information */ static cmo_list *sysinfo_get() { cmo_list *syslist = new_cmo_list(); @@ -246,7 +243,7 @@ static cmo_list *sysinfo_get() static char *new_string(char *s) { - char *t = malloc(sizeof(s)+1); + char *t = MALLOC(strlen(s)+1); strcpy(t, s); return t; } @@ -257,12 +254,36 @@ static int *new_int_array(int *array) int length = 0; while(array[length++] != 0) ; - new_array = malloc(sizeof(int)*length); + new_array = MALLOC(sizeof(int)*length); return memcpy(new_array, array, sizeof(int)*length); } void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]) { + mathcap_init2(ver, vstr, sysname, cmos, sms, NULL); +} + +/* src must be terminated by NULL */ +static char **clone_str_list(char **src) +{ + int i,len; + char **new = NULL; + if(!src) { + for(len=0; src[len]!=NULL; len++) { + } + new = (char **)MALLOC(sizeof(char *)*(len+1)); + new[len] = NULL; + for(i=0; icmotbl = new_table(sysinfo.cmo_tags); new->smtbl = new_table(sysinfo.sm_cmds); + new->opts = clone_str_list(sysinfo.opts); return new; } -/* データベースから cmo_mathcap を生成する */ +/* generating a cmo_mathcap by a local database. */ cmo_mathcap* mathcap_get(mathcap *this) { cmo_list *mc = new_cmo_list(); cmo_list *l3 = new_cmo_list(); - list_append(l3, list_appendl(new_cmo_list(), + cmo_list *si = sysinfo_get(); + cmo_list *sm= table_get_all(this->smtbl); + cmo_list *opts; + int i; + + list_append(l3, (cmo *)list_appendl(new_cmo_list(), new_cmo_int32(OX_DATA), table_get_all(this->cmotbl), NULL)); - list_appendl(mc, (cmo *)sysinfo_get(), - (cmo *)table_get_all(this->smtbl), (cmo *)l3, NULL); + if(this->opts) { + opts = new_cmo_list(); + for(i=0; this->opts[i]!=NULL; i++) { + list_append(opts, (cmo *)new_cmo_string(this->opts[i])); + } + list_appendl(mc, (cmo *)si, (cmo *)sm, (cmo *)l3, (cmo *)opts, NULL); + }else { + list_appendl(mc, (cmo *)si, (cmo *)sm, (cmo *)l3, NULL); + } return new_cmo_mathcap((cmo *)mc); } @@ -322,14 +357,13 @@ static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap return get_messagetypes(ob, OX_DATA); } -/* 受信した mathcap データを反映させる */ -/* this == NULL のとき、はじめて mathcap* オブジェクトをせいせいする */ +/* The mathcap_update integrates received cmo_mathcap into the mathcap + database. If this == NULL, then an instance of mathcap is generated. */ mathcap *mathcap_update(mathcap *this, cmo_mathcap *mc) { cmo_list *types; types = cmo_mathcap_get_cmotypes(mc); if (types != NULL) { - /* すべての cmo の送信を禁止 */ table_ctl_all(this->cmotbl, MATHCAP_FLAG_DENY); table_update(this->cmotbl, types); }