From 923c3245ace71ea0e26a0b12746a699fa499f759 Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Sat, 28 Nov 2015 16:35:44 +0200 Subject: [PATCH] Fix option parsing Using 'flag' results in duplicate code paths for short and long options. This broke the -q short option in swaymsg, because there was: {"quiet", no_argument, &quiet, 'q'} Which will set quiet to 'q' and return 0, not 'q'. --- sway/main.c | 8 +++----- swaygrab/main.c | 6 ++---- swaymsg/main.c | 5 +++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/sway/main.c b/sway/main.c index 473a0990..1261a7ce 100644 --- a/sway/main.c +++ b/sway/main.c @@ -57,10 +57,10 @@ int main(int argc, char **argv) { static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"config", required_argument, NULL, 'c'}, - {"validate", no_argument, &validate, 1}, - {"debug", no_argument, &debug, 1}, + {"validate", no_argument, NULL, 'C'}, + {"debug", no_argument, NULL, 'd'}, {"version", no_argument, NULL, 'v'}, - {"verbose", no_argument, &verbose, 1}, + {"verbose", no_argument, NULL, 'V'}, {"get-socketpath", no_argument, NULL, 'p'}, {0, 0, 0, 0} }; @@ -87,8 +87,6 @@ int main(int argc, char **argv) { break; } switch (c) { - case 0: // Flag - break; case 'h': // help fprintf(stdout, "%s", usage); exit(EXIT_SUCCESS); diff --git a/swaygrab/main.c b/swaygrab/main.c index ae17155f..681a6da4 100644 --- a/swaygrab/main.c +++ b/swaygrab/main.c @@ -128,10 +128,10 @@ int main(int argc, char **argv) { static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, - {"capture", no_argument, &capture, 'c'}, + {"capture", no_argument, NULL, 'c'}, {"version", no_argument, NULL, 'v'}, {"socket", required_argument, NULL, 's'}, - {"raw", no_argument, &raw, 'r'}, + {"raw", no_argument, NULL, 'r'}, {"rate", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; @@ -154,8 +154,6 @@ int main(int argc, char **argv) { break; } switch (c) { - case 0: // Flag - break; case 's': // Socket socket_path = strdup(optarg); break; diff --git a/swaymsg/main.c b/swaymsg/main.c index 8f91dc55..f8c9e14c 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -24,7 +24,7 @@ int main(int argc, char **argv) { static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, - {"quiet", no_argument, &quiet, 'q'}, + {"quiet", no_argument, NULL, 'q'}, {"version", no_argument, NULL, 'v'}, {"socket", required_argument, NULL, 's'}, {"type", required_argument, NULL, 't'}, @@ -48,7 +48,8 @@ int main(int argc, char **argv) { break; } switch (c) { - case 0: // Flag + case 'q': // Quiet + quiet = 1; break; case 's': // Socket socket_path = strdup(optarg);