]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
more: add --help and --version
authorRuediger Meier <ruediger.meier@ga-group.nl>
Wed, 21 Jun 2017 20:37:37 +0000 (22:37 +0200)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Thu, 22 Jun 2017 19:35:01 +0000 (21:35 +0200)
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
text-utils/more.1
text-utils/more.c

index 428fdecb7e230c1cd4c80542317751c294ea59cb..c4420e09a11df5ceac4a6dd6aca24af13930fb99 100644 (file)
@@ -98,6 +98,12 @@ Start displaying each file at line
 The
 .I string
 to be searched in each file before starting to display it.
+.TP
+\fB\-\-help\fR
+Display help text and exit.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Display version information and exit.
 .SH COMMANDS
 Interactive commands for
 .B more
index 7c197b2017a093f87af65860fa734e5699846b24..35786567ab257bfdfc48c0df03022146a52a8b99 100644 (file)
@@ -225,8 +225,9 @@ static void putstring(char *s)
        tputs(s, fileno(stdout), putchar);      /* putp(s); */
 }
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] <file>...\n"), program_invocation_short_name);
 
@@ -244,9 +245,12 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(_(" -<number>   the number of lines per screenful\n"), out);
        fputs(_(" +<number>   display file beginning from line number\n"), out);
        fputs(_(" +/<string>  display file beginning from search string match\n"), out);
-       fputs(_(" -V          display version information and exit\n"), out);
+
+       fputs(USAGE_SEPARATOR, out);
+       fputs(_("     --help     display this help and exit\n"), out);
+       fputs(_(" -V, --version  output version information and exit\n"), out);
        fprintf(out, USAGE_MAN_TAIL("more(1)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -267,6 +271,16 @@ int main(int argc, char **argv)
        textdomain(PACKAGE);
        atexit(close_stdout);
 
+       if (argc > 1) {
+               /* first arg may be one of our standard longopts */
+               if (!strcmp(argv[1], "--help"))
+                       usage();
+               if (!strcmp(argv[1], "--version")) {
+                       printf(UTIL_LINUX_VERSION);
+                       exit(EXIT_SUCCESS);
+               }
+       }
+
        nfiles = argc;
        fnames = argv;
        setlocale(LC_ALL, "");
@@ -319,9 +333,10 @@ int main(int argc, char **argv)
        left = dlines;
        if (nfiles > 1)
                prnames++;
-       if (!no_intty && nfiles == 0)
-               usage(stderr);
-       else
+       if (!no_intty && nfiles == 0) {
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
+       } else
                f = stdin;
        if (!no_tty) {
                signal(SIGQUIT, onquit);
@@ -488,7 +503,7 @@ void argscan(char *s)
                        break;
                default:
                        warnx(_("unknown option -%s"), s);
-                       usage(stderr);
+                       errtryhelp(EXIT_FAILURE);
                        break;
                }
                s++;