=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.40 retrieving revision 1.41 diff -u -p -r1.40 -r1.41 --- mandoc/cgi.c 2012/03/23 09:03:07 1.40 +++ mandoc/cgi.c 2012/03/24 00:31:55 1.41 @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.40 2012/03/23 09:03:07 kristaps Exp $ */ +/* $Id: cgi.c,v 1.41 2012/03/24 00:31:55 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -495,15 +495,22 @@ resp_baddb(void) static void resp_search(struct res *r, size_t sz, void *arg) { - int i; + size_t i, matched; const struct req *req; req = (const struct req *)arg; if (sz > 0) assert(req->q.manroot >= 0); + + for (matched = i = 0; i < sz; i++) + if (r[i].matched) + matched++; - if (1 == sz) { + if (1 == matched) { + for (i = 0; i < sz; i++) + if (r[i].matched) + break; /* * If we have just one result, then jump there now * without any delay. @@ -511,21 +518,19 @@ resp_search(struct res *r, size_t sz, void *arg) puts("Status: 303 See Other"); printf("Location: http://%s%s/show/%d/%u/%u.html?", host, progname, req->q.manroot, - r[0].volume, r[0].rec); + r[i].volume, r[i].rec); http_printquery(req); puts("\n" "Content-Type: text/html; charset=utf-8\n"); return; } - qsort(r, sz, sizeof(struct res), cmp); - resp_begin_html(200, NULL); resp_searchform(req); puts("
"); - if (0 == sz) { + if (0 == matched) { puts("

\n" "No results found.\n" "

\n" @@ -534,9 +539,13 @@ resp_search(struct res *r, size_t sz, void *arg) return; } + qsort(r, sz, sizeof(struct res), cmp); + puts(""); - for (i = 0; i < (int)sz; i++) { + for (i = 0; i < sz; i++) { + if ( ! r[i].matched) + continue; printf("\n" "
\n" "