2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static const char copyright[] =
36 "@(#) Copyright (c) 1980, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
42 static char sccsid[] = "@(#)getNAME.c 8.1 (Berkeley) 6/30/93";
44 static const char rcsid[] =
49 * Get name sections from manual pages.
51 * -i for building intro entries
52 * other apropos database
65 void dorefname(char *);
67 void split(char *, char *);
69 static void usage(void);
72 main(int argc, char *argv[])
76 while ((ch = getopt(argc, argv, "itw")) != -1)
102 getfrom(char *pathname)
106 char headbuf[BUFSIZ];
109 if (freopen(pathname, "r", stdin) == 0) {
110 warn("%s", pathname);
113 if ((name = strrchr(pathname, '/')))
118 if (fgets(headbuf, sizeof headbuf, stdin) == NULL) {
120 printf("%-60s UNKNOWN\n", pathname);
123 if (headbuf[0] != '.')
125 if ((headbuf[1] == 'T' && headbuf[2] == 'H') ||
126 (headbuf[1] == 't' && headbuf[2] == 'h'))
128 if (headbuf[1] == 'D' && headbuf[2] == 't') {
130 printf("%-60s NEW\n", pathname);
137 printf("%-60s OLD\n", pathname);
141 if (fgets(linbuf, sizeof linbuf, stdin) == NULL)
143 if (linbuf[0] != '.')
145 if (linbuf[1] == 'S' && linbuf[2] == 'H')
147 if (linbuf[1] == 's' && linbuf[2] == 'h')
153 if (!tocrc && !intro)
154 printf("%s\t", headbuf);
157 if (fgets(headbuf, sizeof headbuf, stdin) == NULL)
159 if (headbuf[0] == '.') {
160 if (headbuf[1] == 'S' && headbuf[2] == 'H')
162 if (headbuf[1] == 's' && headbuf[2] == 'h')
169 strcat(linbuf, headbuf);
174 printf("%s\n", linbuf);
179 if (fgets(linbuf, sizeof linbuf, stdin) == NULL)
181 if (linbuf[0] != '.')
183 if (linbuf[1] == 'S' && linbuf[2] == 'h')
189 if (!tocrc && !intro)
190 printf(".TH%s\t", &headbuf[3]);
193 if (fgets(headbuf, sizeof headbuf, stdin) == NULL)
195 if (headbuf[0] == '.') {
196 if (headbuf[1] == 'S' && headbuf[2] == 'h')
203 for (loc = strchr(headbuf, ' '); loc; loc = strchr(loc, ' '))
205 strcpy(loc, &loc[1]);
208 if (headbuf[0] != '.') {
209 strcat(linbuf, headbuf);
212 * Get rid of quotes in macros.
214 for (loc = strchr(&headbuf[4], '"'); loc; ) {
215 strcpy(loc, &loc[1]);
216 loc = strchr(loc, '"');
219 * Handle cross references
221 if (headbuf[1] == 'X' && headbuf[2] == 'r') {
222 for (loc = &headbuf[4]; *loc != ' '; loc++)
229 * Put dash between names and description.
231 if (headbuf[1] == 'N' && headbuf[2] == 'd')
232 strcat(linbuf, "\\- ");
234 * Skip over macro names.
236 strcat(linbuf, &headbuf[4]);
242 printf("%s\n", linbuf);
258 char *dp = name, *ep;
261 while (*dp && *dp != '.')
264 for (ep = dp+1; *ep; ep++)
279 split(char *line, char *name)
284 cp = strchr(line, '-');
288 for (--cp; *cp == ' ' || *cp == '\t' || *cp == '\\'; cp--)
291 while (*sp && (*sp == ' ' || *sp == '\t'))
293 for (sep = "", dp = line; dp && *dp; dp = cp, sep = "\n") {
294 cp = strchr(dp, ',');
298 for (tp = cp - 1; *tp == ' ' || *tp == '\t'; tp--)
301 for (++cp; *cp == ' ' || *cp == '\t'; cp++)
304 printf("%s%s\t", sep, dp);
311 dorefname(char *name)
313 char *dp = name, *ep;
316 while (*dp && *dp != '.')
319 for (ep = dp+1; *ep; ep++)
334 (void)fprintf(stderr, "usage: getNAME [-itw] file ...\n");