Files
Cody Boone Ferguson 93963607f3 Many fixes and additions to 1984/mullender
Swap order of alt and original code in build/try sections so that the
original code is suggested second, after alt code, with the bugs and
(mis)features added to the README.md file, pointing out that it'll only
work on VAX-11 / PDP-11 machines. This is added in the bugs.md (it was
actually missing from the bugs.md file).

The alt code (both versions, see below) now have a lower limit on the
microseconds at 500 (still defaults at 10000). This is because anything
much lower and it's nigh impossible to see and in some cases it won't
work at all (at least in the MacBook Pro with the M1 chip).

Added second alt code which is like the first except that once it times
out it starts over.

Running make alt will compile both alt versions.

The gentab.c file that I added (found from the author) and fixed to
compile could not always create code that would compile due to some
characters needing to be escaped like ' and \. These are now escaped if
they are encountered but there certainly could be more that I did not
think of that would have to be escaped.
2023-10-27 03:51:17 -07:00

56 lines
1.0 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include "a.out.h"
main(argc, argv) char **argv;
{
register FILE *fp;
register short pos = 0, c, n;
register char *fmt = "";
if (argc != 2) {
fprintf (stderr, "Usage: %s file\n", argv[0]);
exit (1);
}
if ((fp = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "%s: can't open %s\n", argv[0], argv[1]);
exit(2);
}
fseek (fp, (long) sizeof (struct exec), 0);
printf("/* portable between VAX and PDP11 */\n\n");
printf ("short main[] = {\n");
for (;;) {
if (pos == 0)
printf("\t");
c=getc(fp) & 0377;
if (feof(fp)) break;
n = getc(fp) << 8|c;
switch (rand() % 5) {
case 0:
case 1:
fmt = "%d"; break;
case 2:
fmt = "%u"; break;
case 3:
fmt = "0%o"; break;
case 4:
fmt = "0x%x"; break;
}
if (n == '\\' || n == '\'') fmt = "'\\%c'";
else if (32 <= n && n < 127 && (rand() % 4)) fmt = "'%c'";
printf(n < 8 ? "%d" : fmt, n);
printf(",");
if (pos++ == 8) {
printf("\n");
pos = 0;
}
else printf(" ");
}
printf("};\n");
}