From 3ab6b1a8ed8be36ab2cfac440d1c48eb7ed93e4f Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Thu, 8 Aug 2013 12:19:29 +0000 Subject: [PATCH] 8to9: add simple tool for converting (mainly text) files from octets to nonets --- 8to9/8to9.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 8to9/Makefile | 14 +++++++++ 2 files changed, 94 insertions(+) create mode 100644 8to9/8to9.c create mode 100644 8to9/Makefile diff --git a/8to9/8to9.c b/8to9/8to9.c new file mode 100644 index 0000000..ac5cd18 --- /dev/null +++ b/8to9/8to9.c @@ -0,0 +1,80 @@ +/* + * 8to9.c + * + * Convert octet files to nonet files. + */ +#include +#include +#include +#include +#include "pdp10-stdio.h" + +#define VERSION "pdp10-tools 8to9 version 0.0, built " __DATE__ " " __TIME__ "\n" + +int main(int argc, char **argv) +{ + const char *infile, *outfile; + FILE *infp; + PDP10_FILE *outfp; + int ch; + + infile = NULL; + outfile = NULL; + + for (;;) { + ch = getopt(argc, argv, "Vi:o:"); + switch (ch) { + case 'V': + printf(VERSION); + return 0; + case 'i': + infile = optarg; + continue; + case 'o': + outfile = optarg; + continue; + case -1: + break; + default: + fprintf(stderr, "%s -o OUTFILE [-i INFILE] [-V]\n", argv[0]); + return 1; + } + break; + } + + /* XXX: We currently require a named output file because pdp10-stdio.c doesn't + support fdopen:ing non-seekable files. That should be fixed at some point. */ + if (!outfile) { + fprintf(stderr, "%s: no OUTFILE specified\n", argv[0]); + return 1; + } else { + outfp = pdp10_fopen(outfile, "wb"); + if (!outfp) { + fprintf(stderr, "%s: %s: failed to open for writing: %s\n", argv[0], outfile, strerror(errno)); + return 1; + } + } + + if (!infile) { + infp = stdin; + } else { + infp = fopen(infile, "rb"); + if (!infp) { + fprintf(stderr, "%s: %s: failed to open for reading: %s\n", argv[0], infile, strerror(errno)); + return 1; + } + } + + while ((ch = fgetc(infp)) != EOF) + if (pdp10_fputc(ch, outfp) == EOF) { + fprintf(stderr, "%s: %s: failed to write: %s\n", argv[0], outfile, strerror(errno)); + return 1; + } + + if (pdp10_fclose(outfp) == EOF) { + fprintf(stderr, "%s: %s: failed to close: %s\n", argv[0], outfile, strerror(errno)); + return 1; + } + + return 0; +} diff --git a/8to9/Makefile b/8to9/Makefile new file mode 100644 index 0000000..2eb264c --- /dev/null +++ b/8to9/Makefile @@ -0,0 +1,14 @@ +CC=gcc +CFLAGS=-O2 -g -Wall +CPPFLAGS=-I../include + +8TO9OBJS=8to9.o +LIBOBJS=../lib/pdp10-stdio.o + +8to9: $(8TO9OBJS) $(LIBOBJS) + $(LINK.c) -o $@ $^ + +8to9.o: 8to9.c ../include/pdp10-stdint.h ../include/pdp10-stdio.h + +clean: + rm -f $(8TO9OBJS) 8to9 a.out core.*