+ /* man(1), whatis(1), apropos(1) */
+
+ if (search.argmode != ARG_FILE) {
+ if (argc == 0)
+ usage(search.argmode);
+
+ if (search.argmode == ARG_NAME &&
+ outmode == OUTMODE_ONE)
+ search.firstmatch = 1;
+
+ /* Access the mandoc database. */
+
+ manconf_parse(&conf, conf_file, defpaths, auxpaths);
+#if HAVE_SQLITE3
+ mansearch_setup(1);
+ if ( ! mansearch(&search, &conf.manpath,
+ argc, argv, &res, &sz))
+ usage(search.argmode);
+#else
+ if (search.argmode != ARG_NAME) {
+ fputs("mandoc: database support not compiled in\n",
+ stderr);
+ return((int)MANDOCLEVEL_BADARG);
+ }
+ sz = 0;
+#endif
+
+ if (sz == 0) {
+ if (search.argmode == ARG_NAME)
+ fs_search(&search, &conf.manpath,
+ argc, argv, &res, &sz);
+ else
+ fprintf(stderr,
+ "%s: nothing appropriate\n",
+ progname);
+ }
+
+ if (sz == 0) {
+ rc = MANDOCLEVEL_BADARG;
+ goto out;
+ }
+
+ /*
+ * For standard man(1) and -a output mode,
+ * prepare for copying filename pointers
+ * into the program parameter array.
+ */
+
+ if (outmode == OUTMODE_ONE) {
+ argc = 1;
+ best_prio = 10;
+ } else if (outmode == OUTMODE_ALL)
+ argc = (int)sz;
+
+ /* Iterate all matching manuals. */
+
+ resp = res;
+ for (i = 0; i < sz; i++) {
+ if (outmode == OUTMODE_FLN)
+ puts(res[i].file);
+ else if (outmode == OUTMODE_LST)
+ printf("%s - %s\n", res[i].names,
+ res[i].output == NULL ? "" :
+ res[i].output);
+ else if (outmode == OUTMODE_ONE) {
+ /* Search for the best section. */
+ isec = strcspn(res[i].file, "123456789");
+ sec = res[i].file[isec];
+ if ('\0' == sec)
+ continue;
+ prio = sec_prios[sec - '1'];
+ if (prio >= best_prio)
+ continue;
+ best_prio = prio;
+ resp = res + i;
+ }
+ }
+
+ /*
+ * For man(1), -a and -i output mode, fall through
+ * to the main mandoc(1) code iterating files
+ * and running the parsers on each of them.
+ */
+
+ if (outmode == OUTMODE_FLN || outmode == OUTMODE_LST)
+ goto out;
+ }
+
+ /* mandoc(1) */
+
+ if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths))
+ return((int)MANDOCLEVEL_BADARG);
+
+ if (use_pager && ! isatty(STDOUT_FILENO))
+ use_pager = 0;
+
+ curp.mchars = mchars_alloc();
+ curp.mp = mparse_alloc(options, curp.wlevel, mmsg,
+ curp.mchars, defos);
+
+ /*
+ * Conditionally start up the lookaside buffer before parsing.
+ */
+ if (OUTT_MAN == curp.outtype)
+ mparse_keep(curp.mp);
+
+ if (argc < 1) {
+ if (use_pager)
+ tag_files = tag_init();
+ parse(&curp, STDIN_FILENO, "<stdin>");
+ }
+
+ while (argc > 0) {
+ rctmp = mparse_open(curp.mp, &fd,
+ resp != NULL ? resp->file : *argv);
+ if (rc < rctmp)
+ rc = rctmp;
+
+ if (fd != -1) {
+ if (use_pager) {
+ tag_files = tag_init();
+ use_pager = 0;
+ }
+
+ if (resp == NULL)
+ parse(&curp, fd, *argv);
+ else if (resp->form & FORM_SRC) {
+ /* For .so only; ignore failure. */
+ chdir(conf.manpath.paths[resp->ipath]);
+ parse(&curp, fd, resp->file);
+ } else
+ passthrough(resp->file, fd,
+ conf.output.synopsisonly);
+
+ if (argc > 1 && curp.outtype <= OUTT_UTF8)
+ ascii_sepline(curp.outdata);
+ }