mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-29 15:22:30 +03:00
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.
This commit is contained in:
parent
df520f1265
commit
8a6d1dd408
28
tools/args.h
28
tools/args.h
@ -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)
|
||||
|
23
tools/lvm.c
23
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];
|
||||
arg = com->valid_args[i];
|
||||
a = the_args + arg;
|
||||
|
||||
if (opt == a->short_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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user