[BACK]Return to bconv.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_math

Annotation of OpenXM/src/ox_math/bconv.c, Revision 1.3

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.3     ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/bconv.c,v 1.2 1999/11/02 06:11:57 ohara Exp $ */
1.1       ohara       3: /* $Id: bconv.c,v 1.1 1999/09/30 08:25:31 ohara Exp ohara $ */
                      4: /*
                      5: OX  expression -> バイト列
                      6: CMO expression -> バイト列
                      7: コンバータ
                      8: */
                      9:
                     10: #include <stdio.h>
                     11: #include <stdlib.h>
                     12: #include "ox.h"
                     13: #include "parse.h"
                     14:
1.3     ! ohara      15: static int display(ox *m)
1.1       ohara      16: {
                     17:     int i;
                     18:     int len = 0;
1.3     ! ohara      19:     unsigned char* d_buff;
        !            20:
1.1       ohara      21:     switch(m->tag) {
                     22:     case OX_DATA:
                     23:         len = sizeof(int) + sizeof(int) + cmolen_cmo(((ox_data *)m)->cmo);
1.3     ! ohara      24:         d_buff = malloc(len);
        !            25:                init_dump_buffer(d_buff);
        !            26:         dump_ox_data((ox_data *)m);
1.1       ohara      27:         break;
                     28:     case OX_COMMAND:
                     29:         len = sizeof(int) + sizeof(int) + sizeof(int);
1.3     ! ohara      30:         d_buff = malloc(len);
        !            31:                init_dump_buffer(d_buff);
        !            32:         dump_ox_command((ox_command *)m);
1.1       ohara      33:         break;
                     34:     default:
1.3     ! ohara      35:         len = cmolen_cmo((cmo *)m);
        !            36:         d_buff = malloc(len);
        !            37:                init_dump_buffer(d_buff);
        !            38:         dump_cmo((cmo *)m);
1.1       ohara      39:     }
                     40:
                     41:     for(i=0; i<len; i++) {
1.3     ! ohara      42:         fprintf(stdout, "%02x ", d_buff[i]);
        !            43:         if(i%20 == 19) {
1.1       ohara      44:             fprintf(stdout, "\n");
                     45:         }
                     46:     }
1.3     ! ohara      47:        if(i%20 != 19) {
        !            48:                fprintf(stdout, "\n");
        !            49:        }
        !            50:        free(d_buff);
1.1       ohara      51: }
                     52:
1.3     ! ohara      53: #define SIZE_CMDLINE  8192
1.1       ohara      54:
1.3     ! ohara      55: static int  size = SIZE_CMDLINE;
        !            56: static char cmdline[SIZE_CMDLINE];
1.1       ohara      57:
1.3     ! ohara      58: static int prompt()
1.1       ohara      59: {
                     60:     fprintf(stdout, "> ");
1.3     ! ohara      61:     fgets(cmdline, size, stdin);
        !            62:     setmode_mygetc(cmdline, size);
1.1       ohara      63: }
                     64:
                     65: int main()
                     66: {
                     67:     cmo *m;
                     68:     setbuf(stderr, NULL);
                     69:     setbuf(stdout, NULL);
                     70:
1.2       ohara      71:        setflag_parse(PFLAG_ADDREV);
1.1       ohara      72:     setgetc(mygetc);
                     73:
1.3     ! ohara      74:     for(prompt(); (m = parse()) != NULL; prompt()) {
1.1       ohara      75:         display(m);
                     76:     }
                     77:     return 0;
                     78: }
                     79:

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