=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.40 retrieving revision 1.45 diff -u -p -r1.40 -r1.45 --- mandoc/cgi.c 2012/03/23 09:03:07 1.40 +++ mandoc/cgi.c 2013/06/05 02:00:26 1.45 @@ -1,6 +1,6 @@ -/* $Id: cgi.c,v 1.40 2012/03/23 09:03:07 kristaps Exp $ */ +/* $Id: cgi.c,v 1.45 2013/06/05 02:00:26 schwarze Exp $ */ /* - * Copyright (c) 2011 Kristaps Dzonsons + * Copyright (c) 2011, 2012 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,7 +18,6 @@ #include "config.h" #endif -#include #include #include @@ -495,15 +494,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 +517,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("