tools: switch how-to-type to getopt_long This provides consistency with the other tools that now all take long options. Plus, it's more obvious to have the arguments spelled out. 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
diff --git a/tools/how-to-type.c b/tools/how-to-type.c
index 441db38..903a3ed 100644
--- a/tools/how-to-type.c
+++ b/tools/how-to-type.c
@@ -23,6 +23,7 @@
#include "config.h"
+#include <getopt.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
@@ -32,19 +33,17 @@
#define ARRAY_SIZE(arr) ((sizeof(arr) / sizeof(*(arr))))
static void
-usage(const char *argv0)
+usage(const char *argv0, FILE *fp)
{
- fprintf(stderr, "Usage: %s [-r <rules>] [-m <model>] "
- "[-l <layout>] [-v <variant>] [-o <options>] <unicode codepoint>\n",
- argv0);
- fprintf(stderr, "Pipe into `column -ts $'\\t'` for nicely aligned output.\n");
- exit(2);
+ fprintf(fp, "Usage: %s [--rules <rules>] [--model <model>] "
+ "[--layout <layout>] [--variant <variant>] [--options <options>]"
+ " <unicode codepoint>\n", argv0);
+ fprintf(fp, "Pipe into `column -ts $'\\t'` for nicely aligned output.\n");
}
int
main(int argc, char *argv[])
{
- int opt;
const char *rules = NULL;
const char *model = NULL;
const char *layout_ = NULL;
@@ -61,38 +60,64 @@ main(int argc, char *argv[])
struct xkb_keymap *keymap = NULL;
xkb_keycode_t min_keycode, max_keycode;
xkb_mod_index_t num_mods;
+ enum options {
+ OPT_RULES,
+ OPT_MODEL,
+ OPT_LAYOUT,
+ OPT_VARIANT,
+ OPT_OPTIONS,
+ };
+ static struct option opts[] = {
+ {"help", no_argument, 0, 'h'},
+ {"rules", required_argument, 0, OPT_RULES},
+ {"model", required_argument, 0, OPT_MODEL},
+ {"layout", required_argument, 0, OPT_LAYOUT},
+ {"variant", required_argument, 0, OPT_VARIANT},
+ {"options", required_argument, 0, OPT_OPTIONS},
+ {0, 0, 0, 0},
+ };
+
+ while (1) {
+ int opt;
+ int option_index = 0;
+
+ opt = getopt_long(argc, argv, "h", opts, &option_index);
+ if (opt == -1)
+ break;
- while ((opt = getopt(argc, argv, "r:m:l:v:o:")) != -1) {
switch (opt) {
- case 'r':
+ case OPT_RULES:
rules = optarg;
break;
- case 'm':
+ case OPT_MODEL:
model = optarg;
break;
- case 'l':
+ case OPT_LAYOUT:
layout_ = optarg;
break;
- case 'v':
+ case OPT_VARIANT:
variant = optarg;
break;
- case 'o':
+ case OPT_OPTIONS:
options = optarg;
break;
+ case 'h':
+ usage(argv[0], stdout);
+ exit(EXIT_SUCCESS);
default:
- usage(argv[0]);
+ usage(argv[0], stderr);
exit(EXIT_INVALID_USAGE);
}
}
if (argc - optind != 1) {
- usage(argv[0]);
+ usage(argv[0], stderr);
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]);
+ usage(argv[0], stderr);
exit(EXIT_INVALID_USAGE);
}
codepoint = (uint32_t) val;
diff --git a/tools/xkbcli-how-to-type.1.ronn b/tools/xkbcli-how-to-type.1.ronn
index f89ca76..fc3faa4 100644
--- a/tools/xkbcli-how-to-type.1.ronn
+++ b/tools/xkbcli-how-to-type.1.ronn
@@ -13,19 +13,19 @@ Pipe into `column -ts $'\\t'` for nicely aligned output.
## OPTIONS
- * ` -r <rules>`:
+ * `--rules <rules>`:
The XKB ruleset
- * ` -m <model>`:
+ * `--model <model>`:
The XKB model
- * `-l <layout>`:
+ * `--layout <layout>`:
The XKB layout
- * `-v <variant>`:
+ * `--variant <variant>`:
The XKB layout variant
- * `-o <options>`:
+ * `--options <options>`:
The XKB options
## SEE ALSO