[BACK]Return to mathcap.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Diff for /OpenXM/src/ox_toolkit/mathcap.c between version 1.2 and 1.3

version 1.2, 2000/10/12 15:40:41 version 1.3, 2000/11/18 05:49:18
Line 1 
Line 1 
 /* -*- mode: C; coding: euc-japan -*- */  /* -*- mode: C; coding: euc-japan -*- */
 /* $OpenXM: OpenXM/src/ox_toolkit/mathcap.c,v 1.1 2000/10/10 05:23:20 ohara Exp $ */  /* $OpenXM: OpenXM/src/ox_toolkit/mathcap.c,v 1.2 2000/10/12 15:40:41 ohara Exp $ */
   
 /* This module includes functions for handling mathcap databases. */  /* This module includes functions for handling mathcap databases. */
   
 #include <stdlib.h>  #include <stdlib.h>
 #include "ox_toolkit.h"  #include "ox_toolkit.h"
   
   /* 送信許可されている cmo, sm のリストを得る */
   #define smdb_get_allow_all(x)   mcdb_get_allow_all((x)->sm_db)
   #define cmodb_get_allow_all(x)  mcdb_get_allow_all((x)->cmo_db)
   
   /* 全ての種類の cmo の送信を許可/不許可にする */
   #define cmodb_deny_all(x)   mcdb_ctl_all((x), MATHCAP_FLAG_DENY)
   #define cmodb_allow_all(x)  mcdb_ctl_all((x), MATHCAP_FLAG_ALLOW)
   
 typedef struct {  typedef struct {
     int tag;      int tag;
     int flag;      int flag;
 } mcdb;  } mcdb;
   
 static mcdb *mcdb_lookup(mcdb *db, int tag);  typedef struct {
 static void mcdb_ctl(mcdb *db, int tag, int flag);      mcdb *cmo_db;
 static void mcdb_ctl_all(mcdb *db, int flag);      mcdb *sm_db;
 static cmo_list *mcdb_get_allow_all(mcdb *db);  } mathcap;
   
 static char *new_string(char *s);  static char *new_string(char *s);
 static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap *mc);  static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap *mc);
 static cmo_list *get_messagetypes(cmo_list *ob, int type);  static cmo_list *get_messagetypes(cmo_list *ob, int type);
 static cmo_list *mathcap_sm_get_all();  static cmo_list *mcdb_get_allow_all(mcdb *db);
 static cmo_list *mathcap_sysinfo_get_all();  static cmo_list *sysinfo_get_all();
 static int mathcap_cmo_isallow_cmo_list(cmo_list *ob);  static int cmodb_isallow_cmo(mcdb *cmo_db, cmo *ob);
 static int mathcap_cmo_isallow_cmo_mathcap(cmo_mathcap *ob);  static int cmodb_isallow_cmo_list(mcdb *cmo_db, cmo_list *ob);
 static int mathcap_cmo_isallow_cmo_monomial32(cmo_monomial32 *ob);  static int cmodb_isallow_cmo_mathcap(mcdb *cmo_db, cmo_mathcap *ob);
 static int mathcap_cmo_isallow_tag(int tag);  static int cmodb_isallow_cmo_monomial32(mcdb *cmo_db, cmo_monomial32 *ob);
 static void mathcap_cmo_allow(int tag);  static int cmodb_isallow_tag(mcdb *cmo_db, int tag);
 static void mathcap_cmo_allow_all();  static mcdb *mcdb_lookup(mcdb *db, int tag);
 static void mathcap_cmo_deny(int tag);  static mcdb *new_mcdb(int *src);
 static void mathcap_cmo_deny_all();  static void cmodb_allow(mcdb *cmo_db, int tag);
 static void mathcap_cmo_update(cmo_list* types);  static void cmodb_deny(mcdb *cmo_db, int tag);
   static void cmodb_update(mcdb *cmo_db, 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);
   void sysinfo_set(int version, char *version_string, char *sysname);
   
 static mcdb mathcap_cmo[] = {  static int cmodb_d[] = {
     {CMO_NULL,       MATHCAP_FLAG_ALLOW},      CMO_NULL,
     {CMO_INT32,      MATHCAP_FLAG_ALLOW},      CMO_INT32,
     {CMO_DATUM,      MATHCAP_FLAG_ALLOW},      CMO_DATUM,
     {CMO_STRING,     MATHCAP_FLAG_ALLOW},      CMO_STRING,
     {CMO_MATHCAP,    MATHCAP_FLAG_ALLOW},      CMO_MATHCAP,
     {CMO_LIST,       MATHCAP_FLAG_ALLOW},      CMO_LIST,
     {CMO_MONOMIAL32, MATHCAP_FLAG_ALLOW},      CMO_MONOMIAL32,
     {CMO_ZZ,         MATHCAP_FLAG_ALLOW},      CMO_ZZ,
     {CMO_ZERO,       MATHCAP_FLAG_ALLOW},      CMO_ZERO,
     {CMO_DMS_GENERIC, MATHCAP_FLAG_ALLOW},      CMO_DMS_GENERIC,
     {CMO_RING_BY_NAME, MATHCAP_FLAG_ALLOW},      CMO_RING_BY_NAME,
     {CMO_INDETERMINATE, MATHCAP_FLAG_ALLOW},      CMO_INDETERMINATE,
     {CMO_DISTRIBUTED_POLYNOMIAL, MATHCAP_FLAG_ALLOW},      CMO_DISTRIBUTED_POLYNOMIAL,
     {CMO_ERROR2,     MATHCAP_FLAG_ALLOW},      CMO_ERROR2,
     {0,              MATHCAP_FLAG_DENY}      0,
 };  };
   
 static mcdb mathcap_sm[] = {  static int smdb_d[] = {
     {SM_popCMO,     MATHCAP_FLAG_ALLOW},      SM_popCMO,
     {SM_popString,      MATHCAP_FLAG_ALLOW},      SM_popString,
     {SM_mathcap,        MATHCAP_FLAG_ALLOW},      SM_mathcap,
     {SM_pops,           MATHCAP_FLAG_ALLOW},      SM_pops,
     {SM_executeStringByLocalParser,             MATHCAP_FLAG_ALLOW},      SM_executeStringByLocalParser,
     {SM_executeFunction,        MATHCAP_FLAG_ALLOW},      SM_executeFunction,
     {SM_setMathCap,                 MATHCAP_FLAG_ALLOW},      SM_setMathCap,
     {SM_shutdown,                   MATHCAP_FLAG_ALLOW},      SM_shutdown,
     {SM_control_kill,           MATHCAP_FLAG_ALLOW},      SM_control_kill,
     {SM_control_reset_connection,               MATHCAP_FLAG_ALLOW},      SM_control_reset_connection,
     {0,              MATHCAP_FLAG_DENY}      0,
 };  };
   
 typedef struct {  __inline__
         mcdb *cmo_db;  static void mcdb_init(mcdb *m, int key)
         mcdb *sm_db;  {
 } mathcap;      m->tag  = key;
       m->flag = MATHCAP_FLAG_ALLOW;
   }
   
 mathcap default_mathcap = {mathcap_cmo, mathcap_sm};  static mcdb *new_mcdb(int *src)
   
 mcdb *new_mcdb(mcdb *src)  
 {  {
         mcdb *new;      mcdb *new;
         int len=0;      int len=0;
         while ((src+(len++))->tag != 0) {      int i;
         }      while (src[len++] != 0) {
         new = malloc(sizeof(mcdb)*len);      }
         memcpy(new, src, sizeof(mcdb)*len);      new = malloc(sizeof(mcdb)*len);
         return new;      for(i=0; i<len; i++) {
           mcdb_init(new+i, src[i]);
       }
       return new;
 }  }
   
 mathcap *new_mathcap()  mathcap *new_mathcap_d()
 {  {
         mathcap *new = malloc(sizeof(mathcap));      mathcap *new = malloc(sizeof(mathcap));
         new->cmo_db = new_mcdb(mathcap_cmo);      new->cmo_db = new_mcdb(cmodb_d);
         new->sm_db  = new_mcdb(mathcap_sm);      new->sm_db  = new_mcdb(smdb_d);
         return new;      return new;
 }  }
   
 /* 次の tag についてのキーを探す */  /* 次の tag についてのキーを探す */
Line 137  static struct {
Line 153  static struct {
     char *version_string;      char *version_string;
     char *sysname;      char *sysname;
     char *hosttype;      char *hosttype;
 } mathcap_sysinfo = {0, "NO VERSION", "NONAME", "UNKNOWN"};  } sysinfo = {0, "NO VERSION", "NONAME", "UNKNOWN"};
   
 /* 次の tag をもつ cmo の送信が許可されているかを調べる */  /* 次の tag をもつ cmo の送信が許可されているかを調べる */
 static int mathcap_cmo_isallow_tag(int tag)  static int cmodb_isallow_tag(mcdb *cmo_db, int tag)
 {  {
     mcdb *e = mathcap_cmo;      while (cmo_db->tag != 0 && cmo_db->tag != tag) {
     while (e->tag != 0 && e->tag != tag) {          cmo_db++;
         e++;  
     }      }
     return e->flag;      return cmo_db->flag;
 }  }
   
 static int mathcap_cmo_isallow_cmo_list(cmo_list *ob)  static int cmodb_isallow_cmo_list(mcdb *cmo_db, cmo_list *ob)
 {  {
     cell *el;      cell *el;
     if (mathcap_cmo_isallow_tag(ob->tag)) {      if (cmodb_isallow_tag(cmo_db, ob->tag)) {
         el = list_first(ob);          el = list_first(ob);
         while (!list_endof(ob, el)) {          while (!list_endof(ob, el)) {
             if (!mathcap_cmo_isallow_cmo(el->cmo)) {              if (!cmodb_isallow_cmo(cmo_db, el->cmo)) {
                 return MATHCAP_FLAG_DENY;                  return MATHCAP_FLAG_DENY;
             }              }
             el = list_next(el);              el = list_next(el);
Line 166  static int mathcap_cmo_isallow_cmo_list(cmo_list *ob)
Line 181  static int mathcap_cmo_isallow_cmo_list(cmo_list *ob)
 }  }
   
 __inline__  __inline__
 static int mathcap_cmo_isallow_cmo_monomial32(cmo_monomial32 *ob)  static int cmodb_isallow_cmo_monomial32(mcdb *cmo_db, cmo_monomial32 *ob)
 {  {
     return mathcap_cmo_isallow_tag(ob->tag)      return cmodb_isallow_tag(cmo_db, ob->tag)
         && mathcap_cmo_isallow_cmo(ob->coef);          && cmodb_isallow_cmo(cmo_db, ob->coef);
 }  }
   
 __inline__  __inline__
 static int mathcap_cmo_isallow_cmo_mathcap(cmo_mathcap *ob)  static int cmodb_isallow_cmo_mathcap(mcdb *cmo_db, cmo_mathcap *ob)
 {  {
     return mathcap_cmo_isallow_tag(ob->tag)      return cmodb_isallow_tag(cmo_db, ob->tag)
         && mathcap_cmo_isallow_cmo(ob->ob);          && cmodb_isallow_cmo(cmo_db, ob->ob);
 }  }
   
 /* 次の cmo の送信が許可されているかを調べる */  /* 次の cmo の送信が許可されているかを調べる */
 int mathcap_cmo_isallow_cmo(cmo *ob)  static int cmodb_isallow_cmo(mcdb *cmo_db, 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 mathcap_cmo_isallow_cmo_list((cmo_list *)ob);          return cmodb_isallow_cmo_list(cmo_db, (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 mathcap_cmo_isallow_cmo_mathcap((cmo_mathcap *)ob);          return cmodb_isallow_cmo_mathcap(cmo_db, (cmo_mathcap *)ob);
     case CMO_MONOMIAL32:      case CMO_MONOMIAL32:
         return mathcap_cmo_isallow_cmo_monomial32((cmo_monomial32 *)ob);          return cmodb_isallow_cmo_monomial32(cmo_db, (cmo_monomial32 *)ob);
     default:      default:
         return mathcap_cmo_isallow_tag(tag);          return cmodb_isallow_tag(cmo_db, tag);
     }      }
 }  }
   
 /* 次の tag をもつ cmo の送信を許可する */  /* 次の tag をもつ cmo の送信を許可する */
 __inline__  __inline__
 static void mathcap_cmo_allow(int tag)  static void cmodb_allow(mcdb *cmo_db, int tag)
 {  {
         mcdb_ctl(mathcap_cmo, tag, MATHCAP_FLAG_ALLOW);      mcdb_ctl(cmo_db, tag, MATHCAP_FLAG_ALLOW);
 }  }
   
 /* 次の tag をもつ cmo の送信を不許可にする */  /* 次の tag をもつ cmo の送信を不許可にする */
 __inline__  __inline__
 static void mathcap_cmo_deny(int tag)  static void cmodb_deny(mcdb *cmo_db, int tag)
 {  {
         mcdb_ctl(mathcap_cmo, tag, MATHCAP_FLAG_DENY);      mcdb_ctl(cmo_db, tag, MATHCAP_FLAG_DENY);
 }  }
   
 /* 全ての種類の cmo の送信を不許可にする */  
 __inline__  
 static void mathcap_cmo_deny_all()  
 {  
         mcdb_ctl_all(mathcap_cmo, MATHCAP_FLAG_DENY);  
 }  
   
 /* 全ての種類の cmo の送信を許可する */  
 __inline__  
 static void mathcap_cmo_allow_all()  
 {  
         mcdb_ctl_all(mathcap_cmo, MATHCAP_FLAG_ALLOW);  
 }  
   
 /* 送信許可されている cmo のリストを得る */  
 cmo_list *mathcap_cmo_get_allow_all()  
 {  
         return mcdb_get_allow_all(mathcap_cmo);  
 }  
   
 /* 既知の sm コマンドのリストを得る */  
 __inline__  
 static cmo_list *mathcap_sm_get_all()  
 {  
         return mcdb_get_allow_all(mathcap_sm);  
 }  
   
 /* システム情報を得る */  /* システム情報を得る */
 static cmo_list *mathcap_sysinfo_get_all()  static cmo_list *sysinfo_get_all()
 {  {
     cmo_list *syslist = new_cmo_list();      cmo_list *syslist = new_cmo_list();
     cmo_int32 *ver    = new_cmo_int32(mathcap_sysinfo.version);      cmo_int32 *ver    = new_cmo_int32(sysinfo.version);
     cmo_string *vers  = new_cmo_string(mathcap_sysinfo.version_string);      cmo_string *vers  = new_cmo_string(sysinfo.version_string);
     cmo_string *host  = new_cmo_string(mathcap_sysinfo.hosttype);      cmo_string *host  = new_cmo_string(sysinfo.hosttype);
     cmo_string *sname = new_cmo_string(mathcap_sysinfo.sysname);      cmo_string *sname = new_cmo_string(sysinfo.sysname);
     return list_appendl(syslist, ver, sname, vers, host);      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(sizeof(s)+1);
Line 258  static char *new_string(char *s)
Line 247  static char *new_string(char *s)
     return t;      return t;
 }  }
   
 void mathcap_sysinfo_set(int version, char *version_string, char *sysname)  void sysinfo_set(int version, char *vstr, char *sysname)
 {  {
     char *host = getenv("HOSTTYPE");      char *host = getenv("HOSTTYPE");
       sysinfo.hosttype = (host != NULL)? new_string(host): "UNKNOWN";
       sysinfo.sysname  = new_string(sysname);
       sysinfo.version_string = new_string(vstr);
       sysinfo.version  = version;
   }
   
     mathcap_sysinfo.hosttype = (host != NULL)? new_string(host): "UNKNOWN";  void mathcap_global_init(int ver, char *vstr, char *sysname, int cmos[], int sms[])
     mathcap_sysinfo.sysname  = new_string(sysname);  {
     mathcap_sysinfo.version_string = new_string(version_string);          sysinfo_set(ver, vstr, sysname); /* global! */
     mathcap_sysinfo.version  = version;          if (cmos == NULL) {
                   cmos = cmodb_d;
           }
           if (sms == NULL) {
                   sms = smdb_d;
           }
           /* ... */
 }  }
   
 /* データベースから cmo_mathcap を生成する */  /* データベースから cmo_mathcap を生成する */
 cmo_mathcap* mathcap_get()  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(), new_cmo_int32(OX_DATA), mathcap_cmo_get_allow_all(), NULL));      list_append(l3, list_appendl(new_cmo_list(),
     list_appendl(mc, (cmo *)mathcap_sysinfo_get_all(), (cmo *)mathcap_sm_get_all(), (cmo *)l3, NULL);                                   new_cmo_int32(OX_DATA),
                                    cmodb_get_allow_all(this), NULL));
       list_appendl(mc, (cmo *)sysinfo_get_all(),
                    (cmo *)smdb_get_allow_all(this), (cmo *)l3, NULL);
     return new_cmo_mathcap((cmo *)mc);      return new_cmo_mathcap((cmo *)mc);
 }  }
   
 static void mathcap_cmo_update(cmo_list* types)  static void cmodb_update(mcdb *cmo_db, cmo_list* types)
 {  {
     cell *el = list_first(types);      cell *el = list_first(types);
     cmo_int32 *ob;      cmo_int32 *ob;
     while(!list_endof(types, el)) {      while(!list_endof(types, el)) {
         ob = (cmo_int32 *)el->cmo;          ob = (cmo_int32 *)el->cmo;
         if (ob->tag == CMO_INT32) {          if (ob->tag == CMO_INT32) {
             mathcap_cmo_allow(ob->i);              cmodb_allow(cmo_db, ob->i);
         }          }
         el = list_next(el);          el = list_next(el);
     }      }
Line 294  static void mathcap_cmo_update(cmo_list* types)
Line 297  static void mathcap_cmo_update(cmo_list* types)
 /* cmo_mathcap が妥当な構造を持つかを調べる.  (未実装) */  /* cmo_mathcap が妥当な構造を持つかを調べる.  (未実装) */
 int cmo_mathcap_isvalid(cmo_mathcap *mc)  int cmo_mathcap_isvalid(cmo_mathcap *mc)
 {  {
           /* print_cmo(mc); */
     return 1;      return 1;
 }  }
   
Line 323  static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap 
Line 327  static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap 
 }  }
   
 /* 受信した mathcap データを反映させる */  /* 受信した mathcap データを反映させる */
 void mathcap_update(cmo_mathcap *mc)  /* this == NULL のとき、はじめて mathcap* オブジェクトをせいせいする */
   mathcap *mathcap_update(mathcap *this, cmo_mathcap *mc)
 {  {
     cmo_list *types;      cmo_list *types;
     if (cmo_mathcap_isvalid(mc)) {      if (cmo_mathcap_isvalid(mc)) {
         types = cmo_mathcap_get_cmotypes(mc);          types = cmo_mathcap_get_cmotypes(mc);
         if (types != NULL) {          if (types != NULL) {
             mathcap_cmo_deny_all(); /* すべての cmo の送信を禁止 */              cmodb_deny_all(this->cmo_db); /* すべての cmo の送信を禁止 */
             mathcap_cmo_update(types);              cmodb_update(this->cmo_db, types);
         }          }
     }      }
           return this;
 }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>