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 --- misc-utils/flash_erase.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'misc-utils/flash_erase.c') diff --git a/misc-utils/flash_erase.c b/misc-utils/flash_erase.c index 933373a..2bca78d 100644 --- a/misc-utils/flash_erase.c +++ b/misc-utils/flash_erase.c @@ -76,9 +76,8 @@ static void display_help (void) static void display_version (void) { - printf("%1$s version " VERSION "\n" - "\n" - "Copyright (C) 2000 Arcom Control Systems Ltd\n" + common_print_version(); + printf("Copyright (C) 2000 Arcom Control Systems Ltd\n" "\n" "%1$s comes with NO WARRANTY\n" "to the extent permitted by law.\n" @@ -105,10 +104,10 @@ int main(int argc, char *argv[]) */ for (;;) { int option_index = 0; - static const char *short_options = "jNqu"; + static const char *short_options = "jNquVh"; 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'}, {"jffs2", no_argument, 0, 'j'}, {"noskipbad", no_argument, 0, 'N'}, {"quiet", no_argument, 0, 'q'}, @@ -124,16 +123,12 @@ int main(int argc, char *argv[]) break; switch (c) { - case 0: - switch (option_index) { - case 0: - display_help(); - return 0; - case 1: - display_version(); - return 0; - } - break; + case 'h': + display_help(); + return EXIT_SUCCESS; + case 'V': + display_version(); + return EXIT_SUCCESS; case 'j': jffs2 = 1; break; -- cgit v1.2.3