3 * @brief Code generator for X11 key definitions (X11/keysymdef.h)
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 *****************************************************************************/
39 static int cmpkey (const void *va
, const void *vb
)
41 const struct keysym
*ka
= va
, *kb
= vb
;
43 #if (INT_MAX < 0x7fffffff)
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
)
54 const struct keysym
*const *psym
= node
, *sym
= *psym
;
57 if (sym
->xsym
<= 0xff) /* Latin-1 */
59 if (sym
->xsym
>= 0x1000100 && sym
->xsym
<= 0x110ffff) /* Unicode */
62 printf ("/* XK_%-20s: %s*/\n", sym
->xname
, sym
->uname
);
63 printf ("{ 0x%08"PRIx32
", 0x%04"PRIx32
" },\n", sym
->xsym
, sym
->usym
);
68 static int parse (FILE *in
)
75 while ((len
= getline (&line
, &buflen
, in
)) != -1)
77 struct keysym
*sym
= malloc (sizeof (*sym
));
81 int val
= sscanf (line
,
82 "#define XK_%31s %"SCNi32
" /*%*cU+%"SCNx32
" %63[^*]",
83 sym
->xname
, &sym
->xsym
, &sym
->usym
, sym
->uname
);
92 struct keysym
**psym
= tsearch (sym
, &root
, cmpkey
);
96 free (sym
); /* Duplicate entry */
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
);
107 perror ("Read error");
116 return -parse (stdin
);