qt: playlist: use item title if available
[vlc.git] / modules / video_output / xcb / keysym.c
blob65cd9a4e1ae2888a042f1f6aef083d3d72c56a36
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
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program 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 Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
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>
31 struct keysym
33 char xname[32];
34 char uname[64];
35 uint32_t xsym;
36 uint32_t usym;
39 static int cmpkey (const void *va, const void *vb)
41 const struct keysym *ka = va, *kb = vb;
43 if (ka->xsym > kb->xsym)
44 return +1;
45 if (ka->xsym < kb->xsym)
46 return -1;
47 return 0;
50 static void printkey (const void *node, const VISIT which, const int depth)
52 if (which != postorder && which != leaf)
53 return;
55 const struct keysym *const *psym = node, *sym = *psym;
57 #if 1
58 if (sym->xsym <= 0xff) /* Latin-1 */
59 return;
60 if (sym->xsym >= 0x1000100 && sym->xsym <= 0x110ffff) /* Unicode */
61 return;
62 #endif
63 printf ("/* XK_%-20s: %s*/\n", sym->xname, sym->uname);
64 printf ("{ 0x%08"PRIx32", 0x%04"PRIx32" },\n", sym->xsym, sym->usym);
66 (void) depth;
69 static int parse (FILE *in)
71 void *root = NULL;
72 char *line = NULL;
73 size_t buflen = 0;
74 ssize_t len;
76 while ((len = getline (&line, &buflen, in)) != -1)
78 struct keysym *sym = malloc (sizeof (*sym));
79 if (sym == NULL)
80 abort ();
82 int val = sscanf(line,
83 "#define XK_%31s 0x%"SCNx32" /*%*cU+%"SCNx32" %63[^*]",
84 sym->xname, &sym->xsym, &sym->usym, sym->uname);
85 if (val < 3)
87 free (sym);
88 continue;
90 if (val < 4)
91 sym->uname[0] = '\0';
93 void **psym = tsearch (sym, &root, cmpkey);
94 if (psym == NULL)
95 abort ();
96 if (*psym != sym)
97 free (sym); /* Duplicate entry */
99 free (line);
101 puts ("/* This file is generated automatically. Do not edit! */");
102 puts ("/* Entries are sorted from the smallest to the largest XK */");
103 twalk (root, printkey);
104 tdestroy (root, free);
106 if (ferror (in))
108 perror ("Read error");
109 return 1;
112 return 0;
115 int main (void)
117 return -parse (stdin);