summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-12-07 13:00:40 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-12-07 13:00:40 +0000
commit599529fe8cec0ee754a5030abaa9a8d842f90977 (patch)
treea735bac1e2e1d951ed5e9ace2c80b6a42a7ea33a
parentd17728ddc426a13a4ffda7bbfd0d0ac6b3881502 (diff)
downloadmandoc-599529fe8cec0ee754a5030abaa9a8d842f90977.tar.gz
Have a whatis/apropos mode, with the default (hitting enter within the
expression text) be whatis. This is a much nicer default than apropos, which can be scary. While here, fix the cat.css location (erroneously put in the response page instead of the catman page) and add bits for a default style-sheet.
-rw-r--r--Makefile1
-rw-r--r--cgi.c96
-rw-r--r--man.cgi.721
3 files changed, 72 insertions, 46 deletions
diff --git a/Makefile b/Makefile
index 7b3de446..07545dfd 100644
--- a/Makefile
+++ b/Makefile
@@ -453,6 +453,7 @@ installcgi: all
mkdir -p $(DESTDIR)$(HTDOCDIR)
$(INSTALL_PROGRAM) man.cgi $(DESTDIR)$(CGIBINDIR)
$(INSTALL_DATA) example.style.css $(DESTDIR)$(HTDOCDIR)/man.css
+ $(INSTALL_DATA) man.cgi.css $(DESTDIR)$(HTDOCDIR)
installwww: www
mkdir -p $(PREFIX)/snapshots
diff --git a/cgi.c b/cgi.c
index 97546ae7..d3f523b5 100644
--- a/cgi.c
+++ b/cgi.c
@@ -297,6 +297,8 @@ resp_begin_html(int code, const char *msg)
" <HEAD>" "\n"
" <META HTTP-EQUIV=\"Content-Type\" " "\n"
" CONTENT=\"text/html; charset=utf-8\">" "\n"
+ " <LINK REL=\"stylesheet\" HREF=\"/man.cgi.css\"" "\n"
+ " TYPE=\"text/css\" media=\"all\">" "\n"
" <TITLE>System Manpage Reference</TITLE>" "\n"
" </HEAD>" "\n"
" <BODY>" "\n"
@@ -330,21 +332,27 @@ resp_searchform(const struct req *req)
printf("<FORM ACTION=\"");
html_print(progname);
printf("/search.html\" METHOD=\"get\">\n");
- puts(" <FIELDSET>\n"
- " <INPUT TYPE=\"submit\" VALUE=\"Search:\">");
- printf(" Terms: <INPUT TYPE=\"text\" "
- "SIZE=\"60\" NAME=\"expr\" VALUE=\"");
+ puts("<FIELDSET>\n"
+ "<INPUT TYPE=\"submit\" NAME=\"op\" "
+ "VALUE=\"Whatis\"> or \n"
+ "<INPUT TYPE=\"submit\" NAME=\"op\" "
+ "VALUE=\"apropos\"> for manuals satisfying \n"
+ "<INPUT TYPE=\"text\" SIZE=\"40\" "
+ "NAME=\"expr\" VALUE=\"");
html_print(expr);
- puts("\">");
- printf(" Section: <INPUT TYPE=\"text\" "
- "SIZE=\"4\" NAME=\"sec\" VALUE=\"");
+ puts("\">, section "
+ "<INPUT TYPE=\"text\" "
+ "SIZE=\"4\" NAME=\"sec\" VALUE=\"");
html_print(sec);
- puts("\">");
- printf(" Arch: <INPUT TYPE=\"text\" "
- "SIZE=\"8\" NAME=\"arch\" VALUE=\"");
+ puts("\">, arch "
+ "<INPUT TYPE=\"text\" "
+ "SIZE=\"8\" NAME=\"arch\" VALUE=\"");
html_print(arch);
- puts("\">");
- puts(" </FIELDSET>\n</FORM>\n<!-- End search form. //-->");
+ puts("\">.\n"
+ "<INPUT TYPE=\"reset\" VALUE=\"Reset\">\n"
+ "</FIELDSET>\n"
+ "</FORM>\n"
+ "<!-- End search form. //-->");
}
static void
@@ -361,12 +369,12 @@ resp_error400(void)
{
resp_begin_html(400, "Query Malformed");
- puts("<H1>Malformed Query</H1>\n"
- "<P>\n"
- " The query your entered was malformed.\n"
- " Try again from the\n"
- " <A HREF=\"/index.html\">main page</A>\n"
- "</P>");
+ printf("<H1>Malformed Query</H1>\n"
+ "<P>\n"
+ " The query your entered was malformed.\n"
+ " Try again from the\n"
+ " <A HREF=\"%s/index.html\">main page</A>\n"
+ "</P>", progname);
resp_end_html();
}
@@ -380,11 +388,11 @@ resp_error404(const char *page)
" The page you're looking for, ");
printf(" <B>");
html_print(page);
- puts("</B>,\n"
- " could not be found.\n"
- " Try searching from the\n"
- " <A HREF=\"/index.html\">main page</A>\n"
- "</P>");
+ printf("</B>,\n"
+ " could not be found.\n"
+ " Try searching from the\n"
+ " <A HREF=\"%s/index.html\">main page</A>\n"
+ "</P>", progname);
resp_end_html();
}
@@ -423,21 +431,7 @@ resp_search(struct res *r, size_t sz, void *arg)
return;
}
- resp_begin_http(200, NULL);
- puts("<!DOCTYPE HTML PUBLIC " "\n"
- " \"-//W3C//DTD HTML 4.01//EN\"" "\n"
- " \"http://www.w3.org/TR/html4/strict.dtd\">" "\n"
- "<HTML>" "\n"
- " <HEAD>" "\n"
- " <META HTTP-EQUIV=\"Content-Type\" " "\n"
- " CONTENT=\"text/html; charset=utf-8\">" "\n"
- " <LINK REL=\"stylesheet\" HREF=\"/catman.css\"" "\n"
- " TYPE=\"text/css\" media=\"all\">" "\n"
- " <TITLE>System Manpage Reference</TITLE>" "\n"
- " </HEAD>" "\n"
- " <BODY>" "\n"
- "<!-- Begin page content. //-->");
-
+ resp_begin_html(200, NULL);
resp_searchform((const struct req *)arg);
if (0 == sz)
@@ -484,7 +478,20 @@ catman(const char *file)
return;
}
- resp_begin_html(200, NULL);
+ resp_begin_http(200, NULL);
+ puts("<!DOCTYPE HTML PUBLIC " "\n"
+ " \"-//W3C//DTD HTML 4.01//EN\"" "\n"
+ " \"http://www.w3.org/TR/html4/strict.dtd\">" "\n"
+ "<HTML>" "\n"
+ " <HEAD>" "\n"
+ " <META HTTP-EQUIV=\"Content-Type\" " "\n"
+ " CONTENT=\"text/html; charset=utf-8\">" "\n"
+ " <LINK REL=\"stylesheet\" HREF=\"/catman.css\"" "\n"
+ " TYPE=\"text/css\" media=\"all\">" "\n"
+ " <TITLE>System Manpage Reference</TITLE>" "\n"
+ " </HEAD>" "\n"
+ " <BODY>" "\n"
+ "<!-- Begin page content. //-->");
puts("<PRE>");
while (NULL != (p = fgetln(f, &len))) {
@@ -721,7 +728,7 @@ static void
pg_search(const struct manpaths *ps, const struct req *req, char *path)
{
size_t tt;
- int i, sz, rc;
+ int i, sz, rc, whatis;
const char *ep, *start;
char **cp;
struct opts opt;
@@ -731,6 +738,7 @@ pg_search(const struct manpaths *ps, const struct req *req, char *path)
cp = NULL;
ep = NULL;
sz = 0;
+ whatis = 0;
memset(&opt, 0, sizeof(struct opts));
@@ -741,6 +749,9 @@ pg_search(const struct manpaths *ps, const struct req *req, char *path)
opt.cat = req->fields[i].val;
else if (0 == strcmp(req->fields[i].key, "arch"))
opt.arch = req->fields[i].val;
+ else if (0 == strcmp(req->fields[i].key, "op"))
+ whatis = 0 == strcasecmp
+ (req->fields[i].val, "whatis");
/*
* Poor man's tokenisation.
@@ -770,7 +781,10 @@ pg_search(const struct manpaths *ps, const struct req *req, char *path)
* The resp_search() function is called with the results.
*/
- if (NULL != (expr = exprcomp(sz, cp, &tt)))
+ expr = whatis ? termcomp(sz, cp, &tt) :
+ exprcomp(sz, cp, &tt);
+
+ if (NULL != expr)
rc = apropos_search
(ps->sz, ps->paths, &opt,
expr, tt, (void *)req, resp_search);
diff --git a/man.cgi.7 b/man.cgi.7
index 630c7422..4bca3317 100644
--- a/man.cgi.7
+++ b/man.cgi.7
@@ -39,11 +39,22 @@ The absolute path of the
cache directory.
.El
.Sh FILES
-The configuration file
-.Pa etc/catman.conf
-must exist within the cache directory.
-This is built by
-.Xr catman 8 .
+.Bl -tag -width Ds
+.It Pa etc/catman.conf
+Built by
+.Xr catman 8
+and must exist under the configuration directory root.
+.It Pa man.css
+Must be visible in the server document root, used for styling source
+manual page output.
+.It Pa catman.css
+Must be visible in the server document root, used for styling
+pre-formatted manual page output.
+.It Pa man.cgi.css
+Must be visible in the server document root, used for general styling of
+.Nm
+search and error pages.
+.El
.Sh SEE ALSO
.Xr mandoc 3 ,
.Xr catman 8 ,