changeset 144:1fbc50374a30

Promote help to global config option, teach error_exit() to output usage message when called from get_optflags().
author Rob Landley <rob@landley.net>
date Thu, 11 Oct 2007 15:36:36 -0500
parents 9cbb323f297f
children 8affb8850366
files Config.in lib/args.c lib/lib.c lib/lib.h toys/Config.in toys/help.c
diffstat 6 files changed, 25 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/Config.in	Thu Oct 04 02:04:10 2007 -0500
+++ b/Config.in	Thu Oct 11 15:36:36 2007 -0500
@@ -2,6 +2,22 @@
 
 menu "Global settings"
 
+config HELP
+	bool "help"
+	default y
+	help
+	  usage: help [command]
+
+	  Show usage information for toybox commands.
+
+config HELP_LONG
+	bool "Verbose help text"
+	default y
+	depends on HELP
+	help
+	  Show more than one line of help information per command.
+
+
 config TOYBOX_FREE
 	bool "Free memory unnecessarily"
 	default n
--- a/lib/args.c	Thu Oct 04 02:04:10 2007 -0500
+++ b/lib/args.c	Thu Oct 11 15:36:36 2007 -0500
@@ -133,6 +133,7 @@
 	long *nextarg = (long *)&toy;
 	char *options = toys.which->options;
 
+	if (CFG_HELP) toys.exithelp++;
 	// Allocate memory for optargs
 	maxargs = 0;
 	while (toys.argv[maxargs++]);
@@ -300,6 +301,7 @@
 		error_exit("Need %d argument%s", minargs, minargs ? "s" : "");
 	if (optarg>maxargs)
 		error_exit("Max %d argument%s", maxargs, maxargs ? "s" : "");
+	if (CFG_HELP) toys.exithelp = 0;
 }
 
 // Loop through files listed on the command line
--- a/lib/lib.c	Thu Oct 04 02:04:10 2007 -0500
+++ b/lib/lib.c	Thu Oct 11 15:36:36 2007 -0500
@@ -55,6 +55,12 @@
 {
 	va_list va;
 
+	if (CFG_HELP && toys.exithelp) {
+		*toys.optargs=*toys.argv;
+		help_main();
+		fprintf(stderr,"\n");
+	}
+
 	va_start(va, msg);
 	verror_msg(msg, 0, va);
 	va_end(va);
@@ -75,12 +81,6 @@
 	exit(toys.exitval);
 }
 
-// Stub until the online help system goes in.
-void usage_exit(void)
-{
-	exit(1);
-}
-
 // Die unless we can allocate memory.
 void *xmalloc(size_t size)
 {
--- a/lib/lib.h	Thu Oct 04 02:04:10 2007 -0500
+++ b/lib/lib.h	Thu Oct 11 15:36:36 2007 -0500
@@ -45,7 +45,6 @@
 void perror_msg(char *msg, ...);
 void error_exit(char *msg, ...);
 void perror_exit(char *msg, ...);
-void usage_exit(void);
 void *xmalloc(size_t size);
 void *xzalloc(size_t size);
 void *xrealloc(void *ptr, size_t size);
--- a/toys/Config.in	Thu Oct 04 02:04:10 2007 -0500
+++ b/toys/Config.in	Thu Oct 11 15:36:36 2007 -0500
@@ -101,22 +101,6 @@
 	help
 	  A hello world program.  You don't need this.
 
-config HELP
-	bool "help"
-	default y
-	help
-	  usage: help [command]
-
-	  Show usage information for toybox commands.
-
-config HELP_LONG
-	bool "Verbose help text"
-	default y
-	depends on HELP
-	help
-	  Show more than one line of help information per command.
-
-
 config MDEV
 	bool "mdev"
 	default n
--- a/toys/help.c	Thu Oct 04 02:04:10 2007 -0500
+++ b/toys/help.c	Thu Oct 11 15:36:36 2007 -0500
@@ -28,6 +28,6 @@
 		s = help_data;
 	}
 
-	printf("%s", s);
+	fprintf(toys.exithelp ? stderr : stdout, "%s", s);
 	return 0;
 }