From: Giuseppe Scrivano <gscrivano@gnu•org>
To: git@vger•kernel.org
Subject: [RFC][PATCH] Print the usage string on stdout instead of stderr.
Date: Mon, 17 May 2010 11:48:38 +0200 [thread overview]
Message-ID: <878w7ieu4p.fsf@thor.thematica.it> (raw)
[-- 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
next reply other threads:[~2010-05-17 9:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-17 9:48 Giuseppe Scrivano [this message]
2010-05-17 11:46 ` [RFC][PATCH] Print the usage string on stdout instead of stderr 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878w7ieu4p.fsf@thor.thematica.it \
--to=gscrivano@gnu$(echo .)org \
--cc=git@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox