-
Notifications
You must be signed in to change notification settings - Fork 1
/
soelim.c
executable file
·101 lines (95 loc) · 1.65 KB
/
soelim.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Copyright (c) 1979 Regents of the University of California */
#include <stdio.h>
/*
* soelim - a filter to process n/troff input eliminating .so's
*
* Author: Bill Joy UCB July 8, 1977
*
* This program eliminates .so's from a n/troff input stream.
* It can be used to prepare safe input for submission to the
* phototypesetter since the software supporting the operator
* doesn't let him do chdir.
*
* This is a kludge and the operator should be given the
* ability to do chdir.
*
* This program is more generally useful, it turns out, because
* the program tbl doesn't understand ".so" directives.
*/
main(argc, argv)
int argc;
char *argv[];
{
argc--;
argv++;
if (argc == 0) {
fprintf(stderr, "Usage: %s file [ file ... ]\n", argv[-1]);
exit(1);
}
do {
process(argv[0]);
argv++;
argc--;
} while (argc > 0);
exit(0);
}
process(file)
char *file;
{
register char *cp;
register int c;
char fname[BUFSIZ];
FILE *soee;
soee = fopen(file, "r");
if (soee == NULL) {
perror(file);
return;
}
for (;;) {
c = getc(soee);
if (c < 0)
break;
if (c != '.')
goto simple;
c = getc(soee);
if (c != 's') {
putchar('.');
goto simple;
}
c = getc(soee);
if (c != 'o') {
printf(".s");
goto simple;
}
do
c = getc(soee);
while (c == ' ' || c == '\t');
cp = fname;
for (;;) {
switch (c) {
case ' ':
case '\t':
case '\n':
case EOF:
goto donename;
default:
*cp++ = c;
c = getc(soee);
continue;
}
}
donename:
if (cp == fname) {
printf(".so");
goto simple;
}
*cp++ = 0;
process(fname);
continue;
simple:
if (c == EOF)
break;
putchar(c);
}
fclose(soee);
}