summaryrefslogtreecommitdiff
path: root/dviware/beebe/utils/hd.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /dviware/beebe/utils/hd.c
Initial commit
Diffstat (limited to 'dviware/beebe/utils/hd.c')
-rw-r--r--dviware/beebe/utils/hd.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/dviware/beebe/utils/hd.c b/dviware/beebe/utils/hd.c
new file mode 100644
index 0000000000..a4bc2a4359
--- /dev/null
+++ b/dviware/beebe/utils/hd.c
@@ -0,0 +1,100 @@
+/***********************************************************************
+Dump one or more files to stdout, translating unprintable characters to
+\ooo octal sequences, and starting newlines at each ESC, or when line
+length would exceed 72 characters.
+
+Usage:
+ hd filelist
+
+Both 7-bit and 8-bit input files are supported, and the output contains
+the file name and its last-write date at the top of the page.
+
+Outside of TOPS-20, it will be necessary to provide (possibly dummy)
+definitions of fileof() and timeof(), which are intended to return
+character strings containing the file name and last read or write time,
+given the file pointer.
+
+[15-Aug-87]
+
+***********************************************************************/
+
+#define MAXLINE 72
+#define COMMENT '!' /* marks start of comment to end-of-line */
+
+#include <stdio.h>
+
+char* fileof();
+char* timeof();
+void hd();
+
+FILE* tty;
+
+
+main(argc,argv)
+int argc;
+char* argv[];
+{
+ int k;
+
+ tty = stdout;
+ for (k = 1; k < argc; ++k)
+ hd(argv[k]);
+}
+
+void
+hd(filename)
+char* filename;
+{
+ register int c;
+ register FILE* fp;
+ register int hpos;
+
+ if ((fp = fopen(filename,"rb")) == (FILE*)NULL)
+ exit(2);
+
+ (void)fprintf(tty,"%c%s [%s]\n",
+ COMMENT,fileof(fileno(fp)),timeof(fileno(fp),"w"));
+
+ hpos = 0;
+ while ((c = getc(fp)) != EOF)
+ {
+ if ((c < 040) || (c > 0176) || (c == '\\') || (c == COMMENT))
+ { /* use octal encoding */
+ if (c == 033)
+ {
+ putc('\n',tty);
+ hpos = 0;
+ }
+ else if (hpos > (MAXLINE-4))
+ {
+ putc('\n',tty);
+ putc('\t',tty);
+ hpos = 8;
+ }
+
+ (void)fprintf(tty,"\\%03o",c);
+ hpos += 4;
+ if (c == '\n')
+ {
+ putc('\n',tty);
+ hpos = 0;
+ }
+ }
+ else /* printable character */
+ {
+ if (hpos > (MAXLINE-1))
+ {
+ putc('\n',tty);
+ putc('\t',tty);
+ hpos = 8;
+ }
+ putc(c,tty);
+ hpos++;
+ }
+ }
+ putc('\n',tty);
+ putc('\f',tty);
+
+ (void)fflush(tty);
+ (void)fclose(fp);
+}