=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.201 retrieving revision 1.203 diff -u -p -r1.201 -r1.203 --- mandoc/main.c 2014/12/02 11:31:51 1.201 +++ mandoc/main.c 2014/12/09 07:29:42 1.203 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.201 2014/12/02 11:31:51 schwarze Exp $ */ +/* $Id: main.c,v 1.203 2014/12/09 07:29:42 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze @@ -83,6 +83,9 @@ 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 *); @@ -96,6 +99,8 @@ static void version(void) __attribute__((noreturn)) static int woptions(struct curparse *, char *); static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9}; +static char help_arg[] = "help"; +static char *help_argv[] = {help_arg, NULL}; static const char *progname; @@ -128,6 +133,12 @@ main(int argc, char *argv[]) else ++progname; +#if HAVE_SQLITE3 + if (0 == strncmp(progname, "mandocdb", 8) || + 0 == strncmp(progname, "makewhatis", 10)) + return(mandocdb(argc, argv)); +#endif + /* Search options. */ memset(&paths, 0, sizeof(struct manpaths)); @@ -142,6 +153,8 @@ main(int argc, char *argv[]) search.argmode = ARG_EXPR; else if (strncmp(progname, "whatis", 6) == 0) search.argmode = ARG_WORD; + else if (strncmp(progname, "help", 4) == 0) + search.argmode = ARG_NAME; else search.argmode = ARG_FILE; @@ -273,15 +286,24 @@ main(int argc, char *argv[]) resp = NULL; #endif - /* Quirk for a man(1) section argument without -s. */ + /* + * Quirks for help(1) + * and for a man(1) section argument without -s. + */ - if (search.argmode == ARG_NAME && - argv[0] != NULL && - isdigit((unsigned char)argv[0][0]) && - (argv[0][1] == '\0' || !strcmp(argv[0], "3p"))) { - search.sec = argv[0]; - argv++; - argc--; + if (search.argmode == ARG_NAME) { + if (*progname == 'h') { + if (argc == 0) { + 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]; + argv++; + argc--; + } } rc = MANDOCLEVEL_OK;