summaryrefslogtreecommitdiffstats
path: root/usr.bin/mandoc/cgi.c
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-07-13 12:31:00 +0000
committerschwarze <schwarze@openbsd.org>2014-07-13 12:31:00 +0000
commit46723f19eb8576452765d24b71ce746695447690 (patch)
tree7cb643fbe4e42f0d1db8319a0aa18e5692d3705d /usr.bin/mandoc/cgi.c
parentInstall some config files with mode 0600 as they were before the move to (diff)
downloadwireguard-openbsd-46723f19eb8576452765d24b71ce746695447690.tar.xz
wireguard-openbsd-46723f19eb8576452765d24b71ce746695447690.zip
By popular demand, bring man.cgi default mode closer to what man(1) does:
Even when there are multiple pages with the same name in different sections, show one of them, using the same priorities as in the default man.conf(5) file.
Diffstat (limited to 'usr.bin/mandoc/cgi.c')
-rw-r--r--usr.bin/mandoc/cgi.c68
1 files changed, 47 insertions, 21 deletions
diff --git a/usr.bin/mandoc/cgi.c b/usr.bin/mandoc/cgi.c
index f68977e75cc..c0c1a9c77d9 100644
--- a/usr.bin/mandoc/cgi.c
+++ b/usr.bin/mandoc/cgi.c
@@ -1,4 +1,4 @@
-/* $Id: cgi.c,v 1.9 2014/07/13 09:58:52 schwarze Exp $ */
+/* $Id: cgi.c,v 1.10 2014/07/13 12:31:00 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@usta.de>
@@ -73,10 +73,12 @@ static void resp_noresult(const struct req *,
static void resp_search(const struct req *,
struct manpage *, size_t);
static void resp_searchform(const struct req *);
+static void resp_show(const struct req *, const char *);
static const char *scriptname; /* CGI script name */
static const char *httphost; /* hostname used in the URIs */
+static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
static const char *const sec_numbers[] = {
"0", "1", "2", "3", "3p", "4", "5", "6", "7", "8", "9"
};
@@ -504,7 +506,9 @@ resp_error_internal(void)
static void
resp_search(const struct req *req, struct manpage *r, size_t sz)
{
- size_t i;
+ size_t i, iuse, isec;
+ int prio, priouse;
+ char sec;
if (1 == sz) {
/*
@@ -546,6 +550,30 @@ resp_search(const struct req *req, struct manpage *r, size_t sz)
puts("</TABLE>\n"
"</DIV>");
+
+ /*
+ * In man(1) mode, show one of the pages
+ * even if more than one is found.
+ */
+
+ if (req->q.equal) {
+ puts("<HR>");
+ iuse = 0;
+ priouse = 10;
+ for (i = 0; i < sz; i++) {
+ isec = strcspn(r[i].file, "123456789");
+ sec = r[i].file[isec];
+ if ('\0' == sec)
+ continue;
+ prio = sec_prios[sec - '1'];
+ if (prio >= priouse)
+ continue;
+ priouse = prio;
+ iuse = i;
+ }
+ resp_show(req, r[iuse].file);
+ }
+
resp_end_html();
}
@@ -559,13 +587,10 @@ catman(const struct req *req, const char *file)
int italic, bold;
if (NULL == (f = fopen(file, "r"))) {
- resp_error_badrequest(
- "You specified an invalid manual file.");
+ puts("<P>You specified an invalid manual file.</P>");
return;
}
- resp_begin_html(200, NULL);
- resp_searchform(req);
puts("<DIV CLASS=\"catman\">\n"
"<PRE>");
@@ -679,9 +704,7 @@ catman(const struct req *req, const char *file)
}
puts("</PRE>\n"
- "</DIV>\n"
- "</BODY>\n"
- "</HTML>");
+ "</DIV>");
fclose(f);
}
@@ -698,8 +721,7 @@ format(const struct req *req, const char *file)
char opts[PATH_MAX + 128];
if (-1 == (fd = open(file, O_RDONLY, 0))) {
- resp_error_badrequest(
- "You specified an invalid manual file.");
+ puts("<P>You specified an invalid manual file.</P>");
return;
}
@@ -728,9 +750,6 @@ format(const struct req *req, const char *file)
return;
}
- resp_begin_html(200, NULL);
- resp_searchform(req);
-
vp = html_alloc(opts);
if (NULL != mdoc)
@@ -738,14 +757,21 @@ format(const struct req *req, const char *file)
else
html_man(vp, man);
- puts("</BODY>\n"
- "</HTML>");
-
html_free(vp);
mparse_free(mp);
}
static void
+resp_show(const struct req *req, const char *file)
+{
+
+ if ('c' == *file)
+ catman(req, file);
+ else
+ format(req, file);
+}
+
+static void
pg_show(const struct req *req, const char *path)
{
char *sub;
@@ -769,10 +795,10 @@ pg_show(const struct req *req, const char *path)
return;
}
- if ('c' == *sub)
- catman(req, sub);
- else
- format(req, sub);
+ resp_begin_html(200, NULL);
+ resp_searchform(req);
+ resp_show(req, sub);
+ resp_end_html();
}
static void