aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-06-22 10:36:36 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-06-22 10:36:36 +0000
commitb798e2f310dfb8b08a37d21e0f52592f02426620 (patch)
tree1fe8cfa7054216fbb5566ec23d7f65d9706c008c
parentbe592fa5c6fb8d29d7c83639eb53888ef64cb498 (diff)
downloadmandoc-b798e2f310dfb8b08a37d21e0f52592f02426620.tar.gz
mandoc-b798e2f310dfb8b08a37d21e0f52592f02426620.tar.zst
mandoc-b798e2f310dfb8b08a37d21e0f52592f02426620.zip
Clean up makewhatis.c a little bit and add verbosity (-v).
-rw-r--r--makewhatis.19
-rw-r--r--makewhatis.c68
2 files changed, 45 insertions, 32 deletions
diff --git a/makewhatis.1 b/makewhatis.1
index 0e781c99..3546cb3c 100644
--- a/makewhatis.1
+++ b/makewhatis.1
@@ -1,4 +1,4 @@
-.\" $Id: makewhatis.1,v 1.5 2011/06/21 14:16:05 kristaps Exp $
+.\" $Id: makewhatis.1,v 1.6 2011/06/22 10:36:36 kristaps 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: June 21 2011 $
+.Dd $Mdocdate: June 22 2011 $
.Dt MAKEWHATIS 1
.Os
.Sh NAME
@@ -22,6 +22,7 @@
.Nd index UNIX manuals
.Sh SYNOPSIS
.Nm
+.Op Fl v
.Op Fl d Ar dir
.Ar
.Sh DESCRIPTION
@@ -41,6 +42,10 @@ or
.Xr man 7
.Ux
manual format.
+.It Fl v
+Verbose output.
+If specified once, prints the name of each indexed file.
+If twice, prints keywords for each file.
.El
.Pp
By default,
diff --git a/makewhatis.c b/makewhatis.c
index 3161ba19..44751b68 100644
--- a/makewhatis.c
+++ b/makewhatis.c
@@ -1,4 +1,4 @@
-/* $Id: makewhatis.c,v 1.9 2011/06/22 09:10:36 kristaps Exp $ */
+/* $Id: makewhatis.c,v 1.10 2011/06/22 10:36:36 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -21,11 +21,6 @@
#include <sys/param.h>
#include <assert.h>
-#ifdef __linux__
-# include <db_185.h>
-#else
-# include <db.h>
-#endif
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
@@ -33,6 +28,12 @@
#include <stdlib.h>
#include <string.h>
+#ifdef __linux__
+# include <db_185.h>
+#else
+# include <db.h>
+#endif
+
#include "man.h"
#include "mdoc.h"
#include "mandoc.h"
@@ -44,15 +45,15 @@
/* Bit-fields. See makewhatis.1. */
-#define TYPE_NAME 0x01
-#define TYPE_FUNCTION 0x02
-#define TYPE_UTILITY 0x04
-#define TYPE_INCLUDES 0x08
-#define TYPE_VARIABLE 0x10
-#define TYPE_STANDARD 0x20
-#define TYPE_AUTHOR 0x40
-#define TYPE_CONFIG 0x80
-#define TYPE_DESC 0x100
+#define TYPE_NAME 0x01
+#define TYPE_FUNCTION 0x02
+#define TYPE_UTILITY 0x04
+#define TYPE_INCLUDES 0x08
+#define TYPE_VARIABLE 0x10
+#define TYPE_STANDARD 0x20
+#define TYPE_AUTHOR 0x40
+#define TYPE_CONFIG 0x80
+#define TYPE_DESC 0x100
/* Buffer for storing growable data. */
@@ -236,7 +237,7 @@ main(int argc, char *argv[])
fbuf[MAXPATHLEN], /* btree fname */
fbbuf[MAXPATHLEN], /* btree backup fname */
vbuf[8]; /* stringified record number */
- int ch, seq;
+ int ch, seq, verb;
DB *idx, /* index database */
*db, /* keyword database */
*hash; /* temporary keyword hashtable */
@@ -256,12 +257,16 @@ main(int argc, char *argv[])
++progname;
dir = "";
+ verb = 0;
- while (-1 != (ch = getopt(argc, argv, "d:")))
+ while (-1 != (ch = getopt(argc, argv, "d:v")))
switch (ch) {
case ('d'):
dir = optarg;
break;
+ case ('v'):
+ verb++;
+ break;
default:
usage();
return((int)MANDOCLEVEL_BADARG);
@@ -298,7 +303,7 @@ main(int argc, char *argv[])
'\0' != fbbuf[MAXPATHLEN - 2] ||
'\0' != ibuf[MAXPATHLEN - 2] ||
'\0' != ibbuf[MAXPATHLEN - 2]) {
- fprintf(stderr, "%s: Path too long\n", progname);
+ fprintf(stderr, "%s: Path too long\n", dir);
exit((int)MANDOCLEVEL_SYSERR);
}
@@ -326,9 +331,9 @@ main(int argc, char *argv[])
}
/*
- * Try parsing the manuals given on the command line. If we
- * totally fail, then just keep on going. Take resulting trees
- * and push them down into the database code.
+ * Try parsing each manual given on the command line.
+ * If we fail, then emit an error and keep on going.
+ * Take resulting trees and push them down into the database code.
* Use the auto-parser and don't report any errors.
*/
@@ -348,6 +353,8 @@ main(int argc, char *argv[])
while (NULL != (fn = *argv++)) {
mparse_reset(mp);
+ /* Initialise the in-memory hash of keywords. */
+
if (hash)
(*hash->close)(hash);
@@ -364,12 +371,12 @@ main(int argc, char *argv[])
fprintf(stderr, "%s: Parse failure\n", fn);
continue;
}
+
mparse_result(mp, &mdoc, &man);
+
if (NULL == mdoc && NULL == man)
continue;
- /* Manual section: can be empty string. */
-
msec = NULL != mdoc ?
mdoc_meta(mdoc)->msec :
man_meta(man)->msec;
@@ -378,9 +385,6 @@ main(int argc, char *argv[])
man_meta(man)->title;
arch = NULL != mdoc ? mdoc_meta(mdoc)->arch : NULL;
- assert(msec);
- assert(mtitle);
-
/*
* The index record value consists of a nil-terminated
* filename, a nil-terminated manual section, and a
@@ -422,8 +426,9 @@ main(int argc, char *argv[])
val.size = sizeof(vbuf);
val.data = vbuf;
- printf("Added: %s (%zu): 0x%x\n",
- (char *)key.data, key.size,
+ if (verb > 1)
+ printf("%s: Keyword %s (%zu): 0x%x\n",
+ fn, (char *)key.data, key.size,
*(int *)val.data);
dbt_put(db, fbbuf, &key, &val);
@@ -449,7 +454,8 @@ main(int argc, char *argv[])
val.data = dbuf.cp;
val.size = dbuf.len;
- printf("Indexed: %s\n", fn);
+ if (verb > 0)
+ printf("%s: Indexed\n", fn);
dbt_put(idx, ibbuf, &key, &val);
rec++;
@@ -457,6 +463,7 @@ main(int argc, char *argv[])
(*db->close)(db);
(*idx->close)(idx);
+
if (hash)
(*hash->close)(hash);
@@ -924,5 +931,6 @@ static void
usage(void)
{
- fprintf(stderr, "usage: %s [-d path] [file...]\n", progname);
+ fprintf(stderr, "usage: %s [-v] [-d path] [file...]\n",
+ progname);
}