From 148195537704906dd9a50cea8442a4df0cd8b16f Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 2 Aug 2016 13:49:11 +0200 Subject: options are now passed in POSIX style (ie. -o and -b) command line help is provided using -h or when specifying an unknown option --- applause.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/applause.c b/applause.c index da412a6..3ccc468 100644 --- a/applause.c +++ b/applause.c @@ -957,9 +957,20 @@ static const NativeMethod native_methods[] = { {NULL, NULL, NULL} }; +static void +usage(const char *program) +{ + printf("%s [-h] [-o OUTPUT] [-b SIZE]\n" + "\tOUTPUT\tNumber of output ports to reserve (default: %d)\n" + "\tSIZE\tMinimum size of the output buffer in milliseconds (default: %dms)\n", + program, + DEFAULT_NUMBER_OF_OUTPUT_PORTS, DEFAULT_BUFFER_SIZE); +} + int main(int argc, char **argv) { + int opt; int buffer_size = DEFAULT_BUFFER_SIZE; struct sigaction signal_action; @@ -967,13 +978,20 @@ main(int argc, char **argv) pthread_t command_server_thread; - /* - * FIXME: Support --help - */ - if (argc > 1) - output_ports_count = atoi(argv[1]); - if (argc > 2) - buffer_size = atoi(argv[2]); + while ((opt = getopt(argc, argv, "ho:b:")) >= 0) { + switch (opt) { + case '?': + case 'h': /* get help */ + usage(argv[0]); + return 0; + case 'o': /* output ports */ + output_ports_count = atoi(optarg); + break; + case 'b': /* buffer size */ + buffer_size = atoi(optarg); + break; + } + } /* * Register sigint_handler() as the SIGINT handler. -- cgit v1.2.3