[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[help-gengetopt] flag setting issues with override
From: |
Papp Gyozo (VBuster) |
Subject: |
[help-gengetopt] flag setting issues with override |
Date: |
Thu, 04 Feb 2010 14:17:01 +0100 |
Hi Lorenzo,
we've encountered a problem with flags with gengetopt 2.22.1/2. I know that you
don't like flags very much but my app is using 14 flags. (for historical
reasons, of course ;) Since it is a business product I couldn't change the
option type so easily.
The problem arises when a flag option is set more than once in successive call
of getoptions_internal(). In this case update_arg() flips back, eventually
reset the flag_given while field_given is incremented twice:
if (field_given)
(*field_given)++;
case ARG_FLAG:
*((int *)field) = !*((int *)field);
I don't know and could not figure out by myself if it is the intended behaviour
of gengetopt. Could you help me, please? If I change update_arg() it solve my
problem:
- if (field_given && *field_given && ! override)
+ if (field_given && *field_given && ( !override || arg_type == ARG_FLAG ))
return 0;
but I don't know if it is the good thing (tm).
The detailed scenario is that config file is parsed first and then the command
line. The latter has precedence over the former, that is, command line
arguments overrides option values given in config file. In my understanding
"override" should mean "confirm" in case of flags at least when different
settings are originated from different sources (or different runs of
gengetopt_internal()).
Here is the code flow:
struct getoptions_params ggo = {
1, // override what is in cmdline struct
1, // initialize struct w/ default values
0, // check required
0, // check ambiguity
1 // print errors (getopt_long, too)
};
getoptions_init ( options );
(...)
ggo.override = 1, ggo.initialize = 0;
if ( options->config_arg
&& getoptions_config_file ( options->config_arg, options, &ggo ) )
(...)
if ( getoptions_ext ( argc, argv, options, &ggo ) != EXIT_SUCCESS )
Note that we should follow these approach. Otherwise, in reverse order, when
override is set to 0, gengetopt raises error if a groupoption is set in both
the command line and in the config file. (It might be another issue.)
--
Papp, Gyozo
VirusBuster Kft
- [help-gengetopt] flag setting issues with override,
Papp Gyozo (VBuster) <=