[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.4 and 1.5

version 1.4, 2000/11/21 07:59:08 version 1.5, 2000/11/24 05:49:26
Line 1 
Line 1 
 /* -*- 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.4 2000/11/21 07:59:08 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 <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 の送信を許可/不許可にする */  
 #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;  } table;
   
 typedef struct {  typedef struct mathcap {
     mcdb *cmodb;      table *cmotbl;
     mcdb *smdb;      table *smtbl;
 } mathcap;  } mathcap;
   
   static void table_init(table *m, int key);
   static table *new_table(int *src);
   static table *table_lookup(table *tbl, int tag);
   static void table_ctl(table *tbl, int tag, int flag);
   static void table_ctl_all(table *tbl, int flag);
   static cmo_list *table_get_all(table *tbl);
   static void table_allow(table *tbl, int tag);
   static void table_deny(table *tbl, int tag);
   static void table_update(table *cmotbl, cmo_list* types);
   static int table_allowQ_tag(table *tbl, int tag);
   static int table_allowQ_cmo_list(table *cmotbl, cmo_list *ob);
   static int table_allowQ_cmo_monomial32(table *cmotbl, cmo_monomial32 *ob);
   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 62  static int cmodb_d[] = {
Line 58  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 69  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()  
 {  
     mathcap *new = malloc(sizeof(mathcap));  
     new->cmodb = new_mcdb(cmodb_d);  
     new->smdb  = new_mcdb(smdb_d);  
     return new;  
 }  
   
 /* 次の tag についてのキーを探す */  /* 次の tag についてのキーを探す */
 static mcdb *mcdb_lookup(mcdb *db, int tag)  static table *table_lookup(table *tbl, int tag)
 {  {
     while (db->tag != 0) {      while (tbl->tag != 0) {
         if (db->tag == tag) {          if (tbl->tag == tag) {
             return db;              return tbl;
         }          }
         db++;          tbl++;
     }      }
     return NULL;      return NULL;
 }  }
   
 /* tag に対する送信制御 */  /* 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;
     }      }
 }  }
   
 /* 全データに対する送信制御 */  /* 全データに対する送信制御 */
 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 のリストを得る */  /* 送信許可されている tag のリストを得る */
 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 {  /* 次の tag をもつ cmo or sm_cmd の送信を許可する */
     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 の送信が許可されているかを調べる */  /* 次の tag をもつ cmo or sm_cmd の送信を不許可にする */
 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)  /* 次の tag をもつ cmo or sm_cmd の送信が許可されているかを調べる */
   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 200  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 の送信が許可されているかを調べる */  /* 次の cmo の送信が許可されているかを調べる */
 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 の送信を許可する */  
 __inline__  
 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()  static cmo_list *sysinfo_get()
 {  {
     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);
Line 241  static cmo_list *sysinfo_get_all()
Line 244  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(sizeof(s)+1);
Line 249  static char *new_string(char *s)
Line 251  static char *new_string(char *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 を生成する */  /* データベースから cmo_mathcap を生成する */
Line 277  cmo_mathcap* mathcap_get(mathcap *this)
Line 291  cmo_mathcap* mathcap_get(mathcap *this)
     cmo_list *l3 = new_cmo_list();      cmo_list *l3 = new_cmo_list();
     list_append(l3, list_appendl(new_cmo_list(),      list_append(l3, 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 333  static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap 
Line 327  static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap 
 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) {          /* すべての cmo の送信を禁止 */
             cmodb_deny_all(this->cmodb); /* すべての cmo の送信を禁止 */          table_ctl_all(this->cmotbl, MATHCAP_FLAG_DENY);
             cmodb_update(this->cmodb, types);          table_update(this->cmotbl, types);
         }  
     }      }
         return this;  
       return this;
   }
   
   int mathcap_allowQ_cmo(mathcap *this, cmo *ob)
   {
       return table_allowQ_cmo(this->cmotbl, ob);
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

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