+ struct manconf conf;
+ struct mansearch search;
+ struct curparse curp;
+ struct winsize ws;
+ struct tag_files *tag_files;
+ struct manpage *res, *resp;
+ const char *progname, *sec, *thisarg;
+ char *conf_file, *defpaths, *auxpaths;
+ char *oarg;
+ unsigned char *uc;
+ size_t i, sz;
+ int prio, best_prio;
+ enum outmode outmode;
+ int fd, startdir;
+ int show_usage;
+ int options;
+ int use_pager;
+ int status, signum;
+ int c;
+ pid_t pager_pid, tc_pgid, man_pgid, pid;
+
+#if HAVE_PROGNAME
+ progname = getprogname();
+#else
+ if (argc < 1)
+ progname = mandoc_strdup("mandoc");
+ else if ((progname = strrchr(argv[0], '/')) == NULL)
+ progname = argv[0];
+ else
+ ++progname;
+ setprogname(progname);
+#endif
+
+ if (strncmp(progname, "mandocdb", 8) == 0 ||
+ strcmp(progname, BINM_MAKEWHATIS) == 0)
+ return mandocdb(argc, argv);
+
+#if HAVE_PLEDGE
+ if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1)
+ err((int)MANDOCLEVEL_SYSERR, "pledge");
+#endif
+
+#if HAVE_SANDBOX_INIT
+ if (sandbox_init(kSBXProfileNoInternet, SANDBOX_NAMED, NULL) == -1)
+ errx((int)MANDOCLEVEL_SYSERR, "sandbox_init");
+#endif
+
+ /* Search options. */
+
+ memset(&conf, 0, sizeof(conf));
+ conf_file = defpaths = NULL;
+ auxpaths = NULL;
+
+ memset(&search, 0, sizeof(struct mansearch));
+ search.outkey = "Nd";
+ oarg = NULL;
+
+ if (strcmp(progname, BINM_MAN) == 0)
+ search.argmode = ARG_NAME;
+ else if (strcmp(progname, BINM_APROPOS) == 0)
+ search.argmode = ARG_EXPR;
+ else if (strcmp(progname, BINM_WHATIS) == 0)
+ search.argmode = ARG_WORD;
+ else if (strncmp(progname, "help", 4) == 0)
+ search.argmode = ARG_NAME;
+ else
+ search.argmode = ARG_FILE;
+
+ /* Parser and formatter options. */
+
+ memset(&curp, 0, sizeof(struct curparse));
+ curp.outtype = OUTT_LOCALE;
+ curp.mmin = MANDOCERR_MAX;
+ curp.outopts = &conf.output;
+ options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1;
+ mmsg_stream = stderr;
+
+ use_pager = 1;
+ tag_files = NULL;
+ show_usage = 0;
+ outmode = OUTMODE_DEF;
+
+ while ((c = getopt(argc, argv,
+ "aC:cfhI:iK:klM:m:O:S:s:T:VW:w")) != -1) {
+ if (c == 'i' && search.argmode == ARG_EXPR) {
+ optind--;
+ break;
+ }