version 1.58, 2015/10/06 18:32:19 |
version 1.59, 2015/10/11 21:12:55 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
#include <assert.h> |
#include <assert.h> |
|
#include <err.h> |
#include <errno.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <getopt.h> |
#include <getopt.h> |
Line 55 extern const char *const mansearch_keynames[]; |
|
Line 56 extern const char *const mansearch_keynames[]; |
|
#define SQL_BIND_TEXT(_db, _s, _i, _v) \ |
#define SQL_BIND_TEXT(_db, _s, _i, _v) \ |
do { if (SQLITE_OK != sqlite3_bind_text \ |
do { if (SQLITE_OK != sqlite3_bind_text \ |
((_s), (_i)++, (_v), -1, SQLITE_STATIC)) \ |
((_s), (_i)++, (_v), -1, SQLITE_STATIC)) \ |
fprintf(stderr, "%s\n", sqlite3_errmsg((_db))); \ |
warnx("%s", sqlite3_errmsg((_db))); \ |
} while (0) |
} while (0) |
#define SQL_BIND_INT64(_db, _s, _i, _v) \ |
#define SQL_BIND_INT64(_db, _s, _i, _v) \ |
do { if (SQLITE_OK != sqlite3_bind_int64 \ |
do { if (SQLITE_OK != sqlite3_bind_int64 \ |
((_s), (_i)++, (_v))) \ |
((_s), (_i)++, (_v))) \ |
fprintf(stderr, "%s\n", sqlite3_errmsg((_db))); \ |
warnx("%s", sqlite3_errmsg((_db))); \ |
} while (0) |
} while (0) |
#define SQL_BIND_BLOB(_db, _s, _i, _v) \ |
#define SQL_BIND_BLOB(_db, _s, _i, _v) \ |
do { if (SQLITE_OK != sqlite3_bind_blob \ |
do { if (SQLITE_OK != sqlite3_bind_blob \ |
((_s), (_i)++, (&_v), sizeof(_v), SQLITE_STATIC)) \ |
((_s), (_i)++, (&_v), sizeof(_v), SQLITE_STATIC)) \ |
fprintf(stderr, "%s\n", sqlite3_errmsg((_db))); \ |
warnx("%s", sqlite3_errmsg((_db))); \ |
} while (0) |
} while (0) |
|
|
struct expr { |
struct expr { |
Line 120 mansearch_setup(int start) |
|
Line 121 mansearch_setup(int start) |
|
|
|
if (start) { |
if (start) { |
if (NULL != pagecache) { |
if (NULL != pagecache) { |
fprintf(stderr, "pagecache already enabled\n"); |
warnx("pagecache already enabled"); |
return (int)MANDOCLEVEL_BADARG; |
return (int)MANDOCLEVEL_BADARG; |
} |
} |
|
|
Line 140 mansearch_setup(int start) |
|
Line 141 mansearch_setup(int start) |
|
if (SQLITE_OK == c) |
if (SQLITE_OK == c) |
return (int)MANDOCLEVEL_OK; |
return (int)MANDOCLEVEL_OK; |
|
|
fprintf(stderr, "pagecache: %s\n", sqlite3_errstr(c)); |
warnx("pagecache: %s", sqlite3_errstr(c)); |
|
|
} else if (NULL == pagecache) { |
} else if (NULL == pagecache) { |
fprintf(stderr, "pagecache missing\n"); |
warnx("pagecache missing"); |
return (int)MANDOCLEVEL_BADARG; |
return (int)MANDOCLEVEL_BADARG; |
} |
} |
|
|
Line 233 mansearch(const struct mansearch *search, |
|
Line 234 mansearch(const struct mansearch *search, |
|
for (i = 0; i < paths->sz; i++) { |
for (i = 0; i < paths->sz; i++) { |
if (chdir_status && paths->paths[i][0] != '/') { |
if (chdir_status && paths->paths[i][0] != '/') { |
if ( ! getcwd_status) { |
if ( ! getcwd_status) { |
fprintf(stderr, "%s: getcwd: %s\n", |
warnx("%s: getcwd: %s", paths->paths[i], buf); |
paths->paths[i], buf); |
|
continue; |
continue; |
} else if (chdir(buf) == -1) { |
} else if (chdir(buf) == -1) { |
perror(buf); |
perror(buf); |
Line 251 mansearch(const struct mansearch *search, |
|
Line 251 mansearch(const struct mansearch *search, |
|
SQLITE_OPEN_READONLY, NULL); |
SQLITE_OPEN_READONLY, NULL); |
|
|
if (SQLITE_OK != c) { |
if (SQLITE_OK != c) { |
fprintf(stderr, "%s/%s: %s\n", |
warn("%s/%s", paths->paths[i], MANDOC_DB); |
paths->paths[i], MANDOC_DB, strerror(errno)); |
|
sqlite3_close(db); |
sqlite3_close(db); |
continue; |
continue; |
} |
} |
Line 274 mansearch(const struct mansearch *search, |
|
Line 273 mansearch(const struct mansearch *search, |
|
j = 1; |
j = 1; |
c = sqlite3_prepare_v2(db, sql, -1, &s, NULL); |
c = sqlite3_prepare_v2(db, sql, -1, &s, NULL); |
if (SQLITE_OK != c) |
if (SQLITE_OK != c) |
fprintf(stderr, "%s\n", sqlite3_errmsg(db)); |
warnx("%s", sqlite3_errmsg(db)); |
|
|
for (ep = e; NULL != ep; ep = ep->next) { |
for (ep = e; NULL != ep; ep = ep->next) { |
if (NULL == ep->substr) { |
if (NULL == ep->substr) { |
Line 316 mansearch(const struct mansearch *search, |
|
Line 315 mansearch(const struct mansearch *search, |
|
} |
} |
|
|
if (SQLITE_DONE != c) |
if (SQLITE_DONE != c) |
fprintf(stderr, "%s\n", sqlite3_errmsg(db)); |
warnx("%s", sqlite3_errmsg(db)); |
|
|
sqlite3_finalize(s); |
sqlite3_finalize(s); |
|
|
Line 325 mansearch(const struct mansearch *search, |
|
Line 324 mansearch(const struct mansearch *search, |
|
"WHERE pageid=? ORDER BY sec, arch, name", |
"WHERE pageid=? ORDER BY sec, arch, name", |
-1, &s, NULL); |
-1, &s, NULL); |
if (SQLITE_OK != c) |
if (SQLITE_OK != c) |
fprintf(stderr, "%s\n", sqlite3_errmsg(db)); |
warnx("%s", sqlite3_errmsg(db)); |
|
|
c = sqlite3_prepare_v2(db, |
c = sqlite3_prepare_v2(db, |
"SELECT bits, key, pageid FROM keys " |
"SELECT bits, key, pageid FROM keys " |
"WHERE pageid=? AND bits & ?", |
"WHERE pageid=? AND bits & ?", |
-1, &s2, NULL); |
-1, &s2, NULL); |
if (SQLITE_OK != c) |
if (SQLITE_OK != c) |
fprintf(stderr, "%s\n", sqlite3_errmsg(db)); |
warnx("%s", sqlite3_errmsg(db)); |
|
|
for (mp = ohash_first(&htab, &idx); |
for (mp = ohash_first(&htab, &idx); |
NULL != mp; |
NULL != mp; |
Line 513 buildnames(const struct mansearch *search, struct manp |
|
Line 512 buildnames(const struct mansearch *search, struct manp |
|
globfree(&globinfo); |
globfree(&globinfo); |
} |
} |
if (c != SQLITE_DONE) |
if (c != SQLITE_DONE) |
fprintf(stderr, "%s\n", sqlite3_errmsg(db)); |
warnx("%s", sqlite3_errmsg(db)); |
sqlite3_reset(s); |
sqlite3_reset(s); |
|
|
/* If none of the files is usable, use the first name. */ |
/* If none of the files is usable, use the first name. */ |
Line 563 buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t pag |
|
Line 562 buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t pag |
|
output = newoutput; |
output = newoutput; |
} |
} |
if (SQLITE_DONE != c) |
if (SQLITE_DONE != c) |
fprintf(stderr, "%s\n", sqlite3_errmsg(db)); |
warnx("%s", sqlite3_errmsg(db)); |
sqlite3_reset(s); |
sqlite3_reset(s); |
return output; |
return output; |
} |
} |
Line 805 exprterm(const struct mansearch *search, char *buf, in |
|
Line 804 exprterm(const struct mansearch *search, char *buf, in |
|
free(val); |
free(val); |
if (irc) { |
if (irc) { |
regerror(irc, &e->regexp, errbuf, sizeof(errbuf)); |
regerror(irc, &e->regexp, errbuf, sizeof(errbuf)); |
fprintf(stderr, "regcomp: %s\n", errbuf); |
warnx("regcomp: %s", errbuf); |
free(e); |
free(e); |
return NULL; |
return NULL; |
} |
} |