Annotation of OpenXM/src/ox_math/bconv.c, Revision 1.2
1.1 ohara 1: /* -*- mode: C; coding: euc-japan -*- */
2: /* $OpenXM$ */
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:
15: char* dump_ox_data(char* array, ox_data* m);
16: char* dump_ox_command(char* array, ox_command* m);
17:
18: int display(ox *m)
19: {
20: int i;
21: int len = 0;
22: unsigned char* array;
23:
24: switch(m->tag) {
25: case OX_DATA:
26: len = sizeof(int) + sizeof(int) + cmolen_cmo(((ox_data *)m)->cmo);
27: array = malloc(len);
28: dump_ox_data(array, (ox_data *)m);
29: break;
30: case OX_COMMAND:
31: len = sizeof(int) + sizeof(int) + sizeof(int);
32: array = malloc(len);
33: dump_ox_command(array, (ox_command *)m);
34: break;
35: default:
36: len = cmolen_cmo(m);
37: array = malloc(len);
38: dump_cmo(array, m);
39: }
40:
41: for(i=0; i<len; i++) {
42: fprintf(stdout, "%02x ", array[i]);
43: if(i%20==19) {
44: fprintf(stdout, "\n");
45: }
46: }
47: fprintf(stdout, "\n");
48: }
49:
50: #define SIZE_CMDLINE 4096
51:
52: char cmdline[SIZE_CMDLINE];
53:
54: int prompt(char* s, int size)
55: {
56: fprintf(stdout, "> ");
57: fgets(s, size, stdin);
58: setmode_mygetc(s, size);
59: }
60:
61: int main()
62: {
63: cmo *m;
64: setbuf(stderr, NULL);
65: setbuf(stdout, NULL);
66:
1.2 ! ohara 67: setflag_parse(PFLAG_ADDREV);
1.1 ohara 68: setgetc(mygetc);
69:
70: while(1) {
71: prompt(cmdline, SIZE_CMDLINE);
72: if ((m = parse()) == NULL) {
73: break;
74: }
75: display(m);
76: }
77: return 0;
78: }
79:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>