=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.218 retrieving revision 1.221 diff -u -p -r1.218 -r1.221 --- mandoc/main.c 2015/02/03 21:16:02 1.218 +++ mandoc/main.c 2015/02/16 16:23:54 1.221 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.218 2015/02/03 21:16:02 schwarze Exp $ */ +/* $Id: main.c,v 1.221 2015/02/16 16:23:54 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze @@ -103,7 +103,6 @@ static enum mandoclevel passthrough(const char *, int static void spawn_pager(void); static int toptions(struct curparse *, char *); static void usage(enum argmode) __attribute__((noreturn)); -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}; @@ -134,8 +133,9 @@ main(int argc, char *argv[]) int options; int c; - progname = strrchr(argv[0], '/'); - if (progname == NULL) + if (argc < 1) + progname = "mandoc"; + else if ((progname = strrchr(argv[0], '/')) == NULL) progname = argv[0]; else ++progname; @@ -256,9 +256,6 @@ main(int argc, char *argv[]) case 'w': outmode = OUTMODE_FLN; break; - case 'V': - version(); - /* NOTREACHED */ default: show_usage = 1; break; @@ -287,8 +284,10 @@ main(int argc, char *argv[]) /* Parse arguments. */ - argc -= optind; - argv += optind; + if (argc > 0) { + argc -= optind; + argv += optind; + } resp = NULL; /* @@ -414,13 +413,13 @@ main(int argc, char *argv[]) if (OUTT_MAN == curp.outtype) mparse_keep(curp.mp); - if (argc == 0) { + if (argc < 1) { if (use_pager && isatty(STDOUT_FILENO)) spawn_pager(); parse(&curp, STDIN_FILENO, "", &rc); } - while (argc) { + while (argc > 0) { rctmp = mparse_open(curp.mp, &fd, resp != NULL ? resp->file : *argv); if (rc < rctmp) @@ -483,37 +482,29 @@ out: } static void -version(void) -{ - - printf("mandoc %s\n", VERSION); - exit((int)MANDOCLEVEL_OK); -} - -static void usage(enum argmode argmode) { switch (argmode) { case ARG_FILE: - fputs("usage: mandoc [-acfhklV] [-Ios=name] " + fputs("usage: mandoc [-acfhkl] [-Ios=name] " "[-Kencoding] [-mformat] [-Ooption]\n" "\t [-Toutput] [-Wlevel] [file ...]\n", stderr); break; case ARG_NAME: - fputs("usage: man [-acfhklVw] [-C file] [-I os=name] " + fputs("usage: man [-acfhklw] [-C file] [-I os=name] " "[-K encoding] [-M path] [-m path]\n" "\t [-O option=value] [-S subsection] [-s section] " "[-T output] [-W level]\n" "\t [section] name ...\n", stderr); break; case ARG_WORD: - fputs("usage: whatis [-acfhklVw] [-C file] " + fputs("usage: whatis [-acfhklw] [-C file] " "[-M path] [-m path] [-O outkey] [-S arch]\n" "\t [-s section] name ...\n", stderr); break; case ARG_EXPR: - fputs("usage: apropos [-acfhklVw] [-C file] " + fputs("usage: apropos [-acfhklw] [-C file] " "[-M path] [-m path] [-O outkey] [-S arch]\n" "\t [-s section] expression ...\n", stderr); break; @@ -563,7 +554,7 @@ found: " consider running # makewhatis %s\n", progname, name, sec, paths->paths[ipath]); #endif - + *res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage)); page = *res + (*ressz - 1); page->file = file;