tools: consistently return 2 on invalid usage Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
diff --git a/tools/compile-keymap.c b/tools/compile-keymap.c
index e090de1..9458f6a 100644
--- a/tools/compile-keymap.c
+++ b/tools/compile-keymap.c
@@ -170,7 +170,7 @@ parse_options(int argc, char **argv, struct xkb_rule_names *names)
break;
default:
usage(argv);
- exit(1);
+ exit(EXIT_INVALID_USAGE);
}
}
@@ -301,11 +301,11 @@ main(int argc, char **argv)
if (argc <= 1) {
usage(argv);
- return 1;
+ return EXIT_INVALID_USAGE;
}
if (!parse_options(argc, argv, &names))
- return 1;
+ return EXIT_INVALID_USAGE;
ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES);
assert(ctx);
diff --git a/tools/how-to-type.c b/tools/how-to-type.c
index 6fef401..441db38 100644
--- a/tools/how-to-type.c
+++ b/tools/how-to-type.c
@@ -50,7 +50,7 @@ main(int argc, char *argv[])
const char *layout_ = NULL;
const char *variant = NULL;
const char *options = NULL;
- int exit = EXIT_FAILURE;
+ int err = EXIT_FAILURE;
struct xkb_context *ctx = NULL;
char *endp;
long val;
@@ -81,16 +81,19 @@ main(int argc, char *argv[])
break;
default:
usage(argv[0]);
+ exit(EXIT_INVALID_USAGE);
}
}
if (argc - optind != 1) {
usage(argv[0]);
+ exit(EXIT_INVALID_USAGE);
}
errno = 0;
val = strtol(argv[optind], &endp, 0);
if (errno != 0 || endp == argv[optind] || val < 0 || val > 0x10FFFF) {
usage(argv[0]);
+ exit(EXIT_INVALID_USAGE);
}
codepoint = (uint32_t) val;
@@ -188,9 +191,9 @@ main(int argc, char *argv[])
}
}
- exit = EXIT_SUCCESS;
+ err = EXIT_SUCCESS;
err:
xkb_keymap_unref(keymap);
xkb_context_unref(ctx);
- return exit;
+ return err;
}
diff --git a/tools/interactive-evdev.c b/tools/interactive-evdev.c
index e8afb5e..a49b932 100644
--- a/tools/interactive-evdev.c
+++ b/tools/interactive-evdev.c
@@ -413,7 +413,7 @@ main(int argc, char *argv[])
evdev_offset = strtol(optarg, NULL, 10);
if (errno) {
fprintf(stderr, "error: -n option expects a number\n");
- exit(EXIT_FAILURE);
+ exit(EXIT_INVALID_USAGE);
}
break;
case 'c':
@@ -435,7 +435,7 @@ main(int argc, char *argv[])
" -c (to report changes to the state)\n"
" -d (to enable compose)\n"
" -g (to use GTK consumed mode)\n");
- exit(2);
+ exit(EXIT_INVALID_USAGE);
}
}
diff --git a/tools/interactive-wayland.c b/tools/interactive-wayland.c
index 8cc41de..3ac7ad7 100644
--- a/tools/interactive-wayland.c
+++ b/tools/interactive-wayland.c
@@ -662,6 +662,14 @@ main(int argc, char *argv[])
struct interactive_dpy inter;
struct wl_registry *registry;
+ if (argc != 1) {
+ ret = strcmp(argv[1], "--help");
+ fprintf(ret ? stderr : stdout, "Usage: %s [--help]\n", argv[0]);
+ if (ret)
+ fprintf(stderr, "unrecognized option: %s\n", argv[1]);
+ return ret ? EXIT_INVALID_USAGE : EXIT_SUCCESS;
+ }
+
setlocale(LC_ALL, "");
memset(&inter, 0, sizeof(inter));
diff --git a/tools/interactive-x11.c b/tools/interactive-x11.c
index d98433e..c7ca9aa 100644
--- a/tools/interactive-x11.c
+++ b/tools/interactive-x11.c
@@ -26,6 +26,7 @@
#include <locale.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
#include <xcb/xkb.h>
@@ -336,6 +337,14 @@ main(int argc, char *argv[])
struct xkb_context *ctx;
struct keyboard core_kbd;
+ if (argc != 1) {
+ ret = strcmp(argv[1], "--help");
+ fprintf(ret ? stderr : stdout, "Usage: %s [--help]\n", argv[0]);
+ if (ret)
+ fprintf(stderr, "unrecognized option: %s\n", argv[1]);
+ return ret ? EXIT_INVALID_USAGE : EXIT_SUCCESS;
+ }
+
setlocale(LC_ALL, "");
conn = xcb_connect(NULL, NULL);
diff --git a/tools/registry-list.c b/tools/registry-list.c
index e51c41f..0dc71d1 100644
--- a/tools/registry-list.c
+++ b/tools/registry-list.c
@@ -30,9 +30,9 @@
#include "xkbcommon/xkbregistry.h"
static void
-usage(const char *progname)
+usage(const char *progname, FILE *fp)
{
- fprintf(stderr,
+ fprintf(fp,
"Usage: %s [OPTIONS] [/path/to/xkb_base_directory [/path2]...]\n"
"\n"
"Options:\n"
@@ -77,9 +77,11 @@ main(int argc, char **argv)
switch (c) {
case 'h':
+ usage(argv[0], stdout);
+ return 0;
case '?':
- usage(argv[0]);
- return 1;
+ usage(argv[0], stderr);
+ return EXIT_INVALID_USAGE;
case 'd':
load_defaults = false;
break;