ANSI C conversion.

This commit is contained in:
carl 2019-05-11 01:15:51 +08:00
parent 970e7da896
commit 0301827482
3 changed files with 101 additions and 86 deletions

View file

@ -18,7 +18,6 @@ static char rcsid[] = "$Id$";
#include <stdarg.h>
#include <stdlib.h>
#include "system.h"
#include "print.h"
#include "em_pseu.h"
#include "em_mnem.h"
@ -31,58 +30,65 @@ static char rcsid[] = "$Id$";
char *filename; /* Name of input file */
int errors; /* Number of errors */
extern char *C_error;
extern int C_out(register struct e_instr *);
void error(const char *, ...);
void fatal(const char *, ...);
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct e_instr buf;
register struct e_instr *p = &buf;
if (argc >= 2) {
if (argc >= 2)
{
filename = argv[1];
}
else filename = 0;
if (!EM_open(filename)) {
else
filename = 0;
if (!EM_open(filename))
{
fatal(EM_error);
}
EM_getinstr(p);
C_init((arith) EM_wordsize, (arith) EM_pointersize);
if (argc >= 3) {
if (!C_open(argv[2])) {
if (argc >= 3)
{
if (!C_open(argv[2]))
{
fatal("C_open failed");
}
}
else if (!C_open( (char *) 0)) fatal("C_open failed");
else if (!C_open((char *) 0))
fatal("C_open failed");
C_magic();
while (p->em_type != EM_EOF) {
if (p->em_type == EM_FATAL) {
while (p->em_type != EM_EOF)
{
if (p->em_type == EM_FATAL)
{
fatal("%s", EM_error);
}
if (EM_error) {
if (EM_error)
{
error("%s", EM_error);
}
if (p->em_type != EM_ERROR && !C_out(p)) {
if (p->em_type != EM_ERROR && !C_out(p))
{
error("%s", C_error);
}
EM_getinstr(p);
}
C_close();
EM_close();
exit(errors ? 1 : 0);
exit(errors ? EXIT_FAILURE : EXIT_SUCCESS);
}
/* VARARGS */
void
error(const char *s, ...)
void error(const char *s, ...)
{
va_list ap;
va_start(ap, s);
fprint(STDERR,
"%s, line %d: ",
filename ? filename : "standard input",
fprint(STDERR, "%s, line %d: ", filename ? filename : "standard input",
EM_lineno);
doprnt(STDERR, s, ap);
fprint(STDERR, "\n");
@ -91,12 +97,12 @@ error(const char *s, ...)
}
/* VARARGS */
void
fatal(const char *s, ...)
void fatal(const char *s, ...)
{
va_list ap;
va_start(ap, s);
if (C_busy()) C_close();
if (C_busy())
C_close();
error(s, ap);
exit(1);
exit(EXIT_FAILURE);
}

View file

@ -3,10 +3,10 @@
.SH NAME
em_decode, em_encode \- compact to readable EM and v.v.
.SH SYNOPSIS
.B ~em/lib.bin/em_decode
.B em_decode
[ inputfile [ outputfile ] ]
.br
.B ~em/lib.bin/em_encode
.B em_encode
[ inputfile [ outputfile ] ]
.SH DESCRIPTION
Most programs involved with the EM project only produce and accept
@ -15,12 +15,12 @@ These files are only machine readable.
A description of this compact form can be found in [1].
To inspect the code produced by compilers or to patch them for one reason
or another, human readable assembly code is needed.
Em_decode produces human readable assembly code from the compact form.
em_decode produces human readable assembly code from the compact form.
.PP
Em_decode accepts the normal compact form in both optimized and
em_decode accepts the normal compact form in both optimized and
unoptimized form.
.PP
Em_encode produces the compact form
em_encode produces the compact form
out of these human readable assembly code.
.PP
The first argument is the input file.

View file

@ -33,36 +33,50 @@ long szdata;
long ptr7;
long ptr8;
main(argc, argv)
int argc;
char *argv[];
/* Forward declarations. */
static void esize(char *);
static int rd_open(char*);
static int rd_byte(void);
static long rd_int(long n);
static int rd_header(void);
static void rd_close(void);
#define rd_ptr() ((ptr) rd_int(psize))
int main(int argc, char *argv[])
{
printf("TPFCRE uref vers w/p text nproc szdata\n");
if (argc == 1) {
if (argc == 1)
{
esize("e.out");
}
else {
while (argc > 1) {
else
{
while (argc > 1)
{
esize(argv[1]);
argc--, argv++;
}
}
exit(0);
exit(EXIT_SUCCESS);
}
esize(fname)
char *fname;
static void esize(char *fname)
{
eof = 0;
if (!rd_open(fname)) {
if (!rd_open(fname))
{
printf("%s: cannot open\n", fname);
}
else {
if (!rd_header()) {
else
{
if (!rd_header())
{
printf("%s: not EM object format\n", fname);
}
else {
else
{
printf("%c", flags & 0001 ? 'T' : '-');
printf("%c", flags & 0002 ? 'P' : '-');
printf("%c", flags & 0004 ? 'F' : '-');
@ -91,15 +105,12 @@ esize(fname)
#define btol(a) ((long)(((long) (a)) & 0xFF))
int
rd_open(load_file)
char *load_file;
static int rd_open(char* load_file)
{
return (load_fp = fopen(load_file, "r")) != NULL;
return (load_fp = fopen(load_file, "rb")) != NULL;
}
int
rd_byte()
static int rd_byte(void)
{
int i;
@ -108,9 +119,7 @@ rd_byte()
return (i);
}
long
rd_int(n)
long n;
static long rd_int(long n)
{
long l;
register int i;
@ -121,10 +130,10 @@ rd_int(n)
return (l);
}
#define rd_ptr() ((ptr) rd_int(psize))
int
rd_header()
/* read e.out header information */
static int rd_header(void)
{
magic = rd_int(2L);
if (magic != MAGIC || eof)
@ -150,7 +159,7 @@ rd_header()
return !eof;
}
rd_close()
static void rd_close(void)
{
fclose(load_fp);
}