Standardise CLI options

Make uniform the command-line options of the various programs.
Positioning: delete some useless short options.
This commit is contained in:
Matteo Cypriani 2011-12-19 15:06:47 +01:00
parent ffd1c1d625
commit 8c070d482e
5 changed files with 67 additions and 45 deletions

View File

@ -9,7 +9,7 @@
/* Arguments & program configuration */
#define OPTIONS "Aa:c:C:f:hi:k:K:l:o:p:qt:vV" // getopt string
#define OPTIONS "a:Ac:C:f:hi:k:K:l:o:p:qt:vV" // getopt string
#define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-aggregator.conf"
#define DEFAULT_AGGREGATE_TIMEOUT 1500 // milliseconds
#define DEFAULT_KEEP_TIMEOUT 3000 // milliseconds

View File

@ -27,7 +27,7 @@
#define DEFAULT_FLOOD_DELAY 1000
/* Program arguments (getopt string) */
#define OPTIONS "d:f::hi:l::n:p:t:V"
#define OPTIONS "F::hi:I:l::n:p:t:V"
/* Function headers */
@ -143,16 +143,13 @@ void parse_main_options(int argc, char **argv)
{
switch (opt)
{
case 'd' :
strncpy(options.dest_ip, optarg, INET_ADDRSTRLEN) ;
break ;
case 'f' :
case 'F' :
/* Facultative getopt options do not handle separated values
* (like -f <delay>), so we have to test separately.
* (like -F <delay>), so we have to test separately.
*/
if (optarg) // We got an option like -f<delay>, it's OK
if (optarg) // We got an option like -F<delay>, it's OK
options.flood_delay = strtoul(optarg, NULL, 0) ;
else // We got -f alone or -f <port>
else // We got -F alone or -F <port>
{
/* If we are at the end of the string, or the next optind
* is an option, we have the option without argument */
@ -171,9 +168,12 @@ void parse_main_options(int argc, char **argv)
case 'h' :
print_usage() ;
exit(0) ;
case 'i' :
case 'I' :
strncpy(options.iface, optarg, IFNAMSIZ + 1) ;
break ;
case 'i' :
strncpy(options.dest_ip, optarg, INET_ADDRSTRLEN) ;
break ;
case 'l' :
/* Facultative getopt options do not handle separated values
* (like -l <port>), so we have to test separately.
@ -223,7 +223,7 @@ void check_destination_ip()
if (options.dest_ip[0] == '\0')
{
fprintf(stderr, "Error! You must specify a destination IP address"
" (-d).\n") ;
" (-i) .\n") ;
print_usage() ;
exit(OWL_ERR_BAD_USAGE) ;
}
@ -485,16 +485,27 @@ void print_usage()
{
printf("Usage:\n"
"Localisation request:\n"
"\t%s -d dest_ip [-p dest_port] [-i iface] [-t delay]"
" [-n nb_packets] [-f [delay]] [-l [port]]\n"
"\t%s"
" -i dest_ip"
" [-p dest_port]"
" [-I iface]"
" [-t delay]"
" [-n nb_packets]"
" [-F [delay]]"
" [-l [port]]\n"
"Calibration request:\n"
"\t%s -d dest_ip [-p dest_port] [-i iface] [-t delay]"
" [-n nb_packets] direction x y z\n"
"\t%s"
" -i dest_ip"
" [-p dest_port]"
" [-I iface]"
" [-t delay]"
" [-n nb_packets]"
" direction x y z\n"
"\n"
"Options:\n"
"\t-h\t\tPrint this help.\n"
"\t-V\t\tPrint version information.\n"
"\t-d dest_ip\tDestination IP address of the localisation"
"\t-i dest_ip\tDestination IP address of the localisation"
" request.\n"
"\t-p dest_port\tDestination port of the localisation request"
" (default: %d).\n"
@ -504,11 +515,11 @@ void print_usage()
"\t-n nb_packets\tNumber of packet transmitted for the request"
" (default: %d for a normal request, %d for a calibration"
" request).\n"
"\t-i iface\tName of the network interface used to transmit the"
"\t-I iface\tName of the network interface used to transmit the"
" request (e.g. \"eth2\"). If this option is absent, interface"
" is selected automatically. You must be root to use this"
" option.\n"
"\t-f [delay]\t\"Flood mode\": loop undefinitely, sending a"
"\t-F [delay]\t\"Flood mode\": loop undefinitely, sending a"
" new request every <delay> milliseconds (default: %d ms).\n"
"\t-l [port]\tWait for the computed position and display it."
" The Optional argument <port> allows to specify the listening"

View File

@ -56,7 +56,7 @@
/* Arguments & program configuration */
#define OPTIONS "Aa:d:D:f:hH:kl:m:n:p:P:qr:t:vVw:" // getopt string
#define OPTIONS "a:Af:hH:i:I:Kl:m:n:p: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

View File

@ -445,14 +445,6 @@ int parse_main_options(int argc, char **argv)
case 'a' :
#ifdef USE_PTHREAD
SET_AUTOCALIBRATION_PORT(strtol(optarg, NULL, 0)) ;
#endif // USE_PTHREAD
break ;
case 'd' :
SET_AGGREGATION_IP(optarg) ;
break ;
case 'D' :
#ifdef USE_PTHREAD
SET_AUTOCALIBRATION_IP(optarg) ;
#endif // USE_PTHREAD
break ;
case 'f' : // Config file
@ -462,12 +454,20 @@ int parse_main_options(int argc, char **argv)
SET_AUTOCALIBRATION_HELLO_DELAY(strtol(optarg, NULL, 0)) ;
#endif // USE_PTHREAD
break ;
case 'k' :
case 'i' :
SET_AGGREGATION_IP(optarg) ;
break ;
case 'I' :
#ifdef USE_PTHREAD
SET_AUTOCALIBRATION_IP(optarg) ;
#endif // USE_PTHREAD
break ;
case 'K' :
#ifdef USE_PTHREAD
SET_KEEP_MONITOR() ;
#else // USE_PTHREAD
fprintf(stderr, "Warning! The program was compiled without"
" support of POSIX threads, so -k (monitor mode"
" support of POSIX threads, so -K (monitor mode"
" keeping-up) is not available and will be ignored."
"\n") ;
#endif // USE_PTHREAD
@ -1434,13 +1434,24 @@ void sigterm_handler(int num)
void print_usage()
{
printf("Usage :\n"
"\t%s [-f config_file] [-m mode] [-d aggregation_ip]"
" [-l listening_port] [-p aggregation_port] -r rtap_iface"
" [-w wifi_iface] [-k] [-v[v[v[v]]] | -q] [-A]"
" [-D autocalibration_ip]"
" [-P autocalibration_request_port ] [-a autocalibration_port]"
" [-H autocalibration_hello_delay] [-t autocalibration_delay]"
" [-n autocalibration_nb_packets] [direction x y z]\n"
"\t%s"
" [-f config_file]"
" [-m mode]"
" [-i aggregation_ip]"
" [-l listening_port]"
" [-p aggregation_port]"
" -r rtap_iface"
" [-w wifi_iface]"
" [-K]"
" [-v[v[v[v]]] | -q]"
" [-A]"
" [-I autocalibration_ip]"
" [-P autocalibration_request_port]"
" [-a autocalibration_port]"
" [-H autocalibration_hello_delay]"
" [-t autocalibration_delay]"
" [-n autocalibration_nb_packets]"
" [direction x y z]\n"
"\t%s -h\n"
"\t%s -V\n"
@ -1456,7 +1467,7 @@ void print_usage()
" (default: a).\n"
"\t-l listening_port\tPort on which explicit positioning"
" requests are sent by mobiles (default: %d).\n"
"\t-d aggregation_ip\tIP address of the aggregation server"
"\t-i aggregation_ip\tIP address of the aggregation server"
" (default: 127.0.0.1)\n"
"\t-p aggregation_port\tRequests are transmitted to the"
" aggregation server on this port (default: %d).\n"
@ -1468,7 +1479,7 @@ void print_usage()
"(These options are available only if the program was compiled"
" with support of POSIX threads.)\n"
"\t-A\t\t\tEnable autocalibration (default: disabled).\n"
"\t-D autocalib_ip\t\tDestination IP of the autocalibration"
"\t-I autocalib_ip\t\tDestination IP of the autocalibration"
"requests (default: aggregation_ip).\n"
"\t-P autocalib_req_port\tPort on which autocalibration"
" positioning requests are sent (default: %d).\n"
@ -1485,7 +1496,7 @@ void print_usage()
" (direction is an integer; x, y, z are floats).\n"
"Other options:\n"
"\t-k\tKeep the monitor mode up on wifi_iface. Use it with buggy"
"\t-K\tKeep the monitor mode up on wifi_iface. Use it with buggy"
" drivers that disable monitor mode periodically. Available"
" only if the program was compiled with support of POSIX"
" threads.\n"

View File

@ -116,17 +116,17 @@ void UserInterface::fill_data_input_options()
("data-input.mobile-csv-file", po::value<string>(),
"CSV file to use for mobiles input (when"
" data-input.mobile-medium = CSV).")
("data-input.topology-medium,T", po::value< vector<string> >()
("data-input.topology-medium", po::value< vector<string> >()
->composing(),
"Medium from which topology (buildings, areas and waypoints) is"
" read. You can specify this option more than once. Allowed: CSV.")
("data-input.areas-csv-file,A", po::value<string>(),
("data-input.areas-csv-file", po::value<string>(),
"CSV file to use for topology input (when"
" data-input.topology-medium = CSV).")
("data-input.waypoints-csv-file,W", po::value<string>(),
("data-input.waypoints-csv-file", po::value<string>(),
"CSV file to use for waypoints input (when"
" data-input.topology-medium = CSV).")
("data-input.reference-points-medium,R", po::value< vector<string> >()
("data-input.reference-points-medium", po::value< vector<string> >()
->composing(),
"Medium from which reference points are read. You can specify this"
" option more than once. Allowed: CSV.")
@ -146,9 +146,9 @@ void UserInterface::fill_input_options()
options.add_options()
("input.medium,I", po::value<string>(),
"Medium from which requests are read. Allowed: CSV, UDP.")
("input.csv-file,C", po::value<string>(),
("input.csv-file", po::value<string>(),
"CSV file to use for input (when input.medium = CSV).")
("input.udp-port,p", po::value<int>()
("input.udp-port", po::value<int>()
->default_value(OWL_DEFAULT_AGGREGATION_PORT),
"Port on which the UDP socket listens (when input.medium = UDP).")
;