From 78aae09a0909d2e8148d36355cebaf2509a4f55a Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 14:47:47 +0000 Subject: [PATCH] Initial revision --- util/misc/convert.c | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 util/misc/convert.c diff --git a/util/misc/convert.c b/util/misc/convert.c new file mode 100644 index 000000000..44df72d3d --- /dev/null +++ b/util/misc/convert.c @@ -0,0 +1,87 @@ +#ifndef NORCSID +static char rcsid[] = "$Header$"; +#endif + +/* This program converts either human-readable or compact EM + assembly code to calls of the procedure-interface. + It must be linked with two libraries: + - a library to read EM code, according to read_em(3) + - a library implementing the em_code(3) interface. + Thus, this program could serve as an EM_encoder, an + EM_decoder, or some code generator, depending on how it is + linked. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +char *filename; /* Name of input file */ +int errors; /* Number of errors */ + +main(argc,argv) + char **argv; +{ + struct e_instr *EM_getinstr(); + register struct e_instr *p; + register struct e_args *ap; + + if (argc >= 2) { + filename = argv[1]; + } + else filename = 0; + if (!EM_open(filename)) { + fatal(EM_error); + } + p = EM_getinstr(); + C_init((arith) EM_wordsize, (arith) EM_pointersize); + if (argc >= 3) { + if (!C_open(argv[2])) { + fatal("C_open failed"); + } + } + else if (!C_open( (char *) 0)) fatal("C_open failed"); + C_magic(); + while (p) { + if (p->em_type == EM_FATAL) { + fatal("EM_getinstr: %s", EM_error); + } + if (p->em_type == EM_ERROR) { + error("EM_getinstr: %s", EM_error); + continue; + } + if (!EM_mkcalls(p)) { + error("EM_mkcalls: %s", EM_error); + } + p = EM_getinstr(); + } + C_close(); + EM_close(); + return errors ? 1 : 0; +} + +/* VARARGS */ +error(s,a1,a2,a3,a4) + char *s; +{ + fprintf(stderr, + "%s, line %d: ", + filename ? filename : "standard input", + EM_lineno); + fprintf(stderr,s,a1,a2,a3,a4); + putc('\n', stderr); + errors++; +} + +/* VARARGS */ +fatal(s,a1,a2,a3,a4) + char *s; +{ + error(s,a1,a2,a3,a4); + exit(1); +}