=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -p -r1.28 -r1.29 --- mandoc/cgi.c 2011/12/10 23:09:25 1.28 +++ mandoc/cgi.c 2011/12/11 00:22:47 1.29 @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.28 2011/12/10 23:09:25 kristaps Exp $ */ +/* $Id: cgi.c,v 1.29 2011/12/11 00:22:47 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -103,9 +103,10 @@ static void resp_index(const struct req *); static void resp_search(struct res *, size_t, void *); static void resp_searchform(const struct req *); -static const char *progname; -static const char *cache; -static const char *host; +static const char *progname; /* cgi script name */ +static const char *cache; /* cache directory */ +static const char *css; /* css directory */ +static const char *host; /* hostname */ static const char * const pages[PAGE__MAX] = { "index", /* PAGE_INDEX */ @@ -338,19 +339,19 @@ resp_begin_html(int code, const char *msg) resp_begin_http(code, msg); - puts("\n" - "\n" - "\n" - "\n" - "\n" - "System Manpage Reference\n" - "\n" - "\n" - ""); + printf("\n" + "\n" + "\n" + "\n" + "\n" + "System Manpage Reference\n" + "\n" + "\n" + "\n", css); } static void @@ -367,16 +368,15 @@ resp_searchform(const struct req *req) int i; puts(""); - printf("
\n"); - printf("
\n" + printf("\n" + "
\n" "Search Parameters\n" " or \n" " for manuals satisfying \n" - "q.expr ? req->q.expr : ""); printf("\">, section " "q.manroot >= 0); + if (1 == sz) { /* * If we have just one result, then jump there now * without any delay. */ puts("Status: 303 See Other"); - printf("Location: http://%s%s/show/%u/%u.html\n", - host, progname, + printf("Location: http://%s%s/show/%d/%u/%u.html\n", + host, progname, req->q.manroot, r[0].volume, r[0].rec); puts("Content-Type: text/html; charset=utf-8\n"); return; @@ -488,8 +491,6 @@ resp_search(struct res *r, size_t sz, void *arg) qsort(r, sz, sizeof(struct res), cmp); resp_begin_html(200, NULL); - - req = (const struct req *)arg; resp_searchform(req); if (0 == sz) { @@ -497,9 +498,8 @@ resp_search(struct res *r, size_t sz, void *arg) "No %s results found.\n", req->q.whatis ? "whatis" : "apropos"); if (req->q.whatis) { - printf("(Try q.expr ? req->q.expr : ""); printf("&sec="); html_print(req->q.sec ? req->q.sec : ""); @@ -515,14 +515,11 @@ resp_search(struct res *r, size_t sz, void *arg) puts("

\n" ""); - assert(req->q.manroot >= 0); for (i = 0; i < (int)sz; i++) { printf("\n" "
\n" - "", - req->q.manroot, + "", + progname, req->q.manroot, r[i].volume, r[i].rec); html_print(r[i].title); putchar('('); @@ -566,20 +563,20 @@ catman(const char *file) } resp_begin_http(200, NULL); - puts("\n" - "\n" - "\n" - "\n" - "\n" - "System Manpage Reference\n" - "\n" - "\n" - "\n" - "
");
+	printf("\n"
+	       "\n"
+	       "\n"
+	       "\n"
+	       "\n"
+	       "System Manpage Reference\n"
+	       "\n"
+	       "\n"
+	       "\n"
+	       "
\n", css);
 
 	while (NULL != (p = fgetln(f, &len))) {
 		bold = italic = 0;
@@ -722,10 +719,10 @@ format(const char *file)
 		return;
 	}
 
-	snprintf(opts, sizeof(opts), "style=/man.css,"
+	snprintf(opts, sizeof(opts), "style=%s/man.css,"
 			"man=%s/search.html?sec=%%S&expr=%%N,"
 			/*"includes=/cgi-bin/man.cgi/usr/include/%%I"*/,
-			progname);
+			css, progname);
 
 	mparse_result(mp, &mdoc, &man);
 	vp = html_alloc(opts);
@@ -942,16 +939,16 @@ main(void)
 
 	/* Scan our run-time environment. */
 
-	progname = getenv("SCRIPT_NAME");
-	if (NULL == progname)
+	if (NULL == (cache = getenv("CACHE_DIR")))
+		cache = "/cache/man.cgi";
+
+	if (NULL == (progname = getenv("SCRIPT_NAME")))
 		progname = "";
 
-	cache = getenv("CACHE_DIR");
-	if (NULL == cache)
-		cache = "/cache/man.cgi";
+	if (NULL == (css = getenv("CSS_DIR")))
+		css = "/";
 
-	host = getenv("HTTP_HOST");
-	if (NULL == host)
+	if (NULL == (host = getenv("HTTP_HOST")))
 		host = "localhost";
 
 	/*