aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandocdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c133
1 files changed, 67 insertions, 66 deletions
diff --git a/mandocdb.c b/mandocdb.c
index 68a0294c..0fc16443 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.140 2014/04/19 02:56:54 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.141 2014/04/20 16:46:04 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -180,12 +180,12 @@ static char tempfilename[32];
static char *progname;
static int nodb; /* no database changes */
static int mparse_options; /* abort the parse early */
-static int use_all; /* use all found files */
-static int debug; /* print what we're doing */
-static int warnings; /* warn about crap */
+static int use_all; /* use all found files */
+static int debug; /* print what we're doing */
+static int warnings; /* warn about crap */
static int write_utf8; /* write UTF-8 output; else ASCII */
static int exitcode; /* to be returned by main */
-static enum op op; /* operational mode */
+static enum op op; /* operational mode */
static char basedir[PATH_MAX]; /* current base directory */
static struct ohash mpages; /* table of distinct manual pages */
static struct ohash mlinks; /* table of directory entries */
@@ -320,6 +320,7 @@ static const struct mdoc_handler mdocs[MDOC_MAX] = {
{ NULL, 0 }, /* Ta */
};
+
int
main(int argc, char *argv[])
{
@@ -348,7 +349,7 @@ main(int argc, char *argv[])
++progname;
/*
- * We accept a few different invocations.
+ * We accept a few different invocations.
* The CHECKOP macro makes sure that invocation styles don't
* clobber each other.
*/
@@ -363,32 +364,32 @@ main(int argc, char *argv[])
while (-1 != (ch = getopt(argc, argv, "aC:Dd:npQT:tu:v")))
switch (ch) {
- case ('a'):
+ case 'a':
use_all = 1;
break;
- case ('C'):
+ case 'C':
CHECKOP(op, ch);
path_arg = optarg;
op = OP_CONFFILE;
break;
- case ('D'):
+ case 'D':
debug++;
break;
- case ('d'):
+ case 'd':
CHECKOP(op, ch);
path_arg = optarg;
op = OP_UPDATE;
break;
- case ('n'):
+ case 'n':
nodb = 1;
break;
- case ('p'):
+ case 'p':
warnings = 1;
break;
- case ('Q'):
+ case 'Q':
mparse_options |= MPARSE_QUICK;
break;
- case ('T'):
+ case 'T':
if (strcmp(optarg, "utf8")) {
fprintf(stderr, "-T%s: Unsupported "
"output format\n", optarg);
@@ -396,18 +397,18 @@ main(int argc, char *argv[])
}
write_utf8 = 1;
break;
- case ('t'):
+ case 't':
CHECKOP(op, ch);
dup2(STDOUT_FILENO, STDERR_FILENO);
op = OP_TEST;
nodb = warnings = 1;
break;
- case ('u'):
+ case 'u':
CHECKOP(op, ch);
path_arg = optarg;
op = OP_DELETE;
break;
- case ('v'):
+ case 'v':
/* Compatibility with espie@'s makewhatis. */
break;
default:
@@ -470,8 +471,8 @@ main(int argc, char *argv[])
* manpath_parse() wants to do it.
*/
if (argc > 0) {
- dirs.paths = mandoc_calloc
- (argc, sizeof(char *));
+ dirs.paths = mandoc_calloc(argc,
+ sizeof(char *));
dirs.sz = (size_t)argc;
for (i = 0; i < argc; i++)
dirs.paths[i] = mandoc_strdup(argv[i]);
@@ -538,7 +539,7 @@ usage:
" %s [-DnpQ] [-Tutf8] -d dir [file ...]\n"
" %s [-Dnp] -u dir [file ...]\n"
" %s [-Q] -t file ...\n",
- progname, progname, progname,
+ progname, progname, progname,
progname, progname);
return((int)MANDOCLEVEL_BADARG);
@@ -552,7 +553,7 @@ usage:
* If use_all has been specified, grok all files.
* If not, sanitise paths to the following:
*
- * [./]man*[/<arch>]/<name>.<section>
+ * [./]man*[/<arch>]/<name>.<section>
* or
* [./]cat<section>[/<arch>]/<name>.0
*
@@ -592,7 +593,7 @@ treescan(void)
* Symbolic links require various sanity checks,
* then get handled just like regular files.
*/
- case (FTS_SL):
+ case FTS_SL:
if (NULL == realpath(path, buf)) {
if (warnings)
say(path, "&realpath");
@@ -615,7 +616,7 @@ treescan(void)
* If we're a regular file, add an mlink by using the
* stored directory data and handling the filename.
*/
- case (FTS_F):
+ case FTS_F:
if (0 == strcmp(path, MANDOC_DB))
continue;
if ( ! use_all && ff->fts_level < 2) {
@@ -672,9 +673,9 @@ treescan(void)
mlink_add(mlink, ff->fts_statp);
continue;
- case (FTS_D):
+ case FTS_D:
/* FALLTHROUGH */
- case (FTS_DP):
+ case FTS_DP:
break;
default:
@@ -684,10 +685,10 @@ treescan(void)
}
switch (ff->fts_level) {
- case (0):
+ case 0:
/* Ignore the root directory. */
break;
- case (1):
+ case 1:
/*
* This might contain manX/ or catX/.
* Try to infer this from the name.
@@ -708,14 +709,14 @@ treescan(void)
dsec = NULL;
}
- if (NULL != dsec || use_all)
+ if (NULL != dsec || use_all)
break;
if (warnings)
say(path, "Unknown directory part");
fts_set(f, ff, FTS_SKIP);
break;
- case (2):
+ case 2:
/*
* Possibly our architecture.
* If we're descending, keep tabs on it.
@@ -747,7 +748,7 @@ treescan(void)
* Try to infer the manual section, architecture, and page name from the
* path, assuming it looks like
*
- * [./]man*[/<arch>]/<name>.<section>
+ * [./]man*[/<arch>]/<name>.<section>
* or
* [./]cat<section>[/<arch>]/<name>.0
*
@@ -984,7 +985,7 @@ mlinks_undupe(struct mpage *mpage)
*++bufp = '\0';
strlcat(buf, mlink->dsec, PATH_MAX);
if (NULL == ohash_find(&mlinks,
- ohash_qlookup(&mlinks, buf)))
+ ohash_qlookup(&mlinks, buf)))
goto nextlink;
if (warnings)
say(mlink->file, "Man source exists: %s", buf);
@@ -1113,14 +1114,14 @@ mpages_merge(struct mchars *mc, struct mparse *mp)
goto nextpage;
}
switch (child_pid = fork()) {
- case (-1):
+ case -1:
exitcode = (int)MANDOCLEVEL_SYSERR;
say(mpage->mlinks->file, "&fork gunzip");
child_pid = 0;
close(fd[1]);
close(fd[0]);
goto nextpage;
- case (0):
+ case 0:
close(fd[0]);
if (-1 == dup2(fd[1], STDOUT_FILENO)) {
say(mpage->mlinks->file,
@@ -1335,7 +1336,7 @@ parse_cat(struct mpage *mpage, int fd)
while (NULL != (line = fgetln(stream, &len)))
if ('\n' != *line && ' ' != *line)
break;
-
+
/*
* Read up until the next section into a buffer.
* Strip the leading and trailing newline from each read line,
@@ -1405,7 +1406,7 @@ parse_cat(struct mpage *mpage, int fd)
if (0 == len) {
memmove(line, line + 1, plen--);
continue;
- }
+ }
memmove(line - 1, line + 1, plen - len);
plen -= 2;
}
@@ -1469,11 +1470,11 @@ parse_man(struct mpage *mpage, const struct man_node *n)
body = n;
assert(body->parent);
if (NULL != (head = body->parent->head) &&
- 1 == head->nchild &&
- NULL != (head = (head->child)) &&
- MAN_TEXT == head->type &&
- 0 == strcmp(head->string, "NAME") &&
- NULL != body->child) {
+ 1 == head->nchild &&
+ NULL != (head = (head->child)) &&
+ MAN_TEXT == head->type &&
+ 0 == strcmp(head->string, "NAME") &&
+ NULL != body->child) {
/*
* Suck the entire NAME section into memory.
@@ -1487,7 +1488,7 @@ parse_man(struct mpage *mpage, const struct man_node *n)
if (NULL == title)
return;
- /*
+ /*
* Go through a special heuristic dance here.
* Conventionally, one or more manual names are
* comma-specified prior to a whitespace, then a
@@ -1569,15 +1570,15 @@ parse_mdoc(struct mpage *mpage, const struct mdoc_node *n)
assert(NULL != n);
for (n = n->child; NULL != n; n = n->next) {
switch (n->type) {
- case (MDOC_ELEM):
+ case MDOC_ELEM:
/* FALLTHROUGH */
- case (MDOC_BLOCK):
+ case MDOC_BLOCK:
/* FALLTHROUGH */
- case (MDOC_HEAD):
+ case MDOC_HEAD:
/* FALLTHROUGH */
- case (MDOC_BODY):
+ case MDOC_BODY:
/* FALLTHROUGH */
- case (MDOC_TAIL):
+ case MDOC_TAIL:
if (NULL != mdocs[n->tok].fp)
if (0 == (*mdocs[n->tok].fp)(mpage, n))
break;
@@ -1601,8 +1602,8 @@ parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_node *n)
size_t sz;
if (SEC_SYNOPSIS != n->sec ||
- NULL == (n = n->child) ||
- MDOC_TEXT != n->type)
+ NULL == (n = n->child) ||
+ MDOC_TEXT != n->type)
return(0);
/*
@@ -1645,11 +1646,11 @@ parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_node *n)
if (NULL == (n = n->child) || MDOC_TEXT != n->type)
return(0);
- /*
+ /*
* Parse: .Fn "struct type *name" "char *arg".
- * First strip away pointer symbol.
+ * First strip away pointer symbol.
* Then store the function name, then type.
- * Finally, store the arguments.
+ * Finally, store the arguments.
*/
if (NULL == (cp = strrchr(n->string, ' ')))
@@ -1866,7 +1867,7 @@ render_key(struct mchars *mc, struct str *key)
if (strcspn(val, res) == bsz) {
key->rendered = key->key;
return;
- }
+ }
/* Pre-allocate by the length of the input */
@@ -1886,17 +1887,17 @@ render_key(struct mchars *mc, struct str *key)
}
switch (*val) {
- case (ASCII_HYPH):
+ case ASCII_HYPH:
buf[pos++] = '-';
val++;
continue;
- case ('\t'):
+ case '\t':
/* FALLTHROUGH */
- case (ASCII_NBRSP):
+ case ASCII_NBRSP:
buf[pos++] = ' ';
val++;
/* FALLTHROUGH */
- case (ASCII_BREAK):
+ case ASCII_BREAK:
continue;
default:
break;
@@ -1913,8 +1914,8 @@ render_key(struct mchars *mc, struct str *key)
* predefined character or special character.
*/
- esc = mandoc_escape
- ((const char **)&val, &seq, &len);
+ esc = mandoc_escape((const char **)&val,
+ &seq, &len);
if (ESCAPE_ERROR == esc)
break;
if (ESCAPE_SPECIAL != esc)
@@ -2125,11 +2126,11 @@ dbclose(int real)
}
switch (child = fork()) {
- case (-1):
+ case -1:
exitcode = (int)MANDOCLEVEL_SYSERR;
say("", "&fork cmp");
return;
- case (0):
+ case 0:
execlp("cmp", "cmp", "-s",
tempfilename, MANDOC_DB, NULL);
say("", "&exec cmp");
@@ -2151,11 +2152,11 @@ dbclose(int real)
*strrchr(tempfilename, '/') = '\0';
switch (child = fork()) {
- case (-1):
+ case -1:
exitcode = (int)MANDOCLEVEL_SYSERR;
say("", "&fork rm");
return;
- case (0):
+ case 0:
execlp("rm", "rm", "-rf", tempfilename, NULL);
say("", "&exec rm");
exit((int)MANDOCLEVEL_SYSERR);
@@ -2186,7 +2187,7 @@ dbopen(int real)
const char *sql;
int rc, ofl;
- if (nodb)
+ if (nodb)
return(1);
*tempfilename = '\0';
@@ -2206,7 +2207,7 @@ dbopen(int real)
remove(MANDOC_DB "~");
rc = sqlite3_open_v2(MANDOC_DB "~", &db, ofl, NULL);
- if (SQLITE_OK == rc)
+ if (SQLITE_OK == rc)
goto create_tables;
if (MPARSE_QUICK & mparse_options) {
exitcode = (int)MANDOCLEVEL_SYSERR;
@@ -2399,10 +2400,10 @@ say(const char *file, const char *format, ...)
use_errno = 1;
if (NULL != format) {
switch (*format) {
- case ('&'):
+ case '&':
format++;
break;
- case ('\0'):
+ case '\0':
format = NULL;
break;
default: