Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/makemandb Teach whatis(1) to handle MLINKS



details:   https://anonhg.NetBSD.org/src/rev/a035d1cd9a35
branches:  trunk
changeset: 823459:a035d1cd9a35
user:      abhinav <abhinav%NetBSD.org@localhost>
date:      Sun Apr 23 16:56:49 2017 +0000

description:
Teach whatis(1) to handle MLINKS

Similar to apropos(1), whatis did not utilise the mandb_links table till now.
Therefore, if it was asked about one of the links to a man page, it would
error out. This change teaches whatis(1) to look up both the FTS table
as well as the links table, thus ensuring that it is able to answer queries
about MLINKS as well.

Comparision between outputs before this change and after this change:

#Before change
$ whatis realloc
realloc: not found

#after change
$ ./whatis realloc
realloc(3) - general memory allocation operations
realloc(3) - general purpose memory allocation functions
realloc(9) - general-purpose kernel memory allocator

diffstat:

 usr.sbin/makemandb/whatis.c |  14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diffs (42 lines):

diff -r 59f633545194 -r a035d1cd9a35 usr.sbin/makemandb/whatis.c
--- a/usr.sbin/makemandb/whatis.c       Sun Apr 23 14:34:22 2017 +0000
+++ b/usr.sbin/makemandb/whatis.c       Sun Apr 23 16:56:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: whatis.c,v 1.5 2016/05/22 19:26:04 abhinav Exp $       */
+/*     $NetBSD: whatis.c,v 1.6 2017/04/23 16:56:49 abhinav Exp $       */
 /*-
  * Copyright (c) 2012 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: whatis.c,v 1.5 2016/05/22 19:26:04 abhinav Exp $");
+__RCSID("$NetBSD: whatis.c,v 1.6 2017/04/23 16:56:49 abhinav Exp $");
 
 #include <err.h>
 #include <stdio.h>
@@ -49,8 +49,12 @@
 whatis(sqlite3 *db, const char *cmd)
 {
        static const char sqlstr[] = "SELECT name, section, name_desc"
-                                    " FROM mandb WHERE name MATCH ? AND name=?"
-                                    " ORDER BY section, name";
+               " FROM mandb WHERE name MATCH ? AND name=?"
+               " UNION"
+               " SELECT b.link AS name, b.section, a.name_desc FROM mandb a"
+               " JOIN"
+               " mandb_links b ON a.name=b.target AND a.section=b.section WHERE b.link=?"
+               " GROUP BY a.name, a.section, a.name_desc ORDER BY section, name";
        sqlite3_stmt *stmt = NULL;
        int retval;
 
@@ -60,6 +64,8 @@
                errx(EXIT_FAILURE, "Unable to query database");
        if (sqlite3_bind_text(stmt, 2, cmd, -1, NULL) != SQLITE_OK)
                errx(EXIT_FAILURE, "Unable to query database");
+       if (sqlite3_bind_text(stmt, 3, cmd, -1, NULL) != SQLITE_OK)
+               errx(EXIT_FAILURE, "Unable to query database");
        retval = 1;
        while (sqlite3_step(stmt) == SQLITE_ROW) {
                printf("%s(%s) - %s\n", sqlite3_column_text(stmt, 0),



Home | Main Index | Thread Index | Old Index