1
/* "$XConsortium: Lookup.c,v 1.12 90/12/11 13:19:10 rws Exp $"; */
4
* Copyright 1988, 1989 by the Massachusetts Institute of Technology
6
* Permission to use, copy, modify, and distribute this software and its
7
* documentation for any purpose and without fee is hereby granted, provided
8
* that the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of M.I.T. not be used in advertising
11
* or publicity pertaining to distribution of the software without specific,
12
* written prior permission. M.I.T. makes no representations about the
13
* suitability of this software for any purpose. It is provided "as is"
14
* without express or implied warranty.
19
#include <X11/Xutil.h>
22
#include <X11/keysymdef.h>
30
/* bit (1<<i) means character is in codeset i */
31
static unsigned short Const latin1[128] =
32
{0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
33
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
34
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
35
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
36
0x10ee, 0x0000, 0x1000, 0x1084, 0x102e, 0x1000, 0x1080, 0x108e, /* 10 */
37
0x108e, 0x1080, 0x0000, 0x1080, 0x1080, 0x10ee, 0x1000, 0x1008,
38
0x108e, 0x1080, 0x1084, 0x1084, 0x108e, 0x1004, 0x1000, 0x1084, /* 11 */
39
0x100e, 0x1000, 0x0000, 0x1080, 0x1000, 0x1084, 0x1000, 0x0000,
40
0x0004, 0x000e, 0x000e, 0x0008, 0x000e, 0x0008, 0x0008, 0x0006, /* 12 */
41
0x0004, 0x000e, 0x0004, 0x000e, 0x0004, 0x000e, 0x000e, 0x0004,
42
0x0000, 0x0004, 0x0004, 0x0006, 0x000e, 0x0008, 0x000e, 0x000e, /* 13 */
43
0x0008, 0x0004, 0x000e, 0x000c, 0x000e, 0x0002, 0x0000, 0x000e,
44
0x0004, 0x000e, 0x000e, 0x0008, 0x000e, 0x0008, 0x0008, 0x0006, /* 14 */
45
0x0004, 0x000e, 0x0004, 0x000e, 0x0004, 0x000e, 0x000e, 0x0004,
46
0x0000, 0x0004, 0x0004, 0x0006, 0x000e, 0x0008, 0x000e, 0x000e, /* 15 */
47
0x0008, 0x0004, 0x000e, 0x000c, 0x000e, 0x0002, 0x0000, 0x0000};
49
/* bit (1<<i) means character is in codeset i */
50
static unsigned short Const latin2[128] =
51
{0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
52
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
53
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
54
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
55
0x0000, 0x0008, 0x0004, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 10 */
56
0x0000, 0x0008, 0x0004, 0x0000, 0x0000, 0x0000, 0x0008, 0x0004,
57
0x0000, 0x0008, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0008, /* 11 */
58
0x0000, 0x0008, 0x0004, 0x0000, 0x0000, 0x0000, 0x0008, 0x0004,
59
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 12 */
60
0x0008, 0x0000, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
61
0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 13 */
62
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
63
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 14 */
64
0x0008, 0x0000, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
65
0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 15 */
66
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000c};
68
/* maps Cyrillic keysyms to 8859-5 */
69
static unsigned char Const cyrillic[128] =
70
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74
0x00, 0xf2, 0xf3, 0xf1, 0xf4, 0xf5, 0xf6, 0xf7, /* 10 */
75
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0x00, 0xfe, 0xff,
76
0xf0, 0xa2, 0xa3, 0xa1, 0xa4, 0xa5, 0xa6, 0xa7, /* 11 */
77
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0x00, 0xae, 0xaf,
78
0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3, /* 12 */
79
0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
80
0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2, /* 13 */
81
0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
82
0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3, /* 14 */
83
0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
84
0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2, /* 15 */
85
0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca};
87
/* maps Greek keysyms to 8859-7 */
88
static unsigned char Const greek[128] =
89
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93
0x00, 0xb6, 0xb8, 0xb9, 0xba, 0xda, 0x00, 0xbc, /* 10 */
94
0xbe, 0xdb, 0x00, 0xbf, 0x00, 0x00, 0xb5, 0xaf,
95
0x00, 0xdc, 0xdd, 0xde, 0xdf, 0xfa, 0xc0, 0xfc, /* 11 */
96
0xfd, 0xfb, 0xe0, 0xfe, 0x00, 0x00, 0x00, 0x00,
97
0x00, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 12 */
98
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
99
0xd0, 0xd1, 0xd3, 0x00, 0xd4, 0xd5, 0xd6, 0xd7, /* 13 */
100
0xd8, 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101
0x00, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, /* 14 */
102
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
103
0xf0, 0xf1, 0xf3, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7, /* 15 */
104
0xf8, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
111
#define sX0201 0x01000004
118
int XmuLookupString (event, buffer, nbytes, keysym, status, keysymSet)
119
register XKeyEvent *event;
123
XComposeStatus *status;
124
unsigned long keysymSet;
130
kset = keysymSet & 0xffffff;
131
count = XLookupString(event, buffer, nbytes, &symbol, status);
132
if (keysym) *keysym = symbol;
133
if ((nbytes == 0) || (symbol == NoSymbol)) {
135
} else if ((count == 0) && ((symbol >> 8) == kset)) {
139
buffer[0] = (symbol & 0xff);
140
if (buffer[0] == 0x7e)
144
buffer[0] = cyrillic[symbol & 0x7f];
147
buffer[0] = greek[symbol & 0x7f];
152
buffer[0] = (symbol & 0xff);
155
} else if ((keysymSet != 0) && (count == 1) &&
156
(((unsigned char *)buffer)[0] == symbol) &&
158
!(latin1[symbol & 0x7f] & (1 << kset))) {
159
if ((keysymSet == sHebrew) && (symbol == XK_multiply))
161
else if ((keysymSet == sHebrew) && (symbol == XK_division))
163
else if ((keysymSet == sCyrillic) && (symbol == XK_section))
165
else if ((keysymSet == sX0201) && (symbol == XK_yen))
169
} else if (count != 0) {
170
if ((keysymSet == sX0201) &&
171
((symbol == XK_backslash) || (symbol == XK_asciitilde)))
173
} else if (((symbol >> 8) == sLatin2) &&
174
(symbol & 0x80) && (latin2[symbol & 0x7f] & (1 << kset))) {
175
buffer[0] = (symbol & 0xff);
177
} else if ((keysymSet == sGreek) &&
178
((symbol == XK_leftsinglequotemark) ||
179
(symbol == XK_rightsinglequotemark))) {
180
buffer[0] = symbol - (XK_leftsinglequotemark - 0xa1);
186
/* produces ISO 8859-1 encoding plus ASCII control */
187
int XmuLookupLatin1 (event, buffer, nbytes, keysym, status)
188
register XKeyEvent *event;
192
XComposeStatus *status;
194
return XLookupString(event, buffer, nbytes, keysym, status);
197
/* produces ISO 8859-2 encoding plus ASCII control */
198
int XmuLookupLatin2 (event, buffer, nbytes, keysym, status)
199
register XKeyEvent *event;
203
XComposeStatus *status;
205
return XmuLookupString(event, buffer, nbytes, keysym, status, sLatin2);
208
/* produces ISO 8859-3 encoding plus ASCII control */
209
int XmuLookupLatin3 (event, buffer, nbytes, keysym, status)
210
register XKeyEvent *event;
214
XComposeStatus *status;
216
return XmuLookupString(event, buffer, nbytes, keysym, status, sLatin3);
219
/* produces ISO 8859-4 encoding plus ASCII control */
220
int XmuLookupLatin4 (event, buffer, nbytes, keysym, status)
221
register XKeyEvent *event;
225
XComposeStatus *status;
227
return XmuLookupString(event, buffer, nbytes, keysym, status, sLatin4);
230
/* produces ISO 8859-1 GL plus Katakana plus ASCII control */
231
int XmuLookupKana (event, buffer, nbytes, keysym, status)
232
register XKeyEvent *event;
236
XComposeStatus *status;
238
return XmuLookupString(event, buffer, nbytes, keysym, status, sKana);
241
/* produces JIS X0201-1976 (8-bit) */
242
int XmuLookupJISX0201 (event, buffer, nbytes, keysym, status)
243
register XKeyEvent *event;
247
XComposeStatus *status;
249
return XmuLookupString(event, buffer, nbytes, keysym, status, sX0201);
252
/* produces ISO 8859-6 encoding plus ASCII control */
253
int XmuLookupArabic (event, buffer, nbytes, keysym, status)
254
register XKeyEvent *event;
258
XComposeStatus *status;
260
return XmuLookupString(event, buffer, nbytes, keysym, status, sArabic);
263
/* produces ISO/IEC 8859-5 encoding plus ASCII control */
264
int XmuLookupCyrillic (event, buffer, nbytes, keysym, status)
265
register XKeyEvent *event;
269
XComposeStatus *status;
271
return XmuLookupString(event, buffer, nbytes, keysym, status, sCyrillic);
274
/* produces ISO 8859-7 encoding plus ASCII control */
275
int XmuLookupGreek (event, buffer, nbytes, keysym, status)
276
register XKeyEvent *event;
280
XComposeStatus *status;
282
return XmuLookupString(event, buffer, nbytes, keysym, status, sGreek);
285
/* XXX this character set needs work */
287
int XmuLookupAPL (event, buffer, nbytes, keysym, status)
288
register XKeyEvent *event;
292
XComposeStatus *status;
294
return XmuLookupString(event, buffer, nbytes, keysym, status, sAPL);
297
/* produces ISO 8859-8 encoding plus ASCII control */
298
int XmuLookupHebrew (event, buffer, nbytes, keysym, status)
299
register XKeyEvent *event;
303
XComposeStatus *status;
305
return XmuLookupString(event, buffer, nbytes, keysym, status, sHebrew);