Annotation of src/usr.bin/mandoc/mandocdb.c, Revision 1.183
1.183 ! schwarze 1: /* $OpenBSD: mandocdb.c,v 1.182 2016/10/20 16:29:13 schwarze Exp $ */
1.1 schwarze 2: /*
1.47 schwarze 3: * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
1.164 schwarze 4: * Copyright (c) 2011-2016 Ingo Schwarze <schwarze@openbsd.org>
1.180 schwarze 5: * Copyright (c) 2016 Ed Maste <emaste@freebsd.org>
1.1 schwarze 6: *
7: * Permission to use, copy, modify, and distribute this software for any
8: * purpose with or without fee is hereby granted, provided that the above
9: * copyright notice and this permission notice appear in all copies.
10: *
1.140 schwarze 11: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.1 schwarze 12: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.140 schwarze 13: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.1 schwarze 14: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18: */
1.117 schwarze 19: #include <sys/types.h>
1.47 schwarze 20: #include <sys/stat.h>
1.72 schwarze 21: #include <sys/wait.h>
1.1 schwarze 22:
23: #include <assert.h>
1.33 schwarze 24: #include <ctype.h>
1.151 schwarze 25: #include <err.h>
1.34 schwarze 26: #include <errno.h>
1.1 schwarze 27: #include <fcntl.h>
1.47 schwarze 28: #include <fts.h>
1.44 schwarze 29: #include <limits.h>
1.173 schwarze 30: #include <stdarg.h>
1.47 schwarze 31: #include <stddef.h>
1.1 schwarze 32: #include <stdio.h>
33: #include <stdint.h>
34: #include <stdlib.h>
35: #include <string.h>
1.14 schwarze 36: #include <unistd.h>
1.1 schwarze 37:
1.141 schwarze 38: #include "mandoc_aux.h"
1.156 schwarze 39: #include "mandoc_ohash.h"
1.141 schwarze 40: #include "mandoc.h"
41: #include "roff.h"
1.47 schwarze 42: #include "mdoc.h"
1.1 schwarze 43: #include "man.h"
1.140 schwarze 44: #include "manconf.h"
1.47 schwarze 45: #include "mansearch.h"
1.173 schwarze 46: #include "dba_array.h"
47: #include "dba.h"
1.1 schwarze 48:
1.68 schwarze 49: extern const char *const mansearch_keynames[];
50:
1.47 schwarze 51: enum op {
52: OP_DEFAULT = 0, /* new dbs from dir list or default config */
53: OP_CONFFILE, /* new databases from custom config file */
54: OP_UPDATE, /* delete/add entries in existing database */
55: OP_DELETE, /* delete entries from existing database */
56: OP_TEST /* change no databases, report potential problems */
57: };
1.11 schwarze 58:
1.47 schwarze 59: struct str {
60: const struct mpage *mpage; /* if set, the owning parse */
61: uint64_t mask; /* bitmask in sequence */
1.131 schwarze 62: char key[]; /* rendered text */
1.28 schwarze 63: };
64:
1.47 schwarze 65: struct inodev {
66: ino_t st_ino;
67: dev_t st_dev;
68: };
1.28 schwarze 69:
1.47 schwarze 70: struct mpage {
71: struct inodev inodev; /* used for hashing routine */
1.173 schwarze 72: struct dba_array *dba;
1.47 schwarze 73: char *sec; /* section from file content */
74: char *arch; /* architecture from file content */
75: char *title; /* title from file content */
76: char *desc; /* description from file content */
1.180 schwarze 77: struct mpage *next; /* singly linked list */
1.47 schwarze 78: struct mlink *mlinks; /* singly linked list */
1.129 schwarze 79: int name_head_done;
1.173 schwarze 80: enum form form; /* format from file content */
1.28 schwarze 81: };
82:
1.47 schwarze 83: struct mlink {
84: char file[PATH_MAX]; /* filename rel. to manpath */
85: char *dsec; /* section from directory */
86: char *arch; /* architecture from directory */
87: char *name; /* name from file name (not empty) */
88: char *fsec; /* section from file name suffix */
89: struct mlink *next; /* singly linked list */
1.75 schwarze 90: struct mpage *mpage; /* parent */
1.81 schwarze 91: int gzip; /* filename has a .gz suffix */
1.173 schwarze 92: enum form dform; /* format from directory */
93: enum form fform; /* format from file name suffix */
1.1 schwarze 94: };
95:
1.143 schwarze 96: typedef int (*mdoc_fp)(struct mpage *, const struct roff_meta *,
1.142 schwarze 97: const struct roff_node *);
1.1 schwarze 98:
1.19 schwarze 99: struct mdoc_handler {
1.47 schwarze 100: mdoc_fp fp; /* optional handler */
101: uint64_t mask; /* set unless handler returns 0 */
1.19 schwarze 102: };
1.171 schwarze 103:
104:
105: int mandocdb(int, char *[]);
1.19 schwarze 106:
1.173 schwarze 107: static void dbadd(struct dba *, struct mpage *);
1.75 schwarze 108: static void dbadd_mlink(const struct mlink *mlink);
1.173 schwarze 109: static void dbprune(struct dba *);
110: static void dbwrite(struct dba *);
1.47 schwarze 111: static void filescan(const char *);
1.180 schwarze 112: static int fts_compare(const FTSENT **, const FTSENT **);
1.47 schwarze 113: static void mlink_add(struct mlink *, const struct stat *);
1.88 schwarze 114: static void mlink_check(struct mpage *, struct mlink *);
1.47 schwarze 115: static void mlink_free(struct mlink *);
116: static void mlinks_undupe(struct mpage *);
117: static void mpages_free(void);
1.173 schwarze 118: static void mpages_merge(struct dba *, struct mparse *);
1.81 schwarze 119: static void parse_cat(struct mpage *, int);
1.143 schwarze 120: static void parse_man(struct mpage *, const struct roff_meta *,
1.142 schwarze 121: const struct roff_node *);
1.143 schwarze 122: static void parse_mdoc(struct mpage *, const struct roff_meta *,
1.142 schwarze 123: const struct roff_node *);
1.143 schwarze 124: static int parse_mdoc_head(struct mpage *, const struct roff_meta *,
1.142 schwarze 125: const struct roff_node *);
1.143 schwarze 126: static int parse_mdoc_Fd(struct mpage *, const struct roff_meta *,
1.142 schwarze 127: const struct roff_node *);
128: static void parse_mdoc_fname(struct mpage *, const struct roff_node *);
1.143 schwarze 129: static int parse_mdoc_Fn(struct mpage *, const struct roff_meta *,
1.142 schwarze 130: const struct roff_node *);
1.143 schwarze 131: static int parse_mdoc_Fo(struct mpage *, const struct roff_meta *,
1.142 schwarze 132: const struct roff_node *);
1.143 schwarze 133: static int parse_mdoc_Nd(struct mpage *, const struct roff_meta *,
1.142 schwarze 134: const struct roff_node *);
1.143 schwarze 135: static int parse_mdoc_Nm(struct mpage *, const struct roff_meta *,
1.142 schwarze 136: const struct roff_node *);
1.143 schwarze 137: static int parse_mdoc_Sh(struct mpage *, const struct roff_meta *,
1.142 schwarze 138: const struct roff_node *);
1.164 schwarze 139: static int parse_mdoc_Va(struct mpage *, const struct roff_meta *,
140: const struct roff_node *);
1.143 schwarze 141: static int parse_mdoc_Xr(struct mpage *, const struct roff_meta *,
1.142 schwarze 142: const struct roff_node *);
1.69 schwarze 143: static void putkey(const struct mpage *, char *, uint64_t);
1.131 schwarze 144: static void putkeys(const struct mpage *, char *, size_t, uint64_t);
1.47 schwarze 145: static void putmdockey(const struct mpage *,
1.142 schwarze 146: const struct roff_node *, uint64_t);
1.131 schwarze 147: static int render_string(char **, size_t *);
1.172 schwarze 148: static void say(const char *, const char *, ...)
149: __attribute__((__format__ (printf, 2, 3)));
1.120 schwarze 150: static int set_basedir(const char *, int);
1.47 schwarze 151: static int treescan(void);
152: static size_t utf8(unsigned int, char [7]);
153:
1.59 schwarze 154: static int nodb; /* no database changes */
1.73 schwarze 155: static int mparse_options; /* abort the parse early */
1.98 schwarze 156: static int use_all; /* use all found files */
157: static int debug; /* print what we're doing */
158: static int warnings; /* warn about crap */
1.52 schwarze 159: static int write_utf8; /* write UTF-8 output; else ASCII */
1.47 schwarze 160: static int exitcode; /* to be returned by main */
1.98 schwarze 161: static enum op op; /* operational mode */
1.47 schwarze 162: static char basedir[PATH_MAX]; /* current base directory */
1.180 schwarze 163: static struct mpage *mpage_head; /* list of distinct manual pages */
1.47 schwarze 164: static struct ohash mpages; /* table of distinct manual pages */
165: static struct ohash mlinks; /* table of directory entries */
1.90 schwarze 166: static struct ohash names; /* table of all names */
1.47 schwarze 167: static struct ohash strings; /* table of all strings */
1.90 schwarze 168: static uint64_t name_mask;
1.47 schwarze 169:
1.19 schwarze 170: static const struct mdoc_handler mdocs[MDOC_MAX] = {
1.47 schwarze 171: { NULL, 0 }, /* Ap */
172: { NULL, 0 }, /* Dd */
173: { NULL, 0 }, /* Dt */
174: { NULL, 0 }, /* Os */
175: { parse_mdoc_Sh, TYPE_Sh }, /* Sh */
176: { parse_mdoc_head, TYPE_Ss }, /* Ss */
177: { NULL, 0 }, /* Pp */
178: { NULL, 0 }, /* D1 */
179: { NULL, 0 }, /* Dl */
180: { NULL, 0 }, /* Bd */
181: { NULL, 0 }, /* Ed */
182: { NULL, 0 }, /* Bl */
183: { NULL, 0 }, /* El */
184: { NULL, 0 }, /* It */
185: { NULL, 0 }, /* Ad */
186: { NULL, TYPE_An }, /* An */
187: { NULL, TYPE_Ar }, /* Ar */
188: { NULL, TYPE_Cd }, /* Cd */
189: { NULL, TYPE_Cm }, /* Cm */
190: { NULL, TYPE_Dv }, /* Dv */
191: { NULL, TYPE_Er }, /* Er */
192: { NULL, TYPE_Ev }, /* Ev */
193: { NULL, 0 }, /* Ex */
194: { NULL, TYPE_Fa }, /* Fa */
195: { parse_mdoc_Fd, 0 }, /* Fd */
196: { NULL, TYPE_Fl }, /* Fl */
197: { parse_mdoc_Fn, 0 }, /* Fn */
198: { NULL, TYPE_Ft }, /* Ft */
199: { NULL, TYPE_Ic }, /* Ic */
1.49 schwarze 200: { NULL, TYPE_In }, /* In */
1.47 schwarze 201: { NULL, TYPE_Li }, /* Li */
1.89 schwarze 202: { parse_mdoc_Nd, 0 }, /* Nd */
1.86 schwarze 203: { parse_mdoc_Nm, 0 }, /* Nm */
1.47 schwarze 204: { NULL, 0 }, /* Op */
205: { NULL, 0 }, /* Ot */
206: { NULL, TYPE_Pa }, /* Pa */
207: { NULL, 0 }, /* Rv */
1.49 schwarze 208: { NULL, TYPE_St }, /* St */
1.164 schwarze 209: { parse_mdoc_Va, TYPE_Va }, /* Va */
210: { parse_mdoc_Va, TYPE_Vt }, /* Vt */
1.47 schwarze 211: { parse_mdoc_Xr, 0 }, /* Xr */
212: { NULL, 0 }, /* %A */
213: { NULL, 0 }, /* %B */
214: { NULL, 0 }, /* %D */
215: { NULL, 0 }, /* %I */
216: { NULL, 0 }, /* %J */
217: { NULL, 0 }, /* %N */
218: { NULL, 0 }, /* %O */
219: { NULL, 0 }, /* %P */
220: { NULL, 0 }, /* %R */
221: { NULL, 0 }, /* %T */
222: { NULL, 0 }, /* %V */
223: { NULL, 0 }, /* Ac */
224: { NULL, 0 }, /* Ao */
225: { NULL, 0 }, /* Aq */
226: { NULL, TYPE_At }, /* At */
227: { NULL, 0 }, /* Bc */
228: { NULL, 0 }, /* Bf */
229: { NULL, 0 }, /* Bo */
230: { NULL, 0 }, /* Bq */
231: { NULL, TYPE_Bsx }, /* Bsx */
232: { NULL, TYPE_Bx }, /* Bx */
233: { NULL, 0 }, /* Db */
234: { NULL, 0 }, /* Dc */
235: { NULL, 0 }, /* Do */
236: { NULL, 0 }, /* Dq */
237: { NULL, 0 }, /* Ec */
238: { NULL, 0 }, /* Ef */
239: { NULL, TYPE_Em }, /* Em */
240: { NULL, 0 }, /* Eo */
241: { NULL, TYPE_Fx }, /* Fx */
242: { NULL, TYPE_Ms }, /* Ms */
243: { NULL, 0 }, /* No */
244: { NULL, 0 }, /* Ns */
245: { NULL, TYPE_Nx }, /* Nx */
246: { NULL, TYPE_Ox }, /* Ox */
247: { NULL, 0 }, /* Pc */
248: { NULL, 0 }, /* Pf */
249: { NULL, 0 }, /* Po */
250: { NULL, 0 }, /* Pq */
251: { NULL, 0 }, /* Qc */
252: { NULL, 0 }, /* Ql */
253: { NULL, 0 }, /* Qo */
254: { NULL, 0 }, /* Qq */
255: { NULL, 0 }, /* Re */
256: { NULL, 0 }, /* Rs */
257: { NULL, 0 }, /* Sc */
258: { NULL, 0 }, /* So */
259: { NULL, 0 }, /* Sq */
260: { NULL, 0 }, /* Sm */
261: { NULL, 0 }, /* Sx */
262: { NULL, TYPE_Sy }, /* Sy */
263: { NULL, TYPE_Tn }, /* Tn */
264: { NULL, 0 }, /* Ux */
265: { NULL, 0 }, /* Xc */
266: { NULL, 0 }, /* Xo */
1.128 schwarze 267: { parse_mdoc_Fo, 0 }, /* Fo */
1.47 schwarze 268: { NULL, 0 }, /* Fc */
269: { NULL, 0 }, /* Oo */
270: { NULL, 0 }, /* Oc */
271: { NULL, 0 }, /* Bk */
272: { NULL, 0 }, /* Ek */
273: { NULL, 0 }, /* Bt */
274: { NULL, 0 }, /* Hf */
275: { NULL, 0 }, /* Fr */
276: { NULL, 0 }, /* Ud */
277: { NULL, TYPE_Lb }, /* Lb */
278: { NULL, 0 }, /* Lp */
279: { NULL, TYPE_Lk }, /* Lk */
280: { NULL, TYPE_Mt }, /* Mt */
281: { NULL, 0 }, /* Brq */
282: { NULL, 0 }, /* Bro */
283: { NULL, 0 }, /* Brc */
284: { NULL, 0 }, /* %C */
285: { NULL, 0 }, /* Es */
286: { NULL, 0 }, /* En */
287: { NULL, TYPE_Dx }, /* Dx */
288: { NULL, 0 }, /* %Q */
289: { NULL, 0 }, /* br */
290: { NULL, 0 }, /* sp */
291: { NULL, 0 }, /* %U */
292: { NULL, 0 }, /* Ta */
1.121 schwarze 293: { NULL, 0 }, /* ll */
1.1 schwarze 294: };
295:
1.98 schwarze 296:
1.1 schwarze 297: int
1.3 schwarze 298: mandocdb(int argc, char *argv[])
1.1 schwarze 299: {
1.140 schwarze 300: struct manconf conf;
301: struct mparse *mp;
1.173 schwarze 302: struct dba *dba;
1.161 schwarze 303: const char *path_arg, *progname;
1.140 schwarze 304: size_t j, sz;
1.47 schwarze 305: int ch, i;
306:
1.158 millert 307: if (pledge("stdio rpath wpath cpath fattr flock proc exec", NULL) == -1) {
1.167 schwarze 308: warn("pledge");
1.155 schwarze 309: return (int)MANDOCLEVEL_SYSERR;
310: }
311:
1.140 schwarze 312: memset(&conf, 0, sizeof(conf));
1.47 schwarze 313:
314: /*
1.98 schwarze 315: * We accept a few different invocations.
1.47 schwarze 316: * The CHECKOP macro makes sure that invocation styles don't
317: * clobber each other.
318: */
319: #define CHECKOP(_op, _ch) do \
320: if (OP_DEFAULT != (_op)) { \
1.151 schwarze 321: warnx("-%c: Conflicting option", (_ch)); \
1.47 schwarze 322: goto usage; \
323: } while (/*CONSTCOND*/0)
1.10 schwarze 324:
1.47 schwarze 325: path_arg = NULL;
1.28 schwarze 326: op = OP_DEFAULT;
1.1 schwarze 327:
1.83 schwarze 328: while (-1 != (ch = getopt(argc, argv, "aC:Dd:npQT:tu:v")))
1.1 schwarze 329: switch (ch) {
1.98 schwarze 330: case 'a':
1.6 schwarze 331: use_all = 1;
332: break;
1.98 schwarze 333: case 'C':
1.47 schwarze 334: CHECKOP(op, ch);
335: path_arg = optarg;
1.28 schwarze 336: op = OP_CONFFILE;
1.25 schwarze 337: break;
1.98 schwarze 338: case 'D':
1.82 schwarze 339: debug++;
340: break;
1.98 schwarze 341: case 'd':
1.47 schwarze 342: CHECKOP(op, ch);
343: path_arg = optarg;
1.2 schwarze 344: op = OP_UPDATE;
1.1 schwarze 345: break;
1.98 schwarze 346: case 'n':
1.47 schwarze 347: nodb = 1;
348: break;
1.98 schwarze 349: case 'p':
1.83 schwarze 350: warnings = 1;
351: break;
1.98 schwarze 352: case 'Q':
1.73 schwarze 353: mparse_options |= MPARSE_QUICK;
1.59 schwarze 354: break;
1.98 schwarze 355: case 'T':
1.52 schwarze 356: if (strcmp(optarg, "utf8")) {
1.151 schwarze 357: warnx("-T%s: Unsupported output format",
358: optarg);
1.52 schwarze 359: goto usage;
360: }
361: write_utf8 = 1;
362: break;
1.98 schwarze 363: case 't':
1.47 schwarze 364: CHECKOP(op, ch);
1.28 schwarze 365: dup2(STDOUT_FILENO, STDERR_FILENO);
366: op = OP_TEST;
1.47 schwarze 367: nodb = warnings = 1;
1.28 schwarze 368: break;
1.98 schwarze 369: case 'u':
1.47 schwarze 370: CHECKOP(op, ch);
371: path_arg = optarg;
1.1 schwarze 372: op = OP_DELETE;
373: break;
1.98 schwarze 374: case 'v':
1.83 schwarze 375: /* Compatibility with espie@'s makewhatis. */
1.28 schwarze 376: break;
1.1 schwarze 377: default:
1.28 schwarze 378: goto usage;
1.1 schwarze 379: }
380:
381: argc -= optind;
382: argv += optind;
383:
1.163 schwarze 384: if (nodb) {
385: if (pledge("stdio rpath", NULL) == -1) {
1.167 schwarze 386: warn("pledge");
1.163 schwarze 387: return (int)MANDOCLEVEL_SYSERR;
388: }
1.155 schwarze 389: }
390:
1.28 schwarze 391: if (OP_CONFFILE == op && argc > 0) {
1.151 schwarze 392: warnx("-C: Too many arguments");
1.28 schwarze 393: goto usage;
394: }
395:
1.47 schwarze 396: exitcode = (int)MANDOCLEVEL_OK;
1.157 schwarze 397: mchars_alloc();
398: mp = mparse_alloc(mparse_options, MANDOCLEVEL_BADARG, NULL, NULL);
1.156 schwarze 399: mandoc_ohash_init(&mpages, 6, offsetof(struct mpage, inodev));
400: mandoc_ohash_init(&mlinks, 6, offsetof(struct mlink, file));
1.2 schwarze 401:
1.47 schwarze 402: if (OP_UPDATE == op || OP_DELETE == op || OP_TEST == op) {
1.2 schwarze 403:
1.47 schwarze 404: /*
1.109 schwarze 405: * Most of these deal with a specific directory.
1.97 schwarze 406: * Jump into that directory first.
1.47 schwarze 407: */
1.120 schwarze 408: if (OP_TEST != op && 0 == set_basedir(path_arg, 1))
1.47 schwarze 409: goto out;
1.97 schwarze 410:
1.174 schwarze 411: dba = nodb ? dba_new(128) : dba_read(MANDOC_DB);
412: if (dba != NULL) {
1.97 schwarze 413: /*
414: * The existing database is usable. Process
415: * all files specified on the command-line.
416: */
1.163 schwarze 417: if (!nodb) {
418: if (pledge("stdio rpath wpath cpath fattr flock", NULL) == -1) {
1.167 schwarze 419: warn("pledge");
1.163 schwarze 420: exitcode = (int)MANDOCLEVEL_SYSERR;
421: goto out;
422: }
1.155 schwarze 423: }
1.97 schwarze 424: use_all = 1;
1.95 schwarze 425: for (i = 0; i < argc; i++)
426: filescan(argv[i]);
1.174 schwarze 427: if (nodb == 0)
1.173 schwarze 428: dbprune(dba);
1.95 schwarze 429: } else {
1.177 schwarze 430: /* Database missing or corrupt. */
1.179 schwarze 431: if (op != OP_UPDATE || errno != ENOENT)
432: say(MANDOC_DB, "%s: Automatically recreating"
433: " from scratch", strerror(errno));
1.97 schwarze 434: exitcode = (int)MANDOCLEVEL_OK;
1.95 schwarze 435: op = OP_DEFAULT;
436: if (0 == treescan())
437: goto out;
1.173 schwarze 438: dba = dba_new(128);
1.95 schwarze 439: }
1.47 schwarze 440: if (OP_DELETE != op)
1.173 schwarze 441: mpages_merge(dba, mp);
442: if (nodb == 0)
443: dbwrite(dba);
444: dba_free(dba);
1.47 schwarze 445: } else {
446: /*
447: * If we have arguments, use them as our manpaths.
1.181 schwarze 448: * If we don't, use man.conf(5).
1.47 schwarze 449: */
450: if (argc > 0) {
1.140 schwarze 451: conf.manpath.paths = mandoc_reallocarray(NULL,
1.101 schwarze 452: argc, sizeof(char *));
1.140 schwarze 453: conf.manpath.sz = (size_t)argc;
1.47 schwarze 454: for (i = 0; i < argc; i++)
1.140 schwarze 455: conf.manpath.paths[i] = mandoc_strdup(argv[i]);
1.47 schwarze 456: } else
1.140 schwarze 457: manconf_parse(&conf, path_arg, NULL, NULL);
1.84 schwarze 458:
1.140 schwarze 459: if (conf.manpath.sz == 0) {
1.84 schwarze 460: exitcode = (int)MANDOCLEVEL_BADARG;
461: say("", "Empty manpath");
462: }
1.2 schwarze 463:
1.47 schwarze 464: /*
465: * First scan the tree rooted at a base directory, then
466: * build a new database and finally move it into place.
467: * Ignore zero-length directories and strip trailing
468: * slashes.
469: */
1.140 schwarze 470: for (j = 0; j < conf.manpath.sz; j++) {
471: sz = strlen(conf.manpath.paths[j]);
472: if (sz && conf.manpath.paths[j][sz - 1] == '/')
473: conf.manpath.paths[j][--sz] = '\0';
1.47 schwarze 474: if (0 == sz)
475: continue;
1.2 schwarze 476:
1.47 schwarze 477: if (j) {
1.156 schwarze 478: mandoc_ohash_init(&mpages, 6,
479: offsetof(struct mpage, inodev));
480: mandoc_ohash_init(&mlinks, 6,
481: offsetof(struct mlink, file));
1.47 schwarze 482: }
1.1 schwarze 483:
1.140 schwarze 484: if ( ! set_basedir(conf.manpath.paths[j], argc > 0))
1.120 schwarze 485: continue;
1.47 schwarze 486: if (0 == treescan())
1.120 schwarze 487: continue;
1.173 schwarze 488: dba = dba_new(128);
489: mpages_merge(dba, mp);
490: if (nodb == 0)
491: dbwrite(dba);
492: dba_free(dba);
1.28 schwarze 493:
1.140 schwarze 494: if (j + 1 < conf.manpath.sz) {
1.47 schwarze 495: mpages_free();
496: ohash_delete(&mpages);
497: ohash_delete(&mlinks);
498: }
1.2 schwarze 499: }
1.47 schwarze 500: }
501: out:
1.140 schwarze 502: manconf_free(&conf);
1.123 schwarze 503: mparse_free(mp);
1.157 schwarze 504: mchars_free();
1.47 schwarze 505: mpages_free();
506: ohash_delete(&mpages);
507: ohash_delete(&mlinks);
1.150 schwarze 508: return exitcode;
1.47 schwarze 509: usage:
1.161 schwarze 510: progname = getprogname();
1.83 schwarze 511: fprintf(stderr, "usage: %s [-aDnpQ] [-C file] [-Tutf8]\n"
512: " %s [-aDnpQ] [-Tutf8] dir ...\n"
513: " %s [-DnpQ] [-Tutf8] -d dir [file ...]\n"
514: " %s [-Dnp] -u dir [file ...]\n"
1.59 schwarze 515: " %s [-Q] -t file ...\n",
1.161 schwarze 516: progname, progname, progname, progname, progname);
1.1 schwarze 517:
1.150 schwarze 518: return (int)MANDOCLEVEL_BADARG;
1.47 schwarze 519: }
1.1 schwarze 520:
1.47 schwarze 521: /*
1.180 schwarze 522: * To get a singly linked list in alpha order while inserting entries
523: * at the beginning, process directory entries in reverse alpha order.
524: */
525: static int
526: fts_compare(const FTSENT **a, const FTSENT **b)
527: {
528: return -strcmp((*a)->fts_name, (*b)->fts_name);
529: }
530:
531: /*
1.47 schwarze 532: * Scan a directory tree rooted at "basedir" for manpages.
533: * We use fts(), scanning directory parts along the way for clues to our
534: * section and architecture.
535: *
536: * If use_all has been specified, grok all files.
537: * If not, sanitise paths to the following:
538: *
1.98 schwarze 539: * [./]man*[/<arch>]/<name>.<section>
1.47 schwarze 540: * or
541: * [./]cat<section>[/<arch>]/<name>.0
542: *
1.169 krw 543: * TODO: accommodate for multi-language directories.
1.47 schwarze 544: */
545: static int
546: treescan(void)
547: {
1.96 schwarze 548: char buf[PATH_MAX];
1.47 schwarze 549: FTS *f;
550: FTSENT *ff;
551: struct mlink *mlink;
1.173 schwarze 552: int gzip;
553: enum form dform;
1.51 schwarze 554: char *dsec, *arch, *fsec, *cp;
555: const char *path;
1.47 schwarze 556: const char *argv[2];
1.1 schwarze 557:
1.47 schwarze 558: argv[0] = ".";
559: argv[1] = (char *)NULL;
1.1 schwarze 560:
1.180 schwarze 561: f = fts_open((char * const *)argv, FTS_PHYSICAL | FTS_NOCHDIR,
562: fts_compare);
1.153 schwarze 563: if (f == NULL) {
1.47 schwarze 564: exitcode = (int)MANDOCLEVEL_SYSERR;
1.80 schwarze 565: say("", "&fts_open");
1.150 schwarze 566: return 0;
1.47 schwarze 567: }
1.2 schwarze 568:
1.47 schwarze 569: dsec = arch = NULL;
570: dform = FORM_NONE;
1.2 schwarze 571:
1.153 schwarze 572: while ((ff = fts_read(f)) != NULL) {
1.47 schwarze 573: path = ff->fts_path + 2;
1.96 schwarze 574: switch (ff->fts_info) {
575:
576: /*
577: * Symbolic links require various sanity checks,
578: * then get handled just like regular files.
579: */
1.98 schwarze 580: case FTS_SL:
1.153 schwarze 581: if (realpath(path, buf) == NULL) {
1.96 schwarze 582: if (warnings)
583: say(path, "&realpath");
584: continue;
585: }
586: if (strstr(buf, basedir) != buf) {
587: if (warnings) say("",
588: "%s: outside base directory", buf);
589: continue;
590: }
591: /* Use logical inode to avoid mpages dupe. */
1.153 schwarze 592: if (stat(path, ff->fts_statp) == -1) {
1.96 schwarze 593: if (warnings)
594: say(path, "&stat");
595: continue;
596: }
597: /* FALLTHROUGH */
598:
1.15 schwarze 599: /*
1.47 schwarze 600: * If we're a regular file, add an mlink by using the
601: * stored directory data and handling the filename.
1.15 schwarze 602: */
1.98 schwarze 603: case FTS_F:
1.153 schwarze 604: if ( ! strcmp(path, MANDOC_DB))
1.47 schwarze 605: continue;
606: if ( ! use_all && ff->fts_level < 2) {
607: if (warnings)
608: say(path, "Extraneous file");
609: continue;
1.81 schwarze 610: }
611: gzip = 0;
612: fsec = NULL;
1.153 schwarze 613: while (fsec == NULL) {
1.81 schwarze 614: fsec = strrchr(ff->fts_name, '.');
1.153 schwarze 615: if (fsec == NULL || strcmp(fsec+1, "gz"))
1.81 schwarze 616: break;
617: gzip = 1;
618: *fsec = '\0';
619: fsec = NULL;
620: }
1.153 schwarze 621: if (fsec == NULL) {
1.47 schwarze 622: if ( ! use_all) {
623: if (warnings)
624: say(path,
625: "No filename suffix");
626: continue;
627: }
1.153 schwarze 628: } else if ( ! strcmp(++fsec, "html")) {
1.47 schwarze 629: if (warnings)
630: say(path, "Skip html");
631: continue;
1.153 schwarze 632: } else if ( ! strcmp(fsec, "ps")) {
1.47 schwarze 633: if (warnings)
634: say(path, "Skip ps");
635: continue;
1.153 schwarze 636: } else if ( ! strcmp(fsec, "pdf")) {
1.47 schwarze 637: if (warnings)
638: say(path, "Skip pdf");
639: continue;
640: } else if ( ! use_all &&
1.153 schwarze 641: ((dform == FORM_SRC &&
1.138 schwarze 642: strncmp(fsec, dsec, strlen(dsec))) ||
1.153 schwarze 643: (dform == FORM_CAT && strcmp(fsec, "0")))) {
1.47 schwarze 644: if (warnings)
645: say(path, "Wrong filename suffix");
646: continue;
647: } else
648: fsec[-1] = '\0';
1.51 schwarze 649:
1.47 schwarze 650: mlink = mandoc_calloc(1, sizeof(struct mlink));
1.100 schwarze 651: if (strlcpy(mlink->file, path,
652: sizeof(mlink->file)) >=
653: sizeof(mlink->file)) {
654: say(path, "Filename too long");
655: free(mlink);
656: continue;
657: }
1.47 schwarze 658: mlink->dform = dform;
1.51 schwarze 659: mlink->dsec = dsec;
660: mlink->arch = arch;
661: mlink->name = ff->fts_name;
662: mlink->fsec = fsec;
1.81 schwarze 663: mlink->gzip = gzip;
1.47 schwarze 664: mlink_add(mlink, ff->fts_statp);
665: continue;
1.96 schwarze 666:
1.98 schwarze 667: case FTS_D:
668: case FTS_DP:
1.96 schwarze 669: break;
670:
671: default:
1.47 schwarze 672: if (warnings)
673: say(path, "Not a regular file");
674: continue;
675: }
676:
677: switch (ff->fts_level) {
1.98 schwarze 678: case 0:
1.47 schwarze 679: /* Ignore the root directory. */
680: break;
1.98 schwarze 681: case 1:
1.47 schwarze 682: /*
683: * This might contain manX/ or catX/.
684: * Try to infer this from the name.
685: * If we're not in use_all, enforce it.
686: */
687: cp = ff->fts_name;
1.153 schwarze 688: if (ff->fts_info == FTS_DP) {
689: dform = FORM_NONE;
690: dsec = NULL;
1.47 schwarze 691: break;
1.153 schwarze 692: }
1.15 schwarze 693:
1.153 schwarze 694: if ( ! strncmp(cp, "man", 3)) {
1.47 schwarze 695: dform = FORM_SRC;
696: dsec = cp + 3;
1.153 schwarze 697: } else if ( ! strncmp(cp, "cat", 3)) {
1.47 schwarze 698: dform = FORM_CAT;
699: dsec = cp + 3;
1.51 schwarze 700: } else {
701: dform = FORM_NONE;
702: dsec = NULL;
1.26 schwarze 703: }
1.47 schwarze 704:
1.153 schwarze 705: if (dsec != NULL || use_all)
1.47 schwarze 706: break;
707:
708: if (warnings)
709: say(path, "Unknown directory part");
710: fts_set(f, ff, FTS_SKIP);
711: break;
1.98 schwarze 712: case 2:
1.47 schwarze 713: /*
714: * Possibly our architecture.
715: * If we're descending, keep tabs on it.
716: */
1.153 schwarze 717: if (ff->fts_info != FTS_DP && dsec != NULL)
1.47 schwarze 718: arch = ff->fts_name;
1.51 schwarze 719: else
720: arch = NULL;
1.47 schwarze 721: break;
722: default:
1.153 schwarze 723: if (ff->fts_info == FTS_DP || use_all)
1.47 schwarze 724: break;
725: if (warnings)
726: say(path, "Extraneous directory part");
727: fts_set(f, ff, FTS_SKIP);
728: break;
1.14 schwarze 729: }
1.47 schwarze 730: }
731:
732: fts_close(f);
1.150 schwarze 733: return 1;
1.47 schwarze 734: }
1.1 schwarze 735:
1.47 schwarze 736: /*
737: * Add a file to the mlinks table.
738: * Do not verify that it's a "valid" looking manpage (we'll do that
739: * later).
740: *
741: * Try to infer the manual section, architecture, and page name from the
742: * path, assuming it looks like
743: *
1.98 schwarze 744: * [./]man*[/<arch>]/<name>.<section>
1.47 schwarze 745: * or
746: * [./]cat<section>[/<arch>]/<name>.0
747: *
748: * See treescan() for the fts(3) version of this.
749: */
750: static void
751: filescan(const char *file)
752: {
753: char buf[PATH_MAX];
754: struct stat st;
755: struct mlink *mlink;
756: char *p, *start;
757:
758: assert(use_all);
759:
760: if (0 == strncmp(file, "./", 2))
761: file += 2;
762:
1.96 schwarze 763: /*
764: * We have to do lstat(2) before realpath(3) loses
765: * the information whether this is a symbolic link.
766: * We need to know that because for symbolic links,
767: * we want to use the orginal file name, while for
768: * regular files, we want to use the real path.
769: */
770: if (-1 == lstat(file, &st)) {
771: exitcode = (int)MANDOCLEVEL_BADARG;
772: say(file, "&lstat");
773: return;
774: } else if (0 == ((S_IFREG | S_IFLNK) & st.st_mode)) {
775: exitcode = (int)MANDOCLEVEL_BADARG;
776: say(file, "Not a regular file");
777: return;
778: }
779:
780: /*
781: * We have to resolve the file name to the real path
782: * in any case for the base directory check.
783: */
1.47 schwarze 784: if (NULL == realpath(file, buf)) {
785: exitcode = (int)MANDOCLEVEL_BADARG;
1.80 schwarze 786: say(file, "&realpath");
1.47 schwarze 787: return;
1.63 schwarze 788: }
789:
1.109 schwarze 790: if (OP_TEST == op)
1.63 schwarze 791: start = buf;
1.109 schwarze 792: else if (strstr(buf, basedir) == buf)
793: start = buf + strlen(basedir);
1.63 schwarze 794: else {
1.47 schwarze 795: exitcode = (int)MANDOCLEVEL_BADARG;
796: say("", "%s: outside base directory", buf);
797: return;
1.63 schwarze 798: }
799:
1.96 schwarze 800: /*
801: * Now we are sure the file is inside our tree.
802: * If it is a symbolic link, ignore the real path
803: * and use the original name.
804: * This implies passing stuff like "cat1/../man1/foo.1"
805: * on the command line won't work. So don't do that.
806: * Note the stat(2) can still fail if the link target
807: * doesn't exist.
808: */
809: if (S_IFLNK & st.st_mode) {
810: if (-1 == stat(buf, &st)) {
811: exitcode = (int)MANDOCLEVEL_BADARG;
812: say(file, "&stat");
813: return;
814: }
1.100 schwarze 815: if (strlcpy(buf, file, sizeof(buf)) >= sizeof(buf)) {
816: say(file, "Filename too long");
817: return;
818: }
1.109 schwarze 819: start = buf;
820: if (OP_TEST != op && strstr(buf, basedir) == buf)
821: start += strlen(basedir);
1.1 schwarze 822: }
1.63 schwarze 823:
1.47 schwarze 824: mlink = mandoc_calloc(1, sizeof(struct mlink));
1.116 schwarze 825: mlink->dform = FORM_NONE;
1.100 schwarze 826: if (strlcpy(mlink->file, start, sizeof(mlink->file)) >=
827: sizeof(mlink->file)) {
828: say(start, "Filename too long");
1.134 schwarze 829: free(mlink);
1.100 schwarze 830: return;
831: }
1.1 schwarze 832:
1.10 schwarze 833: /*
1.47 schwarze 834: * First try to guess our directory structure.
835: * If we find a separator, try to look for man* or cat*.
836: * If we find one of these and what's underneath is a directory,
837: * assume it's an architecture.
1.10 schwarze 838: */
1.47 schwarze 839: if (NULL != (p = strchr(start, '/'))) {
840: *p++ = '\0';
841: if (0 == strncmp(start, "man", 3)) {
842: mlink->dform = FORM_SRC;
1.51 schwarze 843: mlink->dsec = start + 3;
1.47 schwarze 844: } else if (0 == strncmp(start, "cat", 3)) {
845: mlink->dform = FORM_CAT;
1.51 schwarze 846: mlink->dsec = start + 3;
1.47 schwarze 847: }
1.10 schwarze 848:
1.47 schwarze 849: start = p;
850: if (NULL != mlink->dsec && NULL != (p = strchr(start, '/'))) {
851: *p++ = '\0';
1.51 schwarze 852: mlink->arch = start;
1.47 schwarze 853: start = p;
1.41 deraadt 854: }
1.47 schwarze 855: }
1.7 schwarze 856:
1.47 schwarze 857: /*
858: * Now check the file suffix.
859: * Suffix of `.0' indicates a catpage, `.1-9' is a manpage.
860: */
861: p = strrchr(start, '\0');
862: while (p-- > start && '/' != *p && '.' != *p)
863: /* Loop. */ ;
864:
865: if ('.' == *p) {
866: *p++ = '\0';
1.51 schwarze 867: mlink->fsec = p;
1.47 schwarze 868: }
1.41 deraadt 869:
1.47 schwarze 870: /*
871: * Now try to parse the name.
872: * Use the filename portion of the path.
873: */
874: mlink->name = start;
875: if (NULL != (p = strrchr(start, '/'))) {
876: mlink->name = p + 1;
877: *p = '\0';
878: }
879: mlink_add(mlink, &st);
880: }
1.2 schwarze 881:
1.47 schwarze 882: static void
883: mlink_add(struct mlink *mlink, const struct stat *st)
884: {
885: struct inodev inodev;
886: struct mpage *mpage;
887: unsigned int slot;
888:
889: assert(NULL != mlink->file);
890:
1.51 schwarze 891: mlink->dsec = mandoc_strdup(mlink->dsec ? mlink->dsec : "");
892: mlink->arch = mandoc_strdup(mlink->arch ? mlink->arch : "");
893: mlink->name = mandoc_strdup(mlink->name ? mlink->name : "");
894: mlink->fsec = mandoc_strdup(mlink->fsec ? mlink->fsec : "");
1.47 schwarze 895:
896: if ('0' == *mlink->fsec) {
897: free(mlink->fsec);
898: mlink->fsec = mandoc_strdup(mlink->dsec);
899: mlink->fform = FORM_CAT;
900: } else if ('1' <= *mlink->fsec && '9' >= *mlink->fsec)
901: mlink->fform = FORM_SRC;
902: else
903: mlink->fform = FORM_NONE;
1.1 schwarze 904:
1.47 schwarze 905: slot = ohash_qlookup(&mlinks, mlink->file);
906: assert(NULL == ohash_find(&mlinks, slot));
907: ohash_insert(&mlinks, slot, mlink);
908:
1.139 schwarze 909: memset(&inodev, 0, sizeof(inodev)); /* Clear padding. */
1.47 schwarze 910: inodev.st_ino = st->st_ino;
911: inodev.st_dev = st->st_dev;
912: slot = ohash_lookup_memory(&mpages, (char *)&inodev,
913: sizeof(struct inodev), inodev.st_ino);
914: mpage = ohash_find(&mpages, slot);
915: if (NULL == mpage) {
916: mpage = mandoc_calloc(1, sizeof(struct mpage));
917: mpage->inodev.st_ino = inodev.st_ino;
918: mpage->inodev.st_dev = inodev.st_dev;
1.173 schwarze 919: mpage->form = FORM_NONE;
1.180 schwarze 920: mpage->next = mpage_head;
921: mpage_head = mpage;
1.47 schwarze 922: ohash_insert(&mpages, slot, mpage);
923: } else
924: mlink->next = mpage->mlinks;
925: mpage->mlinks = mlink;
1.75 schwarze 926: mlink->mpage = mpage;
1.47 schwarze 927: }
1.1 schwarze 928:
1.47 schwarze 929: static void
930: mlink_free(struct mlink *mlink)
931: {
1.1 schwarze 932:
1.47 schwarze 933: free(mlink->dsec);
934: free(mlink->arch);
935: free(mlink->name);
936: free(mlink->fsec);
937: free(mlink);
938: }
1.1 schwarze 939:
1.47 schwarze 940: static void
941: mpages_free(void)
942: {
943: struct mpage *mpage;
944: struct mlink *mlink;
945:
1.180 schwarze 946: while ((mpage = mpage_head) != NULL) {
947: while ((mlink = mpage->mlinks) != NULL) {
1.47 schwarze 948: mpage->mlinks = mlink->next;
949: mlink_free(mlink);
950: }
1.180 schwarze 951: mpage_head = mpage->next;
1.47 schwarze 952: free(mpage->sec);
953: free(mpage->arch);
954: free(mpage->title);
955: free(mpage->desc);
956: free(mpage);
957: }
958: }
1.1 schwarze 959:
1.47 schwarze 960: /*
961: * For each mlink to the mpage, check whether the path looks like
962: * it is formatted, and if it does, check whether a source manual
963: * exists by the same name, ignoring the suffix.
964: * If both conditions hold, drop the mlink.
965: */
966: static void
967: mlinks_undupe(struct mpage *mpage)
968: {
969: char buf[PATH_MAX];
970: struct mlink **prev;
971: struct mlink *mlink;
972: char *bufp;
973:
974: mpage->form = FORM_CAT;
975: prev = &mpage->mlinks;
976: while (NULL != (mlink = *prev)) {
977: if (FORM_CAT != mlink->dform) {
978: mpage->form = FORM_NONE;
979: goto nextlink;
980: }
1.100 schwarze 981: (void)strlcpy(buf, mlink->file, sizeof(buf));
1.47 schwarze 982: bufp = strstr(buf, "cat");
983: assert(NULL != bufp);
984: memcpy(bufp, "man", 3);
985: if (NULL != (bufp = strrchr(buf, '.')))
986: *++bufp = '\0';
1.100 schwarze 987: (void)strlcat(buf, mlink->dsec, sizeof(buf));
1.47 schwarze 988: if (NULL == ohash_find(&mlinks,
1.98 schwarze 989: ohash_qlookup(&mlinks, buf)))
1.47 schwarze 990: goto nextlink;
991: if (warnings)
992: say(mlink->file, "Man source exists: %s", buf);
993: if (use_all)
994: goto nextlink;
995: *prev = mlink->next;
996: mlink_free(mlink);
997: continue;
998: nextlink:
999: prev = &(*prev)->next;
1.1 schwarze 1000: }
1.47 schwarze 1001: }
1.1 schwarze 1002:
1.88 schwarze 1003: static void
1.50 schwarze 1004: mlink_check(struct mpage *mpage, struct mlink *mlink)
1005: {
1.88 schwarze 1006: struct str *str;
1007: unsigned int slot;
1.50 schwarze 1008:
1009: /*
1010: * Check whether the manual section given in a file
1011: * agrees with the directory where the file is located.
1012: * Some manuals have suffixes like (3p) on their
1013: * section number either inside the file or in the
1014: * directory name, some are linked into more than one
1015: * section, like encrypt(1) = makekey(8).
1016: */
1017:
1018: if (FORM_SRC == mpage->form &&
1.88 schwarze 1019: strcasecmp(mpage->sec, mlink->dsec))
1.50 schwarze 1020: say(mlink->file, "Section \"%s\" manual in %s directory",
1021: mpage->sec, mlink->dsec);
1022:
1023: /*
1024: * Manual page directories exist for each kernel
1025: * architecture as returned by machine(1).
1026: * However, many manuals only depend on the
1027: * application architecture as returned by arch(1).
1028: * For example, some (2/ARM) manuals are shared
1029: * across the "armish" and "zaurus" kernel
1030: * architectures.
1031: * A few manuals are even shared across completely
1032: * different architectures, for example fdformat(1)
1.178 schwarze 1033: * on amd64, i386, and sparc64.
1.50 schwarze 1034: */
1035:
1.88 schwarze 1036: if (strcasecmp(mpage->arch, mlink->arch))
1.50 schwarze 1037: say(mlink->file, "Architecture \"%s\" manual in "
1038: "\"%s\" directory", mpage->arch, mlink->arch);
1039:
1.88 schwarze 1040: /*
1041: * XXX
1.90 schwarze 1042: * parse_cat() doesn't set NAME_TITLE yet.
1.88 schwarze 1043: */
1044:
1045: if (FORM_CAT == mpage->form)
1046: return;
1047:
1048: /*
1049: * Check whether this mlink
1050: * appears as a name in the NAME section.
1051: */
1.50 schwarze 1052:
1.90 schwarze 1053: slot = ohash_qlookup(&names, mlink->name);
1054: str = ohash_find(&names, slot);
1.88 schwarze 1055: assert(NULL != str);
1.90 schwarze 1056: if ( ! (NAME_TITLE & str->mask))
1.88 schwarze 1057: say(mlink->file, "Name missing in NAME section");
1.50 schwarze 1058: }
1059:
1.47 schwarze 1060: /*
1061: * Run through the files in the global vector "mpages"
1062: * and add them to the database specified in "basedir".
1063: *
1064: * This handles the parsing scheme itself, using the cues of directory
1065: * and filename to determine whether the file is parsable or not.
1066: */
1067: static void
1.173 schwarze 1068: mpages_merge(struct dba *dba, struct mparse *mp)
1.47 schwarze 1069: {
1.180 schwarze 1070: struct mpage *mpage, *mpage_dest;
1.75 schwarze 1071: struct mlink *mlink, *mlink_dest;
1.144 schwarze 1072: struct roff_man *man;
1.75 schwarze 1073: char *sodest;
1.69 schwarze 1074: char *cp;
1.117 schwarze 1075: int fd;
1.64 schwarze 1076:
1.180 schwarze 1077: for (mpage = mpage_head; mpage != NULL; mpage = mpage->next) {
1.47 schwarze 1078: mlinks_undupe(mpage);
1.180 schwarze 1079: if ((mlink = mpage->mlinks) == NULL)
1080: continue;
1.1 schwarze 1081:
1.90 schwarze 1082: name_mask = NAME_MASK;
1.156 schwarze 1083: mandoc_ohash_init(&names, 4, offsetof(struct str, key));
1084: mandoc_ohash_init(&strings, 6, offsetof(struct str, key));
1.47 schwarze 1085: mparse_reset(mp);
1086: man = NULL;
1.81 schwarze 1087: sodest = NULL;
1088:
1.166 schwarze 1089: if ((fd = mparse_open(mp, mlink->file)) == -1) {
1.136 schwarze 1090: say(mlink->file, "&open");
1.117 schwarze 1091: goto nextpage;
1.81 schwarze 1092: }
1.11 schwarze 1093:
1094: /*
1.137 schwarze 1095: * Interpret the file as mdoc(7) or man(7) source
1096: * code, unless it is known to be formatted.
1.11 schwarze 1097: */
1.136 schwarze 1098: if (mlink->dform != FORM_CAT || mlink->fform != FORM_CAT) {
1.137 schwarze 1099: mparse_readfd(mp, fd, mlink->file);
1.165 schwarze 1100: close(fd);
1.145 schwarze 1101: mparse_result(mp, &man, &sodest);
1.47 schwarze 1102: }
1.11 schwarze 1103:
1.126 schwarze 1104: if (sodest != NULL) {
1.75 schwarze 1105: mlink_dest = ohash_find(&mlinks,
1106: ohash_qlookup(&mlinks, sodest));
1.126 schwarze 1107: if (mlink_dest == NULL) {
1108: mandoc_asprintf(&cp, "%s.gz", sodest);
1109: mlink_dest = ohash_find(&mlinks,
1110: ohash_qlookup(&mlinks, cp));
1111: free(cp);
1112: }
1113: if (mlink_dest != NULL) {
1.75 schwarze 1114:
1115: /* The .so target exists. */
1116:
1117: mpage_dest = mlink_dest->mpage;
1118: while (1) {
1119: mlink->mpage = mpage_dest;
1120:
1121: /*
1122: * If the target was already
1123: * processed, add the links
1124: * to the database now.
1125: * Otherwise, this will
1126: * happen when we come
1127: * to the target.
1128: */
1129:
1.173 schwarze 1130: if (mpage_dest->dba != NULL)
1131: dbadd_mlink(mlink);
1.75 schwarze 1132:
1.126 schwarze 1133: if (mlink->next == NULL)
1.75 schwarze 1134: break;
1135: mlink = mlink->next;
1136: }
1137:
1138: /* Move all links to the target. */
1139:
1140: mlink->next = mlink_dest->next;
1141: mlink_dest->next = mpage->mlinks;
1142: mpage->mlinks = NULL;
1143: }
1.81 schwarze 1144: goto nextpage;
1.145 schwarze 1145: } else if (man != NULL && man->macroset == MACROSET_MDOC) {
1.159 schwarze 1146: mdoc_validate(man);
1.47 schwarze 1147: mpage->form = FORM_SRC;
1.146 schwarze 1148: mpage->sec = man->meta.msec;
1.112 schwarze 1149: mpage->sec = mandoc_strdup(
1.126 schwarze 1150: mpage->sec == NULL ? "" : mpage->sec);
1.146 schwarze 1151: mpage->arch = man->meta.arch;
1.47 schwarze 1152: mpage->arch = mandoc_strdup(
1.126 schwarze 1153: mpage->arch == NULL ? "" : mpage->arch);
1.146 schwarze 1154: mpage->title = mandoc_strdup(man->meta.title);
1.145 schwarze 1155: } else if (man != NULL && man->macroset == MACROSET_MAN) {
1.160 schwarze 1156: man_validate(man);
1.47 schwarze 1157: mpage->form = FORM_SRC;
1.146 schwarze 1158: mpage->sec = mandoc_strdup(man->meta.msec);
1.136 schwarze 1159: mpage->arch = mandoc_strdup(mlink->arch);
1.146 schwarze 1160: mpage->title = mandoc_strdup(man->meta.title);
1.11 schwarze 1161: } else {
1.47 schwarze 1162: mpage->form = FORM_CAT;
1.136 schwarze 1163: mpage->sec = mandoc_strdup(mlink->dsec);
1164: mpage->arch = mandoc_strdup(mlink->arch);
1165: mpage->title = mandoc_strdup(mlink->name);
1.1 schwarze 1166: }
1.41 deraadt 1167:
1.129 schwarze 1168: assert(mpage->desc == NULL);
1.145 schwarze 1169: if (man != NULL && man->macroset == MACROSET_MDOC)
1.146 schwarze 1170: parse_mdoc(mpage, &man->meta, man->first);
1.129 schwarze 1171: else if (man != NULL)
1.146 schwarze 1172: parse_man(mpage, &man->meta, man->first);
1.47 schwarze 1173: else
1.117 schwarze 1174: parse_cat(mpage, fd);
1.129 schwarze 1175: if (mpage->desc == NULL)
1.92 schwarze 1176: mpage->desc = mandoc_strdup(mpage->mlinks->name);
1.88 schwarze 1177:
1178: if (warnings && !use_all)
1179: for (mlink = mpage->mlinks; mlink;
1180: mlink = mlink->next)
1181: mlink_check(mpage, mlink);
1.6 schwarze 1182:
1.173 schwarze 1183: dbadd(dba, mpage);
1.136 schwarze 1184: mlink = mpage->mlinks;
1.81 schwarze 1185:
1186: nextpage:
1.47 schwarze 1187: ohash_delete(&strings);
1.90 schwarze 1188: ohash_delete(&names);
1.47 schwarze 1189: }
1190: }
1.6 schwarze 1191:
1.47 schwarze 1192: static void
1.81 schwarze 1193: parse_cat(struct mpage *mpage, int fd)
1.47 schwarze 1194: {
1195: FILE *stream;
1196: char *line, *p, *title;
1.162 schwarze 1197: size_t linesz, plen, titlesz;
1198: ssize_t len;
1199: int offs;
1.1 schwarze 1200:
1.81 schwarze 1201: stream = (-1 == fd) ?
1202: fopen(mpage->mlinks->file, "r") :
1203: fdopen(fd, "r");
1204: if (NULL == stream) {
1.114 doug 1205: if (-1 != fd)
1206: close(fd);
1.47 schwarze 1207: if (warnings)
1.80 schwarze 1208: say(mpage->mlinks->file, "&fopen");
1.47 schwarze 1209: return;
1210: }
1.1 schwarze 1211:
1.162 schwarze 1212: line = NULL;
1213: linesz = 0;
1214:
1.47 schwarze 1215: /* Skip to first blank line. */
1.1 schwarze 1216:
1.162 schwarze 1217: while (getline(&line, &linesz, stream) != -1)
1218: if (*line == '\n')
1.47 schwarze 1219: break;
1.1 schwarze 1220:
1.47 schwarze 1221: /*
1222: * Assume the first line that is not indented
1223: * is the first section header. Skip to it.
1224: */
1.1 schwarze 1225:
1.162 schwarze 1226: while (getline(&line, &linesz, stream) != -1)
1227: if (*line != '\n' && *line != ' ')
1.47 schwarze 1228: break;
1.98 schwarze 1229:
1.47 schwarze 1230: /*
1231: * Read up until the next section into a buffer.
1232: * Strip the leading and trailing newline from each read line,
1233: * appending a trailing space.
1234: * Ignore empty (whitespace-only) lines.
1235: */
1.28 schwarze 1236:
1.47 schwarze 1237: titlesz = 0;
1238: title = NULL;
1.38 schwarze 1239:
1.162 schwarze 1240: while ((len = getline(&line, &linesz, stream)) != -1) {
1241: if (*line != ' ')
1.47 schwarze 1242: break;
1.162 schwarze 1243: offs = 0;
1244: while (isspace((unsigned char)line[offs]))
1245: offs++;
1246: if (line[offs] == '\0')
1.47 schwarze 1247: continue;
1.162 schwarze 1248: title = mandoc_realloc(title, titlesz + len - offs);
1249: memcpy(title + titlesz, line + offs, len - offs);
1250: titlesz += len - offs;
1.47 schwarze 1251: title[titlesz - 1] = ' ';
1252: }
1.162 schwarze 1253: free(line);
1.28 schwarze 1254:
1.47 schwarze 1255: /*
1256: * If no page content can be found, or the input line
1257: * is already the next section header, or there is no
1258: * trailing newline, reuse the page title as the page
1259: * description.
1260: */
1.1 schwarze 1261:
1.47 schwarze 1262: if (NULL == title || '\0' == *title) {
1263: if (warnings)
1264: say(mpage->mlinks->file,
1265: "Cannot find NAME section");
1266: fclose(stream);
1267: free(title);
1268: return;
1269: }
1.24 schwarze 1270:
1.162 schwarze 1271: title[titlesz - 1] = '\0';
1.24 schwarze 1272:
1.47 schwarze 1273: /*
1274: * Skip to the first dash.
1275: * Use the remaining line as the description (no more than 70
1276: * bytes).
1277: */
1.28 schwarze 1278:
1.47 schwarze 1279: if (NULL != (p = strstr(title, "- "))) {
1280: for (p += 2; ' ' == *p || '\b' == *p; p++)
1281: /* Skip to next word. */ ;
1282: } else {
1283: if (warnings)
1284: say(mpage->mlinks->file,
1285: "No dash in title line");
1286: p = title;
1287: }
1.1 schwarze 1288:
1.47 schwarze 1289: plen = strlen(p);
1.1 schwarze 1290:
1.47 schwarze 1291: /* Strip backspace-encoding from line. */
1.1 schwarze 1292:
1.47 schwarze 1293: while (NULL != (line = memchr(p, '\b', plen))) {
1294: len = line - p;
1295: if (0 == len) {
1296: memmove(line, line + 1, plen--);
1297: continue;
1.98 schwarze 1298: }
1.47 schwarze 1299: memmove(line - 1, line + 1, plen - len);
1300: plen -= 2;
1301: }
1.1 schwarze 1302:
1.47 schwarze 1303: mpage->desc = mandoc_strdup(p);
1304: fclose(stream);
1305: free(title);
1306: }
1.16 schwarze 1307:
1.47 schwarze 1308: /*
1309: * Put a type/word pair into the word database for this particular file.
1310: */
1311: static void
1.69 schwarze 1312: putkey(const struct mpage *mpage, char *value, uint64_t type)
1.47 schwarze 1313: {
1314: putkeys(mpage, value, strlen(value), type);
1.2 schwarze 1315: }
1316:
1317: /*
1.47 schwarze 1318: * Grok all nodes at or below a certain mdoc node into putkey().
1.2 schwarze 1319: */
1320: static void
1.47 schwarze 1321: putmdockey(const struct mpage *mpage,
1.142 schwarze 1322: const struct roff_node *n, uint64_t m)
1.2 schwarze 1323: {
1.16 schwarze 1324:
1.47 schwarze 1325: for ( ; NULL != n; n = n->next) {
1326: if (NULL != n->child)
1327: putmdockey(mpage, n->child, m);
1.141 schwarze 1328: if (n->type == ROFFT_TEXT)
1.47 schwarze 1329: putkey(mpage, n->string, m);
1330: }
1331: }
1.16 schwarze 1332:
1.47 schwarze 1333: static void
1.143 schwarze 1334: parse_man(struct mpage *mpage, const struct roff_meta *meta,
1.142 schwarze 1335: const struct roff_node *n)
1.47 schwarze 1336: {
1.142 schwarze 1337: const struct roff_node *head, *body;
1.78 schwarze 1338: char *start, *title;
1.47 schwarze 1339: char byte;
1.78 schwarze 1340: size_t sz;
1.16 schwarze 1341:
1.168 schwarze 1342: if (n == NULL)
1.47 schwarze 1343: return;
1.16 schwarze 1344:
1.47 schwarze 1345: /*
1346: * We're only searching for one thing: the first text child in
1347: * the BODY of a NAME section. Since we don't keep track of
1348: * sections in -man, run some hoops to find out whether we're in
1349: * the correct section or not.
1350: */
1.16 schwarze 1351:
1.141 schwarze 1352: if (n->type == ROFFT_BODY && n->tok == MAN_SH) {
1.47 schwarze 1353: body = n;
1.168 schwarze 1354: if ((head = body->parent->head) != NULL &&
1355: (head = head->child) != NULL &&
1356: head->next == NULL &&
1.141 schwarze 1357: head->type == ROFFT_TEXT &&
1.168 schwarze 1358: strcmp(head->string, "NAME") == 0 &&
1359: body->child != NULL) {
1.2 schwarze 1360:
1.47 schwarze 1361: /*
1362: * Suck the entire NAME section into memory.
1363: * Yes, we might run away.
1364: * But too many manuals have big, spread-out
1365: * NAME sections over many lines.
1366: */
1.2 schwarze 1367:
1.78 schwarze 1368: title = NULL;
1.147 schwarze 1369: deroff(&title, body);
1.47 schwarze 1370: if (NULL == title)
1371: return;
1.16 schwarze 1372:
1.98 schwarze 1373: /*
1.47 schwarze 1374: * Go through a special heuristic dance here.
1375: * Conventionally, one or more manual names are
1376: * comma-specified prior to a whitespace, then a
1377: * dash, then a description. Try to puzzle out
1378: * the name parts here.
1379: */
1.16 schwarze 1380:
1.78 schwarze 1381: start = title;
1.47 schwarze 1382: for ( ;; ) {
1383: sz = strcspn(start, " ,");
1384: if ('\0' == start[sz])
1385: break;
1.1 schwarze 1386:
1.47 schwarze 1387: byte = start[sz];
1388: start[sz] = '\0';
1.67 schwarze 1389:
1390: /*
1391: * Assume a stray trailing comma in the
1392: * name list if a name begins with a dash.
1393: */
1394:
1395: if ('-' == start[0] ||
1396: ('\\' == start[0] && '-' == start[1]))
1397: break;
1.1 schwarze 1398:
1.90 schwarze 1399: putkey(mpage, start, NAME_TITLE);
1.129 schwarze 1400: if ( ! (mpage->name_head_done ||
1401: strcasecmp(start, meta->title))) {
1402: putkey(mpage, start, NAME_HEAD);
1403: mpage->name_head_done = 1;
1404: }
1.1 schwarze 1405:
1.47 schwarze 1406: if (' ' == byte) {
1407: start += sz + 1;
1408: break;
1409: }
1.1 schwarze 1410:
1.47 schwarze 1411: assert(',' == byte);
1412: start += sz + 1;
1413: while (' ' == *start)
1414: start++;
1415: }
1.1 schwarze 1416:
1.78 schwarze 1417: if (start == title) {
1.90 schwarze 1418: putkey(mpage, start, NAME_TITLE);
1.129 schwarze 1419: if ( ! (mpage->name_head_done ||
1420: strcasecmp(start, meta->title))) {
1421: putkey(mpage, start, NAME_HEAD);
1422: mpage->name_head_done = 1;
1423: }
1.47 schwarze 1424: free(title);
1425: return;
1426: }
1.1 schwarze 1427:
1.47 schwarze 1428: while (isspace((unsigned char)*start))
1429: start++;
1.1 schwarze 1430:
1.47 schwarze 1431: if (0 == strncmp(start, "-", 1))
1432: start += 1;
1433: else if (0 == strncmp(start, "\\-\\-", 4))
1434: start += 4;
1435: else if (0 == strncmp(start, "\\-", 2))
1436: start += 2;
1437: else if (0 == strncmp(start, "\\(en", 4))
1438: start += 4;
1439: else if (0 == strncmp(start, "\\(em", 4))
1440: start += 4;
1.1 schwarze 1441:
1.47 schwarze 1442: while (' ' == *start)
1443: start++;
1.1 schwarze 1444:
1.47 schwarze 1445: mpage->desc = mandoc_strdup(start);
1446: free(title);
1447: return;
1448: }
1449: }
1.1 schwarze 1450:
1.47 schwarze 1451: for (n = n->child; n; n = n->next) {
1452: if (NULL != mpage->desc)
1453: break;
1.129 schwarze 1454: parse_man(mpage, meta, n);
1.1 schwarze 1455: }
1456: }
1457:
1458: static void
1.143 schwarze 1459: parse_mdoc(struct mpage *mpage, const struct roff_meta *meta,
1.142 schwarze 1460: const struct roff_node *n)
1.1 schwarze 1461: {
1462:
1.47 schwarze 1463: assert(NULL != n);
1464: for (n = n->child; NULL != n; n = n->next) {
1465: switch (n->type) {
1.141 schwarze 1466: case ROFFT_ELEM:
1467: case ROFFT_BLOCK:
1468: case ROFFT_HEAD:
1469: case ROFFT_BODY:
1470: case ROFFT_TAIL:
1.47 schwarze 1471: if (NULL != mdocs[n->tok].fp)
1.127 schwarze 1472: if (0 == (*mdocs[n->tok].fp)(mpage, meta, n))
1.47 schwarze 1473: break;
1474: if (mdocs[n->tok].mask)
1475: putmdockey(mpage, n->child,
1476: mdocs[n->tok].mask);
1477: break;
1478: default:
1.141 schwarze 1479: assert(n->type != ROFFT_ROOT);
1.47 schwarze 1480: continue;
1481: }
1482: if (NULL != n->child)
1.127 schwarze 1483: parse_mdoc(mpage, meta, n);
1.1 schwarze 1484: }
1485: }
1486:
1.19 schwarze 1487: static int
1.143 schwarze 1488: parse_mdoc_Fd(struct mpage *mpage, const struct roff_meta *meta,
1.142 schwarze 1489: const struct roff_node *n)
1.1 schwarze 1490: {
1.131 schwarze 1491: char *start, *end;
1.1 schwarze 1492: size_t sz;
1.19 schwarze 1493:
1.47 schwarze 1494: if (SEC_SYNOPSIS != n->sec ||
1.98 schwarze 1495: NULL == (n = n->child) ||
1.141 schwarze 1496: n->type != ROFFT_TEXT)
1.150 schwarze 1497: return 0;
1.1 schwarze 1498:
1499: /*
1500: * Only consider those `Fd' macro fields that begin with an
1501: * "inclusion" token (versus, e.g., #define).
1502: */
1.47 schwarze 1503:
1.1 schwarze 1504: if (strcmp("#include", n->string))
1.150 schwarze 1505: return 0;
1.1 schwarze 1506:
1.141 schwarze 1507: if ((n = n->next) == NULL || n->type != ROFFT_TEXT)
1.150 schwarze 1508: return 0;
1.1 schwarze 1509:
1510: /*
1511: * Strip away the enclosing angle brackets and make sure we're
1512: * not zero-length.
1513: */
1514:
1515: start = n->string;
1516: if ('<' == *start || '"' == *start)
1517: start++;
1518:
1519: if (0 == (sz = strlen(start)))
1.150 schwarze 1520: return 0;
1.1 schwarze 1521:
1522: end = &start[(int)sz - 1];
1523: if ('>' == *end || '"' == *end)
1524: end--;
1525:
1.47 schwarze 1526: if (end > start)
1527: putkeys(mpage, start, end - start + 1, TYPE_In);
1.150 schwarze 1528: return 0;
1.1 schwarze 1529: }
1530:
1.133 schwarze 1531: static void
1.142 schwarze 1532: parse_mdoc_fname(struct mpage *mpage, const struct roff_node *n)
1.1 schwarze 1533: {
1.69 schwarze 1534: char *cp;
1.133 schwarze 1535: size_t sz;
1.1 schwarze 1536:
1.141 schwarze 1537: if (n->type != ROFFT_TEXT)
1.133 schwarze 1538: return;
1.19 schwarze 1539:
1.133 schwarze 1540: /* Skip function pointer punctuation. */
1.1 schwarze 1541:
1.133 schwarze 1542: cp = n->string;
1543: while (*cp == '(' || *cp == '*')
1.1 schwarze 1544: cp++;
1.133 schwarze 1545: sz = strcspn(cp, "()");
1.1 schwarze 1546:
1.133 schwarze 1547: putkeys(mpage, cp, sz, TYPE_Fn);
1.128 schwarze 1548: if (n->sec == SEC_SYNOPSIS)
1.133 schwarze 1549: putkeys(mpage, cp, sz, NAME_SYN);
1550: }
1.19 schwarze 1551:
1.133 schwarze 1552: static int
1.143 schwarze 1553: parse_mdoc_Fn(struct mpage *mpage, const struct roff_meta *meta,
1.142 schwarze 1554: const struct roff_node *n)
1.133 schwarze 1555: {
1556:
1557: if (n->child == NULL)
1.150 schwarze 1558: return 0;
1.133 schwarze 1559:
1560: parse_mdoc_fname(mpage, n->child);
1.19 schwarze 1561:
1.133 schwarze 1562: for (n = n->child->next; n != NULL; n = n->next)
1.141 schwarze 1563: if (n->type == ROFFT_TEXT)
1.47 schwarze 1564: putkey(mpage, n->string, TYPE_Fa);
1.19 schwarze 1565:
1.150 schwarze 1566: return 0;
1.128 schwarze 1567: }
1568:
1569: static int
1.143 schwarze 1570: parse_mdoc_Fo(struct mpage *mpage, const struct roff_meta *meta,
1.142 schwarze 1571: const struct roff_node *n)
1.128 schwarze 1572: {
1.132 schwarze 1573:
1.141 schwarze 1574: if (n->type != ROFFT_HEAD)
1.150 schwarze 1575: return 1;
1.128 schwarze 1576:
1.133 schwarze 1577: if (n->child != NULL)
1578: parse_mdoc_fname(mpage, n->child);
1579:
1.150 schwarze 1580: return 0;
1.1 schwarze 1581: }
1582:
1.19 schwarze 1583: static int
1.164 schwarze 1584: parse_mdoc_Va(struct mpage *mpage, const struct roff_meta *meta,
1585: const struct roff_node *n)
1586: {
1587: char *cp;
1588:
1589: if (n->type != ROFFT_ELEM && n->type != ROFFT_BODY)
1590: return 0;
1591:
1.168 schwarze 1592: if (n->child != NULL &&
1593: n->child->next == NULL &&
1594: n->child->type == ROFFT_TEXT)
1.164 schwarze 1595: return 1;
1596:
1597: cp = NULL;
1598: deroff(&cp, n);
1599: if (cp != NULL) {
1600: putkey(mpage, cp, TYPE_Vt | (n->tok == MDOC_Va ||
1601: n->type == ROFFT_BODY ? TYPE_Va : 0));
1602: free(cp);
1603: }
1604:
1605: return 0;
1606: }
1607:
1608: static int
1.143 schwarze 1609: parse_mdoc_Xr(struct mpage *mpage, const struct roff_meta *meta,
1.142 schwarze 1610: const struct roff_node *n)
1.1 schwarze 1611: {
1.47 schwarze 1612: char *cp;
1.1 schwarze 1613:
1614: if (NULL == (n = n->child))
1.150 schwarze 1615: return 0;
1.1 schwarze 1616:
1.47 schwarze 1617: if (NULL == n->next) {
1618: putkey(mpage, n->string, TYPE_Xr);
1.150 schwarze 1619: return 0;
1.47 schwarze 1620: }
1.1 schwarze 1621:
1.77 schwarze 1622: mandoc_asprintf(&cp, "%s(%s)", n->string, n->next->string);
1.47 schwarze 1623: putkey(mpage, cp, TYPE_Xr);
1624: free(cp);
1.150 schwarze 1625: return 0;
1.1 schwarze 1626: }
1627:
1.19 schwarze 1628: static int
1.143 schwarze 1629: parse_mdoc_Nd(struct mpage *mpage, const struct roff_meta *meta,
1.142 schwarze 1630: const struct roff_node *n)
1.1 schwarze 1631: {
1632:
1.141 schwarze 1633: if (n->type == ROFFT_BODY)
1.147 schwarze 1634: deroff(&mpage->desc, n);
1.150 schwarze 1635: return 0;
1.1 schwarze 1636: }
1637:
1.19 schwarze 1638: static int
1.143 schwarze 1639: parse_mdoc_Nm(struct mpage *mpage, const struct roff_meta *meta,
1.142 schwarze 1640: const struct roff_node *n)
1.1 schwarze 1641: {
1642:
1.86 schwarze 1643: if (SEC_NAME == n->sec)
1.90 schwarze 1644: putmdockey(mpage, n->child, NAME_TITLE);
1.141 schwarze 1645: else if (n->sec == SEC_SYNOPSIS && n->type == ROFFT_HEAD) {
1.127 schwarze 1646: if (n->child == NULL)
1647: putkey(mpage, meta->name, NAME_SYN);
1648: else
1649: putmdockey(mpage, n->child, NAME_SYN);
1.129 schwarze 1650: }
1651: if ( ! (mpage->name_head_done ||
1652: n->child == NULL || n->child->string == NULL ||
1653: strcasecmp(n->child->string, meta->title))) {
1.175 schwarze 1654: putkey(mpage, n->child->string, NAME_HEAD);
1.129 schwarze 1655: mpage->name_head_done = 1;
1.127 schwarze 1656: }
1.150 schwarze 1657: return 0;
1.1 schwarze 1658: }
1659:
1.19 schwarze 1660: static int
1.143 schwarze 1661: parse_mdoc_Sh(struct mpage *mpage, const struct roff_meta *meta,
1.142 schwarze 1662: const struct roff_node *n)
1.1 schwarze 1663: {
1664:
1.150 schwarze 1665: return n->sec == SEC_CUSTOM && n->type == ROFFT_HEAD;
1.1 schwarze 1666: }
1667:
1.47 schwarze 1668: static int
1.143 schwarze 1669: parse_mdoc_head(struct mpage *mpage, const struct roff_meta *meta,
1.142 schwarze 1670: const struct roff_node *n)
1.1 schwarze 1671: {
1672:
1.150 schwarze 1673: return n->type == ROFFT_HEAD;
1.1 schwarze 1674: }
1675:
1.47 schwarze 1676: /*
1677: * Add a string to the hash table for the current manual.
1678: * Each string has a bitmask telling which macros it belongs to.
1679: * When we finish the manual, we'll dump the table.
1680: */
1.1 schwarze 1681: static void
1.131 schwarze 1682: putkeys(const struct mpage *mpage, char *cp, size_t sz, uint64_t v)
1.1 schwarze 1683: {
1.90 schwarze 1684: struct ohash *htab;
1.47 schwarze 1685: struct str *s;
1.68 schwarze 1686: const char *end;
1.47 schwarze 1687: unsigned int slot;
1.131 schwarze 1688: int i, mustfree;
1.1 schwarze 1689:
1.47 schwarze 1690: if (0 == sz)
1691: return;
1.68 schwarze 1692:
1.131 schwarze 1693: mustfree = render_string(&cp, &sz);
1694:
1.90 schwarze 1695: if (TYPE_Nm & v) {
1696: htab = &names;
1697: v &= name_mask;
1.124 schwarze 1698: if (v & NAME_FIRST)
1699: name_mask &= ~NAME_FIRST;
1.90 schwarze 1700: if (debug > 1)
1701: say(mpage->mlinks->file,
1.183 ! schwarze 1702: "Adding name %*s, bits=0x%llx", (int)sz, cp,
! 1703: (unsigned long long)v);
1.90 schwarze 1704: } else {
1705: htab = &strings;
1706: if (debug > 1)
1.173 schwarze 1707: for (i = 0; i < KEY_MAX; i++)
1.118 schwarze 1708: if ((uint64_t)1 << i & v)
1.90 schwarze 1709: say(mpage->mlinks->file,
1710: "Adding key %s=%*s",
1.172 schwarze 1711: mansearch_keynames[i], (int)sz, cp);
1.68 schwarze 1712: }
1.47 schwarze 1713:
1714: end = cp + sz;
1.90 schwarze 1715: slot = ohash_qlookupi(htab, cp, &end);
1716: s = ohash_find(htab, slot);
1.1 schwarze 1717:
1.47 schwarze 1718: if (NULL != s && mpage == s->mpage) {
1719: s->mask |= v;
1.1 schwarze 1720: return;
1.47 schwarze 1721: } else if (NULL == s) {
1.101 schwarze 1722: s = mandoc_calloc(1, sizeof(struct str) + sz + 1);
1.47 schwarze 1723: memcpy(s->key, cp, sz);
1.90 schwarze 1724: ohash_insert(htab, slot, s);
1.47 schwarze 1725: }
1726: s->mpage = mpage;
1727: s->mask = v;
1.131 schwarze 1728:
1729: if (mustfree)
1730: free(cp);
1.1 schwarze 1731: }
1732:
1733: /*
1.47 schwarze 1734: * Take a Unicode codepoint and produce its UTF-8 encoding.
1735: * This isn't the best way to do this, but it works.
1736: * The magic numbers are from the UTF-8 packaging.
1737: * They're not as scary as they seem: read the UTF-8 spec for details.
1.1 schwarze 1738: */
1.47 schwarze 1739: static size_t
1740: utf8(unsigned int cp, char out[7])
1.1 schwarze 1741: {
1.47 schwarze 1742: size_t rc;
1.1 schwarze 1743:
1.47 schwarze 1744: rc = 0;
1745: if (cp <= 0x0000007F) {
1746: rc = 1;
1747: out[0] = (char)cp;
1748: } else if (cp <= 0x000007FF) {
1749: rc = 2;
1750: out[0] = (cp >> 6 & 31) | 192;
1751: out[1] = (cp & 63) | 128;
1752: } else if (cp <= 0x0000FFFF) {
1753: rc = 3;
1754: out[0] = (cp >> 12 & 15) | 224;
1755: out[1] = (cp >> 6 & 63) | 128;
1756: out[2] = (cp & 63) | 128;
1757: } else if (cp <= 0x001FFFFF) {
1758: rc = 4;
1759: out[0] = (cp >> 18 & 7) | 240;
1760: out[1] = (cp >> 12 & 63) | 128;
1761: out[2] = (cp >> 6 & 63) | 128;
1762: out[3] = (cp & 63) | 128;
1763: } else if (cp <= 0x03FFFFFF) {
1764: rc = 5;
1765: out[0] = (cp >> 24 & 3) | 248;
1766: out[1] = (cp >> 18 & 63) | 128;
1767: out[2] = (cp >> 12 & 63) | 128;
1768: out[3] = (cp >> 6 & 63) | 128;
1769: out[4] = (cp & 63) | 128;
1770: } else if (cp <= 0x7FFFFFFF) {
1771: rc = 6;
1772: out[0] = (cp >> 30 & 1) | 252;
1773: out[1] = (cp >> 24 & 63) | 128;
1774: out[2] = (cp >> 18 & 63) | 128;
1775: out[3] = (cp >> 12 & 63) | 128;
1776: out[4] = (cp >> 6 & 63) | 128;
1777: out[5] = (cp & 63) | 128;
1778: } else
1.150 schwarze 1779: return 0;
1.19 schwarze 1780:
1.47 schwarze 1781: out[rc] = '\0';
1.150 schwarze 1782: return rc;
1.1 schwarze 1783: }
1784:
1.47 schwarze 1785: /*
1.131 schwarze 1786: * If the string contains escape sequences,
1787: * replace it with an allocated rendering and return 1,
1788: * such that the caller can free it after use.
1789: * Otherwise, do nothing and return 0.
1.47 schwarze 1790: */
1.131 schwarze 1791: static int
1792: render_string(char **public, size_t *psz)
1.1 schwarze 1793: {
1.131 schwarze 1794: const char *src, *scp, *addcp, *seq;
1795: char *dst;
1796: size_t ssz, dsz, addsz;
1.71 schwarze 1797: char utfbuf[7], res[6];
1.131 schwarze 1798: int seqlen, unicode;
1.47 schwarze 1799:
1800: res[0] = '\\';
1801: res[1] = '\t';
1802: res[2] = ASCII_NBRSP;
1803: res[3] = ASCII_HYPH;
1.71 schwarze 1804: res[4] = ASCII_BREAK;
1805: res[5] = '\0';
1.1 schwarze 1806:
1.131 schwarze 1807: src = scp = *public;
1808: ssz = *psz;
1809: dst = NULL;
1810: dsz = 0;
1811:
1812: while (scp < src + *psz) {
1813:
1814: /* Leave normal characters unchanged. */
1815:
1816: if (strchr(res, *scp) == NULL) {
1817: if (dst != NULL)
1818: dst[dsz++] = *scp;
1819: scp++;
1820: continue;
1821: }
1.1 schwarze 1822:
1.47 schwarze 1823: /*
1.131 schwarze 1824: * Found something that requires replacing,
1825: * make sure we have a destination buffer.
1.47 schwarze 1826: */
1.131 schwarze 1827:
1828: if (dst == NULL) {
1829: dst = mandoc_malloc(ssz + 1);
1830: dsz = scp - src;
1831: memcpy(dst, src, dsz);
1.47 schwarze 1832: }
1.39 schwarze 1833:
1.131 schwarze 1834: /* Handle single-char special characters. */
1835:
1836: switch (*scp) {
1837: case '\\':
1838: break;
1.98 schwarze 1839: case '\t':
1840: case ASCII_NBRSP:
1.131 schwarze 1841: dst[dsz++] = ' ';
1842: scp++;
1843: continue;
1844: case ASCII_HYPH:
1845: dst[dsz++] = '-';
1.71 schwarze 1846: /* FALLTHROUGH */
1.98 schwarze 1847: case ASCII_BREAK:
1.131 schwarze 1848: scp++;
1.47 schwarze 1849: continue;
1.71 schwarze 1850: default:
1.131 schwarze 1851: abort();
1.71 schwarze 1852: }
1.39 schwarze 1853:
1.47 schwarze 1854: /*
1.131 schwarze 1855: * Found an escape sequence.
1856: * Read past the slash, then parse it.
1857: * Ignore everything except characters.
1.47 schwarze 1858: */
1.52 schwarze 1859:
1.131 schwarze 1860: scp++;
1861: if (mandoc_escape(&scp, &seq, &seqlen) != ESCAPE_SPECIAL)
1.47 schwarze 1862: continue;
1.39 schwarze 1863:
1.47 schwarze 1864: /*
1.52 schwarze 1865: * Render the special character
1866: * as either UTF-8 or ASCII.
1.47 schwarze 1867: */
1.52 schwarze 1868:
1869: if (write_utf8) {
1.157 schwarze 1870: unicode = mchars_spec2cp(seq, seqlen);
1.131 schwarze 1871: if (unicode <= 0)
1.52 schwarze 1872: continue;
1.131 schwarze 1873: addsz = utf8(unicode, utfbuf);
1874: if (addsz == 0)
1.52 schwarze 1875: continue;
1.131 schwarze 1876: addcp = utfbuf;
1.52 schwarze 1877: } else {
1.157 schwarze 1878: addcp = mchars_spec2str(seq, seqlen, &addsz);
1.131 schwarze 1879: if (addcp == NULL)
1.52 schwarze 1880: continue;
1.131 schwarze 1881: if (*addcp == ASCII_NBRSP) {
1882: addcp = " ";
1883: addsz = 1;
1.52 schwarze 1884: }
1885: }
1.1 schwarze 1886:
1.47 schwarze 1887: /* Copy the rendered glyph into the stream. */
1.1 schwarze 1888:
1.131 schwarze 1889: ssz += addsz;
1890: dst = mandoc_realloc(dst, ssz + 1);
1891: memcpy(dst + dsz, addcp, addsz);
1892: dsz += addsz;
1893: }
1894: if (dst != NULL) {
1895: *public = dst;
1896: *psz = dsz;
1897: }
1898:
1899: /* Trim trailing whitespace and NUL-terminate. */
1900:
1901: while (*psz > 0 && (*public)[*psz - 1] == ' ')
1902: --*psz;
1903: if (dst != NULL) {
1904: (*public)[*psz] = '\0';
1.150 schwarze 1905: return 1;
1.131 schwarze 1906: } else
1.150 schwarze 1907: return 0;
1.1 schwarze 1908: }
1909:
1.75 schwarze 1910: static void
1911: dbadd_mlink(const struct mlink *mlink)
1912: {
1.173 schwarze 1913: dba_page_alias(mlink->mpage->dba, mlink->name, NAME_FILE);
1914: dba_page_add(mlink->mpage->dba, DBP_SECT, mlink->dsec);
1915: dba_page_add(mlink->mpage->dba, DBP_SECT, mlink->fsec);
1916: dba_page_add(mlink->mpage->dba, DBP_ARCH, mlink->arch);
1917: dba_page_add(mlink->mpage->dba, DBP_FILE, mlink->file);
1.75 schwarze 1918: }
1919:
1.11 schwarze 1920: /*
1.47 schwarze 1921: * Flush the current page's terms (and their bits) into the database.
1.53 schwarze 1922: * Also, handle escape sequences at the last possible moment.
1.11 schwarze 1923: */
1924: static void
1.173 schwarze 1925: dbadd(struct dba *dba, struct mpage *mpage)
1.11 schwarze 1926: {
1.47 schwarze 1927: struct mlink *mlink;
1928: struct str *key;
1.131 schwarze 1929: char *cp;
1.173 schwarze 1930: uint64_t mask;
1.47 schwarze 1931: size_t i;
1932: unsigned int slot;
1.131 schwarze 1933: int mustfree;
1.47 schwarze 1934:
1.85 schwarze 1935: mlink = mpage->mlinks;
1.11 schwarze 1936:
1.85 schwarze 1937: if (nodb) {
1.104 schwarze 1938: for (key = ohash_first(&names, &slot); NULL != key;
1.131 schwarze 1939: key = ohash_next(&names, &slot))
1.104 schwarze 1940: free(key);
1941: for (key = ohash_first(&strings, &slot); NULL != key;
1.131 schwarze 1942: key = ohash_next(&strings, &slot))
1.104 schwarze 1943: free(key);
1.102 schwarze 1944: if (0 == debug)
1945: return;
1.85 schwarze 1946: while (NULL != mlink) {
1947: fputs(mlink->name, stdout);
1948: if (NULL == mlink->next ||
1949: strcmp(mlink->dsec, mlink->next->dsec) ||
1950: strcmp(mlink->fsec, mlink->next->fsec) ||
1951: strcmp(mlink->arch, mlink->next->arch)) {
1952: putchar('(');
1953: if ('\0' == *mlink->dsec)
1954: fputs(mlink->fsec, stdout);
1955: else
1956: fputs(mlink->dsec, stdout);
1957: if ('\0' != *mlink->arch)
1958: printf("/%s", mlink->arch);
1959: putchar(')');
1960: }
1961: mlink = mlink->next;
1962: if (NULL != mlink)
1963: fputs(", ", stdout);
1964: }
1.89 schwarze 1965: printf(" - %s\n", mpage->desc);
1.11 schwarze 1966: return;
1.85 schwarze 1967: }
1968:
1969: if (debug)
1970: say(mlink->file, "Adding to database");
1.47 schwarze 1971:
1.131 schwarze 1972: cp = mpage->desc;
1973: i = strlen(cp);
1974: mustfree = render_string(&cp, &i);
1.176 schwarze 1975: mpage->dba = dba_page_new(dba->pages,
1.173 schwarze 1976: *mpage->arch == '\0' ? mlink->arch : mpage->arch,
1977: cp, mlink->file, mpage->form);
1.131 schwarze 1978: if (mustfree)
1979: free(cp);
1.176 schwarze 1980: dba_page_add(mpage->dba, DBP_SECT, mpage->sec);
1.47 schwarze 1981:
1.173 schwarze 1982: while (mlink != NULL) {
1.75 schwarze 1983: dbadd_mlink(mlink);
1.85 schwarze 1984: mlink = mlink->next;
1985: }
1.47 schwarze 1986:
1.90 schwarze 1987: for (key = ohash_first(&names, &slot); NULL != key;
1988: key = ohash_next(&names, &slot)) {
1989: assert(key->mpage == mpage);
1.173 schwarze 1990: dba_page_alias(mpage->dba, key->key, key->mask);
1.90 schwarze 1991: free(key);
1992: }
1.47 schwarze 1993: for (key = ohash_first(&strings, &slot); NULL != key;
1994: key = ohash_next(&strings, &slot)) {
1995: assert(key->mpage == mpage);
1.173 schwarze 1996: i = 0;
1997: for (mask = TYPE_Xr; mask <= TYPE_Lb; mask *= 2) {
1998: if (key->mask & mask)
1999: dba_macro_add(dba->macros, i,
2000: key->key, mpage->dba);
2001: i++;
2002: }
1.47 schwarze 2003: free(key);
1.33 schwarze 2004: }
1.47 schwarze 2005: }
1.41 deraadt 2006:
1.47 schwarze 2007: static void
1.173 schwarze 2008: dbprune(struct dba *dba)
1.47 schwarze 2009: {
1.173 schwarze 2010: struct dba_array *page, *files;
2011: char *file;
1.11 schwarze 2012:
1.173 schwarze 2013: dba_array_FOREACH(dba->pages, page) {
2014: files = dba_array_get(page, DBP_FILE);
2015: dba_array_FOREACH(files, file) {
2016: if (*file < ' ')
2017: file++;
2018: if (ohash_find(&mlinks, ohash_qlookup(&mlinks,
2019: file)) != NULL) {
2020: if (debug)
2021: say(file, "Deleting from database");
2022: dba_array_del(dba->pages);
2023: break;
2024: }
1.63 schwarze 2025: }
1.11 schwarze 2026: }
1.47 schwarze 2027: }
1.22 schwarze 2028:
1.47 schwarze 2029: /*
1.173 schwarze 2030: * Write the database from memory to disk.
1.47 schwarze 2031: */
2032: static void
1.173 schwarze 2033: dbwrite(struct dba *dba)
1.47 schwarze 2034: {
1.173 schwarze 2035: char tfn[32];
1.72 schwarze 2036: int status;
2037: pid_t child;
1.11 schwarze 2038:
1.173 schwarze 2039: if (dba_write(MANDOC_DB "~", dba) != -1) {
2040: if (rename(MANDOC_DB "~", MANDOC_DB) == -1) {
2041: exitcode = (int)MANDOCLEVEL_SYSERR;
2042: say(MANDOC_DB, "&rename");
2043: unlink(MANDOC_DB "~");
2044: }
1.47 schwarze 2045: return;
1.28 schwarze 2046: }
1.22 schwarze 2047:
1.173 schwarze 2048: (void)strlcpy(tfn, "/tmp/mandocdb.XXXXXXXX", sizeof(tfn));
2049: if (mkdtemp(tfn) == NULL) {
2050: exitcode = (int)MANDOCLEVEL_SYSERR;
2051: say("", "&%s", tfn);
1.47 schwarze 2052: return;
1.173 schwarze 2053: }
1.22 schwarze 2054:
1.173 schwarze 2055: (void)strlcat(tfn, "/" MANDOC_DB, sizeof(tfn));
2056: if (dba_write(tfn, dba) == -1) {
2057: exitcode = (int)MANDOCLEVEL_SYSERR;
2058: say(tfn, "&dba_write");
2059: goto out;
1.72 schwarze 2060: }
2061:
2062: switch (child = fork()) {
1.98 schwarze 2063: case -1:
1.72 schwarze 2064: exitcode = (int)MANDOCLEVEL_SYSERR;
1.80 schwarze 2065: say("", "&fork cmp");
1.72 schwarze 2066: return;
1.98 schwarze 2067: case 0:
1.173 schwarze 2068: execlp("cmp", "cmp", "-s", tfn, MANDOC_DB, (char *)NULL);
1.80 schwarze 2069: say("", "&exec cmp");
1.72 schwarze 2070: exit(0);
2071: default:
2072: break;
2073: }
1.173 schwarze 2074: if (waitpid(child, &status, 0) == -1) {
1.72 schwarze 2075: exitcode = (int)MANDOCLEVEL_SYSERR;
1.80 schwarze 2076: say("", "&wait cmp");
1.72 schwarze 2077: } else if (WIFSIGNALED(status)) {
2078: exitcode = (int)MANDOCLEVEL_SYSERR;
1.80 schwarze 2079: say("", "cmp died from signal %d", WTERMSIG(status));
1.72 schwarze 2080: } else if (WEXITSTATUS(status)) {
1.47 schwarze 2081: exitcode = (int)MANDOCLEVEL_SYSERR;
1.72 schwarze 2082: say(MANDOC_DB,
2083: "Data changed, but cannot replace database");
2084: }
2085:
1.173 schwarze 2086: out:
2087: *strrchr(tfn, '/') = '\0';
1.72 schwarze 2088: switch (child = fork()) {
1.98 schwarze 2089: case -1:
1.72 schwarze 2090: exitcode = (int)MANDOCLEVEL_SYSERR;
1.80 schwarze 2091: say("", "&fork rm");
1.72 schwarze 2092: return;
1.98 schwarze 2093: case 0:
1.173 schwarze 2094: execlp("rm", "rm", "-rf", tfn, (char *)NULL);
1.80 schwarze 2095: say("", "&exec rm");
1.72 schwarze 2096: exit((int)MANDOCLEVEL_SYSERR);
2097: default:
2098: break;
2099: }
1.173 schwarze 2100: if (waitpid(child, &status, 0) == -1) {
1.72 schwarze 2101: exitcode = (int)MANDOCLEVEL_SYSERR;
1.80 schwarze 2102: say("", "&wait rm");
1.72 schwarze 2103: } else if (WIFSIGNALED(status) || WEXITSTATUS(status)) {
2104: exitcode = (int)MANDOCLEVEL_SYSERR;
1.173 schwarze 2105: say("", "%s: Cannot remove temporary directory", tfn);
1.22 schwarze 2106: }
1.47 schwarze 2107: }
1.6 schwarze 2108:
1.47 schwarze 2109: static int
1.120 schwarze 2110: set_basedir(const char *targetdir, int report_baddir)
1.47 schwarze 2111: {
2112: static char startdir[PATH_MAX];
1.110 schwarze 2113: static int getcwd_status; /* 1 = ok, 2 = failure */
2114: static int chdir_status; /* 1 = changed directory */
1.109 schwarze 2115: char *cp;
1.6 schwarze 2116:
1.47 schwarze 2117: /*
1.110 schwarze 2118: * Remember the original working directory, if possible.
2119: * This will be needed if the second or a later directory
2120: * on the command line is given as a relative path.
2121: * Do not error out if the current directory is not
2122: * searchable: Maybe it won't be needed after all.
2123: */
2124: if (0 == getcwd_status) {
2125: if (NULL == getcwd(startdir, sizeof(startdir))) {
2126: getcwd_status = 2;
2127: (void)strlcpy(startdir, strerror(errno),
2128: sizeof(startdir));
2129: } else
2130: getcwd_status = 1;
2131: }
2132:
2133: /*
2134: * We are leaving the old base directory.
2135: * Do not use it any longer, not even for messages.
2136: */
2137: *basedir = '\0';
2138:
2139: /*
2140: * If and only if the directory was changed earlier and
2141: * the next directory to process is given as a relative path,
2142: * first go back, or bail out if that is impossible.
1.47 schwarze 2143: */
1.110 schwarze 2144: if (chdir_status && '/' != *targetdir) {
2145: if (2 == getcwd_status) {
1.47 schwarze 2146: exitcode = (int)MANDOCLEVEL_SYSERR;
1.110 schwarze 2147: say("", "getcwd: %s", startdir);
1.150 schwarze 2148: return 0;
1.47 schwarze 2149: }
1.110 schwarze 2150: if (-1 == chdir(startdir)) {
1.47 schwarze 2151: exitcode = (int)MANDOCLEVEL_SYSERR;
1.80 schwarze 2152: say("", "&chdir %s", startdir);
1.150 schwarze 2153: return 0;
1.2 schwarze 2154: }
2155: }
1.110 schwarze 2156:
2157: /*
2158: * Always resolve basedir to the canonicalized absolute
2159: * pathname and append a trailing slash, such that
2160: * we can reliably check whether files are inside.
2161: */
1.47 schwarze 2162: if (NULL == realpath(targetdir, basedir)) {
1.120 schwarze 2163: if (report_baddir || errno != ENOENT) {
2164: exitcode = (int)MANDOCLEVEL_BADARG;
2165: say("", "&%s: realpath", targetdir);
2166: }
1.150 schwarze 2167: return 0;
1.47 schwarze 2168: } else if (-1 == chdir(basedir)) {
1.120 schwarze 2169: if (report_baddir || errno != ENOENT) {
2170: exitcode = (int)MANDOCLEVEL_BADARG;
2171: say("", "&chdir");
2172: }
1.150 schwarze 2173: return 0;
1.109 schwarze 2174: }
1.110 schwarze 2175: chdir_status = 1;
1.109 schwarze 2176: cp = strchr(basedir, '\0');
2177: if ('/' != cp[-1]) {
2178: if (cp - basedir >= PATH_MAX - 1) {
2179: exitcode = (int)MANDOCLEVEL_SYSERR;
2180: say("", "Filename too long");
1.150 schwarze 2181: return 0;
1.109 schwarze 2182: }
2183: *cp++ = '/';
2184: *cp = '\0';
1.47 schwarze 2185: }
1.150 schwarze 2186: return 1;
1.2 schwarze 2187: }
2188:
2189: static void
1.47 schwarze 2190: say(const char *file, const char *format, ...)
1.2 schwarze 2191: {
1.47 schwarze 2192: va_list ap;
1.80 schwarze 2193: int use_errno;
1.2 schwarze 2194:
1.47 schwarze 2195: if ('\0' != *basedir)
2196: fprintf(stderr, "%s", basedir);
2197: if ('\0' != *basedir && '\0' != *file)
1.110 schwarze 2198: fputc('/', stderr);
1.47 schwarze 2199: if ('\0' != *file)
2200: fprintf(stderr, "%s", file);
1.31 schwarze 2201:
1.80 schwarze 2202: use_errno = 1;
2203: if (NULL != format) {
2204: switch (*format) {
1.98 schwarze 2205: case '&':
1.80 schwarze 2206: format++;
2207: break;
1.98 schwarze 2208: case '\0':
1.80 schwarze 2209: format = NULL;
2210: break;
2211: default:
2212: use_errno = 0;
2213: break;
2214: }
2215: }
2216: if (NULL != format) {
2217: if ('\0' != *basedir || '\0' != *file)
2218: fputs(": ", stderr);
2219: va_start(ap, format);
2220: vfprintf(stderr, format, ap);
2221: va_end(ap);
2222: }
2223: if (use_errno) {
2224: if ('\0' != *basedir || '\0' != *file || NULL != format)
2225: fputs(": ", stderr);
1.47 schwarze 2226: perror(NULL);
1.80 schwarze 2227: } else
2228: fputc('\n', stderr);
1.1 schwarze 2229: }