[PATCH 07/10] Allow optional arguments in the config file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <cernekee at gmail.com>
---
 main.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c
index 4d5cb0e..0506481 100644
--- a/main.c
+++ b/main.c
@@ -324,7 +324,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)
 {
@@ -408,10 +408,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++;
-- 
1.7.5.4




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux