Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/makemandb instead of having a format and no format ...



details:   https://anonhg.NetBSD.org/src/rev/124329fb47e6
branches:  trunk
changeset: 785843:124329fb47e6
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Apr 02 17:16:50 2013 +0000

description:
instead of having a format and no format flag, and exposing various formatters,
provide a format enum and expose html formatting too.

diffstat:

 usr.sbin/makemandb/apropos-utils.3 |  10 +----
 usr.sbin/makemandb/apropos-utils.c |  68 ++++++++++++++++++++++++-------------
 usr.sbin/makemandb/apropos-utils.h |  16 +++++---
 usr.sbin/makemandb/apropos.1       |  16 +++++---
 usr.sbin/makemandb/apropos.c       |  54 ++++++++++++++++++++----------
 5 files changed, 100 insertions(+), 64 deletions(-)

diffs (truncated from 371 to 300 lines):

diff -r 4653a2a7b5b2 -r 124329fb47e6 usr.sbin/makemandb/apropos-utils.3
--- a/usr.sbin/makemandb/apropos-utils.3        Tue Apr 02 13:31:47 2013 +0000
+++ b/usr.sbin/makemandb/apropos-utils.3        Tue Apr 02 17:16:50 2013 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: apropos-utils.3,v 1.1 2012/02/07 19:13:32 joerg Exp $
+.\" $NetBSD: apropos-utils.3,v 1.2 2013/04/02 17:16:50 christos Exp $
 .\"
 .\" Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
 .\" All rights reserved.
@@ -42,11 +42,7 @@
 .Ft void
 .Fn close_db "sqlite3 *db"
 .Ft int
-.Fn run_query "sqlite3 *db" "const char *snippet_args[3]" "query_args *args"
-.Ft int
-.Fn run_query_html "sqlite3 *db" "query_args *args"
-.Ft int
-.Fn run_query_pager "sqlite3 *db" "query_args *args"
+.Fn run_query "sqlite3 *db" "query_format fmt" "query_args *args"
 .Sh DESCRIPTION
 These functions all live in the
 .Pa apropos-utils.h
@@ -61,7 +57,5 @@
 .Xr close_db 3 ,
 .Xr init_db 3 ,
 .Xr run_query 3 ,
-.Xr run_query_html 3 ,
-.Xr run_query_pager 3
 .Sh AUTHORS
 .An Abhinav Upadhyay
diff -r 4653a2a7b5b2 -r 124329fb47e6 usr.sbin/makemandb/apropos-utils.c
--- a/usr.sbin/makemandb/apropos-utils.c        Tue Apr 02 13:31:47 2013 +0000
+++ b/usr.sbin/makemandb/apropos-utils.c        Tue Apr 02 17:16:50 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apropos-utils.c,v 1.14 2013/03/29 20:46:07 christos Exp $      */
+/*     $NetBSD: apropos-utils.c,v 1.15 2013/04/02 17:16:50 christos Exp $      */
 /*-
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
  * All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos-utils.c,v 1.14 2013/03/29 20:46:07 christos Exp $");
+__RCSID("$NetBSD: apropos-utils.c,v 1.15 2013/04/02 17:16:50 christos Exp $");
 
 #include <sys/queue.h>
 #include <sys/stat.h>
@@ -468,8 +468,8 @@
  *  arpopos-utils.h for the description of individual fields.
  *
  */
-int
-run_query(sqlite3 *db, const char *snippet_args[3], query_args *args)
+static int
+run_query_internal(sqlite3 *db, const char *snippet_args[3], query_args *args)
 {
        const char *default_snippet_args[3];
        char *section_clause = NULL;
@@ -719,7 +719,7 @@
  *  inline HTML fragments.
  *  After that it delegates the call the actual user supplied callback function.
  */
-int
+static int
 run_query_html(sqlite3 *db, query_args *args)
 {
        struct orig_callback_data orig_data;
@@ -728,7 +728,7 @@
        const char *snippet_args[] = {"\002", "\003", "..."};
        args->callback = &callback_html;
        args->callback_data = (void *) &orig_data;
-       return run_query(db, snippet_args, args);
+       return run_query_internal(db, snippet_args, args);
 }
 
 /*
@@ -879,24 +879,16 @@
  *  For this purpose it first calls it's own callback function callback_pager
  *  which then delegates the call to the user supplied callback.
  */
-int
+static int
 run_query_pager(sqlite3 *db, query_args *args)
 {
        struct orig_callback_data orig_data;
        orig_data.callback = args->callback;
        orig_data.data = args->callback_data;
-       const char *snippet_args[3];
-
-       if (args->flags & APROPOS_NOFORMAT) {
-               snippet_args[0] = snippet_args[1] = "";
-       } else {
-               snippet_args[0] = "\002";
-               snippet_args[1] = "\003";
-       }
-       snippet_args[2] = "...";
+       const char *snippet_args[3] = { "\002", "\003", "..." };
        args->callback = &callback_pager;
        args->callback_data = (void *) &orig_data;
-       return run_query(db, snippet_args, args);
+       return run_query_internal(db, snippet_args, args);
 }
 
 static void
@@ -944,7 +936,7 @@
  *  For this purpose it first calls it's own callback function callback_pager
  *  which then delegates the call to the user supplied callback.
  */
-int
+static int
 run_query_term(sqlite3 *db, query_args *args)
 {
        struct orig_callback_data orig_data;
@@ -952,17 +944,43 @@
        orig_data.callback = args->callback;
        orig_data.data = args->callback_data;
        const char *snippet_args[5];
-       if (args->flags & APROPOS_NOFORMAT) {
-               snippet_args[0] = snippet_args[1] = snippet_args[3] =
-                   snippet_args[4] = "";
-               snippet_args[2] = "...";
-       } else
-               term_init(STDOUT_FILENO, snippet_args);
+
+       term_init(STDOUT_FILENO, snippet_args);
        ta.smul = snippet_args[3];
        ta.rmul = snippet_args[4];
        ta.orig_data = (void *) &orig_data;
 
        args->callback = &callback_term;
        args->callback_data = &ta;
-       return run_query(db, snippet_args, args);
+       return run_query_internal(db, snippet_args, args);
+}
+
+static int
+run_query_none(sqlite3 *db, query_args *args)
+{
+       struct orig_callback_data orig_data;
+       orig_data.callback = args->callback;
+       orig_data.data = args->callback_data;
+       const char *snippet_args[3] = { "", "", "..." };
+       args->callback = &callback_pager;
+       args->callback_data = (void *) &orig_data;
+       return run_query_internal(db, snippet_args, args);
 }
+
+int
+run_query(sqlite3 *db, query_format fmt, query_args *args)
+{
+       switch (fmt) {
+       case APROPOS_NONE:
+               return run_query_none(db, args);
+       case APROPOS_HTML:
+               return run_query_html(db, args);
+       case APROPOS_TERM:
+               return run_query_term(db, args);
+       case APROPOS_PAGER:
+               return run_query_pager(db, args);
+       default:
+               warnx("Unknown query format %d", (int)fmt);
+               return -1;
+       }
+}
diff -r 4653a2a7b5b2 -r 124329fb47e6 usr.sbin/makemandb/apropos-utils.h
--- a/usr.sbin/makemandb/apropos-utils.h        Tue Apr 02 13:31:47 2013 +0000
+++ b/usr.sbin/makemandb/apropos-utils.h        Tue Apr 02 17:16:50 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apropos-utils.h,v 1.8 2013/03/29 20:07:31 christos Exp $       */
+/*     $NetBSD: apropos-utils.h,v 1.9 2013/04/02 17:16:50 christos Exp $       */
 /*-
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
  * All rights reserved.
@@ -80,18 +80,20 @@
                const char *, size_t);  // The callback function
        void *callback_data;    // data to pass to the callback function
        char **errmsg;          // buffer for storing the error msg
-       int  flags;
-#define APROPOS_NOFORMAT 1
 } query_args;
 
+typedef enum query_format {
+    APROPOS_NONE,
+    APROPOS_PAGER,
+    APROPOS_TERM,
+    APROPOS_HTML
+} query_format;
+
 char *lower(char *);
 void concat(char **, const char *);
 void concat2(char **, const char *, size_t);
 sqlite3 *init_db(int, const char *);
 void close_db(sqlite3 *);
 char *get_dbpath(const char *);
-int run_query(sqlite3 *, const char *[3], query_args *);
-int run_query_html(sqlite3 *, query_args *);
-int run_query_pager(sqlite3 *, query_args *);
-int run_query_term(sqlite3 *, query_args *);
+int run_query(sqlite3 *, query_format, query_args *);
 #endif
diff -r 4653a2a7b5b2 -r 124329fb47e6 usr.sbin/makemandb/apropos.1
--- a/usr.sbin/makemandb/apropos.1      Tue Apr 02 13:31:47 2013 +0000
+++ b/usr.sbin/makemandb/apropos.1      Tue Apr 02 17:16:50 2013 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: apropos.1,v 1.11 2013/03/29 21:39:09 wiz Exp $
+.\" $NetBSD: apropos.1,v 1.12 2013/04/02 17:16:50 christos Exp $
 .\"
 .\" Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
 .\" All rights reserved.
@@ -37,7 +37,7 @@
 .Nd search the complete content of all man pages
 .Sh SYNOPSIS
 .Nm
-.Op Fl 123456789Ccilpr
+.Op Fl 123456789CchilPpr
 .Op Fl n Ar results
 .Op Fl S Ar machine
 .Op Fl s Ar section
@@ -72,19 +72,23 @@
 Do not show the context of the match.
 .It Fl c
 Do show the context of the match (default).
+.It Fl h
+Turn on html formatting.
 .It Fl i
-Turn on escape code formatting.
+Turn on terminal escape code formatting.
 .It Fl l
 Legacy mode: Only searches name and name description.
-Does not print context, or escape format the text.
+Does not print context and turns off formatting.
 .It Fl n Ar results
 Output up to the specified number of search results.
 The default limit is infinity.
+.It Fl P
+Turn on pager formatting.
 .It Fl p
-Pipe the results through a pager (defaulting to
+Turn on pager formatting, and pipe the results through a pager (defaulting to
 .Xr more 1 ) .
 .It Fl r
-On tty output don't issue any formatting escape codes.
+Turn off formatting.
 .It Fl S Ar machine
 Limit the search to the pages for the specified machine architecture.
 By default pages for all architectures are shown in the search results.
diff -r 4653a2a7b5b2 -r 124329fb47e6 usr.sbin/makemandb/apropos.c
--- a/usr.sbin/makemandb/apropos.c      Tue Apr 02 13:31:47 2013 +0000
+++ b/usr.sbin/makemandb/apropos.c      Tue Apr 02 17:16:50 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apropos.c,v 1.15 2013/03/29 21:39:16 wiz Exp $ */
+/*     $NetBSD: apropos.c,v 1.16 2013/04/02 17:16:50 christos Exp $    */
 /*-
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
  * All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos.c,v 1.15 2013/03/29 21:39:16 wiz Exp $");
+__RCSID("$NetBSD: apropos.c,v 1.16 2013/04/02 17:16:50 christos Exp $");
 
 #include <err.h>
 #include <search.h>
@@ -49,7 +49,7 @@
        int nresults;
        int pager;
        int no_context;
-       int no_format;
+       query_format format;
        int legacy;
        const char *machine;
 } apropos_flags;
@@ -71,7 +71,7 @@
 parseargs(int argc, char **argv, struct apropos_flags *aflags)
 {
        int ch;
-       while ((ch = getopt(argc, argv, "123456789Cciln:prS:s:")) != -1) {
+       while ((ch = getopt(argc, argv, "123456789Cchiln:PprS:s:")) != -1) {
                switch (ch) {
                case '1':
                case '2':
@@ -90,22 +90,28 @@
                case 'c':
                        aflags->no_context = 0;
                        break;
+               case 'h':
+                       aflags->format = APROPOS_HTML;
+                       break;
                case 'i':
-                       aflags->no_format = 0;
+                       aflags->format = APROPOS_TERM;
                        break;
                case 'l':
                        aflags->legacy = 1;
                        aflags->no_context = 1;
-                       aflags->no_format = 1;
+                       aflags->format = APROPOS_NONE;
                        break;



Home | Main Index | Thread Index | Old Index