From 0b67cf95cc19dc74b1430dcc81531a329b302156 Mon Sep 17 00:00:00 2001 From: Patrick Pan Date: Wed, 27 May 2020 19:10:04 -0400 Subject: [PATCH] Allow multiple -k and -t arguments --- src/skhd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/skhd.c b/src/skhd.c index 3525269..9ed1abd 100644 --- a/src/skhd.c +++ b/src/skhd.c @@ -267,6 +267,7 @@ internal bool parse_arguments(int argc, char **argv) { int option; + char synthesize_opt = 0; const char *short_option = "VPvc:k:t:rho"; struct option long_option[] = { { "verbose", no_argument, NULL, 'V' }, @@ -282,6 +283,9 @@ parse_arguments(int argc, char **argv) }; while ((option = getopt_long(argc, argv, short_option, long_option, NULL)) != -1) { + if (synthesize_opt != 0 && option != synthesize_opt) { + error("skhd: cannot pass arguments after -%c", synthesize_opt); + } switch (option) { case 'V': { verbose = true; @@ -301,11 +305,11 @@ parse_arguments(int argc, char **argv) } break; case 'k': { synthesize_key(optarg); - return true; + synthesize_opt = option; } break; case 't': { synthesize_text(optarg); - return true; + synthesize_opt = option; } break; case 'r': { pid_t pid = read_pid_file(); @@ -321,6 +325,10 @@ parse_arguments(int argc, char **argv) } } + if (synthesize_opt != 0) { + return true; + } + return false; }