aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/catman.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-12-04 22:52:50 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-12-04 22:52:50 +0000
commit7284ec2208ed30f3a0d6f9975f330a7ebb44b988 (patch)
tree1cef240b362ef33cdde98cc81f41390579c245cb /catman.c
parent472358268a3a5ae7eff4dbde1e48f925e8c7d82b (diff)
downloadmandoc-7284ec2208ed30f3a0d6f9975f330a7ebb44b988.tar.gz
mandoc-7284ec2208ed30f3a0d6f9975f330a7ebb44b988.tar.zst
mandoc-7284ec2208ed30f3a0d6f9975f330a7ebb44b988.zip
Make catman and man.cgi understand the index type-field.
Also make catman's man.conf be generated as catman.conf to avoid clobbering a real man.conf file. Finally, add a placeholder catman() function to man.cgi for preformatted manuals in the cache.
Diffstat (limited to 'catman.c')
-rw-r--r--catman.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/catman.c b/catman.c
index f3e214e6..7118e1ba 100644
--- a/catman.c
+++ b/catman.c
@@ -1,4 +1,4 @@
-/* $Id: catman.c,v 1.2 2011/11/27 11:46:44 kristaps Exp $ */
+/* $Id: catman.c,v 1.3 2011/12/04 22:52:50 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -265,12 +265,12 @@ jobstart(const char *dst, const char *src, pid_t *pid)
static int
indexhtml(char *dst)
{
- DB *db;
+ DB *idx;
DBT key, val;
size_t sz;
int c, rc;
unsigned int fl;
- const char *f;
+ const char *f, *cp;
char *d;
char fname[MAXPATHLEN];
pid_t pid;
@@ -281,25 +281,32 @@ indexhtml(char *dst)
xstrlcpy(fname, dst, MAXPATHLEN);
xstrlcat(fname, "/mandoc.index", MAXPATHLEN);
- db = dbopen(fname, O_RDONLY, 0, DB_RECNO, NULL);
- if (NULL == db) {
+ idx = dbopen(fname, O_RDONLY, 0, DB_RECNO, NULL);
+ if (NULL == idx) {
perror(fname);
return(-1);
}
fl = R_FIRST;
- while (0 == (c = (*db->seq)(db, &key, &val, fl))) {
+ while (0 == (c = (*idx->seq)(idx, &key, &val, fl))) {
fl = R_NEXT;
- f = (const char *)val.data;
+ cp = (const char *)val.data;
+ if (0 == val.size)
+ continue;
+ if (NULL == (f = memchr(cp, '\0', val.size)))
+ break;
+ if (++f - cp >= (int)val.size)
+ break;
+ if (NULL == memchr(f, '\0', val.size - (f - cp)))
+ break;
dst[(int)sz] = '\0';
xstrlcat(dst, "/", MAXPATHLEN);
xstrlcat(dst, f, MAXPATHLEN);
- /*xstrlcat(dst, ".html", MAXPATHLEN);*/
if (-1 == (rc = isnewer(dst, f))) {
- fprintf(stderr, "%s: Manpage missing\n", f);
+ fprintf(stderr, "%s: File missing\n", f);
break;
} else if (0 == rc)
continue;
@@ -317,19 +324,24 @@ indexhtml(char *dst)
if ( ! filecpy(dst, f))
break;
-
- /*if ( ! jobstart(dst, f, &pid))
- break;*/
+#if 0
+ if ( ! jobstart(dst, f, &pid))
+ break;
+#endif
if (verbose)
printf("%s\n", dst);
}
- (*db->close)(db);
+ (*idx->close)(idx);
if (c < 0)
perror(fname);
- /*if ( ! jobwait(pid))
- c = -1;*/
+ else if (0 == c)
+ fprintf(stderr, "%s: Corrupt index\n", fname);
+#if 0
+ if ( ! jobwait(pid))
+ c = -1;
+#endif
return(1 == c ? 1 : -1);
}
@@ -433,7 +445,7 @@ manup(const struct manpaths *dirs, const char *dir)
return(0);
}
- xstrlcat(dst, "/man.conf", MAXPATHLEN);
+ xstrlcat(dst, "/catman.conf", MAXPATHLEN);
if (verbose)
printf("%s\n", dst);