diff options
author | Jim Meyering <jim@meyering.net> | 2007-03-05 14:47:02 +0100 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-03-05 14:47:02 +0100 |
commit | cc46aa2dbbaebc7f68e8bbfc9bfb313a2e1c2e18 (patch) | |
tree | e71e1f5415e909e14cb9a808d8a603272d9a2e68 /partprobe | |
parent | 3389f62ba35ca2f0c5ba87ae29af5ef807ecf985 (diff) | |
download | parted-cc46aa2dbbaebc7f68e8bbfc9bfb313a2e1c2e18.tar.gz |
Make partprobe accept --help and --version options.
Add long options: --no-update (same as existing -d), and
--summary (same as existing -s).
* partprobe/partprobe.c
Include configmake.h, getopt.h, and NLS-related things.
(main): Rewrite option handling.
Along the way, fix a bug whereby "partprobe DEV1 DEV2 ... DEVN" would
exit successfully whenever process_dev (DEVN) returns nonzero, even
when that function fails for each of the preceding devices.
Diffstat (limited to 'partprobe')
-rw-r--r-- | partprobe/partprobe.c | 127 |
1 files changed, 81 insertions, 46 deletions
diff --git a/partprobe/partprobe.c b/partprobe/partprobe.c index 9a26e9a..78257d4 100644 --- a/partprobe/partprobe.c +++ b/partprobe/partprobe.c @@ -31,16 +31,40 @@ #include <stdio.h> #include <string.h> +#include <getopt.h> #include "closeout.h" +#include "configmake.h" #include "version-etc.h" +#include <locale.h> +#include "gettext.h" +#if ! ENABLE_NLS +# undef textdomain +# define textdomain(Domainname) /* empty */ +# undef bindtextdomain +# define bindtextdomain(Domainname, Dirname) /* empty */ +#endif + +#undef _ +#define _(msgid) gettext (msgid) + #define AUTHORS \ "<http://parted.alioth.debian.org/cgi-bin/trac.cgi/browser/AUTHORS>" /* The official name of this program (e.g., no `g' prefix). */ #define PROGRAM_NAME "partprobe" +static struct option const long_options[] = + { + {"no-update", no_argument, NULL, 'd'}, + {"summary", no_argument, NULL, 's'}, + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {NULL, 0, NULL, 0} + }; + + char *program_name; /* initialized to 0 according to the language lawyers */ @@ -106,70 +130,81 @@ error: return 0; } -static void -help () -{ - printf ("usage: %s [-d] [-h] [-s] [-v] [DEVICES...]\n\n" - "-d don't update the kernel\n" - "-s print a summary of contents\n" - "-v version info\n", PROGRAM_NAME); -} - -static void -version () +void +usage (int status) { - version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, VERSION, AUTHORS, - (char *) NULL); + if (status != EXIT_SUCCESS) + fprintf (stderr, _("Try `%s --help' for more information.\n"), + program_name); + else + { + printf (_("Usage: %s [OPTION] [DEVICE]...\n"), PROGRAM_NAME); + fputs (_("\ +Inform the OS of partition table changes.\n\ +\n\ + -d, --no-update don't update the kernel\n\ + -s, --summary print a summary of contents\n\ + -h, --help display this help and exit\n\ + -v, --version output version information and exit\n\ +"), stdout); + fputs (_("\ +\n\ +With no DEVICE, probe all partitions.\n\ +"), stdout); + printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT); + } + exit (status); } int main (int argc, char* argv[]) { - int dev_passed = 0; - int i; - PedDevice* dev; - int status = 1; + int status = 0; program_name = argv[0]; atexit (close_stdout); - for (i = 1; i < argc; i++) { - if (argv[i][0] != '-') { - dev_passed = 1; - continue; - } - switch (argv[i][1]) { - case '?': - case 'h': - help(); - return 0; + int c; + while ((c = getopt_long (argc, argv, "dhsv", long_options, NULL)) != -1) + switch (c) { + case 'd': + opt_no_probe = 1; + break; - case 'd': opt_no_probe = 1; break; - case 's': opt_summary = 1; break; + case 's': + opt_summary = 1; + break; - case 'v': - version(); - return 0; - } - } - - if (dev_passed) { - for (i = 1; i < argc; i++) { - if (argv[i][0] == '-') - continue; + case 'h': + usage (EXIT_SUCCESS); + break; - dev = ped_device_get (argv[i]); - if (dev) - status &= process_dev (dev); - else - status = 0; + case 'v': + version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, + VERSION, AUTHORS, (char *) NULL); + exit (EXIT_SUCCESS); + break; + + default: + usage (EXIT_FAILURE); + } + + int n_dev = argc - optind; + if (n_dev != 0) { + int i; + for (i = optind; i < argc; i++) { + PedDevice *dev = ped_device_get (argv[i]); + if (dev == NULL || process_dev (dev) == 0) + status = 1; } } else { ped_device_probe_all (); + PedDevice *dev; for (dev = ped_device_get_next (NULL); dev; dev = ped_device_get_next (dev)) - status &= process_dev (dev); + if (process_dev (dev) == 0) + status = 1; } - return !status; + return status; } |