=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.202 retrieving revision 1.207 diff -u -p -r1.202 -r1.207 --- mandoc/main.c 2014/12/05 21:55:04 1.202 +++ mandoc/main.c 2014/12/17 18:45:35 1.207 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.202 2014/12/05 21:55:04 schwarze Exp $ */ +/* $Id: main.c,v 1.207 2014/12/17 18:45:35 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze @@ -83,12 +83,17 @@ struct curparse { }; static int koptions(int *, char *); +#if HAVE_SQLITE3 +int mandocdb(int, char**); +#endif static int moptions(int *, char *); 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)); @@ -107,12 +112,14 @@ main(int argc, char *argv[]) struct curparse curp; struct mansearch search; struct manpaths paths; - char *conf_file, *defpaths, *auxpaths; + 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; + int prio, best_prio, synopsis_only; char sec; #endif enum mandoclevel rc; @@ -120,7 +127,6 @@ main(int argc, char *argv[]) int fd; int show_usage; int use_pager; - int synopsis_only; int options; int c; @@ -130,19 +136,27 @@ main(int argc, char *argv[]) else ++progname; +#if HAVE_SQLITE3 + if (strcmp(progname, BINM_MAKEWHATIS) == 0) + return(mandocdb(argc, argv)); +#endif + /* Search options. */ memset(&paths, 0, sizeof(struct manpaths)); - conf_file = defpaths = auxpaths = NULL; +#if HAVE_SQLITE3 + conf_file = defpaths = NULL; +#endif + auxpaths = NULL; memset(&search, 0, sizeof(struct mansearch)); search.outkey = "Nd"; - if (strcmp(progname, "man") == 0) + if (strcmp(progname, BINM_MAN) == 0) search.argmode = ARG_NAME; - else if (strncmp(progname, "apropos", 7) == 0) + else if (strcmp(progname, BINM_APROPOS) == 0) search.argmode = ARG_EXPR; - else if (strncmp(progname, "whatis", 6) == 0) + else if (strcmp(progname, BINM_WHATIS) == 0) search.argmode = ARG_WORD; else if (strncmp(progname, "help", 4) == 0) search.argmode = ARG_NAME; @@ -159,7 +173,9 @@ main(int argc, char *argv[]) use_pager = 1; show_usage = 0; +#if HAVE_SQLITE3 synopsis_only = 0; +#endif outmode = OUTMODE_DEF; while (-1 != (c = getopt(argc, argv, @@ -169,7 +185,9 @@ main(int argc, char *argv[]) outmode = OUTMODE_ALL; break; case 'C': +#if HAVE_SQLITE3 conf_file = optarg; +#endif break; case 'c': use_pager = 0; @@ -179,7 +197,9 @@ 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; @@ -213,7 +233,9 @@ main(int argc, char *argv[]) outmode = OUTMODE_ALL; break; case 'M': +#if HAVE_SQLITE3 defpaths = optarg; +#endif break; case 'm': auxpaths = optarg; @@ -288,10 +310,11 @@ main(int argc, char *argv[]) argv = help_argv; argc = 1; } - } else if (argv[0] != NULL && - isdigit((unsigned char)argv[0][0]) && - (argv[0][1] == '\0' || !strcmp(argv[0], "3p"))) { - search.sec = argv[0]; + } else if (((uc = argv[0]) != NULL) && + ((isdigit(uc[0]) && (uc[1] == '\0' || + (isalpha(uc[1]) && uc[2] == '\0'))) || + (uc[0] == 'n' && uc[1] == '\0'))) { + search.sec = uc; argv++; argc--; } @@ -596,6 +619,7 @@ parse(struct curparse *curp, int fd, const char *file, *level = rc; } +#if HAVE_SQLITE3 static enum mandoclevel passthrough(const char *file, int fd, int synopsis_only) { @@ -659,6 +683,7 @@ fail: progname, file, syscall, strerror(errno)); return(MANDOCLEVEL_SYSERR); } +#endif static int koptions(int *options, char *arg)