version 1.4, 2000/11/21 07:59:08 |
version 1.14, 2015/08/04 05:24:44 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM: OpenXM/src/ox_toolkit/mathcap.c,v 1.3 2000/11/18 05:49:18 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/ox_toolkit/mathcap.c,v 1.13 2005/10/12 04:03:37 takayama Exp $ */ |
|
|
/* This module includes functions for handling mathcap databases. */ |
/* This module includes functions for handling mathcap databases. */ |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
|
#include <string.h> |
#include "ox_toolkit.h" |
#include "ox_toolkit.h" |
|
|
/* 送信許可されている cmo, sm のリストを得る */ |
#define MATHCAP_FLAG_DENY 0 |
#define smdb_get_allow_all(x) mcdb_get_allow_all((x)) |
#define MATHCAP_FLAG_ALLOW 1 |
#define cmodb_get_allow_all(x) mcdb_get_allow_all((x)) |
|
|
|
/* 全ての種類の cmo の送信を許可/不許可にする */ |
static void table_init(table *m, int key); |
#define cmodb_deny_all(x) mcdb_ctl_all((x), MATHCAP_FLAG_DENY) |
static table *new_table(int *src); |
#define cmodb_allow_all(x) mcdb_ctl_all((x), MATHCAP_FLAG_ALLOW) |
static table *table_lookup(table *tbl, int tag); |
|
static void table_ctl(table *tbl, int tag, int flag); |
typedef struct { |
static void table_ctl_all(table *tbl, int flag); |
int tag; |
static cmo_list *table_get_all(table *tbl); |
int flag; |
static void table_allow(table *tbl, int tag); |
} mcdb; |
static void table_deny(table *tbl, int tag); |
|
static void table_update(table *cmotbl, cmo_list* types); |
typedef struct { |
static int table_allowQ_tag(table *tbl, int tag); |
mcdb *cmodb; |
static int table_allowQ_cmo_list(table *cmotbl, cmo_list *ob); |
mcdb *smdb; |
static int table_allowQ_cmo_monomial32(table *cmotbl, cmo_monomial32 *ob); |
} mathcap; |
static int table_allowQ_cmo_mathcap(table *cmotbl, cmo_mathcap *ob); |
|
static int table_allowQ_cmo(table *cmotbl, cmo *ob); |
|
static cmo_list *sysinfo_get(); |
static char *new_string(char *s); |
static char *new_string(char *s); |
static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap *mc); |
static int *new_int_array(int *array); |
static cmo_list *get_messagetypes(cmo_list *ob, int type); |
static cmo_list *get_messagetypes(cmo_list *ob, int type); |
static cmo_list *mcdb_get_allow_all(mcdb *db); |
static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap *mc); |
static cmo_list *sysinfo_get_all(); |
|
static int cmodb_isallow_cmo(mcdb *cmodb, cmo *ob); |
|
static int cmodb_isallow_cmo_list(mcdb *cmodb, cmo_list *ob); |
|
static int cmodb_isallow_cmo_mathcap(mcdb *cmodb, cmo_mathcap *ob); |
|
static int cmodb_isallow_cmo_monomial32(mcdb *cmodb, cmo_monomial32 *ob); |
|
static int cmodb_isallow_tag(mcdb *cmodb, int tag); |
|
static mcdb *mcdb_lookup(mcdb *db, int tag); |
|
static mcdb *new_mcdb(int *src); |
|
static void cmodb_allow(mcdb *cmodb, int tag); |
|
static void cmodb_deny(mcdb *cmodb, int tag); |
|
static void cmodb_update(mcdb *cmodb, cmo_list* types); |
|
static void mcdb_ctl(mcdb *db, int tag, int flag); |
|
static void mcdb_ctl_all(mcdb *db, int flag); |
|
static void mcdb_init(mcdb *m, int key); |
|
static void sysinfo_set(int version, char *version_string, char *sysname); |
|
|
|
static int cmodb_d[] = { |
static int cmotbl_a[] = { |
CMO_NULL, |
CMO_NULL, |
CMO_INT32, |
CMO_INT32, |
CMO_DATUM, |
CMO_DATUM, |
Line 53 static int cmodb_d[] = { |
|
Line 39 static int cmodb_d[] = { |
|
CMO_LIST, |
CMO_LIST, |
CMO_MONOMIAL32, |
CMO_MONOMIAL32, |
CMO_ZZ, |
CMO_ZZ, |
|
CMO_QQ, |
|
CMO_BIGFLOAT, |
|
CMO_IEEE_DOUBLE_FLOAT, |
CMO_ZERO, |
CMO_ZERO, |
CMO_DMS_GENERIC, |
CMO_DMS_GENERIC, |
CMO_RING_BY_NAME, |
CMO_RING_BY_NAME, |
Line 62 static int cmodb_d[] = { |
|
Line 51 static int cmodb_d[] = { |
|
0, |
0, |
}; |
}; |
|
|
static int smdb_d[] = { |
static int smtbl_a[] = { |
SM_popCMO, |
SM_popCMO, |
SM_popString, |
SM_popString, |
SM_mathcap, |
SM_mathcap, |
Line 73 static int smdb_d[] = { |
|
Line 62 static int smdb_d[] = { |
|
SM_shutdown, |
SM_shutdown, |
SM_control_kill, |
SM_control_kill, |
SM_control_reset_connection, |
SM_control_reset_connection, |
|
SM_control_spawn_server, |
|
SM_control_terminate_server, |
0, |
0, |
}; |
}; |
|
|
|
static struct { |
|
int version; |
|
char *version_string; |
|
char *sysname; |
|
char *hosttype; |
|
int *cmo_tags; |
|
int *sm_cmds; |
|
} sysinfo = {0, "NO VERSION", "NONAME", "UNKNOWN", cmotbl_a, smtbl_a}; |
|
|
__inline__ |
__inline__ |
static void mcdb_init(mcdb *m, int key) |
static void table_init(table *m, int key) |
{ |
{ |
m->tag = key; |
m->tag = key; |
m->flag = MATHCAP_FLAG_ALLOW; |
m->flag = MATHCAP_FLAG_ALLOW; |
} |
} |
|
|
static mcdb *new_mcdb(int *src) |
static table *new_table(int *src) |
{ |
{ |
mcdb *new; |
table *new; |
int len=0; |
int len=0; |
int i; |
int i; |
while (src[len++] != 0) { |
while (src[len++] != 0) { |
} |
} |
new = malloc(sizeof(mcdb)*len); |
new = MALLOC(sizeof(table)*len); |
for(i=0; i<len; i++) { |
for(i=0; i<len; i++) { |
mcdb_init(new+i, src[i]); |
table_init(new+i, src[i]); |
} |
} |
return new; |
return new; |
} |
} |
|
|
mathcap *new_mathcap_d() |
/* looking for an item of the tag */ |
|
static table *table_lookup(table *tbl, int tag) |
{ |
{ |
mathcap *new = malloc(sizeof(mathcap)); |
while (tbl->tag != 0) { |
new->cmodb = new_mcdb(cmodb_d); |
if (tbl->tag == tag) { |
new->smdb = new_mcdb(smdb_d); |
return tbl; |
return new; |
|
} |
|
|
|
/* 次の tag についてのキーを探す */ |
|
static mcdb *mcdb_lookup(mcdb *db, int tag) |
|
{ |
|
while (db->tag != 0) { |
|
if (db->tag == tag) { |
|
return db; |
|
} |
} |
db++; |
tbl++; |
} |
} |
return NULL; |
return NULL; |
} |
} |
|
|
/* tag に対する送信制御 */ |
/* controller about a cmo identified by the tag */ |
static void mcdb_ctl(mcdb *db, int tag, int flag) |
static void table_ctl(table *tbl, int tag, int flag) |
{ |
{ |
mcdb *e = mcdb_lookup(db, tag); |
table *e = table_lookup(tbl, tag); |
if (e != NULL) { |
if (e != NULL) { |
e->flag = flag; |
e->flag = flag; |
} |
} |
} |
} |
|
|
/* 全データに対する送信制御 */ |
/* controller about all CMObjects */ |
static void mcdb_ctl_all(mcdb *db, int flag) |
static void table_ctl_all(table *tbl, int flag) |
{ |
{ |
while (db->tag != 0) { |
while (tbl->tag != 0) { |
db->flag = flag; |
tbl->flag = flag; |
db++; |
tbl++; |
} |
} |
} |
} |
|
|
/* 送信許可されている tag のリストを得る */ |
/* getting the list of tags of all allowed objects */ |
static cmo_list *mcdb_get_allow_all(mcdb *db) |
static cmo_list *table_get_all(table *tbl) |
{ |
{ |
cmo_list *list = new_cmo_list(); |
cmo_list *list = new_cmo_list(); |
while (db->tag != 0) { |
while (tbl->tag != 0) { |
if (db->flag == MATHCAP_FLAG_ALLOW) { |
if (tbl->flag == MATHCAP_FLAG_ALLOW) { |
list_append(list, (cmo *)new_cmo_int32(db->tag)); |
list_append(list, (cmo *)new_cmo_int32(tbl->tag)); |
} |
} |
db++; |
tbl++; |
} |
} |
return list; |
return list; |
} |
} |
|
|
static struct { |
/* giving a permssion to send objects identified by the tag. */ |
int version; |
__inline__ |
char *version_string; |
static void table_allow(table *tbl, int tag) |
char *sysname; |
{ |
char *hosttype; |
table_ctl(tbl, tag, MATHCAP_FLAG_ALLOW); |
int *cmo_tags; |
} |
int *sm_cmds; |
|
} sysinfo = {0, "NO VERSION", "NONAME", "UNKNOWN", cmodb_d, smdb_d}; |
|
|
|
/* 次の tag をもつ cmo の送信が許可されているかを調べる */ |
/* taking a permssion to send objects identified by the tag. */ |
static int cmodb_isallow_tag(mcdb *cmodb, int tag) |
__inline__ |
|
static void table_deny(table *tbl, int tag) |
{ |
{ |
while (cmodb->tag != 0 && cmodb->tag != tag) { |
table_ctl(tbl, tag, MATHCAP_FLAG_DENY); |
cmodb++; |
} |
|
|
|
static void table_update(table *cmotbl, cmo_list* types) |
|
{ |
|
cell *el = list_first(types); |
|
cmo_int32 *ob; |
|
while(!list_endof(types, el)) { |
|
ob = (cmo_int32 *)el->cmo; |
|
if (ob->tag == CMO_INT32) { |
|
table_allow(cmotbl, ob->i); |
|
} |
|
el = list_next(el); |
} |
} |
return cmodb->flag; |
|
} |
} |
|
|
static int cmodb_isallow_cmo_list(mcdb *cmodb, cmo_list *ob) |
/* 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) { |
|
tbl++; |
|
} |
|
return tbl->flag; |
|
} |
|
|
|
static int table_allowQ_cmo_list(table *cmotbl, cmo_list *ob) |
|
{ |
cell *el; |
cell *el; |
if (cmodb_isallow_tag(cmodb, ob->tag)) { |
if (table_allowQ_tag(cmotbl, ob->tag)) { |
el = list_first(ob); |
el = list_first(ob); |
while (!list_endof(ob, el)) { |
while (!list_endof(ob, el)) { |
if (!cmodb_isallow_cmo(cmodb, el->cmo)) { |
if (!table_allowQ_cmo(cmotbl, el->cmo)) { |
return MATHCAP_FLAG_DENY; |
return MATHCAP_FLAG_DENY; |
} |
} |
el = list_next(el); |
el = list_next(el); |
Line 183 static int cmodb_isallow_cmo_list(mcdb *cmodb, cmo_lis |
|
Line 193 static int cmodb_isallow_cmo_list(mcdb *cmodb, cmo_lis |
|
} |
} |
|
|
__inline__ |
__inline__ |
static int cmodb_isallow_cmo_monomial32(mcdb *cmodb, cmo_monomial32 *ob) |
static int table_allowQ_cmo_monomial32(table *cmotbl, cmo_monomial32 *ob) |
{ |
{ |
return cmodb_isallow_tag(cmodb, ob->tag) |
return table_allowQ_tag(cmotbl, ob->tag) |
&& cmodb_isallow_cmo(cmodb, ob->coef); |
&& table_allowQ_cmo(cmotbl, ob->coef); |
} |
} |
|
|
__inline__ |
__inline__ |
static int cmodb_isallow_cmo_mathcap(mcdb *cmodb, cmo_mathcap *ob) |
static int table_allowQ_cmo_mathcap(table *cmotbl, cmo_mathcap *ob) |
{ |
{ |
return cmodb_isallow_tag(cmodb, ob->tag) |
return table_allowQ_tag(cmotbl, ob->tag) |
&& cmodb_isallow_cmo(cmodb, ob->ob); |
&& table_allowQ_cmo(cmotbl, ob->ob); |
} |
} |
|
|
/* 次の cmo の送信が許可されているかを調べる */ |
/* getting a permission to send the following object. */ |
static int cmodb_isallow_cmo(mcdb *cmodb, cmo *ob) |
static int table_allowQ_cmo(table *cmotbl, cmo *ob) |
{ |
{ |
int tag = ob->tag; |
int tag = ob->tag; |
switch(tag) { |
switch(tag) { |
case CMO_LIST: |
case CMO_LIST: |
case CMO_DISTRIBUTED_POLYNOMIAL: |
case CMO_DISTRIBUTED_POLYNOMIAL: |
return cmodb_isallow_cmo_list(cmodb, (cmo_list *)ob); |
return table_allowQ_cmo_list(cmotbl, (cmo_list *)ob); |
case CMO_MATHCAP: |
case CMO_MATHCAP: |
case CMO_ERROR2: |
case CMO_ERROR2: |
case CMO_RING_BY_NAME: |
case CMO_RING_BY_NAME: |
case CMO_INDETERMINATE: |
case CMO_INDETERMINATE: |
return cmodb_isallow_cmo_mathcap(cmodb, (cmo_mathcap *)ob); |
return table_allowQ_cmo_mathcap(cmotbl, (cmo_mathcap *)ob); |
case CMO_MONOMIAL32: |
case CMO_MONOMIAL32: |
return cmodb_isallow_cmo_monomial32(cmodb, (cmo_monomial32 *)ob); |
return table_allowQ_cmo_monomial32(cmotbl, (cmo_monomial32 *)ob); |
default: |
default: |
return cmodb_isallow_tag(cmodb, tag); |
return table_allowQ_tag(cmotbl, tag); |
} |
} |
} |
} |
|
|
/* 次の tag をもつ cmo の送信を許可する */ |
/* getting the System Information */ |
__inline__ |
static cmo_list *sysinfo_get() |
static void cmodb_allow(mcdb *cmodb, int tag) |
|
{ |
{ |
mcdb_ctl(cmodb, tag, MATHCAP_FLAG_ALLOW); |
|
} |
|
|
|
/* 次の tag をもつ cmo の送信を不許可にする */ |
|
__inline__ |
|
static void cmodb_deny(mcdb *cmodb, int tag) |
|
{ |
|
mcdb_ctl(cmodb, tag, MATHCAP_FLAG_DENY); |
|
} |
|
|
|
/* システム情報を得る */ |
|
static cmo_list *sysinfo_get_all() |
|
{ |
|
cmo_list *syslist = new_cmo_list(); |
cmo_list *syslist = new_cmo_list(); |
cmo_int32 *ver = new_cmo_int32(sysinfo.version); |
cmo_int32 *ver = new_cmo_int32(sysinfo.version); |
cmo_string *vers = new_cmo_string(sysinfo.version_string); |
cmo_string *vers = new_cmo_string(sysinfo.version_string); |
Line 241 static cmo_list *sysinfo_get_all() |
|
Line 237 static cmo_list *sysinfo_get_all() |
|
return list_appendl(syslist, ver, sname, vers, host, NULL); |
return list_appendl(syslist, ver, sname, vers, host, NULL); |
} |
} |
|
|
__inline__ |
|
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; |
} |
} |
|
|
void sysinfo_set(int version, char *vstr, char *sysname) |
static int *new_int_array(int *array) |
{ |
{ |
|
int *new_array; |
|
int length = 0; |
|
while(array[length++] != 0) |
|
; |
|
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[]) |
|
{ |
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); |
sysinfo.version_string = new_string(vstr); |
sysinfo.version_string = new_string(vstr); |
sysinfo.version = version; |
sysinfo.version = ver; |
|
if (cmos != NULL) { |
|
sysinfo.cmo_tags = new_int_array(cmos); |
|
} |
|
if (sms != NULL) { |
|
sysinfo.sm_cmds = new_int_array(sms); |
|
} |
} |
} |
|
|
void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]) |
mathcap *new_mathcap() |
{ |
{ |
sysinfo_set(ver, vstr, sysname); /* global! */ |
mathcap *new = MALLOC(sizeof(mathcap)); |
if (cmos == NULL) { |
new->cmotbl = new_table(sysinfo.cmo_tags); |
cmos = cmodb_d; |
new->smtbl = new_table(sysinfo.sm_cmds); |
} |
return new; |
if (sms == NULL) { |
|
sms = smdb_d; |
|
} |
|
/* ... */ |
|
} |
} |
|
|
/* データベースから 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(), |
list_append(l3, (cmo *)list_appendl(new_cmo_list(), |
new_cmo_int32(OX_DATA), |
new_cmo_int32(OX_DATA), |
cmodb_get_allow_all(this->cmodb), NULL)); |
table_get_all(this->cmotbl), NULL)); |
list_appendl(mc, (cmo *)sysinfo_get_all(), |
list_appendl(mc, (cmo *)sysinfo_get(), |
(cmo *)smdb_get_allow_all(this->smdb), (cmo *)l3, NULL); |
(cmo *)table_get_all(this->smtbl), (cmo *)l3, NULL); |
return new_cmo_mathcap((cmo *)mc); |
return new_cmo_mathcap((cmo *)mc); |
} |
} |
|
|
static void cmodb_update(mcdb *cmodb, cmo_list* types) |
|
{ |
|
cell *el = list_first(types); |
|
cmo_int32 *ob; |
|
while(!list_endof(types, el)) { |
|
ob = (cmo_int32 *)el->cmo; |
|
if (ob->tag == CMO_INT32) { |
|
cmodb_allow(cmodb, ob->i); |
|
} |
|
el = list_next(el); |
|
} |
|
} |
|
|
|
/* cmo_mathcap が妥当な構造を持つかを調べる. (未実装) */ |
|
int cmo_mathcap_isvalid(cmo_mathcap *mc) |
|
{ |
|
/* print_cmo(mc); */ |
|
return 1; |
|
} |
|
|
|
/* ( ..., ( type, (...) ), (cmo_int32, (...) ), ... ) */ |
/* ( ..., ( type, (...) ), (cmo_int32, (...) ), ... ) */ |
/* ^^^^^ Here! */ |
/* ^^^^^ Here! */ |
static cmo_list *get_messagetypes(cmo_list *ob, int type) |
static cmo_list *get_messagetypes(cmo_list *ob, int type) |
Line 328 static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap |
|
Line 315 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; |
if (cmo_mathcap_isvalid(mc)) { |
types = cmo_mathcap_get_cmotypes(mc); |
types = cmo_mathcap_get_cmotypes(mc); |
if (types != NULL) { |
if (types != NULL) { |
table_ctl_all(this->cmotbl, MATHCAP_FLAG_DENY); |
cmodb_deny_all(this->cmodb); /* すべての cmo の送信を禁止 */ |
table_update(this->cmotbl, types); |
cmodb_update(this->cmodb, types); |
|
} |
|
} |
} |
return this; |
|
|
return this; |
|
} |
|
|
|
int mathcap_allowQ_cmo(mathcap *this, cmo *ob) |
|
{ |
|
return table_allowQ_cmo(this->cmotbl, ob); |
} |
} |