=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -p -r1.31 -r1.32 --- mandoc/cgi.c 2011/12/14 13:36:59 1.31 +++ mandoc/cgi.c 2011/12/15 12:05:19 1.32 @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.31 2011/12/14 13:36:59 kristaps Exp $ */ +/* $Id: cgi.c,v 1.32 2011/12/15 12:05:19 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -80,9 +80,9 @@ struct req { }; static int atou(const char *, unsigned *); -static void catman(const char *); +static void catman(const struct req *, const char *); static int cmp(const void *, const void *); -static void format(const char *); +static void format(const struct req *, const char *); static void html_print(const char *); static void html_putchar(char); static int http_decode(char *); @@ -346,12 +346,14 @@ resp_begin_html(int code, const char *msg) "\n" "\n" - "\n" + "\n" "System Manpage Reference\n" "\n" "\n" - "\n", css); + "\n", css, css); } static void @@ -368,7 +370,8 @@ resp_searchform(const struct req *req) int i; puts(""); - printf("
\n" + printf("
\n" + "\n" "
\n" "Search Parameters\n" "\n" "
\n" - ""); + "\n" + "
"); puts(""); } @@ -549,7 +553,7 @@ pg_index(const struct req *req, char *path) } static void -catman(const char *file) +catman(const struct req *req, const char *file) { FILE *f; size_t len; @@ -562,21 +566,10 @@ catman(const char *file) return; } - resp_begin_http(200, NULL); - printf("\n" - "\n" - "\n" - "\n" - "\n" - "System Manpage Reference\n" - "\n" - "\n" - "\n" - "
\n", css);
+	resp_begin_html(200, NULL);
+	resp_searchform(req);
+	puts("
\n" + "
");
 
 	while (NULL != (p = fgetln(f, &len))) {
 		bold = italic = 0;
@@ -688,6 +681,7 @@ catman(const char *file)
 	}
 
 	puts("
\n" + "
\n" "\n" ""); @@ -695,7 +689,7 @@ catman(const char *file) } static void -format(const char *file) +format(const struct req *req, const char *file) { struct mparse *mp; int fd; @@ -719,23 +713,31 @@ format(const char *file) return; } - snprintf(opts, sizeof(opts), "style=%s/man.css," + snprintf(opts, sizeof(opts), "fragment," "man=%s/search.html?sec=%%S&expr=%%N," /*"includes=/cgi-bin/man.cgi/usr/include/%%I"*/, - css, progname); + progname); mparse_result(mp, &mdoc, &man); + if (NULL == man && NULL == mdoc) { + resp_baddb(); + mparse_free(mp); + return; + } + + resp_begin_html(200, NULL); + resp_searchform(req); + vp = html_alloc(opts); - if (NULL != mdoc) { - resp_begin_http(200, NULL); + if (NULL != mdoc) html_mdoc(vp, mdoc); - } else if (NULL != man) { - resp_begin_http(200, NULL); + else html_man(vp, man); - } else - resp_baddb(); + puts("\n" + ""); + html_free(vp); mparse_free(mp); } @@ -829,9 +831,9 @@ pg_show(const struct req *req, char *path) resp_baddb(); else { if (0 == strcmp(cp, "cat")) - catman(fn + 1); + catman(req, fn + 1); else - format(fn + 1); + format(req, fn + 1); } out: if (idx)