From 3ba33321de0790d60dc473acee093de5a3650480 Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Sat, 28 Nov 2015 15:47:44 +0200 Subject: Use macros for exit values --- swaygrab/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'swaygrab') diff --git a/swaygrab/main.c b/swaygrab/main.c index 63cf223f..e60d154f 100644 --- a/swaygrab/main.c +++ b/swaygrab/main.c @@ -10,7 +10,7 @@ #include "ipc-client.h" void sway_terminate(void) { - exit(1); + exit(EXIT_FAILURE); } int numlen(int n) { @@ -163,7 +163,7 @@ int main(int argc, char **argv) { #else fprintf(stdout, "version not detected\n"); #endif - exit(0); + exit(EXIT_SUCCESS); break; } } -- cgit v1.2.3 From b235ccd212920db7e444716b7a36fcb4a36a3644 Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Sat, 28 Nov 2015 16:09:14 +0200 Subject: swaygrab: Print usage and exit on unknown options --- swaygrab/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'swaygrab') diff --git a/swaygrab/main.c b/swaygrab/main.c index e60d154f..90d118e2 100644 --- a/swaygrab/main.c +++ b/swaygrab/main.c @@ -135,6 +135,15 @@ int main(int argc, char **argv) { {0, 0, 0, 0} }; + const char *usage = + "Usage: swaygrab [options] [file]\n" + "\n" + " -c, --capture Capture video.\n" + " -v, --version Show the version number and quit.\n" + " -s, --socket Use the specified socket.\n" + " -R, --rate Specify framerate (default: 30)\n" + " -r, --raw Write raw rgba data to stdout.\n"; + int c; while (1) { int option_index = 0; @@ -165,6 +174,9 @@ int main(int argc, char **argv) { #endif exit(EXIT_SUCCESS); break; + default: + fprintf(stderr, "%s", usage); + exit(EXIT_FAILURE); } } -- cgit v1.2.3 From 12c8cf5bf6dd0d0e77ff78260b603cdaa1731a65 Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Sat, 28 Nov 2015 16:18:54 +0200 Subject: swaygrab: Add --help option that prints usage --- swaygrab/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'swaygrab') diff --git a/swaygrab/main.c b/swaygrab/main.c index 90d118e2..ae17155f 100644 --- a/swaygrab/main.c +++ b/swaygrab/main.c @@ -127,6 +127,7 @@ int main(int argc, char **argv) { init_log(L_INFO); static struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, {"capture", no_argument, &capture, 'c'}, {"version", no_argument, NULL, 'v'}, {"socket", required_argument, NULL, 's'}, @@ -138,6 +139,7 @@ int main(int argc, char **argv) { const char *usage = "Usage: swaygrab [options] [file]\n" "\n" + " -h, --help Show help message and quit.\n" " -c, --capture Capture video.\n" " -v, --version Show the version number and quit.\n" " -s, --socket Use the specified socket.\n" @@ -147,7 +149,7 @@ int main(int argc, char **argv) { int c; while (1) { int option_index = 0; - c = getopt_long(argc, argv, "cvs:r", long_options, &option_index); + c = getopt_long(argc, argv, "hcvs:r", long_options, &option_index); if (c == -1) { break; } -- cgit v1.2.3 From 923c3245ace71ea0e26a0b12746a699fa499f759 Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Sat, 28 Nov 2015 16:35:44 +0200 Subject: 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'. --- swaygrab/main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'swaygrab') 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; -- cgit v1.2.3