aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2016-08-02 13:49:11 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2016-08-02 13:49:11 +0200
commit148195537704906dd9a50cea8442a4df0cd8b16f (patch)
treed97a65a6de609a17999cafc9feaff0d40bc637eb
parent7e3608fe8b0a8e42fa303375cab0d60ede95c81e (diff)
downloadapplause2-148195537704906dd9a50cea8442a4df0cd8b16f.tar.gz
options are now passed in POSIX style (ie. -o and -b)
command line help is provided using -h or when specifying an unknown option
-rw-r--r--applause.c32
1 files 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.