[Listener] Add option -V

The new option -V displays the compilation-time options. In the future,
it should display the version number.

When the user calls the program either with -h or the new option -V, we
do not try any more to open and parse the configuration file (which was
useless since -h, and now -V, exit the program).
This commit is contained in:
Matteo Cypriani 2010-10-20 17:55:26 +02:00
parent 3c0f74fcb3
commit 737630b8c9
2 changed files with 57 additions and 17 deletions

View File

@ -48,7 +48,7 @@
/* Arguments & program configuration */
#define OPTIONS "Aa:d:f:hH:kl:m:n:p:qr:t:vw:" // getopt string
#define OPTIONS "Aa:d:f:hH:kl:m:n:p:qr:t:vVw:" // getopt string
#define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-listener.conf"
enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ;
#define DEFAULT_AUTOCALIBRATION_HELLO_DELAY 120 // seconds
@ -88,6 +88,7 @@ int make_packet(char **packet) ;
#endif // USE_PTHREAD
void print_usage(void) ;
void print_version(void) ;
/* Macros to allow switching option handling with the libconfuse

View File

@ -181,28 +181,38 @@ void parse_config_file(int argc, char **argv)
CFG_END()
} ;
char *config_file ; // Configuration file name
char *config_file = NULL ; // Configuration file name
#endif // USE_CONFIG_FILE
// Option -f specifies a config file, so we search for it first
// Option -f specifies a config file, options -h and -V exit 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)
{
switch (opt)
{
case 'f' :
#ifdef USE_CONFIG_FILE
config_file = malloc((strlen(optarg) + 1) * sizeof(char)) ;
strcpy(config_file, optarg) ;
config_file = malloc((strlen(optarg) + 1) * sizeof(char)) ;
strcpy(config_file, optarg) ;
#else // USE_CONFIG_FILE
fprintf(stderr, "Warning! Program was not compiled with"
" configuration file support, so -f is not available. You"
" must specify all options on the command line, or default"
" value will be used.\n") ;
fprintf(stderr, "Warning! Program was not compiled with"
" configuration file support, so -f is not available."
" You must specify all options on the command line,"
" or default value will be used.\n") ;
#endif // USE_CONFIG_FILE
case 'h' :
print_usage() ;
exit(0) ;
case 'V' :
print_version() ;
exit(0) ;
}
}
#ifdef USE_CONFIG_FILE
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)) ;
@ -262,9 +272,8 @@ void parse_command_line(int argc, char **argv)
break ;
case 'f' : // Config file
break ; // (already parsed)
case 'h' :
print_usage() ;
exit(0) ;
case 'h' : // Usage
break ; // (already parsed)
case 'H' :
#ifdef USE_PTHREAD
SET_AUTOCALIBRATION_HELLO_DELAY(strtol(optarg, NULL, 0)) ;
@ -308,6 +317,8 @@ void parse_command_line(int argc, char **argv)
case 'v' :
SET_VERBOSE() ;
break ;
case 'V' : // Version
break ; // (already parsed)
case 'w' :
SET_WIFI_IFACE(optarg) ;
break ;
@ -962,9 +973,12 @@ void print_usage()
" [-w wifi_iface] [-k] [-v | -q] [-A] [-a autocalibration_port]"
" [-H autocalibration_hello_delay] [-t autocalibration_delay]"
" [-n autocalibration_nb_packets]\n"
"\t%s -h\n"
"\t%s -V\n"
"Main options:\n"
"\t-h\t\tPrint this help.\n"
"\t-V\t\tShow version.\n"
"\t-f config_file\tUse 'config_file' instead of the default"
" configuration file (%s). Available only if program was"
" compiled with libconfuse.\n"
@ -1004,6 +1018,8 @@ void print_usage()
"\t-q\tQuiet mode (default).\n"
,
program_name,
program_name,
program_name,
DEFAULT_CONFIG_FILE,
LOC_REQUEST_DEFAULT_PORT,
AGGREGATE_DEFAULT_PORT,
@ -1013,3 +1029,26 @@ void print_usage()
DEFAULT_AUTOCALIBRATION_NBPKT
) ;
}
void print_version()
{
printf("This is OWLPS Listener, part of the Open Wireless Positioning"
" System project.\n"
"\n"
"Compilation-time options:\n"
"\tSupport for POSIX threads: %s.\n"
"\tSupport for configuration file (libconfuse): %s.\n",
#ifdef USE_PTHREAD
"YES"
#else // USE_PTHREAD
"NO"
#endif // USE_PTHREAD
,
#ifdef USE_CONFIG_FILE
"YES"
#else // USE_CONFIG_FILE
"NO"
#endif // USE_CONFIG_FILE
) ;
}