From 987c4c151995e3ee7188da26f4f3b5c8e05f2b7a Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Thu, 5 Dec 2002 22:35:15 +0000 Subject: [PATCH] Fix long arg processing. --- tools/lvm.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/lvm.c b/tools/lvm.c index 7377f9521..dbc295ff9 100644 --- a/tools/lvm.c +++ b/tools/lvm.c @@ -360,9 +360,7 @@ void usage(const char *name) * 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. + * can't have more than 'a' long arguments. */ static void _add_getopt_arg(int arg, char **ptr, struct option **o) { @@ -379,7 +377,10 @@ 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 = arg; + if (a->short_arg) + (*o)->val = a->short_arg; + else + (*o)->val = arg; (*o)++; } } @@ -434,6 +435,9 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, optind = 0; while ((opt = getopt_long(*argc, *argv, str, opts, NULL)) >= 0) { + if (opt == '?') + return 0; + a = _find_arg(cmd->command, opt); if (!a) { @@ -1146,5 +1150,7 @@ int main(int argc, char **argv) out: _fin(cmd); + if (ret == ECMD_PROCESSED) + ret = 0; return ret; }