summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/mandoc/apropos_db.c26
-rw-r--r--usr.bin/mandoc/apropos_db.h10
-rw-r--r--usr.bin/mandoc/mandocdb.819
-rw-r--r--usr.bin/mandoc/mandocdb.c76
-rw-r--r--usr.bin/mandoc/manpath.c17
-rw-r--r--usr.bin/mandoc/manpath.h4
6 files changed, 80 insertions, 72 deletions
diff --git a/usr.bin/mandoc/apropos_db.c b/usr.bin/mandoc/apropos_db.c
index ec1be3164e3..4c39b0fe3f9 100644
--- a/usr.bin/mandoc/apropos_db.c
+++ b/usr.bin/mandoc/apropos_db.c
@@ -1,4 +1,4 @@
-/* $Id: apropos_db.c,v 1.14 2011/12/10 22:18:20 schwarze Exp $ */
+/* $Id: apropos_db.c,v 1.15 2011/12/19 02:26:33 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -105,7 +105,7 @@ static const struct type types[] = {
{ TYPE_Va, "Va" },
{ TYPE_Va, "Vt" },
{ TYPE_Xr, "Xr" },
- { INT_MAX, "any" },
+ { UINT64_MAX, "any" },
{ 0, NULL }
};
@@ -186,7 +186,7 @@ btree_read(const DBT *k, const DBT *v,
static size_t
norm_utf8(unsigned int cp, char out[7])
{
- size_t rc;
+ int rc;
rc = 0;
@@ -227,7 +227,7 @@ norm_utf8(unsigned int cp, char out[7])
return(0);
out[rc] = '\0';
- return(rc);
+ return((size_t)rc);
}
/*
@@ -354,6 +354,7 @@ index_read(const DBT *key, const DBT *val, int index,
{
size_t left;
char *np, *cp;
+ char type;
#define INDEX_BREAD(_dst) \
do { \
@@ -364,13 +365,23 @@ index_read(const DBT *key, const DBT *val, int index,
cp = np + 1; \
} while (/* CONSTCOND */ 0)
- left = val->size;
- cp = (char *)val->data;
+ if (0 == (left = val->size))
+ return(0);
+ cp = val->data;
rec->res.rec = *(recno_t *)key->data;
rec->res.volume = index;
- INDEX_BREAD(rec->res.type);
+ if ('d' == (type = *cp++))
+ rec->res.type = RESTYPE_MDOC;
+ else if ('a' == type)
+ rec->res.type = RESTYPE_MAN;
+ else if ('c' == type)
+ rec->res.type = RESTYPE_CAT;
+ else
+ return(0);
+
+ left--;
INDEX_BREAD(rec->res.file);
INDEX_BREAD(rec->res.cat);
INDEX_BREAD(rec->res.title);
@@ -570,7 +581,6 @@ static void
recfree(struct rec *rec)
{
- free(rec->res.type);
free(rec->res.file);
free(rec->res.cat);
free(rec->res.title);
diff --git a/usr.bin/mandoc/apropos_db.h b/usr.bin/mandoc/apropos_db.h
index 302d8435694..82f5ac3d543 100644
--- a/usr.bin/mandoc/apropos_db.h
+++ b/usr.bin/mandoc/apropos_db.h
@@ -1,4 +1,4 @@
-/* $Id: apropos_db.h,v 1.9 2011/11/28 00:16:38 schwarze Exp $ */
+/* $Id: apropos_db.h,v 1.10 2011/12/19 02:26:33 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -17,8 +17,14 @@
#ifndef APROPOS_H
#define APROPOS_H
+enum restype {
+ RESTYPE_MAN, /* man(7) file */
+ RESTYPE_MDOC, /* mdoc(7) file */
+ RESTYPE_CAT /* pre-formatted file */
+};
+
struct res {
- char *type; /* file type: mdoc, man or cat */
+ enum restype type; /* input file type */
char *file; /* file in file-system */
char *cat; /* category (3p, 3, etc.) */
char *title; /* title (FOO, etc.) */
diff --git a/usr.bin/mandoc/mandocdb.8 b/usr.bin/mandoc/mandocdb.8
index c0c72a1224c..51ba0aa6b88 100644
--- a/usr.bin/mandoc/mandocdb.8
+++ b/usr.bin/mandoc/mandocdb.8
@@ -1,4 +1,4 @@
-.\" $Id: mandocdb.8,v 1.12 2011/12/12 01:59:13 schwarze Exp $
+.\" $Id: mandocdb.8,v 1.13 2011/12/19 02:26:33 schwarze Exp $
.\"
.\" Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: December 12 2011 $
+.Dd $Mdocdate: December 19 2011 $
.Dt MANDOCDB 8
.Os
.Sh NAME
@@ -110,20 +110,19 @@ database with record values consisting of
.Pp
.Bl -enum -compact
.It
-the string
-.Cm mdoc ,
-.Cm man ,
+the character
+.Cm d ,
+.Cm a ,
or
-.Cm cat
+.Cm c
to indicate the file type
.Po
-file in
.Xr mdoc 7 ,
.Xr man 7 ,
and post-formatted, respectively
.Pc ,
.It
-the filename,
+the filename relative to the databases' path,
.It
the manual section,
.It
@@ -137,9 +136,7 @@ and the description.
.Pp
Each of the above is NUL-terminated.
.Pp
-Both the manual section and description may be zero-length if the record
-is unassigned.
-Entries are sequentially-numbered, but the filenames are unordered.
+If the record value is zero-length, it is unassigned.
.Ss Keyword Database
The keyword database,
.Pa mandoc.db ,
diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c
index 3e2152e5c54..7cea6b47866 100644
--- a/usr.bin/mandoc/mandocdb.c
+++ b/usr.bin/mandoc/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.25 2011/12/12 01:59:13 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.26 2011/12/19 02:26:33 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -17,7 +17,6 @@
*/
#include <sys/param.h>
#include <sys/types.h>
-#include <sys/stat.h>
#include <assert.h>
#include <dirent.h>
@@ -97,7 +96,7 @@ static void index_prune(const struct of *, DB *,
recno_t *, recno_t **, size_t *,
size_t *);
static void ofile_argbuild(int, char *[], struct of **);
-static int ofile_dirbuild(const char *, const char *,
+static void ofile_dirbuild(const char *, const char *,
const char *, int, struct of **);
static void ofile_free(struct of *);
static void pformatted(DB *, struct buf *, struct buf *,
@@ -372,12 +371,8 @@ mandocdb(int argc, char *argv[])
exit((int)MANDOCLEVEL_SYSERR);
}
- if (verb > 2) {
- printf("%s: Opened\n", fbuf);
- printf("%s: Opened\n", ibuf);
- }
-
ofile_argbuild(argc, argv, &of);
+
if (NULL == of)
goto out;
@@ -387,13 +382,16 @@ mandocdb(int argc, char *argv[])
&maxrec, &recs, &recsz, &reccur);
/*
- * Go to the root of the respective manual tree
- * such that .so links work. In case of failure,
- * just prod on, even though .so links won't work.
+ * Go to the root of the respective manual tree.
+ * This must work or no manuals may be found (they're
+ * indexed relative to the root).
*/
if (OP_UPDATE == op) {
- chdir(dir);
+ if (-1 == chdir(dir)) {
+ perror(dir);
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
index_merge(of, mp, &dbuf, &buf, hash,
db, fbuf, idx, ibuf,
maxrec, recs, reccur);
@@ -462,9 +460,12 @@ mandocdb(int argc, char *argv[])
ofile_free(of);
of = NULL;
- if ( ! ofile_dirbuild(dirs.paths[i], NULL, NULL,
- 0, &of))
+ if (-1 == chdir(dirs.paths[i])) {
+ perror(dirs.paths[i]);
exit((int)MANDOCLEVEL_SYSERR);
+ }
+
+ ofile_dirbuild(".", NULL, NULL, 0, &of);
if (NULL == of)
continue;
@@ -472,12 +473,16 @@ mandocdb(int argc, char *argv[])
of = of->first;
/*
- * Go to the root of the respective manual tree
- * such that .so links work. In case of failure,
- * just prod on, even though .so links won't work.
+ * Go to the root of the respective manual tree.
+ * This must work or no manuals may be found (they're
+ * indexed relative to the root).
*/
- chdir(dirs.paths[i]);
+ if (-1 == chdir(dirs.paths[i])) {
+ perror(dirs.paths[i]);
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
+
index_merge(of, mp, &dbuf, &buf, hash, db, fbuf,
idx, ibuf, maxrec, recs, reccur);
}
@@ -516,6 +521,7 @@ index_merge(const struct of *of, struct mparse *mp,
size_t sv;
unsigned seq;
struct db_val vbuf;
+ char type;
for (rec = 0; of; of = of->next) {
fn = of->fname;
@@ -596,7 +602,8 @@ index_merge(const struct of *of, struct mparse *mp,
*/
dbuf->len = 0;
- buf_append(dbuf, mdoc ? "mdoc" : (man ? "man" : "cat"));
+ type = mdoc ? 'd' : (man ? 'a' : 'c');
+ buf_appendb(dbuf, &type, 1);
buf_appendb(dbuf, fn, strlen(fn) + 1);
buf_appendb(dbuf, msec, strlen(msec) + 1);
buf_appendb(dbuf, mtitle, strlen(mtitle) + 1);
@@ -684,7 +691,7 @@ index_prune(const struct of *ofile, DB *db, const char *dbf,
recno_t **recs, size_t *recsz, size_t *reccur)
{
const struct of *of;
- const char *fn, *cp;
+ const char *fn;
struct db_val *vbuf;
unsigned seq, sseq;
DBT key, val;
@@ -695,7 +702,6 @@ index_prune(const struct of *ofile, DB *db, const char *dbf,
while (0 == (ch = (*idx->seq)(idx, &key, &val, seq))) {
seq = R_NEXT;
*maxrec = *(recno_t *)key.data;
- cp = val.data;
/* Deleted records are zero-sized. Skip them. */
@@ -709,11 +715,8 @@ index_prune(const struct of *ofile, DB *db, const char *dbf,
* Failing any of these, we go into our error handler.
*/
- if (NULL == (fn = memchr(cp, '\0', val.size)))
- break;
- if (++fn - cp >= (int)val.size)
- break;
- if (NULL == memchr(fn, '\0', val.size - (fn - cp)))
+ fn = (char *)val.data + 1;
+ if (NULL == memchr(fn, '\0', val.size - 1))
break;
/*
@@ -1443,12 +1446,11 @@ ofile_argbuild(int argc, char *argv[], struct of **of)
* everything else is a manual.
* Pass in a pointer to a NULL structure for the first invocation.
*/
-static int
+static void
ofile_dirbuild(const char *dir, const char* psec, const char *parch,
int p_src_form, struct of **of)
{
char buf[MAXPATHLEN];
- struct stat sb;
size_t sz;
DIR *d;
const char *fn, *sec, *arch;
@@ -1510,14 +1512,13 @@ ofile_dirbuild(const char *dir, const char* psec, const char *parch,
if (verb > 2)
printf("%s: Scanning\n", buf);
- if ( ! ofile_dirbuild(buf, sec, arch,
- src_form, of))
- return(0);
+ ofile_dirbuild(buf, sec, arch, src_form, of);
}
+
if (DT_REG != dp->d_type ||
- (NULL == psec && !use_all) ||
- !strcmp(MANDOC_DB, fn) ||
- !strcmp(MANDOC_IDX, fn))
+ (NULL == psec && !use_all) ||
+ ! strcmp(MANDOC_DB, fn) ||
+ ! strcmp(MANDOC_IDX, fn))
continue;
/*
@@ -1581,13 +1582,15 @@ ofile_dirbuild(const char *dir, const char* psec, const char *parch,
"%s: Path too long\n", buf);
continue;
}
- if (0 == stat(buf, &sb))
+ if (0 == access(buf, R_OK))
continue;
}
}
+ assert('.' == dir[0]);
+ assert('/' == dir[1]);
buf[0] = '\0';
- strlcat(buf, dir, MAXPATHLEN);
+ strlcat(buf, dir + 2, MAXPATHLEN);
strlcat(buf, "/", MAXPATHLEN);
sz = strlcat(buf, fn, MAXPATHLEN);
if (sz >= MAXPATHLEN) {
@@ -1629,7 +1632,6 @@ ofile_dirbuild(const char *dir, const char* psec, const char *parch,
}
closedir(d);
- return(1);
}
static void
diff --git a/usr.bin/mandoc/manpath.c b/usr.bin/mandoc/manpath.c
index 86084a7aca5..ed58c403ccf 100644
--- a/usr.bin/mandoc/manpath.c
+++ b/usr.bin/mandoc/manpath.c
@@ -1,4 +1,4 @@
-/* $Id: manpath.c,v 1.2 2011/12/12 01:59:13 schwarze Exp $ */
+/* $Id: manpath.c,v 1.3 2011/12/19 02:26:33 schwarze Exp $ */
/*
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -16,7 +16,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
+#include <sys/param.h>
+
#include <assert.h>
#include <ctype.h>
#include <limits.h>
@@ -31,6 +32,7 @@
#define MAN_CONF_KEY "_whatdb"
static void manpath_add(struct manpaths *, const char *);
+static void manpath_parseline(struct manpaths *, char *);
void
manpath_parse(struct manpaths *dirs, const char *file,
@@ -43,7 +45,7 @@ manpath_parse(struct manpaths *dirs, const char *file,
defp = getenv("MANPATH");
if (NULL == defp)
- manpath_parseconf(dirs, file);
+ manpath_manconf(dirs, file ? file : MAN_CONF_FILE);
else
manpath_parseline(dirs, defp);
}
@@ -51,7 +53,7 @@ manpath_parse(struct manpaths *dirs, const char *file,
/*
* Parse a FULL pathname from a colon-separated list of arrays.
*/
-void
+static void
manpath_parseline(struct manpaths *dirs, char *path)
{
char *dir;
@@ -89,13 +91,6 @@ manpath_add(struct manpaths *dirs, const char *dir)
}
void
-manpath_parseconf(struct manpaths *dirs, const char *file)
-{
-
- manpath_manconf(dirs, file ? file : MAN_CONF_FILE);
-}
-
-void
manpath_free(struct manpaths *p)
{
int i;
diff --git a/usr.bin/mandoc/manpath.h b/usr.bin/mandoc/manpath.h
index 632834d6fc4..4b2233d17a2 100644
--- a/usr.bin/mandoc/manpath.h
+++ b/usr.bin/mandoc/manpath.h
@@ -1,4 +1,4 @@
-/* $Id: manpath.h,v 1.2 2011/12/12 01:59:13 schwarze Exp $ */
+/* $Id: manpath.h,v 1.3 2011/12/19 02:26:33 schwarze Exp $ */
/*
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -31,8 +31,6 @@ __BEGIN_DECLS
void manpath_manconf(struct manpaths *, const char *);
void manpath_parse(struct manpaths *, const char *, char *, char *);
-void manpath_parseconf(struct manpaths *, const char *);
-void manpath_parseline(struct manpaths *, char *);
void manpath_free(struct manpaths *);
__END_DECLS