Commit | Line | Data |
---|---|---|
45964d3d BJ |
1 | #include <stdio.h> |
2 | /* | |
3 | * soelim - a filter to process n/troff input eliminating .so's | |
4 | * | |
5 | * Author: Bill Joy UCB July 8, 1977 | |
6 | * | |
7 | * This program eliminates .so's from a n/troff input stream. | |
8 | * It can be used to prepare safe input for submission to the | |
9 | * phototypesetter since the software supporting the operator | |
10 | * doesn't let him do chdir. | |
11 | * | |
12 | * This is a kludge and the operator should be given the | |
13 | * ability to do chdir. | |
14 | * | |
15 | * This program is more generally useful, it turns out, because | |
16 | * the program tbl doesn't understand ".so" directives. | |
17 | */ | |
18 | ||
19 | main(argc, argv) | |
20 | int argc; | |
21 | char *argv[]; | |
22 | { | |
23 | ||
24 | argc--; | |
25 | argv++; | |
26 | if (argc == 0) { | |
27 | fprintf(stderr, "Usage: %s file [ file ... ]\n", argv[-1]); | |
28 | exit(1); | |
29 | } | |
30 | do { | |
31 | process(argv[0]); | |
32 | argv++; | |
33 | argc--; | |
34 | } while (argc > 0); | |
35 | exit(0); | |
36 | } | |
37 | ||
38 | process(file) | |
39 | char *file; | |
40 | { | |
41 | register char *cp; | |
42 | register int c; | |
43 | char fname[BUFSIZ]; | |
44 | FILE *soee; | |
45 | ||
46 | soee = fopen(file, "r"); | |
47 | if (soee == NULL) { | |
48 | perror(file); | |
49 | return; | |
50 | } | |
51 | for (;;) { | |
52 | c = getc(soee); | |
53 | if (c < 0) | |
54 | break; | |
55 | if (c != '.') | |
56 | goto simple; | |
57 | c = getc(soee); | |
58 | if (c != 's') { | |
59 | putchar('.'); | |
60 | goto simple; | |
61 | } | |
62 | c = getc(soee); | |
63 | if (c != 'o') { | |
64 | printf(".s"); | |
65 | goto simple; | |
66 | } | |
67 | do | |
68 | c = getc(soee); | |
69 | while (c == ' ' || c == '\t'); | |
70 | cp = fname; | |
71 | for (;;) { | |
72 | switch (c) { | |
73 | ||
74 | case ' ': | |
75 | case '\t': | |
76 | case '\n': | |
77 | case EOF: | |
78 | goto donename; | |
79 | ||
80 | default: | |
81 | *cp++ = c; | |
82 | c = getc(soee); | |
83 | continue; | |
84 | } | |
85 | } | |
86 | donename: | |
87 | if (cp == fname) { | |
88 | printf(".so"); | |
89 | goto simple; | |
90 | } | |
91 | *cp++ = 0; | |
92 | process(fname); | |
93 | continue; | |
94 | simple: | |
95 | if (c == EOF) | |
96 | break; | |
97 | putchar(c); | |
98 | } | |
99 | fclose(soee); | |
100 | } |