From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p5MAabKG025117 for ; Wed, 22 Jun 2011 06:36:37 -0400 (EDT) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.3/8.14.3/Submit) id p5MAabRJ000763; Wed, 22 Jun 2011 06:36:37 -0400 (EDT) Date: Wed, 22 Jun 2011 06:36:37 -0400 (EDT) Message-Id: <201106221036.p5MAabRJ000763@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Clean up makewhatis.c a little bit and add verbosity (-v). X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Clean up makewhatis.c a little bit and add verbosity (-v). Modified Files: -------------- mdocml: makewhatis.c makewhatis.1 Revision Data ------------- Index: makewhatis.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/makewhatis.c,v retrieving revision 1.9 retrieving revision 1.10 diff -Lmakewhatis.c -Lmakewhatis.c -u -p -r1.9 -r1.10 --- makewhatis.c +++ makewhatis.c @@ -21,11 +21,6 @@ #include #include -#ifdef __linux__ -# include -#else -# include -#endif #include #include #include @@ -33,6 +28,12 @@ #include #include +#ifdef __linux__ +# include +#else +# include +#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); } Index: makewhatis.1 =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/makewhatis.1,v retrieving revision 1.5 retrieving revision 1.6 diff -Lmakewhatis.1 -Lmakewhatis.1 -u -p -r1.5 -r1.6 --- makewhatis.1 +++ makewhatis.1 @@ -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, -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv