[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.3

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.3     ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/testclient.c,v 1.2 1999/11/02 06:11:58 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:
                     31: /* 平成11年7月10日 */
                     32: #define VERSION 0x11071000
1.3     ! ohara      33: #define ID_STRING  "testclient version 0.11071000"
1.1       ohara      34:
                     35: int prompt()
                     36: {
1.3     ! ohara      37:     printf("> ");
1.1       ohara      38: }
                     39:
                     40: int main(int argc, char* argv[])
                     41: {
                     42:     ox* m = NULL;
                     43:     cmo* c = NULL;
                     44:     int code;
1.3     ! ohara      45:        char *server = "ox_sm1";
1.1       ohara      46:
                     47:     setbuf(stderr, NULL);
                     48:
                     49:     if (argc>1) {
1.3     ! ohara      50:                server = argv[1];
        !            51:        }
        !            52:        fprintf(stderr, "testclient:: I use %s as an OX server.\n", server);
        !            53:        sv = ox_start("localhost", "ox", server);
        !            54:        if (sv == NULL) {
        !            55:                fprintf(stderr, "testclient:: I cannot connect to servers.\n");
        !            56:                exit(1);
        !            57:        }
        !            58:
        !            59:     if (argc>1) {
1.1       ohara      60:         ox_mathcap(sv);
                     61:         send_ox_cmo(sv->stream, make_mathcap_object(VERSION, ID_STRING));
                     62:     }
                     63:
                     64:     ox_reset(sv);
                     65:     send_ox_cmo(sv->stream, new_cmo_string("N[ArcTan[1]]"));
                     66:     send_ox_command(sv->stream, SM_executeStringByLocalParser);
                     67:     send_ox_command(sv->stream, SM_popCMO);
                     68:     receive_ox_tag(sv->stream);
                     69:     c = receive_cmo(sv->stream);
1.3     ! ohara      70:     fprintf(stderr, "testclient:: cmo received.\n");
1.1       ohara      71:     print_cmo(c);
                     72:
                     73:     while(prompt(), (m = parse()) != NULL) {
                     74:         send_ox(sv, m);
                     75:         if (m->tag == OX_COMMAND) {
                     76:             code = ((ox_command *)m)->command;
                     77:             if (code >= 1024) {
                     78:                 break;
                     79:             }else if (code == SM_popCMO || code == SM_popString) {
                     80:                 receive_ox_tag(sv->stream);
                     81:                 c = receive_cmo(sv->stream);
1.3     ! ohara      82:                 fprintf(stderr, "testclient:: cmo received.\n");
1.1       ohara      83:                 print_cmo(c);
                     84:             }
                     85:         }
                     86:     }
                     87:
                     88:     ox_reset(sv);
1.3     ! ohara      89:     fprintf(stderr, "The testclient resets.\n");
1.1       ohara      90:     ox_close(sv);
1.3     ! ohara      91:     fprintf(stderr, "The testclient halts.\n");
1.1       ohara      92:
                     93:     return 0;
                     94: }

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