ORCA/EZ assembler source file converter

This commit is contained in:
Eric Fischer 1999-11-29 12:27:26 -08:00
parent 6a3e4d8df6
commit 145127d195

97
orca.c Normal file
View File

@ -0,0 +1,97 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
char **av;
void
usage (char *s)
{
fprintf (stderr, "Usage: %s [file]\n");
}
void
process (FILE *f, char *name)
{
int a, b;
a = getc (f); /* load address */
b = getc (f); /* high half of load address */
if (a == EOF || b == EOF)
return;
a = getc (f); /* file length */
b = getc (f); /* high half of file length */
if (a == EOF || b == EOF)
return;
a = getc (f); /* language */
b = getc (f); /* revision */
if (a == EOF || b == EOF)
return;
if (a != 1) {
fprintf (stderr, "%s: %s: not an ORCA/EZ file\n", *av, name);
return;
}
printf ("; revision %d\n", b);
a = getc (f); /* unused date */
b = getc (f); /* unused date */
if (a == EOF || b == EOF)
return;
while (1) {
int c;
int i, j;
int len;
len = getc (f);
if (len == 0 || len == EOF)
break;
for (i = 0; i < len - 2; i++) {
c = getc (f);
if (c < 128)
for (j = 0; j < c; j++)
printf (" ");
else
printf ("%c", c & 0x7f);
}
len = getc (f);
printf ("\n");
}
}
int
main (int argc, char **argv)
{
av = argv;
if (argc < 2) {
process (stdin, "standard input");
} else if (argc == 2) {
FILE *f = fopen (argv[1], "r");
if (f) {
process (f, argv[1]);
fclose (f);
} else {
fprintf (stderr, "%s: %s: %s\n", argv[0], argv[1],
strerror (errno));
exit (EXIT_FAILURE);
}
} else {
usage (argv[0]);
exit (EXIT_FAILURE);
}
return (EXIT_SUCCESS);
}