Move include path from X11/extensions/ to xkbcommon/
[platform/upstream/libxkbcommon.git] / test / xkey.c
1 #include "xkbmisc.h"
2 #include "xkbcommon/xkbcommon.h"
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6
7 static void print_keysym(const char *s)
8 {
9     KeySym ks = xkb_string_to_keysym(s);
10     if (ks == NoSymbol)
11         printf("NoSymbol\n");
12     else
13         printf("0x%lX\n", ks);
14 }
15
16 static void print_string(KeySym ks)
17 {
18     char s[16];
19
20     xkb_keysym_to_string(ks, s, sizeof s);
21     printf("%s\n", s);
22 }
23
24 int main(int argc, char *argv[])
25 {
26     int mode;
27     KeySym sym;
28
29     if (argc < 3) {
30         fprintf(stderr, "error: not enough arguments\n");
31         exit(EXIT_FAILURE);
32     }
33
34     if (strcmp(argv[1], "-k") == 0) {
35         mode = 0;
36         sym = strtoul(argv[2], NULL, 16);
37     }
38     else if (strcmp(argv[1], "-s") == 0)
39         mode = 1;
40     else {
41         fprintf(stderr, "error: unrecognized argument \"%s\"\n", argv[1]);
42         exit(EXIT_FAILURE);
43     }
44
45     if (mode == 0)
46         print_string(sym);
47     else
48         print_keysym(argv[2]);
49
50     return 0;
51 }