Annotation of OpenXM/src/ox_toolkit/bconv.c, Revision 1.1
1.1 ! ohara 1: /* -*- mode: C -*- */
! 2: /* $OpenXM$ */
! 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 int size = SIZE_CMDLINE;
! 53: static char cmdline[SIZE_CMDLINE];
! 54:
! 55: static int prompt()
! 56: {
! 57: fprintf(stdout, "> ");
! 58: fgets(cmdline, size, stdin);
! 59: setmode_mygetc(cmdline, size);
! 60: }
! 61:
! 62: int main()
! 63: {
! 64: cmo *m;
! 65: setbuf(stderr, NULL);
! 66: setbuf(stdout, NULL);
! 67:
! 68: setflag_parse(PFLAG_ADDREV);
! 69: setgetc(mygetc);
! 70:
! 71: for(prompt(); (m = parse()) != NULL; prompt()) {
! 72: display(m);
! 73: }
! 74: return 0;
! 75: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>