From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mms2.broadcom.com ([216.31.210.18]) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Qqtzi-0001aa-5E for linux-mtd@lists.infradead.org; Tue, 09 Aug 2011 21:37:51 +0000 From: "Brian Norris" To: "Artem Bityutskiy" Subject: [PATCH v2 5/5] mtdinfo: consolidate help as display_help() Date: Tue, 9 Aug 2011 14:36:46 -0700 Message-ID: <1312925806-15929-6-git-send-email-computersforpeace@gmail.com> In-Reply-To: <1312925806-15929-1-git-send-email-computersforpeace@gmail.com> References: <1312925806-15929-1-git-send-email-computersforpeace@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: brian.foster@maxim-ic.com, Brian Norris , linux-mtd@lists.infradead.org, Mike Frysinger List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 --- ubi-utils/mtdinfo.c | 36 +++++++++++++++++++----------------- 1 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ubi-utils/mtdinfo.c b/ubi-utils/mtdinfo.c index 1c3a46f..9f25fd8 100644 --- a/ubi-utils/mtdinfo.c +++ b/ubi-utils/mtdinfo.c @@ -50,10 +50,16 @@ static struct args args = { .node = NULL, }; -static const char doc[] = PROGRAM_NAME " version " VERSION - " - a tool to print MTD information."; - -static const char optionsstr[] = +static void display_help(void) +{ + printf( +"%1$s version %2$s - a tool to print MTD information.\n" +"\n" +"Usage: %1$s [--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" @@ -61,17 +67,15 @@ static const char optionsstr[] = " 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 " [--map | -M] [--ubi-info | -u]\n" -" " PROGRAM_NAME " --all [--ubi-info | -u]\n" -" " PROGRAM_NAME " [--help | --version]\n" +"-V, --version print program 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"; +"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" +"\t\t\t\tand include UBI layout information\n" +" %1$s -a print information about all MTD devices\n", + PROGRAM_NAME, VERSION); +} 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