[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Handle options independent of their order.
From: |
Benno Schulenberg |
Subject: |
[PATCH] Handle options independent of their order. |
Date: |
Mon, 09 Apr 2007 23:34:15 +0200 |
Abort on any invalid option, and handle -v and -h first.
---
parted/parted.c | 42 +++++++++++++++++++++++++++++++-----------
1 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/parted/parted.c b/parted/parted.c
index 4107ae0..fe060fb 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -96,6 +96,9 @@ int opt_script_mode = 0;
int opt_machine_mode = 0;
int is_toggle_mode = 0;
+static char* short_usage_msg = N_(
+"Usage: parted [-hlmsv] [DEVICE [COMMAND [PARAMETERS]]...]\n");
+
static char* number_msg = N_(
"NUMBER is the partition number used by Linux. On MS-DOS disk labels, the "
"primary partitions number from 1 to 4, logical partitions from 5 onwards.\n");
@@ -136,7 +139,7 @@ static Command* commands [256] = {NULL};
static PedTimer* g_timer;
static TimerContext timer_context;
-static int _print_list (int cli);
+static int _print_list ();
static void _done (PedDevice* dev);
static void
@@ -1291,7 +1294,7 @@ do_print (PedDevice** dev)
}
else if (has_list_arg)
- return _print_list (0);
+ return _print_list ();
else if (has_num_arg) {
PedPartition* part = NULL;
@@ -1510,7 +1513,7 @@ error:
}
static int
-_print_list (int cli)
+_print_list ()
{
PedDevice *current_dev = NULL;
@@ -1521,9 +1524,6 @@ _print_list (int cli)
putchar ('\n');
}
- if(cli)
- exit(0);
-
return 1;
}
@@ -2253,13 +2253,12 @@ _version ()
{
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, VERSION, AUTHORS,
(char *) NULL);
- exit (EXIT_SUCCESS);
}
static int
_parse_options (int* argc_ptr, char*** argv_ptr)
{
-int opt;
+int opt, help = 0, list = 0, version = 0, wrong = 0;
while (1)
{
@@ -2269,14 +2268,35 @@ while (1)
break;
switch (opt) {
- case 'h': help_msg (); break;
- case 'l': _print_list(1); break;
+ case 'h': help = 1; break;
+ case 'l': list = 1; break;
case 'm': opt_machine_mode = 1; break;
case 's': opt_script_mode = 1; break;
- case 'v': _version (); break;
+ case 'v': version = 1; break;
+ default: wrong = 1; break;
}
}
+if (wrong == 1) {
+ printf (_(short_usage_msg));
+ return 0;
+}
+
+if (version == 1) {
+ _version ();
+ exit (EXIT_SUCCESS);
+}
+
+if (help == 1) {
+ help_msg ();
+ exit (EXIT_SUCCESS);
+}
+
+if (list == 1) {
+ _print_list ();
+ exit (EXIT_SUCCESS);
+}
+
*argc_ptr -= optind;
*argv_ptr += optind;
return 1;
--
1.5.0.7
- [PATCH] Handle options independent of their order.,
Benno Schulenberg <=