Annotation of src/usr.bin/soelim/soelim.c, Revision 1.1.1.1
1.1 deraadt 1: /* $NetBSD: soelim.c,v 1.3 1994/12/21 08:11:26 jtc Exp $ */
2:
3: /*
4: * Copyright (c) 1980, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: */
35:
36: #ifndef lint
37: static char copyright[] =
38: "@(#) Copyright (c) 1980, 1993\n\
39: The Regents of the University of California. All rights reserved.\n";
40: #endif /* not lint */
41:
42: #ifndef lint
43: #if 0
44: static char sccsid[] = "@(#)soelim.c 8.1 (Berkeley) 6/6/93";
45: #endif
46: static char rcsid[] = "$NetBSD: soelim.c,v 1.3 1994/12/21 08:11:26 jtc Exp $";
47: #endif /* not lint */
48:
49: #include <stdio.h>
50: /*
51: * soelim - a filter to process n/troff input eliminating .so's
52: *
53: * Author: Bill Joy UCB July 8, 1977
54: *
55: * This program eliminates .so's from a n/troff input stream.
56: * It can be used to prepare safe input for submission to the
57: * phototypesetter since the software supporting the operator
58: * doesn't let him do chdir.
59: *
60: * This is a kludge and the operator should be given the
61: * ability to do chdir.
62: *
63: * This program is more generally useful, it turns out, because
64: * the program tbl doesn't understand ".so" directives.
65: */
66: #define STDIN_NAME "-"
67:
68: main(argc, argv)
69: int argc;
70: char *argv[];
71: {
72:
73: argc--;
74: argv++;
75: if (argc == 0) {
76: (void)process(STDIN_NAME);
77: exit(0);
78: }
79: do {
80: (void)process(argv[0]);
81: argv++;
82: argc--;
83: } while (argc > 0);
84: exit(0);
85: }
86:
87: int process(file)
88: char *file;
89: {
90: register char *cp;
91: register int c;
92: char fname[BUFSIZ];
93: FILE *soee;
94: int isfile;
95:
96: if (!strcmp(file, STDIN_NAME)) {
97: soee = stdin;
98: } else {
99: soee = fopen(file, "r");
100: if (soee == NULL) {
101: perror(file);
102: return(-1);
103: }
104: }
105: for (;;) {
106: c = getc(soee);
107: if (c == EOF)
108: break;
109: if (c != '.')
110: goto simple;
111: c = getc(soee);
112: if (c != 's') {
113: putchar('.');
114: goto simple;
115: }
116: c = getc(soee);
117: if (c != 'o') {
118: printf(".s");
119: goto simple;
120: }
121: do
122: c = getc(soee);
123: while (c == ' ' || c == '\t');
124: cp = fname;
125: isfile = 0;
126: for (;;) {
127: switch (c) {
128:
129: case ' ':
130: case '\t':
131: case '\n':
132: case EOF:
133: goto donename;
134:
135: default:
136: *cp++ = c;
137: c = getc(soee);
138: isfile++;
139: continue;
140: }
141: }
142: donename:
143: if (cp == fname) {
144: printf(".so");
145: goto simple;
146: }
147: *cp = 0;
148: if (process(fname) < 0)
149: if (isfile)
150: printf(".so %s\n", fname);
151: continue;
152: simple:
153: if (c == EOF)
154: break;
155: putchar(c);
156: if (c != '\n') {
157: c = getc(soee);
158: goto simple;
159: }
160: }
161: if (soee != stdin) {
162: fclose(soee);
163: }
164: return(0);
165: }