summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorjdolecek <jdolecek@NetBSD.org>2002-03-08 21:59:07 +0000
committerjdolecek <jdolecek@NetBSD.org>2002-03-08 21:59:07 +0000
commit534dd161ea723d3f8add10e15a7e70ae2450cd84 (patch)
treea0de9e288b8c1ef12c62ca75b497571f317f0e07 /libexec
parent8bcbaa7bc893540be6bf045238abd546a41d67c3 (diff)
If called without arguments, parse /etc/man.conf and regenerate the whatis
databases specified there. By default, the individual databases are actually generated by forked children in this case, for performance reasons. This feature can be switched off by new -f flag. If the configuration file can't be parsed or doesn't contain any _whatdb entries, the code falls back to /usr/share/man as before. Added -C, which allows to specify alternate configuration file. This is compatible with apropos(1) and whatis(1) flag of same name. Update manpage accordingly and document behaviour a bit better. Also add a HISTORY section, hopefully correct (done using CVS logs). This solves toolchain/5231 by Tim Rightnour and bin/7696 by Allen Briggs.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/makewhatis/Makefile6
-rw-r--r--libexec/makewhatis/makewhatis.878
-rw-r--r--libexec/makewhatis/makewhatis.c124
3 files changed, 187 insertions, 21 deletions
diff --git a/libexec/makewhatis/Makefile b/libexec/makewhatis/Makefile
index 54e48617064..8ceac42df8e 100644
--- a/libexec/makewhatis/Makefile
+++ b/libexec/makewhatis/Makefile
@@ -1,6 +1,10 @@
-# $NetBSD: Makefile,v 1.10 2002/01/29 10:20:31 tv Exp $
+# $NetBSD: Makefile,v 1.11 2002/03/08 21:59:07 jdolecek Exp $
PROG= makewhatis
+SRCS= makewhatis.c config.c
+.PATH: ${.CURDIR}/../../usr.bin/man
+CPPFLAGS+=-I${.CURDIR}/../../usr.bin
+
MAN= ${PROG}.8
.ifndef HOSTPROG
diff --git a/libexec/makewhatis/makewhatis.8 b/libexec/makewhatis/makewhatis.8
index 75c354ec01f..8e29c51d34d 100644
--- a/libexec/makewhatis/makewhatis.8
+++ b/libexec/makewhatis/makewhatis.8
@@ -1,6 +1,6 @@
-.\" $NetBSD: makewhatis.8,v 1.6 2002/01/15 02:24:15 wiz Exp $
+.\" $NetBSD: makewhatis.8,v 1.7 2002/03/08 21:59:07 jdolecek Exp $
.\"
-.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1997, 2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
@@ -34,13 +34,16 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd September 25, 1999
+.Dd March 8, 2002
.Dt MAKEWHATIS 8
+.Os
.Sh NAME
.Nm makewhatis
.Nd create a whatis.db database
.Sh SYNOPSIS
.Nm /usr/libexec/makewhatis
+.Op Fl C Ar file
+.Op Fl f
.Op Ar manpath ...
.Sh DESCRIPTION
.Nm
@@ -49,27 +52,76 @@ strips the NAME lines from compiled or raw
pages and creates
a whatis.db database
for use in
-.Xr apropos 1
+.Xr apropos 1 ,
+.Xr whatis 1
or with
.Xr man 1 's
.Fl k
option.
-If
-.Ar manpath
-is unspecified,
-.Nm
-by default creates a database for /usr/share/man.
Man pages compressed with
.Xr compress 1
and
.Xr gzip 1
are uncompressed before processing.
+.Pp
+When
+.Ar manpath
+is provided multiple times, the resulting database file
+is generated in the first directory specified, and contains
+entries for all the directories.
+.Pp
+If
+.Ar manpath
+is not provided,
+.Nm
+parses
+.Pa /etc/man.conf
+and regenerates whatis database files specified there. Each
+database file is assumed to reside on root of appropriate
+man page hierarchy.
+.Pp
+The options are as follows:
+.Bl -tag -width flag
+.It Fl C
+Use different
+.Xr man.conf(5)
+configuration file instead of the default,
+.Pa /etc/man.conf .
+.It Fl f
+Don't spawn child process to generate individual database files,
+do all work synchronously on foreground.
+.El
+.Sh FILES
+.Bl -tag -compact -width /etc/man.conf1
+.It Pa whatis.db
+name of the whatis database
+.It Pa /etc/man.conf
+.Xr man 1
+configuration file, used to get location of whatis databases when
+.Nm
+is called without arguments
+.El
.Sh SEE ALSO
+.Xr apropos 1 ,
.Xr man 1 ,
+.Xr whatis 1 ,
.Xr man.conf 5
+.Sh HISTORY
+.Nm
+first appeared in
+.Nx 1.0 ,
+as a shell script written by
+.An J.T. Conklin Aq jtc@netbsd.org
+and
+.An Thorsten Frueauf Aq frueauf@ira.uka.de .
+Further work was done by
+Matthew Green, Luke Mewburn and
+Chris Demetriou.
+.Pp
+Matthias Scheler
+has reimplemented
+.Nm
+in C in
+.Nx 1.5 .
.Sh AUTHORS
.An Matthias Scheler Aq tron@netbsd.org
-.Sh BUGS
-.Nm
-should find its search paths using
-.Pa /etc/man.conf .
diff --git a/libexec/makewhatis/makewhatis.c b/libexec/makewhatis/makewhatis.c
index c5a685f55e7..fd56e2d256d 100644
--- a/libexec/makewhatis/makewhatis.c
+++ b/libexec/makewhatis/makewhatis.c
@@ -1,4 +1,4 @@
-/* $NetBSD: makewhatis.c,v 1.22 2002/03/07 20:37:14 jdolecek Exp $ */
+/* $NetBSD: makewhatis.c,v 1.23 2002/03/08 21:59:07 jdolecek Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\n\
#endif /* not lint */
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: makewhatis.c,v 1.22 2002/03/07 20:37:14 jdolecek Exp $");
+__RCSID("$NetBSD: makewhatis.c,v 1.23 2002/03/08 21:59:07 jdolecek Exp $");
#endif /* not lint */
#if HAVE_CONFIG_H
@@ -52,6 +52,7 @@ __RCSID("$NetBSD: makewhatis.c,v 1.22 2002/03/07 20:37:14 jdolecek Exp $");
#include <sys/types.h>
#include <sys/param.h>
+#include <sys/queue.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -60,6 +61,7 @@ __RCSID("$NetBSD: makewhatis.c,v 1.22 2002/03/07 20:37:14 jdolecek Exp $");
#include <errno.h>
#include <fcntl.h>
#include <fts.h>
+#include <glob.h>
#include <locale.h>
#include <paths.h>
#include <signal.h>
@@ -69,6 +71,9 @@ __RCSID("$NetBSD: makewhatis.c,v 1.22 2002/03/07 20:37:14 jdolecek Exp $");
#include <unistd.h>
#include <zlib.h>
+#include <man/config.h>
+#include <man/pathnames.h>
+
typedef struct manpagestruct manpage;
struct manpagestruct {
manpage *mp_left,*mp_right;
@@ -104,6 +109,7 @@ void processmanpages(manpage **,whatis **);
void dumpwhatis(FILE *, whatis *);
void *emalloc(size_t);
char *estrdup(const char *);
+static int makewhatis(char * const *manpath);
char * const default_manpath[] = {
"/usr/share/man",
@@ -111,12 +117,120 @@ char * const default_manpath[] = {
};
const char *sectionext = "0123456789ln";
-const char *whatisdb = "whatis.db";
+const char *whatisdb = _PATH_WHATIS;
int
main(int argc, char *const *argv)
{
char * const *manpath;
+ int c, dofork=1;
+ const char *conffile = NULL;
+ ENTRY *ep;
+ TAG *tp;
+ int rv, jobs = 0, status;
+ glob_t pg;
+ char *paths[2], **p, *sl;
+ int retval = EXIT_SUCCESS;
+
+ (void)setlocale(LC_ALL, "");
+
+ while((c = getopt(argc, argv, "C:f")) != -1) {
+ switch(c) {
+ case 'C':
+ conffile = optarg;
+ break;
+ case 'f':
+ /* run all processing on foreground */
+ dofork = 0;
+ break;
+ default:
+ fprintf(stderr, "Usage: %s [-C file] [-f] [path ...]\n",
+ getprogname());
+ exit(EXIT_FAILURE);
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc >= 2) {
+ manpath = &argv[0];
+
+ mkwhatis:
+ return (makewhatis(manpath));
+ }
+
+ /*
+ * Try read config file, fallback to default_manpath[]
+ * if man.conf not available.
+ */
+ config(conffile);
+ if ((tp = getlist("_whatdb")) == NULL) {
+ manpath = default_manpath;
+ goto mkwhatis;
+ }
+
+ /* Build individual databases */
+ paths[1] = NULL;
+ TAILQ_FOREACH(ep, &tp->list, q) {
+ if ((rv = glob(ep->s,
+ GLOB_BRACE | GLOB_NOSORT | GLOB_ERR | GLOB_NOCHECK,
+ NULL, &pg)) != 0)
+ err(EXIT_FAILURE, "glob('%s')", ep->s);
+
+ /* We always have something to work with here */
+ for (p = pg.gl_pathv; *p; p++) {
+ sl = strrchr(*p, '/');
+ if (!sl)
+ err(EXIT_FAILURE, "glob: _whatdb entry '%s' doesn't contain slash", ep->s);
+
+ /*
+ * Cut the last component of path, leaving just
+ * the directory. We will use the result as root
+ * for manpage search.
+ * glob malloc()s space for the paths, so it's
+ * okay to change it in-place.
+ */
+ *sl = '\0';
+ paths[0] = *p;
+
+ if (!dofork) {
+ /* Do not fork child */
+ makewhatis(paths);
+ continue;
+ }
+
+ switch (fork()) {
+ case 0:
+ exit(makewhatis(paths));
+ break;
+ case -1:
+ warn("fork");
+ makewhatis(paths);
+ break;
+ default:
+ jobs++;
+ break;
+ }
+
+ }
+
+ globfree(&pg);
+ }
+
+ /* Wait for the childern to finish */
+ while(jobs > 0) {
+ wait(&status);
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS)
+ retval = EXIT_FAILURE;
+ jobs--;
+ }
+
+ return (retval);
+}
+
+static int
+makewhatis(char * const * manpath)
+{
FTS *fts;
FTSENT *fe;
manpage *source;
@@ -124,10 +238,6 @@ main(int argc, char *const *argv)
FILE *out;
size_t sdoff, sdlen;
- (void)setlocale(LC_ALL, "");
-
- manpath = (argc < 2) ? default_manpath : &argv[1];
-
if ((fts = fts_open(manpath, FTS_LOGICAL, NULL)) == NULL)
err(EXIT_FAILURE, "Cannot open `%s'", *manpath);