Make it possible to build libkeymap out-of-tree
[platform/upstream/kbd.git] / src / libkeymap / ksyms.c
1 #include <linux/keyboard.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include "ksyms.h"
6 #include "nls.h"
7
8 #include "keymap.h"
9
10 /* Keysyms whose KTYP is KT_LATIN or KT_LETTER and whose KVAL is 0..127. */
11
12 static const char *iso646_syms[] = {
13         "nul",
14         "Control_a",
15         "Control_b",
16         "Control_c",
17         "Control_d",
18         "Control_e",
19         "Control_f",
20         "Control_g",
21         "BackSpace",
22         "Tab",
23         "Linefeed",
24         "Control_k",
25         "Control_l",
26         "Control_m",
27         "Control_n",
28         "Control_o",
29         "Control_p",
30         "Control_q",
31         "Control_r",
32         "Control_s",
33         "Control_t",
34         "Control_u",
35         "Control_v",
36         "Control_w",
37         "Control_x",
38         "Control_y",
39         "Control_z",
40         "Escape",
41         "Control_backslash",
42         "Control_bracketright",
43         "Control_asciicircum",
44         "Control_underscore",
45         "space",
46         "exclam",
47         "quotedbl",
48         "numbersign",
49         "dollar",
50         "percent",
51         "ampersand",
52         "apostrophe",
53         "parenleft",
54         "parenright",
55         "asterisk",
56         "plus",
57         "comma",
58         "minus",
59         "period",
60         "slash",
61         "zero",
62         "one",
63         "two",
64         "three",
65         "four",
66         "five",
67         "six",
68         "seven",
69         "eight",
70         "nine",
71         "colon",
72         "semicolon",
73         "less",
74         "equal",
75         "greater",
76         "question",
77         "at",
78         "A",
79         "B",
80         "C",
81         "D",
82         "E",
83         "F",
84         "G",
85         "H",
86         "I",
87         "J",
88         "K",
89         "L",
90         "M",
91         "N",
92         "O",
93         "P",
94         "Q",
95         "R",
96         "S",
97         "T",
98         "U",
99         "V",
100         "W",
101         "X",
102         "Y",
103         "Z",
104         "bracketleft",
105         "backslash",
106         "bracketright",
107         "asciicircum",
108         "underscore",
109         "grave",
110         "a",
111         "b",
112         "c",
113         "d",
114         "e",
115         "f",
116         "g",
117         "h",
118         "i",
119         "j",
120         "k",
121         "l",
122         "m",
123         "n",
124         "o",
125         "p",
126         "q",
127         "r",
128         "s",
129         "t",
130         "u",
131         "v",
132         "w",
133         "x",
134         "y",
135         "z",
136         "braceleft",
137         "bar",
138         "braceright",
139         "asciitilde",
140         "Delete",
141
142         /* set_charset() fills in charset dependent strings here. */
143         /* start with the latin1 defaults */
144         "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
145         "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
146         "nobreakspace",
147         "exclamdown",
148         "cent",
149         "sterling",
150         "currency",
151         "yen",
152         "brokenbar",
153         "section",
154         "diaeresis",
155         "copyright",
156         "ordfeminine",
157         "guillemotleft",
158         "notsign",
159         "hyphen",
160         "registered",
161         "macron",
162         "degree",
163         "plusminus",
164         "twosuperior",
165         "threesuperior",
166         "acute",
167         "mu",
168         "paragraph",
169         "periodcentered",
170         "cedilla",
171         "onesuperior",
172         "masculine",
173         "guillemotright",
174         "onequarter",
175         "onehalf",
176         "threequarters",
177         "questiondown",
178         "Agrave",
179         "Aacute",
180         "Acircumflex",
181         "Atilde",
182         "Adiaeresis",
183         "Aring",
184         "AE",
185         "Ccedilla",
186         "Egrave",
187         "Eacute",
188         "Ecircumflex",
189         "Ediaeresis",
190         "Igrave",
191         "Iacute",
192         "Icircumflex",
193         "Idiaeresis",
194         "ETH",
195         "Ntilde",
196         "Ograve",
197         "Oacute",
198         "Ocircumflex",
199         "Otilde",
200         "Odiaeresis",
201         "multiply",
202         "Ooblique",
203         "Ugrave",
204         "Uacute",
205         "Ucircumflex",
206         "Udiaeresis",
207         "Yacute",
208         "THORN",
209         "ssharp",
210         "agrave",
211         "aacute",
212         "acircumflex",
213         "atilde",
214         "adiaeresis",
215         "aring",
216         "ae",
217         "ccedilla",
218         "egrave",
219         "eacute",
220         "ecircumflex",
221         "ediaeresis",
222         "igrave",
223         "iacute",
224         "icircumflex",
225         "idiaeresis",
226         "eth",
227         "ntilde",
228         "ograve",
229         "oacute",
230         "ocircumflex",
231         "otilde",
232         "odiaeresis",
233         "division",
234         "oslash",
235         "ugrave",
236         "uacute",
237         "ucircumflex",
238         "udiaeresis",
239         "yacute",
240         "thorn",
241         "ydiaeresis",
242 };
243
244 /* Keysyms whose KTYP is KT_LATIN or KT_LETTER and whose KVAL is 128..255,
245    and their Unicode equivalent. */
246
247 static sym latin1_syms[] = {
248         { 0x00a0, "nobreakspace" },
249         { 0x00a1, "exclamdown" },
250         { 0x00a2, "cent" },
251         { 0x00a3, "sterling" },
252         { 0x00a4, "currency" },
253         { 0x00a5, "yen" },
254         { 0x00a6, "brokenbar" },
255         { 0x00a7, "section" },
256         { 0x00a8, "diaeresis" },
257         { 0x00a9, "copyright" },
258         { 0x00aa, "ordfeminine" },
259         { 0x00ab, "guillemotleft" },
260         { 0x00ac, "notsign" },
261         { 0x00ad, "hyphen" },
262         { 0x00ae, "registered" },
263         { 0x00af, "macron" },
264         { 0x00b0, "degree" },
265         { 0x00b1, "plusminus" },
266         { 0x00b2, "twosuperior" },
267         { 0x00b3, "threesuperior" },
268         { 0x00b4, "acute" },
269         { 0x00b5, "mu" },
270         { 0x00b6, "paragraph" },
271         { 0x00b7, "periodcentered" },
272         { 0x00b8, "cedilla" },
273         { 0x00b9, "onesuperior" },
274         { 0x00ba, "masculine" },
275         { 0x00bb, "guillemotright" },
276         { 0x00bc, "onequarter" },
277         { 0x00bd, "onehalf" },
278         { 0x00be, "threequarters" },
279         { 0x00bf, "questiondown" },
280         { 0x00c0, "Agrave" },
281         { 0x00c1, "Aacute" },
282         { 0x00c2, "Acircumflex" },
283         { 0x00c3, "Atilde" },
284         { 0x00c4, "Adiaeresis" },
285         { 0x00c5, "Aring" },
286         { 0x00c6, "AE" },
287         { 0x00c7, "Ccedilla" },
288         { 0x00c8, "Egrave" },
289         { 0x00c9, "Eacute" },
290         { 0x00ca, "Ecircumflex" },
291         { 0x00cb, "Ediaeresis" },
292         { 0x00cc, "Igrave" },
293         { 0x00cd, "Iacute" },
294         { 0x00ce, "Icircumflex" },
295         { 0x00cf, "Idiaeresis" },
296         { 0x00d0, "ETH" },
297         { 0x00d1, "Ntilde" },
298         { 0x00d2, "Ograve" },
299         { 0x00d3, "Oacute" },
300         { 0x00d4, "Ocircumflex" },
301         { 0x00d5, "Otilde" },
302         { 0x00d6, "Odiaeresis" },
303         { 0x00d7, "multiply" },
304         { 0x00d8, "Ooblique" },
305         { 0x00d9, "Ugrave" },
306         { 0x00da, "Uacute" },
307         { 0x00db, "Ucircumflex" },
308         { 0x00dc, "Udiaeresis" },
309         { 0x00dd, "Yacute" },
310         { 0x00de, "THORN" },
311         { 0x00df, "ssharp" },
312         { 0x00e0, "agrave" },
313         { 0x00e1, "aacute" },
314         { 0x00e2, "acircumflex" },
315         { 0x00e3, "atilde" },
316         { 0x00e4, "adiaeresis" },
317         { 0x00e5, "aring" },
318         { 0x00e6, "ae" },
319         { 0x00e7, "ccedilla" },
320         { 0x00e8, "egrave" },
321         { 0x00e9, "eacute" },
322         { 0x00ea, "ecircumflex" },
323         { 0x00eb, "ediaeresis" },
324         { 0x00ec, "igrave" },
325         { 0x00ed, "iacute" },
326         { 0x00ee, "icircumflex" },
327         { 0x00ef, "idiaeresis" },
328         { 0x00f0, "eth" },
329         { 0x00f1, "ntilde" },
330         { 0x00f2, "ograve" },
331         { 0x00f3, "oacute" },
332         { 0x00f4, "ocircumflex" },
333         { 0x00f5, "otilde" },
334         { 0x00f6, "odiaeresis" },
335         { 0x00f7, "division" },
336         { 0x00f8, "oslash" },
337         { 0x00f9, "ugrave" },
338         { 0x00fa, "uacute" },
339         { 0x00fb, "ucircumflex" },
340         { 0x00fc, "udiaeresis" },
341         { 0x00fd, "yacute" },
342         { 0x00fe, "thorn" },
343         { 0x00ff, "ydiaeresis" }
344 };
345
346 static sym latin2_syms[] = {
347         { 0x00a0, "" },         /* 0240 */
348         { 0x0104, "Aogonek" },
349         { 0x02d8, "breve" },
350         { 0x0141, "Lstroke" },
351         { 0x00a4, "" },
352         { 0x013d, "Lcaron" },
353         { 0x015a, "Sacute" },
354         { 0x00a7, "" },
355         { 0x00a8, "" },
356         { 0x0160, "Scaron" },
357         { 0x015e, "Scedilla" },
358         { 0x0164, "Tcaron" },
359         { 0x0179, "Zacute" },
360         { 0x00ad, "" },
361         { 0x017d, "Zcaron" },
362         { 0x017b, "Zabovedot" },
363         { 0x00b0, "" },
364         { 0x0105, "aogonek" },
365         { 0x02db, "ogonek" },
366         { 0x0142, "lstroke" },
367         { 0x00b4, "" },
368         { 0x013e, "lcaron" },
369         { 0x015b, "sacute" },
370         { 0x02c7, "caron" },
371         { 0x00b8, "" },
372         { 0x0161, "scaron" },
373         { 0x015f, "scedilla" },
374         { 0x0165, "tcaron" },
375         { 0x017a, "zacute" },
376         { 0x02dd, "doubleacute" },
377         { 0x017e, "zcaron" },
378         { 0x017c, "zabovedot" },
379         { 0x0154, "Racute" },   /* 0300 */
380         { 0x00c1, "" },
381         { 0x00c2, "" },
382         { 0x0102, "Abreve" },
383         { 0x00c4, "" },
384         { 0x0139, "Lacute" },
385         { 0x0106, "Cacute" },
386         { 0x00c7, "" },
387         { 0x010c, "Ccaron" },
388         { 0x00c9, "" },
389         { 0x0118, "Eogonek" },
390         { 0x00cb, "" },
391         { 0x011a, "Ecaron" },
392         { 0x00cd, "" },
393         { 0x00ce, "" },
394         { 0x010e, "Dcaron" },
395         { 0x0110, "Dstroke" },
396         { 0x0143, "Nacute" },
397         { 0x0147, "Ncaron" },
398         { 0x00d3, "" },
399         { 0x00d4, "" },
400         { 0x0150, "Odoubleacute" },
401         { 0x00d6, "" },
402         { 0x00d7, "" },
403         { 0x0158, "Rcaron" },
404         { 0x016e, "Uring" },
405         { 0x00da, "" },
406         { 0x0170, "Udoubleacute" },
407         { 0x00dc, "" },
408         { 0x00dd, "" },
409         { 0x0162, "Tcedilla" },
410         { 0x00df, "" },
411         { 0x0155, "racute" },
412         { 0x00e1, "" },
413         { 0x00e2, "" },
414         { 0x0103, "abreve" },
415         { 0x00e4, "" },
416         { 0x013a, "lacute" },
417         { 0x0107, "cacute" },
418         { 0x00e7, "" },
419         { 0x010d, "ccaron" },
420         { 0x00e9, "" },
421         { 0x0119, "eogonek" },
422         { 0x00eb, "" },
423         { 0x011b, "ecaron" },
424         { 0x00ed, "" },
425         { 0x00ee, "" },
426         { 0x010f, "dcaron" },
427         { 0x0111, "dstroke" },
428         { 0x0144, "nacute" },
429         { 0x0148, "ncaron" },
430         { 0x00f3, "" },
431         { 0x00f4, "" },
432         { 0x0151, "odoubleacute" },
433         { 0x00f6, "" },
434         { 0x00f7, "" },
435         { 0x0159, "rcaron" },
436         { 0x016f, "uring" },
437         { 0x00fa, "" },
438         { 0x0171, "udoubleacute" },
439         { 0x00fc, "" },
440         { 0x00fd, "" },
441         { 0x0163, "tcedilla" },
442         { 0x02d9, "abovedot" }
443 };
444
445 static sym mazovia_syms[] = {
446         /* as specified by Wlodek Bzyl <matwb@univ.gda.pl> */
447         { 0x0080, "" },
448         { 0x0081, "" },
449         { 0x0082, "" },
450         { 0x0083, "" },
451         { 0x0084, "" },
452         { 0x0085, "" },
453         { 0x0105, "aogonek" },
454         { 0x0087, "" },
455         { 0x0088, "" },
456         { 0x0089, "" },
457         { 0x008a, "" },
458         { 0x008b, "" },
459         { 0x008c, "" },
460         { 0x0107, "cacute" },
461         { 0x008e, "" },
462         { 0x0104, "Aogonek" },
463         { 0x0118, "Eogonek" },
464         { 0x0119, "eogonek" },
465         { 0x0142, "lstroke" },
466         { 0x0093, "" },
467         { 0x0094, "" },
468         { 0x0106, "Cacute" },
469         { 0x0096, "" },
470         { 0x0097, "" },
471         { 0x015a, "Sacute" },
472         { 0x0099, "" },
473         { 0x009a, "" },
474         { 0x009b, "" },
475         { 0x0141, "Lstroke" },
476         { 0x009d, "" },
477         { 0x015b, "sacute" },
478         { 0x009f, "" },
479         { 0x0179, "Zacute" },
480         { 0x017b, "Zabovedot" },
481         { 0x00f3, "oacute" },
482         { 0x00d3, "Oacute" },
483         { 0x0144, "nacute" },
484         { 0x0143, "Nacute" },
485         { 0x017a, "zacute" },
486         { 0x017c, "zabovedot" },
487         { 0x00a8, "" },
488         { 0x00a9, "" },
489         { 0x00aa, "" },
490         { 0x00ab, "" },
491         { 0x00ac, "" },
492         { 0x00ad, "" },
493         { 0x00ab, "guillemotleft" },
494         { 0x00bb, "guillemotright" },
495         { 0x00b0, "" },
496         { 0x00b1, "" },
497         { 0x00b2, "" },
498         { 0x00b3, "" },
499         { 0x00b4, "" },
500         { 0x00b5, "" },
501         { 0x00b6, "" },
502         { 0x00b7, "" },
503         { 0x00b8, "" },
504         { 0x00b9, "" },
505         { 0x00ba, "" },
506         { 0x00bb, "" },
507         { 0x00bc, "" },
508         { 0x00bd, "" },
509         { 0x00be, "" },
510         { 0x00bf, "" },
511         { 0x00c0, "" },
512         { 0x00c1, "" },
513         { 0x00c2, "" },
514         { 0x00c3, "" },
515         { 0x00c4, "" },
516         { 0x00c5, "" },
517         { 0x00c6, "" },
518         { 0x00c7, "" },
519         { 0x00c8, "" },
520         { 0x00c9, "" },
521         { 0x00ca, "" },
522         { 0x00cb, "" },
523         { 0x00cc, "" },
524         { 0x00cd, "" },
525         { 0x00ce, "" },
526         { 0x00cf, "" },
527         { 0x00d0, "" },
528         { 0x00d1, "" },
529         { 0x00d2, "" },
530         { 0x00d3, "" },
531         { 0x00d4, "" },
532         { 0x00d5, "" },
533         { 0x00d6, "" },
534         { 0x00d7, "" },
535         { 0x00d8, "" },
536         { 0x00d9, "" },
537         { 0x00da, "" },
538         { 0x00db, "" },
539         { 0x00dc, "" },
540         { 0x00dd, "" },
541         { 0x00de, "" },
542         { 0x00df, "" },
543         { 0x00e0, "" },
544         { 0x00e1, "" },
545         { 0x00e2, "" },
546         { 0x00e3, "" },
547         { 0x00e4, "" },
548         { 0x00e5, "" },
549         { 0x00e6, "" },
550         { 0x00e7, "" },
551         { 0x00e8, "" },
552         { 0x00e9, "" },
553         { 0x00ea, "" },
554         { 0x00eb, "" },
555         { 0x00ec, "" },
556         { 0x00ed, "" },
557         { 0x00ee, "" },
558         { 0x00ef, "" },
559         { 0x00f0, "" },
560         { 0x00f1, "" },
561         { 0x00f2, "" },
562         { 0x00f3, "" },
563         { 0x00f4, "" },
564         { 0x00f5, "" },
565         { 0x00f6, "" },
566         { 0x00f7, "" },
567         { 0x00f8, "" },
568         { 0x00f9, "" },
569         { 0x00fa, "" },
570         { 0x00fb, "" },
571         { 0x00fc, "" },
572         { 0x00fd, "" },
573         { 0x00fe, "" },
574         { 0x201e, "quotedblbase" }
575 };
576
577 static sym latin3_syms[] = {
578         { 0x00a0, "" },
579         { 0x0126, "Hstroke" },
580         { 0x02d8, "" },
581         { 0x00a3, "" },
582         { 0x00a4, "" },
583         { 0xfffd, "" },
584         { 0x0124, "Hcircumflex" },
585         { 0x00a7, "" },
586         { 0x00a8, "" },
587         { 0x0130, "Iabovedot" },
588         { 0x015e, "" },
589         { 0x011e, "Gbreve" },
590         { 0x0134, "Jcircumflex" },
591         { 0x00ad, "" },
592         { 0xfffd, "" },
593         { 0x017b, "" },
594         { 0x00b0, "" },
595         { 0x0127, "hstroke" },
596         { 0x00b2, "" },
597         { 0x00b3, "" },
598         { 0x00b4, "" },
599         { 0x00b5, "" },
600         { 0x0125, "hcircumflex" },
601         { 0x00b7, "" },
602         { 0x00b8, "" },
603         { 0x0131, "idotless" },
604         { 0x015f, "" },
605         { 0x011f, "gbreve" },
606         { 0x0135, "jcircumflex" },
607         { 0x00bd, "" },
608         { 0xfffd, "" },
609         { 0x017c, "" },
610         { 0x00c0, "" },
611         { 0x00c1, "" },
612         { 0x00c2, "" },
613         { 0xfffd, "" },
614         { 0x00c4, "" },
615         { 0x010a, "Cabovedot" },
616         { 0x0108, "Ccircumflex" },
617         { 0x00c7, "" },
618         { 0x00c8, "" },
619         { 0x00c9, "" },
620         { 0x00ca, "" },
621         { 0x00cb, "" },
622         { 0x00cc, "" },
623         { 0x00cd, "" },
624         { 0x00ce, "" },
625         { 0x00cf, "" },
626         { 0xfffd, "" },
627         { 0x00d1, "" },
628         { 0x00d2, "" },
629         { 0x00d3, "" },
630         { 0x00d4, "" },
631         { 0x0120, "Gabovedot" },
632         { 0x00d6, "" },
633         { 0x00d7, "" },
634         { 0x011c, "Gcircumflex" },
635         { 0x00d9, "" },
636         { 0x00da, "" },
637         { 0x00db, "" },
638         { 0x00dc, "" },
639         { 0x016c, "Ubreve" },
640         { 0x015c, "Scircumflex" },
641         { 0x00df, "" },
642         { 0x00e0, "" },
643         { 0x00e1, "" },
644         { 0x00e2, "" },
645         { 0xfffd, "" },
646         { 0x00e4, "" },
647         { 0x010b, "cabovedot" },
648         { 0x0109, "ccircumflex" },
649         { 0x00e7, "" },
650         { 0x00e8, "" },
651         { 0x00e9, "" },
652         { 0x00ea, "" },
653         { 0x00eb, "" },
654         { 0x00ec, "" },
655         { 0x00ed, "" },
656         { 0x00ee, "" },
657         { 0x00ef, "" },
658         { 0xfffd, "" },
659         { 0x00f1, "" },
660         { 0x00f2, "" },
661         { 0x00f3, "" },
662         { 0x00f4, "" },
663         { 0x0121, "gabovedot" },
664         { 0x00f6, "" },
665         { 0x00f7, "" },
666         { 0x011d, "gcircumflex" },
667         { 0x00f9, "" },
668         { 0x00fa, "" },
669         { 0x00fb, "" },
670         { 0x00fc, "" },
671         { 0x016d, "ubreve" },
672         { 0x015d, "scircumflex" },
673         { 0x02d9, "" }
674 };
675
676 static sym latin4_syms[] = {
677         { 0x00a0, "" },
678         { 0x0104, "" },
679         { 0x0138, "kra" },
680         { 0x0156, "Rcedilla" },
681         { 0x00a4, "" },
682         { 0x0128, "Itilde" },
683         { 0x013b, "Lcedilla" },
684         { 0x00a7, "" },
685         { 0x00a8, "" },
686         { 0x0160, "" },
687         { 0x0112, "Emacron" },
688         { 0x0122, "Gcedilla" },
689         { 0x0166, "Tslash" },
690         { 0x00ad, "" },
691         { 0x017d, "" },
692         { 0x00af, "" },
693         { 0x00b0, "" },
694         { 0x0105, "" },
695         { 0x02db, "" },
696         { 0x0157, "rcedilla" },
697         { 0x00b4, "" },
698         { 0x0129, "itilde" },
699         { 0x013c, "lcedilla" },
700         { 0x02c7, "" },
701         { 0x00b8, "" },
702         { 0x0161, "" },
703         { 0x0113, "emacron" },
704         { 0x0123, "gcedilla" },
705         { 0x0167, "tslash" },
706         { 0x014a, "ENG" },
707         { 0x017e, "" },
708         { 0x014b, "eng" },
709         { 0x0100, "Amacron" },
710         { 0x00c1, "" },
711         { 0x00c2, "" },
712         { 0x00c3, "" },
713         { 0x00c4, "" },
714         { 0x00c5, "" },
715         { 0x00c6, "" },
716         { 0x012e, "Iogonek" },
717         { 0x010c, "" },
718         { 0x00c9, "" },
719         { 0x0118, "" },
720         { 0x00cb, "" },
721         { 0x0116, "Eabovedot" },
722         { 0x00cd, "" },
723         { 0x00ce, "" },
724         { 0x012a, "Imacron" },
725         { 0x0110, "" },
726         { 0x0145, "Ncedilla" },
727         { 0x014c, "Omacron" },
728         { 0x0136, "Kcedilla" },
729         { 0x00d4, "" },
730         { 0x00d5, "" },
731         { 0x00d6, "" },
732         { 0x00d7, "" },
733         { 0x00d8, "" },
734         { 0x0172, "Uogonek" },
735         { 0x00da, "" },
736         { 0x00db, "" },
737         { 0x00dc, "" },
738         { 0x0168, "Utilde" },
739         { 0x016a, "Umacron" },
740         { 0x00df, "" },
741         { 0x0101, "amacron" },
742         { 0x00e1, "" },
743         { 0x00e2, "" },
744         { 0x00e3, "" },
745         { 0x00e4, "" },
746         { 0x00e5, "" },
747         { 0x00e6, "" },
748         { 0x012f, "iogonek" },
749         { 0x010d, "" },
750         { 0x00e9, "" },
751         { 0x0119, "" },
752         { 0x00eb, "" },
753         { 0x0117, "eabovedot" },
754         { 0x00ed, "" },
755         { 0x00ee, "" },
756         { 0x012b, "imacron" },
757         { 0x0111, "" },
758         { 0x0146, "ncedilla" },
759         { 0x014d, "omacron" },
760         { 0x0137, "kcedilla" },
761         { 0x00f4, "" },
762         { 0x00f5, "" },
763         { 0x00f6, "" },
764         { 0x00f7, "" },
765         { 0x00f8, "" },
766         { 0x0173, "uogonek" },
767         { 0x00fa, "" },
768         { 0x00fb, "" },
769         { 0x00fc, "" },
770         { 0x0169, "utilde" },
771         { 0x016b, "umacron" },
772         { 0x02d9, "" }
773 };
774
775 static sym iso_8859_5_syms[] = { /* 160-255 */
776         { 0x00a0, "nobreakspace" },
777         { 0x0401, "cyrillic_capital_letter_io" },
778         { 0x0402, "serbocroatian_cyrillic_capital_letter_dje" },
779         { 0x0403, "macedonian_cyrillic_capital_letter_gje" },
780         { 0x0404, "ukrainian_cyrillic_capital_letter_ie" },
781         { 0x0405, "macedonian_cyrillic_capital_letter_dze" },
782         { 0x0406, "ukrainian_cyrillic_capital_letter_i" },
783         { 0x0407, "ukrainian_cyrillic_capital_letter_yi" },
784         { 0x0408, "cyrillic_capital_letter_je" },                       /* 0250 */
785         { 0x0409, "cyrillic_capital_letter_lje" },
786         { 0x040a, "cyrillic_capital_letter_nje" },
787         { 0x040b, "serbocroatian_cyrillic_capital_letter_chje" },
788         { 0x040c, "macedonian_cyrillic_capital_letter_kje" },
789         { 0x00ad, "hyphen" },
790         { 0x040e, "bielorussian_cyrillic_capital_letter_short_u" },
791         { 0x040f, "cyrillic_capital_letter_dze" },
792         { 0x0410, "cyrillic_capital_letter_a" },                        /* 0260 */
793         { 0x0411, "cyrillic_capital_letter_be" },
794         { 0x0412, "cyrillic_capital_letter_ve" },
795         { 0x0413, "cyrillic_capital_letter_ghe" },
796         { 0x0414, "cyrillic_capital_letter_de" },
797         { 0x0415, "cyrillic_capital_letter_ie" },
798         { 0x0416, "cyrillic_capital_letter_zhe" },
799         { 0x0417, "cyrillic_capital_letter_ze" },
800         { 0x0418, "cyrillic_capital_letter_i" },                        /* 0270 */
801         { 0x0419, "cyrillic_capital_letter_short_i" },
802         { 0x041a, "cyrillic_capital_letter_ka" },
803         { 0x041b, "cyrillic_capital_letter_el" },
804         { 0x041c, "cyrillic_capital_letter_em" },
805         { 0x041d, "cyrillic_capital_letter_en" },
806         { 0x041e, "cyrillic_capital_letter_o" },
807         { 0x041f, "cyrillic_capital_letter_pe" },
808         { 0x0420, "cyrillic_capital_letter_er" },                       /* 0300 */
809         { 0x0421, "cyrillic_capital_letter_es" },
810         { 0x0422, "cyrillic_capital_letter_te" },
811         { 0x0423, "cyrillic_capital_letter_u" },
812         { 0x0424, "cyrillic_capital_letter_ef" },
813         { 0x0425, "cyrillic_capital_letter_ha" },
814         { 0x0426, "cyrillic_capital_letter_tse" },
815         { 0x0427, "cyrillic_capital_letter_che" },
816         { 0x0428, "cyrillic_capital_letter_sha" },                      /* 0310 */
817         { 0x0429, "cyrillic_capital_letter_shcha" },
818         { 0x042a, "cyrillic_capital_hard_sign" },
819         { 0x042b, "cyrillic_capital_letter_yeru" },
820         { 0x042c, "cyrillic_capital_soft_sign" },
821         { 0x042d, "cyrillic_capital_letter_e" },
822         { 0x042e, "cyrillic_capital_letter_yu" },
823         { 0x042f, "cyrillic_capital_letter_ya" },
824         { 0x0430, "cyrillic_small_letter_a" },                          /* 0320 */
825         { 0x0431, "cyrillic_small_letter_be" },
826         { 0x0432, "cyrillic_small_letter_ve" },
827         { 0x0433, "cyrillic_small_letter_ghe" },
828         { 0x0434, "cyrillic_small_letter_de" },
829         { 0x0435, "cyrillic_small_letter_ie" },
830         { 0x0436, "cyrillic_small_letter_zhe" },
831         { 0x0437, "cyrillic_small_letter_ze" },
832         { 0x0438, "cyrillic_small_letter_i" },                          /* 0330 */
833         { 0x0439, "cyrillic_small_letter_short_i" },
834         { 0x043a, "cyrillic_small_letter_ka" },
835         { 0x043b, "cyrillic_small_letter_el" },
836         { 0x043c, "cyrillic_small_letter_em" },
837         { 0x043d, "cyrillic_small_letter_en" },
838         { 0x043e, "cyrillic_small_letter_o" },
839         { 0x043f, "cyrillic_small_letter_pe" },
840         { 0x0440, "cyrillic_small_letter_er" },                         /* 0340 */
841         { 0x0441, "cyrillic_small_letter_es" },
842         { 0x0442, "cyrillic_small_letter_te" },
843         { 0x0443, "cyrillic_small_letter_u" },
844         { 0x0444, "cyrillic_small_letter_ef" },
845         { 0x0445, "cyrillic_small_letter_ha" },
846         { 0x0446, "cyrillic_small_letter_tse" },
847         { 0x0447, "cyrillic_small_letter_che" },
848         { 0x0448, "cyrillic_small_letter_sha" },                        /* 0350 */
849         { 0x0449, "cyrillic_small_letter_shcha" },
850         { 0x044a, "cyrillic_small_hard_sign" },
851         { 0x044b, "cyrillic_small_letter_yeru" },
852         { 0x044c, "cyrillic_small_soft_sign" },
853         { 0x044d, "cyrillic_small_letter_e" },
854         { 0x044e, "cyrillic_small_letter_yu" },
855         { 0x044f, "cyrillic_small_letter_ya" },
856         { 0x2116, "number_acronym" },                                   /* 0360 */
857         { 0x0451, "cyrillic_small_letter_io" },
858         { 0x0452, "serbocroatian_cyrillic_small_letter_dje" },
859         { 0x0453, "macedonian_cyrillic_small_letter_gje" },
860         { 0x0454, "ukrainian_cyrillic_small_letter_ie" },
861         { 0x0455, "macedonian_cyrillic_small_letter_dze" },
862         { 0x0456, "ukrainian_cyrillic_small_letter_i" },
863         { 0x0457, "ukrainian_cyrillic_small_letter_yi" },
864         { 0x0458, "cyrillic_small_letter_je" },                         /* 0370 */
865         { 0x0459, "cyrillic_small_letter_lje" },
866         { 0x045a, "cyrillic_small_letter_nje" },
867         { 0x045b, "serbocroatian_cyrillic_small_letter_chje" },
868         { 0x045c, "macedonian_cyrillic_small_letter_kje" },
869         { 0x00a7, "section" },
870         { 0x045e, "bielorussian_cyrillic_small_letter_short_u" },       /* printing error in ECMA-113 */
871         { 0x045f, "cyrillic_small_letter_dze" }
872 };
873
874 static sym iso_8859_7_syms[] = { /* 160-255 */
875         { 0x00a0, "" },
876         { 0x02bd, "leftquote" },
877         { 0x02bc, "rightquote" },
878         { 0x00a3, "" },
879         { 0xfffd, "" },
880         { 0xfffd, "" },
881         { 0x00a6, "" },
882         { 0x00a7, "" },
883         { 0x00a8, "" },
884         { 0x00a9, "" },
885         { 0xfffd, "" },
886         { 0x00ab, "" },
887         { 0x00ac, "" },
888         { 0x00ad, "" },
889         { 0xfffd, "" },
890         { 0x2015, "" },
891         { 0x00b0, "" },
892         { 0x00b1, "" },
893         { 0x00b2, "" },
894         { 0x00b3, "" },
895         { 0x0384, "accent" },
896         { 0x0385, "diaeresisaccent" },
897         { 0x0386, "Alphaaccent" },
898         { 0x00b7, "" },
899         { 0x0388, "Epsilonaccent" },
900         { 0x0389, "Etaaccent" },
901         { 0x038a, "Iotaaccent" },
902         { 0x00bb, "guillemotright" },
903         { 0x038c, "Omicronaccent" },
904         { 0x00bd, "onehalf" },
905         { 0x038e, "Upsilonaccent" },
906         { 0x038f, "Omegaaccent" },
907         { 0x0390, "iotadiaeresisaccent" },
908         { 0x0391, "Alpha" },
909         { 0x0392, "Beta" },
910         { 0x0393, "Gamma" },
911         { 0x0394, "Delta" },
912         { 0x0395, "Epsilon" },
913         { 0x0396, "Zeta" },
914         { 0x0397, "Eta" },
915         { 0x0398, "Theta" },
916         { 0x0399, "Iota" },
917         { 0x039a, "Kappa" },
918         { 0x039b, "Lamda" /*sic*/ },
919         { 0x039c, "Mu" },
920         { 0x039d, "Nu" },
921         { 0x039e, "Ksi" },
922         { 0x039f, "Omicron" },
923         { 0x03a0, "Pi" },
924         { 0x03a1, "Rho" },
925         { 0xfffd, "" },
926         { 0x03a3, "Sigma" },
927         { 0x03a4, "Tau" },
928         { 0x03a5, "Upsilon" },
929         { 0x03a6, "Phi" },
930         { 0x03a7, "Khi" },
931         { 0x03a8, "Psi" },
932         { 0x03a9, "Omega" },
933         { 0x03aa, "Iotadiaeresis" },
934         { 0x03ab, "Upsilondiaeresis" },
935         { 0x03ac, "alphaaccent" },
936         { 0x03ad, "epsilonaccent" },
937         { 0x03ae, "etaaccent" },
938         { 0x03af, "iotaaccent" },
939         { 0x03b0, "upsilondiaeresisaccent" },
940         { 0x03b1, "alpha" },
941         { 0x03b2, "beta" },
942         { 0x03b3, "gamma" },
943         { 0x03b4, "delta" },
944         { 0x03b5, "epsilon" },
945         { 0x03b6, "zeta" },
946         { 0x03b7, "eta" },
947         { 0x03b8, "theta" },
948         { 0x03b9, "iota" },
949         { 0x03ba, "kappa" },
950         { 0x03bb, "lamda" /*sic*/ },
951         { 0x03bc, "mu" },
952         { 0x03bd, "nu" },
953         { 0x03be, "ksi" },
954         { 0x03bf, "omicron" },
955         { 0x03c0, "pi" },
956         { 0x03c1, "rho" },
957         { 0x03c2, "terminalsigma" },
958         { 0x03c3, "sigma" },
959         { 0x03c4, "tau" },
960         { 0x03c5, "upsilon" },
961         { 0x03c6, "phi" },
962         { 0x03c7, "khi" },
963         { 0x03c8, "psi" },
964         { 0x03c9, "omega" },
965         { 0x03ca, "iotadiaeresis" },
966         { 0x03cb, "upsilondiaeresis" },
967         { 0x03cc, "omicronaccent" },
968         { 0x03cd, "upsilonaccent" },
969         { 0x03ce, "omegaaccent" },
970         { 0xfffd, "" }
971 };
972
973 static sym iso_8859_8_syms[] = {
974         { 0x00a0, "" },
975         { 0xfffd, "" },
976         { 0x00a2, "" },
977         { 0x00a3, "" },
978         { 0x00a4, "" },
979         { 0x00a5, "" },
980         { 0x00a6, "" },
981         { 0x00a7, "" },
982         { 0x00a8, "" },
983         { 0x00a9, "" },
984         { 0x00d7, "multiply" },
985         { 0x00ab, "" },
986         { 0x00ac, "" },
987         { 0x00ad, "" },
988         { 0x00ae, "" },
989         { 0x203e, "overscore" },
990         { 0x00b0, "" },
991         { 0x00b1, "" },
992         { 0x00b2, "" },
993         { 0x00b3, "" },
994         { 0x00b4, "" },
995         { 0x00b5, "" },
996         { 0x00b6, "" },
997         { 0x00b7, "" },
998         { 0x00b8, "" },
999         { 0x00b9, "" },
1000         { 0x00f7, "division" },
1001         { 0x00bb, "" },
1002         { 0x00bc, "" },
1003         { 0x00bd, "" },
1004         { 0x00be, "" },
1005         { 0xfffd, "" },
1006         { 0xfffd, "" },
1007         { 0xfffd, "" },
1008         { 0xfffd, "" },
1009         { 0xfffd, "" },
1010         { 0xfffd, "" },
1011         { 0xfffd, "" },
1012         { 0xfffd, "" },
1013         { 0xfffd, "" },
1014         { 0xfffd, "" },
1015         { 0xfffd, "" },
1016         { 0xfffd, "" },
1017         { 0xfffd, "" },
1018         { 0xfffd, "" },
1019         { 0xfffd, "" },
1020         { 0xfffd, "" },
1021         { 0xfffd, "" },
1022         { 0xfffd, "" },
1023         { 0xfffd, "" },
1024         { 0xfffd, "" },
1025         { 0xfffd, "" },
1026         { 0xfffd, "" },
1027         { 0xfffd, "" },
1028         { 0xfffd, "" },
1029         { 0xfffd, "" },
1030         { 0xfffd, "" },
1031         { 0xfffd, "" },
1032         { 0xfffd, "" },
1033         { 0xfffd, "" },
1034         { 0xfffd, "" },
1035         { 0xfffd, "" },
1036         { 0xfffd, "" },
1037         { 0x2017, "doubleunderscore" },
1038         { 0x05d0, "alef" },
1039         { 0x05d1, "bet" },
1040         { 0x05d2, "gimel" },
1041         { 0x05d3, "dalet" },
1042         { 0x05d4, "he" },
1043         { 0x05d5, "vav" },
1044         { 0x05d6, "zayin" },
1045         { 0x05d7, "het" },
1046         { 0x05d8, "tet" },
1047         { 0x05d9, "yod" },
1048         { 0x05da, "finalkaf" },
1049         { 0x05db, "kaf" },
1050         { 0x05dc, "lamed" },
1051         { 0x05dd, "finalmem" },
1052         { 0x05de, "mem" },
1053         { 0x05df, "finalnun" },
1054         { 0x05e0, "nun" },
1055         { 0x05e1, "samekh" },
1056         { 0x05e2, "ayin" },
1057         { 0x05e3, "finalpe" },
1058         { 0x05e4, "pe" },
1059         { 0x05e5, "finaltsadi" },
1060         { 0x05e6, "tsadi" },
1061         { 0x05e7, "qof" },
1062         { 0x05e8, "resh" },
1063         { 0x05e9, "shin" },
1064         { 0x05ea, "tav" },
1065         { 0xfffd, "" },
1066         { 0xfffd, "" },
1067         { 0xfffd, "" },
1068         { 0xfffd, "" },
1069         { 0xfffd, "" }
1070 };
1071
1072 static sym iso_8859_9_syms[] = { /* latin-5 */
1073         /* Identical to latin-1, but with the 6 symbols
1074            ETH, eth, THORN, thorn, Yacute, yacute replaced by
1075            Gbreve, gbreve, Scedilla, scedilla, Idotabove, dotlessi */
1076         { 0x011e, "Gbreve" },
1077         { 0x00d1, "" },
1078         { 0x00d2, "" },
1079         { 0x00d3, "" },
1080         { 0x00d4, "" },
1081         { 0x00d5, "" },
1082         { 0x00d6, "" },
1083         { 0x00d7, "" },
1084         { 0x00d8, "" },
1085         { 0x00d9, "" },
1086         { 0x00da, "" },
1087         { 0x00db, "" },
1088         { 0x00dc, "" },
1089         { 0x0130, "Idotabove" },
1090         { 0x015e, "Scedilla" },
1091         { 0x00df, "" },
1092         { 0x00e0, "" },
1093         { 0x00e1, "" },
1094         { 0x00e2, "" },
1095         { 0x00e3, "" },
1096         { 0x00e4, "" },
1097         { 0x00e5, "" },
1098         { 0x00e6, "" },
1099         { 0x00e7, "" },
1100         { 0x00e8, "" },
1101         { 0x00e9, "" },
1102         { 0x00ea, "" },
1103         { 0x00eb, "" },
1104         { 0x00ec, "" },
1105         { 0x00ed, "" },
1106         { 0x00ee, "" },
1107         { 0x00ef, "" },
1108         { 0x011f, "gbreve" },
1109         { 0x00f1, "" },
1110         { 0x00f2, "" },
1111         { 0x00f3, "" },
1112         { 0x00f4, "" },
1113         { 0x00f5, "" },
1114         { 0x00f6, "" },
1115         { 0x00f7, "" },
1116         { 0x00f8, "" },
1117         { 0x00f9, "" },
1118         { 0x00fa, "" },
1119         { 0x00fb, "" },
1120         { 0x00fc, "" },
1121         { 0x0131, "dotlessi" },
1122         { 0x015f, "scedilla" },
1123         { 0x00ff, "" }
1124 };
1125
1126 #include "syms.koi8.h"
1127 #include "syms.cp1250.h"
1128 #include "syms.thai.h"
1129 #include "syms.ethiopic.h"
1130 #include "syms.sami.h"
1131
1132 static sym iso_8859_15_syms[] = {
1133         /* latin-1 with 8 changes */
1134         { 0x00a0, "" },
1135         { 0x00a1, "" },
1136         { 0x00a2, "" },
1137         { 0x00a3, "" },
1138         { 0x20ac, "euro" },
1139         { 0x00a5, "" },
1140         { 0x0160, "Scaron" },
1141         { 0x00a7, "" },
1142         { 0x0161, "scaron" },
1143         { 0x00a9, "" },
1144         { 0x00aa, "" },
1145         { 0x00ab, "" },
1146         { 0x00ac, "" },
1147         { 0x00ad, "" },
1148         { 0x00ae, "" },
1149         { 0x00af, "" },
1150         { 0x00b0, "" },
1151         { 0x00b1, "" },
1152         { 0x00b2, "" },
1153         { 0x00b3, "" },
1154         { 0x017d, "Zcaron" },
1155         { 0x00b5, "" },
1156         { 0x00b6, "" },
1157         { 0x00b7, "" },
1158         { 0x017e, "zcaron" },
1159         { 0x00b9, "" },
1160         { 0x00ba, "" },
1161         { 0x00bb, "" },
1162         { 0x0152, "OE" },
1163         { 0x0153, "oe" },
1164         { 0x0178, "Ydiaeresis" },
1165         { 0x00bf, "" },
1166         { 0x00c0, "" },
1167         { 0x00c1, "" },
1168         { 0x00c2, "" },
1169         { 0x00c3, "" },
1170         { 0x00c4, "" },
1171         { 0x00c5, "" },
1172         { 0x00c6, "" },
1173         { 0x00c7, "" },
1174         { 0x00c8, "" },
1175         { 0x00c9, "" },
1176         { 0x00ca, "" },
1177         { 0x00cb, "" },
1178         { 0x00cc, "" },
1179         { 0x00cd, "" },
1180         { 0x00ce, "" },
1181         { 0x00cf, "" },
1182         { 0x00d0, "" },
1183         { 0x00d1, "" },
1184         { 0x00d2, "" },
1185         { 0x00d3, "" },
1186         { 0x00d4, "" },
1187         { 0x00d5, "" },
1188         { 0x00d6, "" },
1189         { 0x00d7, "" },
1190         { 0x00d8, "" },
1191         { 0x00d9, "" },
1192         { 0x00da, "" },
1193         { 0x00db, "" },
1194         { 0x00dc, "" },
1195         { 0x00dd, "" },
1196         { 0x00de, "" },
1197         { 0x00df, "" },
1198         { 0x00e0, "" },
1199         { 0x00e1, "" },
1200         { 0x00e2, "" },
1201         { 0x00e3, "" },
1202         { 0x00e4, "" },
1203         { 0x00e5, "" },
1204         { 0x00e6, "" },
1205         { 0x00e7, "" },
1206         { 0x00e8, "" },
1207         { 0x00e9, "" },
1208         { 0x00ea, "" },
1209         { 0x00eb, "" },
1210         { 0x00ec, "" },
1211         { 0x00ed, "" },
1212         { 0x00ee, "" },
1213         { 0x00ef, "" },
1214         { 0x00f0, "" },
1215         { 0x00f1, "" },
1216         { 0x00f2, "" },
1217         { 0x00f3, "" },
1218         { 0x00f4, "" },
1219         { 0x00f5, "" },
1220         { 0x00f6, "" },
1221         { 0x00f7, "" },
1222         { 0x00f8, "" },
1223         { 0x00f9, "" },
1224         { 0x00fa, "" },
1225         { 0x00fb, "" },
1226         { 0x00fc, "" },
1227         { 0x00fd, "" },
1228         { 0x00fe, "" },
1229         { 0x00ff, "" }
1230 };
1231
1232 /* Keysyms whose KTYP is KT_FN. */
1233
1234 static const char *fn_syms[] = {
1235         "F1",   "F2",   "F3",   "F4",   "F5",
1236         "F6",   "F7",   "F8",   "F9",   "F10",
1237         "F11",  "F12",  "F13",  "F14",  "F15",
1238         "F16",  "F17",  "F18",  "F19",  "F20",
1239         "Find",                 /* also called: "Home" */
1240         "Insert",
1241         "Remove",
1242         "Select",               /* also called: "End" */
1243         "Prior",                /* also called: "PageUp" */
1244         "Next",                 /* also called: "PageDown" */
1245         "Macro",
1246         "Help",
1247         "Do",
1248         "Pause",
1249         "F21",  "F22",  "F23",  "F24",  "F25",
1250         "F26",  "F27",  "F28",  "F29",  "F30",
1251         "F31",  "F32",  "F33",  "F34",  "F35",
1252         "F36",  "F37",  "F38",  "F39",  "F40",
1253         "F41",  "F42",  "F43",  "F44",  "F45",
1254         "F46",  "F47",  "F48",  "F49",  "F50",
1255         "F51",  "F52",  "F53",  "F54",  "F55",
1256         "F56",  "F57",  "F58",  "F59",  "F60",
1257         "F61",  "F62",  "F63",  "F64",  "F65",
1258         "F66",  "F67",  "F68",  "F69",  "F70",
1259         "F71",  "F72",  "F73",  "F74",  "F75",
1260         "F76",  "F77",  "F78",  "F79",  "F80",
1261         "F81",  "F82",  "F83",  "F84",  "F85",
1262         "F86",  "F87",  "F88",  "F89",  "F90",
1263         "F91",  "F92",  "F93",  "F94",  "F95",
1264         "F96",  "F97",  "F98",  "F99",  "F100",
1265         "F101", "F102", "F103", "F104", "F105",
1266         "F106", "F107", "F108", "F109", "F110",
1267         "F111", "F112", "F113", "F114", "F115",
1268         "F116", "F117", "F118", "F119", "F120",
1269         "F121", "F122", "F123", "F124", "F125",
1270         "F126", "F127", "F128", "F129", "F130",
1271         "F131", "F132", "F133", "F134", "F135",
1272         "F136", "F137", "F138", "F139", "F140",
1273         "F141", "F142", "F143", "F144", "F145",
1274         "F146", "F147", "F148", "F149", "F150",
1275         "F151", "F152", "F153", "F154", "F155",
1276         "F156", "F157", "F158", "F159", "F160",
1277         "F161", "F162", "F163", "F164", "F165",
1278         "F166", "F167", "F168", "F169", "F170",
1279         "F171", "F172", "F173", "F174", "F175",
1280         "F176", "F177", "F178", "F179", "F180",
1281         "F181", "F182", "F183", "F184", "F185",
1282         "F186", "F187", "F188", "F189", "F190",
1283         "F191", "F192", "F193", "F194", "F195",
1284         "F196", "F197", "F198", "F199", "F200",
1285         "F201", "F202", "F203", "F204", "F205",
1286         "F206", "F207", "F208", "F209", "F210",
1287         "F211", "F212", "F213", "F214", "F215",
1288         "F216", "F217", "F218", "F219", "F220",
1289         "F221", "F222", "F223", "F224", "F225",
1290         "F226", "F227", "F228", "F229", "F230",
1291         "F231", "F232", "F233", "F234", "F235",
1292         "F236", "F237", "F238", "F239", "F240",
1293         "F241", "F242", "F243", "F244", "F245",
1294         "F246"          /* there are 10 keys named Insert etc., total 256 */
1295 };
1296
1297 /* Keysyms whose KTYP is KT_SPEC. */
1298
1299 static const char *spec_syms[] = {
1300         "VoidSymbol",
1301         "Return",
1302         "Show_Registers",
1303         "Show_Memory",
1304         "Show_State",
1305         "Break",
1306         "Last_Console",
1307         "Caps_Lock",
1308         "Num_Lock",
1309         "Scroll_Lock",
1310         "Scroll_Forward",
1311         "Scroll_Backward",
1312         "Boot",
1313         "Caps_On",
1314         "Compose",
1315         "SAK",
1316         "Decr_Console",
1317         "Incr_Console",
1318         "KeyboardSignal",
1319         "Bare_Num_Lock"
1320 };
1321
1322 /* Keysyms whose KTYP is KT_PAD. */
1323
1324 static const char *pad_syms[] = {
1325         "KP_0",
1326         "KP_1",
1327         "KP_2",
1328         "KP_3",
1329         "KP_4",
1330         "KP_5",
1331         "KP_6",
1332         "KP_7",
1333         "KP_8",
1334         "KP_9",
1335         "KP_Add",
1336         "KP_Subtract",
1337         "KP_Multiply",
1338         "KP_Divide",
1339         "KP_Enter",
1340         "KP_Comma",
1341         "KP_Period",
1342         "KP_MinPlus"
1343 };
1344
1345 /* Keysyms whose KTYP is KT_DEAD. */
1346
1347 static const char *dead_syms[] = {
1348         "dead_grave",
1349         "dead_acute",
1350         "dead_circumflex",
1351         "dead_tilde",
1352         "dead_diaeresis",
1353         "dead_cedilla"
1354 };
1355
1356 /* Keysyms whose KTYP is KT_CONS. */
1357
1358 static const char *cons_syms[] = {
1359         "Console_1",
1360         "Console_2",
1361         "Console_3",
1362         "Console_4",
1363         "Console_5",
1364         "Console_6",
1365         "Console_7",
1366         "Console_8",
1367         "Console_9",
1368         "Console_10",
1369         "Console_11",
1370         "Console_12",
1371         "Console_13",
1372         "Console_14",
1373         "Console_15",
1374         "Console_16",
1375         "Console_17",
1376         "Console_18",
1377         "Console_19",
1378         "Console_20",
1379         "Console_21",
1380         "Console_22",
1381         "Console_23",
1382         "Console_24",
1383         "Console_25",
1384         "Console_26",
1385         "Console_27",
1386         "Console_28",
1387         "Console_29",
1388         "Console_30",
1389         "Console_31",
1390         "Console_32",
1391         "Console_33",
1392         "Console_34",
1393         "Console_35",
1394         "Console_36",
1395         "Console_37",
1396         "Console_38",
1397         "Console_39",
1398         "Console_40",
1399         "Console_41",
1400         "Console_42",
1401         "Console_43",
1402         "Console_44",
1403         "Console_45",
1404         "Console_46",
1405         "Console_47",
1406         "Console_48",
1407         "Console_49",
1408         "Console_50",
1409         "Console_51",
1410         "Console_52",
1411         "Console_53",
1412         "Console_54",
1413         "Console_55",
1414         "Console_56",
1415         "Console_57",
1416         "Console_58",
1417         "Console_59",
1418         "Console_60",
1419         "Console_61",
1420         "Console_62",
1421         "Console_63"
1422 };
1423
1424 /* Keysyms whose KTYP is KT_CUR. */
1425
1426 static const char *cur_syms[] = {
1427         "Down",
1428         "Left",
1429         "Right",
1430         "Up"
1431 };
1432
1433 /* Keysyms whose KTYP is KT_SHIFT. */
1434
1435 static const char *shift_syms[] = {
1436         "Shift",
1437         "AltGr",
1438         "Control",
1439         "Alt",
1440         "ShiftL",
1441         "ShiftR",
1442         "CtrlL",
1443         "CtrlR",
1444         "CapsShift"
1445 };
1446
1447 /* Keysyms whose KTYP is KT_ASCII. */
1448
1449 static const char *ascii_syms[] = {
1450         "Ascii_0",
1451         "Ascii_1",
1452         "Ascii_2",
1453         "Ascii_3",
1454         "Ascii_4",
1455         "Ascii_5",
1456         "Ascii_6",
1457         "Ascii_7",
1458         "Ascii_8",
1459         "Ascii_9",
1460         "Hex_0",
1461         "Hex_1",
1462         "Hex_2",
1463         "Hex_3",
1464         "Hex_4",
1465         "Hex_5",
1466         "Hex_6",
1467         "Hex_7",
1468         "Hex_8",
1469         "Hex_9",
1470         "Hex_A",
1471         "Hex_B",
1472         "Hex_C",
1473         "Hex_D",
1474         "Hex_E",
1475         "Hex_F"
1476 };
1477
1478 /* Keysyms whose KTYP is KT_LOCK. */
1479
1480 static const char *lock_syms[] = {
1481         "Shift_Lock",
1482         "AltGr_Lock",
1483         "Control_Lock",
1484         "Alt_Lock",
1485         "ShiftL_Lock",
1486         "ShiftR_Lock",
1487         "CtrlL_Lock",
1488         "CtrlR_Lock",
1489         "CapsShift_Lock"
1490 };
1491
1492 /* Keysyms whose KTYP is KT_SLOCK. */
1493
1494 static const char *sticky_syms[] = {
1495         "SShift",
1496         "SAltGr",
1497         "SControl",
1498         "SAlt",
1499         "SShiftL",
1500         "SShiftR",
1501         "SCtrlL",
1502         "SCtrlR",
1503         "SCapsShift"
1504 };
1505
1506 /* Keysyms whose KTYP is KT_BRL. */
1507
1508 static const char *brl_syms[] = {
1509         "Brl_blank",
1510         "Brl_dot1",
1511         "Brl_dot2",
1512         "Brl_dot3",
1513         "Brl_dot4",
1514         "Brl_dot5",
1515         "Brl_dot6",
1516         "Brl_dot7",
1517         "Brl_dot8",
1518         "Brl_dot9",
1519         "Brl_dot10"
1520 };
1521
1522 #define E(x) { x, sizeof(x) / sizeof(x[0]) }
1523
1524 syms_entry syms[] = {
1525         E(iso646_syms),         /* KT_LATIN */
1526         E(fn_syms),             /* KT_FN */
1527         E(spec_syms),           /* KT_SPEC */
1528         E(pad_syms),            /* KT_PAD */
1529         E(dead_syms),           /* KT_DEAD */
1530         E(cons_syms),           /* KT_CONS */
1531         E(cur_syms),            /* KT_CUR */
1532         E(shift_syms),          /* KT_SHIFT */
1533         { 0, 0 },               /* KT_META */
1534         E(ascii_syms),          /* KT_ASCII */
1535         E(lock_syms),           /* KT_LOCK */
1536         { 0, 0 },               /* KT_LETTER */
1537         E(sticky_syms),         /* KT_SLOCK */
1538         { 0, 0 },               /*  */
1539         E(brl_syms)             /* KT_BRL */
1540 };
1541
1542 #undef E
1543
1544 struct syn
1545 synonyms[] = {
1546         { "Control_h",          "BackSpace" },
1547         { "Control_i",          "Tab" },
1548         { "Control_j",          "Linefeed" },
1549         { "Home",               "Find" },
1550 /* Unfortunately Delete already denotes ASCII 0177 */
1551 /*      { "Delete",             "Remove" }, */
1552         { "End",                "Select" },
1553         { "PageUp",             "Prior" },
1554         { "PageDown",           "Next" },
1555         { "multiplication",     "multiply" },
1556         { "pound",              "sterling" },
1557         { "pilcrow",            "paragraph" },
1558         { "Oslash",             "Ooblique" },
1559         { "Shift_L",            "ShiftL" },
1560         { "Shift_R",            "ShiftR" },
1561         { "Control_L",          "CtrlL" },
1562         { "Control_R",          "CtrlR" },
1563         { "AltL",               "Alt" },
1564         { "AltR",               "AltGr" },
1565         { "Alt_L",              "Alt" },
1566         { "Alt_R",              "AltGr" },
1567         { "AltGr_L",            "Alt" },
1568         { "AltGr_R",            "AltGr" },
1569         { "AltLLock",           "Alt_Lock" },
1570         { "AltRLock",           "AltGr_Lock" },
1571         { "SCtrl",              "SControl" },
1572         { "Spawn_Console",      "KeyboardSignal" },
1573         { "Uncaps_Shift",       "CapsShift" },
1574 /* the names of the Greek letters are spelled differently
1575    in the iso-8859-7 and the Unicode standards */
1576         { "lambda",             "lamda" },
1577         { "Lambda",             "Lamda" },
1578         { "xi",                 "ksi" },
1579         { "Xi",                 "Ksi" },
1580         { "chi",                "khi" },
1581         { "Chi",                "Khi" },
1582 /* diacriticals */
1583         { "tilde",              "asciitilde" },
1584         { "circumflex",         "asciicircum" },
1585 /* as dead_ogonek, dead_caron, dead_breve and dead_doubleacute do not exist
1586  * (yet), I put also compose lines for use with respectively dead_cedilla,
1587  * dead_circumflex, dead_tilde and dead_tilde */
1588         { "dead_ogonek",        "dead_cedilla" },
1589         { "dead_caron",         "dead_circumflex" },
1590         { "dead_breve",         "dead_tilde" },
1591         { "dead_doubleacute",   "dead_tilde" },
1592 /* turkish */
1593         { "Idotabove",          "Iabovedot" },
1594         { "dotlessi",           "idotless" },
1595 /* cyrillic */
1596         { "no-break_space",     "nobreakspace" },
1597         { "paragraph_sign",     "section" },
1598         { "soft_hyphen",        "hyphen" },
1599         { "bielorussian_cyrillic_capital_letter_i", "ukrainian_cyrillic_capital_letter_i" },
1600         { "cyrillic_capital_letter_kha", "cyrillic_capital_letter_ha" },
1601         { "cyrillic_capital_letter_ge", "cyrillic_capital_letter_ghe" },
1602         { "cyrillic_capital_letter_ia", "cyrillic_capital_letter_ya" },
1603         { "cyrillic_capital_letter_iu", "cyrillic_capital_letter_yu" },
1604         { "cyrillic_capital_letter_yeri", "cyrillic_capital_letter_yeru" },
1605         { "cyrillic_capital_letter_reversed_e", "cyrillic_capital_letter_e" },
1606         { "cyrillic_capital_letter_ii", "cyrillic_capital_letter_i" },
1607         { "cyrillic_capital_letter_short_ii", "cyrillic_capital_letter_short_i" },
1608         { "bielorussian_cyrillic_small_letter_i", "ukrainian_cyrillic_small_letter_i" },
1609         { "cyrillic_small_letter_kha", "cyrillic_small_letter_ha" },
1610         { "cyrillic_small_letter_ge", "cyrillic_small_letter_ghe" },
1611         { "cyrillic_small_letter_ia", "cyrillic_small_letter_ya" },
1612         { "cyrillic_small_letter_iu", "cyrillic_small_letter_yu" },
1613         { "cyrillic_small_letter_yeri", "cyrillic_small_letter_yeru" },
1614         { "cyrillic_small_letter_reversed_e", "cyrillic_small_letter_e" },
1615         { "cyrillic_small_letter_ii", "cyrillic_small_letter_i" },
1616         { "cyrillic_small_letter_short_ii", "cyrillic_small_letter_short_i" },
1617 /* iso-8859-7 */
1618         { "rightanglequote",    "guillemotright" }
1619 };
1620
1621 const unsigned int syms_size = sizeof(syms) / sizeof(syms_entry);
1622 const unsigned int syn_size = sizeof(synonyms) / sizeof(synonyms[0]);
1623
1624 struct cs {
1625     const char *charset;
1626     sym *charnames;
1627     int start;
1628 } charsets[] = {
1629     { "", NULL, 256 },
1630     { "iso-8859-1",     latin1_syms, 160 },
1631     { "iso-8859-2",     latin2_syms, 160 },
1632     { "iso-8859-3",     latin3_syms, 160 },
1633     { "iso-8859-4",     latin4_syms, 160 },
1634     { "iso-8859-5",     iso_8859_5_syms, 160 },
1635     { "iso-8859-7",     iso_8859_7_syms, 160 },
1636     { "iso-8859-8",     iso_8859_8_syms, 160 },
1637     { "iso-8859-9",     iso_8859_9_syms, 208 },
1638     { "iso-8859-10",    latin6_syms, 160 },
1639     { "iso-8859-15",    iso_8859_15_syms, 160 },
1640     { "mazovia",        mazovia_syms, 128 },
1641     { "cp-1250",        cp1250_syms, 128 },
1642     { "koi8-r",         koi8_syms, 128 },
1643     { "koi8-u",         koi8_syms, 128 },
1644     { "tis-620",        tis_620_syms, 160 },            /* thai */
1645     { "iso-10646-18",   iso_10646_18_syms, 159 },       /* ethiopic */
1646     { "iso-ir-197",     iso_ir_197_syms, 160 },         /* sami */
1647     { "iso-ir-209",     iso_ir_209_syms, 160 },         /* sami */
1648 };
1649
1650 /* Functions for both dumpkeys and loadkeys. */
1651
1652 void
1653 list_charsets(FILE *f) {
1654         int lth,ct;
1655         unsigned int i, j;
1656         char *mm[] = { "iso-8859-", "koi8-" };
1657
1658         for (j=0; j<sizeof(mm)/sizeof(mm[0]); j++) {
1659                 if(j)
1660                         fprintf(f, ",");
1661                 fprintf(f, "%s{", mm[j]);
1662                 ct = 0;
1663                 lth = strlen(mm[j]);
1664                 for(i=1; i < sizeof(charsets)/sizeof(charsets[0]); i++) {
1665                         if(!strncmp(charsets[i].charset, mm[j], lth)) {
1666                                 if(ct++)
1667                                         fprintf(f, ",");
1668                                 fprintf(f, "%s", charsets[i].charset+lth);
1669                         }
1670                 }
1671                 fprintf(f, "}");
1672         }
1673         for(i=1; i < sizeof(charsets)/sizeof(charsets[0]); i++) {
1674                 for (j=0; j<sizeof(mm)/sizeof(mm[0]); j++) {
1675                         lth = strlen(mm[j]);
1676                         if(!strncmp(charsets[i].charset, mm[j], lth))
1677                                 goto nxti;
1678                 }
1679                 fprintf(f, ",%s", charsets[i].charset);
1680         nxti:;
1681         }
1682         fprintf(f, "\n");
1683 }
1684
1685 int
1686 set_charset(const char *charset) {
1687         sym *p;
1688         unsigned int i;
1689
1690         for (i = 1; i < sizeof(charsets)/sizeof(charsets[0]); i++) {
1691                 if (!strcasecmp(charsets[i].charset, charset)) {
1692                         charsets[0].charset = charsets[i].charset;
1693                         charsets[0].charnames = charsets[i].charnames;
1694                         charsets[0].start = charsets[i].start;
1695                         p = charsets[i].charnames;
1696                         for (i = charsets[i].start; i < 256; i++,p++) {
1697                                 if(p->name[0])
1698                                         syms[0].table[i] = p->name;
1699                         }
1700                         return 0;
1701                 }
1702         }
1703         return 1;
1704 }
1705
1706 const char *
1707 codetoksym(int code) {
1708         unsigned int i;
1709         int j;
1710         sym *p;
1711
1712         if (code < 0)
1713                 return NULL;
1714
1715         if (code < 0x1000) {    /* "traditional" keysym */
1716                 if (code < 0x80)
1717                         return iso646_syms[code];
1718                 if (KTYP(code) == KT_META)
1719                         return NULL;
1720                 if (KTYP(code) == KT_LETTER)
1721                         code = K(KT_LATIN, KVAL(code));
1722                 if (KTYP(code) > KT_LATIN)
1723                         return syms[KTYP(code)].table[KVAL(code)];
1724
1725                 for (i = 0; i < sizeof(charsets)/sizeof(charsets[0]); i++) {
1726                         p = charsets[i].charnames;
1727                         if (!p)
1728                                 continue;
1729                         p += KVAL(code) - charsets[i].start;
1730                         if (p->name[0])
1731                                 return p->name;
1732                 }
1733         }
1734
1735         else {                  /* Unicode keysym */
1736                 code ^= 0xf000;
1737
1738                 if (code < 0x80)
1739                         return iso646_syms[code];
1740
1741                 for (i = 0; i < sizeof(charsets)/sizeof(charsets[0]); i++) {
1742                         p = charsets[i].charnames;
1743                         if (!p)
1744                                 continue;
1745                         for (j = charsets[i].start; j < 256; j++, p++) {
1746                                 if (p->uni == code && p->name[0])
1747                                         return p->name;
1748                         }
1749                 }
1750         }
1751
1752         return NULL;
1753 }
1754
1755 /* Functions for loadkeys. */
1756
1757 int
1758 ksymtocode(struct keymap *kmap, const char *s, int direction) {
1759         unsigned int i;
1760         int j, jmax;
1761         int keycode;
1762         sym *p;
1763
1764         if (direction == TO_AUTO)
1765                 direction = kmap->prefer_unicode ? TO_UNICODE : TO_8BIT;
1766
1767         if (!strncmp(s, "Meta_", 5)) {
1768                 keycode = ksymtocode(kmap, s+5, TO_8BIT);
1769                 if (KTYP(keycode) == KT_LATIN)
1770                         return K(KT_META, KVAL(keycode));
1771
1772                 /* Avoid error messages for Meta_acute with UTF-8 */
1773                 else if(direction == TO_UNICODE)
1774                         return (0);
1775
1776                 /* fall through to error printf */
1777         }
1778
1779         for (i = 0; i < syms_size; i++) {
1780                 jmax = ((i == 0 && direction == TO_UNICODE) ? 128 : syms[i].size);
1781                 for (j = 0; j < jmax; j++)
1782                         if (!strcmp(s,syms[i].table[j]))
1783                                 return K(i, j);
1784         }
1785
1786         for (i = 0; i < syn_size; i++)
1787                 if (!strcmp(s, synonyms[i].synonym))
1788                         return ksymtocode(kmap, synonyms[i].official_name, direction);
1789
1790         if (direction == TO_UNICODE) {
1791                 for (i = 0; i < sizeof(charsets)/sizeof(charsets[0]); i++) {
1792                         p = charsets[i].charnames;
1793                         for (j = charsets[i].start; j < 256; j++, p++)
1794                                 if (!strcmp(s,p->name))
1795                                         return (p->uni ^ 0xf000);
1796                 }
1797         } else /* if (!chosen_charset[0]) */ {
1798                 /* note: some keymaps use latin1 but with euro,
1799                    so set_charset() would fail */
1800                 /* note: some keymaps with charset line still use
1801                    symbols from more than one character set,
1802                    so we cannot have the  `if (!chosen_charset[0])'  here */
1803
1804                 for (i = 0; i < 256 - 160; i++)
1805                         if (!strcmp(s, latin1_syms[i].name)) {
1806                                 log_verbose(kmap, LOG_VERBOSE1,
1807                                         _("assuming iso-8859-1 %s\n"), s);
1808                                 return K(KT_LATIN, 160 + i);
1809                         }
1810
1811                 for (i = 0; i < 256 - 160; i++)
1812                         if (!strcmp(s, iso_8859_15_syms[i].name)) {
1813                                 log_verbose(kmap, LOG_VERBOSE1,
1814                                         _("assuming iso-8859-15 %s\n"), s);
1815                                 return K(KT_LATIN, 160 + i);
1816                         }
1817
1818                 for (i = 0; i < 256 - 160; i++)
1819                         if (!strcmp(s, latin2_syms[i].name)) {
1820                                 log_verbose(kmap, LOG_VERBOSE1,
1821                                         _("assuming iso-8859-2 %s\n"), s);
1822                                 return K(KT_LATIN, 160 + i);
1823                         }
1824
1825                 for (i = 0; i < 256 - 160; i++)
1826                         if (!strcmp(s, latin3_syms[i].name)) {
1827                                 log_verbose(kmap, LOG_VERBOSE1,
1828                                         _("assuming iso-8859-3 %s\n"), s);
1829                                 return K(KT_LATIN, 160 + i);
1830                         }
1831
1832                 for (i = 0; i < 256 - 160; i++)
1833                         if (!strcmp(s, latin4_syms[i].name)) {
1834                                 log_verbose(kmap, LOG_VERBOSE1,
1835                                         _("assuming iso-8859-4 %s\n"), s);
1836                                 return K(KT_LATIN, 160 + i);
1837                         }
1838         }
1839
1840         log_error(kmap, _("unknown keysym '%s'\n"), s);
1841
1842         return CODE_FOR_UNKNOWN_KSYM;
1843 }
1844
1845 int
1846 convert_code(struct keymap *kmap, int code, int direction)
1847 {
1848         const char *ksym;
1849         int unicode_forced = (direction == TO_UNICODE);
1850         int input_is_unicode = (code >= 0x1000);
1851         int result;
1852
1853         if (direction == TO_AUTO)
1854                 direction = kmap->prefer_unicode ? TO_UNICODE : TO_8BIT;
1855
1856         if (KTYP(code) == KT_META)
1857                 return code;
1858         else if (!input_is_unicode && code < 0x80)
1859                 /* basic ASCII is fine in every situation */
1860                 return code;
1861         else if (input_is_unicode && (code ^ 0xf000) < 0x80)
1862                 /* so is Unicode "Basic Latin" */
1863                 return code ^ 0xf000;
1864         else if ((input_is_unicode && direction == TO_UNICODE) ||
1865                  (!input_is_unicode && direction == TO_8BIT))
1866                 /* no conversion necessary */
1867                 result = code;
1868         else {
1869                 /* depending on direction, this will give us either an 8-bit
1870                  * K(KTYP, KVAL) or a Unicode keysym xor 0xf000 */
1871                 ksym = codetoksym(code);
1872                 if (ksym)
1873                         result = ksymtocode(kmap, ksym, direction);
1874                 else
1875                         result = code;
1876         }
1877
1878         /* if direction was TO_UNICODE from the beginning, we return the true
1879          * Unicode value (without the 0xf000 mask) */
1880         if (unicode_forced && result >= 0x1000)
1881                 return result ^ 0xf000;
1882         else
1883                 return result;
1884 }
1885
1886 int
1887 add_capslock(struct keymap *kmap, int code)
1888 {
1889         if (KTYP(code) == KT_LATIN && (!(kmap->prefer_unicode) || code < 0x80))
1890                 return K(KT_LETTER, KVAL(code));
1891         else if ((code ^ 0xf000) < 0x100)
1892                 /* Unicode Latin-1 Supplement */
1893                 /* a bit dirty to use KT_LETTER here, but it should work */
1894                 return K(KT_LETTER, code ^ 0xf000);
1895         else
1896                 return convert_code(kmap, code, TO_AUTO);
1897 }