summaryrefslogtreecommitdiffstats
path: root/text-utils
diff options
context:
space:
mode:
authorRuediger Meier2017-06-21 22:37:37 +0200
committerRuediger Meier2017-06-22 21:35:01 +0200
commitc1da6d1eec6210b3bfbd3d8710178e2fcc0f0d5e (patch)
tree5ebce2315d43d0a578171f62ad5a9363830e2cfc /text-utils
parentwhereis: add --help and --version (diff)
downloadkernel-qcow2-util-linux-c1da6d1eec6210b3bfbd3d8710178e2fcc0f0d5e.tar.gz
kernel-qcow2-util-linux-c1da6d1eec6210b3bfbd3d8710178e2fcc0f0d5e.tar.xz
kernel-qcow2-util-linux-c1da6d1eec6210b3bfbd3d8710178e2fcc0f0d5e.zip
more: add --help and --version
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'text-utils')
-rw-r--r--text-utils/more.16
-rw-r--r--text-utils/more.c29
2 files changed, 28 insertions, 7 deletions
diff --git a/text-utils/more.1 b/text-utils/more.1
index 428fdecb7..c4420e09a 100644
--- a/text-utils/more.1
+++ b/text-utils/more.1
@@ -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
diff --git a/text-utils/more.c b/text-utils/more.c
index 7c197b201..35786567a 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -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++;