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

Annotation of OpenXM/src/ox_math/testclient.c, Revision 1.4

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.4     ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/testclient.c,v 1.3 1999/11/06 21:39:37 ohara Exp $ */
1.1       ohara       3:
                      4: #include <stdio.h>
                      5: #include <stdlib.h>
                      6: #include <unistd.h>
                      7: #include <string.h>
                      8: #include <errno.h>
                      9: #include <fcntl.h>
                     10: #include "ox.h"
                     11:
                     12: ox_file_t sv;
                     13:
                     14: int dumpx(int fd, int n)
                     15: {
                     16:     unsigned char buff[2048];
                     17:     int i;
                     18:     int len = read(fd, buff, n);
                     19:
                     20:     fprintf(stderr, "I have read %d byte from socket.\n", len);
                     21:     for(i = 0; i < len; i++) {
                     22:         fprintf(stderr, "%02x ", buff[i]);
                     23:         if (i%20 == 19) {
                     24:             fprintf(stderr, "\n");
                     25:         }
                     26:     }
                     27:     fprintf(stderr, "\n");
                     28:     return len;
                     29: }
                     30:
1.4     ! ohara      31: /* 平成11年11月7日 */
        !            32: #define VERSION 0x11110700
        !            33: #define ID_STRING  "testclient version 0.11110700"
1.1       ohara      34:
                     35: int prompt()
                     36: {
1.3       ohara      37:     printf("> ");
1.1       ohara      38: }
                     39:
1.4     ! ohara      40: int test_0()
1.1       ohara      41: {
                     42:     cmo* c = NULL;
1.3       ohara      43:
1.4     ! ohara      44:        ox_mathcap(sv);
        !            45:        send_ox_cmo(sv->stream, make_mathcap_object(VERSION, ID_STRING));
1.1       ohara      46:
                     47:     ox_reset(sv);
                     48:     send_ox_cmo(sv->stream, new_cmo_string("N[ArcTan[1]]"));
                     49:     send_ox_command(sv->stream, SM_executeStringByLocalParser);
                     50:     send_ox_command(sv->stream, SM_popCMO);
                     51:     receive_ox_tag(sv->stream);
                     52:     c = receive_cmo(sv->stream);
1.3       ohara      53:     fprintf(stderr, "testclient:: cmo received.\n");
1.1       ohara      54:     print_cmo(c);
1.4     ! ohara      55: }
        !            56:
        !            57: int main(int argc, char* argv[])
        !            58: {
        !            59:     ox* m = NULL;
        !            60:     cmo* c = NULL;
        !            61:     int code;
        !            62:     char *server = "ox_sm1";
        !            63:
        !            64:     setbuf(stderr, NULL);
        !            65:
        !            66:     if (argc>1) {
        !            67:         server = argv[1];
        !            68:     }
        !            69:     fprintf(stderr, "testclient:: I use %s as an OX server.\n", server);
        !            70:     sv = ox_start("localhost", "ox", server);
        !            71:     if (sv == NULL) {
        !            72:         fprintf(stderr, "testclient:: I cannot connect to servers.\n");
        !            73:         exit(1);
        !            74:     }
        !            75:
        !            76:     if (strcmp(argc, "ox_math")==0) {
        !            77:                test_0();
        !            78:     }
1.1       ohara      79:
                     80:     while(prompt(), (m = parse()) != NULL) {
                     81:         send_ox(sv, m);
                     82:         if (m->tag == OX_COMMAND) {
                     83:             code = ((ox_command *)m)->command;
                     84:             if (code >= 1024) {
                     85:                 break;
                     86:             }else if (code == SM_popCMO || code == SM_popString) {
                     87:                 receive_ox_tag(sv->stream);
                     88:                 c = receive_cmo(sv->stream);
1.3       ohara      89:                 fprintf(stderr, "testclient:: cmo received.\n");
1.1       ohara      90:                 print_cmo(c);
                     91:             }
                     92:         }
                     93:     }
                     94:
                     95:     ox_reset(sv);
1.3       ohara      96:     fprintf(stderr, "The testclient resets.\n");
1.1       ohara      97:     ox_close(sv);
1.3       ohara      98:     fprintf(stderr, "The testclient halts.\n");
1.1       ohara      99:
                    100:     return 0;
                    101: }

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