summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-04-04 02:31:01 +0000
committerschwarze <schwarze@openbsd.org>2014-04-04 02:31:01 +0000
commite4570e6c6b7c381b3c06c286e868837037fef2d5 (patch)
treef25b361a0e825ef2e693a28fb573238170671279
parentsync (diff)
downloadwireguard-openbsd-e4570e6c6b7c381b3c06c286e868837037fef2d5.tar.xz
wireguard-openbsd-e4570e6c6b7c381b3c06c286e868837037fef2d5.zip
When the -n or -t flag is given to makewhatis(8),
write names and decriptions to stdout, in a format similar to apropos(1) output. Inspired by espie@'s makewhatis.
-rw-r--r--usr.bin/mandoc/makewhatis.88
-rw-r--r--usr.bin/mandoc/mandocdb.c46
2 files changed, 44 insertions, 10 deletions
diff --git a/usr.bin/mandoc/makewhatis.8 b/usr.bin/mandoc/makewhatis.8
index 2a2bdb39480..72729cc2a4a 100644
--- a/usr.bin/mandoc/makewhatis.8
+++ b/usr.bin/mandoc/makewhatis.8
@@ -1,4 +1,4 @@
-.\" $Id: makewhatis.8,v 1.8 2014/04/03 16:26:53 schwarze Exp $
+.\" $Id: makewhatis.8,v 1.9 2014/04/04 02:31:01 schwarze Exp $
.\"
.\" Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,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: April 3 2014 $
+.Dd $Mdocdate: April 4 2014 $
.Dt MAKEWHATIS 8
.Os
.Sh NAME
@@ -103,8 +103,8 @@ Merge (remove and re-add)
to the database in
.Ar dir .
.It Fl n
-Do not create or modify any database;
-scan and parse only.
+Do not create or modify any database; scan and parse only,
+and print manual page names and descriptions to standard output.
.It Fl p
Print warnings about potential problems with manual pages
to the standard error output.
diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c
index d8ca01205ae..ced3c83771d 100644
--- a/usr.bin/mandoc/mandocdb.c
+++ b/usr.bin/mandoc/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.84 2014/04/03 21:45:27 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.85 2014/04/04 02:31:01 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -1850,11 +1850,43 @@ dbadd(struct mpage *mpage, struct mchars *mc)
size_t i;
unsigned int slot;
- if (debug)
- say(mpage->mlinks->file, "Adding to database");
-
- if (nodb)
+ mlink = mpage->mlinks;
+
+ if (nodb) {
+ while (NULL != mlink) {
+ fputs(mlink->name, stdout);
+ if (NULL == mlink->next ||
+ strcmp(mlink->dsec, mlink->next->dsec) ||
+ strcmp(mlink->fsec, mlink->next->fsec) ||
+ strcmp(mlink->arch, mlink->next->arch)) {
+ putchar('(');
+ if ('\0' == *mlink->dsec)
+ fputs(mlink->fsec, stdout);
+ else
+ fputs(mlink->dsec, stdout);
+ if ('\0' != *mlink->arch)
+ printf("/%s", mlink->arch);
+ putchar(')');
+ }
+ mlink = mlink->next;
+ if (NULL != mlink)
+ fputs(", ", stdout);
+ }
+ for (key = ohash_first(&strings, &slot); NULL != key;
+ key = ohash_next(&strings, &slot)) {
+ if (TYPE_Nd & key->mask) {
+ if (NULL == key->rendered)
+ render_key(mc, key);
+ printf(" - %s", key->rendered);
+ break;
+ }
+ }
+ putchar('\n');
return;
+ }
+
+ if (debug)
+ say(mlink->file, "Adding to database");
i = 1;
SQL_BIND_INT(stmts[STMT_INSERT_PAGE], i, FORM_SRC == mpage->form);
@@ -1862,8 +1894,10 @@ dbadd(struct mpage *mpage, struct mchars *mc)
mpage->recno = sqlite3_last_insert_rowid(db);
sqlite3_reset(stmts[STMT_INSERT_PAGE]);
- for (mlink = mpage->mlinks; mlink; mlink = mlink->next)
+ while (NULL != mlink) {
dbadd_mlink(mlink);
+ mlink = mlink->next;
+ }
for (key = ohash_first(&strings, &slot); NULL != key;
key = ohash_next(&strings, &slot)) {