=================================================================== RCS file: /home/cvs/OpenXM/src/ox_toolkit/testclient.c,v retrieving revision 1.2 retrieving revision 1.7 diff -u -p -r1.2 -r1.7 --- OpenXM/src/ox_toolkit/testclient.c 1999/12/15 07:51:20 1.2 +++ OpenXM/src/ox_toolkit/testclient.c 2000/11/27 09:57:10 1.7 @@ -1,5 +1,5 @@ /* -*- 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.6 2000/11/21 07:59:08 ohara Exp $ */ /* A sample implementation of an OpenXM client with OpenXM C library */ @@ -9,17 +9,19 @@ #include #include #include -#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]; 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); + fprintf(stderr, "I have read %d byte from socket(%d).\n", len, oxfp->fd); for(i = 0; i < len; i++) { fprintf(stderr, "%02x ", buff[i]); if (i%20 == 19) { @@ -30,14 +32,34 @@ int dumpx(int fd, int n) return len; } +#define SIZE_CMDLINE 8192 + +static int size = SIZE_CMDLINE; +static char cmdline[SIZE_CMDLINE]; + +static int prompt() +{ + fprintf(stdout, "> "); + fgets(cmdline, size, stdin); + init_parser(cmdline); +} + #define VERSION 0x11121500 -#define ID_STRING "testclient version 0.11121500" +#define ID_STRING "v0.11121500" -int prompt() +mathcap *oxf_mathcap(OXFILE *oxfp) { - printf("> "); + if (oxfp->mathcap == NULL) { + oxfp->mathcap = new_mathcap(); + } + return oxfp->mathcap; } +cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp) +{ + return mathcap_get(oxf_mathcap(oxfp)); +} + int test_0() { cmo* c = NULL; @@ -46,31 +68,35 @@ int test_0() c = ox_mathcap(sv); fprintf(stderr, "testclient:: cmo received.(%p)\n", c); #else - c = ox_mathcap(sv); + c = (cmo *)ox_mathcap(sv); #endif 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, oxf_cmo_mathcap(sv)); + ox_reset(sv); - send_ox_cmo(sv->stream, new_cmo_string("N[ArcTan[1]]")); - send_ox_command(sv->stream, SM_executeStringByLocalParser); - send_ox_command(sv->stream, SM_popCMO); - receive_ox_tag(sv->stream); - c = receive_cmo(sv->stream); + send_ox_cmo(sv, (cmo *)new_cmo_string("N[ArcTan[1]]")); + send_ox_command(sv, SM_executeStringByLocalParser); + send_ox_command(sv, SM_popCMO); + receive_ox_tag(sv); + c = receive_cmo(sv); fprintf(stderr, "testclient:: cmo received.\n"); print_cmo(c); } int test_1() { - cmo *c = NULL; - cmo *m = make_mathcap_object(1000, "test!"); + cmo *c, *m; + + mathcap_init(1000, "test!", "testclient", NULL, NULL); + m = oxf_cmo_mathcap(sv); fprintf(stderr, "testclient:: test cmo_mathcap.\n"); - send_ox_cmo(sv->stream, m); - send_ox_command(sv->stream, SM_popCMO); - receive_ox_tag(sv->stream); - c = receive_cmo(sv->stream); + send_ox_cmo(sv, m); + send_ox_command(sv, SM_popCMO); + receive_ox_tag(sv); + c = receive_cmo(sv); fprintf(stderr, "testclient:: cmo received.(%p)\n", c); print_cmo(c); fputc('\n', stderr); @@ -80,7 +106,7 @@ int test_1() testclient >(OX_DATA,(CMO_INT32,123)) >(OX_COMMAND,(SM_popCMO)) - */ + */ int main(int argc, char* argv[]) { @@ -95,7 +121,7 @@ int main(int argc, char* argv[]) server = argv[1]; } fprintf(stderr, "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) { fprintf(stderr, "testclient:: I cannot connect to servers.\n"); exit(1); @@ -105,15 +131,17 @@ int main(int argc, char* argv[]) test_1(); } + setflag_parse(PFLAG_ADDREV); + while(prompt(), (m = parse()) != NULL) { - send_ox(sv->stream, m); + send_ox(sv, m); if (m->tag == OX_COMMAND) { code = ((ox_command *)m)->command; if (code >= 1024) { break; }else if (code == SM_popCMO || code == SM_popString) { - receive_ox_tag(sv->stream); - c = receive_cmo(sv->stream); + receive_ox_tag(sv); + c = receive_cmo(sv); fprintf(stderr, "testclient:: cmo received.\n"); print_cmo(c); }