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