aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2013-12-27 18:51:25 +0000
committerIngo Schwarze <schwarze@openbsd.org>2013-12-27 18:51:25 +0000
commita7ed20ecbd09e040f50a359f60f9ac351bafd50f (patch)
tree206053d141537f164a475ed3e3189b2821fca7e0
parentf025d38ef1ad098b22a683e883f7b6ddce37cd66 (diff)
downloadmandoc-a7ed20ecbd09e040f50a359f60f9ac351bafd50f.tar.gz
mandoc-a7ed20ecbd09e040f50a359f60f9ac351bafd50f.tar.zst
mandoc-a7ed20ecbd09e040f50a359f60f9ac351bafd50f.zip
Change the mansearch() interface to use the mlinks table in the database
and return a list of names with sections, used by apropos(1) for display. While here, improve uniformity of the interface by allocating the file name dynamically, just like the names list and the description.
-rw-r--r--apropos.c6
-rw-r--r--manpage.c11
-rw-r--r--mansearch.c59
-rw-r--r--mansearch.h5
4 files changed, 66 insertions, 15 deletions
diff --git a/apropos.c b/apropos.c
index 96313bc1..f9f71138 100644
--- a/apropos.c
+++ b/apropos.c
@@ -1,4 +1,4 @@
-/* $Id: apropos.c,v 1.34 2013/07/05 09:33:02 schwarze Exp $ */
+/* $Id: apropos.c,v 1.35 2013/12/27 18:51:25 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -96,7 +96,9 @@ main(int argc, char *argv[])
goto usage;
for (i = 0; i < sz; i++) {
- printf("%s - %s\n", res[i].file, res[i].desc);
+ printf("%s - %s\n", res[i].names, res[i].desc);
+ free(res[i].file);
+ free(res[i].names);
free(res[i].desc);
}
diff --git a/manpage.c b/manpage.c
index dadf98f1..9c98b21d 100644
--- a/manpage.c
+++ b/manpage.c
@@ -1,4 +1,4 @@
-/* $Id: manpage.c,v 1.4 2013/06/05 02:00:26 schwarze Exp $ */
+/* $Id: manpage.c,v 1.5 2013/12/27 18:51:25 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -106,11 +106,14 @@ main(int argc, char *argv[])
for (i = 0; i < sz; i++) {
printf("%6zu %s: %s\n",
- i + 1, res[i].file, res[i].desc);
+ i + 1, res[i].names, res[i].desc);
+ free(res[i].names);
free(res[i].desc);
}
if (0 == term) {
+ for (i = 0; i < sz; i++)
+ free(res[i].file);
free(res);
return(EXIT_SUCCESS);
}
@@ -127,12 +130,16 @@ main(int argc, char *argv[])
}
if (0 == i) {
+ for (i = 0; i < sz; i++)
+ free(res[i].file);
free(res);
return(EXIT_SUCCESS);
}
show:
cmd = res[i - 1].form ? "mandoc" : "cat";
strlcpy(buf, res[i - 1].file, PATH_MAX);
+ for (i = 0; i < sz; i++)
+ free(res[i].file);
free(res);
show(cmd, buf);
diff --git a/mansearch.c b/mansearch.c
index 05d11293..829152e4 100644
--- a/mansearch.c
+++ b/mansearch.c
@@ -1,4 +1,4 @@
-/* $Id: mansearch.c,v 1.9 2013/12/27 01:16:54 schwarze Exp $ */
+/* $Id: mansearch.c,v 1.10 2013/12/27 18:51:25 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -144,7 +144,9 @@ mansearch(const struct mansearch *search,
int fd, rc, c;
int64_t id;
char buf[PATH_MAX];
- char *sql;
+ char *sql, *newnames;
+ const char *oldnames, *sep1, *name, *sec, *sep2, *arch;
+ struct manpage *mpage;
struct expr *e, *ep;
sqlite3 *db;
sqlite3_stmt *s;
@@ -282,7 +284,12 @@ mansearch(const struct mansearch *search,
fprintf(stderr, "%s\n", sqlite3_errmsg(db));
sqlite3_finalize(s);
- sqlite3_close(db);
+
+ c = sqlite3_prepare_v2(db,
+ "SELECT * FROM mlinks WHERE pageid=?",
+ -1, &s, NULL);
+ if (SQLITE_OK != c)
+ fprintf(stderr, "%s\n", sqlite3_errmsg(db));
for (mp = ohash_first(&htab, &idx);
NULL != mp;
@@ -292,16 +299,50 @@ mansearch(const struct mansearch *search,
*res = mandoc_realloc
(*res, maxres * sizeof(struct manpage));
}
- strlcpy((*res)[cur].file,
- paths->paths[i], PATH_MAX);
- strlcat((*res)[cur].file, "/", PATH_MAX);
- strlcat((*res)[cur].file, mp->file, PATH_MAX);
- (*res)[cur].desc = mp->desc;
- (*res)[cur].form = mp->form;
+ mpage = *res + cur;
+ if (-1 == asprintf(&mpage->file, "%s/%s",
+ paths->paths[i], mp->file)) {
+ perror(0);
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
+ mpage->names = NULL;
+ mpage->desc = mp->desc;
+ mpage->form = mp->form;
+
+ j = 1;
+ SQL_BIND_INT64(db, s, j, mp->id);
+ while (SQLITE_ROW == (c = sqlite3_step(s))) {
+ if (NULL == mpage->names) {
+ oldnames = "";
+ sep1 = "";
+ } else {
+ oldnames = mpage->names;
+ sep1 = ", ";
+ }
+ sec = sqlite3_column_text(s, 1);
+ arch = sqlite3_column_text(s, 2);
+ name = sqlite3_column_text(s, 3);
+ sep2 = '\0' == *arch ? "" : "/";
+ if (-1 == asprintf(&newnames,
+ "%s%s%s(%s%s%s)", oldnames, sep1,
+ name, sec, sep2, arch)) {
+ perror(0);
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
+ free(mpage->names);
+ mpage->names = newnames;
+ }
+ if (SQLITE_DONE != c)
+ fprintf(stderr, "%s\n", sqlite3_errmsg(db));
+ sqlite3_reset(s);
+
free(mp->file);
free(mp);
cur++;
}
+
+ sqlite3_finalize(s);
+ sqlite3_close(db);
ohash_delete(&htab);
}
rc = 1;
diff --git a/mansearch.h b/mansearch.h
index 25e6d6b7..d433e25d 100644
--- a/mansearch.h
+++ b/mansearch.h
@@ -1,4 +1,4 @@
-/* $Id: mansearch.h,v 1.4 2013/06/06 14:27:02 schwarze Exp $ */
+/* $Id: mansearch.h,v 1.5 2013/12/27 18:51:25 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -61,7 +61,8 @@
__BEGIN_DECLS
struct manpage {
- char file[PATH_MAX]; /* prefixed by manpath */
+ char *file; /* to be prefixed by manpath */
+ char *names; /* a list of names with sections */
char *desc; /* description of manpage */
int form; /* 0 == catpage */
};