diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2011-11-26 22:38:11 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2011-11-26 22:38:11 +0000 |
commit | edb836f226a3e9d500cba400695648b0a3ee6585 (patch) | |
tree | 9bac1273d1f20dec6c26f4b7dc1eec6b498342c7 | |
parent | 0aba7e883febd4a1eb4d3f54a32041eccd254290 (diff) | |
download | mandoc-edb836f226a3e9d500cba400695648b0a3ee6585.tar.gz |
Sync to OpenBSD, mostly gratuitous and whitespace differences,
but a few serious things as well:
* -M overrides MANPATH
* -m prepends to the path
* put back database close calls that got lost in mandocdb
* missing sys/types.h in manpath.c, needed for size_t
ok kristaps@
-rw-r--r-- | apropos.1 | 6 | ||||
-rw-r--r-- | apropos.c | 18 | ||||
-rw-r--r-- | apropos_db.c | 53 | ||||
-rw-r--r-- | apropos_db.h | 8 | ||||
-rw-r--r-- | mandocdb.c | 13 | ||||
-rw-r--r-- | manpath.c | 17 |
6 files changed, 61 insertions, 54 deletions
@@ -44,7 +44,7 @@ searched for databases. Invalid paths, or paths without manual databases, are ignored. .It Fl m Ar manpath -Append the colon-separated paths to the list of paths searched +Prepend the colon-separated paths to the list of paths searched for .Xr mandocdb 8 databases. @@ -154,10 +154,10 @@ If an architecture is specified in the output, use .Sh ENVIRONMENT .Bl -tag -width Ds .It Ev MANPATH -Comma-separated paths overriding the default list of paths searched for +Colon-separated paths overriding the default list of paths searched for manual databases. Invalid paths, or paths without manual databases, are ignored. -Takes precedence over +Overridden by .Fl M . .El .\" .Sh FILES @@ -20,7 +20,6 @@ #endif #include <assert.h> -#include <ctype.h> #include <getopt.h> #include <stdio.h> #include <stdlib.h> @@ -61,7 +60,7 @@ main(int argc, char *argv[]) e = NULL; rc = 0; - while (-1 != (ch = getopt(argc, argv, "M:m:S:s:"))) + while (-1 != (ch = getopt(argc, argv, "M:m:S:s:"))) switch (ch) { case ('M'): defpaths = optarg; @@ -96,10 +95,10 @@ main(int argc, char *argv[]) } rc = apropos_search - (paths.sz, paths.paths, + (paths.sz, paths.paths, &opts, e, terms, NULL, list); - if (0 == rc) + if (0 == rc) fprintf(stderr, "%s: Error reading " "manual database\n", progname); @@ -119,8 +118,8 @@ list(struct res *res, size_t sz, void *arg) qsort(res, sz, sizeof(struct res), cmp); for (i = 0; i < (int)sz; i++) - printf("%s(%s%s%s) - %s\n", res[i].title, - res[i].cat, + printf("%s(%s%s%s) - %s\n", res[i].title, + res[i].cat, *res[i].arch ? "/" : "", *res[i].arch ? res[i].arch : "", res[i].desc); @@ -139,9 +138,10 @@ usage(void) { fprintf(stderr, "usage: %s " - "[-M dirs] " - "[-m dirs] " + "[-M path] " + "[-m path] " "[-S arch] " "[-s section] " - "expression...\n", progname); + "expression...\n", + progname); } diff --git a/apropos_db.c b/apropos_db.c index c3affea4..fd302d87 100644 --- a/apropos_db.c +++ b/apropos_db.c @@ -115,12 +115,12 @@ static const struct type types[] = { }; static DB *btree_open(void); -static int btree_read(const DBT *, +static int btree_read(const DBT *, const struct mchars *, char **); static int expreval(const struct expr *, int *); -static void exprexec(const struct expr *, +static void exprexec(const struct expr *, const char *, uint64_t, struct rec *); -static int exprmark(const struct expr *, +static int exprmark(const struct expr *, const char *, uint64_t, int *); static struct expr *exprexpr(int, char *[], int *, int *, size_t *); static struct expr *exprterm(char *, int); @@ -148,7 +148,7 @@ btree_open(void) info.flags = R_DUP; db = dbopen(MANDOC_DB, O_RDONLY, 0, DB_BTREE, &info); - if (NULL != db) + if (NULL != db) return(db); return(NULL); @@ -176,7 +176,7 @@ btree_read(const DBT *v, const struct mchars *mc, char **buf) /* * Take a Unicode codepoint and produce its UTF-8 encoding. * This isn't the best way to do this, but it works. - * The magic numbers are from the UTF-8 packaging. + * The magic numbers are from the UTF-8 packaging. * They're not as scary as they seem: read the UTF-8 spec for details. */ static size_t @@ -241,7 +241,7 @@ norm_string(const char *val, const struct mchars *mc, char **buf) const char *seq, *cpp; int len, u, pos; enum mandoc_esc esc; - static const char res[] = { '\\', '\t', + static const char res[] = { '\\', '\t', ASCII_NBRSP, ASCII_HYPH, '\0' }; /* Pre-allocate by the length of the input */ @@ -287,7 +287,7 @@ norm_string(const char *val, const struct mchars *mc, char **buf) if (ESCAPE_ERROR == esc) break; - /* + /* * XXX - this just does UTF-8, but we need to know * beforehand whether we should do text substitution. */ @@ -382,7 +382,7 @@ index_read(const DBT *key, const DBT *val, int index, */ int apropos_search(int pathsz, char **paths, const struct opts *opts, - const struct expr *expr, size_t terms, void *arg, + const struct expr *expr, size_t terms, void *arg, void (*res)(struct res *, size_t, void *)) { struct rectree tree; @@ -420,7 +420,7 @@ apropos_search(int pathsz, char **paths, const struct opts *opts, for (mlen = i = 0; i < tree.len; i++) if (tree.node[i].matched) - memcpy(&ress[mlen++], &tree.node[i].res, + memcpy(&ress[mlen++], &tree.node[i].res, sizeof(struct res)); (*res)(ress, mlen, arg); @@ -460,7 +460,7 @@ single_search(struct rectree *tree, const struct opts *opts, memset(&r, 0, sizeof(struct rec)); - if (NULL == (btree = btree_open())) + if (NULL == (btree = btree_open())) return(1); if (NULL == (idx = index_open())) { @@ -469,8 +469,8 @@ single_search(struct rectree *tree, const struct opts *opts, } while (0 == (ch = (*btree->seq)(btree, &key, &val, R_NEXT))) { - if (key.size < 2 || sizeof(struct db_val) != val.size) - break; + if (key.size < 2 || sizeof(struct db_val) != val.size) + break; if ( ! btree_read(&key, mc, &buf)) break; @@ -492,13 +492,13 @@ single_search(struct rectree *tree, const struct opts *opts, */ for (leaf = root; leaf >= 0; ) - if (rec > rs[leaf].res.rec && + if (rec > rs[leaf].res.rec && rs[leaf].rhs >= 0) leaf = rs[leaf].rhs; - else if (rec < rs[leaf].res.rec && + else if (rec < rs[leaf].res.rec && rs[leaf].lhs >= 0) leaf = rs[leaf].lhs; - else + else break; /* @@ -540,10 +540,11 @@ single_search(struct rectree *tree, const struct opts *opts, (rs, (tree->len + 1) * sizeof(struct rec)); memcpy(&rs[tree->len], &r, sizeof(struct rec)); - rs[tree->len].matches = + rs[tree->len].matches = mandoc_calloc(terms, sizeof(int)); - exprexec(expr, buf, mask, &rs[tree->len]); + exprexec(expr, buf, mask, &rs[tree->len]); + /* Append to our tree. */ if (leaf >= 0) { @@ -553,11 +554,11 @@ single_search(struct rectree *tree, const struct opts *opts, rs[leaf].lhs = tree->len; } else root = tree->len; - + memset(&r, 0, sizeof(struct rec)); tree->len++; } - + (*btree->close)(btree); (*idx->close)(idx); @@ -632,7 +633,7 @@ exprexpr(int argc, char *argv[], int *pos, int *lvl, size_t *tt) log = 0; if (NULL != e && 0 == strcmp("-a", argv[*pos])) - log = 1; + log = 1; else if (NULL != e && 0 == strcmp("-o", argv[*pos])) log = 2; @@ -744,7 +745,7 @@ void exprfree(struct expr *p) { struct expr *pp; - + while (NULL != p) { if (p->subexpr) exprfree(p->subexpr); @@ -758,7 +759,7 @@ exprfree(struct expr *p) } static int -exprmark(const struct expr *p, const char *cp, +exprmark(const struct expr *p, const char *cp, uint64_t mask, int *ms) { @@ -813,7 +814,7 @@ expreval(const struct expr *p, int *ms) for ( ; p->next && p->next->and; p = p->next) { /* Evaluate a subexpression, if applicable. */ if (p->next->subexpr && ! ms[p->next->index]) - ms[p->next->index] = + ms[p->next->index] = expreval(p->next->subexpr, ms); match = match && ms[p->next->index]; } @@ -830,11 +831,11 @@ expreval(const struct expr *p, int *ms) * If this evaluates to true, mark the expression as satisfied. */ static void -exprexec(const struct expr *p, const char *cp, +exprexec(const struct expr *e, const char *cp, uint64_t mask, struct rec *r) { assert(0 == r->matched); - exprmark(p, cp, mask, r->matches); - r->matched = expreval(p, r->matches); + exprmark(e, cp, mask, r->matches); + r->matched = expreval(e, r->matches); } diff --git a/apropos_db.h b/apropos_db.h index 316d5669..3e0b347b 100644 --- a/apropos_db.h +++ b/apropos_db.h @@ -24,11 +24,11 @@ struct res { char *arch; /* arch (or empty string) */ char *desc; /* description (from Nd) */ unsigned int rec; /* record in index */ - /* + /* * The index volume. This indexes into the array of directories * searched for manual page databases. */ - unsigned int volume; + unsigned int volume; }; struct opts { @@ -40,8 +40,8 @@ __BEGIN_DECLS struct expr; -int apropos_search(int, char **, const struct opts *, - const struct expr *, size_t, void *, +int apropos_search(int, char **, const struct opts *, + const struct expr *, size_t, void *, void (*)(struct res *, size_t, void *)); struct expr *exprcomp(int, char *[], size_t *); void exprfree(struct expr *); @@ -378,7 +378,7 @@ main(int argc, char *argv[]) &maxrec, &recs, &recsz); if (OP_UPDATE == op) - index_merge(of, mp, &dbuf, &buf, hash, + index_merge(of, mp, &dbuf, &buf, hash, db, fbuf, idx, ibuf, use_all, verb, maxrec, recs, reccur); @@ -411,11 +411,16 @@ main(int argc, char *argv[]) sz2 = strlcat(ibuf, MANDOC_IDX, MAXPATHLEN); if (sz1 >= MAXPATHLEN || sz2 >= MAXPATHLEN) { - fprintf(stderr, "%s: Path too long\n", + fprintf(stderr, "%s: Path too long\n", dirs.paths[i]); exit((int)MANDOCLEVEL_BADARG); } + if (db) + (*db->close)(db); + if (idx) + (*idx->close)(idx); + db = dbopen(fbuf, flags, 0644, DB_BTREE, &info); idx = dbopen(ibuf, flags, 0644, DB_RECNO, NULL); @@ -444,7 +449,7 @@ main(int argc, char *argv[]) of = of->first; - index_merge(of, mp, &dbuf, &buf, hash, db, fbuf, + index_merge(of, mp, &dbuf, &buf, hash, db, fbuf, idx, ibuf, use_all, verb, maxrec, recs, reccur); } @@ -471,7 +476,7 @@ out: void index_merge(const struct of *of, struct mparse *mp, struct buf *dbuf, struct buf *buf, - DB *hash, DB *db, const char *dbf, + DB *hash, DB *db, const char *dbf, DB *idx, const char *idxf, int use_all, int verb, recno_t maxrec, const recno_t *recs, size_t reccur) { @@ -19,6 +19,7 @@ #include "config.h" #endif +#include <sys/types.h> #include <assert.h> #include <ctype.h> #include <limits.h> @@ -35,25 +36,25 @@ static void manpath_add(struct manpaths *, const char *); void -manpath_parse(struct manpaths *dirs, char *defp, char *auxp) +manpath_parse(struct manpaths *dirs, char *defp, char *auxp) { - if (NULL != getenv("MANPATH")) + manpath_parseline(dirs, auxp); + + if (NULL == defp) defp = getenv("MANPATH"); if (NULL == defp) manpath_parseconf(dirs); else manpath_parseline(dirs, defp); - - manpath_parseline(dirs, auxp); } /* * Parse a FULL pathname from a colon-separated list of arrays. */ void -manpath_parseline(struct manpaths *dirs, char *path) +manpath_parseline(struct manpaths *dirs, char *path) { char *dir; @@ -69,7 +70,7 @@ manpath_parseline(struct manpaths *dirs, char *path) * Grow the array one-by-one for simplicity's sake. */ static void -manpath_add(struct manpaths *dirs, const char *dir) +manpath_add(struct manpaths *dirs, const char *dir) { char buf[PATH_MAX]; char *cp; @@ -83,7 +84,7 @@ manpath_add(struct manpaths *dirs, const char *dir) return; dirs->paths = mandoc_realloc - (dirs->paths, + (dirs->paths, ((size_t)dirs->sz + 1) * sizeof(char *)); dirs->paths[dirs->sz++] = mandoc_strdup(cp); @@ -143,7 +144,7 @@ manpath_manconf(const char *file, struct manpaths *dirs) { FILE *stream; char *p, *q; - size_t len, keysz; + size_t len, keysz; keysz = strlen(MAN_CONF_KEY); assert(keysz > 0); |