From 7dd42c510dc8ab10f52dcc2d20dc8af412be0744 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 19 Jul 2016 15:06:58 +0200 Subject: Unify version string printing When a program does sophisticated enough command line processing (i.e. getopt), make sure it responds to -V and --version. When a program prints a version string, make sure it uses the common_print_version macro to print out its name, that it is part of mtd-utils and the mtd-utils version from the build system in a fashion similar to common program packages like the GNU coreutils. When a program responds to -V/--version or -h/--help, make sure it reports success exit status. Signed-off-by: David Oberhollenzer Signed-off-by: Richard Weinberger --- jffsX-utils/jffs2dump.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'jffsX-utils/jffs2dump.c') diff --git a/jffsX-utils/jffs2dump.c b/jffsX-utils/jffs2dump.c index f8b8ac7..4b3164b 100644 --- a/jffsX-utils/jffs2dump.c +++ b/jffsX-utils/jffs2dump.c @@ -54,8 +54,8 @@ void display_help (void) { printf("Usage: %s [OPTION]... INPUTFILE\n" "Dump the contents of a binary JFFS2 image.\n\n" - " --help display this help and exit\n" - " --version display version information and exit\n" + " -h, --help display this help and exit\n" + " -V, --version display version information and exit\n" " -b, --bigendian image is big endian\n" " -l, --littleendian image is little endian\n" " -c, --content dump image contents\n" @@ -70,9 +70,8 @@ void display_help (void) void display_version (void) { - printf("%1$s " VERSION "\n" - "\n" - "Copyright (C) 2003 Thomas Gleixner \n" + common_print_version(); + printf("Copyright (C) 2003 Thomas Gleixner \n" "\n" "%1$s comes with NO WARRANTY\n" "to the extent permitted by law.\n" @@ -102,10 +101,10 @@ void process_options (int argc, char *argv[]) for (;;) { int option_index = 0; - static const char *short_options = "blce:rd:o:v"; + static const char *short_options = "blce:rd:o:vVh"; static const struct option long_options[] = { - {"help", no_argument, 0, 0}, - {"version", no_argument, 0, 0}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, {"bigendian", no_argument, 0, 'b'}, {"littleendian", no_argument, 0, 'l'}, {"content", no_argument, 0, 'c'}, @@ -124,15 +123,11 @@ void process_options (int argc, char *argv[]) } switch (c) { - case 0: - switch (option_index) { - case 0: - display_help(); - break; - case 1: - display_version(); - break; - } + case 'h': + display_help(); + break; + case 'V': + display_version(); break; case 'v': verbose = 1; -- cgit v1.2.3