File: [local] / OpenXM / src / ox_math / Attic / bconv.c (download)
Revision 1.2, Tue Nov 2 06:11:57 1999 UTC (24 years, 8 months ago) by ohara
Branch: MAIN
Changes since 1.1: +1 -1
lines
partly support the followings:
cmo_monomial32, cmo_dms_generic, cmo_ring_by_name, cmo_indeterminate.
|
/* -*- mode: C; coding: euc-japan -*- */
/* $OpenXM: OpenXM/src/ox_math/bconv.c,v 1.2 1999/11/02 06:11:57 ohara Exp $ */
/* $Id: bconv.c,v 1.1 1999/09/30 08:25:31 ohara Exp ohara $ */
/*
OX expression -> バイト列
CMO expression -> バイト列
コンバータ
*/
#include <stdio.h>
#include <stdlib.h>
#include "ox.h"
#include "parse.h"
char* dump_ox_data(char* array, ox_data* m);
char* dump_ox_command(char* array, ox_command* m);
int display(ox *m)
{
int i;
int len = 0;
unsigned char* array;
switch(m->tag) {
case OX_DATA:
len = sizeof(int) + sizeof(int) + cmolen_cmo(((ox_data *)m)->cmo);
array = malloc(len);
dump_ox_data(array, (ox_data *)m);
break;
case OX_COMMAND:
len = sizeof(int) + sizeof(int) + sizeof(int);
array = malloc(len);
dump_ox_command(array, (ox_command *)m);
break;
default:
len = cmolen_cmo(m);
array = malloc(len);
dump_cmo(array, m);
}
for(i=0; i<len; i++) {
fprintf(stdout, "%02x ", array[i]);
if(i%20==19) {
fprintf(stdout, "\n");
}
}
fprintf(stdout, "\n");
}
#define SIZE_CMDLINE 4096
char cmdline[SIZE_CMDLINE];
int prompt(char* s, int size)
{
fprintf(stdout, "> ");
fgets(s, size, stdin);
setmode_mygetc(s, size);
}
int main()
{
cmo *m;
setbuf(stderr, NULL);
setbuf(stdout, NULL);
setflag_parse(PFLAG_ADDREV);
setgetc(mygetc);
while(1) {
prompt(cmdline, SIZE_CMDLINE);
if ((m = parse()) == NULL) {
break;
}
display(m);
}
return 0;
}