Removed build dependency on kbproto.
[platform/upstream/libxkbcommon.git] / tools / messages.c.jinja
1 /*
2  * NOTE: This file has been generated automatically by “{{script}}”.
3  *       Do not edit manually!
4  *
5  */
6
7 /*
8  * Copyright © 2023 Pierre Le Marre <dev@wismill.eu>
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice (including the next
18  * paragraph) shall be included in all copies or substantial portions of the
19  * Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */
29
30 #include "config.h"
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include "messages-codes.h"
37 #include "messages.h"
38 #include "utils.h"
39
40 static const struct xkb_message_entry xkb_messages[] = {
41     {% for entry in entries %}
42     { {#--#}{{ entry.message_code_constant}}, "{{entry.message_name}}"}{{ "" if loop.last else "," }}
43     {% endfor %}
44 };
45
46 int
47 xkb_message_get_all(const struct xkb_message_entry **messages)
48 {
49     *messages = xkb_messages;
50     return ARRAY_SIZE(xkb_messages);
51 }
52
53 const struct xkb_message_entry*
54 xkb_message_get(xkb_message_code_t code)
55 {
56     {# Binary search seems overkill for now #}
57     if (code < _XKB_LOG_MESSAGE_MIN_CODE || code > _XKB_LOG_MESSAGE_MAX_CODE)
58         return NULL;
59
60     for (size_t idx = 0; idx < ARRAY_SIZE(xkb_messages); idx++) {
61         if (xkb_messages[idx].code == code)
62             return &xkb_messages[idx];
63     }
64
65     /* no matching message code found */
66     return NULL;
67 }