From: Kevin Cernekee Date: Mon, 8 Oct 2012 01:03:41 +0000 (-0700) Subject: Allow optional arguments in the config file X-Git-Tag: v4.99~42 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=286e2f333b4e093d91f5aad850a6cf121c87efe7;p=users%2Fdwmw2%2Fopenconnect.git Allow optional arguments in the config file getopt_long() treats an argument as optional if has_arg == 2. Extend this feature to the config file parser as well. Signed-off-by: Kevin Cernekee --- diff --git a/main.c b/main.c index 68170325..03f0fa92 100644 --- a/main.c +++ b/main.c @@ -321,7 +321,7 @@ static int config_line_num = 0; * 3. It may be freed during normal operation, so we have to use strdup() * even when it's an option from argv[]. (e.g. vpninfo->cert_password). */ -#define keep_config_arg() (config_file?strdup(config_arg):config_arg) +#define keep_config_arg() (config_file && config_arg ? strdup(config_arg) : config_arg) static int next_option(int argc, char **argv, char **config_arg) { @@ -405,10 +405,12 @@ static int next_option(int argc, char **argv, char **config_arg) fprintf(stderr, _("Option '%s' does not take an argument at line %d\n"), this->name, config_line_num); return '?'; - } else if (this->has_arg && !*line) { + } else if (this->has_arg == 1 && !*line) { fprintf(stderr, _("Option '%s' requires an argument at line %d\n"), this->name, config_line_num); return '?'; + } else if (this->has_arg == 2 && !*line) { + line = NULL; } config_line_num++;