[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:
parent
3c0f74fcb3
commit
737630b8c9
|
@ -48,7 +48,7 @@
|
||||||
|
|
||||||
|
|
||||||
/* Arguments & program configuration */
|
/* 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"
|
#define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-listener.conf"
|
||||||
enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ;
|
enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ;
|
||||||
#define DEFAULT_AUTOCALIBRATION_HELLO_DELAY 120 // seconds
|
#define DEFAULT_AUTOCALIBRATION_HELLO_DELAY 120 // seconds
|
||||||
|
@ -88,6 +88,7 @@ int make_packet(char **packet) ;
|
||||||
#endif // USE_PTHREAD
|
#endif // USE_PTHREAD
|
||||||
|
|
||||||
void print_usage(void) ;
|
void print_usage(void) ;
|
||||||
|
void print_version(void) ;
|
||||||
|
|
||||||
|
|
||||||
/* Macros to allow switching option handling with the libconfuse
|
/* Macros to allow switching option handling with the libconfuse
|
||||||
|
|
|
@ -181,28 +181,38 @@ void parse_config_file(int argc, char **argv)
|
||||||
CFG_END()
|
CFG_END()
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
char *config_file ; // Configuration file name
|
char *config_file = NULL ; // Configuration file name
|
||||||
#endif // USE_CONFIG_FILE
|
#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 ;
|
int opt ;
|
||||||
do
|
while ((opt = getopt(argc, argv, OPTIONS)) != -1)
|
||||||
opt = getopt(argc, argv, OPTIONS) ;
|
|
||||||
while (opt != 'f' && opt != -1) ;
|
|
||||||
if (opt == 'f')
|
|
||||||
{
|
{
|
||||||
|
switch (opt)
|
||||||
|
{
|
||||||
|
case 'f' :
|
||||||
#ifdef USE_CONFIG_FILE
|
#ifdef USE_CONFIG_FILE
|
||||||
config_file = malloc((strlen(optarg) + 1) * sizeof(char)) ;
|
config_file = malloc((strlen(optarg) + 1) * sizeof(char)) ;
|
||||||
strcpy(config_file, optarg) ;
|
strcpy(config_file, optarg) ;
|
||||||
#else // USE_CONFIG_FILE
|
#else // USE_CONFIG_FILE
|
||||||
fprintf(stderr, "Warning! Program was not compiled with"
|
fprintf(stderr, "Warning! Program was not compiled with"
|
||||||
" configuration file support, so -f is not available. You"
|
" configuration file support, so -f is not available."
|
||||||
" must specify all options on the command line, or default"
|
" You must specify all options on the command line,"
|
||||||
" value will be used.\n") ;
|
" or default value will be used.\n") ;
|
||||||
#endif // USE_CONFIG_FILE
|
#endif // USE_CONFIG_FILE
|
||||||
|
case 'h' :
|
||||||
|
print_usage() ;
|
||||||
|
exit(0) ;
|
||||||
|
case 'V' :
|
||||||
|
print_version() ;
|
||||||
|
exit(0) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_CONFIG_FILE
|
#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 =
|
config_file =
|
||||||
malloc((strlen(DEFAULT_CONFIG_FILE) + 1) * sizeof(char)) ;
|
malloc((strlen(DEFAULT_CONFIG_FILE) + 1) * sizeof(char)) ;
|
||||||
|
@ -262,9 +272,8 @@ void parse_command_line(int argc, char **argv)
|
||||||
break ;
|
break ;
|
||||||
case 'f' : // Config file
|
case 'f' : // Config file
|
||||||
break ; // (already parsed)
|
break ; // (already parsed)
|
||||||
case 'h' :
|
case 'h' : // Usage
|
||||||
print_usage() ;
|
break ; // (already parsed)
|
||||||
exit(0) ;
|
|
||||||
case 'H' :
|
case 'H' :
|
||||||
#ifdef USE_PTHREAD
|
#ifdef USE_PTHREAD
|
||||||
SET_AUTOCALIBRATION_HELLO_DELAY(strtol(optarg, NULL, 0)) ;
|
SET_AUTOCALIBRATION_HELLO_DELAY(strtol(optarg, NULL, 0)) ;
|
||||||
|
@ -308,6 +317,8 @@ void parse_command_line(int argc, char **argv)
|
||||||
case 'v' :
|
case 'v' :
|
||||||
SET_VERBOSE() ;
|
SET_VERBOSE() ;
|
||||||
break ;
|
break ;
|
||||||
|
case 'V' : // Version
|
||||||
|
break ; // (already parsed)
|
||||||
case 'w' :
|
case 'w' :
|
||||||
SET_WIFI_IFACE(optarg) ;
|
SET_WIFI_IFACE(optarg) ;
|
||||||
break ;
|
break ;
|
||||||
|
@ -962,9 +973,12 @@ void print_usage()
|
||||||
" [-w wifi_iface] [-k] [-v | -q] [-A] [-a autocalibration_port]"
|
" [-w wifi_iface] [-k] [-v | -q] [-A] [-a autocalibration_port]"
|
||||||
" [-H autocalibration_hello_delay] [-t autocalibration_delay]"
|
" [-H autocalibration_hello_delay] [-t autocalibration_delay]"
|
||||||
" [-n autocalibration_nb_packets]\n"
|
" [-n autocalibration_nb_packets]\n"
|
||||||
|
"\t%s -h\n"
|
||||||
|
"\t%s -V\n"
|
||||||
|
|
||||||
"Main options:\n"
|
"Main options:\n"
|
||||||
"\t-h\t\tPrint this help.\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"
|
"\t-f config_file\tUse 'config_file' instead of the default"
|
||||||
" configuration file (%s). Available only if program was"
|
" configuration file (%s). Available only if program was"
|
||||||
" compiled with libconfuse.\n"
|
" compiled with libconfuse.\n"
|
||||||
|
@ -1004,6 +1018,8 @@ void print_usage()
|
||||||
"\t-q\tQuiet mode (default).\n"
|
"\t-q\tQuiet mode (default).\n"
|
||||||
,
|
,
|
||||||
program_name,
|
program_name,
|
||||||
|
program_name,
|
||||||
|
program_name,
|
||||||
DEFAULT_CONFIG_FILE,
|
DEFAULT_CONFIG_FILE,
|
||||||
LOC_REQUEST_DEFAULT_PORT,
|
LOC_REQUEST_DEFAULT_PORT,
|
||||||
AGGREGATE_DEFAULT_PORT,
|
AGGREGATE_DEFAULT_PORT,
|
||||||
|
@ -1013,3 +1029,26 @@ void print_usage()
|
||||||
DEFAULT_AUTOCALIBRATION_NBPKT
|
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
|
||||||
|
) ;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue