=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.52 retrieving revision 1.58 diff -u -p -r1.52 -r1.58 --- mandoc/cgi.c 2014/07/09 07:30:47 1.52 +++ mandoc/cgi.c 2014/07/09 14:18:59 1.58 @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.52 2014/07/09 07:30:47 schwarze Exp $ */ +/* $Id: cgi.c,v 1.58 2014/07/09 14:18:59 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -20,7 +20,7 @@ #endif #include -#include +#include #include #include #include @@ -28,13 +28,6 @@ #include #include -#if defined(__sun) -/* for stat() */ -#include -#include -#include -#endif - #include "mandoc.h" #include "mandoc_aux.h" #include "main.h" @@ -52,7 +45,7 @@ enum page { * A query as passed to the search function. */ struct query { - const char *manroot; /* manual root directory */ + const char *manpath; /* desired manual directory */ const char *arch; /* architecture */ const char *sec; /* manual section */ const char *expr; /* unparsed expression string */ @@ -60,10 +53,10 @@ struct query { }; struct req { - struct query q; - char **p; /* array of available manroots */ - size_t psz; - enum page page; + struct query q; + char **p; /* array of available manpaths */ + size_t psz; /* number of available manpaths */ + enum page page; }; static void catman(const struct req *, const char *); @@ -77,7 +70,7 @@ static void http_parse(struct req *, char *); static void http_print(const char *); static void http_putchar(char); static void http_printquery(const struct req *); -static void pathgen(DIR *, struct req *); +static void pathgen(struct req *); static void pg_index(const struct req *, char *); static void pg_search(const struct req *, char *); static void pg_show(const struct req *, char *); @@ -93,10 +86,10 @@ static void resp_search(const struct req *, struct manpage *, size_t); static void resp_searchform(const struct req *); -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 *scriptname; /* CGI script name */ +static const char *mandir; /* contains all manpath directories */ +static const char *cssdir; /* css directory */ +static const char *httphost; /* hostname used in the URIs */ static const char * const pages[PAGE__MAX] = { "index", /* PAGE_INDEX */ @@ -130,29 +123,49 @@ html_putchar(char c) break; } } + static void http_printquery(const struct req *req) { - printf("&expr="); - http_print(req->q.expr ? req->q.expr : ""); - printf("&sec="); - http_print(req->q.sec ? req->q.sec : ""); - printf("&arch="); - http_print(req->q.arch ? req->q.arch : ""); + if (NULL != req->q.manpath) { + printf("&manpath="); + http_print(req->q.manpath); + } + if (NULL != req->q.sec) { + printf("&sec="); + http_print(req->q.sec); + } + if (NULL != req->q.arch) { + printf("&arch="); + http_print(req->q.arch); + } + if (NULL != req->q.expr) { + printf("&expr="); + http_print(req->q.expr ? req->q.expr : ""); + } } - static void html_printquery(const struct req *req) { - printf("&expr="); - html_print(req->q.expr ? req->q.expr : ""); - printf("&sec="); - html_print(req->q.sec ? req->q.sec : ""); - printf("&arch="); - html_print(req->q.arch ? req->q.arch : ""); + if (NULL != req->q.manpath) { + printf("&manpath="); + html_print(req->q.manpath); + } + if (NULL != req->q.sec) { + printf("&sec="); + html_print(req->q.sec); + } + if (NULL != req->q.arch) { + printf("&arch="); + html_print(req->q.arch); + } + if (NULL != req->q.expr) { + printf("&expr="); + html_print(req->q.expr ? req->q.expr : ""); + } } static void @@ -191,7 +204,7 @@ http_parse(struct req *req, char *p) int legacy; memset(&req->q, 0, sizeof(struct query)); - req->q.manroot = req->p[0]; + req->q.manpath = req->p[0]; legacy = -1; while ('\0' != *p) { @@ -225,7 +238,7 @@ http_parse(struct req *req, char *p) else if (0 == strcmp(key, "arch")) req->q.arch = val; else if (0 == strcmp(key, "manpath")) - req->q.manroot = val; + req->q.manpath = val; else if (0 == strcmp(key, "apropos")) legacy = 0 == strcmp(val, "0"); } @@ -330,7 +343,8 @@ resp_begin_html(int code, const char *msg) "System Manpage Reference\n" "\n" "\n" - "\n", css, css); + "\n", + cssdir, cssdir); } static void @@ -354,7 +368,7 @@ resp_searchform(const struct req *req) " for manuals satisfying \n" "q.expr ? req->q.expr : ""); printf("\">, section " ""); for (i = 0; i < (int)req->psz; i++) { printf("