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 --- nand-utils/nftl_format.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'nand-utils/nftl_format.c') diff --git a/nand-utils/nftl_format.c b/nand-utils/nftl_format.c index 1fc3b36..8485553 100644 --- a/nand-utils/nftl_format.c +++ b/nand-utils/nftl_format.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,8 @@ #include #include +#include "common.h" + unsigned char BadUnitTable[MAX_ERASE_ZONES]; unsigned char *readbuf; unsigned char *writebuf[4]; @@ -53,6 +56,12 @@ struct INFTLMediaHeader *INFTLhdr; static int do_oobcheck = 1; static int do_rwecheck = 1; +static const struct option long_opts[] = { + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}, +}; + static unsigned char check_block_1(unsigned long block) { unsigned char oobbuf[16]; @@ -195,6 +204,21 @@ void usage(int rc) exit(rc); } +static void display_version(void) +{ + common_print_version(); + printf("Copyright (C) 2005 Thomas Gleixner \n" + "\n" + "%1$s comes with NO WARRANTY\n" + "to the extent permitted by law.\n" + "\n" + "You may redistribute copies of %1$s\n" + "under the terms of the GNU General Public Licence.\n" + "See the file `COPYING' for more information.\n", + PROGRAM_NAME); + exit(EXIT_SUCCESS); +} + int main(int argc, char **argv) { unsigned long startofs = 0, part_size = 0; @@ -207,16 +231,14 @@ int main(int argc, char **argv) char *mtddevice; const char *nftl; int c, do_inftl = 0, do_bbt = 0; - - - printf("version 1.24 2005/11/07 11:15:13 gleixner\n"); + int idx = 0; if (argc < 2) usage(1); nftl = "NFTL"; - while ((c = getopt(argc, argv, "?hib")) > 0) { + while ((c = getopt_long(argc, argv, "?hibV", long_opts, &idx)) != -1) { switch (c) { case 'i': nftl = "INFTL"; @@ -229,6 +251,9 @@ int main(int argc, char **argv) case '?': usage(0); break; + case 'V': + display_version(); + break; default: usage(1); break; -- cgit v1.2.3