=================================================================== RCS file: /home/cvs/OpenXM/src/ox_toolkit/testclient.c,v retrieving revision 1.4 retrieving revision 1.10 diff -u -p -r1.4 -r1.10 --- OpenXM/src/ox_toolkit/testclient.c 2000/03/10 12:24:40 1.4 +++ OpenXM/src/ox_toolkit/testclient.c 2003/01/13 12:03:12 1.10 @@ -1,5 +1,5 @@ /* -*- mode: C -*- */ -/* $OpenXM: OpenXM/src/ox_toolkit/testclient.c,v 1.3 1999/12/22 11:26:37 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_toolkit/testclient.c,v 1.9 2003/01/11 11:42:32 ohara Exp $ */ /* A sample implementation of an OpenXM client with OpenXM C library */ @@ -12,22 +12,23 @@ #include "ox_toolkit.h" -ox_file_t sv; +extern OXFILE *ox_start(char* host, char* prog1, char* prog2); +OXFILE *sv; -int dumpx(int fd, int n) +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); + ox_printf("I have read %d byte from socket(%d).\n", len, oxfp->fd); for(i = 0; i < len; i++) { - fprintf(stderr, "%02x ", buff[i]); + ox_printf("%02x ", buff[i]); if (i%20 == 19) { - fprintf(stderr, "\n"); + ox_printf("\n"); } } - fprintf(stderr, "\n"); + ox_printf("\n"); return len; } @@ -44,44 +45,47 @@ static int prompt() } #define VERSION 0x11121500 -#define ID_STRING "testclient version 0.11121500" +#define ID_STRING "v0.11121500" int test_0() { cmo* c = NULL; #ifdef DEBUG - fprintf(stderr, "testclient:: calling ox_mathcap().\n"); + ox_printf("testclient:: calling ox_mathcap().\n"); c = ox_mathcap(sv); - fprintf(stderr, "testclient:: cmo received.(%p)\n", c); + ox_printf("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); - fprintf(stderr, "testclient:: cmo received.\n"); + 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); + ox_printf("testclient:: cmo received.\n"); print_cmo(c); } int test_1() { - cmo *c = NULL; - cmo *m = make_mathcap_object(1000, "test!"); - 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); - fprintf(stderr, "testclient:: cmo received.(%p)\n", c); + cmo *c, *m; + + mathcap_init(1000, "test!", "testclient", NULL, NULL); + m = oxf_cmo_mathcap(sv); + ox_printf("testclient:: test cmo_mathcap.\n"); + send_ox_cmo(sv, m); + send_ox_command(sv, SM_popCMO); + receive_ox_tag(sv); + c = receive_cmo(sv); + ox_printf("testclient:: cmo received.(%p)\n", c); print_cmo(c); - fputc('\n', stderr); + ox_printf("\n"); } /* Example: @@ -97,15 +101,15 @@ int main(int argc, char* argv[]) int code; char *server = "ox_sm1"; - setbuf(stderr, NULL); + ox_stderr_init(NULL); if (argc>1) { server = argv[1]; } - fprintf(stderr, "testclient:: I use %s as an OX server.\n", server); - sv = ox_start("localhost", "ox", server); + ox_printf("testclient:: I use %s as an OX server.\n", server); +/* sv = ox_start("localhost", "ox", server); */ if (sv == NULL) { - fprintf(stderr, "testclient:: I cannot connect to servers.\n"); + ox_printf("testclient:: I cannot connect to servers.\n"); exit(1); } @@ -116,24 +120,24 @@ int main(int argc, char* argv[]) 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); - fprintf(stderr, "testclient:: cmo received.\n"); + receive_ox_tag(sv); + c = receive_cmo(sv); + ox_printf("testclient:: cmo received.\n"); print_cmo(c); } } } ox_reset(sv); - fprintf(stderr, "The testclient resets.\n"); + ox_printf("The testclient resets.\n"); ox_close(sv); - fprintf(stderr, "The testclient halts.\n"); + ox_printf("The testclient halts.\n"); return 0; }