- size_t tt;
- int i, sz, rc, whatis;
- const char *ep, *start;
- char **cp;
- struct opts opt;
- struct expr *expr;
-
- expr = NULL;
- cp = NULL;
- ep = NULL;
- sz = 0;
- whatis = 1;
-
- memset(&opt, 0, sizeof(struct opts));
-
- for (sz = i = 0; i < (int)req->fieldsz; i++)
- if (0 == strcmp(req->fields[i].key, "expr"))
- ep = req->fields[i].val;
- else if (0 == strcmp(req->fields[i].key, "query"))
- ep = req->fields[i].val;
- else if (0 == strcmp(req->fields[i].key, "sec"))
- opt.cat = req->fields[i].val;
- else if (0 == strcmp(req->fields[i].key, "sektion"))
- opt.cat = req->fields[i].val;
- else if (0 == strcmp(req->fields[i].key, "arch"))
- opt.arch = req->fields[i].val;
- else if (0 == strcmp(req->fields[i].key, "apropos"))
- whatis = 0 == strcmp
- (req->fields[i].val, "0");
- else if (0 == strcmp(req->fields[i].key, "op"))
- whatis = 0 == strcasecmp
- (req->fields[i].val, "whatis");
-
- if (NULL != opt.cat && 0 == strcmp(opt.cat, "0"))
- opt.cat = NULL;
+ struct mansearch search;
+ struct manpaths paths;
+ struct manpage *res;
+ char **cp;
+ const char *ep, *start;
+ size_t ressz;
+ int i, sz;
+
+ /*
+ * Begin by chdir()ing into the root of the manpath.
+ * This way we can pick up the database files, which are
+ * relative to the manpath root.
+ */
+
+ if (-1 == (chdir(req->q.manpath))) {
+ resp_error_badrequest(
+ "You specified an invalid manpath.");
+ return;
+ }
+
+ search.arch = req->q.arch;
+ search.sec = req->q.sec;
+ search.deftype = TYPE_Nm | TYPE_Nd;
+ search.flags = 0;
+
+ paths.sz = 1;
+ paths.paths = mandoc_malloc(sizeof(char *));
+ paths.paths[0] = mandoc_strdup(".");