Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/usr.sbin/makemandb/apropos-utils.c,v rcsdiff: /ftp/cvs/cvsroot/src/usr.sbin/makemandb/apropos-utils.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.4.2.3 retrieving revision 1.4.2.4 diff -u -p -r1.4.2.3 -r1.4.2.4 --- src/usr.sbin/makemandb/apropos-utils.c 2012/05/23 10:08:29 1.4.2.3 +++ src/usr.sbin/makemandb/apropos-utils.c 2012/10/30 19:00:37 1.4.2.4 @@ -1,4 +1,4 @@ -/* $NetBSD: apropos-utils.c,v 1.4.2.3 2012/05/23 10:08:29 yamt Exp $ */ +/* $NetBSD: apropos-utils.c,v 1.4.2.4 2012/10/30 19:00:37 yamt Exp $ */ /*- * Copyright (c) 2011 Abhinav Upadhyay * All rights reserved. @@ -31,8 +31,9 @@ */ #include -__RCSID("$NetBSD: apropos-utils.c,v 1.4.2.3 2012/05/23 10:08:29 yamt Exp $"); +__RCSID("$NetBSD: apropos-utils.c,v 1.4.2.4 2012/10/30 19:00:37 yamt Exp $"); +#include #include #include @@ -46,6 +47,7 @@ __RCSID("$NetBSD: apropos-utils.c,v 1.4. #include #include "apropos-utils.h" +#include "manconf.h" #include "mandoc.h" #include "sqlite3.h" @@ -260,6 +262,28 @@ unzip(sqlite3_context *pctx, int nval, s 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 @@ unzip(sqlite3_context *pctx, int nval, s * 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 @@ init_db(int db_flag) 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 @@ 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)); @@ -350,6 +377,7 @@ init_db(int db_flag) goto error; } return db; + error: sqlite3_close(db); sqlite3_shutdown();