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

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

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

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