From 599529fe8cec0ee754a5030abaa9a8d842f90977 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Wed, 7 Dec 2011 13:00:40 +0000 Subject: 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. --- cgi.c | 96 ++++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 55 insertions(+), 41 deletions(-) (limited to 'cgi.c') 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) " " "\n" " " "\n" + " " "\n" " System Manpage Reference" "\n" " " "\n" " " "\n" @@ -330,21 +332,27 @@ resp_searchform(const struct req *req) printf("
\n"); - puts("
\n" - " "); - printf(" Terms: \n" + " or \n" + " for manuals satisfying \n" + ""); - printf(" Section: , section " + ""); - printf(" Arch: , arch " + ""); - puts("
\n
\n"); + puts("\">.\n" + "\n" + "\n" + "\n" + ""); } static void @@ -361,12 +369,12 @@ resp_error400(void) { resp_begin_html(400, "Query Malformed"); - puts("

Malformed Query

\n" - "

\n" - " The query your entered was malformed.\n" - " Try again from the\n" - " main page\n" - "

"); + printf("

Malformed Query

\n" + "

\n" + " The query your entered was malformed.\n" + " Try again from the\n" + " main page\n" + "

", progname); resp_end_html(); } @@ -380,11 +388,11 @@ resp_error404(const char *page) " The page you're looking for, "); printf(" "); html_print(page); - puts(",\n" - " could not be found.\n" - " Try searching from the\n" - " main page\n" - "

"); + printf(",\n" + " could not be found.\n" + " Try searching from the\n" + " main page\n" + "

", 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("" "\n" - "" "\n" - " " "\n" - " " "\n" - " " "\n" - " System Manpage Reference" "\n" - " " "\n" - " " "\n" - ""); - + 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("" "\n" + "" "\n" + " " "\n" + " " "\n" + " " "\n" + " System Manpage Reference" "\n" + " " "\n" + " " "\n" + ""); puts("
");
 	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);
-- 
cgit