aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandocdb.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-11-23 09:52:20 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-11-23 09:52:20 +0000
commit62dc4f949b755b4b88b3f476e7da3ae0827618a6 (patch)
treec1a163cbe6a24ae0a8b6ebeafad210b03116899a /mandocdb.c
parent0d939acd4f8824b1b980fca108e1064981608d28 (diff)
downloadmandoc-62dc4f949b755b4b88b3f476e7da3ae0827618a6.tar.gz
mandoc-62dc4f949b755b4b88b3f476e7da3ae0827618a6.tar.zst
mandoc-62dc4f949b755b4b88b3f476e7da3ae0827618a6.zip
Have mandocdb(8) take advantage of manpath.h.
This brings it in line with makewhatis(8), which, like apropos(1), will use man.conf (or manpath(1)) if no manpath entries are provided.
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/mandocdb.c b/mandocdb.c
index 2858b890..a1e1ba36 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.9 2011/11/20 12:39:08 kristaps Exp $ */
+/* $Id: mandocdb.c,v 1.10 2011/11/23 09:52:20 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -39,6 +39,7 @@
#include "mdoc.h"
#include "mandoc.h"
#include "mandocdb.h"
+#include "manpath.h"
#define MANDOC_BUFSZ BUFSIZ
#define MANDOC_SLOP 1024
@@ -247,6 +248,7 @@ int
main(int argc, char *argv[])
{
struct mparse *mp; /* parse sequence */
+ struct manpaths dirs;
enum op op; /* current operation */
const char *dir;
char ibuf[MAXPATHLEN], /* index fname */
@@ -274,6 +276,8 @@ main(int argc, char *argv[])
else
++progname;
+ memset(&dirs, 0, sizeof(struct manpaths));
+
verb = 0;
of = NULL;
db = idx = NULL;
@@ -370,19 +374,34 @@ main(int argc, char *argv[])
goto out;
}
- for (i = 0; i < argc; i++) {
+ /*
+ * Configure the directories we're going to scan.
+ * If we have command-line arguments, use them.
+ * If not, we use man(1)'s method (see mandocdb.8).
+ */
+
+ if (argc > 0) {
+ dirs.paths = mandoc_malloc(argc * sizeof(char *));
+ dirs.sz = argc;
+ for (i = 0; i < argc; i++)
+ dirs.paths[i] = mandoc_strdup(argv[i]);
+ } else
+ manpath_parseconf(&dirs);
+
+ for (i = 0; i < dirs.sz; i++) {
ibuf[0] = fbuf[0] = '\0';
- strlcat(fbuf, argv[i], MAXPATHLEN);
+ strlcat(fbuf, dirs.paths[i], MAXPATHLEN);
strlcat(fbuf, "/", MAXPATHLEN);
sz1 = strlcat(fbuf, MANDOC_DB, MAXPATHLEN);
- strlcat(ibuf, argv[i], MAXPATHLEN);
+ strlcat(ibuf, dirs.paths[i], MAXPATHLEN);
strlcat(ibuf, "/", MAXPATHLEN);
sz2 = strlcat(ibuf, MANDOC_IDX, MAXPATHLEN);
if (sz1 >= MAXPATHLEN || sz2 >= MAXPATHLEN) {
- fprintf(stderr, "%s: Path too long\n", argv[i]);
+ fprintf(stderr, "%s: Path too long\n",
+ dirs.paths[i]);
exit((int)MANDOCLEVEL_BADARG);
}
@@ -405,7 +424,7 @@ main(int argc, char *argv[])
ofile_free(of);
of = NULL;
- if ( ! ofile_dirbuild(argv[i], verb, &of))
+ if ( ! ofile_dirbuild(dirs.paths[i], verb, &of))
exit((int)MANDOCLEVEL_SYSERR);
if (NULL == of)
@@ -427,6 +446,7 @@ out:
if (mp)
mparse_free(mp);
+ manpath_free(&dirs);
ofile_free(of);
free(buf.cp);
free(dbuf.cp);