]> git.sesse.net Git - vlc/blob - modules/video_output/xcb/keysym.c
Use var_InheritString for --decklink-video-connection.
[vlc] / modules / video_output / xcb / keysym.c
1 /*
2  * @file keysym.c
3  * @brief Code generator for X11 key definitions (X11/keysymdef.h)
4  */
5 /*****************************************************************************
6  * Copyright © 2009 Rémi Denis-Courmont
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  ****************************************************************************/
22
23 #define _GNU_SOURCE 1
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <inttypes.h>
27 #include <limits.h>
28 #include <search.h>
29 #include <assert.h>
30
31 struct keysym
32 {
33     char xname[32];
34     char uname[64];
35     int32_t xsym;
36     int32_t usym;
37 };
38
39 static int cmpkey (const void *va, const void *vb)
40 {
41     const struct keysym *ka = va, *kb = vb;
42
43 #if (INT_MAX < 0x7fffffff)
44 # error Oups!
45 #endif
46     return ka->xsym - kb->xsym;
47 }
48
49 static void printkey (const void *node, const VISIT which, const int depth)
50 {
51     if (which != postorder && which != leaf)
52         return;
53
54     const struct keysym *const *psym = node, *sym = *psym;
55
56 #if 1
57     if (sym->xsym <= 0xff) /* Latin-1 */
58         return;
59     if (sym->xsym >= 0x1000100 && sym->xsym <= 0x110ffff) /* Unicode */
60         return;
61 #endif
62     printf ("/* XK_%-20s: %s*/\n", sym->xname, sym->uname);
63     printf ("{ 0x%08"PRIx32", 0x%04"PRIx32" },\n", sym->xsym, sym->usym);
64         
65     (void) depth;
66 }
67
68 static int parse (FILE *in)
69 {
70     void *root = NULL;
71     char *line = NULL;
72     size_t buflen = 0;
73     ssize_t len;
74
75     while ((len = getline (&line, &buflen, in)) != -1)
76     {
77         struct keysym *sym = malloc (sizeof (*sym));
78         if (sym == NULL)
79             abort ();
80
81         int val = sscanf (line,
82                           "#define XK_%31s %"SCNi32" /*%*cU+%"SCNx32" %63[^*]",
83                           sym->xname, &sym->xsym, &sym->usym, sym->uname);
84         if (val < 3)
85         {
86             free (sym);
87             continue;
88         }
89         if (val < 4)
90             sym->uname[0] = '\0';
91
92         struct keysym **psym = tsearch (sym, &root, cmpkey);
93         if (psym == NULL)
94             abort ();
95         if (*psym != sym)
96             free (sym); /* Duplicate entry */
97     }
98     free (line);
99
100     puts ("/* This file is generated automatically. Do not edit! */");
101     puts ("/* Entries are sorted from the smallest to the largest XK */");
102     twalk (root, printkey);
103     tdestroy (root, free);
104
105     if (ferror (in))
106     {
107         perror ("Read error");
108         return 1;
109     }
110
111     return 0;
112 }
113
114 int main (void)
115 {
116     return -parse (stdin);
117 }