version 1.5, 2000/11/24 05:49:26 |
version 1.17, 2016/08/23 02:24:19 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- 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. */ |
/* This module includes functions for handling mathcap databases. */ |
|
|
|
|
#define MATHCAP_FLAG_DENY 0 |
#define MATHCAP_FLAG_DENY 0 |
#define MATHCAP_FLAG_ALLOW 1 |
#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 void table_init(table *m, int key); |
static table *new_table(int *src); |
static table *new_table(int *src); |
static table *table_lookup(table *tbl, int tag); |
static table *table_lookup(table *tbl, int tag); |
Line 49 static int cmotbl_a[] = { |
|
Line 39 static int cmotbl_a[] = { |
|
CMO_LIST, |
CMO_LIST, |
CMO_MONOMIAL32, |
CMO_MONOMIAL32, |
CMO_ZZ, |
CMO_ZZ, |
|
CMO_QQ, |
|
CMO_BIGFLOAT32, |
|
CMO_COMPLEX, |
|
CMO_IEEE_DOUBLE_FLOAT, |
CMO_ZERO, |
CMO_ZERO, |
CMO_DMS_GENERIC, |
CMO_DMS_GENERIC, |
CMO_RING_BY_NAME, |
CMO_RING_BY_NAME, |
CMO_INDETERMINATE, |
CMO_INDETERMINATE, |
CMO_DISTRIBUTED_POLYNOMIAL, |
CMO_DISTRIBUTED_POLYNOMIAL, |
|
CMO_RECURSIVE_POLYNOMIAL, |
|
CMO_POLYNOMIAL_IN_ONE_VARIABLE, |
CMO_ERROR2, |
CMO_ERROR2, |
0, |
0, |
}; |
}; |
|
|
char *hosttype; |
char *hosttype; |
int *cmo_tags; |
int *cmo_tags; |
int *sm_cmds; |
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__ |
__inline__ |
static void table_init(table *m, int key) |
static void table_init(table *m, int key) |
Line 97 static table *new_table(int *src) |
|
Line 94 static table *new_table(int *src) |
|
int i; |
int i; |
while (src[len++] != 0) { |
while (src[len++] != 0) { |
} |
} |
new = malloc(sizeof(table)*len); |
new = MALLOC(sizeof(table)*len); |
for(i=0; i<len; i++) { |
for(i=0; i<len; i++) { |
table_init(new+i, src[i]); |
table_init(new+i, src[i]); |
} |
} |
return new; |
return new; |
} |
} |
|
|
/* 次の tag についてのキーを探す */ |
/* looking for an item of the tag */ |
static table *table_lookup(table *tbl, int tag) |
static table *table_lookup(table *tbl, int tag) |
{ |
{ |
while (tbl->tag != 0) { |
while (tbl->tag != 0) { |
Line 116 static table *table_lookup(table *tbl, int tag) |
|
Line 113 static table *table_lookup(table *tbl, int tag) |
|
return NULL; |
return NULL; |
} |
} |
|
|
/* tag に対する送信制御 */ |
/* controller about a cmo identified by the tag */ |
static void table_ctl(table *tbl, int tag, int flag) |
static void table_ctl(table *tbl, int tag, int flag) |
{ |
{ |
table *e = table_lookup(tbl, tag); |
table *e = table_lookup(tbl, tag); |
Line 125 static void table_ctl(table *tbl, int tag, int flag) |
|
Line 122 static void table_ctl(table *tbl, int tag, int flag) |
|
} |
} |
} |
} |
|
|
/* 全データに対する送信制御 */ |
/* controller about all CMObjects */ |
static void table_ctl_all(table *tbl, int flag) |
static void table_ctl_all(table *tbl, int flag) |
{ |
{ |
while (tbl->tag != 0) { |
while (tbl->tag != 0) { |
Line 134 static void table_ctl_all(table *tbl, int flag) |
|
Line 131 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) |
static cmo_list *table_get_all(table *tbl) |
{ |
{ |
cmo_list *list = new_cmo_list(); |
cmo_list *list = new_cmo_list(); |
Line 147 static cmo_list *table_get_all(table *tbl) |
|
Line 144 static cmo_list *table_get_all(table *tbl) |
|
return list; |
return list; |
} |
} |
|
|
/* 次の tag をもつ cmo or sm_cmd の送信を許可する */ |
/* giving a permssion to send objects identified by the tag. */ |
__inline__ |
__inline__ |
static void table_allow(table *tbl, int tag) |
static void table_allow(table *tbl, int tag) |
{ |
{ |
table_ctl(tbl, tag, MATHCAP_FLAG_ALLOW); |
table_ctl(tbl, tag, MATHCAP_FLAG_ALLOW); |
} |
} |
|
|
/* 次の tag をもつ cmo or sm_cmd の送信を不許可にする */ |
/* taking a permssion to send objects identified by the tag. */ |
__inline__ |
__inline__ |
static void table_deny(table *tbl, int tag) |
static void table_deny(table *tbl, int tag) |
{ |
{ |
Line 174 static void table_update(table *cmotbl, cmo_list* type |
|
Line 171 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) |
static int table_allowQ_tag(table *tbl, int tag) |
{ |
{ |
while (tbl->tag != 0 && tbl->tag != tag) { |
while (tbl->tag != 0 && tbl->tag != tag) { |
Line 213 static int table_allowQ_cmo_mathcap(table *cmotbl, cmo |
|
Line 210 static int table_allowQ_cmo_mathcap(table *cmotbl, cmo |
|
&& table_allowQ_cmo(cmotbl, ob->ob); |
&& table_allowQ_cmo(cmotbl, ob->ob); |
} |
} |
|
|
/* 次の cmo の送信が許可されているかを調べる */ |
/* getting a permission to send the following object. */ |
static int table_allowQ_cmo(table *cmotbl, cmo *ob) |
static int table_allowQ_cmo(table *cmotbl, cmo *ob) |
{ |
{ |
int tag = ob->tag; |
int tag = ob->tag; |
Line 233 static int table_allowQ_cmo(table *cmotbl, cmo *ob) |
|
Line 230 static int table_allowQ_cmo(table *cmotbl, cmo *ob) |
|
} |
} |
} |
} |
|
|
/* システム情報を得る */ |
/* getting the System Information */ |
static cmo_list *sysinfo_get() |
static cmo_list *sysinfo_get() |
{ |
{ |
cmo_list *syslist = new_cmo_list(); |
cmo_list *syslist = new_cmo_list(); |
Line 246 static cmo_list *sysinfo_get() |
|
Line 243 static cmo_list *sysinfo_get() |
|
|
|
static char *new_string(char *s) |
static char *new_string(char *s) |
{ |
{ |
char *t = malloc(sizeof(s)+1); |
char *t = MALLOC(strlen(s)+1); |
strcpy(t, s); |
strcpy(t, s); |
return t; |
return t; |
} |
} |
Line 257 static int *new_int_array(int *array) |
|
Line 254 static int *new_int_array(int *array) |
|
int length = 0; |
int length = 0; |
while(array[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); |
return memcpy(new_array, array, sizeof(int)*length); |
} |
} |
|
|
void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]) |
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; i<len; i++) { |
|
new[i] = (char *)MALLOC(strlen(src[i])+1); |
|
strcpy(new[i], src[i]); |
|
} |
|
} |
|
return new; |
|
} |
|
|
|
/* options must be terminated by NULL */ |
|
void mathcap_init2(int ver, char *vstr, char *sysname, int cmos[], int sms[], char *options[]) |
|
{ |
char *host = getenv("HOSTTYPE"); |
char *host = getenv("HOSTTYPE"); |
sysinfo.hosttype = (host != NULL)? new_string(host): "UNKNOWN"; |
sysinfo.hosttype = (host != NULL)? new_string(host): "UNKNOWN"; |
sysinfo.sysname = new_string(sysname); |
sysinfo.sysname = new_string(sysname); |
Line 274 void mathcap_init(int ver, char *vstr, char *sysname, |
|
Line 295 void mathcap_init(int ver, char *vstr, char *sysname, |
|
if (sms != NULL) { |
if (sms != NULL) { |
sysinfo.sm_cmds = new_int_array(sms); |
sysinfo.sm_cmds = new_int_array(sms); |
} |
} |
|
sysinfo.opts = clone_str_list(options); |
} |
} |
|
|
mathcap *new_mathcap() |
mathcap *new_mathcap() |
{ |
{ |
mathcap *new = malloc(sizeof(mathcap)); |
mathcap *new = MALLOC(sizeof(mathcap)); |
new->cmotbl = new_table(sysinfo.cmo_tags); |
new->cmotbl = new_table(sysinfo.cmo_tags); |
new->smtbl = new_table(sysinfo.sm_cmds); |
new->smtbl = new_table(sysinfo.sm_cmds); |
|
new->opts = clone_str_list(sysinfo.opts); |
return new; |
return new; |
} |
} |
|
|
/* データベースから cmo_mathcap を生成する */ |
/* generating a cmo_mathcap by a local database. */ |
cmo_mathcap* mathcap_get(mathcap *this) |
cmo_mathcap* mathcap_get(mathcap *this) |
{ |
{ |
cmo_list *mc = new_cmo_list(); |
cmo_list *mc = new_cmo_list(); |
cmo_list *l3 = 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), |
new_cmo_int32(OX_DATA), |
table_get_all(this->cmotbl), NULL)); |
table_get_all(this->cmotbl), NULL)); |
list_appendl(mc, (cmo *)sysinfo_get(), |
if(this->opts) { |
(cmo *)table_get_all(this->smtbl), (cmo *)l3, NULL); |
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); |
return new_cmo_mathcap((cmo *)mc); |
} |
} |
|
|
Line 322 static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap |
|
Line 357 static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap |
|
return get_messagetypes(ob, OX_DATA); |
return get_messagetypes(ob, OX_DATA); |
} |
} |
|
|
/* 受信した mathcap データを反映させる */ |
/* The mathcap_update integrates received cmo_mathcap into the mathcap |
/* this == NULL のとき、はじめて mathcap* オブジェクトをせいせいする */ |
database. If this == NULL, then an instance of mathcap is generated. */ |
mathcap *mathcap_update(mathcap *this, cmo_mathcap *mc) |
mathcap *mathcap_update(mathcap *this, cmo_mathcap *mc) |
{ |
{ |
cmo_list *types; |
cmo_list *types; |
types = cmo_mathcap_get_cmotypes(mc); |
types = cmo_mathcap_get_cmotypes(mc); |
if (types != NULL) { |
if (types != NULL) { |
/* すべての cmo の送信を禁止 */ |
|
table_ctl_all(this->cmotbl, MATHCAP_FLAG_DENY); |
table_ctl_all(this->cmotbl, MATHCAP_FLAG_DENY); |
table_update(this->cmotbl, types); |
table_update(this->cmotbl, types); |
} |
} |