[vlc-devel] commit: Code generator for the previous commit ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sun Jan 3 12:15:48 CET 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jan 3 13:14:54 2010 +0200| [8d55c1fbc769319e7b106518bfe2e83e9e17b0af] | committer: Rémi Denis-Courmont
Code generator for the previous commit
This is not used automatically as I don't know how to tell automake to
build code for the build architecture instead of the host one.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8d55c1fbc769319e7b106518bfe2e83e9e17b0af
---
modules/video_output/xcb/keysym.c | 117 +++++++++++++++++++++++++++++++++++++
1 files changed, 117 insertions(+), 0 deletions(-)
diff --git a/modules/video_output/xcb/keysym.c b/modules/video_output/xcb/keysym.c
new file mode 100644
index 0000000..7988b45
--- /dev/null
+++ b/modules/video_output/xcb/keysym.c
@@ -0,0 +1,117 @@
+/*
+ * @file keysym.c
+ * @brief Code generator for X11 key definitions (X11/keysymdef.h)
+ */
+/*****************************************************************************
+ * Copyright © 2009 Rémi Denis-Courmont
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ ****************************************************************************/
+
+#define _GNU_SOURCE 1
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <search.h>
+#include <assert.h>
+
+struct keysym
+{
+ char xname[32];
+ char uname[64];
+ int32_t xsym;
+ int32_t usym;
+};
+
+static int cmpkey (const void *va, const void *vb)
+{
+ const struct keysym *ka = va, *kb = vb;
+
+#if (INT_MAX < 0x7fffffff)
+# error Oups!
+#endif
+ return ka->xsym - kb->xsym;
+}
+
+static void printkey (const void *node, const VISIT which, const int depth)
+{
+ if (which != postorder)
+ return;
+
+ const struct keysym *const *psym = node, *sym = *psym;
+
+#if 1
+ if (sym->xsym <= 0xff) /* Latin-1 */
+ return;
+ if (sym->xsym >= 0x1000100 && sym->xsym <= 0x110ffff) /* Unicode */
+ return;
+#endif
+ printf ("/* XK_%-20s: %s*/\n", sym->xname, sym->uname);
+ printf ("{ 0x%08"PRIx32", 0x%04"PRIx32" },\n", sym->xsym, sym->usym);
+
+ (void) depth;
+}
+
+static int parse (FILE *in)
+{
+ void *root = NULL;
+ char *line = NULL;
+ size_t buflen = 0;
+ ssize_t len;
+
+ while ((len = getline (&line, &buflen, in)) != -1)
+ {
+ struct keysym *sym = malloc (sizeof (*sym));
+ if (sym == NULL)
+ abort ();
+
+ int val = sscanf (line,
+ "#define XK_%31s %"SCNi32" /*%*cU+%"SCNx32" %63[^*]",
+ sym->xname, &sym->xsym, &sym->usym, sym->uname);
+ if (val < 3)
+ {
+ free (sym);
+ continue;
+ }
+ if (val < 4)
+ sym->uname[0] = '\0';
+
+ struct keysym **psym = tsearch (sym, &root, cmpkey);
+ if (psym == NULL)
+ abort ();
+ if (*psym != sym)
+ free (sym); /* Duplicate entry */
+ }
+ free (line);
+
+ puts ("/* This file is generated automatically. Do not edit! */");
+ puts ("/* Entries are sorted from the smallest to the largest XK */");
+ twalk (root, printkey);
+ tdestroy (root, free);
+
+ if (ferror (in))
+ {
+ perror ("Read error");
+ return 1;
+ }
+
+ return 0;
+}
+
+int main (void)
+{
+ return -parse (stdin);
+}
More information about the vlc-devel
mailing list