/*
- * Copyright (C) 2001 Sistina Software
- *
- * LVM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * LVM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with LVM; see the file COPYING. If not, write to
- * the Free Software Foundation, 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
*
+ * This file is released under the GPL.
+ */
+
+/*
+ * Put all long args that don't have a
+ * corresponding short option first ...
*/
+xx(version_ARG, '\0', "version", NULL)
+/*
+ * ... and now the short args.
+ */
xx(available_ARG, 'a', "available", yes_no_arg)
xx(all_ARG, 'a', "all", NULL)
xx(autobackup_ARG, 'A', "autobackup", yes_no_arg)
xx(uuidlist_ARG, 'U', "uuidlist", NULL)
xx(verbose_ARG, 'v', "verbose", NULL)
xx(volumegroup_ARG, 'V', "volumegroup", NULL)
-xx(version_ARG, (char) 0x1, "version", NULL)
xx(allocation_ARG, 'x', "allocation", yes_no_arg)
xx(yes_ARG, 'y', "yes", NULL)
xx(zero_ARG, 'Z', "zero", yes_no_arg)
__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;
(*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)++;
}
}
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;
}