1 /*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1980, 1993\n\
11 The Regents of the University of California. All rights reserved.\n";
12 #endif /* not lint */
13
14 #ifndef lint
15 static char sccsid[] = "@(#)soelim.c 8.1 (Berkeley) 06/06/93";
16 #endif /* not lint */
17
18 #include <stdio.h>
19 /*
20 * soelim - a filter to process n/troff input eliminating .so's
21 *
22 * Author: Bill Joy UCB July 8, 1977
23 *
24 * This program eliminates .so's from a n/troff input stream.
25 * It can be used to prepare safe input for submission to the
26 * phototypesetter since the software supporting the operator
27 * doesn't let him do chdir.
28 *
29 * This is a kludge and the operator should be given the
30 * ability to do chdir.
31 *
32 * This program is more generally useful, it turns out, because
33 * the program tbl doesn't understand ".so" directives.
34 */
35 #define STDIN_NAME "-"
36
main(argc,argv)37 main(argc, argv)
38 int argc;
39 char *argv[];
40 {
41
42 argc--;
43 argv++;
44 if (argc == 0) {
45 (void)process(STDIN_NAME);
46 exit(0);
47 }
48 do {
49 (void)process(argv[0]);
50 argv++;
51 argc--;
52 } while (argc > 0);
53 exit(0);
54 }
55
process(file)56 int process(file)
57 char *file;
58 {
59 register char *cp;
60 register int c;
61 char fname[BUFSIZ];
62 FILE *soee;
63 int isfile;
64
65 if (!strcmp(file, STDIN_NAME)) {
66 soee = stdin;
67 } else {
68 soee = fopen(file, "r");
69 if (soee == NULL) {
70 perror(file);
71 return(-1);
72 }
73 }
74 for (;;) {
75 c = getc(soee);
76 if (c == EOF)
77 break;
78 if (c != '.')
79 goto simple;
80 c = getc(soee);
81 if (c != 's') {
82 putchar('.');
83 goto simple;
84 }
85 c = getc(soee);
86 if (c != 'o') {
87 printf(".s");
88 goto simple;
89 }
90 do
91 c = getc(soee);
92 while (c == ' ' || c == '\t');
93 cp = fname;
94 isfile = 0;
95 for (;;) {
96 switch (c) {
97
98 case ' ':
99 case '\t':
100 case '\n':
101 case EOF:
102 goto donename;
103
104 default:
105 *cp++ = c;
106 c = getc(soee);
107 isfile++;
108 continue;
109 }
110 }
111 donename:
112 if (cp == fname) {
113 printf(".so");
114 goto simple;
115 }
116 *cp = 0;
117 if (process(fname) < 0)
118 if (isfile)
119 printf(".so %s\n", fname);
120 continue;
121 simple:
122 if (c == EOF)
123 break;
124 putchar(c);
125 if (c != '\n') {
126 c = getc(soee);
127 goto simple;
128 }
129 }
130 if (soee != stdin) {
131 fclose(soee);
132 }
133 return(0);
134 }
135