This repository has been archived by the owner on Jul 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
charsets.c
485 lines (448 loc) · 11.7 KB
/
charsets.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/* $XTermId: charsets.c,v 1.42 2011/09/11 14:40:17 tom Exp $ */
/*
* Copyright 1998-2009,2011 by Thomas E. Dickey
*
* All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name(s) of the above copyright
* holders shall not be used in advertising or otherwise to promote the
* sale, use or other dealings in this Software without prior written
* authorization.
*
*/
#include <xterm.h>
#include <data.h>
#include <fontutils.h>
#include <X11/keysym.h>
/*
* This module performs translation as needed to support the DEC VT220 national
* replacement character sets. We assume that xterm's font is based on the ISO
* 8859-1 (Latin 1) character set, which is almost the same as the DEC
* multinational character set. Glyph positions 0-31 have to be the DEC
* graphic characters, though.
*
* References:
* "VT220 Programmer Pocket Guide" EK-VT220-HR-002 (2nd ed., 1984), which
* contains character charts for the national character sets.
* "VT330/VT340 Programmer Reference Manual Volume 1: Text Programming"
* EK-VT3XX-TP-001 (1st ed, 1987), which contains a table (2-1)
* listing the glyphs which are mapped from the multinational
* character set to the national character set.
*
* The latter reference, though easier to read, has a few errors and omissions.
*/
/*
* Translate an input keysym to the corresponding NRC keysym.
*/
unsigned
xtermCharSetIn(unsigned code, int charset)
{
#define MAP(to, from) case from: code = to; break
if (code >= 128 && code < 256) {
switch (charset) {
case 'A': /* United Kingdom set (or Latin 1) */
if (code == XK_sterling)
code = 0x23;
code &= 0x7f;
break;
#if OPT_XMC_GLITCH
case '?':
#endif
case '1': /* Alternate Character ROM standard characters */
case '2': /* Alternate Character ROM special graphics */
case 'B': /* ASCII set */
break;
case '0': /* special graphics (line drawing) */
break;
case '4': /* Dutch */
switch (code) {
MAP(0x23, XK_sterling);
MAP(0x40, XK_threequarters);
MAP(0x5b, XK_ydiaeresis);
MAP(0x5c, XK_onehalf);
MAP(0x5d, XK_bar); /* glyph is not ISO-8859-1 */
MAP(0x7b, XK_diaeresis);
MAP(0x7c, XK_f); /* glyph is not ISO-8859-1 */
MAP(0x7d, XK_onequarter);
MAP(0x7e, XK_acute);
}
break;
case 'C':
case '5': /* Finnish */
switch (code) {
MAP(0x5b, XK_Adiaeresis);
MAP(0x5c, XK_Odiaeresis);
MAP(0x5d, XK_Aring);
MAP(0x5e, XK_Udiaeresis);
MAP(0x60, XK_eacute);
MAP(0x7b, XK_adiaeresis);
MAP(0x7c, XK_odiaeresis);
MAP(0x7d, XK_aring);
MAP(0x7e, XK_udiaeresis);
}
break;
case 'R': /* French */
switch (code) {
MAP(0x23, XK_sterling);
MAP(0x40, XK_agrave);
MAP(0x5b, XK_degree);
MAP(0x5c, XK_ccedilla);
MAP(0x5d, XK_section);
MAP(0x7b, XK_eacute);
MAP(0x7c, XK_ugrave);
MAP(0x7d, XK_egrave);
MAP(0x7e, XK_diaeresis);
}
break;
case 'Q': /* French Canadian */
switch (code) {
MAP(0x40, XK_agrave);
MAP(0x5b, XK_acircumflex);
MAP(0x5c, XK_ccedilla);
MAP(0x5d, XK_ecircumflex);
MAP(0x5e, XK_icircumflex);
MAP(0x60, XK_ocircumflex);
MAP(0x7b, XK_eacute);
MAP(0x7c, XK_ugrave);
MAP(0x7d, XK_egrave);
MAP(0x7e, XK_ucircumflex);
}
break;
case 'K': /* German */
switch (code) {
MAP(0x40, XK_section);
MAP(0x5b, XK_Adiaeresis);
MAP(0x5c, XK_Odiaeresis);
MAP(0x5d, XK_Udiaeresis);
MAP(0x7b, XK_adiaeresis);
MAP(0x7c, XK_odiaeresis);
MAP(0x7d, XK_udiaeresis);
MAP(0x7e, XK_ssharp);
}
break;
case 'Y': /* Italian */
switch (code) {
MAP(0x23, XK_sterling);
MAP(0x40, XK_section);
MAP(0x5b, XK_degree);
MAP(0x5c, XK_ccedilla);
MAP(0x5d, XK_eacute);
MAP(0x60, XK_ugrave);
MAP(0x7b, XK_agrave);
MAP(0x7c, XK_ograve);
MAP(0x7d, XK_egrave);
MAP(0x7e, XK_igrave);
}
break;
case 'E':
case '6': /* Norwegian/Danish */
switch (code) {
MAP(0x40, XK_Adiaeresis);
MAP(0x5b, XK_AE);
MAP(0x5c, XK_Ooblique);
MAP(0x5d, XK_Aring);
MAP(0x5e, XK_Udiaeresis);
MAP(0x60, XK_adiaeresis);
MAP(0x7b, XK_ae);
MAP(0x7c, XK_oslash);
MAP(0x7d, XK_aring);
MAP(0x7e, XK_udiaeresis);
}
break;
case 'Z': /* Spanish */
switch (code) {
MAP(0x23, XK_sterling);
MAP(0x40, XK_section);
MAP(0x5b, XK_exclamdown);
MAP(0x5c, XK_Ntilde);
MAP(0x5d, XK_questiondown);
MAP(0x7b, XK_degree);
MAP(0x7c, XK_ntilde);
MAP(0x7d, XK_ccedilla);
}
break;
case 'H':
case '7': /* Swedish */
switch (code) {
MAP(0x40, XK_Eacute);
MAP(0x5b, XK_Adiaeresis);
MAP(0x5c, XK_Odiaeresis);
MAP(0x5d, XK_Aring);
MAP(0x5e, XK_Udiaeresis);
MAP(0x60, XK_eacute);
MAP(0x7b, XK_adiaeresis);
MAP(0x7c, XK_odiaeresis);
MAP(0x7d, XK_aring);
MAP(0x7e, XK_udiaeresis);
}
break;
case '=': /* Swiss */
switch (code) {
MAP(0x23, XK_ugrave);
MAP(0x40, XK_agrave);
MAP(0x5b, XK_eacute);
MAP(0x5c, XK_ccedilla);
MAP(0x5d, XK_ecircumflex);
MAP(0x5e, XK_icircumflex);
MAP(0x5f, XK_egrave);
MAP(0x60, XK_ocircumflex);
MAP(0x7b, XK_adiaeresis);
MAP(0x7c, XK_odiaeresis);
MAP(0x7d, XK_udiaeresis);
MAP(0x7e, XK_ucircumflex);
}
break;
default: /* any character sets we don't recognize */
break;
}
code &= 0x7f; /* NRC in any case is 7-bit */
}
return code;
#undef MAP
}
/*
* Translate a string to the display form. This assumes the font has the
* DEC graphic characters in cells 0-31, and otherwise is ISO-8859-1.
*/
int
xtermCharSetOut(XtermWidget xw, IChar * buf, IChar * ptr, int leftset)
{
IChar *s;
TScreen *screen = TScreenOf(xw);
int count = 0;
int rightset = screen->gsets[(int) (screen->curgr)];
#define MAP(from, to) case from: chr = to; break
TRACE(("CHARSET GL=%c(G%d) GR=%c(G%d) SS%d\n\t%s\n",
leftset, screen->curgl,
rightset, screen->curgr,
screen->curss,
visibleIChar(buf, (unsigned) (ptr - buf))));
for (s = buf; s < ptr; ++s) {
int eight = CharOf(E2A(*s));
int seven = eight & 0x7f;
int cs = (eight >= 128) ? rightset : leftset;
int chr = eight;
count++;
#if OPT_WIDE_CHARS
/*
* This is only partly right - prevent inadvertant remapping of
* the replacement character and other non-8bit codes into bogus
* 8bit codes.
*/
if (screen->utf8_mode) {
if (*s > 255)
continue;
}
#endif
switch (cs) {
case 'A': /* United Kingdom set (or Latin 1) */
if ((xw->flags & NATIONAL)
|| (screen->vtXX_level <= 1)) {
if (chr == 0x23) {
#if OPT_WIDE_CHARS
chr = (screen->utf8_mode
? 0xa3
: XTERM_POUND);
#else
chr = XTERM_POUND;
#endif
}
} else {
chr = (seven | 0x80);
}
break;
#if OPT_XMC_GLITCH
case '?':
#endif
case '1': /* Alternate Character ROM standard characters */
case '2': /* Alternate Character ROM special graphics */
case 'B': /* ASCII set */
break;
case '0': /* special graphics (line drawing) */
if (seven > 0x5f && seven <= 0x7e) {
#if OPT_WIDE_CHARS
if (screen->utf8_mode)
chr = (int) dec2ucs((unsigned) (seven - 0x5f));
else
#endif
chr = seven - 0x5f;
} else {
chr = seven;
}
break;
case '4': /* Dutch */
switch (chr = seven) {
MAP(0x23, XK_sterling);
MAP(0x40, XK_threequarters);
MAP(0x5b, XK_ydiaeresis);
MAP(0x5c, XK_onehalf);
MAP(0x5d, XK_bar);
MAP(0x7b, XK_diaeresis);
MAP(0x7c, XK_f);
MAP(0x7d, XK_onequarter);
MAP(0x7e, XK_acute);
}
break;
case 'C':
case '5': /* Finnish */
switch (chr = seven) {
MAP(0x5b, XK_Adiaeresis);
MAP(0x5c, XK_Odiaeresis);
MAP(0x5d, XK_Aring);
MAP(0x5e, XK_Udiaeresis);
MAP(0x60, XK_eacute);
MAP(0x7b, XK_adiaeresis);
MAP(0x7c, XK_odiaeresis);
MAP(0x7d, XK_aring);
MAP(0x7e, XK_udiaeresis);
}
break;
case 'R': /* French */
switch (chr = seven) {
MAP(0x23, XK_sterling);
MAP(0x40, XK_agrave);
MAP(0x5b, XK_degree);
MAP(0x5c, XK_ccedilla);
MAP(0x5d, XK_section);
MAP(0x7b, XK_eacute);
MAP(0x7c, XK_ugrave);
MAP(0x7d, XK_egrave);
MAP(0x7e, XK_diaeresis);
}
break;
case 'Q': /* French Canadian */
switch (chr = seven) {
MAP(0x40, XK_agrave);
MAP(0x5b, XK_acircumflex);
MAP(0x5c, XK_ccedilla);
MAP(0x5d, XK_ecircumflex);
MAP(0x5e, XK_icircumflex);
MAP(0x60, XK_ocircumflex);
MAP(0x7b, XK_eacute);
MAP(0x7c, XK_ugrave);
MAP(0x7d, XK_egrave);
MAP(0x7e, XK_ucircumflex);
}
break;
case 'K': /* German */
switch (chr = seven) {
MAP(0x40, XK_section);
MAP(0x5b, XK_Adiaeresis);
MAP(0x5c, XK_Odiaeresis);
MAP(0x5d, XK_Udiaeresis);
MAP(0x7b, XK_adiaeresis);
MAP(0x7c, XK_odiaeresis);
MAP(0x7d, XK_udiaeresis);
MAP(0x7e, XK_ssharp);
}
break;
case 'Y': /* Italian */
switch (chr = seven) {
MAP(0x23, XK_sterling);
MAP(0x40, XK_section);
MAP(0x5b, XK_degree);
MAP(0x5c, XK_ccedilla);
MAP(0x5d, XK_eacute);
MAP(0x60, XK_ugrave);
MAP(0x7b, XK_agrave);
MAP(0x7c, XK_ograve);
MAP(0x7d, XK_egrave);
MAP(0x7e, XK_igrave);
}
break;
case 'E':
case '6': /* Norwegian/Danish */
switch (chr = seven) {
MAP(0x40, XK_Adiaeresis);
MAP(0x5b, XK_AE);
MAP(0x5c, XK_Ooblique);
MAP(0x5d, XK_Aring);
MAP(0x5e, XK_Udiaeresis);
MAP(0x60, XK_adiaeresis);
MAP(0x7b, XK_ae);
MAP(0x7c, XK_oslash);
MAP(0x7d, XK_aring);
MAP(0x7e, XK_udiaeresis);
}
break;
case 'Z': /* Spanish */
switch (chr = seven) {
MAP(0x23, XK_sterling);
MAP(0x40, XK_section);
MAP(0x5b, XK_exclamdown);
MAP(0x5c, XK_Ntilde);
MAP(0x5d, XK_questiondown);
MAP(0x7b, XK_degree);
MAP(0x7c, XK_ntilde);
MAP(0x7d, XK_ccedilla);
}
break;
case 'H':
case '7': /* Swedish */
switch (chr = seven) {
MAP(0x40, XK_Eacute);
MAP(0x5b, XK_Adiaeresis);
MAP(0x5c, XK_Odiaeresis);
MAP(0x5d, XK_Aring);
MAP(0x5e, XK_Udiaeresis);
MAP(0x60, XK_eacute);
MAP(0x7b, XK_adiaeresis);
MAP(0x7c, XK_odiaeresis);
MAP(0x7d, XK_aring);
MAP(0x7e, XK_udiaeresis);
}
break;
case '=': /* Swiss */
switch (chr = seven) {
MAP(0x23, XK_ugrave);
MAP(0x40, XK_agrave);
MAP(0x5b, XK_eacute);
MAP(0x5c, XK_ccedilla);
MAP(0x5d, XK_ecircumflex);
MAP(0x5e, XK_icircumflex);
MAP(0x5f, XK_egrave);
MAP(0x60, XK_ocircumflex);
MAP(0x7b, XK_adiaeresis);
MAP(0x7c, XK_odiaeresis);
MAP(0x7d, XK_udiaeresis);
MAP(0x7e, XK_ucircumflex);
}
break;
default: /* any character sets we don't recognize */
count--;
break;
}
/*
* The state machine already treated DEL as a nonprinting and
* nonspacing character. If we have DEL now, simply render
* it as a blank.
*/
if (chr == ANSI_DEL)
chr = ' ';
*s = (IChar) A2E(chr);
}
TRACE(("%d\t%s\n",
count,
visibleIChar(buf, (unsigned) (ptr - buf))));
return count;
#undef MAP
}