From 1e0aef8257164d9d2f06e50b262dea31395f8af0 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 17 Mar 2012 18:51:59 +0100 Subject: [PATCH] raw: add long options and version printing Signed-off-by: Sami Kerola --- disk-utils/raw.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/disk-utils/raw.c b/disk-utils/raw.c index 028fd7a7a1..5b5ebf04f8 100644 --- a/disk-utils/raw.c +++ b/disk-utils/raw.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "c.h" #include "nls.h" @@ -34,7 +35,6 @@ #define RAW_NR_MINORS 8192 -char * progname; int do_query = 0; int do_query_all = 0; @@ -57,6 +57,8 @@ static void __attribute__ ((__noreturn__)) usage(int err) " %1$s -q %2$srawN\n" " %1$s -qa\n"), program_invocation_short_name, RAWDEVDIR); fputs(USAGE_OPTIONS, out); + fputs(_(" -q, --query set query mode\n"), out); + fputs(_(" -a, --all query all raw devices\n"), out); fputs(USAGE_HELP, out); fputs(USAGE_VERSION, out); fprintf(out, USAGE_MAN_TAIL("raw(8)")); @@ -75,22 +77,31 @@ int main(int argc, char *argv[]) struct stat statbuf; + static const struct option longopts[] = { + {"query", no_argument, 0, 'q'}, + {"all", no_argument, 0, 'a'}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {NULL, no_argument, 0, '0'}, + }; + setlocale(LC_MESSAGES, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - progname = argv[0]; - - while ((c = getopt(argc, argv, "ahq")) != -1) { + while ((c = getopt_long(argc, argv, "qaVh", longopts, NULL)) != -1) { switch (c) { + case 'q': + do_query = 1; + break; case 'a': do_query_all = 1; break; + case 'V': + printf(UTIL_LINUX_VERSION); + return EXIT_SUCCESS; case 'h': usage(0); - case 'q': - do_query = 1; - break; default: usage(1); } -- 2.47.3