[PATCH 11/13] more: add --help and --version

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ruediger Meier <ruediger.meier@xxxxxxxxxxx>

Signed-off-by: Ruediger Meier <ruediger.meier@xxxxxxxxxxx>
---
 text-utils/more.1 |  6 ++++++
 text-utils/more.c | 29 ++++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/text-utils/more.1 b/text-utils/more.1
index 428fdec..c4420e0 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 7c197b2..3578656 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++;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux