2 * Copyright © 2023 Pierre Le Marre <dev@wismill.eu>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
31 #include "messages-codes.h"
34 static xkb_message_code_t
35 parse_message_code(char *raw_code) {
36 xkb_message_code_t code;
37 code = atoi(raw_code);
38 if (!code && strstr(raw_code, "XKB-")) {
39 return atoi(&(raw_code[4]));
48 printf("Usage: %s MESSAGE_CODES\n"
50 "Check whether the given message codes are supported.\n",
53 const struct xkb_message_entry *xkb_messages;
54 size_t count = xkb_message_get_all(&xkb_messages);
56 printf("\nCurrent supported messages:\n");
57 for (size_t idx = 0; idx < count; idx++) {
58 printf("- XKB-%03u: %s\n", xkb_messages[idx].code, xkb_messages[idx].label);
62 #define XKB_CHECK_MSG_ERROR_PREFIX "xkb-check-messages: ERROR: "
63 #define MALFORMED_MESSAGE (1 << 2)
64 #define UNSUPPORTED_MESSAGE (1 << 3)
66 int main(int argc, char **argv) {
69 return EXIT_INVALID_USAGE;
73 xkb_message_code_t code;
74 const struct xkb_message_entry* entry;
75 for (int k=1; k < argc; k++) {
76 code = parse_message_code(argv[k]);
79 XKB_CHECK_MSG_ERROR_PREFIX "Malformed message code: %s\n",
81 rc |= MALFORMED_MESSAGE;
84 entry = xkb_message_get(code);
87 XKB_CHECK_MSG_ERROR_PREFIX "Unsupported message code: %s\n",
89 rc |= UNSUPPORTED_MESSAGE;