Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Make mandb path configurable. makemandb (and related tools) use
details: https://anonhg.NetBSD.org/src/rev/32af0b839921
branches: trunk
changeset: 781912:32af0b839921
user: wiz <wiz%NetBSD.org@localhost>
date: Sat Oct 06 15:33:59 2012 +0000
description:
Make mandb path configurable. makemandb (and related tools) use
the path from the _mandb variable from man.conf now.
Set _mandb in man.conf to same value as was used before.
>From Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>.
diffstat:
etc/man.conf | 8 ++------
usr.sbin/makemandb/Makefile | 13 ++++++++-----
usr.sbin/makemandb/apropos-utils.c | 38 +++++++++++++++++++++++++++++++++-----
usr.sbin/makemandb/apropos-utils.h | 7 ++++---
usr.sbin/makemandb/apropos.1 | 12 +++++++-----
usr.sbin/makemandb/apropos.c | 6 +++---
usr.sbin/makemandb/init_db.3 | 28 +++++++++++++++++++---------
usr.sbin/makemandb/makemandb.8 | 15 +++++++--------
usr.sbin/makemandb/makemandb.c | 32 ++++++++++++++++++--------------
usr.sbin/makemandb/whatis.1 | 21 ++++++++++++++-------
usr.sbin/makemandb/whatis.c | 6 +++---
11 files changed, 118 insertions(+), 68 deletions(-)
diffs (truncated from 487 to 300 lines):
diff -r b4bbebdeb7e9 -r 32af0b839921 etc/man.conf
--- a/etc/man.conf Sat Oct 06 14:41:40 2012 +0000
+++ b/etc/man.conf Sat Oct 06 15:33:59 2012 +0000
@@ -1,14 +1,10 @@
-# $NetBSD: man.conf,v 1.30 2012/02/16 22:57:19 joerg Exp $
+# $NetBSD: man.conf,v 1.31 2012/10/06 15:33:59 wiz Exp $
# Sheer, raging paranoia...
_version BSD.2
# The whatis/apropos database.
-_whatdb /usr/share/man/whatis.db
-_whatdb /usr/X11R7/man/whatis.db
-_whatdb /usr/X11R6/man/whatis.db
-_whatdb /usr/pkg/man/whatis.db
-_whatdb /usr/local/man/whatis.db
+_mandb /var/db/man.db
# Subdirectories for paths ending in '/', IN SEARCH ORDER.
_subdir cat1 man1 cat8 man8 cat6 man6 cat2 man2 cat3 man3 cat4 man4 cat5 man5 cat7 man7 man3f cat9 man9 catn mann catl manl
diff -r b4bbebdeb7e9 -r 32af0b839921 usr.sbin/makemandb/Makefile
--- a/usr.sbin/makemandb/Makefile Sat Oct 06 14:41:40 2012 +0000
+++ b/usr.sbin/makemandb/Makefile Sat Oct 06 15:33:59 2012 +0000
@@ -1,14 +1,15 @@
-# $NetBSD: Makefile,v 1.2 2012/02/16 20:58:55 joerg Exp $
+# $NetBSD: Makefile,v 1.3 2012/10/06 15:33:59 wiz Exp $
.include <bsd.own.mk>
MDIST= ${NETBSDSRCDIR}/external/bsd/mdocml/dist
MDOCDIR=${NETBSDSRCDIR}/external/bsd/mdocml
+MANCONFDIR=${NETBSDSRCDIR}/usr.bin/man
PROGS= makemandb apropos whatis
-SRCS.makemandb= makemandb.c apropos-utils.c
-SRCS.apropos= apropos.c apropos-utils.c
-SRCS.whatis= whatis.c apropos-utils.c
+SRCS.makemandb= makemandb.c apropos-utils.c manconf.c
+SRCS.apropos= apropos.c apropos-utils.c manconf.c
+SRCS.whatis= whatis.c apropos-utils.c manconf.c
MAN.makemandb= makemandb.8
MAN.apropos= apropos.1
MAN.whatis= whatis.1
@@ -17,7 +18,9 @@
BINDIR.makemandb= /usr/sbin
BINDIR.whatis= /usr/bin
-CPPFLAGS+=-I${MDIST} -I${.OBJDIR}
+.PATH: ${MANCONFDIR}
+
+CPPFLAGS+=-I${MDIST} -I${MANCONFDIR} -I${.OBJDIR}
MDOCMLOBJDIR!= cd ${MDOCDIR}/lib/libmandoc && ${PRINTOBJDIR}
MDOCMLLIB= ${MDOCMLOBJDIR}/libmandoc.a
diff -r b4bbebdeb7e9 -r 32af0b839921 usr.sbin/makemandb/apropos-utils.c
--- a/usr.sbin/makemandb/apropos-utils.c Sat Oct 06 14:41:40 2012 +0000
+++ b/usr.sbin/makemandb/apropos-utils.c Sat Oct 06 15:33:59 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apropos-utils.c,v 1.6 2012/05/10 15:36:09 joerg Exp $ */
+/* $NetBSD: apropos-utils.c,v 1.7 2012/10/06 15:33:59 wiz Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
* All rights reserved.
@@ -31,8 +31,9 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos-utils.c,v 1.6 2012/05/10 15:36:09 joerg Exp $");
+__RCSID("$NetBSD: apropos-utils.c,v 1.7 2012/10/06 15:33:59 wiz Exp $");
+#include <sys/queue.h>
#include <sys/stat.h>
#include <assert.h>
@@ -46,6 +47,7 @@
#include <zlib.h>
#include "apropos-utils.h"
+#include "manconf.h"
#include "mandoc.h"
#include "sqlite3.h"
@@ -260,6 +262,28 @@
sqlite3_result_text(pctx, (const char *) outbuf, stream.total_out, free);
}
+/*
+ * get_dbpath --
+ * Read the path of the database from man.conf and return.
+ */
+char *
+get_dbpath(const char *manconf)
+{
+ TAG *tp;
+ char *dbpath;
+
+ config(manconf);
+ tp = gettag("_mandb", 1);
+ if (!tp)
+ return NULL;
+
+ if (TAILQ_EMPTY(&tp->entrylist))
+ return NULL;
+
+ dbpath = TAILQ_LAST(&tp->entrylist, tqh)->s;
+ return dbpath;
+}
+
/* init_db --
* Prepare the database. Register the compress/uncompress functions and the
* stopword tokenizer.
@@ -276,7 +300,7 @@
* In normal cases the function should return a handle to the db.
*/
sqlite3 *
-init_db(int db_flag)
+init_db(int db_flag, const char *manconf)
{
sqlite3 *db = NULL;
sqlite3_stmt *stmt;
@@ -284,8 +308,11 @@
int rc;
int create_db_flag = 0;
+ char *dbpath = get_dbpath(manconf);
+ if (dbpath == NULL)
+ errx(EXIT_FAILURE, "_mandb entry not found in man.conf");
/* Check if the database exists or not */
- if (!(stat(DBPATH, &sb) == 0 && S_ISREG(sb.st_mode))) {
+ if (!(stat(dbpath, &sb) == 0 && S_ISREG(sb.st_mode))) {
/* Database does not exist, check if DB_CREATE was specified, and set
* flag to create the database schema
*/
@@ -299,7 +326,7 @@
/* Now initialize the database connection */
sqlite3_initialize();
- rc = sqlite3_open_v2(DBPATH, &db, db_flag, NULL);
+ rc = sqlite3_open_v2(dbpath, &db, db_flag, NULL);
if (rc != SQLITE_OK) {
warnx("%s", sqlite3_errmsg(db));
@@ -350,6 +377,7 @@
goto error;
}
return db;
+
error:
sqlite3_close(db);
sqlite3_shutdown();
diff -r b4bbebdeb7e9 -r 32af0b839921 usr.sbin/makemandb/apropos-utils.h
--- a/usr.sbin/makemandb/apropos-utils.h Sat Oct 06 14:41:40 2012 +0000
+++ b/usr.sbin/makemandb/apropos-utils.h Sat Oct 06 15:33:59 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apropos-utils.h,v 1.3 2012/05/07 11:18:16 wiz Exp $ */
+/* $NetBSD: apropos-utils.h,v 1.4 2012/10/06 15:33:59 wiz Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
* All rights reserved.
@@ -35,7 +35,7 @@
#include "sqlite3.h"
-#define DBPATH "/var/db/man.db"
+#define MANCONF "/etc/man.conf"
#define SECMAX 9
/* Flags for opening the database */
@@ -84,8 +84,9 @@
char *lower(char *);
void concat(char **, const char *);
void concat2(char **, const char *, size_t);
-sqlite3 *init_db(int);
+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 *);
diff -r b4bbebdeb7e9 -r 32af0b839921 usr.sbin/makemandb/apropos.1
--- a/usr.sbin/makemandb/apropos.1 Sat Oct 06 14:41:40 2012 +0000
+++ b/usr.sbin/makemandb/apropos.1 Sat Oct 06 15:33:59 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: apropos.1,v 1.5 2012/04/22 21:27:07 wiz Exp $
+.\" $NetBSD: apropos.1,v 1.6 2012/10/06 15:33:59 wiz Exp $
.\"
.\" Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 21, 2012
+.Dd October 5, 2012
.Dt APROPOS 1
.Os
.Sh NAME
@@ -106,9 +106,11 @@
options directly.
.El
.Sh FILES
-.Bl -hang -width -compact
-.It Pa /var/db/man.db
-The Sqlite FTS database which contains an index of the manual pages.
+.Bl -hang -width /etc/man.conf -compact
+.It Pa /etc/man.conf
+The location of the Sqlite FTS database can be configured using the
+.Cd _mandb
+tag.
.El
.Sh SEE ALSO
.Xr man 1 ,
diff -r b4bbebdeb7e9 -r 32af0b839921 usr.sbin/makemandb/apropos.c
--- a/usr.sbin/makemandb/apropos.c Sat Oct 06 14:41:40 2012 +0000
+++ b/usr.sbin/makemandb/apropos.c Sat Oct 06 15:33:59 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apropos.c,v 1.7 2012/09/07 11:28:46 wiz Exp $ */
+/* $NetBSD: apropos.c,v 1.8 2012/10/06 15:33:59 wiz 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.7 2012/09/07 11:28:46 wiz Exp $");
+__RCSID("$NetBSD: apropos.c,v 1.8 2012/10/06 15:33:59 wiz Exp $");
#include <err.h>
#include <search.h>
@@ -151,7 +151,7 @@
if (query == NULL)
errx(EXIT_FAILURE, "Try using more relevant keywords");
- if ((db = init_db(MANDB_READONLY)) == NULL)
+ if ((db = init_db(MANDB_READONLY, MANCONF)) == NULL)
exit(EXIT_FAILURE);
/* If user wants to page the output, then set some settings */
diff -r b4bbebdeb7e9 -r 32af0b839921 usr.sbin/makemandb/init_db.3
--- a/usr.sbin/makemandb/init_db.3 Sat Oct 06 14:41:40 2012 +0000
+++ b/usr.sbin/makemandb/init_db.3 Sat Oct 06 15:33:59 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: init_db.3,v 1.1 2012/02/07 19:13:32 joerg Exp $
+.\" $NetBSD: init_db.3,v 1.2 2012/10/06 15:33:59 wiz Exp $
.\"
.\" Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 17, 2011
+.Dd October 5, 2011
.Dt INIT_DB 3
.Os
.Sh NAME
@@ -38,7 +38,7 @@
.Sh SYNOPSIS
.In apropos-utils.h
.Ft sqlite3 *
-.Fn init_db "int db_flag"
+.Fn init_db "int db_flag" "char *manconf"
.Sh DESCRIPTION
The
.Fn init_db
@@ -63,24 +63,34 @@
This will open the database in read/write mode, and will also create
the database schema if it does not exist already.
.El
+.Pp
+The second argument
+.Fa manconf
+specifies the location of the man.conf configuration file.
+By default it is stored at
+.Pa /etc/man.conf .
+The location of the man.db database is configured in the configuration file
+using the
+.Cd _mandb
+tag.
.Sh RETURN VALUES
On successful execution the
.Fn init_db
function will return a pointer to a sqlite3 structure which represents
a connection to the database.
.Pp
-In case the file
-.Pa /var/db/man.db
-does not exist and
+In case the man.db file does not exist and
.Dv DB_CREATE
is not used as a value of
.Fa db_flag ,
.Dv NULL
will be returned.
.Sh FILES
-.Bl -hang -width /var/db/man.db -compact
-.It Pa /var/db/man.db
-The Sqlite FTS database which contains an index of the manual pages.
+.Bl -hang -width /etc/man.conf -compact
Home |
Main Index |
Thread Index |
Old Index