]> sourceware.org Git - lvm2.git/commitdiff
I had another look at the argument processing code:
authorJoe Thornber <thornber@redhat.com>
Mon, 17 Dec 2001 10:08:27 +0000 (10:08 +0000)
committerJoe Thornber <thornber@redhat.com>
Mon, 17 Dec 2001 10:08:27 +0000 (10:08 +0000)
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.

tools/args.h
tools/lvm.c

index 269b9957f21fde5fa3c96967b7cccd63d66c280d..a94c5a4dcd962305b74275f55a47b7c153a954b0 100644 (file)
@@ -1,23 +1,18 @@
 /*
- * 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)
@@ -63,7 +58,6 @@ xx(uuid_ARG, 'u', "uuid", NULL)
 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)
index f10101b3325079fb563087a078ed793e5d528b42..60d5276eeec1b57b8927425822b0d985f7f72cc9 100644 (file)
@@ -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;
        }
 
This page took 0.035835 seconds and 5 git commands to generate.