[Aggregator] Look for -h before the main options

The options -f and -h are now parsed before the other options (instead
of just -f).
This commit is contained in:
Matteo Cypriani 2011-04-12 22:40:18 +02:00
parent 52c3b34170
commit 7a95851795
1 changed files with 17 additions and 9 deletions

View File

@ -188,19 +188,27 @@ void parse_config_file(int argc, char **argv)
CFG_END()
} ;
char *config_file ;
char *config_file = NULL ; // Configuration file name
// Option -f specifies a config file, so we search for it first
// Option -f specifies a config file, -h exits the
// program, so we search for them first
int opt ;
do
opt = getopt(argc, argv, OPTIONS) ;
while (opt != 'f' && opt != -1) ;
if (opt == 'f')
while ((opt = getopt(argc, argv, OPTIONS)) != -1)
{
config_file = malloc((strlen(optarg) + 1) * sizeof(char)) ;
strcpy(config_file, optarg) ;
switch (opt)
{
case 'f' :
config_file = malloc((strlen(optarg) + 1) * sizeof(char)) ;
strcpy(config_file, optarg) ;
break ;
case 'h' :
print_usage() ;
exit(0) ;
}
}
else // If -f isn't found, we use the default config file
// If -f isn't found, we use the default config file
if (config_file == NULL)
{
config_file =
malloc((strlen(DEFAULT_CONFIG_FILE) + 1) * sizeof(char)) ;