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

Diff for /OpenXM/src/oxc/sm_ext.c between version 1.5 and 1.6

version 1.5, 2000/11/28 18:11:42 version 1.6, 2000/11/30 10:27:02
Line 1 
Line 1 
 /* -*- mode: C; coding: euc-japan -*- */  /* -*- mode: C; coding: euc-japan -*- */
 /* $OpenXM: OpenXM/src/oxc/sm_ext.c,v 1.4 2000/11/28 04:52:05 ohara Exp $ */  /* $OpenXM: OpenXM/src/oxc/sm_ext.c,v 1.5 2000/11/28 18:11:42 ohara Exp $ */
   
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
Line 12 
Line 12 
   
 /* ultra loose data base. */  /* ultra loose data base. */
 static db db_localfunc[] = {  static db db_localfunc[] = {
     {lf_oxc_open, "oxc_open"},      {lf_oxc_open, "spawn"},
     {NULL, NULL}      {NULL, NULL}
 };  };
   
 static db db_sm[] = {  static db db_sm[] = {
       {sm_control_spawn,     SM_control_spawn_server},
       {sm_control_terminate, SM_control_terminate_server},
     {sm_executeFunction, SM_executeFunction},      {sm_executeFunction, SM_executeFunction},
     {sm_mathcap,         SM_mathcap},      {sm_mathcap,         SM_mathcap},
     {sm_set_mathcap,     SM_setMathCap},      {sm_set_mathcap,     SM_setMathCap},
     {sm_popCMO,          SM_popCMO},      {sm_popCMO,          SM_popCMO},
     {sm_pops,            SM_pops},      {sm_pops,            SM_pops},
         {sm_control_reset_pid, SM_control_reset_connection_pid},          {sm_control_reset_pid, SM_control_reset_connection_pid},
         {sm_control_kill_pid, SM_control_kill_pid},  
         {sm_control_kill, SM_control_kill},          {sm_control_kill, SM_control_kill},
     {NULL, NULL}      {NULL, NULL}
 };  };
   
   extern OXFILE *stack_oxfp;
   
 __inline__  __inline__
 static int (*db_search(void *key, db *dbs, int (*cmp)(void *, void *)))()  static int (*db_search(void *key, db *dbs, int (*cmp)(void *, void *)))()
 {  {
Line 50  Normally local functions push a return value to the st
Line 53  Normally local functions push a return value to the st
 but, if error occurs, then these return non-positive numbers and  but, if error occurs, then these return non-positive numbers and
 the sm_executeFunction push an error object.  the sm_executeFunction push an error object.
 */  */
 void sm_executeFunction(OXFILE *oxfp)  void sm_executeFunction()
 {  {
     int (*func)(OXFILE *);      int (*func)();
     int retcode = 0;      int retcode = 0;
     cmo *ob = pop();      cmo *ob = pop();
     if (ob->tag == CMO_STRING) {      if (ob->tag == CMO_STRING) {
         func = lookup_localfunction(((cmo_string *)ob)->s);          func = lookup_localfunction(((cmo_string *)ob)->s);
         if (func != NULL) {          if (func != NULL) {
             if ((retcode = func(oxfp)) > 0) {              if ((retcode = func()) > 0) {
                 return;                  return;
             }              }
         }          }
Line 88  static int getargs(cmo ***args)
Line 91  static int getargs(cmo ***args)
   
 #define MAX_PROCESS 1024  #define MAX_PROCESS 1024
   
   /* Process Table */
 static pid_t *pids = NULL;  static pid_t *pids = NULL;
 static int pid_ptr = 0;  static int pid_ptr = 0;
 static int pid_size = 0;  static int pid_size = 0;
   
 void pids_extend()  static void pids_extend()
 {  {
     int size2 = pid_size + MAX_PROCESS;      int size2 = pid_size + MAX_PROCESS;
     pid_t *pids2 = (pid_t *)malloc(sizeof(pid_t)*size2);      pid_t *pids2 = (pid_t *)malloc(sizeof(pid_t)*size2);
Line 163  void pid_kill_all()
Line 167  void pid_kill_all()
         }          }
 }  }
   
   cmo_error2 *type_checker(cmo *ob, int type)
   {
   /*      cmo_error2 *err_ob; */
           if (ob->tag != type) {
                   /* push and return an error object */
           }
           return NULL;
   }
   
   int sm_control_spawn_main(int argc, cmo *argv[])
   {
       char *cmd = ((cmo_string *)argv[0])->s;
       int  port = ((cmo_int32 *)argv[1])->i;
       pid_t pid = lf_oxc_open_main(cmd, port);
       if (pid > 0) {
           push(new_cmo_int32(pid));
           pid_regist(pid);
       }
       return pid;
   }
   
 int lf_oxc_open()  int lf_oxc_open()
 {  {
     cmo **argv;      cmo **argv;
     char *cmd;          if (getargs(&argv) != 2 ||
     int port;                  type_checker(argv[0], CMO_STRING) != NULL
     pid_t pid;                  || type_checker(argv[0], CMO_INT32) != NULL) {
   
     if (getargs(&argv) != 2 || argv[0]->tag != CMO_STRING  
         || argv[1]->tag != CMO_INT32) {  
         fprintf(stderr, "oxc: invalid arguments\n");          fprintf(stderr, "oxc: invalid arguments\n");
         return -1;          return -1;
     }      }
           return sm_control_spawn_main(2, argv);
   }
   
     cmd  = ((cmo_string *)argv[0])->s;  int sm_control_spawn()
     port = ((cmo_int32 *)argv[1])->i;  {
     pid = lf_oxc_open_main(cmd, port);      cmo *argv[2];
     if (pid > 0) {          argv[0] = pop();
         push(new_cmo_int32(pid));          argv[1] = pop();
         pid_regist(pid);  
           if (type_checker(argv[0], CMO_STRING) != NULL
                   || type_checker(argv[0], CMO_INT32) != NULL) {
           fprintf(stderr, "oxc: invalid arguments\n");
           return -1;
     }      }
     return pid;          return sm_control_spawn_main(2, argv);
 }  }
   
 void sm_mathcap(OXFILE *oxfp)  void sm_mathcap()
 {  {
     push((cmo *)oxf_cmo_mathcap(oxfp));      push((cmo *)oxf_cmo_mathcap(stack_oxfp));
 }  }
   
 void sm_set_mathcap(OXFILE *oxfp)  void sm_set_mathcap()
 {  {
     cmo_mathcap *m = (cmo_mathcap *)pop();      cmo_mathcap *m = (cmo_mathcap *)pop();
     if (m->tag == CMO_MATHCAP) {      if (m->tag == CMO_MATHCAP) {
         oxf_mathcap_update(oxfp, m);          oxf_mathcap_update(stack_oxfp, m);
     }else {      }else {
         push_error(-1, m);          push_error(-1, m);
         /* an error object must be pushed */          /* an error object must be pushed */
     }      }
 }  }
   
 void sm_control_kill(OXFILE *oxfp)  void sm_control_kill()
 {  {
         pid_kill_all();          pid_kill_all();
 }  }
   
 void sm_control_kill_pid(OXFILE *oxfp)  void sm_control_terminate()
 {  {
     cmo_int32 *m = (cmo_int32 *)pop();      cmo_int32 *m = (cmo_int32 *)pop();
     pid_t pid = m->i;      pid_t pid = m->i;
Line 216  void sm_control_kill_pid(OXFILE *oxfp)
Line 244  void sm_control_kill_pid(OXFILE *oxfp)
     }      }
 }  }
   
 void sm_control_reset_pid(OXFILE *oxfp)  void sm_control_reset_pid()
 {  {
     cmo_int32 *m = (cmo_int32 *)pop();      cmo_int32 *m = (cmo_int32 *)pop();
     pid_t pid = m->i;      pid_t pid = m->i;
Line 227  void sm_control_reset_pid(OXFILE *oxfp)
Line 255  void sm_control_reset_pid(OXFILE *oxfp)
         /* ... */          /* ... */
 }  }
   
 void sm_control_spawn_server(OXFILE *oxfp);  
 void sm_control_terminate_server(OXFILE *oxfp);  
   
 static int intcmp(int key1, int key2)  static int intcmp(int key1, int key2)
 {  {
     return key1 != key2;      return key1 != key2;
 }  }
   
   
 int (*sm_search_f(int code))()  int (*sm_search_f(int code))()
 {  {

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

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