-/* $Id: mandocdb.c,v 1.209 2015/11/07 17:58:55 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.219 2016/07/15 18:03:45 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-2016 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
#else
#include "compat_fts.h"
#endif
-#include <getopt.h>
#include <limits.h>
+#if HAVE_SANDBOX_INIT
+#include <sandbox.h>
+#endif
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
uint64_t mask; /* set unless handler returns 0 */
};
+
+int mandocdb(int, char *[]);
+
static void dbclose(int);
static void dbadd(struct mpage *);
static void dbadd_mlink(const struct mlink *mlink);
const struct roff_node *);
static void parse_mdoc(struct mpage *, const struct roff_meta *,
const struct roff_node *);
-static int parse_mdoc_body(struct mpage *, const struct roff_meta *,
- const struct roff_node *);
static int parse_mdoc_head(struct mpage *, const struct roff_meta *,
const struct roff_node *);
static int parse_mdoc_Fd(struct mpage *, const struct roff_meta *,
const struct roff_node *);
static int parse_mdoc_Sh(struct mpage *, const struct roff_meta *,
const struct roff_node *);
+static int parse_mdoc_Va(struct mpage *, const struct roff_meta *,
+ const struct roff_node *);
static int parse_mdoc_Xr(struct mpage *, const struct roff_meta *,
const struct roff_node *);
static void putkey(const struct mpage *, char *, uint64_t);
{ NULL, TYPE_Pa }, /* Pa */
{ NULL, 0 }, /* Rv */
{ NULL, TYPE_St }, /* St */
- { NULL, TYPE_Va }, /* Va */
- { parse_mdoc_body, TYPE_Va }, /* Vt */
+ { parse_mdoc_Va, TYPE_Va }, /* Va */
+ { parse_mdoc_Va, TYPE_Vt }, /* Vt */
{ parse_mdoc_Xr, 0 }, /* Xr */
{ NULL, 0 }, /* %A */
{ NULL, 0 }, /* %B */
#if HAVE_PLEDGE
if (pledge("stdio rpath wpath cpath fattr flock proc exec", NULL) == -1) {
- perror("pledge");
+ warn("pledge");
+ return (int)MANDOCLEVEL_SYSERR;
+ }
+#endif
+
+#if HAVE_SANDBOX_INIT
+ if (sandbox_init(kSBXProfileNoInternet, SANDBOX_NAMED, NULL) == -1) {
+ warnx("sandbox_init");
return (int)MANDOCLEVEL_SYSERR;
}
#endif
argv += optind;
#if HAVE_PLEDGE
- if (nodb && pledge("stdio rpath", NULL) == -1) {
- perror("pledge");
- return (int)MANDOCLEVEL_SYSERR;
+ if (nodb) {
+ if (pledge("stdio rpath", NULL) == -1) {
+ warn("pledge");
+ return (int)MANDOCLEVEL_SYSERR;
+ }
}
#endif
* all files specified on the command-line.
*/
#if HAVE_PLEDGE
- if (!nodb && pledge("stdio rpath wpath cpath fattr flock",
- NULL) == -1) {
- perror("pledge");
- exitcode = (int)MANDOCLEVEL_SYSERR;
- goto out;
+ if (!nodb) {
+ if (pledge("stdio rpath wpath cpath fattr flock", NULL) == -1) {
+ warn("pledge");
+ exitcode = (int)MANDOCLEVEL_SYSERR;
+ goto out;
+ }
}
#endif
use_all = 1;
* or
* [./]cat<section>[/<arch>]/<name>.0
*
- * TODO: accomodate for multi-language directories.
+ * TODO: accommodate for multi-language directories.
*/
static int
treescan(void)
man = NULL;
sodest = NULL;
- mparse_open(mp, &fd, mlink->file);
- if (fd == -1) {
+ if ((fd = mparse_open(mp, mlink->file)) == -1) {
say(mlink->file, "&open");
goto nextpage;
}
*/
if (mlink->dform != FORM_CAT || mlink->fform != FORM_CAT) {
mparse_readfd(mp, fd, mlink->file);
+ close(fd);
mparse_result(mp, &man, &sodest);
}
char byte;
size_t sz;
- if (NULL == n)
+ if (n == NULL)
return;
/*
if (n->type == ROFFT_BODY && n->tok == MAN_SH) {
body = n;
- assert(body->parent);
- if (NULL != (head = body->parent->head) &&
- 1 == head->nchild &&
- NULL != (head = (head->child)) &&
+ if ((head = body->parent->head) != NULL &&
+ (head = head->child) != NULL &&
+ head->next == NULL &&
head->type == ROFFT_TEXT &&
- 0 == strcmp(head->string, "NAME") &&
- NULL != body->child) {
+ strcmp(head->string, "NAME") == 0 &&
+ body->child != NULL) {
/*
* Suck the entire NAME section into memory.
return 0;
}
+static int
+parse_mdoc_Va(struct mpage *mpage, const struct roff_meta *meta,
+ const struct roff_node *n)
+{
+ char *cp;
+
+ if (n->type != ROFFT_ELEM && n->type != ROFFT_BODY)
+ return 0;
+
+ if (n->child != NULL &&
+ n->child->next == NULL &&
+ n->child->type == ROFFT_TEXT)
+ return 1;
+
+ cp = NULL;
+ deroff(&cp, n);
+ if (cp != NULL) {
+ putkey(mpage, cp, TYPE_Vt | (n->tok == MDOC_Va ||
+ n->type == ROFFT_BODY ? TYPE_Va : 0));
+ free(cp);
+ }
+
+ return 0;
+}
+
static int
parse_mdoc_Xr(struct mpage *mpage, const struct roff_meta *meta,
const struct roff_node *n)
return n->type == ROFFT_HEAD;
}
-static int
-parse_mdoc_body(struct mpage *mpage, const struct roff_meta *meta,
- const struct roff_node *n)
-{
-
- return n->type == ROFFT_BODY;
-}
-
/*
* Add a string to the hash table for the current manual.
* Each string has a bitmask telling which macros it belongs to.