Annotation of OpenXM/doc/oxlib/test3.c, Revision 1.3
1.3 ! noro 1: /* $OpenXM: OpenXM/doc/oxlib/test3.c,v 1.2 2000/03/16 07:41:41 noro Exp $ */
1.1 noro 2: #include <asir/ox.h>
1.3 ! noro 3: #include <signal.h>
1.1 noro 4:
5: main(int argc, char **argv)
6: {
7: char buf[BUFSIZ+1];
8: int c;
9: unsigned char sendbuf[BUFSIZ+10];
10: unsigned char *result;
11: unsigned char h[3];
12: int len,i,j;
13: static int result_len = 0;
14: char *kwd,*bdy;
15: unsigned int cmd;
16:
1.3 ! noro 17: signal(SIGINT,SIG_IGN);
1.1 noro 18: asir_ox_init(1); /* 1: network byte order; 0: native byte order */
19: result_len = BUFSIZ;
20: result = (void *)malloc(BUFSIZ);
21: while ( 1 ) {
22: printf("Input>"); fflush(stdout);
23: fgets(buf,BUFSIZ,stdin);
24: for ( i = 0; buf[i] && isspace(buf[i]); i++ );
25: if ( !buf[i] )
26: continue;
27: kwd = buf+i;
28: for ( ; buf[i] && !isspace(buf[i]); i++ );
29: buf[i] = 0;
30: bdy = buf+i+1;
31: if ( !strcmp(kwd,"asir") ) {
32: sprintf(sendbuf,"%s;",bdy);
33: asir_ox_execute_string(sendbuf);
34: } else if ( !strcmp(kwd,"push") ) {
35: h[0] = 0;
36: h[2] = 0;
37: j = 0;
38: while ( 1 ) {
39: for ( ; (c= *bdy) && isspace(c); bdy++ );
40: if ( !c )
41: break;
42: else if ( h[0] ) {
43: h[1] = c;
44: sendbuf[j++] = strtoul(h,0,16);
45: h[0] = 0;
46: } else
47: h[0] = c;
48: bdy++;
49: }
50: if ( h[0] )
51: fprintf(stderr,"Number of characters is odd.\n");
52: else {
53: sendbuf[j] = 0;
54: asir_ox_push_cmo(sendbuf);
55: }
56: } else if ( !strcmp(kwd,"cmd") ) {
57: cmd = atoi(bdy);
58: asir_ox_push_cmd(cmd);
59: } else if ( !strcmp(kwd,"pop") ) {
60: len = asir_ox_peek_cmo_size();
61: if ( !len )
62: continue;
63: if ( len > result_len ) {
64: result = (char *)realloc(result,len);
65: result_len = len;
66: }
67: asir_ox_pop_cmo(result,len);
68: printf("Output>"); fflush(stdout);
69: printf("\n");
70: for ( i = 0; i < len; ) {
71: printf("%02x ",result[i]);
72: i++;
73: if ( !(i%16) )
74: printf("\n");
75: }
76: printf("\n");
77: }
78: }
79: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>