From 2eaf496d05dc5276250d1f1aa045dcfd27d8004e Mon Sep 17 00:00:00 2001 From: dschmenk Date: Fri, 6 Sep 2013 21:11:24 -0700 Subject: [PATCH] MERLIN <-> text conversion utility --- src/Makefile | 2 +- src/merlin2text.c | 31 +++++++++++++++++++++++++++++++ src/text2merlin.c | 24 ++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 src/merlin2text.c create mode 100755 src/text2merlin.c diff --git a/src/Makefile b/src/Makefile index 046f6bf..1a10585 100755 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -BIN=a2serclk a2pid a2mon a2term dskread dskwrite bintomon bload brun +BIN=a2serclk a2pid a2mon a2term dskread dskwrite bintomon bload brun text2merlin merlin2text all: $(BIN) fusea2pi: fusea2pi.c a2lib.c diff --git a/src/merlin2text.c b/src/merlin2text.c new file mode 100755 index 0000000..507278f --- /dev/null +++ b/src/merlin2text.c @@ -0,0 +1,31 @@ +#include +#include + +int main(int argc, char **argv) +{ + int fin, comment, charpos; + char c; + + if (argc > 1) + { + fin = open(argv[1], O_RDONLY, 0); + } + else + fin = 0; + comment = charpos = 0; + while (read(fin, &c, 1) == 1) + { + c &= 0x7f; + if ((charpos++ == 0 && c == '*') || c == ';') + comment = 1; + if (c == '\r') + { + comment = charpos = 0; + c = '\n'; + } + if (c == ' ' && !comment) + c = '\t'; + putc(c & 0x7f, stdout); + } + return (0); +} diff --git a/src/text2merlin.c b/src/text2merlin.c new file mode 100755 index 0000000..5369a25 --- /dev/null +++ b/src/text2merlin.c @@ -0,0 +1,24 @@ +#include +#include + +int main(int argc, char **argv) +{ + int fout; + char c; + + if (argc > 1) + fout = open(argv[1], O_WRONLY|O_CREAT, 0644); + else + fout = 1; + while ((c = getc(stdin)) != EOF) + { + if (c == '\n') + c = '\r'; + if (c == '\t') + c = ' '; + c |= 0x80; + write(fout, &c, 1); + } + close(fout); + return (0); +}