From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway22.websitewelcome.com (gateway22.websitewelcome.com [192.185.46.233]) by sourceware.org (Postfix) with ESMTPS id 981FA3857804 for ; Sun, 21 Feb 2021 01:52:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 981FA3857804 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway22.websitewelcome.com (Postfix) with ESMTP id ED0D97415 for ; Sat, 20 Feb 2021 19:52:19 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id Ddv1lgUDKHPnUDdv1l7FAR; Sat, 20 Feb 2021 19:52:19 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=qqV7BMwExFCH661EbIGW3wqRw92v4Fosf2GmGmtIr+U=; b=TKXW+S4sjiWWOJd8q7orqV1P6l UjpuF2EVVXYRx5f2JCAVWUHcx/bRaQ931/OCLqBzVKnd/O+S2/MMkqHJxox75CL/n7kTnAFsukypX ddJGiPwT5xnj/5XXHQWkyy0dE; Received: from 97-122-70-152.hlrn.qwest.net ([97.122.70.152]:54612 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lDdv1-000Oe9-Ed; Sat, 20 Feb 2021 18:52:19 -0700 From: Tom Tromey To: dwz@sourceware.org Cc: Tom Tromey Subject: [PATCH] Print --version and --help to stdout Date: Sat, 20 Feb 2021 18:52:13 -0700 Message-Id: <20210221015213.886373-1-tom@tromey.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.70.152 X-Source-L: No X-Exim-ID: 1lDdv1-000Oe9-Ed X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-70-152.hlrn.qwest.net (localhost.localdomain) [97.122.70.152]:54612 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3034.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Feb 2021 01:52:28 -0000 Normall --version and --help output go to stdout and cause a program to exit with status 0. The rationale for the exit status is that the user asked for this behavior, and the program successfully complied. Printing --help output to stdout is nicer for piping into a pager. This patch changes dwz to follow this approach. I kept the program invocation name in the Usage line. Different programs seem to handle this differently. --- dwz.c | 105 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/dwz.c b/dwz.c index de432fb..01ad7ef 100644 --- a/dwz.c +++ b/dwz.c @@ -16223,20 +16223,20 @@ static struct option_help dwz_misc_options_help[] = "Display this information." } }; -/* Print LEN spaces to stderr. */ +/* Print LEN spaces to STREAM. */ static void -do_indent (unsigned int len) +do_indent (FILE *stream, unsigned int len) { unsigned int i; for (i = 0; i < len; i++) - fprintf (stderr, " "); + fprintf (stream, " "); } -/* Print MSG to stderr, indenting to INDENT and wrapping at LIMIT. Assume - starting position is at INDENT. */ +/* Print MSG to STREAM, indenting to INDENT and wrapping at LIMIT. + Assume starting position is at INDENT. */ static void -wrap (unsigned int indent, unsigned int limit, const char *msg) +wrap (FILE *stream, unsigned int indent, unsigned int limit, const char *msg) { unsigned int len = indent; const char *s = msg; @@ -16253,13 +16253,13 @@ wrap (unsigned int indent, unsigned int limit, const char *msg) if (len + 1 /* space */ + word_len > limit) { - fprintf (stderr, "\n"); - do_indent (indent); + fprintf (stream, "\n"); + do_indent (stream ,indent); len = indent; } else if (len > indent) { - fprintf (stderr, " "); + fprintf (stream, " "); len += 1; } @@ -16267,10 +16267,10 @@ wrap (unsigned int indent, unsigned int limit, const char *msg) { const char *i; for (i = s; i < e; ++i) - fprintf (stderr, "%c", *i); + fprintf (stream, "%c", *i); } else - fprintf (stderr, "%s", s); + fprintf (stream, "%s", s); len += word_len; if (e == NULL) @@ -16280,10 +16280,10 @@ wrap (unsigned int indent, unsigned int limit, const char *msg) } } -/* Print OPTIONS_HELP of length H to stderr, indenting to help message to +/* Print OPTIONS_HELP of length H to STREAM, indenting to help message to INDENT an wrapping at LIMIT. */ static void -print_options_help (struct option_help *options_help, unsigned int n, +print_options_help (FILE *stream, struct option_help *options_help, unsigned int n, unsigned int indent, unsigned int limit) { unsigned len; @@ -16294,29 +16294,29 @@ print_options_help (struct option_help *options_help, unsigned int n, { len = 0; - fprintf (stderr, " "); + fprintf (stream, " "); len += 2; s = options_help[i].short_name; if (s) { - fprintf (stderr, "-%s", s); + fprintf (stream, "-%s", s); len += 2; } s = options_help[i].long_name; if (len == 4) { - fprintf (stderr, ", "); + fprintf (stream, ", "); len += 2; } - fprintf (stderr, "--%s", s); + fprintf (stream, "--%s", s); len += 2 + strlen (s); s = options_help[i].argument; if (s) { - fprintf (stderr, " %s", s); + fprintf (stream, " %s", s); len += 1 + strlen (s); } @@ -16325,65 +16325,65 @@ print_options_help (struct option_help *options_help, unsigned int n, { if (len > indent) { - fprintf (stderr, "\n"); - do_indent (indent); + fprintf (stream, "\n"); + do_indent (stream, indent); } else - do_indent (indent - len); + do_indent (stream, indent - len); len = indent; - wrap (indent, limit, s); + wrap (stream, indent, limit, s); } - fprintf (stderr, "\n"); + fprintf (stream, "\n"); s = options_help[i].default_value; if (s) { - do_indent (indent); - fprintf (stderr, "Default value: %s.\n", s); + do_indent (stream, indent); + fprintf (stream, "Default value: %s.\n", s); } } } /* Print usage and exit. */ static void -usage (void) +usage (const char *progname, int failing) { unsigned int n; unsigned int indent, limit; - const char *msg; + FILE *stream = failing ? stderr : stdout; - msg - = ("Usage:\n" - " dwz [common options] [-h] [-m COMMONFILE] [-M NAME | -r] [FILES]\n" - " dwz [common options] -o OUTFILE FILE\n" - " dwz [ -v | -? ]"); - error (0, 0, "%s", msg); + fprintf (stream, + ("Usage:\n" + " %s [common options] [-h] [-m COMMONFILE] [-M NAME | -r] [FILES]\n" + " %s [common options] -o OUTFILE FILE\n" + " %s [ -v | -? ]\n"), + progname, progname, progname); indent = 30; limit = 80; - fprintf (stderr, "Common options:\n"); + fprintf (stream, "Common options:\n"); n = (sizeof (dwz_common_options_help) / sizeof (dwz_common_options_help[0])); - print_options_help (dwz_common_options_help, n, indent, limit); + print_options_help (stream, dwz_common_options_help, n, indent, limit); - fprintf (stderr, "Single-file options:\n"); + fprintf (stream, "Single-file options:\n"); n = (sizeof (dwz_single_file_options_help) / sizeof (dwz_single_file_options_help[0])); - print_options_help (dwz_single_file_options_help, n, indent, limit); + print_options_help (stream, dwz_single_file_options_help, n, indent, limit); - fprintf (stderr, "Multi-file options:\n"); + fprintf (stream, "Multi-file options:\n"); n = (sizeof (dwz_multi_file_options_help) / sizeof (dwz_multi_file_options_help[0])); - print_options_help (dwz_multi_file_options_help, n, indent, limit); + print_options_help (stream, dwz_multi_file_options_help, n, indent, limit); - fprintf (stderr, "Miscellaneous options:\n"); + fprintf (stream, "Miscellaneous options:\n"); n = (sizeof (dwz_misc_options_help) / sizeof (dwz_misc_options_help[0])); - print_options_help (dwz_misc_options_help, n, indent, limit); + print_options_help (stream, dwz_misc_options_help, n, indent, limit); #if DEVEL - fprintf (stderr, "Development options:\n"); + fprintf (stream, "Development options:\n"); msg = (" --devel-trace\n" " --devel-progress\n" @@ -16405,24 +16405,23 @@ usage (void) " --devel-deduplication-mode={none,intra-cu,inter-cu}\n" " --devel-uni-lang / --devel-no-uni-lang\n" " --devel-gen-cu / --devel-no-gen-cu\n"); - fprintf (stderr, "%s", msg); + fprintf (stream, "%s", msg); #endif - exit (1); + exit (failing); } /* Print version and exit. */ static void version (void) { - fprintf (stderr, - "dwz version " DWZ_VERSION "\n" - "Copyright (C) " RH_YEARS " Red Hat, Inc.\n" - "Copyright (C) " FSF_YEARS " Free Software Foundation, Inc.\n" - "Copyright (C) " SUSE_YEARS " SUSE LLC.\n" - "This program is free software; you may redistribute it under the terms of\n" - "the GNU General Public License version 3 or (at your option) any later version.\n" - "This program has absolutely no warranty.\n"); + printf ("dwz version " DWZ_VERSION "\n" + "Copyright (C) " RH_YEARS " Red Hat, Inc.\n" + "Copyright (C) " FSF_YEARS " Free Software Foundation, Inc.\n" + "Copyright (C) " SUSE_YEARS " SUSE LLC.\n" + "This program is free software; you may redistribute it under the terms of\n" + "the GNU General Public License version 3 or (at your option) any later version.\n" + "This program has absolutely no warranty.\n"); exit (0); } @@ -16451,7 +16450,7 @@ main (int argc, char *argv[]) { default: case '?': - usage (); + usage (argv[0], c != '?'); break; case 0: -- 2.26.2