summaryrefslogtreecommitdiff
path: root/dviware/beebe/utils/unhd.c
blob: 456adec9f589bd14b30a9c115e1276f5600f281d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/***********************************************************************
Process a file output by hd back into an 8-bit binary file.  Characters
out of the range 040..0176 are ignored.

Usage:
	unhd infile outfile

The open mode flags passed to fopen() are likely to require modification
outside of TOPS-20.

[15-Aug-87]
***********************************************************************/

#include <stdio.h>
#define COMMENT '!'		/* marks start of comment to end-of-line */

void
main(argc,argv)
int argc;
char* argv[];
{
    FILE* in;
    FILE* out;
    register int c;

    if (argc < 2)
    {
	(void)fprintf(stderr,"Usage: unhd infile outfile");
	exit(0);
    }
    if ((in = fopen(argv[1],"rb")) == (FILE*)NULL)
        exit(1);
    if ((out = fopen(argv[2],"wb8")) == (FILE*)NULL)
        exit(2);

    while ((c = getc(in)) != EOF)
    {
        if (c == COMMENT)
	{
	    while (((c = getc(in)) != EOF) && (c != '\n'))
	        /* flush comment */;
	}
	else if (c > 037)
	{
	    if (c == '\\')
	    {
		c = getc(in) - '0';
		c = (c << 3) + (getc(in) - '0');
		c = (c << 3) + (getc(in) - '0');
	    }
	    putc(c,out);
	}
    }
    exit(0);
}