[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.2 and 1.14

version 1.2, 1999/12/15 07:51:20 version 1.14, 2005/07/20 17:48:03
Line 1 
Line 1 
 /* -*- mode: C -*- */  /* -*- mode: C -*- */
 /* $OpenXM: OpenXM/src/ox_toolkit/testclient.c,v 1.1 1999/12/15 05:21:25 ohara Exp $ */  /* $OpenXM: OpenXM/src/ox_toolkit/testclient.c,v 1.13 2003/09/15 09:31:42 ohara Exp $ */
   
 /* A sample implementation of an OpenXM client with OpenXM C library */  /* A sample implementation of an OpenXM client with OpenXM C library */
   
Line 9 
Line 9 
 #include <string.h>  #include <string.h>
 #include <errno.h>  #include <errno.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include "ox.h"  
   
 ox_file_t sv;  #include "ox_toolkit.h"
   
 int dumpx(int fd, int n)  extern OXFILE *ox_start(char* host, char* prog1, char* prog2);
   OXFILE *sv;
   
   int dumpx(OXFILE *oxfp, int n)
 {  {
     unsigned char buff[2048];      unsigned char buff[2048];
     int i;      int i;
     int len = read(fd, buff, n);      int len = oxf_read(buff, 1, n, oxfp);
   
     fprintf(stderr, "I have read %d byte from socket.\n", len);      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(stderr, "%02x ", buff[i]);          ox_printf("%02x ", buff[i]);
         if (i%20 == 19) {          if (i%20 == 19) {
             fprintf(stderr, "\n");              ox_printf("\n");
         }          }
     }      }
     fprintf(stderr, "\n");      ox_printf("\n");
     return len;      return len;
 }  }
   
 #define VERSION 0x11121500  #define SIZE_CMDLINE  8192
 #define ID_STRING  "testclient version 0.11121500"  
   
 int prompt()  static int  size = SIZE_CMDLINE;
   static char cmdline[SIZE_CMDLINE];
   
   static void prompt()
 {  {
     printf("> ");      fprintf(stdout, "> ");
       fgets(cmdline, size, stdin);
 }  }
   
 int test_0()  #define VERSION 0x11121500
   #define ID_STRING  "v0.11121500"
   
   void test_0()
 {  {
     cmo* c = NULL;      cmo* c = NULL;
 #ifdef DEBUG      ox_printf("testclient:: calling ox_mathcap().\n");
     fprintf(stderr, "testclient:: calling ox_mathcap().\n");      c = (cmo *)ox_mathcap(sv);
     c = ox_mathcap(sv);      ox_printf("testclient:: cmo received.(%p)\n", c);
     fprintf(stderr, "testclient:: cmo received.(%p)\n", c);  
 #else  
     c = ox_mathcap(sv);  
 #endif  
     print_cmo(c);      print_cmo(c);
     fflush(stderr);  
     send_ox_cmo(sv->stream, make_mathcap_object(VERSION, ID_STRING));  
   
       mathcap_init(VERSION, ID_STRING, "testclient", NULL, NULL);
       send_ox_cmo(sv, (cmo *)oxf_cmo_mathcap(sv));
   
     ox_reset(sv);      ox_reset(sv);
     send_ox_cmo(sv->stream, new_cmo_string("N[ArcTan[1]]"));      send_ox_cmo(sv, (cmo *)new_cmo_string("N[ArcTan[1]]"));
     send_ox_command(sv->stream, SM_executeStringByLocalParser);      send_ox_command(sv, SM_executeStringByLocalParser);
     send_ox_command(sv->stream, SM_popCMO);      send_ox_command(sv, SM_popCMO);
     receive_ox_tag(sv->stream);      receive_ox_tag(sv);
     c = receive_cmo(sv->stream);      c = receive_cmo(sv);
     fprintf(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 = NULL;      cmo *c, *m;
     cmo *m = make_mathcap_object(1000, "test!");  
     fprintf(stderr, "testclient:: test cmo_mathcap.\n");          mathcap_init(1000, "test!", "testclient", NULL, NULL);
     send_ox_cmo(sv->stream, m);          m = (cmo *)oxf_cmo_mathcap(sv);
     send_ox_command(sv->stream, SM_popCMO);      ox_printf("testclient:: test cmo_mathcap.\n");
     receive_ox_tag(sv->stream);      send_ox_cmo(sv, m);
     c = receive_cmo(sv->stream);      send_ox_command(sv, SM_popCMO);
     fprintf(stderr, "testclient:: cmo received.(%p)\n", c);      receive_ox_tag(sv);
       c = receive_cmo(sv);
       ox_printf("testclient:: cmo received.(%p)\n", c);
     print_cmo(c);      print_cmo(c);
     fputc('\n', stderr);          ox_printf("\n");
 }  }
   
 /*  Example:  /*  Example:
   testclient    testclient
   >(OX_DATA,(CMO_INT32,123))    >(OX_DATA,(CMO_INT32,123))
   >(OX_COMMAND,(SM_popCMO))    >(OX_COMMAND,(SM_popCMO))
   */   */
   
 int main(int argc, char* argv[])  int main(int argc, char* argv[])
 {  {
Line 89  int main(int argc, char* argv[])
Line 96  int main(int argc, char* argv[])
     int code;      int code;
     char *server = "ox_sm1";      char *server = "ox_sm1";
   
     setbuf(stderr, NULL);      ox_stderr_init(stderr);
   
     if (argc>1) {      if (argc>1) {
         server = argv[1];          server = argv[1];
     }      }
     fprintf(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(stderr, "testclient:: I cannot connect to servers.\n");          ox_printf("testclient:: I cannot connect to servers.\n");
         exit(1);          exit(1);
     }      }
   
Line 105  int main(int argc, char* argv[])
Line 112  int main(int argc, char* argv[])
         test_1();          test_1();
     }      }
   
     while(prompt(), (m = parse()) != NULL) {      while(prompt(), (m = ox_parse_lisp(cmdline)) != NULL) {
         send_ox(sv->stream, 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;
             if (code >= 1024) {              if (code >= 1024) {
                 break;                  break;
             }else if (code == SM_popCMO || code == SM_popString) {              }else if (code == SM_popCMO || code == SM_popString) {
                 receive_ox_tag(sv->stream);                  receive_ox_tag(sv);
                 c = receive_cmo(sv->stream);                  c = receive_cmo(sv);
                 fprintf(stderr, "testclient:: cmo received.\n");                  ox_printf("testclient:: cmo received.\n");
                 print_cmo(c);                  print_cmo(c);
             }              }
         }          }
     }      }
   
     ox_reset(sv);      ox_reset(sv);
     fprintf(stderr, "The testclient resets.\n");      ox_printf("The testclient resets.\n");
     ox_close(sv);      ox_close(sv);
     fprintf(stderr, "The testclient halts.\n");      ox_printf("The testclient halts.\n");
   
     return 0;      return 0;
 }  }

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

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