[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.1 and 1.8

version 1.1, 2000/10/10 05:23:20 version 1.8, 2003/05/19 06:57:38
Line 1 
Line 1 
 /* -*- mode: C; coding: euc-japan -*- */  /* -*- mode: C; coding: euc-japan -*- */
 /* $OpenXM$ */  /* $OpenXM: OpenXM/src/ox_toolkit/mathcap.c,v 1.7 2000/12/03 16:15:03 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"
   
 typedef struct {  #define MATHCAP_FLAG_DENY   0
     int tag;  #define MATHCAP_FLAG_ALLOW  1
     int flag;  
 } mc_cell;  
   
 static int mathcap_cmo_isallow_tag(int tag);  static void table_init(table *m, int key);
 static mc_cell *mathcap_cmo_lookup(int tag);  static table *new_table(int *src);
 static int mathcap_cmo_isallow_cmo_list(cmo_list *ob);  static table *table_lookup(table *tbl, int tag);
 static int mathcap_cmo_isallow_cmo_monomial32(cmo_monomial32 *ob);  static void table_ctl(table *tbl, int tag, int flag);
 static int mathcap_cmo_isallow_cmo_mathcap(cmo_mathcap *ob);  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 void mathcap_cmo_update(cmo_list* types);  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 *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 *cmo_mathcap_get_cmotypes(cmo_mathcap *mc);  
   
 static mc_cell mathcap_cmo[] = {  static int cmotbl_a[] = {
     {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 int mathcap_sm[] = {  static int smtbl_a[] = {
     SM_popCMO,      SM_popCMO,
     SM_popString,      SM_popString,
     SM_mathcap,      SM_mathcap,
Line 52  static int mathcap_sm[] = {
Line 59  static int mathcap_sm[] = {
     SM_shutdown,      SM_shutdown,
     SM_control_kill,      SM_control_kill,
     SM_control_reset_connection,      SM_control_reset_connection,
     0      SM_control_spawn_server,
       SM_control_terminate_server,
       0,
 };  };
   
 static struct {  static struct {
Line 60  static struct {
Line 69  static struct {
     char *version_string;      char *version_string;
     char *sysname;      char *sysname;
     char *hosttype;      char *hosttype;
 } mathcap_sysinfo = {0, "NO VERSION", "NONAME", "UNKNOWN"};      int  *cmo_tags;
       int  *sm_cmds;
   } sysinfo = {0, "NO VERSION", "NONAME", "UNKNOWN", cmotbl_a, smtbl_a};
   
 /* 次の tag をもつ cmo の送信が許可されているかを調べる */  __inline__
 static int mathcap_cmo_isallow_tag(int tag)  static void table_init(table *m, int key)
 {  {
     mc_cell *e = mathcap_cmo;      m->tag  = key;
     while (e->tag != 0 && e->tag != tag) {      m->flag = MATHCAP_FLAG_ALLOW;
         e++;  
     }  
     return e->flag;  
 }  }
   
 /* 次の tag についてのキーを探す */  static table *new_table(int *src)
 static mc_cell *mathcap_cmo_lookup(int tag)  
 {  {
     mc_cell *e = mathcap_cmo;      table *new;
     while (e->tag != 0) {      int len=0;
         if (e->tag == tag) {      int i;
             return e;      while (src[len++] != 0) {
         }  
         e++;  
     }      }
     return NULL;      new = malloc(sizeof(table)*len);
       for(i=0; i<len; i++) {
           table_init(new+i, src[i]);
       }
       return new;
 }  }
   
 static int mathcap_cmo_isallow_cmo_list(cmo_list *ob)  /* looking for an item of the tag */
   static table *table_lookup(table *tbl, int tag)
 {  {
     cell *el;      while (tbl->tag != 0) {
     if (mathcap_cmo_isallow_tag(ob->tag)) {          if (tbl->tag == tag) {
         el = list_first(ob);              return tbl;
         while (!list_endof(ob, el)) {  
             if (!mathcap_cmo_isallow_cmo(el->cmo)) {  
                 return MATHCAP_FLAG_DENY;  
             }  
             el = list_next(el);  
         }          }
         return MATHCAP_FLAG_ALLOW;          tbl++;
     }      }
     return MATHCAP_FLAG_DENY;      return NULL;
 }  }
   
 static int mathcap_cmo_isallow_cmo_monomial32(cmo_monomial32 *ob)  /* controller about a cmo identified by the tag */
   static void table_ctl(table *tbl, int tag, int flag)
 {  {
     return mathcap_cmo_isallow_tag(ob->tag)      table *e = table_lookup(tbl, tag);
         && mathcap_cmo_isallow_cmo(ob->coef);      if (e != NULL) {
           e->flag = flag;
       }
 }  }
   
 static int mathcap_cmo_isallow_cmo_mathcap(cmo_mathcap *ob)  /* controller about all CMObjects */
   static void table_ctl_all(table *tbl, int flag)
 {  {
     return mathcap_cmo_isallow_tag(ob->tag)      while (tbl->tag != 0) {
         && mathcap_cmo_isallow_cmo(ob->ob);          tbl->flag = flag;
           tbl++;
       }
 }  }
   
 /* 次の cmo の送信が許可されているかを調べる */  /* getting the list of tags of all allowed objects */
 int mathcap_cmo_isallow_cmo(cmo *ob)  static cmo_list *table_get_all(table *tbl)
 {  {
     int tag = ob->tag;      cmo_list *list = new_cmo_list();
     switch(tag) {      while (tbl->tag != 0) {
     case CMO_LIST:          if (tbl->flag == MATHCAP_FLAG_ALLOW) {
     case CMO_DISTRIBUTED_POLYNOMIAL:              list_append(list, (cmo *)new_cmo_int32(tbl->tag));
         return mathcap_cmo_isallow_cmo_list((cmo_list *)ob);          }
     case CMO_MATHCAP:          tbl++;
     case CMO_ERROR2:  
     case CMO_RING_BY_NAME:  
     case CMO_INDETERMINATE:  
         return mathcap_cmo_isallow_cmo_mathcap((cmo_mathcap *)ob);  
     case CMO_MONOMIAL32:  
         return mathcap_cmo_isallow_cmo_monomial32((cmo_monomial32 *)ob);  
     default:  
         return mathcap_cmo_isallow_tag(tag);  
     }      }
       return list;
 }  }
   
 /* 次の tag をもつ cmo の送信を許可する */  /* giving a permssion to send objects identified by the tag. */
 void mathcap_cmo_allow(int tag)  __inline__
   static void table_allow(table *tbl, int tag)
 {  {
     mc_cell *e = mathcap_cmo_lookup(tag);      table_ctl(tbl, tag, MATHCAP_FLAG_ALLOW);
     if (e != NULL) {  
         e->flag = MATHCAP_FLAG_ALLOW;  
     }  
 }  }
   
 /* 次の tag をもつ cmo の送信を不許可にする */  /* taking a permssion to send objects identified by the tag. */
 void mathcap_cmo_deny(int tag)  __inline__
   static void table_deny(table *tbl, int tag)
 {  {
     mc_cell *e = mathcap_cmo_lookup(tag);      table_ctl(tbl, tag, MATHCAP_FLAG_DENY);
     if (e != NULL) {  
         e->flag = MATHCAP_FLAG_DENY;  
     }  
 }  }
   
 /* 全ての種類の cmo の送信を不許可にする */  static void table_update(table *cmotbl, cmo_list* types)
 void mathcap_cmo_deny_all()  
 {  {
     mc_cell *e = mathcap_cmo;      cell *el = list_first(types);
     while (e->tag != 0) {      cmo_int32 *ob;
         e->flag = MATHCAP_FLAG_DENY;      while(!list_endof(types, el)) {
         e++;          ob = (cmo_int32 *)el->cmo;
           if (ob->tag == CMO_INT32) {
               table_allow(cmotbl, ob->i);
           }
           el = list_next(el);
     }      }
 }  }
   
 /* 全ての種類の cmo の送信を許可する */  /* getting a permission to send objects identified by the tag. */
 void mathcap_cmo_allow_all()  static int table_allowQ_tag(table *tbl, int tag)
 {  {
     mc_cell *e = mathcap_cmo;      while (tbl->tag != 0 && tbl->tag != tag) {
     while (e->tag != 0) {          tbl++;
         e->flag = MATHCAP_FLAG_ALLOW;  
         e++;  
     }      }
       return tbl->flag;
 }  }
   
 /* 送信許可されている cmo のリストを得る */  static int table_allowQ_cmo_list(table *cmotbl, cmo_list *ob)
 cmo_list *mathcap_cmo_get_allow_all()  
 {  {
     cmo_list *list = new_cmo_list();      cell *el;
     mc_cell *e = mathcap_cmo;      if (table_allowQ_tag(cmotbl, ob->tag)) {
     while (e->tag != 0) {          el = list_first(ob);
         if (e->flag != MATHCAP_FLAG_DENY) {          while (!list_endof(ob, el)) {
             list_append(list, new_cmo_int32(e->tag));              if (!table_allowQ_cmo(cmotbl, el->cmo)) {
                   return MATHCAP_FLAG_DENY;
               }
               el = list_next(el);
         }          }
         e++;          return MATHCAP_FLAG_ALLOW;
     }      }
     return list;      return MATHCAP_FLAG_DENY;
 }  }
   
 /* 既知の sm コマンドのリストを得る */  __inline__
 cmo_list *mathcap_sm_get_all()  static int table_allowQ_cmo_monomial32(table *cmotbl, cmo_monomial32 *ob)
 {  {
     cmo_list *list = new_cmo_list();      return table_allowQ_tag(cmotbl, ob->tag)
     int i;          && table_allowQ_cmo(cmotbl, ob->coef);
     for(i=0; mathcap_sm[i] != 0; i++) {  }
         list_append(list, new_cmo_int32(mathcap_sm[i]));  
   __inline__
   static int table_allowQ_cmo_mathcap(table *cmotbl, cmo_mathcap *ob)
   {
       return table_allowQ_tag(cmotbl, ob->tag)
           && table_allowQ_cmo(cmotbl, ob->ob);
   }
   
   /* getting a permission to send the following object. */
   static int table_allowQ_cmo(table *cmotbl, cmo *ob)
   {
       int tag = ob->tag;
       switch(tag) {
       case CMO_LIST:
       case CMO_DISTRIBUTED_POLYNOMIAL:
           return table_allowQ_cmo_list(cmotbl, (cmo_list *)ob);
       case CMO_MATHCAP:
       case CMO_ERROR2:
       case CMO_RING_BY_NAME:
       case CMO_INDETERMINATE:
           return table_allowQ_cmo_mathcap(cmotbl, (cmo_mathcap *)ob);
       case CMO_MONOMIAL32:
           return table_allowQ_cmo_monomial32(cmotbl, (cmo_monomial32 *)ob);
       default:
           return table_allowQ_tag(cmotbl, tag);
     }      }
     return list;  
 }  }
   
 /* システム情報を得る */  /* getting the System Information */
 cmo_list *mathcap_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(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);
 }  }
   
 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 mathcap_sysinfo_set(int version, char *version_string, char *sysname)  static int *new_int_array(int *array)
 {  {
     char *host = getenv("HOSTTYPE");      int *new_array;
       int length = 0;
     mathcap_sysinfo.hosttype = (host != NULL)? new_string(host): "UNKNOWN";      while(array[length++] != 0)
     mathcap_sysinfo.sysname  = new_string(sysname);          ;
     mathcap_sysinfo.version_string = new_string(version_string);      new_array = malloc(sizeof(int)*length);
     mathcap_sysinfo.version  = version;      return memcpy(new_array, array, sizeof(int)*length);
 }  }
   
 /* データベースから cmo_mathcap を生成する */  void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[])
 cmo_mathcap* mathcap_get()  
 {  {
     cmo_list *mc = new_cmo_list();      char *host = getenv("HOSTTYPE");
     cmo_list *l3 = new_cmo_list();      sysinfo.hosttype = (host != NULL)? new_string(host): "UNKNOWN";
     list_append(l3, list_appendl(new_cmo_list(), new_cmo_int32(OX_DATA), mathcap_cmo_get_allow_all(), NULL));      sysinfo.sysname  = new_string(sysname);
     list_appendl(mc, (cmo *)mathcap_sysinfo_get_all(), (cmo *)mathcap_sm_get_all(), (cmo *)l3, NULL);      sysinfo.version_string = new_string(vstr);
     return new_cmo_mathcap((cmo *)mc);      sysinfo.version  = ver;
       if (cmos != NULL) {
           sysinfo.cmo_tags = new_int_array(cmos);
       }
       if (sms != NULL) {
           sysinfo.sm_cmds = new_int_array(sms);
       }
 }  }
   
 static void mathcap_cmo_update(cmo_list* types)  mathcap *new_mathcap()
 {  {
     cell *el = list_first(types);      mathcap *new = malloc(sizeof(mathcap));
     cmo_int32 *ob;      new->cmotbl = new_table(sysinfo.cmo_tags);
     while(!list_endof(types, el)) {      new->smtbl  = new_table(sysinfo.sm_cmds);
         ob = (cmo_int32 *)el->cmo;      return new;
         if (ob->tag == CMO_INT32) {  
             mathcap_cmo_allow(ob->i);  
         }  
         el = list_next(el);  
     }  
 }  }
   
 /* cmo_mathcap が妥当な構造を持つかを調べる.  (未実装) */  /* generating a cmo_mathcap by a local database. */
 int cmo_mathcap_isvalid(cmo_mathcap *mc)  cmo_mathcap* mathcap_get(mathcap *this)
 {  {
     return 1;      cmo_list *mc = new_cmo_list();
       cmo_list *l3 = new_cmo_list();
       list_append(l3, 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);
       return new_cmo_mathcap((cmo *)mc);
 }  }
   
 /* ( ..., ( type, (...) ), (cmo_int32, (...) ), ... )  */  /* ( ..., ( type, (...) ), (cmo_int32, (...) ), ... )  */
Line 271  static cmo_list *get_messagetypes(cmo_list *ob, int ty
Line 305  static cmo_list *get_messagetypes(cmo_list *ob, int ty
   
 /* cmo_mathcap->ob = ( (...), (...), ( ( cmo_int32, (...) ), ...), ...) */  /* cmo_mathcap->ob = ( (...), (...), ( ( cmo_int32, (...) ), ...), ...) */
 /*                                              ^^^^^ Here!         */  /*                                              ^^^^^ Here!         */
   __inline__
 static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap *mc)  static cmo_list *cmo_mathcap_get_cmotypes(cmo_mathcap *mc)
 {  {
     cmo_list *ob = (cmo_list *)list_nth((cmo_list *)mc->ob, 2);      cmo_list *ob = (cmo_list *)list_nth((cmo_list *)mc->ob, 2);
     return get_messagetypes(ob, OX_DATA);      return get_messagetypes(ob, OX_DATA);
 }  }
   
 /* 受信した mathcap データを反映させる */  /* The mathcap_update integrates received cmo_mathcap into the mathcap
 void mathcap_update(cmo_mathcap *mc)     database. If this == NULL, then an instance of mathcap is generated. */
   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);
             mathcap_cmo_deny_all(); /* すべての cmo の送信を禁止 */          table_update(this->cmotbl, types);
             mathcap_cmo_update(types);  
         }  
     }      }
   
       return this;
 }  }
   
 /* 互換性のため */  int mathcap_allowQ_cmo(mathcap *this, cmo *ob)
 cmo* make_mathcap_object(int version, char *id_string)  
 {  {
     mathcap_sysinfo_set(version, id_string, "ox_math");      return table_allowQ_cmo(this->cmotbl, ob);
     return (cmo *)mathcap_get();  
 }  }
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

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