summaryrefslogtreecommitdiffstats
path: root/tools/lvm.c
diff options
context:
space:
mode:
authorJoe Thornber <thornber@redhat.com>2001-12-17 10:08:27 +0000
committerJoe Thornber <thornber@redhat.com>2001-12-17 10:08:27 +0000
commit8a6d1dd408a0dd059a8551cc4a6ed25c758db898 (patch)
treeace2f57c59b528df639b8ed777bb0b670e1a5a07 /tools/lvm.c
parentdf520f126531482afa749423a6e42424c058a7e1 (diff)
downloadlvm2-8a6d1dd408a0dd059a8551cc4a6ed25c758db898.tar.gz
lvm2-8a6d1dd408a0dd059a8551cc4a6ed25c758db898.tar.xz
lvm2-8a6d1dd408a0dd059a8551cc4a6ed25c758db898.zip
I had another look at the argument processing code:
o You must list long args with no short option (eg. --version) at the front of the args.h file. o If an argument has no short option, set the short option in args.h to '\0' o The index into the 'the_args' var is now stored as the option value for getopt, iff there is no short opt.
Diffstat (limited to 'tools/lvm.c')
-rw-r--r--tools/lvm.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/tools/lvm.c b/tools/lvm.c
index f10101b3..60d5276e 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -376,6 +376,15 @@ static void alloc_command(void)
__alloc(2 * _array_size);
}
+/*
+ * Sets up the short and long argument. If there
+ * is no short argument then the index of the
+ * argument in the the_args array is set as the
+ * long opt value. Yuck. Of course this means we
+ * can't have more than 'a' long arguments. Since
+ * we have only 1 ATM (--version) I think we can
+ * live with this restriction.
+ */
static void add_getopt_arg(int arg, char **ptr, struct option **o)
{
struct arg *a = the_args + arg;
@@ -391,7 +400,7 @@ static void add_getopt_arg(int arg, char **ptr, struct option **o)
(*o)->name = a->long_arg + 2;
(*o)->has_arg = a->fn ? 1 : 0;
(*o)->flag = NULL;
- (*o)->val = a->short_arg;
+ (*o)->val = arg;
(*o)++;
}
}
@@ -456,12 +465,18 @@ static int process_command_line(struct command *com, int *argc, char ***argv)
static struct arg *find_arg(struct command *com, int opt)
{
struct arg *a;
- int i;
+ int i, arg;
for (i = 0; i < com->num_args; i++) {
- a = the_args + com->valid_args[i];
-
- if (opt == a->short_arg)
+ arg = com->valid_args[i];
+ a = the_args + arg;
+
+ /*
+ * opt should equal either the
+ * short arg, or the index into
+ * 'the_args'.
+ */
+ if ((a->short_arg && (opt == a->short_arg)) || (opt == arg))
return a;
}