All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Brian Norris" <computersforpeace@gmail.com>
To: "Artem Bityutskiy" <dedekind1@gmail.com>
Cc: brian.foster@maxim-ic.com,
	Brian Norris <computersforpeace@gmail.com>,
	linux-mtd@lists.infradead.org,
	Mike Frysinger <vapier.adi@gmail.com>
Subject: [PATCH v4 5/5] mtdinfo: consolidate help as display_help()
Date: Mon, 15 Aug 2011 13:17:05 -0700	[thread overview]
Message-ID: <1313439425-27044-1-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1313079580-22144-1-git-send-email-computersforpeace@gmail.com>

The help message for mtdinfo is unnecessarily disjointed. It is split
into three strings which reuse the PROGRAM_NAME string inefficiently and
don't have a consistent style.

This fixup should provide a cleaner look with aligned columns and
easier-to-read source code.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
v4: use spaces instead of tabs for indentation, using "strlen" plus printf
    positional parameters

v3: indented help message 'properly'

v2: split off from previous patch

 ubi-utils/mtdinfo.c |   52 ++++++++++++++++++++++++++------------------------
 1 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/ubi-utils/mtdinfo.c b/ubi-utils/mtdinfo.c
index 1c3a46f..d919673 100644
--- a/ubi-utils/mtdinfo.c
+++ b/ubi-utils/mtdinfo.c
@@ -50,28 +50,32 @@ static struct args args = {
 	.node = NULL,
 };
 
-static const char doc[] = PROGRAM_NAME " version " VERSION
-			 " - a tool to print MTD information.";
-
-static const char optionsstr[] =
-"-u, --ubi-info                  print what would UBI layout be if it was put\n"
-"                                on this MTD device\n"
-"-M, --map                       print eraseblock map\n"
-"-a, --all                       print information about all MTD devices\n"
-"                                Note: `--all' may give less info per device\n"
-"                                than, e.g., `mtdinfo /dev/mtdX'\n"
-"-h, --help                      print help message\n"
-"-V, --version                   print program version";
-
-static const char usage[] =
-"Usage: " PROGRAM_NAME " <MTD node file path> [--map | -M] [--ubi-info | -u]\n"
-"       " PROGRAM_NAME " --all [--ubi-info | -u]\n"
-"       " PROGRAM_NAME " [--help | --version]\n"
-"\n"
-"Example 1: " PROGRAM_NAME " /dev/mtd0       print information MTD device /dev/mtd0\n"
-"Example 2: " PROGRAM_NAME " /dev/mtd0 -u    print information MTD device /dev/mtd0\n"
-"\t\t\t\t   and include UBI layout information\n"
-"Example 3: " PROGRAM_NAME " -a              print information about all MTD devices\n";
+static void display_help(void)
+{
+	printf(
+		"%1$s version %2$s - a tool to print MTD information.\n"
+		"\n"
+		"Usage: %1$s <MTD node file path> [--map | -M] [--ubi-info | -u]\n"
+		"       %1$s --all [--ubi-info | -u]\n"
+		"       %1$s [--help | --version]\n"
+		"\n"
+		"Options:\n"
+		"-u, --ubi-info                  print what would UBI layout be if it was put\n"
+		"                                on this MTD device\n"
+		"-M, --map                       print eraseblock map\n"
+		"-a, --all                       print information about all MTD devices\n"
+		"                                Note: `--all' may give less info per device\n"
+		"                                than, e.g., `mtdinfo /dev/mtdX'\n"
+		"-h, --help                      print help message\n"
+		"-V, --version                   print program version\n"
+		"\n"
+		"Examples:\n"
+		"  %1$s /dev/mtd0             print information MTD device /dev/mtd0\n"
+		"  %1$s /dev/mtd0 -u          print information MTD device /dev/mtd0\n"
+		"  %4$*3$s                    and include UBI layout information\n"
+		"  %1$s -a                    print information about all MTD devices\n",
+		PROGRAM_NAME, VERSION, (int)strlen(PROGRAM_NAME) + 3, "");
+}
 
 static const struct option long_options[] = {
 	{ .name = "ubi-info",  .has_arg = 0, .flag = NULL, .val = 'u' },
@@ -105,9 +109,7 @@ static int parse_opt(int argc, char * const argv[])
 			break;
 
 		case 'h':
-			printf("%s\n\n", doc);
-			printf("%s\n\n", usage);
-			printf("%s\n", optionsstr);
+			display_help();
 			exit(EXIT_SUCCESS);
 
 		case 'V':
-- 
1.7.0.4

  parent reply	other threads:[~2011-08-15 20:17 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-09 21:36 [PATCH v2 0/5] bugfix, cleanup for mtdinfo Brian Norris
2011-08-09 21:36 ` [PATCH v2 1/5] mtdinfo: don't open NULL pointer when getting region_info with `-a' Brian Norris
2011-08-11  4:31   ` Mike Frysinger
2011-08-09 21:36 ` [PATCH v2 2/5] mtdinfo: refactor code to remove "args.all" dependency Brian Norris
2011-08-11  4:33   ` Mike Frysinger
2011-08-09 21:36 ` [PATCH v2 3/5] mtdinfo: restructure help message Brian Norris
2011-08-11  4:33   ` Mike Frysinger
2011-08-09 21:36 ` [PATCH v2 4/5] mtdinfo: fixup "example usage" help section Brian Norris
2011-08-11  4:33   ` Mike Frysinger
2011-08-09 21:36 ` [PATCH v2 5/5] mtdinfo: consolidate help as display_help() Brian Norris
2011-08-11  4:33   ` Mike Frysinger
2011-08-11 16:19     ` [PATCH v3 " Brian Norris
2011-08-11 17:15       ` Mike Frysinger
2011-08-12  7:06       ` Brian Foster
2011-08-12 16:37         ` Brian Norris
2011-08-13 18:10           ` Mike Frysinger
2011-08-15 17:27             ` Brian Norris
2011-08-16  4:00               ` Mike Frysinger
2011-08-16  7:18                 ` Brian Foster
2011-08-16 17:12                   ` Brian Norris
2011-08-17  8:02                     ` Brian Foster
2011-08-15 20:17       ` Brian Norris [this message]
2011-08-16 14:15 ` [PATCH v2 0/5] bugfix, cleanup for mtdinfo Artem Bityutskiy

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=1313439425-27044-1-git-send-email-computersforpeace@gmail.com \
    --to=computersforpeace@gmail.com \
    --cc=brian.foster@maxim-ic.com \
    --cc=dedekind1@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=vapier.adi@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.