From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753777AbbJNRKy (ORCPT ); Wed, 14 Oct 2015 13:10:54 -0400 Received: from demumfd001.nsn-inter.net ([93.183.12.32]:56019 "EHLO demumfd001.nsn-inter.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751889AbbJNRKx (ORCPT ); Wed, 14 Oct 2015 13:10:53 -0400 From: Sriram Raghunathan To: a.p.zijlstra@chello.nl, paulus@samba.org, acme@kernel.org, yunlong.song@huawei.com Cc: mingo@redhat.com, artagnon@gmail.com, hemant@linux.vnet.ibm.com, jolsa@kernel.org, dsahern@gmail.com, sriram.r@nokia.com, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] perf :redirection of usage strings to stdout Date: Wed, 14 Oct 2015 22:40:07 +0530 Message-Id: <1444842607-26505-1-git-send-email-sriram.r@nokia.com> X-Mailer: git-send-email 2.6.1 In-Reply-To: References: X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-size: 5170 X-purgate-ID: 151667::1444842626-0000047E-79FACC4A/0/0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch is to redirect the usage/builtin help strings to stdout rather than stderr. This is follows the patter similar to that of some of the coreutils (ls, rm). This patch originated from the discussion on a mail loop about the inconsistency usage of stdout/stderr usage. Tested the piece of code below with # perf stat -h > /tmp/foo 2>> /tmp/bar # perf --help > /tmp/foo 2>&1 /tmp/bar Signed-off-by: Sriram Raghunathan --- tools/perf/util/parse-options.c | 54 ++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index 01626be..c81b2e3 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c @@ -563,9 +563,9 @@ static void print_option_help(const struct option *opts, int full) int pad; if (opts->type == OPTION_GROUP) { - fputc('\n', stderr); + fputc('\n', stdout); if (*opts->help) - fprintf(stderr, "%s\n", opts->help); + fprintf(stdout, "%s\n", opts->help); return; } if (!full && (opts->flags & PARSE_OPT_HIDDEN)) @@ -573,16 +573,16 @@ static void print_option_help(const struct option *opts, int full) if (opts->flags & PARSE_OPT_DISABLED) return; - pos = fprintf(stderr, " "); + pos = fprintf(stdout, " "); if (opts->short_name) - pos += fprintf(stderr, "-%c", opts->short_name); + pos += fprintf(stdout, "-%c", opts->short_name); else - pos += fprintf(stderr, " "); + pos += fprintf(stdout, " "); if (opts->long_name && opts->short_name) - pos += fprintf(stderr, ", "); + pos += fprintf(stdout, ", "); if (opts->long_name) - pos += fprintf(stderr, "--%s", opts->long_name); + pos += fprintf(stdout, "--%s", opts->long_name); switch (opts->type) { case OPTION_ARGUMENT: @@ -593,11 +593,11 @@ static void print_option_help(const struct option *opts, int full) case OPTION_UINTEGER: if (opts->flags & PARSE_OPT_OPTARG) if (opts->long_name) - pos += fprintf(stderr, "[=]"); + pos += fprintf(stdout, "[=]"); else - pos += fprintf(stderr, "[]"); + pos += fprintf(stdout, "[]"); else - pos += fprintf(stderr, " "); + pos += fprintf(stdout, " "); break; case OPTION_CALLBACK: if (opts->flags & PARSE_OPT_NOARG) @@ -607,19 +607,19 @@ static void print_option_help(const struct option *opts, int full) if (opts->argh) { if (opts->flags & PARSE_OPT_OPTARG) if (opts->long_name) - pos += fprintf(stderr, "[=<%s>]", opts->argh); + pos += fprintf(stdout, "[=<%s>]", opts->argh); else - pos += fprintf(stderr, "[<%s>]", opts->argh); + pos += fprintf(stdout, "[<%s>]", opts->argh); else - pos += fprintf(stderr, " <%s>", opts->argh); + pos += fprintf(stdout, " <%s>", opts->argh); } else { if (opts->flags & PARSE_OPT_OPTARG) if (opts->long_name) - pos += fprintf(stderr, "[=...]"); + pos += fprintf(stdout, "[=...]"); else - pos += fprintf(stderr, "[...]"); + pos += fprintf(stdout, "[...]"); else - pos += fprintf(stderr, " ..."); + pos += fprintf(stdout, " ..."); } break; default: /* OPTION_{BIT,BOOLEAN,SET_UINT,SET_PTR} */ @@ -636,10 +636,10 @@ static void print_option_help(const struct option *opts, int full) 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); + fprintf(stdout, "%*s%s\n", pad + USAGE_GAP, "", opts->help); } int usage_with_options_internal(const char * const *usagestr, @@ -648,23 +648,23 @@ int usage_with_options_internal(const char * const *usagestr, if (!usagestr) return PARSE_OPT_HELP; - fprintf(stderr, "\n usage: %s\n", *usagestr++); + fprintf(stdout, "\n usage: %s\n", *usagestr++); while (*usagestr && **usagestr) - fprintf(stderr, " or: %s\n", *usagestr++); + fprintf(stdout, " or: %s\n", *usagestr++); while (*usagestr) { - fprintf(stderr, "%s%s\n", + fprintf(stdout, "%s%s\n", **usagestr ? " " : "", *usagestr); usagestr++; } if (opts->type != OPTION_GROUP) - fputc('\n', stderr); + fputc('\n', stdout); for ( ; opts->type != OPTION_END; opts++) print_option_help(opts, full); - fputc('\n', stderr); + fputc('\n', stdout); return PARSE_OPT_HELP; } @@ -684,16 +684,16 @@ int parse_options_usage(const char * const *usagestr, if (!usagestr) goto opt; - fprintf(stderr, "\n usage: %s\n", *usagestr++); + fprintf(stdout, "\n usage: %s\n", *usagestr++); while (*usagestr && **usagestr) - fprintf(stderr, " or: %s\n", *usagestr++); + fprintf(stdout, " or: %s\n", *usagestr++); while (*usagestr) { - fprintf(stderr, "%s%s\n", + fprintf(stdout, "%s%s\n", **usagestr ? " " : "", *usagestr); usagestr++; } - fputc('\n', stderr); + fputc('\n', stdout); opt: for ( ; opts->type != OPTION_END; opts++) { -- 2.6.1