Add encoder support for Dirac using the Schroedinger library.
[vlc/asuraparaju-public.git] / modules / video_output / xcb / keysym.c
blob3a285d2b7512d63ebe2a8c7c6042d496b99393a1
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 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.
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.
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 ****************************************************************************/
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 int32_t xsym;
36 int32_t usym;
39 static int cmpkey (const void *va, const void *vb)
41 const struct keysym *ka = va, *kb = vb;
43 #if (INT_MAX < 0x7fffffff)
44 # error Oups!
45 #endif
46 return ka->xsym - kb->xsym;
49 static void printkey (const void *node, const VISIT which, const int depth)
51 if (which != postorder && which != leaf)
52 return;
54 const struct keysym *const *psym = node, *sym = *psym;
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);
65 (void) depth;
68 static int parse (FILE *in)
70 void *root = NULL;
71 char *line = NULL;
72 size_t buflen = 0;
73 ssize_t len;
75 while ((len = getline (&line, &buflen, in)) != -1)
77 struct keysym *sym = malloc (sizeof (*sym));
78 if (sym == NULL)
79 abort ();
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)
86 free (sym);
87 continue;
89 if (val < 4)
90 sym->uname[0] = '\0';
92 struct keysym **psym = tsearch (sym, &root, cmpkey);
93 if (psym == NULL)
94 abort ();
95 if (*psym != sym)
96 free (sym); /* Duplicate entry */
98 free (line);
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);
105 if (ferror (in))
107 perror ("Read error");
108 return 1;
111 return 0;
114 int main (void)
116 return -parse (stdin);