=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mandocdb.c,v retrieving revision 1.97 retrieving revision 1.98 diff -c -r1.97 -r1.98 *** src/usr.bin/mandoc/mandocdb.c 2014/04/19 02:55:44 1.97 --- src/usr.bin/mandoc/mandocdb.c 2014/04/20 16:44:44 1.98 *************** *** 1,4 **** ! /* $Id: mandocdb.c,v 1.97 2014/04/19 02:55:44 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze --- 1,4 ---- ! /* $Id: mandocdb.c,v 1.98 2014/04/20 16:44:44 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze *************** *** 172,183 **** 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 write_utf8; /* write UTF-8 output; else ASCII */ static int exitcode; /* to be returned by main */ ! 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 */ --- 172,183 ---- 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 write_utf8; /* write UTF-8 output; else ASCII */ static int exitcode; /* to be returned by main */ ! 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 */ *************** *** 312,317 **** --- 312,318 ---- { NULL, 0 }, /* Ta */ }; + int mandocdb(int argc, char *argv[]) { *************** *** 340,346 **** ++progname; /* ! * We accept a few different invocations. * The CHECKOP macro makes sure that invocation styles don't * clobber each other. */ --- 341,347 ---- ++progname; /* ! * We accept a few different invocations. * The CHECKOP macro makes sure that invocation styles don't * clobber each other. */ *************** *** 355,386 **** while (-1 != (ch = getopt(argc, argv, "aC:Dd:npQT:tu:v"))) switch (ch) { ! case ('a'): use_all = 1; break; ! case ('C'): CHECKOP(op, ch); path_arg = optarg; op = OP_CONFFILE; break; ! case ('D'): debug++; break; ! case ('d'): CHECKOP(op, ch); path_arg = optarg; op = OP_UPDATE; break; ! case ('n'): nodb = 1; break; ! case ('p'): warnings = 1; break; ! case ('Q'): mparse_options |= MPARSE_QUICK; break; ! case ('T'): if (strcmp(optarg, "utf8")) { fprintf(stderr, "-T%s: Unsupported " "output format\n", optarg); --- 356,387 ---- while (-1 != (ch = getopt(argc, argv, "aC:Dd:npQT:tu:v"))) switch (ch) { ! case 'a': use_all = 1; break; ! case 'C': CHECKOP(op, ch); path_arg = optarg; op = OP_CONFFILE; break; ! case 'D': debug++; break; ! case 'd': CHECKOP(op, ch); path_arg = optarg; op = OP_UPDATE; break; ! case 'n': nodb = 1; break; ! case 'p': warnings = 1; break; ! case 'Q': mparse_options |= MPARSE_QUICK; break; ! case 'T': if (strcmp(optarg, "utf8")) { fprintf(stderr, "-T%s: Unsupported " "output format\n", optarg); *************** *** 388,405 **** } write_utf8 = 1; break; ! case ('t'): CHECKOP(op, ch); dup2(STDOUT_FILENO, STDERR_FILENO); op = OP_TEST; nodb = warnings = 1; break; ! case ('u'): CHECKOP(op, ch); path_arg = optarg; op = OP_DELETE; break; ! case ('v'): /* Compatibility with espie@'s makewhatis. */ break; default: --- 389,406 ---- } write_utf8 = 1; break; ! case 't': CHECKOP(op, ch); dup2(STDOUT_FILENO, STDERR_FILENO); op = OP_TEST; nodb = warnings = 1; break; ! case 'u': CHECKOP(op, ch); path_arg = optarg; op = OP_DELETE; break; ! case 'v': /* Compatibility with espie@'s makewhatis. */ break; default: *************** *** 462,469 **** * manpath_parse() wants to do it. */ if (argc > 0) { ! 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]); --- 463,470 ---- * manpath_parse() wants to do it. */ if (argc > 0) { ! 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]); *************** *** 530,536 **** " %s [-DnpQ] [-Tutf8] -d dir [file ...]\n" " %s [-Dnp] -u dir [file ...]\n" " %s [-Q] -t file ...\n", ! progname, progname, progname, progname, progname); return((int)MANDOCLEVEL_BADARG); --- 531,537 ---- " %s [-DnpQ] [-Tutf8] -d dir [file ...]\n" " %s [-Dnp] -u dir [file ...]\n" " %s [-Q] -t file ...\n", ! progname, progname, progname, progname, progname); return((int)MANDOCLEVEL_BADARG); *************** *** 544,550 **** * If use_all has been specified, grok all files. * If not, sanitise paths to the following: * ! * [./]man*[/]/.
* or * [./]cat
[/]/.0 * --- 545,551 ---- * If use_all has been specified, grok all files. * If not, sanitise paths to the following: * ! * [./]man*[/]/.
* or * [./]cat
[/]/.0 * *************** *** 584,590 **** * Symbolic links require various sanity checks, * then get handled just like regular files. */ ! case (FTS_SL): if (NULL == realpath(path, buf)) { if (warnings) say(path, "&realpath"); --- 585,591 ---- * Symbolic links require various sanity checks, * then get handled just like regular files. */ ! case FTS_SL: if (NULL == realpath(path, buf)) { if (warnings) say(path, "&realpath"); *************** *** 607,613 **** * If we're a regular file, add an mlink by using the * stored directory data and handling the filename. */ ! case (FTS_F): if (0 == strcmp(path, MANDOC_DB)) continue; if ( ! use_all && ff->fts_level < 2) { --- 608,614 ---- * If we're a regular file, add an mlink by using the * stored directory data and handling the filename. */ ! case FTS_F: if (0 == strcmp(path, MANDOC_DB)) continue; if ( ! use_all && ff->fts_level < 2) { *************** *** 664,672 **** mlink_add(mlink, ff->fts_statp); continue; ! case (FTS_D): /* FALLTHROUGH */ ! case (FTS_DP): break; default: --- 665,673 ---- mlink_add(mlink, ff->fts_statp); continue; ! case FTS_D: /* FALLTHROUGH */ ! case FTS_DP: break; default: *************** *** 676,685 **** } switch (ff->fts_level) { ! case (0): /* Ignore the root directory. */ break; ! case (1): /* * This might contain manX/ or catX/. * Try to infer this from the name. --- 677,686 ---- } switch (ff->fts_level) { ! case 0: /* Ignore the root directory. */ break; ! case 1: /* * This might contain manX/ or catX/. * Try to infer this from the name. *************** *** 700,713 **** dsec = NULL; } ! if (NULL != dsec || use_all) break; if (warnings) say(path, "Unknown directory part"); fts_set(f, ff, FTS_SKIP); break; ! case (2): /* * Possibly our architecture. * If we're descending, keep tabs on it. --- 701,714 ---- dsec = NULL; } ! if (NULL != dsec || use_all) break; if (warnings) say(path, "Unknown directory part"); fts_set(f, ff, FTS_SKIP); break; ! case 2: /* * Possibly our architecture. * If we're descending, keep tabs on it. *************** *** 739,745 **** * Try to infer the manual section, architecture, and page name from the * path, assuming it looks like * ! * [./]man*[/]/.
* or * [./]cat
[/]/.0 * --- 740,746 ---- * Try to infer the manual section, architecture, and page name from the * path, assuming it looks like * ! * [./]man*[/]/.
* or * [./]cat
[/]/.0 * *************** *** 976,982 **** *++bufp = '\0'; strlcat(buf, mlink->dsec, PATH_MAX); if (NULL == ohash_find(&mlinks, ! ohash_qlookup(&mlinks, buf))) goto nextlink; if (warnings) say(mlink->file, "Man source exists: %s", buf); --- 977,983 ---- *++bufp = '\0'; strlcat(buf, mlink->dsec, PATH_MAX); if (NULL == ohash_find(&mlinks, ! ohash_qlookup(&mlinks, buf))) goto nextlink; if (warnings) say(mlink->file, "Man source exists: %s", buf); *************** *** 1105,1118 **** goto nextpage; } switch (child_pid = fork()) { ! 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): close(fd[0]); if (-1 == dup2(fd[1], STDOUT_FILENO)) { say(mpage->mlinks->file, --- 1106,1119 ---- goto nextpage; } switch (child_pid = fork()) { ! 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: close(fd[0]); if (-1 == dup2(fd[1], STDOUT_FILENO)) { say(mpage->mlinks->file, *************** *** 1327,1333 **** 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, --- 1328,1334 ---- 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, *************** *** 1397,1403 **** if (0 == len) { memmove(line, line + 1, plen--); continue; ! } memmove(line - 1, line + 1, plen - len); plen -= 2; } --- 1398,1404 ---- if (0 == len) { memmove(line, line + 1, plen--); continue; ! } memmove(line - 1, line + 1, plen - len); plen -= 2; } *************** *** 1461,1471 **** 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) { /* * Suck the entire NAME section into memory. --- 1462,1472 ---- 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) { /* * Suck the entire NAME section into memory. *************** *** 1479,1485 **** 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 --- 1480,1486 ---- 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 *************** *** 1561,1575 **** assert(NULL != n); for (n = n->child; NULL != n; n = n->next) { switch (n->type) { ! case (MDOC_ELEM): /* FALLTHROUGH */ ! case (MDOC_BLOCK): /* FALLTHROUGH */ ! case (MDOC_HEAD): /* FALLTHROUGH */ ! case (MDOC_BODY): /* FALLTHROUGH */ ! case (MDOC_TAIL): if (NULL != mdocs[n->tok].fp) if (0 == (*mdocs[n->tok].fp)(mpage, n)) break; --- 1562,1576 ---- assert(NULL != n); for (n = n->child; NULL != n; n = n->next) { switch (n->type) { ! case MDOC_ELEM: /* FALLTHROUGH */ ! case MDOC_BLOCK: /* FALLTHROUGH */ ! case MDOC_HEAD: /* FALLTHROUGH */ ! case MDOC_BODY: /* FALLTHROUGH */ ! case MDOC_TAIL: if (NULL != mdocs[n->tok].fp) if (0 == (*mdocs[n->tok].fp)(mpage, n)) break; *************** *** 1593,1600 **** size_t sz; if (SEC_SYNOPSIS != n->sec || ! NULL == (n = n->child) || ! MDOC_TEXT != n->type) return(0); /* --- 1594,1601 ---- size_t sz; if (SEC_SYNOPSIS != n->sec || ! NULL == (n = n->child) || ! MDOC_TEXT != n->type) return(0); /* *************** *** 1637,1647 **** if (NULL == (n = n->child) || MDOC_TEXT != n->type) return(0); ! /* * Parse: .Fn "struct type *name" "char *arg". ! * First strip away pointer symbol. * Then store the function name, then type. ! * Finally, store the arguments. */ if (NULL == (cp = strrchr(n->string, ' '))) --- 1638,1648 ---- if (NULL == (n = n->child) || MDOC_TEXT != n->type) return(0); ! /* * Parse: .Fn "struct type *name" "char *arg". ! * First strip away pointer symbol. * Then store the function name, then type. ! * Finally, store the arguments. */ if (NULL == (cp = strrchr(n->string, ' '))) *************** *** 1858,1864 **** if (strcspn(val, res) == bsz) { key->rendered = key->key; return; ! } /* Pre-allocate by the length of the input */ --- 1859,1865 ---- if (strcspn(val, res) == bsz) { key->rendered = key->key; return; ! } /* Pre-allocate by the length of the input */ *************** *** 1878,1894 **** } switch (*val) { ! case (ASCII_HYPH): buf[pos++] = '-'; val++; continue; ! case ('\t'): /* FALLTHROUGH */ ! case (ASCII_NBRSP): buf[pos++] = ' '; val++; /* FALLTHROUGH */ ! case (ASCII_BREAK): continue; default: break; --- 1879,1895 ---- } switch (*val) { ! case ASCII_HYPH: buf[pos++] = '-'; val++; continue; ! case '\t': /* FALLTHROUGH */ ! case ASCII_NBRSP: buf[pos++] = ' '; val++; /* FALLTHROUGH */ ! case ASCII_BREAK: continue; default: break; *************** *** 1905,1912 **** * predefined character or special character. */ ! esc = mandoc_escape ! ((const char **)&val, &seq, &len); if (ESCAPE_ERROR == esc) break; if (ESCAPE_SPECIAL != esc) --- 1906,1913 ---- * predefined character or special character. */ ! esc = mandoc_escape((const char **)&val, ! &seq, &len); if (ESCAPE_ERROR == esc) break; if (ESCAPE_SPECIAL != esc) *************** *** 2117,2127 **** } switch (child = fork()) { ! case (-1): exitcode = (int)MANDOCLEVEL_SYSERR; say("", "&fork cmp"); return; ! case (0): execlp("cmp", "cmp", "-s", tempfilename, MANDOC_DB, NULL); say("", "&exec cmp"); --- 2118,2128 ---- } switch (child = fork()) { ! case -1: exitcode = (int)MANDOCLEVEL_SYSERR; say("", "&fork cmp"); return; ! case 0: execlp("cmp", "cmp", "-s", tempfilename, MANDOC_DB, NULL); say("", "&exec cmp"); *************** *** 2143,2153 **** *strrchr(tempfilename, '/') = '\0'; switch (child = fork()) { ! case (-1): exitcode = (int)MANDOCLEVEL_SYSERR; say("", "&fork rm"); return; ! case (0): execlp("rm", "rm", "-rf", tempfilename, NULL); say("", "&exec rm"); exit((int)MANDOCLEVEL_SYSERR); --- 2144,2154 ---- *strrchr(tempfilename, '/') = '\0'; switch (child = fork()) { ! case -1: exitcode = (int)MANDOCLEVEL_SYSERR; say("", "&fork rm"); return; ! case 0: execlp("rm", "rm", "-rf", tempfilename, NULL); say("", "&exec rm"); exit((int)MANDOCLEVEL_SYSERR); *************** *** 2178,2184 **** const char *sql; int rc, ofl; ! if (nodb) return(1); *tempfilename = '\0'; --- 2179,2185 ---- const char *sql; int rc, ofl; ! if (nodb) return(1); *tempfilename = '\0'; *************** *** 2198,2204 **** remove(MANDOC_DB "~"); rc = sqlite3_open_v2(MANDOC_DB "~", &db, ofl, NULL); ! if (SQLITE_OK == rc) goto create_tables; if (MPARSE_QUICK & mparse_options) { exitcode = (int)MANDOCLEVEL_SYSERR; --- 2199,2205 ---- remove(MANDOC_DB "~"); rc = sqlite3_open_v2(MANDOC_DB "~", &db, ofl, NULL); ! if (SQLITE_OK == rc) goto create_tables; if (MPARSE_QUICK & mparse_options) { exitcode = (int)MANDOCLEVEL_SYSERR; *************** *** 2389,2398 **** use_errno = 1; if (NULL != format) { switch (*format) { ! case ('&'): format++; break; ! case ('\0'): format = NULL; break; default: --- 2390,2399 ---- use_errno = 1; if (NULL != format) { switch (*format) { ! case '&': format++; break; ! case '\0': format = NULL; break; default: