=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.273.2.9 retrieving revision 1.281 diff -u -p -r1.273.2.9 -r1.281 --- mandoc/main.c 2017/02/21 17:04:04 1.273.2.9 +++ mandoc/main.c 2017/02/10 15:45:28 1.281 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.273.2.9 2017/02/21 17:04:04 schwarze Exp $ */ +/* $Id: main.c,v 1.281 2017/02/10 15:45:28 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze @@ -81,7 +81,9 @@ struct curparse { struct manoutput *outopts; /* output options */ }; + int mandocdb(int, char *[]); + static int fs_lookup(const struct manpaths *, size_t ipath, const char *, const char *, const char *, @@ -98,7 +100,7 @@ static void parse(struct curparse *, int, const cha static void passthrough(const char *, int, int); static pid_t spawn_pager(struct tag_files *); static int toptions(struct curparse *, char *); -static void usage(enum argmode) __attribute__((__noreturn__)); +static void usage(enum argmode) __attribute__((noreturn)); static int woptions(struct curparse *, char *); static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9}; @@ -111,14 +113,17 @@ int main(int argc, char *argv[]) { struct manconf conf; - struct mansearch search; struct curparse curp; + struct mansearch search; struct tag_files *tag_files; - struct manpage *res, *resp; - const char *progname, *sec, *thisarg; - char *conf_file, *defpaths, *auxpaths; - char *defos, *oarg; + const char *progname; + char *auxpaths; + char *defos; unsigned char *uc; + struct manpage *res, *resp; + char *conf_file, *defpaths; + const char *sec; + const char *thisarg; size_t i, sz; int prio, best_prio; enum outmode outmode; @@ -164,7 +169,6 @@ main(int argc, char *argv[]) memset(&search, 0, sizeof(struct mansearch)); search.outkey = "Nd"; - oarg = NULL; if (strcmp(progname, BINM_MAN) == 0) search.argmode = ARG_NAME; @@ -243,7 +247,15 @@ main(int argc, char *argv[]) auxpaths = optarg; break; case 'O': - oarg = optarg; + search.outkey = optarg; + while (optarg != NULL) { + thisarg = optarg; + if (manconf_output(&conf.output, + strsep(&optarg, ","), 0) == 0) + continue; + warnx("-O %s: Bad argument", thisarg); + return (int)MANDOCLEVEL_BADARG; + } break; case 'S': search.arch = optarg; @@ -288,21 +300,6 @@ main(int argc, char *argv[]) } } - if (oarg != NULL) { - if (outmode == OUTMODE_LST) - search.outkey = oarg; - else { - while (oarg != NULL) { - thisarg = oarg; - if (manconf_output(&conf.output, - strsep(&oarg, ","), 0) == 0) - continue; - warnx("-O %s: Bad argument", thisarg); - return (int)MANDOCLEVEL_BADARG; - } - } - } - if (outmode == OUTMODE_FLN || outmode == OUTMODE_LST || !isatty(STDOUT_FILENO)) @@ -355,9 +352,6 @@ main(int argc, char *argv[]) /* 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; @@ -365,10 +359,10 @@ main(int argc, char *argv[]) /* Access the mandoc database. */ manconf_parse(&conf, conf_file, defpaths, auxpaths); - mansearch_setup(1); if ( ! mansearch(&search, &conf.manpath, argc, argv, &res, &sz)) usage(search.argmode); + if (sz == 0) { if (search.argmode == ARG_NAME) fs_search(&search, &conf.manpath, @@ -470,7 +464,7 @@ main(int argc, char *argv[]) if (resp == NULL) parse(&curp, fd, *argv); - else if (resp->form & FORM_SRC) { + else if (resp->form == FORM_SRC) { /* For .so only; ignore failure. */ chdir(conf.manpath.paths[resp->ipath]); parse(&curp, fd, resp->file); @@ -522,7 +516,6 @@ out: if (search.argmode != ARG_FILE) { manconf_free(&conf); mansearch_free(res, sz); - mansearch_setup(0); } free(defos); @@ -626,7 +619,8 @@ fs_lookup(const struct manpaths *paths, size_t ipath, glob_t globinfo; struct manpage *page; char *file; - int form, globres; + int globres; + enum form form; form = FORM_SRC; mandoc_asprintf(&file, "%s/man%s/%s.%s",