Hi,
the OpenBSD part of the resync is done (well, there are still a few
minor patches outside the mandocsb/apropos area, i'll resend those
later).
Here is the bsd.lv part, mostly removing trivial differences and
cleaning up whitespace. But there are a few real issues:
* -M overrides MANPATH, not the other way round;
-m _prepends_ to the path, it doesn't _append_.
That was both implemented and documented the wrong way.
* MANPATH is colon-separated, not comma-separated;
the implementation is correct, the manual in part wrong.
* apropos.c doesn't need ctype.h any longer.
* The apropos(1) usage() has -M and -m "path", not "dirs",
just type "apropos -x" on an OpenBSD system.
* I fear removing the database close calls from the dir loop
in mandocdb(8) main because of file descriptor leaks;
or am i missing something?
* manpath.c needs sys/types.h because of size_t.
OK?
Ingo
Index: apropos.1
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos.1,v
retrieving revision 1.8
diff -u -p -r1.8 apropos.1
--- apropos.1 23 Nov 2011 10:09:30 -0000 1.8
+++ apropos.1 26 Nov 2011 16:45:13 -0000
@@ -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 o
.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
Index: apropos.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos.c,v
retrieving revision 1.18
diff -u -p -r1.18 apropos.c
--- apropos.c 23 Nov 2011 09:50:40 -0000 1.18
+++ apropos.c 26 Nov 2011 16:45:13 -0000
@@ -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 *a
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);
}
Index: apropos_db.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos_db.c,v
retrieving revision 1.11
diff -u -p -r1.11 apropos_db.c
--- apropos_db.c 23 Nov 2011 09:55:28 -0000 1.11
+++ apropos_db.c 26 Nov 2011 16:45:13 -0000
@@ -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 mc
/*
* 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 struc
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 struc
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 *va
*/
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,
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, cons
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, cons
}
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, cons
*/
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, cons
(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, cons
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 *po
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);
}
Index: apropos_db.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos_db.h,v
retrieving revision 1.7
diff -u -p -r1.7 apropos_db.h
--- apropos_db.h 23 Nov 2011 09:55:28 -0000 1.7
+++ apropos_db.h 26 Nov 2011 16:45:13 -0000
@@ -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 *);
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.12
diff -u -p -r1.12 mandocdb.c
--- mandocdb.c 26 Nov 2011 11:23:56 -0000 1.12
+++ mandocdb.c 26 Nov 2011 16:45:13 -0000
@@ -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)
{
Index: manpath.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/manpath.c,v
retrieving revision 1.3
diff -u -p -r1.3 manpath.c
--- manpath.c 24 Nov 2011 10:44:56 -0000 1.3
+++ manpath.c 26 Nov 2011 16:45:13 -0000
@@ -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,
* 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
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
{
FILE *stream;
char *p, *q;
- size_t len, keysz;
+ size_t len, keysz;
keysz = strlen(MAN_CONF_KEY);
assert(keysz > 0);
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv