=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.214 retrieving revision 1.218 diff -u -p -r1.214 -r1.218 --- mandoc/main.c 2015/01/14 21:27:17 1.214 +++ mandoc/main.c 2015/02/03 21:16:02 1.218 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.214 2015/01/14 21:27:17 schwarze Exp $ */ +/* $Id: main.c,v 1.218 2015/02/03 21:16:02 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze @@ -19,6 +19,7 @@ #include "config.h" #include +#include /* MACHINE */ #include #include @@ -82,7 +83,6 @@ struct curparse { char outopts[BUFSIZ]; /* buf of output opts */ }; -#if HAVE_SQLITE3 static int fs_lookup(const struct manpaths *, size_t ipath, const char *, const char *, const char *, @@ -90,7 +90,6 @@ static int fs_lookup(const struct manpaths *, static void fs_search(const struct mansearch *, const struct manpaths *, int, char**, struct manpage **, size_t *); -#endif static int koptions(int *, char *); #if HAVE_SQLITE3 int mandocdb(int, char**); @@ -100,9 +99,7 @@ static void mmsg(enum mandocerr, enum mandoclevel, const char *, int, int, const char *); static void parse(struct curparse *, int, const char *, enum mandoclevel *); -#if HAVE_SQLITE3 static enum mandoclevel passthrough(const char *, int, int); -#endif static void spawn_pager(void); static int toptions(struct curparse *, char *); static void usage(enum argmode) __attribute__((noreturn)); @@ -124,13 +121,11 @@ main(int argc, char *argv[]) char *auxpaths; char *defos; unsigned char *uc; -#if HAVE_SQLITE3 struct manpage *res, *resp; char *conf_file, *defpaths; size_t isec, i, sz; int prio, best_prio, synopsis_only; char sec; -#endif enum mandoclevel rc, rctmp; enum outmode outmode; int fd; @@ -153,9 +148,7 @@ main(int argc, char *argv[]) /* Search options. */ memset(&paths, 0, sizeof(struct manpaths)); -#if HAVE_SQLITE3 conf_file = defpaths = NULL; -#endif auxpaths = NULL; memset(&search, 0, sizeof(struct mansearch)); @@ -176,15 +169,13 @@ main(int argc, char *argv[]) memset(&curp, 0, sizeof(struct curparse)); curp.outtype = OUTT_LOCALE; - curp.wlevel = MANDOCLEVEL_FATAL; + curp.wlevel = MANDOCLEVEL_BADARG; options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1; defos = NULL; use_pager = 1; show_usage = 0; -#if HAVE_SQLITE3 synopsis_only = 0; -#endif outmode = OUTMODE_DEF; while (-1 != (c = getopt(argc, argv, @@ -194,9 +185,7 @@ main(int argc, char *argv[]) outmode = OUTMODE_ALL; break; case 'C': -#if HAVE_SQLITE3 conf_file = optarg; -#endif break; case 'c': use_pager = 0; @@ -206,9 +195,7 @@ main(int argc, char *argv[]) break; case 'h': (void)strlcat(curp.outopts, "synopsis,", BUFSIZ); -#if HAVE_SQLITE3 synopsis_only = 1; -#endif use_pager = 0; outmode = OUTMODE_ALL; break; @@ -242,9 +229,7 @@ main(int argc, char *argv[]) outmode = OUTMODE_ALL; break; case 'M': -#if HAVE_SQLITE3 defpaths = optarg; -#endif break; case 'm': auxpaths = optarg; @@ -304,9 +289,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; -#if HAVE_SQLITE3 resp = NULL; -#endif /* * Quirks for help(1) @@ -328,6 +311,10 @@ main(int argc, char *argv[]) argv++; argc--; } + if (search.arch == NULL) + search.arch = getenv("MACHINE"); + if (search.arch == NULL) + search.arch = MACHINE; } rc = MANDOCLEVEL_OK; @@ -335,7 +322,6 @@ main(int argc, char *argv[]) /* man(1), whatis(1), apropos(1) */ if (search.argmode != ARG_FILE) { -#if HAVE_SQLITE3 if (argc == 0) usage(search.argmode); @@ -346,9 +332,18 @@ main(int argc, char *argv[]) /* Access the mandoc database. */ manpath_parse(&paths, conf_file, defpaths, auxpaths); +#if HAVE_SQLITE3 mansearch_setup(1); if( ! mansearch(&search, &paths, 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 && search.argmode == ARG_NAME) fs_search(&search, &paths, argc, argv, &res, &sz); @@ -402,11 +397,6 @@ main(int argc, char *argv[]) if (outmode == OUTMODE_FLN || outmode == OUTMODE_LST) goto out; -#else - fputs("mandoc: database support not compiled in\n", - stderr); - return((int)MANDOCLEVEL_BADARG); -#endif } /* mandoc(1) */ @@ -432,10 +422,7 @@ main(int argc, char *argv[]) while (argc) { rctmp = mparse_open(curp.mp, &fd, -#if HAVE_SQLITE3 - resp != NULL ? resp->file : -#endif - *argv); + resp != NULL ? resp->file : *argv); if (rc < rctmp) rc = rctmp; @@ -444,11 +431,8 @@ main(int argc, char *argv[]) spawn_pager(); use_pager = 0; -#if HAVE_SQLITE3 if (resp == NULL) -#endif parse(&curp, fd, *argv, &rc); -#if HAVE_SQLITE3 else if (resp->form & FORM_SRC) { /* For .so only; ignore failure. */ chdir(paths.paths[resp->ipath]); @@ -459,7 +443,6 @@ main(int argc, char *argv[]) if (rc < rctmp) rc = rctmp; } -#endif rctmp = mparse_wait(curp.mp); if (rc < rctmp) @@ -472,11 +455,9 @@ main(int argc, char *argv[]) if (MANDOCLEVEL_OK != rc && curp.wstop) break; -#if HAVE_SQLITE3 if (resp != NULL) resp++; else -#endif argv++; if (--argc) mparse_reset(curp.mp); @@ -487,14 +468,14 @@ main(int argc, char *argv[]) mparse_free(curp.mp); mchars_free(curp.mchars); -#if HAVE_SQLITE3 out: if (search.argmode != ARG_FILE) { manpath_free(&paths); +#if HAVE_SQLITE3 mansearch_free(res, sz); mansearch_setup(0); - } #endif + } free(defos); @@ -540,7 +521,6 @@ usage(enum argmode argmode) exit((int)MANDOCLEVEL_BADARG); } -#if HAVE_SQLITE3 static int fs_lookup(const struct manpaths *paths, size_t ipath, const char *sec, const char *arch, const char *name, @@ -578,9 +558,11 @@ fs_lookup(const struct manpaths *paths, size_t ipath, return(0); found: +#if HAVE_SQLITE3 fprintf(stderr, "%s: outdated mandoc.db lacks %s(%s) entry,\n" " consider running # makewhatis %s\n", progname, name, sec, paths->paths[ipath]); +#endif *res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage)); page = *res + (*ressz - 1); @@ -630,7 +612,6 @@ fs_search(const struct mansearch *cfg, const struct ma argc--; } } -#endif static void parse(struct curparse *curp, int fd, const char *file, @@ -647,11 +628,6 @@ parse(struct curparse *curp, int fd, const char *file, rc = mparse_readfd(curp->mp, fd, file); - /* Stop immediately if the parse has failed. */ - - if (MANDOCLEVEL_FATAL <= rc) - goto cleanup; - /* * With -Wstop and warnings or errors of at least the requested * level, do not produce output. @@ -742,7 +718,6 @@ cleanup: *level = rc; } -#if HAVE_SQLITE3 static enum mandoclevel passthrough(const char *file, int fd, int synopsis_only) { @@ -808,7 +783,6 @@ fail: progname, file, syscall, strerror(errno)); return(MANDOCLEVEL_SYSERR); } -#endif static int koptions(int *options, char *arg) @@ -889,14 +863,15 @@ static int woptions(struct curparse *curp, char *arg) { char *v, *o; - const char *toks[6]; + const char *toks[7]; toks[0] = "stop"; toks[1] = "all"; toks[2] = "warning"; toks[3] = "error"; - toks[4] = "fatal"; - toks[5] = NULL; + toks[4] = "unsupp"; + toks[5] = "fatal"; + toks[6] = NULL; while (*arg) { o = arg; @@ -913,7 +888,10 @@ woptions(struct curparse *curp, char *arg) curp->wlevel = MANDOCLEVEL_ERROR; break; case 4: - curp->wlevel = MANDOCLEVEL_FATAL; + curp->wlevel = MANDOCLEVEL_UNSUPP; + break; + case 5: + curp->wlevel = MANDOCLEVEL_BADARG; break; default: fprintf(stderr, "%s: -W %s: Bad argument\n",