Skip to content

Commit

Permalink
Make mandb path configurable. makemandb (and related tools) use
Browse files Browse the repository at this point in the history
the path from the _mandb variable from man.conf now.

Set _mandb in man.conf to same value as was used before.

patch from me, committed by wiz in NetBSD repo, diff imported.
  • Loading branch information
abhinav-upadhyay committed Dec 23, 2012
1 parent 3a0cc07 commit 9ef3c99
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions apropos-utils.c
Original file line number Diff line number Diff line change
@@ -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>
* All rights reserved.
Expand Down Expand Up @@ -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>
Expand All @@ -46,6 +47,7 @@ __RCSID("$NetBSD: apropos-utils.c,v 1.6 2012/05/10 15:36:09 joerg Exp $");
#include <zlib.h>

#include "apropos-utils.h"
#include "manconf.h"
#include "mandoc.h"
#include "sqlite3.h"

Expand Down Expand Up @@ -260,6 +262,28 @@ unzip(sqlite3_context *pctx, int nval, sqlite3_value **apval)
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.
Expand All @@ -276,16 +300,19 @@ unzip(sqlite3_context *pctx, int nval, sqlite3_value **apval)
* 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;
struct stat sb;
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
*/
Expand All @@ -299,7 +326,7 @@ init_db(int db_flag)

/* 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));
Expand Down Expand Up @@ -350,6 +377,7 @@ init_db(int db_flag)
goto error;
}
return db;

error:
sqlite3_close(db);
sqlite3_shutdown();
Expand Down

0 comments on commit 9ef3c99

Please sign in to comment.