Annotation of OpenXM/src/ox_toolkit/bconv.c, Revision 1.2
1.1 ohara 1: /* -*- mode: C -*- */
1.2 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/bconv.c,v 1.1 1999/12/15 05:21:25 ohara Exp $ */
1.1 ohara 3:
4: /* bconv can convert an OX expression or a CMO expression to a byte stream. */
5: /* Any expressions, as a string, must have shorter length than 8192.*/
6:
7: #include <stdio.h>
8: #include <stdlib.h>
9: #include "ox.h"
10: #include "parse.h"
11:
12: static int display(ox *m)
13: {
14: int i;
15: int len = 0;
16: unsigned char* d_buff;
17:
18: switch(m->tag) {
19: case OX_DATA:
20: len = sizeof(int) + sizeof(int) + cmolen_cmo(((ox_data *)m)->cmo);
21: d_buff = malloc(len);
22: init_dump_buffer(d_buff);
23: dump_ox_data((ox_data *)m);
24: break;
25: case OX_COMMAND:
26: len = sizeof(int) + sizeof(int) + sizeof(int);
27: d_buff = malloc(len);
28: init_dump_buffer(d_buff);
29: dump_ox_command((ox_command *)m);
30: break;
31: default:
32: len = cmolen_cmo((cmo *)m);
33: d_buff = malloc(len);
34: init_dump_buffer(d_buff);
35: dump_cmo((cmo *)m);
36: }
37:
38: for(i=0; i<len; i++) {
39: fprintf(stdout, "%02x ", d_buff[i]);
40: if(i%20 == 19) {
41: fprintf(stdout, "\n");
42: }
43: }
44: if(i%20 != 19) {
45: fprintf(stdout, "\n");
46: }
47: free(d_buff);
48: }
49:
50: #define SIZE_CMDLINE 8192
51:
52: static char cmdline[SIZE_CMDLINE];
53:
54: static int prompt()
55: {
56: fprintf(stdout, "> ");
1.2 ! ohara 57: fgets(cmdline, SIZE_CMDLINE, stdin);
! 58: init_parser(cmdline);
1.1 ohara 59: }
60:
61: int main()
62: {
63: cmo *m;
64: setbuf(stderr, NULL);
65: setbuf(stdout, NULL);
66:
67: setflag_parse(PFLAG_ADDREV);
68: for(prompt(); (m = parse()) != NULL; prompt()) {
69: display(m);
70: }
71: return 0;
72: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>