1 /* $NetBSD: soelim.c,v 1.13 2004/01/05 23:23:37 jmmv Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
34 __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
35 The Regents of the University of California. All rights reserved.");
40 static char sccsid
[] = "@(#)soelim.c 8.1 (Berkeley) 6/6/93";
42 __RCSID("$NetBSD: soelim.c,v 1.13 2004/01/05 23:23:37 jmmv Exp $");
46 * soelim - a filter to process n/troff input eliminating .so's
48 * Author: Bill Joy UCB July 8, 1977
50 * This program eliminates .so's from a n/troff input stream.
51 * It can be used to prepare safe input for submission to the
52 * phototypesetter since the software supporting the operator
53 * doesn't let him do chdir.
55 * This is a kludge and the operator should be given the
56 * ability to do chdir.
58 * This program is more generally useful, it turns out, because
59 * the program tbl doesn't understand ".so" directives.
61 #include <sys/param.h>
68 #define STDIN_NAME "-"
75 static int process(struct path
*, const char *);
76 static void initpath(struct path
*);
77 static void addpath(struct path
*, const char *);
78 static FILE *openpath(struct path
*, const char *, const char *);
80 int main(int, char **);
84 initpath(struct path
*p
)
91 addpath(struct path
*p
, const char *dir
)
95 if (p
->list
== NULL
|| p
->n
<= p
->c
- 2) {
96 n
= realloc(p
->list
, (p
->n
+ 10) * sizeof(p
->list
[0]));
103 if ((p
->list
[p
->c
++] = strdup(dir
)) == NULL
)
106 p
->list
[p
->c
] = NULL
;
110 openpath(struct path
*p
, const char *name
, const char *parm
)
112 char filename
[MAXPATHLEN
];
117 if (*name
== '/' || p
->c
== 0)
118 return fopen(name
, parm
);
120 for (i
= 0; i
< p
->c
; i
++) {
121 if (p
->list
[i
][0] == '\0')
124 (void)snprintf(filename
, sizeof(filename
), "%s/%s",
128 if ((fp
= fopen(f
, parm
)) != NULL
)
135 main(int argc
, char *argv
[])
143 while ((c
= getopt(argc
, argv
, "I:")) != -1)
149 (void)fprintf(stderr
,
150 "usage: %s [-I<dir>] [files...]\n",
159 (void)process(&p
, STDIN_NAME
);
163 (void)process(&p
, argv
[0]);
171 process(struct path
*p
, const char *file
)
179 if (!strcmp(file
, STDIN_NAME
)) {
182 soee
= openpath(p
, file
, "r");
184 warn("Cannot open `%s'", file
);
206 while (c
== ' ' || c
== '\t');
231 if (process(p
, fname
) < 0)
233 printf(".so %s\n", fname
);