=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.13 retrieving revision 1.16 diff -u -p -r1.13 -r1.16 --- mandoc/cgi.c 2011/12/07 15:12:34 1.13 +++ mandoc/cgi.c 2011/12/07 16:18:52 1.16 @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.13 2011/12/07 15:12:34 kristaps Exp $ */ +/* $Id: cgi.c,v 1.16 2011/12/07 16:18:52 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -67,6 +67,7 @@ struct req { static int atou(const char *, unsigned *); static void catman(const char *); +static int cmp(const void *, const void *); static void format(const char *); static void html_print(const char *); static void html_putchar(char); @@ -295,8 +296,8 @@ resp_begin_html(int code, const char *msg) " \"http://www.w3.org/TR/html4/strict.dtd\">" "\n" "" "\n" " " "\n" - " " "\n" + " " "\n" " " "\n" " System Manpage Reference" "\n" @@ -339,21 +340,21 @@ resp_searchform(const struct req *req) printf("
\n"); - puts("
\n" - " or \n" - " for manuals satisfying \n" - "\n" + "Search Parameters\n" + " or \n" + " for manuals satisfying \n" + ", section " - ", section " + ", arch " - ", arch " + ".\n" "\n" @@ -438,14 +439,22 @@ resp_search(struct res *r, size_t sz, void *arg) return; } + qsort(r, sz, sizeof(struct res), cmp); + resp_begin_html(200, NULL); resp_searchform((const struct req *)arg); - if (0 == sz) + if (0 == sz) { puts("

No results found.

"); + resp_end_html(); + return; + } + puts("

\n" + ""); + for (i = 0; i < (int)sz; i++) { - printf("

"); } + puts("
", r[i].volume, r[i].rec); html_print(r[i].title); @@ -455,11 +464,13 @@ resp_search(struct res *r, size_t sz, void *arg) putchar('/'); html_print(r[i].arch); } - printf(") "); + printf(")"); html_print(r[i].desc); - puts("

"); + puts("
"); + resp_end_html(); } @@ -745,7 +756,7 @@ pg_search(const struct manpaths *ps, const struct req cp = NULL; ep = NULL; sz = 0; - whatis = 0; + whatis = 1; memset(&opt, 0, sizeof(struct opts)); @@ -910,3 +921,12 @@ main(void) return(EXIT_SUCCESS); } + +static int +cmp(const void *p1, const void *p2) +{ + + return(strcasecmp(((const struct res *)p1)->title, + ((const struct res *)p2)->title)); +} +