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