Annotation of src/usr.bin/man/man.c, Revision 1.3
1.3 ! michaels 1: /* $OpenBSD: man.c,v 1.2 1996/06/26 05:37:01 deraadt Exp $ */
1.1 deraadt 2: /* $NetBSD: man.c,v 1.7 1995/09/28 06:05:34 tls Exp $ */
3:
4: /*
5: * Copyright (c) 1987, 1993, 1994, 1995
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.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
37: #ifndef lint
38: static char copyright[] =
39: "@(#) Copyright (c) 1987, 1993, 1994, 1995\n\
40: The Regents of the University of California. All rights reserved.\n";
41: #endif /* not lint */
42:
43: #ifndef lint
44: #if 0
45: static char sccsid[] = "@(#)man.c 8.17 (Berkeley) 1/31/95";
46: #else
1.3 ! michaels 47: static char rcsid[] = "$OpenBSD: man.c,v 1.2 1996/06/26 05:37:01 deraadt Exp $";
1.1 deraadt 48: #endif
49: #endif /* not lint */
50:
51: #include <sys/param.h>
52: #include <sys/queue.h>
53:
54: #include <ctype.h>
55: #include <err.h>
56: #include <errno.h>
57: #include <fcntl.h>
58: #include <fnmatch.h>
59: #include <glob.h>
60: #include <signal.h>
61: #include <stdio.h>
62: #include <stdlib.h>
63: #include <string.h>
64: #include <unistd.h>
65:
66: #include "config.h"
67: #include "pathnames.h"
68:
69: int f_all, f_where;
70:
71: static void build_page __P((char *, char **));
72: static void cat __P((char *));
73: static char *check_pager __P((char *));
74: static int cleanup __P((void));
75: static void how __P((char *));
76: static void jump __P((char **, char *, char *));
77: static int manual __P((char *, TAG *, glob_t *));
78: static void onsig __P((int));
79: static void usage __P((void));
80:
81: int
82: main(argc, argv)
83: int argc;
84: char *argv[];
85: {
86: extern char *optarg;
87: extern int optind;
88: TAG *defp, *defnewp, *section, *sectnewp, *subp;
89: ENTRY *e_defp, *e_sectp, *e_subp, *ep;
90: glob_t pg;
91: size_t len;
92: int ch, f_cat, f_how, found;
93: char **ap, *cmd, *machine, *p, *p_add, *p_path, *pager, *slashp;
94: char *conffile, buf[MAXPATHLEN * 2];
95:
96: f_cat = f_how = 0;
97: conffile = p_add = p_path = NULL;
98: while ((ch = getopt(argc, argv, "-aC:cfhkM:m:P:w")) != EOF)
99: switch (ch) {
100: case 'a':
101: f_all = 1;
102: break;
103: case 'C':
104: conffile = optarg;
105: break;
106: case 'c':
107: case '-': /* Deprecated. */
108: f_cat = 1;
109: break;
110: case 'h':
111: f_how = 1;
112: break;
113: case 'm':
114: p_add = optarg;
115: break;
116: case 'M':
117: case 'P': /* Backward compatibility. */
118: p_path = optarg;
119: break;
120: /*
121: * The -f and -k options are backward compatible,
122: * undocumented ways of calling whatis(1) and apropos(1).
123: */
124: case 'f':
125: jump(argv, "-f", "whatis");
126: /* NOTREACHED */
127: case 'k':
128: jump(argv, "-k", "apropos");
129: /* NOTREACHED */
130: case 'w':
131: f_all = f_where = 1;
132: break;
133: case '?':
134: default:
135: usage();
136: }
137: argc -= optind;
138: argv += optind;
139:
140: if (!*argv)
141: usage();
142:
143: if (!f_cat && !f_how && !f_where)
144: if (!isatty(1))
145: f_cat = 1;
146: else if ((pager = getenv("PAGER")) != NULL)
147: pager = check_pager(pager);
148: else
149: pager = _PATH_PAGER;
150:
151: /* Read the configuration file. */
152: config(conffile);
153:
154: /* Get the machine type. */
155: if ((machine = getenv("MACHINE")) == NULL)
156: machine = MACHINE;
157:
158: /* If there's no _default list, create an empty one. */
159: if ((defp = getlist("_default")) == NULL)
160: defp = addlist("_default");
161:
162: /*
163: * 1: If the user specified a MANPATH variable, or set the -M
164: * option, we replace the _default list with the user's list,
165: * appending the entries in the _subdir list and the machine.
166: */
167: if (p_path == NULL)
168: p_path = getenv("MANPATH");
169: if (p_path != NULL) {
170: while ((e_defp = defp->list.tqh_first) != NULL) {
171: free(e_defp->s);
172: TAILQ_REMOVE(&defp->list, e_defp, q);
173: }
174: for (p = strtok(p_path, ":");
175: p != NULL; p = strtok(NULL, ":")) {
176: slashp = p[strlen(p) - 1] == '/' ? "" : "/";
177: e_subp = (subp = getlist("_subdir")) == NULL ?
178: NULL : subp->list.tqh_first;
179: for (; e_subp != NULL; e_subp = e_subp->q.tqe_next) {
180: (void)snprintf(buf, sizeof(buf), "%s%s%s{/%s,}",
181: p, slashp, e_subp->s, machine);
182: if ((ep = malloc(sizeof(ENTRY))) == NULL ||
183: (ep->s = strdup(buf)) == NULL)
184: err(1, NULL);
185: TAILQ_INSERT_TAIL(&defp->list, ep, q);
186: }
187: }
188: }
189:
190: /*
191: * 2: If the user did not specify MANPATH, -M or a section, rewrite
192: * the _default list to include the _subdir list and the machine.
193: */
194: if (argv[1] == NULL)
195: section = NULL;
196: else if ((section = getlist(*argv)) != NULL)
197: ++argv;
198: if (p_path == NULL && section == NULL) {
199: defnewp = addlist("_default_new");
200: e_defp =
201: defp->list.tqh_first == NULL ? NULL : defp->list.tqh_first;
202: for (; e_defp != NULL; e_defp = e_defp->q.tqe_next) {
203: slashp =
204: e_defp->s[strlen(e_defp->s) - 1] == '/' ? "" : "/";
205: e_subp = (subp = getlist("_subdir")) == NULL ?
206: NULL : subp->list.tqh_first;
207: for (; e_subp != NULL; e_subp = e_subp->q.tqe_next) {
208: (void)snprintf(buf, sizeof(buf), "%s%s%s{/%s,}",
209: e_defp->s, slashp, e_subp->s, machine);
210: if ((ep = malloc(sizeof(ENTRY))) == NULL ||
211: (ep->s = strdup(buf)) == NULL)
212: err(1, NULL);
213: TAILQ_INSERT_TAIL(&defnewp->list, ep, q);
214: }
215: }
216: defp = getlist("_default");
217: while ((e_defp = defp->list.tqh_first) != NULL) {
218: free(e_defp->s);
219: TAILQ_REMOVE(&defp->list, e_defp, q);
220: }
221: free(defp->s);
222: TAILQ_REMOVE(&head, defp, q);
223: defnewp = getlist("_default_new");
224: free(defnewp->s);
225: defnewp->s = "_default";
226: defp = defnewp;
227: }
228:
229: /*
230: * 3: If the user set the -m option, insert the user's list before
231: * whatever list we have, again appending the _subdir list and
1.3 ! michaels 232: * the machine.
1.1 deraadt 233: */
1.3 ! michaels 234: if (p_add != NULL) {
! 235: e_sectp = NULL;
1.1 deraadt 236: for (p = strtok(p_add, ":"); p != NULL; p = strtok(NULL, ":")) {
237: slashp = p[strlen(p) - 1] == '/' ? "" : "/";
238: e_subp = (subp = getlist("_subdir")) == NULL ?
239: NULL : subp->list.tqh_first;
240: for (; e_subp != NULL; e_subp = e_subp->q.tqe_next) {
241: (void)snprintf(buf, sizeof(buf), "%s%s%s{/%s,}",
242: p, slashp, e_subp->s, machine);
243: if ((ep = malloc(sizeof(ENTRY))) == NULL ||
244: (ep->s = strdup(buf)) == NULL)
245: err(1, NULL);
1.3 ! michaels 246: /* puts it at the end, should be at the top, but then the added
! 247: entries would be in reverse order, fix later when all are added*/
! 248: TAILQ_INSERT_TAIL(&defp->list, ep, q);
! 249: if (e_sectp == NULL) /* save first added, to-be the new top */
! 250: e_sectp = ep;
1.1 deraadt 251: }
252: }
1.3 ! michaels 253: if (e_sectp != NULL) { /* entries added, fix order */
! 254: ep->q.tqe_next = defp->list.tqh_first; /* save original head */
! 255: defp->list.tqh_first = e_sectp; /* first added entry, new top */
! 256: *e_sectp->q.tqe_prev = NULL; /* terminate list */
! 257: }
! 258: }
1.1 deraadt 259: /*
260: * 4: If no -m was specified, and a section was, rewrite the section's
261: * paths (if they have a trailing slash) to append the _subdir list
262: * and the machine. This then becomes the _default list.
263: */
264: if (p_add == NULL && section != NULL) {
265: sectnewp = addlist("_section_new");
266: for (e_sectp = section->list.tqh_first;
267: e_sectp != NULL; e_sectp = e_sectp->q.tqe_next) {
268: if (e_sectp->s[strlen(e_sectp->s) - 1] != '/') {
269: (void)snprintf(buf, sizeof(buf),
270: "%s{/%s,}", e_sectp->s, machine);
271: if ((ep = malloc(sizeof(ENTRY))) == NULL ||
272: (ep->s = strdup(buf)) == NULL)
273: err(1, NULL);
274: TAILQ_INSERT_TAIL(§newp->list, ep, q);
275: continue;
276: }
277: e_subp = (subp = getlist("_subdir")) == NULL ?
278: NULL : subp->list.tqh_first;
279: for (; e_subp != NULL; e_subp = e_subp->q.tqe_next) {
280: (void)snprintf(buf, sizeof(buf), "%s%s{/%s,}",
281: e_sectp->s, e_subp->s, machine);
282: if ((ep = malloc(sizeof(ENTRY))) == NULL ||
283: (ep->s = strdup(buf)) == NULL)
284: err(1, NULL);
285: TAILQ_INSERT_TAIL(§newp->list, ep, q);
286: }
287: }
288: sectnewp->s = section->s;
289: defp = sectnewp;
290: TAILQ_REMOVE(&head, section, q);
291: }
292:
293: /*
294: * 5: Search for the files. Set up an interrupt handler, so the
295: * temporary files go away.
296: */
297: (void)signal(SIGINT, onsig);
298: (void)signal(SIGHUP, onsig);
299:
300: memset(&pg, 0, sizeof(pg));
301: for (found = 0; *argv; ++argv)
302: if (manual(*argv, defp, &pg))
303: found = 1;
304:
305: /* 6: If nothing found, we're done. */
306: if (!found) {
307: (void)cleanup();
308: exit (1);
309: }
310:
311: /* 7: If it's simple, display it fast. */
312: if (f_cat) {
313: for (ap = pg.gl_pathv; *ap != NULL; ++ap) {
314: if (**ap == '\0')
315: continue;
316: cat(*ap);
317: }
318: exit (cleanup());
319: }
320: if (f_how) {
321: for (ap = pg.gl_pathv; *ap != NULL; ++ap) {
322: if (**ap == '\0')
323: continue;
324: how(*ap);
325: }
326: exit(cleanup());
327: }
328: if (f_where) {
329: for (ap = pg.gl_pathv; *ap != NULL; ++ap) {
330: if (**ap == '\0')
331: continue;
332: (void)printf("%s\n", *ap);
333: }
334: exit(cleanup());
335: }
336:
337: /*
338: * 8: We display things in a single command; build a list of things
339: * to display.
340: */
341: for (ap = pg.gl_pathv, len = strlen(pager) + 1; *ap != NULL; ++ap) {
342: if (**ap == '\0')
343: continue;
344: len += strlen(*ap) + 1;
345: }
346: if ((cmd = malloc(len)) == NULL) {
347: warn(NULL);
348: (void)cleanup();
349: exit(1);
350: }
351: p = cmd;
352: len = strlen(pager);
353: memmove(p, pager, len);
354: p += len;
355: *p++ = ' ';
356: for (ap = pg.gl_pathv; *ap != NULL; ++ap) {
357: if (**ap == '\0')
358: continue;
359: len = strlen(*ap);
360: memmove(p, *ap, len);
361: p += len;
362: *p++ = ' ';
363: }
364: *p = '\0';
365:
366: /* Use system(3) in case someone's pager is "pager arg1 arg2". */
367: (void)system(cmd);
368:
369: exit(cleanup());
370: }
371:
372: /*
373: * manual --
374: * Search the manuals for the pages.
375: */
376: static int
377: manual(page, tag, pg)
378: char *page;
379: TAG *tag;
380: glob_t *pg;
381: {
382: ENTRY *ep, *e_sufp, *e_tag;
383: TAG *missp, *sufp;
384: int anyfound, cnt, found;
385: char *p, buf[128];
386:
387: anyfound = 0;
388: buf[0] = '*';
389:
390: /* For each element in the list... */
391: e_tag = tag == NULL ? NULL : tag->list.tqh_first;
392: for (; e_tag != NULL; e_tag = e_tag->q.tqe_next) {
393: (void)snprintf(buf, sizeof(buf), "%s/%s.*", e_tag->s, page);
394: if (glob(buf,
395: GLOB_APPEND | GLOB_BRACE | GLOB_NOSORT | GLOB_QUOTE,
396: NULL, pg)) {
397: warn("globbing");
398: (void)cleanup();
399: exit(1);
400: }
401: if (pg->gl_matchc == 0)
402: continue;
403:
404: /* Find out if it's really a man page. */
405: for (cnt = pg->gl_pathc - pg->gl_matchc;
406: cnt < pg->gl_pathc; ++cnt) {
407:
408: /*
409: * Try the _suffix key words first.
410: *
411: * XXX
412: * Older versions of man.conf didn't have the suffix
413: * key words, it was assumed that everything was a .0.
414: * We just test for .0 first, it's fast and probably
415: * going to hit.
416: */
417: (void)snprintf(buf, sizeof(buf), "*/%s.0", page);
418: if (!fnmatch(buf, pg->gl_pathv[cnt], 0))
419: goto next;
420:
421: e_sufp = (sufp = getlist("_suffix")) == NULL ?
422: NULL : sufp->list.tqh_first;
423: for (found = 0;
424: e_sufp != NULL; e_sufp = e_sufp->q.tqe_next) {
425: (void)snprintf(buf,
426: sizeof(buf), "*/%s%s", page, e_sufp->s);
427: if (!fnmatch(buf, pg->gl_pathv[cnt], 0)) {
428: found = 1;
429: break;
430: }
431: }
432: if (found)
433: goto next;
434:
435: /* Try the _build key words next. */
436: e_sufp = (sufp = getlist("_build")) == NULL ?
437: NULL : sufp->list.tqh_first;
438: for (found = 0;
439: e_sufp != NULL; e_sufp = e_sufp->q.tqe_next) {
440: for (p = e_sufp->s;
441: *p != '\0' && !isspace(*p); ++p);
442: if (*p == '\0')
443: continue;
444: *p = '\0';
445: (void)snprintf(buf,
446: sizeof(buf), "*/%s%s", page, e_sufp->s);
447: if (!fnmatch(buf, pg->gl_pathv[cnt], 0)) {
448: if (!f_where)
449: build_page(p + 1,
450: &pg->gl_pathv[cnt]);
451: *p = ' ';
452: found = 1;
453: break;
454: }
455: *p = ' ';
456: }
457: if (found) {
458: next: anyfound = 1;
459: if (!f_all) {
460: /* Delete any other matches. */
461: while (++cnt< pg->gl_pathc)
462: pg->gl_pathv[cnt] = "";
463: break;
464: }
465: continue;
466: }
467:
468: /* It's not a man page, forget about it. */
469: pg->gl_pathv[cnt] = "";
470: }
471:
472: if (anyfound && !f_all)
473: break;
474: }
475:
476: /* If not found, enter onto the missing list. */
477: if (!anyfound) {
478: if ((missp = getlist("_missing")) == NULL)
479: missp = addlist("_missing");
480: if ((ep = malloc(sizeof(ENTRY))) == NULL ||
481: (ep->s = strdup(page)) == NULL) {
482: warn(NULL);
483: (void)cleanup();
484: exit(1);
485: }
486: TAILQ_INSERT_TAIL(&missp->list, ep, q);
487: }
488: return (anyfound);
489: }
490:
491: /*
492: * build_page --
493: * Build a man page for display.
494: */
495: static void
496: build_page(fmt, pathp)
497: char *fmt, **pathp;
498: {
499: static int warned;
500: ENTRY *ep;
501: TAG *intmpp;
502: int fd, n;
503: char *p, *b;
504: char buf[MAXPATHLEN], cmd[MAXPATHLEN], tpath[sizeof(_PATH_TMP)];
505:
506: /* Let the user know this may take awhile. */
507: if (!warned) {
508: warned = 1;
509: warnx("Formatting manual page...");
510: }
511:
512: /*
513: * Historically man chdir'd to the root of the man tree.
514: * This was used in man pages that contained relative ".so"
515: * directives (including other man pages for command aliases etc.)
516: * It even went one step farther, by examining the first line
517: * of the man page and parsing the .so filename so it would
518: * make hard(?) links to the cat'ted man pages for space savings.
519: * (We don't do that here, but we could).
520: */
521:
522: /* copy and find the end */
523: for (b = buf, p = *pathp; (*b++ = *p++) != '\0';)
524: continue;
525:
526: /* skip the last two path components, page name and man[n] */
527: for (--b, n = 2; b != buf; b--)
528: if (*b == '/')
529: if (--n == 0) {
530: *b = '\0';
531: (void) chdir(buf);
532: }
533:
534:
535: /* Add a remove-when-done list. */
536: if ((intmpp = getlist("_intmp")) == NULL)
537: intmpp = addlist("_intmp");
538:
539: /* Move to the printf(3) format string. */
540: for (; *fmt && isspace(*fmt); ++fmt);
541:
542: /*
543: * Get a temporary file and build a version of the file
544: * to display. Replace the old file name with the new one.
545: */
546: (void)strcpy(tpath, _PATH_TMP);
547: if ((fd = mkstemp(tpath)) == -1) {
548: warn("%s", tpath);
549: (void)cleanup();
550: exit(1);
551: }
552: (void)snprintf(buf, sizeof(buf), "%s > %s", fmt, tpath);
553: (void)snprintf(cmd, sizeof(cmd), buf, *pathp);
554: (void)system(cmd);
555: (void)close(fd);
556: if ((*pathp = strdup(tpath)) == NULL) {
557: warn(NULL);
558: (void)cleanup();
559: exit(1);
560: }
561:
562: /* Link the built file into the remove-when-done list. */
563: if ((ep = malloc(sizeof(ENTRY))) == NULL) {
564: warn(NULL);
565: (void)cleanup();
566: exit(1);
567: }
568: ep->s = *pathp;
569: TAILQ_INSERT_TAIL(&intmpp->list, ep, q);
570: }
571:
572: /*
573: * how --
574: * display how information
575: */
576: static void
577: how(fname)
578: char *fname;
579: {
580: FILE *fp;
581:
582: int lcnt, print;
583: char *p, buf[256];
584:
585: if (!(fp = fopen(fname, "r"))) {
586: warn("%s", fname);
587: (void)cleanup();
588: exit (1);
589: }
590: #define S1 "SYNOPSIS"
591: #define S2 "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS"
592: #define D1 "DESCRIPTION"
593: #define D2 "D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN"
594: for (lcnt = print = 0; fgets(buf, sizeof(buf), fp);) {
595: if (!strncmp(buf, S1, sizeof(S1) - 1) ||
596: !strncmp(buf, S2, sizeof(S2) - 1)) {
597: print = 1;
598: continue;
599: } else if (!strncmp(buf, D1, sizeof(D1) - 1) ||
600: !strncmp(buf, D2, sizeof(D2) - 1))
601: return;
602: if (!print)
603: continue;
604: if (*buf == '\n')
605: ++lcnt;
606: else {
607: for(; lcnt; --lcnt)
608: (void)putchar('\n');
609: for (p = buf; isspace(*p); ++p);
610: (void)fputs(p, stdout);
611: }
612: }
613: (void)fclose(fp);
614: }
615:
616: /*
617: * cat --
618: * cat out the file
619: */
620: static void
621: cat(fname)
622: char *fname;
623: {
624: int fd, n;
625: char buf[2048];
626:
627: if ((fd = open(fname, O_RDONLY, 0)) < 0) {
628: warn("%s", fname);
629: (void)cleanup();
630: exit(1);
631: }
632: while ((n = read(fd, buf, sizeof(buf))) > 0)
633: if (write(STDOUT_FILENO, buf, n) != n) {
634: warn("write");
635: (void)cleanup();
636: exit (1);
637: }
638: if (n == -1) {
639: warn("read");
640: (void)cleanup();
641: exit(1);
642: }
643: (void)close(fd);
644: }
645:
646: /*
647: * check_pager --
648: * check the user supplied page information
649: */
650: static char *
651: check_pager(name)
652: char *name;
653: {
654: char *p, *save;
655:
656: /*
657: * if the user uses "more", we make it "more -s"; watch out for
658: * PAGER = "mypager /usr/ucb/more"
659: */
660: for (p = name; *p && !isspace(*p); ++p);
661: for (; p > name && *p != '/'; --p);
662: if (p != name)
663: ++p;
664:
665: /* make sure it's "more", not "morex" */
666: if (!strncmp(p, "more", 4) && (!p[4] || isspace(p[4]))){
667: save = name;
668: /* allocate space to add the "-s" */
669: if (!(name =
670: malloc((u_int)(strlen(save) + sizeof("-s") + 1))))
671: err(1, NULL);
672: (void)sprintf(name, "%s %s", save, "-s");
673: }
674: return(name);
675: }
676:
677: /*
678: * jump --
679: * strip out flag argument and jump
680: */
681: static void
682: jump(argv, flag, name)
683: char **argv, *flag, *name;
684: {
685: char **arg;
686:
687: argv[0] = name;
688: for (arg = argv + 1; *arg; ++arg)
689: if (!strcmp(*arg, flag))
690: break;
691: for (; *arg; ++arg)
692: arg[0] = arg[1];
693: execvp(name, argv);
694: (void)fprintf(stderr, "%s: Command not found.\n", name);
695: exit(1);
696: }
697:
698: /*
699: * onsig --
700: * If signaled, delete the temporary files.
701: */
702: static void
703: onsig(signo)
704: int signo;
705: {
706: (void)cleanup();
707:
708: (void)signal(signo, SIG_DFL);
709: (void)kill(getpid(), signo);
710:
711: /* NOTREACHED */
712: exit (1);
713: }
714:
715: /*
716: * cleanup --
717: * Clean up temporary files, show any error messages.
718: */
719: static int
720: cleanup()
721: {
722: TAG *intmpp, *missp;
723: ENTRY *ep;
724: int rval;
725:
726: rval = 0;
727: ep = (missp = getlist("_missing")) == NULL ?
728: NULL : missp->list.tqh_first;
729: if (ep != NULL)
730: for (; ep != NULL; ep = ep->q.tqe_next) {
731: warnx("no entry for %s in the manual.", ep->s);
732: rval = 1;
733: }
734:
735: ep = (intmpp = getlist("_intmp")) == NULL ?
736: NULL : intmpp->list.tqh_first;
737: for (; ep != NULL; ep = ep->q.tqe_next)
738: (void)unlink(ep->s);
739: return (rval);
740: }
741:
742: /*
743: * usage --
744: * print usage message and die
745: */
746: static void
747: usage()
748: {
749: (void)fprintf(stderr,
750: "usage: man [-achw] [-C file] [-M path] [-m path] [section] title ...\n");
751: exit(1);
752: }