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/flashcp.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'misc-utils/flashcp.c') diff --git a/misc-utils/flashcp.c b/misc-utils/flashcp.c index 3fddeb0..6594a45 100644 --- a/misc-utils/flashcp.c +++ b/misc-utils/flashcp.c @@ -43,9 +43,7 @@ #include #include -typedef int bool; -#define true 1 -#define false 0 +#include "common.h" #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 @@ -96,9 +94,11 @@ static void showusage(bool error) "\n" "usage: %1$s [ -v | --verbose ] \n" " %1$s -h | --help\n" + " %1$s -V | --version\n" "\n" " -h | --help Show this help message\n" " -v | --verbose Show progress reports\n" + " -V | --version Show version information and exit\n" " File which you want to copy to flash\n" " Flash device to write to (e.g. /dev/mtd0, /dev/mtd1, etc.)\n" "\n", @@ -182,10 +182,11 @@ int main (int argc,char *argv[]) for (;;) { int option_index = 0; - static const char *short_options = "hv"; + static const char *short_options = "hvV"; static const struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, {0, 0, 0, 0}, }; @@ -204,6 +205,10 @@ int main (int argc,char *argv[]) flags |= FLAG_VERBOSE; DEBUG("Got FLAG_VERBOSE\n"); break; + case 'V': + common_print_version(); + exit(EXIT_SUCCESS); + break; default: DEBUG("Unknown parameter: %s\n",argv[option_index]); showusage(true); -- cgit v1.2.3