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