Annotation of OpenXM/src/ox_toolkit/bconv.c, Revision 1.4
1.1 ohara 1: /* -*- mode: C -*- */
1.4 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/bconv.c,v 1.3 2000/03/10 12:24:38 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>
1.3 ohara 9:
10: #include "ox_toolkit.h"
1.1 ohara 11:
1.4 ! ohara 12: static void display(ox *m)
1.1 ohara 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);
1.4 ! ohara 22: dump_buffer_init(d_buff);
1.1 ohara 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);
1.4 ! ohara 28: dump_buffer_init(d_buff);
1.1 ohara 29: dump_ox_command((ox_command *)m);
30: break;
31: default:
32: len = cmolen_cmo((cmo *)m);
33: d_buff = malloc(len);
1.4 ! ohara 34: dump_buffer_init(d_buff);
1.1 ohara 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:
1.4 ! ohara 54: static void prompt()
1.1 ohara 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>