aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--apropos.c4
-rw-r--r--mansearch.c50
-rw-r--r--mansearch.h3
3 files changed, 54 insertions, 3 deletions
diff --git a/apropos.c b/apropos.c
index c9fabe26..48f01bb6 100644
--- a/apropos.c
+++ b/apropos.c
@@ -1,4 +1,4 @@
-/* $Id: apropos.c,v 1.37 2014/01/06 03:02:46 schwarze Exp $ */
+/* $Id: apropos.c,v 1.38 2014/04/11 15:46:52 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -95,6 +95,7 @@ main(int argc, char *argv[])
search.flags = whatis ? MANSEARCH_WHATIS : 0;
manpath_parse(&paths, conf_file, defpaths, auxpaths);
+ mansearch_setup(1);
ch = mansearch(&search, &paths, argc, argv, outkey, &res, &sz);
manpath_free(&paths);
@@ -110,6 +111,7 @@ main(int argc, char *argv[])
}
free(res);
+ mansearch_setup(0);
return(sz ? EXIT_SUCCESS : EXIT_FAILURE);
usage:
fprintf(stderr, "usage: %s [-C file] [-M path] [-m path] "
diff --git a/mansearch.c b/mansearch.c
index b2c7fe6d..d7c75072 100644
--- a/mansearch.c
+++ b/mansearch.c
@@ -1,4 +1,4 @@
-/* $Id: mansearch.c,v 1.27 2014/04/10 02:46:21 schwarze Exp $ */
+/* $Id: mansearch.c,v 1.28 2014/04/11 15:46:52 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -19,6 +19,7 @@
#include "config.h"
#endif
+#include <sys/mman.h>
#include <assert.h>
#include <fcntl.h>
#include <getopt.h>
@@ -101,6 +102,53 @@ static void sql_regexp(sqlite3_context *context,
static char *sql_statement(const struct expr *);
int
+mansearch_setup(int start)
+{
+ static void *pagecache;
+ int c;
+
+#define PC_PAGESIZE 1280
+#define PC_NUMPAGES 256
+
+ if (start) {
+ if (NULL != pagecache) {
+ fprintf(stderr, "pagecache already enabled\n");
+ return((int)MANDOCLEVEL_BADARG);
+ }
+
+ pagecache = mmap(NULL, PC_PAGESIZE * PC_NUMPAGES,
+ PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
+
+ if (MAP_FAILED == pagecache) {
+ perror("mmap");
+ pagecache = NULL;
+ return((int)MANDOCLEVEL_SYSERR);
+ }
+
+ c = sqlite3_config(SQLITE_CONFIG_PAGECACHE,
+ pagecache, PC_PAGESIZE, PC_NUMPAGES);
+
+ if (SQLITE_OK == c)
+ return((int)MANDOCLEVEL_OK);
+
+ fprintf(stderr, "pagecache: %s\n", sqlite3_errstr(c));
+
+ } else if (NULL == pagecache) {
+ fprintf(stderr, "pagecache missing\n");
+ return((int)MANDOCLEVEL_BADARG);
+ }
+
+ if (-1 == munmap(pagecache, PC_PAGESIZE * PC_NUMPAGES)) {
+ perror("munmap");
+ pagecache = NULL;
+ return((int)MANDOCLEVEL_SYSERR);
+ }
+
+ pagecache = NULL;
+ return((int)MANDOCLEVEL_OK);
+}
+
+int
mansearch(const struct mansearch *search,
const struct manpaths *paths,
int argc, char *argv[],
diff --git a/mansearch.h b/mansearch.h
index 706515c9..c78b00ac 100644
--- a/mansearch.h
+++ b/mansearch.h
@@ -1,4 +1,4 @@
-/* $Id: mansearch.h,v 1.12 2014/04/10 02:46:21 schwarze Exp $ */
+/* $Id: mansearch.h,v 1.13 2014/04/11 15:46:52 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -85,6 +85,7 @@ struct mansearch {
#define MANSEARCH_WHATIS 0x01 /* whatis mode: equality, no key */
};
+int mansearch_setup(int);
int mansearch(const struct mansearch *cfg, /* options */
const struct manpaths *paths, /* manpaths */
int argc, /* size of argv */