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