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

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

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

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