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

Diff for /OpenXM/src/ox_toolkit/testclient.c between version 1.9 and 1.17

version 1.9, 2003/01/11 11:42:32 version 1.17, 2016/08/23 06:13:10
Line 1 
Line 1 
 /* -*- mode: C -*- */  /* -*- mode: C -*- */
 /* $OpenXM: OpenXM/src/ox_toolkit/testclient.c,v 1.8 2000/11/28 04:24:12 ohara Exp $ */  /* $OpenXM: OpenXM/src/ox_toolkit/testclient.c,v 1.16 2005/10/12 04:03:37 takayama Exp $ */
   
 /* A sample implementation of an OpenXM client with OpenXM C library */  /* A sample implementation of an OpenXM client with OpenXM C library */
   /* Sample input
     (OX_DATA, (CMO_STRING,"printf(\"%a\");"))
     (OX_COMMAND,(SM_executeStringByLocalParser))
    */
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <unistd.h>  #include <unistd.h>
Line 21  int dumpx(OXFILE *oxfp, int n)
Line 24  int dumpx(OXFILE *oxfp, int n)
     int i;      int i;
     int len = oxf_read(buff, 1, n, oxfp);      int len = oxf_read(buff, 1, n, oxfp);
   
     fprintf(ox_stderr, "I have read %d byte from socket(%d).\n", len, oxfp->fd);      ox_printf("I have read %d byte from socket(%d).\n", len, oxfp->fd);
     for(i = 0; i < len; i++) {      for(i = 0; i < len; i++) {
         fprintf(ox_stderr, "%02x ", buff[i]);          ox_printf("%02x ", buff[i]);
         if (i%20 == 19) {          if (i%20 == 19) {
             fprintf(ox_stderr, "\n");              ox_printf("\n");
         }          }
     }      }
     fprintf(ox_stderr, "\n");      ox_printf("\n");
     return len;      return len;
 }  }
   
Line 37  int dumpx(OXFILE *oxfp, int n)
Line 40  int dumpx(OXFILE *oxfp, int n)
 static int  size = SIZE_CMDLINE;  static int  size = SIZE_CMDLINE;
 static char cmdline[SIZE_CMDLINE];  static char cmdline[SIZE_CMDLINE];
   
 static int prompt()  static void prompt()
 {  {
     fprintf(stdout, "> ");      fprintf(stdout, "> ");
     fgets(cmdline, size, stdin);      fgets(cmdline, size, stdin);
     init_parser(cmdline);  
 }  }
   
 #define VERSION 0x11121500  #define VERSION 0x11121500
 #define ID_STRING  "v0.11121500"  #define ID_STRING  "v0.11121500"
   
 int test_0()  void test_0()
 {  {
     cmo* c = NULL;      cmo* c = NULL;
 #ifdef DEBUG      ox_printf("testclient:: calling ox_mathcap().\n");
     fprintf(ox_stderr, "testclient:: calling ox_mathcap().\n");  
     c = ox_mathcap(sv);  
     fprintf(ox_stderr, "testclient:: cmo received.(%p)\n", c);  
 #else  
     c = (cmo *)ox_mathcap(sv);      c = (cmo *)ox_mathcap(sv);
 #endif      ox_printf("testclient:: cmo received.(%p)\n", c);
     print_cmo(c);      print_cmo(c);
     fflush(ox_stderr);  
   
     mathcap_init(VERSION, ID_STRING, "testclient", NULL, NULL);      mathcap_init(VERSION, ID_STRING, "testclient", NULL, NULL);
     send_ox_cmo(sv, oxf_cmo_mathcap(sv));      send_ox_cmo(sv, (cmo *)oxf_cmo_mathcap(sv));
   
     ox_reset(sv);      ox_reset(sv);
     send_ox_cmo(sv, (cmo *)new_cmo_string("N[ArcTan[1]]"));      send_ox_cmo(sv, (cmo *)new_cmo_string("N[ArcTan[1]]"));
Line 69  int test_0()
Line 66  int test_0()
     send_ox_command(sv, SM_popCMO);      send_ox_command(sv, SM_popCMO);
     receive_ox_tag(sv);      receive_ox_tag(sv);
     c = receive_cmo(sv);      c = receive_cmo(sv);
     fprintf(ox_stderr, "testclient:: cmo received.\n");      ox_printf("testclient:: cmo received.\n");
     print_cmo(c);      print_cmo(c);
 }  }
   
 int test_1()  void test_1()
 {  {
     cmo *c, *m;      cmo *c, *m;
   
         mathcap_init(1000, "test!", "testclient", NULL, NULL);          mathcap_init(1000, "test!", "testclient", NULL, NULL);
         m = oxf_cmo_mathcap(sv);          m = (cmo *)oxf_cmo_mathcap(sv);
     fprintf(ox_stderr, "testclient:: test cmo_mathcap.\n");      ox_printf("testclient:: test cmo_mathcap.\n");
     send_ox_cmo(sv, m);      send_ox_cmo(sv, m);
     send_ox_command(sv, SM_popCMO);      send_ox_command(sv, SM_popCMO);
     receive_ox_tag(sv);      receive_ox_tag(sv);
     c = receive_cmo(sv);      c = receive_cmo(sv);
     fprintf(ox_stderr, "testclient:: cmo received.(%p)\n", c);      ox_printf("testclient:: cmo received.(%p)\n", c);
     print_cmo(c);      print_cmo(c);
     fputc('\n', ox_stderr);          ox_printf("\n");
 }  }
   
 /*  Example:  /*  Example:
Line 100  int main(int argc, char* argv[])
Line 97  int main(int argc, char* argv[])
     ox* m = NULL;      ox* m = NULL;
     cmo* c = NULL;      cmo* c = NULL;
     int code;      int code;
     char *server = "ox_sm1";      char *server = "ox_asir";
   
     ox_stderr_init(NULL);      ox_stderr_init(stderr);
     setbuf(ox_stderr, NULL);  
   
     if (argc>1) {      if (argc>1) {
         server = argv[1];          server = argv[1];
     }      }
     fprintf(ox_stderr, "testclient:: I use %s as an OX server.\n", server);      ox_printf("testclient:: I use %s as an OX server.\n", server);
 /*    sv = ox_start("localhost", "ox", server);  */      sv = ox_start("localhost", "ox", server);
     if (sv == NULL) {      if (sv == NULL) {
         fprintf(ox_stderr, "testclient:: I cannot connect to servers.\n");          ox_printf("testclient:: I cannot connect to servers.\n");
         exit(1);          exit(1);
     }      }
   
Line 119  int main(int argc, char* argv[])
Line 115  int main(int argc, char* argv[])
         test_1();          test_1();
     }      }
   
     setflag_parse(PFLAG_ADDREV);      while(prompt(), (m = ox_parse_lisp(cmdline)) != NULL) {
   
     while(prompt(), (m = parse()) != NULL) {  
         send_ox(sv, m);          send_ox(sv, m);
         if (m->tag == OX_COMMAND) {          if (m->tag == OX_COMMAND) {
             code = ((ox_command *)m)->command;              code = ((ox_command *)m)->command;
Line 130  int main(int argc, char* argv[])
Line 124  int main(int argc, char* argv[])
             }else if (code == SM_popCMO || code == SM_popString) {              }else if (code == SM_popCMO || code == SM_popString) {
                 receive_ox_tag(sv);                  receive_ox_tag(sv);
                 c = receive_cmo(sv);                  c = receive_cmo(sv);
                 fprintf(ox_stderr, "testclient:: cmo received.\n");                  ox_printf("testclient:: cmo received.\n");
                 print_cmo(c);                  print_cmo(c);
             }              }
         }          }
     }      }
   
     ox_reset(sv);      ox_reset(sv);
     fprintf(ox_stderr, "The testclient resets.\n");      ox_printf("The testclient resets.\n");
     ox_close(sv);      ox_close(sv);
     fprintf(ox_stderr, "The testclient halts.\n");      ox_printf("The testclient halts.\n");
   
     return 0;      return 0;
 }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.17

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