public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [committed] Don't use argv[0] in usage
Date: Fri, 26 Mar 2021 10:14:05 +0100	[thread overview]
Message-ID: <20210326091404.GA26975@delia> (raw)

Hi,

Using argv[0] in the usage string makes it harder to layout the usage message:
...
$ ./build/dwz -?
Usage:
  ./build/dwz [common options] [-h] [-m COMMONFILE] [-M NAME | -r] [FILES]
  ./build/dwz [common options] -o OUTFILE FILE
  ./build/dwz [ -v | -? ]
...

Instead, just use "dwz".

Committed to trunk.

Thanks,
- Tom

Don't use argv[0] in usage

2021-03-26  Tom de Vries  <tdevries@suse.de>

	* args.c (usage): Drop progname argument.
	(parse_args): Update call to usage.

---
 args.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/args.c b/args.c
index cc8c717..5f96bf3 100644
--- a/args.c
+++ b/args.c
@@ -355,18 +355,22 @@ print_options_help (FILE *stream, struct option_help *options_help, unsigned int
 
 /* Print usage and exit.  */
 static void
-usage (const char *progname, int failing)
+usage (int failing)
 {
-  unsigned int n;
+  unsigned int n, i;
   unsigned int indent, limit;
   FILE *stream = failing ? stderr : stdout;
-
-  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);
+  const char *header_lines[] = {
+    "dwz [common options] [-h] [-m COMMONFILE] [-M NAME | -r] [FILES]",
+    "dwz [common options] -o OUTFILE FILE",
+    "dwz [ -v | -? ]"
+  };
+  unsigned int nr_header_lines
+    = sizeof (header_lines) / sizeof (*header_lines);
+
+  fprintf (stream, "Usage:\n");
+  for (i = 0; i < nr_header_lines; ++i)
+    fprintf (stream, "  %s\n", header_lines[i]);
 
   indent = 30;
   limit = 80;
@@ -495,7 +499,7 @@ parse_args (int argc, char *argv[], bool *hardlink, const char **outfile)
 	{
 	default:
 	case '?':
-	  usage (argv[0], option_index == -1);
+	  usage (option_index == -1);
 	  break;
 
 	case 0:

                 reply	other threads:[~2021-03-26  9:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210326091404.GA26975@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).