chiark / gitweb /
terminal: add xkb-based keyboard devices to idev
[elogind.git] / src / libsystemd-terminal / term-charset.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com>
7
8   systemd 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.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 /*
23  * VTE Character Sets
24  * These are predefined charactersets that can be loaded into GL and GR. By
25  * default we use unicode_lower and unicode_upper, that is, both sets have the
26  * exact unicode mapping. unicode_lower is effectively ASCII and unicode_upper
27  * as defined by the unicode standard (I guess, ISO 8859-1).
28  * Several other character sets are defined here. However, all of them are
29  * limited to the 96 character space of GL or GR. Everything beyond GR (which
30  * was not supported by the classic VTs by DEC but is available in VT emulators
31  * that support unicode/UTF8) is always mapped to unicode and cannot be changed
32  * by these character sets. Even mapping GL and GR is only available for
33  * backwards compatibility as new applications can use the Unicode functionality
34  * of the VTE.
35  *
36  * Moreover, mapping GR is almost unnecessary to support. In fact, Unicode UTF-8
37  * support in VTE works by reading every incoming data as UTF-8 stream. This
38  * maps GL/ASCII to ASCII, as UTF-8 is backwards compatible to ASCII, however,
39  * everything that has the 8th bit set is a >=2-byte haracter in UTF-8. That is,
40  * this is in no way backwards compatible to >=VT220 8bit support. Therefore, if
41  * someone maps a character set into GR and wants to use them with this VTE,
42  * then they must already send UTF-8 characters to use GR (all GR characters are
43  * 8-bits). Hence, they can easily also send the correct UTF-8 character for the
44  * unicode mapping.
45  * The only advantage is that most characters in many sets are 3-byte UTF-8
46  * characters and by mapping the set into GR/GL you can use 2 or 1 byte UTF-8
47  * characters which saves bandwidth.
48  * Another reason is, if you have older applications that use the VT220 8-bit
49  * support and you put a ASCII/8bit-extension to UTF-8 converter in between, you
50  * need these mappings to have the application behave correctly if it uses GL/GR
51  * mappings extensively.
52  *
53  * Anyway, we support GL/GR mappings so here are the most commonly used maps as
54  * defined by Unicode-standard, DEC-private maps and other famous charmaps.
55  *
56  * Characters 1-32 are always the control characters (part of CL) and cannot be
57  * mapped. Characters 34-127 (94 characters) are part of GL and can be mapped.
58  * Characters 33 and 128 are not part of GL and always mapped by the VTE.
59  * However, for GR they can be mapped differently (96 chars) so we have to
60  * include them. The mapper has to take care not to use them in GL.
61  */
62
63 #include <errno.h>
64 #include <stdlib.h>
65 #include <string.h>
66 #include "term-internal.h"
67
68 /*
69  * Lower Unicode character set. This maps the characters to the basic ASCII
70  * characters 33-126. These are all graphics characters defined in ASCII.
71  */
72 term_charset term_unicode_lower = {
73         [0] = 32,
74         [1] = 33,
75         [2] = 34,
76         [3] = 35,
77         [4] = 36,
78         [5] = 37,
79         [6] = 38,
80         [7] = 39,
81         [8] = 40,
82         [9] = 41,
83         [10] = 42,
84         [11] = 43,
85         [12] = 44,
86         [13] = 45,
87         [14] = 46,
88         [15] = 47,
89         [16] = 48,
90         [17] = 49,
91         [18] = 50,
92         [19] = 51,
93         [20] = 52,
94         [21] = 53,
95         [22] = 54,
96         [23] = 55,
97         [24] = 56,
98         [25] = 57,
99         [26] = 58,
100         [27] = 59,
101         [28] = 60,
102         [29] = 61,
103         [30] = 62,
104         [31] = 63,
105         [32] = 64,
106         [33] = 65,
107         [34] = 66,
108         [35] = 67,
109         [36] = 68,
110         [37] = 69,
111         [38] = 70,
112         [39] = 71,
113         [40] = 72,
114         [41] = 73,
115         [42] = 74,
116         [43] = 75,
117         [44] = 76,
118         [45] = 77,
119         [46] = 78,
120         [47] = 79,
121         [48] = 80,
122         [49] = 81,
123         [50] = 82,
124         [51] = 83,
125         [52] = 84,
126         [53] = 85,
127         [54] = 86,
128         [55] = 87,
129         [56] = 88,
130         [57] = 89,
131         [58] = 90,
132         [59] = 91,
133         [60] = 92,
134         [61] = 93,
135         [62] = 94,
136         [63] = 95,
137         [64] = 96,
138         [65] = 97,
139         [66] = 98,
140         [67] = 99,
141         [68] = 100,
142         [69] = 101,
143         [70] = 102,
144         [71] = 103,
145         [72] = 104,
146         [73] = 105,
147         [74] = 106,
148         [75] = 107,
149         [76] = 108,
150         [77] = 109,
151         [78] = 110,
152         [79] = 111,
153         [80] = 112,
154         [81] = 113,
155         [82] = 114,
156         [83] = 115,
157         [84] = 116,
158         [85] = 117,
159         [86] = 118,
160         [87] = 119,
161         [88] = 120,
162         [89] = 121,
163         [90] = 122,
164         [91] = 123,
165         [92] = 124,
166         [93] = 125,
167         [94] = 126,
168         [95] = 127,
169 };
170
171 /*
172  * Upper Unicode Table
173  * This maps all characters to the upper unicode characters 161-254. These are
174  * not compatible to any older 8 bit character sets. See the Unicode standard
175  * for the definitions of each symbol.
176  */
177 term_charset term_unicode_upper = {
178         [0] = 160,
179         [1] = 161,
180         [2] = 162,
181         [3] = 163,
182         [4] = 164,
183         [5] = 165,
184         [6] = 166,
185         [7] = 167,
186         [8] = 168,
187         [9] = 169,
188         [10] = 170,
189         [11] = 171,
190         [12] = 172,
191         [13] = 173,
192         [14] = 174,
193         [15] = 175,
194         [16] = 176,
195         [17] = 177,
196         [18] = 178,
197         [19] = 179,
198         [20] = 180,
199         [21] = 181,
200         [22] = 182,
201         [23] = 183,
202         [24] = 184,
203         [25] = 185,
204         [26] = 186,
205         [27] = 187,
206         [28] = 188,
207         [29] = 189,
208         [30] = 190,
209         [31] = 191,
210         [32] = 192,
211         [33] = 193,
212         [34] = 194,
213         [35] = 195,
214         [36] = 196,
215         [37] = 197,
216         [38] = 198,
217         [39] = 199,
218         [40] = 200,
219         [41] = 201,
220         [42] = 202,
221         [43] = 203,
222         [44] = 204,
223         [45] = 205,
224         [46] = 206,
225         [47] = 207,
226         [48] = 208,
227         [49] = 209,
228         [50] = 210,
229         [51] = 211,
230         [52] = 212,
231         [53] = 213,
232         [54] = 214,
233         [55] = 215,
234         [56] = 216,
235         [57] = 217,
236         [58] = 218,
237         [59] = 219,
238         [60] = 220,
239         [61] = 221,
240         [62] = 222,
241         [63] = 223,
242         [64] = 224,
243         [65] = 225,
244         [66] = 226,
245         [67] = 227,
246         [68] = 228,
247         [69] = 229,
248         [70] = 230,
249         [71] = 231,
250         [72] = 232,
251         [73] = 233,
252         [74] = 234,
253         [75] = 235,
254         [76] = 236,
255         [77] = 237,
256         [78] = 238,
257         [79] = 239,
258         [80] = 240,
259         [81] = 241,
260         [82] = 242,
261         [83] = 243,
262         [84] = 244,
263         [85] = 245,
264         [86] = 246,
265         [87] = 247,
266         [88] = 248,
267         [89] = 249,
268         [90] = 250,
269         [91] = 251,
270         [92] = 252,
271         [93] = 253,
272         [94] = 254,
273         [95] = 255,
274 };
275
276 /*
277  * The DEC supplemental graphics set. For its definition see here:
278  *  http://vt100.net/docs/vt220-rm/table2-3b.html
279  * Its basically a mixture of common European symbols that are not part of
280  * ASCII. Most often, this is mapped into GR to extend the basci ASCII part.
281  *
282  * This is very similar to unicode_upper, however, few symbols differ so do not
283  * mix them up!
284  */
285 term_charset term_dec_supplemental_graphics = {
286         [0] = -1,       /* undefined */
287         [1] = 161,
288         [2] = 162,
289         [3] = 163,
290         [4] = 0,
291         [5] = 165,
292         [6] = 0,
293         [7] = 167,
294         [8] = 164,
295         [9] = 169,
296         [10] = 170,
297         [11] = 171,
298         [12] = 0,
299         [13] = 0,
300         [14] = 0,
301         [15] = 0,
302         [16] = 176,
303         [17] = 177,
304         [18] = 178,
305         [19] = 179,
306         [20] = 0,
307         [21] = 181,
308         [22] = 182,
309         [23] = 183,
310         [24] = 0,
311         [25] = 185,
312         [26] = 186,
313         [27] = 187,
314         [28] = 188,
315         [29] = 189,
316         [30] = 0,
317         [31] = 191,
318         [32] = 192,
319         [33] = 193,
320         [34] = 194,
321         [35] = 195,
322         [36] = 196,
323         [37] = 197,
324         [38] = 198,
325         [39] = 199,
326         [40] = 200,
327         [41] = 201,
328         [42] = 202,
329         [43] = 203,
330         [44] = 204,
331         [45] = 205,
332         [46] = 206,
333         [47] = 207,
334         [48] = 0,
335         [49] = 209,
336         [50] = 210,
337         [51] = 211,
338         [52] = 212,
339         [53] = 213,
340         [54] = 214,
341         [55] = 338,
342         [56] = 216,
343         [57] = 217,
344         [58] = 218,
345         [59] = 219,
346         [60] = 220,
347         [61] = 376,
348         [62] = 0,
349         [63] = 223,
350         [64] = 224,
351         [65] = 225,
352         [66] = 226,
353         [67] = 227,
354         [68] = 228,
355         [69] = 229,
356         [70] = 230,
357         [71] = 231,
358         [72] = 232,
359         [73] = 233,
360         [74] = 234,
361         [75] = 235,
362         [76] = 236,
363         [77] = 237,
364         [78] = 238,
365         [79] = 239,
366         [80] = 0,
367         [81] = 241,
368         [82] = 242,
369         [83] = 243,
370         [84] = 244,
371         [85] = 245,
372         [86] = 246,
373         [87] = 339,
374         [88] = 248,
375         [89] = 249,
376         [90] = 250,
377         [91] = 251,
378         [92] = 252,
379         [93] = 255,
380         [94] = 0,
381         [95] = -1,       /* undefined */
382 };
383
384 /*
385  * DEC special graphics character set. See here for its definition:
386  *  http://vt100.net/docs/vt220-rm/table2-4.html
387  * This contains several characters to create ASCII drawings and similar. Its
388  * commonly mapped into GR to extend the basic ASCII characters.
389  *
390  * Lower 62 characters map to ASCII 33-64, everything beyond is special and
391  * commonly used for ASCII drawings. It depends on the Unicode Standard 3.2 for
392  * the extended horizontal scan-line characters 3, 5, 7, and 9.
393  */
394 term_charset term_dec_special_graphics = {
395         [0] = -1,       /* undefined */
396         [1] = 33,
397         [2] = 34,
398         [3] = 35,
399         [4] = 36,
400         [5] = 37,
401         [6] = 38,
402         [7] = 39,
403         [8] = 40,
404         [9] = 41,
405         [10] = 42,
406         [11] = 43,
407         [12] = 44,
408         [13] = 45,
409         [14] = 46,
410         [15] = 47,
411         [16] = 48,
412         [17] = 49,
413         [18] = 50,
414         [19] = 51,
415         [20] = 52,
416         [21] = 53,
417         [22] = 54,
418         [23] = 55,
419         [24] = 56,
420         [25] = 57,
421         [26] = 58,
422         [27] = 59,
423         [28] = 60,
424         [29] = 61,
425         [30] = 62,
426         [31] = 63,
427         [32] = 64,
428         [33] = 65,
429         [34] = 66,
430         [35] = 67,
431         [36] = 68,
432         [37] = 69,
433         [38] = 70,
434         [39] = 71,
435         [40] = 72,
436         [41] = 73,
437         [42] = 74,
438         [43] = 75,
439         [44] = 76,
440         [45] = 77,
441         [46] = 78,
442         [47] = 79,
443         [48] = 80,
444         [49] = 81,
445         [50] = 82,
446         [51] = 83,
447         [52] = 84,
448         [53] = 85,
449         [54] = 86,
450         [55] = 87,
451         [56] = 88,
452         [57] = 89,
453         [58] = 90,
454         [59] = 91,
455         [60] = 92,
456         [61] = 93,
457         [62] = 94,
458         [63] = 0,
459         [64] = 9830,
460         [65] = 9618,
461         [66] = 9225,
462         [67] = 9228,
463         [68] = 9229,
464         [69] = 9226,
465         [70] = 176,
466         [71] = 177,
467         [72] = 9252,
468         [73] = 9227,
469         [74] = 9496,
470         [75] = 9488,
471         [76] = 9484,
472         [77] = 9492,
473         [78] = 9532,
474         [79] = 9146,
475         [80] = 9147,
476         [81] = 9472,
477         [82] = 9148,
478         [83] = 9149,
479         [84] = 9500,
480         [85] = 9508,
481         [86] = 9524,
482         [87] = 9516,
483         [88] = 9474,
484         [89] = 8804,
485         [90] = 8805,
486         [91] = 960,
487         [92] = 8800,
488         [93] = 163,
489         [94] = 8901,
490         [95] = -1,      /* undefined */
491 };