[BACK]Return to test3.c CVS log [TXT][DIR] Up to [local] / OpenXM / doc / oxlib

Annotation of OpenXM/doc/oxlib/test3.c, Revision 1.2

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

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