git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH] Print the usage string on stdout instead of stderr.
@ 2010-05-17  9:48 Giuseppe Scrivano
  2010-05-17 11:46 ` Michael J Gruber
  0 siblings, 1 reply; 14+ messages in thread
From: Giuseppe Scrivano @ 2010-05-17  9:48 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 190 bytes --]

Hello,

I have noticed that the -h flag uses stderr to print the usage string,
is there any reason for it?

The small patch I have attached changes -h to print on stdout.

Thanks,
Giuseppe


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Print-the-usage-string-on-stdout-instead-of-stderr.patch --]
[-- Type: text/x-diff, Size: 3267 bytes --]

>From 4a5c4e4470dae11e22ff233b34a10b6a912fcd3e Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Mon, 17 May 2010 11:31:09 +0200
Subject: [PATCH] Print the usage string on stdout instead of stderr.

Signed-off-by: Giuseppe Scrivano <gscrivano@gnu.org>
---
 parse-options.c |   36 +++++++++++++++++-------------------
 1 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/parse-options.c b/parse-options.c
index 8546d85..9adaf44 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -479,7 +479,7 @@ static int usage_argh(const struct option *opts)
 			s = literal ? "[%s]" : "[<%s>]";
 	else
 		s = literal ? " %s" : " <%s>";
-	return fprintf(stderr, s, opts->argh ? opts->argh : "...");
+	return printf(s, opts->argh ? opts->argh : "...");
 }
 
 #define USAGE_OPTS_WIDTH 24
@@ -491,47 +491,45 @@ static int usage_with_options_internal(const char * const *usagestr,
 	if (!usagestr)
 		return PARSE_OPT_HELP;
 
-	fprintf(stderr, "usage: %s\n", *usagestr++);
+	printf("usage: %s\n", *usagestr++);
 	while (*usagestr && **usagestr)
-		fprintf(stderr, "   or: %s\n", *usagestr++);
+		printf("   or: %s\n", *usagestr++);
 	while (*usagestr) {
-		fprintf(stderr, "%s%s\n",
-				**usagestr ? "    " : "",
-				*usagestr);
+		printf("%s%s\n",**usagestr ? "    " : "", *usagestr);
 		usagestr++;
 	}
 
 	if (opts->type != OPTION_GROUP)
-		fputc('\n', stderr);
+		fputc('\n', stdout);
 
 	for (; opts->type != OPTION_END; opts++) {
 		size_t pos;
 		int pad;
 
 		if (opts->type == OPTION_GROUP) {
-			fputc('\n', stderr);
+			fputc('\n', stdout);
 			if (*opts->help)
-				fprintf(stderr, "%s\n", opts->help);
+				printf("%s\n", opts->help);
 			continue;
 		}
 		if (!full && (opts->flags & PARSE_OPT_HIDDEN))
 			continue;
 
-		pos = fprintf(stderr, "    ");
+		pos = printf("    ");
 		if (opts->short_name && !(opts->flags & PARSE_OPT_NEGHELP)) {
 			if (opts->flags & PARSE_OPT_NODASH)
-				pos += fprintf(stderr, "%c", opts->short_name);
+				pos += printf("%c", opts->short_name);
 			else
-				pos += fprintf(stderr, "-%c", opts->short_name);
+				pos += printf("-%c", opts->short_name);
 		}
 		if (opts->long_name && opts->short_name)
-			pos += fprintf(stderr, ", ");
+			pos += printf(", ");
 		if (opts->long_name)
-			pos += fprintf(stderr, "--%s%s",
+			pos += printf("--%s%s",
 				(opts->flags & PARSE_OPT_NEGHELP) ?  "no-" : "",
 				opts->long_name);
 		if (opts->type == OPTION_NUMBER)
-			pos += fprintf(stderr, "-NUM");
+			pos += printf("-NUM");
 
 		if (!(opts->flags & PARSE_OPT_NOARG))
 			pos += usage_argh(opts);
@@ -539,12 +537,12 @@ static int usage_with_options_internal(const char * const *usagestr,
 		if (pos <= USAGE_OPTS_WIDTH)
 			pad = USAGE_OPTS_WIDTH - pos;
 		else {
-			fputc('\n', stderr);
+			fputc('\n', stdout);
 			pad = USAGE_OPTS_WIDTH;
 		}
-		fprintf(stderr, "%*s%s\n", pad + USAGE_GAP, "", opts->help);
+		printf("%*s%s\n", pad + USAGE_GAP, "", opts->help);
 	}
-	fputc('\n', stderr);
+	fputc('\n', stdout);
 
 	return PARSE_OPT_HELP;
 }
@@ -560,7 +558,7 @@ void usage_msg_opt(const char *msg,
 		   const char * const *usagestr,
 		   const struct option *options)
 {
-	fprintf(stderr, "%s\n\n", msg);
+	printf("%s\n\n", msg);
 	usage_with_options(usagestr, options);
 }
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2010-05-25  8:34 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-17  9:48 [RFC][PATCH] Print the usage string on stdout instead of stderr Giuseppe Scrivano
2010-05-17 11:46 ` Michael J Gruber
2010-05-17 12:07   ` Miles Bader
2010-05-17 13:30     ` Michael J Gruber
2010-05-17 13:54       ` Miles Bader
2010-05-17 14:07       ` Giuseppe Scrivano
2010-05-17 14:11         ` Tay Ray Chuan
2010-05-17 12:40   ` Giuseppe Scrivano
2010-05-17 13:30     ` Michael J Gruber
2010-05-17 16:02       ` Giuseppe Scrivano
2010-05-18  9:43         ` Michael J Gruber
2010-05-24 20:51           ` Giuseppe Scrivano
2010-05-25  6:46             ` Michael J Gruber
2010-05-25  8:40               ` [PATCH v2] " Giuseppe Scrivano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).