Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/makemandb Fix the #ifdef NOTYET, namely use the ter...



details:   https://anonhg.NetBSD.org/src/rev/8ab13b72b5f7
branches:  trunk
changeset: 784003:8ab13b72b5f7
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Jan 14 18:04:58 2013 +0000

description:
Fix the #ifdef NOTYET, namely use the terminal standout mode to highlight the
search terms.

diffstat:

 usr.sbin/makemandb/Makefile  |   6 ++--
 usr.sbin/makemandb/apropos.c |  49 +++++++++++++++++++++++++++++++++++--------
 2 files changed, 42 insertions(+), 13 deletions(-)

diffs (108 lines):

diff -r 41ccedda85ea -r 8ab13b72b5f7 usr.sbin/makemandb/Makefile
--- a/usr.sbin/makemandb/Makefile       Mon Jan 14 18:01:59 2013 +0000
+++ b/usr.sbin/makemandb/Makefile       Mon Jan 14 18:04:58 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2013/01/14 18:01:59 christos Exp $
+# $NetBSD: Makefile,v 1.5 2013/01/14 18:04:58 christos Exp $
 
 .include <bsd.own.mk>
 
@@ -26,8 +26,8 @@
 
 DPADD.makemandb+=      ${MDOCMLLIB} ${LIBARCHIVE} ${LIBBZ2} ${LIBLZMA}
 LDADD.makemandb+=      -L${MDOCMLOBJDIR} -lmandoc -larchive -lbz2 -llzma
-DPADD+=                ${LIBSQLITE3} ${LIBM} ${LIBZ} ${LIBUTIL}
-LDADD+=                -lsqlite3 -lm -lz -lutil
+DPADD+=                ${LIBSQLITE3} ${LIBM} ${LIBZ} ${LIBTERMLIB} ${LIBUTIL}
+LDADD+=                -lsqlite3 -lm -lz -ltermlib -lutil
 
 stopwords.c: stopwords.txt
        ( set -e; ${TOOL_NBPERF} -n stopwords_hash -s -p ${.ALLSRC};    \
diff -r 41ccedda85ea -r 8ab13b72b5f7 usr.sbin/makemandb/apropos.c
--- a/usr.sbin/makemandb/apropos.c      Mon Jan 14 18:01:59 2013 +0000
+++ b/usr.sbin/makemandb/apropos.c      Mon Jan 14 18:04:58 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apropos.c,v 1.8 2012/10/06 15:33:59 wiz Exp $  */
+/*     $NetBSD: apropos.c,v 1.9 2013/01/14 18:04:58 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.8 2012/10/06 15:33:59 wiz Exp $");
+__RCSID("$NetBSD: apropos.c,v 1.9 2013/01/14 18:04:58 christos Exp $");
 
 #include <err.h>
 #include <search.h>
@@ -40,6 +40,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <util.h>
+#include <term.h>
 
 #include "apropos-utils.h"
 #include "sqlite3.h"
@@ -65,12 +66,40 @@
 
 #define _PATH_PAGER    "/usr/bin/more -s"
 
+static int
+term_init(int fd, const char *sa[3])
+{
+       if (!isatty(fd))
+               return 0;
+
+       TERMINAL *ti;
+       int error;
+       if (ti_setupterm(&ti, NULL, fd, &error) == -1)
+               return 0;
+
+       const char *rmso = ti_getstr(ti, "rmso");
+       if (rmso == NULL)
+               goto out;
+
+       const char *smso = ti_getstr(ti, "smso");
+       if (smso == NULL)
+               goto out;
+
+       sa[0] = estrdup(smso);
+       sa[1] = estrdup(rmso);
+       sa[2] = estrdup("...");
+       del_curterm(ti);
+       return 1;
+out:
+       del_curterm(ti);
+       return 0;
+
+}
+
 int
 main(int argc, char *argv[])
 {
-#ifdef NOTYET
-       static const char *snippet_args[] = {"\033[1m", "\033[0m", "..."};
-#endif
+       const char *snippet_args[3];
        query_args args;
        char *query = NULL;     // the user query
        char *errmsg = NULL;
@@ -175,12 +204,12 @@
        args.callback_data = &cbdata;
        args.errmsg = &errmsg;
 
-#ifdef NOTYET
-       rc = run_query(db, snippet_args, &args);
-#else
-       rc = run_query_pager(db, &args);
-#endif
 
+       if (term_init(STDOUT_FILENO, snippet_args))
+               rc = run_query(db, snippet_args, &args);
+       else
+               rc = run_query_pager(db, &args);
+               
        free(query);
        close_db(db);
        if (errmsg) {



Home | Main Index | Thread Index | Old Index