mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-01-13 15:27:35 +00:00
8to9: add simple tool for converting (mainly text) files from octets to nonets
This commit is contained in:
parent
85ecd9f1f1
commit
3ab6b1a8ed
80
8to9/8to9.c
Normal file
80
8to9/8to9.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 8to9.c
|
||||
*
|
||||
* Convert octet files to nonet files.
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#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;
|
||||
}
|
||||
14
8to9/Makefile
Normal file
14
8to9/Makefile
Normal file
@ -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.*
|
||||
Loading…
x
Reference in New Issue
Block a user