source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Have mandocdb(8) take advantage of manpath.h.
@ 2011-11-23  9:52 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-11-23  9:52 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mdocml:
        mandocdb.c
        mandocdb.8

Revision Data
-------------
Index: mandocdb.8
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.8,v
retrieving revision 1.5
retrieving revision 1.6
diff -Lmandocdb.8 -Lmandocdb.8 -u -p -r1.5 -r1.6
--- mandocdb.8
+++ mandocdb.8
@@ -71,6 +71,12 @@ By default,
 creates databases in each
 .Ar dir
 using files rooted in that directory.
+If
+.Ar dir
+is not provided,
+.Nm
+uses the default paths stipulated by
+.Xr man 1 .
 .Pp
 If fatal parse errors are encountered while parsing, the offending file
 is printed to stderr, omitted from the index, and the parse continues
@@ -190,6 +196,7 @@ to exit at once, possibly in the middle 
 The output databases are corrupt and should be removed .
 .El
 .Sh SEE ALSO
+.Xr man 1 ,
 .Xr mandoc 1 ,
 .Xr btree 3 ,
 .Xr recno 3
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.9 -r1.10
--- mandocdb.c
+++ mandocdb.c
@@ -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);
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-11-23  9:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-23  9:52 mdocml: Have mandocdb(8) take advantage of manpath.h kristaps

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).