1// This is an open source non-commercial project. Dear PVS-Studio, please check
2// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3
4/// @file digraph.c
5///
6/// code for digraphs
7
8#include <assert.h>
9#include <stdbool.h>
10#include <inttypes.h>
11
12#include "nvim/vim.h"
13#include "nvim/ascii.h"
14#include "nvim/digraph.h"
15#include "nvim/charset.h"
16#include "nvim/ex_cmds2.h"
17#include "nvim/ex_docmd.h"
18#include "nvim/ex_getln.h"
19#include "nvim/getchar.h"
20#include "nvim/misc1.h"
21#include "nvim/mbyte.h"
22#include "nvim/message.h"
23#include "nvim/memory.h"
24#include "nvim/garray.h"
25#include "nvim/normal.h"
26#include "nvim/screen.h"
27#include "nvim/strings.h"
28#include "nvim/os/input.h"
29
30typedef int result_T;
31
32typedef struct digraph {
33 char_u char1;
34 char_u char2;
35 result_T result;
36} digr_T;
37
38
39#ifdef INCLUDE_GENERATED_DECLARATIONS
40# include "digraph.c.generated.h"
41#endif
42// digraphs added by the user
43static garray_T user_digraphs = {0, 0, (int)sizeof(digr_T), 10, NULL};
44
45/// Note: Characters marked with XX are not included literally, because some
46/// compilers cannot handle them (Amiga SAS/C is the most picky one).
47static digr_T digraphdefault[] =
48
49// digraphs for Unicode from RFC1345
50// (also work for ISO-8859-1 aka latin1)
51{
52 { 'N', 'U', 0x0a }, // LF for NUL
53 { 'S', 'H', 0x01 },
54 { 'S', 'X', 0x02 },
55 { 'E', 'X', 0x03 },
56 { 'E', 'T', 0x04 },
57 { 'E', 'Q', 0x05 },
58 { 'A', 'K', 0x06 },
59 { 'B', 'L', 0x07 },
60 { 'B', 'S', 0x08 },
61 { 'H', 'T', 0x09 },
62 { 'L', 'F', 0x0a },
63 { 'V', 'T', 0x0b },
64 { 'F', 'F', 0x0c },
65 { 'C', 'R', 0x0d },
66 { 'S', 'O', 0x0e },
67 { 'S', 'I', 0x0f },
68 { 'D', 'L', 0x10 },
69 { 'D', '1', 0x11 },
70 { 'D', '2', 0x12 },
71 { 'D', '3', 0x13 },
72 { 'D', '4', 0x14 },
73 { 'N', 'K', 0x15 },
74 { 'S', 'Y', 0x16 },
75 { 'E', 'B', 0x17 },
76 { 'C', 'N', 0x18 },
77 { 'E', 'M', 0x19 },
78 { 'S', 'B', 0x1a },
79 { 'E', 'C', 0x1b },
80 { 'F', 'S', 0x1c },
81 { 'G', 'S', 0x1d },
82 { 'R', 'S', 0x1e },
83 { 'U', 'S', 0x1f },
84 { 'S', 'P', 0x20 },
85 { 'N', 'b', 0x23 },
86 { 'D', 'O', 0x24 },
87 { 'A', 't', 0x40 },
88 { '<', '(', 0x5b },
89 { '/', '/', 0x5c },
90 { ')', '>', 0x5d },
91 { '\'', '>', 0x5e },
92 { '\'', '!', 0x60 },
93 { '(', '!', 0x7b },
94 { '!', '!', 0x7c },
95 { '!', ')', 0x7d },
96 { '\'', '?', 0x7e },
97 { 'D', 'T', 0x7f },
98 { 'P', 'A', 0x80 },
99 { 'H', 'O', 0x81 },
100 { 'B', 'H', 0x82 },
101 { 'N', 'H', 0x83 },
102 { 'I', 'N', 0x84 },
103 { 'N', 'L', 0x85 },
104 { 'S', 'A', 0x86 },
105 { 'E', 'S', 0x87 },
106 { 'H', 'S', 0x88 },
107 { 'H', 'J', 0x89 },
108 { 'V', 'S', 0x8a },
109 { 'P', 'D', 0x8b },
110 { 'P', 'U', 0x8c },
111 { 'R', 'I', 0x8d },
112 { 'S', '2', 0x8e },
113 { 'S', '3', 0x8f },
114 { 'D', 'C', 0x90 },
115 { 'P', '1', 0x91 },
116 { 'P', '2', 0x92 },
117 { 'T', 'S', 0x93 },
118 { 'C', 'C', 0x94 },
119 { 'M', 'W', 0x95 },
120 { 'S', 'G', 0x96 },
121 { 'E', 'G', 0x97 },
122 { 'S', 'S', 0x98 },
123 { 'G', 'C', 0x99 },
124 { 'S', 'C', 0x9a },
125 { 'C', 'I', 0x9b },
126 { 'S', 'T', 0x9c },
127 { 'O', 'C', 0x9d },
128 { 'P', 'M', 0x9e },
129 { 'A', 'C', 0x9f },
130 { 'N', 'S', 0xa0 },
131 { '!', 'I', 0xa1 },
132 { 'C', 't', 0xa2 },
133 { 'P', 'd', 0xa3 },
134 { 'C', 'u', 0xa4 },
135 { 'Y', 'e', 0xa5 },
136 { 'B', 'B', 0xa6 },
137 { 'S', 'E', 0xa7 },
138 { '\'', ':', 0xa8 },
139 { 'C', 'o', 0xa9 },
140 { '-', 'a', 0xaa },
141 { '<', '<', 0xab },
142 { 'N', 'O', 0xac },
143 { '-', '-', 0xad },
144 { 'R', 'g', 0xae },
145 { '\'', 'm', 0xaf },
146 { 'D', 'G', 0xb0 },
147 { '+', '-', 0xb1 },
148 { '2', 'S', 0xb2 },
149 { '3', 'S', 0xb3 },
150 { '\'', '\'', 0xb4 },
151 { 'M', 'y', 0xb5 },
152 { 'P', 'I', 0xb6 },
153 { '.', 'M', 0xb7 },
154 { '\'', ',', 0xb8 },
155 { '1', 'S', 0xb9 },
156 { '-', 'o', 0xba },
157 { '>', '>', 0xbb },
158 { '1', '4', 0xbc },
159 { '1', '2', 0xbd },
160 { '3', '4', 0xbe },
161 { '?', 'I', 0xbf },
162 { 'A', '!', 0xc0 },
163 { 'A', '\'', 0xc1 },
164 { 'A', '>', 0xc2 },
165 { 'A', '?', 0xc3 },
166 { 'A', ':', 0xc4 },
167 { 'A', 'A', 0xc5 },
168 { 'A', 'E', 0xc6 },
169 { 'C', ',', 0xc7 },
170 { 'E', '!', 0xc8 },
171 { 'E', '\'', 0xc9 },
172 { 'E', '>', 0xca },
173 { 'E', ':', 0xcb },
174 { 'I', '!', 0xcc },
175 { 'I', '\'', 0xcd },
176 { 'I', '>', 0xce },
177 { 'I', ':', 0xcf },
178 { 'D', '-', 0xd0 },
179 { 'N', '?', 0xd1 },
180 { 'O', '!', 0xd2 },
181 { 'O', '\'', 0xd3 },
182 { 'O', '>', 0xd4 },
183 { 'O', '?', 0xd5 },
184 { 'O', ':', 0xd6 },
185 { '*', 'X', 0xd7 },
186 { 'O', '/', 0xd8 },
187 { 'U', '!', 0xd9 },
188 { 'U', '\'', 0xda },
189 { 'U', '>', 0xdb },
190 { 'U', ':', 0xdc },
191 { 'Y', '\'', 0xdd },
192 { 'T', 'H', 0xde },
193 { 's', 's', 0xdf },
194 { 'a', '!', 0xe0 },
195 { 'a', '\'', 0xe1 },
196 { 'a', '>', 0xe2 },
197 { 'a', '?', 0xe3 },
198 { 'a', ':', 0xe4 },
199 { 'a', 'a', 0xe5 },
200 { 'a', 'e', 0xe6 },
201 { 'c', ',', 0xe7 },
202 { 'e', '!', 0xe8 },
203 { 'e', '\'', 0xe9 },
204 { 'e', '>', 0xea },
205 { 'e', ':', 0xeb },
206 { 'i', '!', 0xec },
207 { 'i', '\'', 0xed },
208 { 'i', '>', 0xee },
209 { 'i', ':', 0xef },
210 { 'd', '-', 0xf0 },
211 { 'n', '?', 0xf1 },
212 { 'o', '!', 0xf2 },
213 { 'o', '\'', 0xf3 },
214 { 'o', '>', 0xf4 },
215 { 'o', '?', 0xf5 },
216 { 'o', ':', 0xf6 },
217 { '-', ':', 0xf7 },
218 { 'o', '/', 0xf8 },
219 { 'u', '!', 0xf9 },
220 { 'u', '\'', 0xfa },
221 { 'u', '>', 0xfb },
222 { 'u', ':', 0xfc },
223 { 'y', '\'', 0xfd },
224 { 't', 'h', 0xfe },
225 { 'y', ':', 0xff },
226
227 { 'A', '-', 0x0100 },
228 { 'a', '-', 0x0101 },
229 { 'A', '(', 0x0102 },
230 { 'a', '(', 0x0103 },
231 { 'A', ';', 0x0104 },
232 { 'a', ';', 0x0105 },
233 { 'C', '\'', 0x0106 },
234 { 'c', '\'', 0x0107 },
235 { 'C', '>', 0x0108 },
236 { 'c', '>', 0x0109 },
237 { 'C', '.', 0x010a },
238 { 'c', '.', 0x010b },
239 { 'C', '<', 0x010c },
240 { 'c', '<', 0x010d },
241 { 'D', '<', 0x010e },
242 { 'd', '<', 0x010f },
243 { 'D', '/', 0x0110 },
244 { 'd', '/', 0x0111 },
245 { 'E', '-', 0x0112 },
246 { 'e', '-', 0x0113 },
247 { 'E', '(', 0x0114 },
248 { 'e', '(', 0x0115 },
249 { 'E', '.', 0x0116 },
250 { 'e', '.', 0x0117 },
251 { 'E', ';', 0x0118 },
252 { 'e', ';', 0x0119 },
253 { 'E', '<', 0x011a },
254 { 'e', '<', 0x011b },
255 { 'G', '>', 0x011c },
256 { 'g', '>', 0x011d },
257 { 'G', '(', 0x011e },
258 { 'g', '(', 0x011f },
259 { 'G', '.', 0x0120 },
260 { 'g', '.', 0x0121 },
261 { 'G', ',', 0x0122 },
262 { 'g', ',', 0x0123 },
263 { 'H', '>', 0x0124 },
264 { 'h', '>', 0x0125 },
265 { 'H', '/', 0x0126 },
266 { 'h', '/', 0x0127 },
267 { 'I', '?', 0x0128 },
268 { 'i', '?', 0x0129 },
269 { 'I', '-', 0x012a },
270 { 'i', '-', 0x012b },
271 { 'I', '(', 0x012c },
272 { 'i', '(', 0x012d },
273 { 'I', ';', 0x012e },
274 { 'i', ';', 0x012f },
275 { 'I', '.', 0x0130 },
276 { 'i', '.', 0x0131 },
277 { 'I', 'J', 0x0132 },
278 { 'i', 'j', 0x0133 },
279 { 'J', '>', 0x0134 },
280 { 'j', '>', 0x0135 },
281 { 'K', ',', 0x0136 },
282 { 'k', ',', 0x0137 },
283 { 'k', 'k', 0x0138 },
284 { 'L', '\'', 0x0139 },
285 { 'l', '\'', 0x013a },
286 { 'L', ',', 0x013b },
287 { 'l', ',', 0x013c },
288 { 'L', '<', 0x013d },
289 { 'l', '<', 0x013e },
290 { 'L', '.', 0x013f },
291 { 'l', '.', 0x0140 },
292 { 'L', '/', 0x0141 },
293 { 'l', '/', 0x0142 },
294 { 'N', '\'', 0x0143 },
295 { 'n', '\'', 0x0144 },
296 { 'N', ',', 0x0145 },
297 { 'n', ',', 0x0146 },
298 { 'N', '<', 0x0147 },
299 { 'n', '<', 0x0148 },
300 { '\'', 'n', 0x0149 },
301 { 'N', 'G', 0x014a },
302 { 'n', 'g', 0x014b },
303 { 'O', '-', 0x014c },
304 { 'o', '-', 0x014d },
305 { 'O', '(', 0x014e },
306 { 'o', '(', 0x014f },
307 { 'O', '"', 0x0150 },
308 { 'o', '"', 0x0151 },
309 { 'O', 'E', 0x0152 },
310 { 'o', 'e', 0x0153 },
311 { 'R', '\'', 0x0154 },
312 { 'r', '\'', 0x0155 },
313 { 'R', ',', 0x0156 },
314 { 'r', ',', 0x0157 },
315 { 'R', '<', 0x0158 },
316 { 'r', '<', 0x0159 },
317 { 'S', '\'', 0x015a },
318 { 's', '\'', 0x015b },
319 { 'S', '>', 0x015c },
320 { 's', '>', 0x015d },
321 { 'S', ',', 0x015e },
322 { 's', ',', 0x015f },
323 { 'S', '<', 0x0160 },
324 { 's', '<', 0x0161 },
325 { 'T', ',', 0x0162 },
326 { 't', ',', 0x0163 },
327 { 'T', '<', 0x0164 },
328 { 't', '<', 0x0165 },
329 { 'T', '/', 0x0166 },
330 { 't', '/', 0x0167 },
331 { 'U', '?', 0x0168 },
332 { 'u', '?', 0x0169 },
333 { 'U', '-', 0x016a },
334 { 'u', '-', 0x016b },
335 { 'U', '(', 0x016c },
336 { 'u', '(', 0x016d },
337 { 'U', '0', 0x016e },
338 { 'u', '0', 0x016f },
339 { 'U', '"', 0x0170 },
340 { 'u', '"', 0x0171 },
341 { 'U', ';', 0x0172 },
342 { 'u', ';', 0x0173 },
343 { 'W', '>', 0x0174 },
344 { 'w', '>', 0x0175 },
345 { 'Y', '>', 0x0176 },
346 { 'y', '>', 0x0177 },
347 { 'Y', ':', 0x0178 },
348 { 'Z', '\'', 0x0179 },
349 { 'z', '\'', 0x017a },
350 { 'Z', '.', 0x017b },
351 { 'z', '.', 0x017c },
352 { 'Z', '<', 0x017d },
353 { 'z', '<', 0x017e },
354 { 'O', '9', 0x01a0 },
355 { 'o', '9', 0x01a1 },
356 { 'O', 'I', 0x01a2 },
357 { 'o', 'i', 0x01a3 },
358 { 'y', 'r', 0x01a6 },
359 { 'U', '9', 0x01af },
360 { 'u', '9', 0x01b0 },
361 { 'Z', '/', 0x01b5 },
362 { 'z', '/', 0x01b6 },
363 { 'E', 'D', 0x01b7 },
364 { 'A', '<', 0x01cd },
365 { 'a', '<', 0x01ce },
366 { 'I', '<', 0x01cf },
367 { 'i', '<', 0x01d0 },
368 { 'O', '<', 0x01d1 },
369 { 'o', '<', 0x01d2 },
370 { 'U', '<', 0x01d3 },
371 { 'u', '<', 0x01d4 },
372 { 'A', '1', 0x01de },
373 { 'a', '1', 0x01df },
374 { 'A', '7', 0x01e0 },
375 { 'a', '7', 0x01e1 },
376 { 'A', '3', 0x01e2 },
377 { 'a', '3', 0x01e3 },
378 { 'G', '/', 0x01e4 },
379 { 'g', '/', 0x01e5 },
380 { 'G', '<', 0x01e6 },
381 { 'g', '<', 0x01e7 },
382 { 'K', '<', 0x01e8 },
383 { 'k', '<', 0x01e9 },
384 { 'O', ';', 0x01ea },
385 { 'o', ';', 0x01eb },
386 { 'O', '1', 0x01ec },
387 { 'o', '1', 0x01ed },
388 { 'E', 'Z', 0x01ee },
389 { 'e', 'z', 0x01ef },
390 { 'j', '<', 0x01f0 },
391 { 'G', '\'', 0x01f4 },
392 { 'g', '\'', 0x01f5 },
393 { ';', 'S', 0x02bf },
394 { '\'', '<', 0x02c7 },
395 { '\'', '(', 0x02d8 },
396 { '\'', '.', 0x02d9 },
397 { '\'', '0', 0x02da },
398 { '\'', ';', 0x02db },
399 { '\'', '"', 0x02dd },
400 { 'A', '%', 0x0386 },
401 { 'E', '%', 0x0388 },
402 { 'Y', '%', 0x0389 },
403 { 'I', '%', 0x038a },
404 { 'O', '%', 0x038c },
405 { 'U', '%', 0x038e },
406 { 'W', '%', 0x038f },
407 { 'i', '3', 0x0390 },
408 { 'A', '*', 0x0391 },
409 { 'B', '*', 0x0392 },
410 { 'G', '*', 0x0393 },
411 { 'D', '*', 0x0394 },
412 { 'E', '*', 0x0395 },
413 { 'Z', '*', 0x0396 },
414 { 'Y', '*', 0x0397 },
415 { 'H', '*', 0x0398 },
416 { 'I', '*', 0x0399 },
417 { 'K', '*', 0x039a },
418 { 'L', '*', 0x039b },
419 { 'M', '*', 0x039c },
420 { 'N', '*', 0x039d },
421 { 'C', '*', 0x039e },
422 { 'O', '*', 0x039f },
423 { 'P', '*', 0x03a0 },
424 { 'R', '*', 0x03a1 },
425 { 'S', '*', 0x03a3 },
426 { 'T', '*', 0x03a4 },
427 { 'U', '*', 0x03a5 },
428 { 'F', '*', 0x03a6 },
429 { 'X', '*', 0x03a7 },
430 { 'Q', '*', 0x03a8 },
431 { 'W', '*', 0x03a9 },
432 { 'J', '*', 0x03aa },
433 { 'V', '*', 0x03ab },
434 { 'a', '%', 0x03ac },
435 { 'e', '%', 0x03ad },
436 { 'y', '%', 0x03ae },
437 { 'i', '%', 0x03af },
438 { 'u', '3', 0x03b0 },
439 { 'a', '*', 0x03b1 },
440 { 'b', '*', 0x03b2 },
441 { 'g', '*', 0x03b3 },
442 { 'd', '*', 0x03b4 },
443 { 'e', '*', 0x03b5 },
444 { 'z', '*', 0x03b6 },
445 { 'y', '*', 0x03b7 },
446 { 'h', '*', 0x03b8 },
447 { 'i', '*', 0x03b9 },
448 { 'k', '*', 0x03ba },
449 { 'l', '*', 0x03bb },
450 { 'm', '*', 0x03bc },
451 { 'n', '*', 0x03bd },
452 { 'c', '*', 0x03be },
453 { 'o', '*', 0x03bf },
454 { 'p', '*', 0x03c0 },
455 { 'r', '*', 0x03c1 },
456 { '*', 's', 0x03c2 },
457 { 's', '*', 0x03c3 },
458 { 't', '*', 0x03c4 },
459 { 'u', '*', 0x03c5 },
460 { 'f', '*', 0x03c6 },
461 { 'x', '*', 0x03c7 },
462 { 'q', '*', 0x03c8 },
463 { 'w', '*', 0x03c9 },
464 { 'j', '*', 0x03ca },
465 { 'v', '*', 0x03cb },
466 { 'o', '%', 0x03cc },
467 { 'u', '%', 0x03cd },
468 { 'w', '%', 0x03ce },
469 { '\'', 'G', 0x03d8 },
470 { ',', 'G', 0x03d9 },
471 { 'T', '3', 0x03da },
472 { 't', '3', 0x03db },
473 { 'M', '3', 0x03dc },
474 { 'm', '3', 0x03dd },
475 { 'K', '3', 0x03de },
476 { 'k', '3', 0x03df },
477 { 'P', '3', 0x03e0 },
478 { 'p', '3', 0x03e1 },
479 { '\'', '%', 0x03f4 },
480 { 'j', '3', 0x03f5 },
481 { 'I', 'O', 0x0401 },
482 { 'D', '%', 0x0402 },
483 { 'G', '%', 0x0403 },
484 { 'I', 'E', 0x0404 },
485 { 'D', 'S', 0x0405 },
486 { 'I', 'I', 0x0406 },
487 { 'Y', 'I', 0x0407 },
488 { 'J', '%', 0x0408 },
489 { 'L', 'J', 0x0409 },
490 { 'N', 'J', 0x040a },
491 { 'T', 's', 0x040b },
492 { 'K', 'J', 0x040c },
493 { 'V', '%', 0x040e },
494 { 'D', 'Z', 0x040f },
495 { 'A', '=', 0x0410 },
496 { 'B', '=', 0x0411 },
497 { 'V', '=', 0x0412 },
498 { 'G', '=', 0x0413 },
499 { 'D', '=', 0x0414 },
500 { 'E', '=', 0x0415 },
501 { 'Z', '%', 0x0416 },
502 { 'Z', '=', 0x0417 },
503 { 'I', '=', 0x0418 },
504 { 'J', '=', 0x0419 },
505 { 'K', '=', 0x041a },
506 { 'L', '=', 0x041b },
507 { 'M', '=', 0x041c },
508 { 'N', '=', 0x041d },
509 { 'O', '=', 0x041e },
510 { 'P', '=', 0x041f },
511 { 'R', '=', 0x0420 },
512 { 'S', '=', 0x0421 },
513 { 'T', '=', 0x0422 },
514 { 'U', '=', 0x0423 },
515 { 'F', '=', 0x0424 },
516 { 'H', '=', 0x0425 },
517 { 'C', '=', 0x0426 },
518 { 'C', '%', 0x0427 },
519 { 'S', '%', 0x0428 },
520 { 'S', 'c', 0x0429 },
521 { '=', '"', 0x042a },
522 { 'Y', '=', 0x042b },
523 { '%', '"', 0x042c },
524 { 'J', 'E', 0x042d },
525 { 'J', 'U', 0x042e },
526 { 'J', 'A', 0x042f },
527 { 'a', '=', 0x0430 },
528 { 'b', '=', 0x0431 },
529 { 'v', '=', 0x0432 },
530 { 'g', '=', 0x0433 },
531 { 'd', '=', 0x0434 },
532 { 'e', '=', 0x0435 },
533 { 'z', '%', 0x0436 },
534 { 'z', '=', 0x0437 },
535 { 'i', '=', 0x0438 },
536 { 'j', '=', 0x0439 },
537 { 'k', '=', 0x043a },
538 { 'l', '=', 0x043b },
539 { 'm', '=', 0x043c },
540 { 'n', '=', 0x043d },
541 { 'o', '=', 0x043e },
542 { 'p', '=', 0x043f },
543 { 'r', '=', 0x0440 },
544 { 's', '=', 0x0441 },
545 { 't', '=', 0x0442 },
546 { 'u', '=', 0x0443 },
547 { 'f', '=', 0x0444 },
548 { 'h', '=', 0x0445 },
549 { 'c', '=', 0x0446 },
550 { 'c', '%', 0x0447 },
551 { 's', '%', 0x0448 },
552 { 's', 'c', 0x0449 },
553 { '=', '\'', 0x044a },
554 { 'y', '=', 0x044b },
555 { '%', '\'', 0x044c },
556 { 'j', 'e', 0x044d },
557 { 'j', 'u', 0x044e },
558 { 'j', 'a', 0x044f },
559 { 'i', 'o', 0x0451 },
560 { 'd', '%', 0x0452 },
561 { 'g', '%', 0x0453 },
562 { 'i', 'e', 0x0454 },
563 { 'd', 's', 0x0455 },
564 { 'i', 'i', 0x0456 },
565 { 'y', 'i', 0x0457 },
566 { 'j', '%', 0x0458 },
567 { 'l', 'j', 0x0459 },
568 { 'n', 'j', 0x045a },
569 { 't', 's', 0x045b },
570 { 'k', 'j', 0x045c },
571 { 'v', '%', 0x045e },
572 { 'd', 'z', 0x045f },
573 { 'Y', '3', 0x0462 },
574 { 'y', '3', 0x0463 },
575 { 'O', '3', 0x046a },
576 { 'o', '3', 0x046b },
577 { 'F', '3', 0x0472 },
578 { 'f', '3', 0x0473 },
579 { 'V', '3', 0x0474 },
580 { 'v', '3', 0x0475 },
581 { 'C', '3', 0x0480 },
582 { 'c', '3', 0x0481 },
583 { 'G', '3', 0x0490 },
584 { 'g', '3', 0x0491 },
585 { 'A', '+', 0x05d0 },
586 { 'B', '+', 0x05d1 },
587 { 'G', '+', 0x05d2 },
588 { 'D', '+', 0x05d3 },
589 { 'H', '+', 0x05d4 },
590 { 'W', '+', 0x05d5 },
591 { 'Z', '+', 0x05d6 },
592 { 'X', '+', 0x05d7 },
593 { 'T', 'j', 0x05d8 },
594 { 'J', '+', 0x05d9 },
595 { 'K', '%', 0x05da },
596 { 'K', '+', 0x05db },
597 { 'L', '+', 0x05dc },
598 { 'M', '%', 0x05dd },
599 { 'M', '+', 0x05de },
600 { 'N', '%', 0x05df },
601 { 'N', '+', 0x05e0 },
602 { 'S', '+', 0x05e1 },
603 { 'E', '+', 0x05e2 },
604 { 'P', '%', 0x05e3 },
605 { 'P', '+', 0x05e4 },
606 { 'Z', 'j', 0x05e5 },
607 { 'Z', 'J', 0x05e6 },
608 { 'Q', '+', 0x05e7 },
609 { 'R', '+', 0x05e8 },
610 { 'S', 'h', 0x05e9 },
611 { 'T', '+', 0x05ea },
612 { ',', '+', 0x060c },
613 { ';', '+', 0x061b },
614 { '?', '+', 0x061f },
615 { 'H', '\'', 0x0621 },
616 { 'a', 'M', 0x0622 },
617 { 'a', 'H', 0x0623 },
618 { 'w', 'H', 0x0624 },
619 { 'a', 'h', 0x0625 },
620 { 'y', 'H', 0x0626 },
621 { 'a', '+', 0x0627 },
622 { 'b', '+', 0x0628 },
623 { 't', 'm', 0x0629 },
624 { 't', '+', 0x062a },
625 { 't', 'k', 0x062b },
626 { 'g', '+', 0x062c },
627 { 'h', 'k', 0x062d },
628 { 'x', '+', 0x062e },
629 { 'd', '+', 0x062f },
630 { 'd', 'k', 0x0630 },
631 { 'r', '+', 0x0631 },
632 { 'z', '+', 0x0632 },
633 { 's', '+', 0x0633 },
634 { 's', 'n', 0x0634 },
635 { 'c', '+', 0x0635 },
636 { 'd', 'd', 0x0636 },
637 { 't', 'j', 0x0637 },
638 { 'z', 'H', 0x0638 },
639 { 'e', '+', 0x0639 },
640 { 'i', '+', 0x063a },
641 { '+', '+', 0x0640 },
642 { 'f', '+', 0x0641 },
643 { 'q', '+', 0x0642 },
644 { 'k', '+', 0x0643 },
645 { 'l', '+', 0x0644 },
646 { 'm', '+', 0x0645 },
647 { 'n', '+', 0x0646 },
648 { 'h', '+', 0x0647 },
649 { 'w', '+', 0x0648 },
650 { 'j', '+', 0x0649 },
651 { 'y', '+', 0x064a },
652 { ':', '+', 0x064b },
653 { '"', '+', 0x064c },
654 { '=', '+', 0x064d },
655 { '/', '+', 0x064e },
656 { '\'', '+', 0x064f },
657 { '1', '+', 0x0650 },
658 { '3', '+', 0x0651 },
659 { '0', '+', 0x0652 },
660 { 'a', 'S', 0x0670 },
661 { 'p', '+', 0x067e },
662 { 'v', '+', 0x06a4 },
663 { 'g', 'f', 0x06af },
664 { '0', 'a', 0x06f0 },
665 { '1', 'a', 0x06f1 },
666 { '2', 'a', 0x06f2 },
667 { '3', 'a', 0x06f3 },
668 { '4', 'a', 0x06f4 },
669 { '5', 'a', 0x06f5 },
670 { '6', 'a', 0x06f6 },
671 { '7', 'a', 0x06f7 },
672 { '8', 'a', 0x06f8 },
673 { '9', 'a', 0x06f9 },
674 { 'B', '.', 0x1e02 },
675 { 'b', '.', 0x1e03 },
676 { 'B', '_', 0x1e06 },
677 { 'b', '_', 0x1e07 },
678 { 'D', '.', 0x1e0a },
679 { 'd', '.', 0x1e0b },
680 { 'D', '_', 0x1e0e },
681 { 'd', '_', 0x1e0f },
682 { 'D', ',', 0x1e10 },
683 { 'd', ',', 0x1e11 },
684 { 'F', '.', 0x1e1e },
685 { 'f', '.', 0x1e1f },
686 { 'G', '-', 0x1e20 },
687 { 'g', '-', 0x1e21 },
688 { 'H', '.', 0x1e22 },
689 { 'h', '.', 0x1e23 },
690 { 'H', ':', 0x1e26 },
691 { 'h', ':', 0x1e27 },
692 { 'H', ',', 0x1e28 },
693 { 'h', ',', 0x1e29 },
694 { 'K', '\'', 0x1e30 },
695 { 'k', '\'', 0x1e31 },
696 { 'K', '_', 0x1e34 },
697 { 'k', '_', 0x1e35 },
698 { 'L', '_', 0x1e3a },
699 { 'l', '_', 0x1e3b },
700 { 'M', '\'', 0x1e3e },
701 { 'm', '\'', 0x1e3f },
702 { 'M', '.', 0x1e40 },
703 { 'm', '.', 0x1e41 },
704 { 'N', '.', 0x1e44 },
705 { 'n', '.', 0x1e45 },
706 { 'N', '_', 0x1e48 },
707 { 'n', '_', 0x1e49 },
708 { 'P', '\'', 0x1e54 },
709 { 'p', '\'', 0x1e55 },
710 { 'P', '.', 0x1e56 },
711 { 'p', '.', 0x1e57 },
712 { 'R', '.', 0x1e58 },
713 { 'r', '.', 0x1e59 },
714 { 'R', '_', 0x1e5e },
715 { 'r', '_', 0x1e5f },
716 { 'S', '.', 0x1e60 },
717 { 's', '.', 0x1e61 },
718 { 'T', '.', 0x1e6a },
719 { 't', '.', 0x1e6b },
720 { 'T', '_', 0x1e6e },
721 { 't', '_', 0x1e6f },
722 { 'V', '?', 0x1e7c },
723 { 'v', '?', 0x1e7d },
724 { 'W', '!', 0x1e80 },
725 { 'w', '!', 0x1e81 },
726 { 'W', '\'', 0x1e82 },
727 { 'w', '\'', 0x1e83 },
728 { 'W', ':', 0x1e84 },
729 { 'w', ':', 0x1e85 },
730 { 'W', '.', 0x1e86 },
731 { 'w', '.', 0x1e87 },
732 { 'X', '.', 0x1e8a },
733 { 'x', '.', 0x1e8b },
734 { 'X', ':', 0x1e8c },
735 { 'x', ':', 0x1e8d },
736 { 'Y', '.', 0x1e8e },
737 { 'y', '.', 0x1e8f },
738 { 'Z', '>', 0x1e90 },
739 { 'z', '>', 0x1e91 },
740 { 'Z', '_', 0x1e94 },
741 { 'z', '_', 0x1e95 },
742 { 'h', '_', 0x1e96 },
743 { 't', ':', 0x1e97 },
744 { 'w', '0', 0x1e98 },
745 { 'y', '0', 0x1e99 },
746 { 'A', '2', 0x1ea2 },
747 { 'a', '2', 0x1ea3 },
748 { 'E', '2', 0x1eba },
749 { 'e', '2', 0x1ebb },
750 { 'E', '?', 0x1ebc },
751 { 'e', '?', 0x1ebd },
752 { 'I', '2', 0x1ec8 },
753 { 'i', '2', 0x1ec9 },
754 { 'O', '2', 0x1ece },
755 { 'o', '2', 0x1ecf },
756 { 'U', '2', 0x1ee6 },
757 { 'u', '2', 0x1ee7 },
758 { 'Y', '!', 0x1ef2 },
759 { 'y', '!', 0x1ef3 },
760 { 'Y', '2', 0x1ef6 },
761 { 'y', '2', 0x1ef7 },
762 { 'Y', '?', 0x1ef8 },
763 { 'y', '?', 0x1ef9 },
764 { ';', '\'', 0x1f00 },
765 { ',', '\'', 0x1f01 },
766 { ';', '!', 0x1f02 },
767 { ',', '!', 0x1f03 },
768 { '?', ';', 0x1f04 },
769 { '?', ',', 0x1f05 },
770 { '!', ':', 0x1f06 },
771 { '?', ':', 0x1f07 },
772 { '1', 'N', 0x2002 },
773 { '1', 'M', 0x2003 },
774 { '3', 'M', 0x2004 },
775 { '4', 'M', 0x2005 },
776 { '6', 'M', 0x2006 },
777 { '1', 'T', 0x2009 },
778 { '1', 'H', 0x200a },
779 { '-', '1', 0x2010 },
780 { '-', 'N', 0x2013 },
781 { '-', 'M', 0x2014 },
782 { '-', '3', 0x2015 },
783 { '!', '2', 0x2016 },
784 { '=', '2', 0x2017 },
785 { '\'', '6', 0x2018 },
786 { '\'', '9', 0x2019 },
787 { '.', '9', 0x201a },
788 { '9', '\'', 0x201b },
789 { '"', '6', 0x201c },
790 { '"', '9', 0x201d },
791 { ':', '9', 0x201e },
792 { '9', '"', 0x201f },
793 { '/', '-', 0x2020 },
794 { '/', '=', 0x2021 },
795 { '.', '.', 0x2025 },
796 { ',', '.', 0x2026 },
797 { '%', '0', 0x2030 },
798 { '1', '\'', 0x2032 },
799 { '2', '\'', 0x2033 },
800 { '3', '\'', 0x2034 },
801 { '1', '"', 0x2035 },
802 { '2', '"', 0x2036 },
803 { '3', '"', 0x2037 },
804 { 'C', 'a', 0x2038 },
805 { '<', '1', 0x2039 },
806 { '>', '1', 0x203a },
807 { ':', 'X', 0x203b },
808 { '\'', '-', 0x203e },
809 { '/', 'f', 0x2044 },
810 { '0', 'S', 0x2070 },
811 { '4', 'S', 0x2074 },
812 { '5', 'S', 0x2075 },
813 { '6', 'S', 0x2076 },
814 { '7', 'S', 0x2077 },
815 { '8', 'S', 0x2078 },
816 { '9', 'S', 0x2079 },
817 { '+', 'S', 0x207a },
818 { '-', 'S', 0x207b },
819 { '=', 'S', 0x207c },
820 { '(', 'S', 0x207d },
821 { ')', 'S', 0x207e },
822 { 'n', 'S', 0x207f },
823 { '0', 's', 0x2080 },
824 { '1', 's', 0x2081 },
825 { '2', 's', 0x2082 },
826 { '3', 's', 0x2083 },
827 { '4', 's', 0x2084 },
828 { '5', 's', 0x2085 },
829 { '6', 's', 0x2086 },
830 { '7', 's', 0x2087 },
831 { '8', 's', 0x2088 },
832 { '9', 's', 0x2089 },
833 { '+', 's', 0x208a },
834 { '-', 's', 0x208b },
835 { '=', 's', 0x208c },
836 { '(', 's', 0x208d },
837 { ')', 's', 0x208e },
838 { 'L', 'i', 0x20a4 },
839 { 'P', 't', 0x20a7 },
840 { 'W', '=', 0x20a9 },
841 { '=', 'e', 0x20ac }, // euro
842 { 'E', 'u', 0x20ac }, // euro
843 { '=', 'R', 0x20bd }, // rouble
844 { '=', 'P', 0x20bd }, // rouble
845 { 'o', 'C', 0x2103 },
846 { 'c', 'o', 0x2105 },
847 { 'o', 'F', 0x2109 },
848 { 'N', '0', 0x2116 },
849 { 'P', 'O', 0x2117 },
850 { 'R', 'x', 0x211e },
851 { 'S', 'M', 0x2120 },
852 { 'T', 'M', 0x2122 },
853 { 'O', 'm', 0x2126 },
854 { 'A', 'O', 0x212b },
855 { '1', '3', 0x2153 },
856 { '2', '3', 0x2154 },
857 { '1', '5', 0x2155 },
858 { '2', '5', 0x2156 },
859 { '3', '5', 0x2157 },
860 { '4', '5', 0x2158 },
861 { '1', '6', 0x2159 },
862 { '5', '6', 0x215a },
863 { '1', '8', 0x215b },
864 { '3', '8', 0x215c },
865 { '5', '8', 0x215d },
866 { '7', '8', 0x215e },
867 { '1', 'R', 0x2160 },
868 { '2', 'R', 0x2161 },
869 { '3', 'R', 0x2162 },
870 { '4', 'R', 0x2163 },
871 { '5', 'R', 0x2164 },
872 { '6', 'R', 0x2165 },
873 { '7', 'R', 0x2166 },
874 { '8', 'R', 0x2167 },
875 { '9', 'R', 0x2168 },
876 { 'a', 'R', 0x2169 },
877 { 'b', 'R', 0x216a },
878 { 'c', 'R', 0x216b },
879 { '1', 'r', 0x2170 },
880 { '2', 'r', 0x2171 },
881 { '3', 'r', 0x2172 },
882 { '4', 'r', 0x2173 },
883 { '5', 'r', 0x2174 },
884 { '6', 'r', 0x2175 },
885 { '7', 'r', 0x2176 },
886 { '8', 'r', 0x2177 },
887 { '9', 'r', 0x2178 },
888 { 'a', 'r', 0x2179 },
889 { 'b', 'r', 0x217a },
890 { 'c', 'r', 0x217b },
891 { '<', '-', 0x2190 },
892 { '-', '!', 0x2191 },
893 { '-', '>', 0x2192 },
894 { '-', 'v', 0x2193 },
895 { '<', '>', 0x2194 },
896 { 'U', 'D', 0x2195 },
897 { '<', '=', 0x21d0 },
898 { '=', '>', 0x21d2 },
899 { '=', '=', 0x21d4 },
900 { 'F', 'A', 0x2200 },
901 { 'd', 'P', 0x2202 },
902 { 'T', 'E', 0x2203 },
903 { '/', '0', 0x2205 },
904 { 'D', 'E', 0x2206 },
905 { 'N', 'B', 0x2207 },
906 { '(', '-', 0x2208 },
907 { '-', ')', 0x220b },
908 { '*', 'P', 0x220f },
909 { '+', 'Z', 0x2211 },
910 { '-', '2', 0x2212 },
911 { '-', '+', 0x2213 },
912 { '*', '-', 0x2217 },
913 { 'O', 'b', 0x2218 },
914 { 'S', 'b', 0x2219 },
915 { 'R', 'T', 0x221a },
916 { '0', '(', 0x221d },
917 { '0', '0', 0x221e },
918 { '-', 'L', 0x221f },
919 { '-', 'V', 0x2220 },
920 { 'P', 'P', 0x2225 },
921 { 'A', 'N', 0x2227 },
922 { 'O', 'R', 0x2228 },
923 { '(', 'U', 0x2229 },
924 { ')', 'U', 0x222a },
925 { 'I', 'n', 0x222b },
926 { 'D', 'I', 0x222c },
927 { 'I', 'o', 0x222e },
928 { '.', ':', 0x2234 },
929 { ':', '.', 0x2235 },
930 { ':', 'R', 0x2236 },
931 { ':', ':', 0x2237 },
932 { '?', '1', 0x223c },
933 { 'C', 'G', 0x223e },
934 { '?', '-', 0x2243 },
935 { '?', '=', 0x2245 },
936 { '?', '2', 0x2248 },
937 { '=', '?', 0x224c },
938 { 'H', 'I', 0x2253 },
939 { '!', '=', 0x2260 },
940 { '=', '3', 0x2261 },
941 { '=', '<', 0x2264 },
942 { '>', '=', 0x2265 },
943 { '<', '*', 0x226a },
944 { '*', '>', 0x226b },
945 { '!', '<', 0x226e },
946 { '!', '>', 0x226f },
947 { '(', 'C', 0x2282 },
948 { ')', 'C', 0x2283 },
949 { '(', '_', 0x2286 },
950 { ')', '_', 0x2287 },
951 { '0', '.', 0x2299 },
952 { '0', '2', 0x229a },
953 { '-', 'T', 0x22a5 },
954 { '.', 'P', 0x22c5 },
955 { ':', '3', 0x22ee },
956 { '.', '3', 0x22ef },
957 { 'E', 'h', 0x2302 },
958 { '<', '7', 0x2308 },
959 { '>', '7', 0x2309 },
960 { '7', '<', 0x230a },
961 { '7', '>', 0x230b },
962 { 'N', 'I', 0x2310 },
963 { '(', 'A', 0x2312 },
964 { 'T', 'R', 0x2315 },
965 { 'I', 'u', 0x2320 },
966 { 'I', 'l', 0x2321 },
967 { '<', '/', 0x2329 },
968 { '/', '>', 0x232a },
969 { 'V', 's', 0x2423 },
970 { '1', 'h', 0x2440 },
971 { '3', 'h', 0x2441 },
972 { '2', 'h', 0x2442 },
973 { '4', 'h', 0x2443 },
974 { '1', 'j', 0x2446 },
975 { '2', 'j', 0x2447 },
976 { '3', 'j', 0x2448 },
977 { '4', 'j', 0x2449 },
978 { '1', '.', 0x2488 },
979 { '2', '.', 0x2489 },
980 { '3', '.', 0x248a },
981 { '4', '.', 0x248b },
982 { '5', '.', 0x248c },
983 { '6', '.', 0x248d },
984 { '7', '.', 0x248e },
985 { '8', '.', 0x248f },
986 { '9', '.', 0x2490 },
987 { 'h', 'h', 0x2500 },
988 { 'H', 'H', 0x2501 },
989 { 'v', 'v', 0x2502 },
990 { 'V', 'V', 0x2503 },
991 { '3', '-', 0x2504 },
992 { '3', '_', 0x2505 },
993 { '3', '!', 0x2506 },
994 { '3', '/', 0x2507 },
995 { '4', '-', 0x2508 },
996 { '4', '_', 0x2509 },
997 { '4', '!', 0x250a },
998 { '4', '/', 0x250b },
999 { 'd', 'r', 0x250c },
1000 { 'd', 'R', 0x250d },
1001 { 'D', 'r', 0x250e },
1002 { 'D', 'R', 0x250f },
1003 { 'd', 'l', 0x2510 },
1004 { 'd', 'L', 0x2511 },
1005 { 'D', 'l', 0x2512 },
1006 { 'L', 'D', 0x2513 },
1007 { 'u', 'r', 0x2514 },
1008 { 'u', 'R', 0x2515 },
1009 { 'U', 'r', 0x2516 },
1010 { 'U', 'R', 0x2517 },
1011 { 'u', 'l', 0x2518 },
1012 { 'u', 'L', 0x2519 },
1013 { 'U', 'l', 0x251a },
1014 { 'U', 'L', 0x251b },
1015 { 'v', 'r', 0x251c },
1016 { 'v', 'R', 0x251d },
1017 { 'V', 'r', 0x2520 },
1018 { 'V', 'R', 0x2523 },
1019 { 'v', 'l', 0x2524 },
1020 { 'v', 'L', 0x2525 },
1021 { 'V', 'l', 0x2528 },
1022 { 'V', 'L', 0x252b },
1023 { 'd', 'h', 0x252c },
1024 { 'd', 'H', 0x252f },
1025 { 'D', 'h', 0x2530 },
1026 { 'D', 'H', 0x2533 },
1027 { 'u', 'h', 0x2534 },
1028 { 'u', 'H', 0x2537 },
1029 { 'U', 'h', 0x2538 },
1030 { 'U', 'H', 0x253b },
1031 { 'v', 'h', 0x253c },
1032 { 'v', 'H', 0x253f },
1033 { 'V', 'h', 0x2542 },
1034 { 'V', 'H', 0x254b },
1035 { 'F', 'D', 0x2571 },
1036 { 'B', 'D', 0x2572 },
1037 { 'T', 'B', 0x2580 },
1038 { 'L', 'B', 0x2584 },
1039 { 'F', 'B', 0x2588 },
1040 { 'l', 'B', 0x258c },
1041 { 'R', 'B', 0x2590 },
1042 { '.', 'S', 0x2591 },
1043 { ':', 'S', 0x2592 },
1044 { '?', 'S', 0x2593 },
1045 { 'f', 'S', 0x25a0 },
1046 { 'O', 'S', 0x25a1 },
1047 { 'R', 'O', 0x25a2 },
1048 { 'R', 'r', 0x25a3 },
1049 { 'R', 'F', 0x25a4 },
1050 { 'R', 'Y', 0x25a5 },
1051 { 'R', 'H', 0x25a6 },
1052 { 'R', 'Z', 0x25a7 },
1053 { 'R', 'K', 0x25a8 },
1054 { 'R', 'X', 0x25a9 },
1055 { 's', 'B', 0x25aa },
1056 { 'S', 'R', 0x25ac },
1057 { 'O', 'r', 0x25ad },
1058 { 'U', 'T', 0x25b2 },
1059 { 'u', 'T', 0x25b3 },
1060 { 'P', 'R', 0x25b6 },
1061 { 'T', 'r', 0x25b7 },
1062 { 'D', 't', 0x25bc },
1063 { 'd', 'T', 0x25bd },
1064 { 'P', 'L', 0x25c0 },
1065 { 'T', 'l', 0x25c1 },
1066 { 'D', 'b', 0x25c6 },
1067 { 'D', 'w', 0x25c7 },
1068 { 'L', 'Z', 0x25ca },
1069 { '0', 'm', 0x25cb },
1070 { '0', 'o', 0x25ce },
1071 { '0', 'M', 0x25cf },
1072 { '0', 'L', 0x25d0 },
1073 { '0', 'R', 0x25d1 },
1074 { 'S', 'n', 0x25d8 },
1075 { 'I', 'c', 0x25d9 },
1076 { 'F', 'd', 0x25e2 },
1077 { 'B', 'd', 0x25e3 },
1078 { '*', '2', 0x2605 },
1079 { '*', '1', 0x2606 },
1080 { '<', 'H', 0x261c },
1081 { '>', 'H', 0x261e },
1082 { '0', 'u', 0x263a },
1083 { '0', 'U', 0x263b },
1084 { 'S', 'U', 0x263c },
1085 { 'F', 'm', 0x2640 },
1086 { 'M', 'l', 0x2642 },
1087 { 'c', 'S', 0x2660 },
1088 { 'c', 'H', 0x2661 },
1089 { 'c', 'D', 0x2662 },
1090 { 'c', 'C', 0x2663 },
1091 { 'M', 'd', 0x2669 },
1092 { 'M', '8', 0x266a },
1093 { 'M', '2', 0x266b },
1094 { 'M', 'b', 0x266d },
1095 { 'M', 'x', 0x266e },
1096 { 'M', 'X', 0x266f },
1097 { 'O', 'K', 0x2713 },
1098 { 'X', 'X', 0x2717 },
1099 { '-', 'X', 0x2720 },
1100 { 'I', 'S', 0x3000 },
1101 { ',', '_', 0x3001 },
1102 { '.', '_', 0x3002 },
1103 { '+', '"', 0x3003 },
1104 { '+', '_', 0x3004 },
1105 { '*', '_', 0x3005 },
1106 { ';', '_', 0x3006 },
1107 { '0', '_', 0x3007 },
1108 { '<', '+', 0x300a },
1109 { '>', '+', 0x300b },
1110 { '<', '\'', 0x300c },
1111 { '>', '\'', 0x300d },
1112 { '<', '"', 0x300e },
1113 { '>', '"', 0x300f },
1114 { '(', '"', 0x3010 },
1115 { ')', '"', 0x3011 },
1116 { '=', 'T', 0x3012 },
1117 { '=', '_', 0x3013 },
1118 { '(', '\'', 0x3014 },
1119 { ')', '\'', 0x3015 },
1120 { '(', 'I', 0x3016 },
1121 { ')', 'I', 0x3017 },
1122 { '-', '?', 0x301c },
1123 { 'A', '5', 0x3041 },
1124 { 'a', '5', 0x3042 },
1125 { 'I', '5', 0x3043 },
1126 { 'i', '5', 0x3044 },
1127 { 'U', '5', 0x3045 },
1128 { 'u', '5', 0x3046 },
1129 { 'E', '5', 0x3047 },
1130 { 'e', '5', 0x3048 },
1131 { 'O', '5', 0x3049 },
1132 { 'o', '5', 0x304a },
1133 { 'k', 'a', 0x304b },
1134 { 'g', 'a', 0x304c },
1135 { 'k', 'i', 0x304d },
1136 { 'g', 'i', 0x304e },
1137 { 'k', 'u', 0x304f },
1138 { 'g', 'u', 0x3050 },
1139 { 'k', 'e', 0x3051 },
1140 { 'g', 'e', 0x3052 },
1141 { 'k', 'o', 0x3053 },
1142 { 'g', 'o', 0x3054 },
1143 { 's', 'a', 0x3055 },
1144 { 'z', 'a', 0x3056 },
1145 { 's', 'i', 0x3057 },
1146 { 'z', 'i', 0x3058 },
1147 { 's', 'u', 0x3059 },
1148 { 'z', 'u', 0x305a },
1149 { 's', 'e', 0x305b },
1150 { 'z', 'e', 0x305c },
1151 { 's', 'o', 0x305d },
1152 { 'z', 'o', 0x305e },
1153 { 't', 'a', 0x305f },
1154 { 'd', 'a', 0x3060 },
1155 { 't', 'i', 0x3061 },
1156 { 'd', 'i', 0x3062 },
1157 { 't', 'U', 0x3063 },
1158 { 't', 'u', 0x3064 },
1159 { 'd', 'u', 0x3065 },
1160 { 't', 'e', 0x3066 },
1161 { 'd', 'e', 0x3067 },
1162 { 't', 'o', 0x3068 },
1163 { 'd', 'o', 0x3069 },
1164 { 'n', 'a', 0x306a },
1165 { 'n', 'i', 0x306b },
1166 { 'n', 'u', 0x306c },
1167 { 'n', 'e', 0x306d },
1168 { 'n', 'o', 0x306e },
1169 { 'h', 'a', 0x306f },
1170 { 'b', 'a', 0x3070 },
1171 { 'p', 'a', 0x3071 },
1172 { 'h', 'i', 0x3072 },
1173 { 'b', 'i', 0x3073 },
1174 { 'p', 'i', 0x3074 },
1175 { 'h', 'u', 0x3075 },
1176 { 'b', 'u', 0x3076 },
1177 { 'p', 'u', 0x3077 },
1178 { 'h', 'e', 0x3078 },
1179 { 'b', 'e', 0x3079 },
1180 { 'p', 'e', 0x307a },
1181 { 'h', 'o', 0x307b },
1182 { 'b', 'o', 0x307c },
1183 { 'p', 'o', 0x307d },
1184 { 'm', 'a', 0x307e },
1185 { 'm', 'i', 0x307f },
1186 { 'm', 'u', 0x3080 },
1187 { 'm', 'e', 0x3081 },
1188 { 'm', 'o', 0x3082 },
1189 { 'y', 'A', 0x3083 },
1190 { 'y', 'a', 0x3084 },
1191 { 'y', 'U', 0x3085 },
1192 { 'y', 'u', 0x3086 },
1193 { 'y', 'O', 0x3087 },
1194 { 'y', 'o', 0x3088 },
1195 { 'r', 'a', 0x3089 },
1196 { 'r', 'i', 0x308a },
1197 { 'r', 'u', 0x308b },
1198 { 'r', 'e', 0x308c },
1199 { 'r', 'o', 0x308d },
1200 { 'w', 'A', 0x308e },
1201 { 'w', 'a', 0x308f },
1202 { 'w', 'i', 0x3090 },
1203 { 'w', 'e', 0x3091 },
1204 { 'w', 'o', 0x3092 },
1205 { 'n', '5', 0x3093 },
1206 { 'v', 'u', 0x3094 },
1207 { '"', '5', 0x309b },
1208 { '0', '5', 0x309c },
1209 { '*', '5', 0x309d },
1210 { '+', '5', 0x309e },
1211 { 'a', '6', 0x30a1 },
1212 { 'A', '6', 0x30a2 },
1213 { 'i', '6', 0x30a3 },
1214 { 'I', '6', 0x30a4 },
1215 { 'u', '6', 0x30a5 },
1216 { 'U', '6', 0x30a6 },
1217 { 'e', '6', 0x30a7 },
1218 { 'E', '6', 0x30a8 },
1219 { 'o', '6', 0x30a9 },
1220 { 'O', '6', 0x30aa },
1221 { 'K', 'a', 0x30ab },
1222 { 'G', 'a', 0x30ac },
1223 { 'K', 'i', 0x30ad },
1224 { 'G', 'i', 0x30ae },
1225 { 'K', 'u', 0x30af },
1226 { 'G', 'u', 0x30b0 },
1227 { 'K', 'e', 0x30b1 },
1228 { 'G', 'e', 0x30b2 },
1229 { 'K', 'o', 0x30b3 },
1230 { 'G', 'o', 0x30b4 },
1231 { 'S', 'a', 0x30b5 },
1232 { 'Z', 'a', 0x30b6 },
1233 { 'S', 'i', 0x30b7 },
1234 { 'Z', 'i', 0x30b8 },
1235 { 'S', 'u', 0x30b9 },
1236 { 'Z', 'u', 0x30ba },
1237 { 'S', 'e', 0x30bb },
1238 { 'Z', 'e', 0x30bc },
1239 { 'S', 'o', 0x30bd },
1240 { 'Z', 'o', 0x30be },
1241 { 'T', 'a', 0x30bf },
1242 { 'D', 'a', 0x30c0 },
1243 { 'T', 'i', 0x30c1 },
1244 { 'D', 'i', 0x30c2 },
1245 { 'T', 'U', 0x30c3 },
1246 { 'T', 'u', 0x30c4 },
1247 { 'D', 'u', 0x30c5 },
1248 { 'T', 'e', 0x30c6 },
1249 { 'D', 'e', 0x30c7 },
1250 { 'T', 'o', 0x30c8 },
1251 { 'D', 'o', 0x30c9 },
1252 { 'N', 'a', 0x30ca },
1253 { 'N', 'i', 0x30cb },
1254 { 'N', 'u', 0x30cc },
1255 { 'N', 'e', 0x30cd },
1256 { 'N', 'o', 0x30ce },
1257 { 'H', 'a', 0x30cf },
1258 { 'B', 'a', 0x30d0 },
1259 { 'P', 'a', 0x30d1 },
1260 { 'H', 'i', 0x30d2 },
1261 { 'B', 'i', 0x30d3 },
1262 { 'P', 'i', 0x30d4 },
1263 { 'H', 'u', 0x30d5 },
1264 { 'B', 'u', 0x30d6 },
1265 { 'P', 'u', 0x30d7 },
1266 { 'H', 'e', 0x30d8 },
1267 { 'B', 'e', 0x30d9 },
1268 { 'P', 'e', 0x30da },
1269 { 'H', 'o', 0x30db },
1270 { 'B', 'o', 0x30dc },
1271 { 'P', 'o', 0x30dd },
1272 { 'M', 'a', 0x30de },
1273 { 'M', 'i', 0x30df },
1274 { 'M', 'u', 0x30e0 },
1275 { 'M', 'e', 0x30e1 },
1276 { 'M', 'o', 0x30e2 },
1277 { 'Y', 'A', 0x30e3 },
1278 { 'Y', 'a', 0x30e4 },
1279 { 'Y', 'U', 0x30e5 },
1280 { 'Y', 'u', 0x30e6 },
1281 { 'Y', 'O', 0x30e7 },
1282 { 'Y', 'o', 0x30e8 },
1283 { 'R', 'a', 0x30e9 },
1284 { 'R', 'i', 0x30ea },
1285 { 'R', 'u', 0x30eb },
1286 { 'R', 'e', 0x30ec },
1287 { 'R', 'o', 0x30ed },
1288 { 'W', 'A', 0x30ee },
1289 { 'W', 'a', 0x30ef },
1290 { 'W', 'i', 0x30f0 },
1291 { 'W', 'e', 0x30f1 },
1292 { 'W', 'o', 0x30f2 },
1293 { 'N', '6', 0x30f3 },
1294 { 'V', 'u', 0x30f4 },
1295 { 'K', 'A', 0x30f5 },
1296 { 'K', 'E', 0x30f6 },
1297 { 'V', 'a', 0x30f7 },
1298 { 'V', 'i', 0x30f8 },
1299 { 'V', 'e', 0x30f9 },
1300 { 'V', 'o', 0x30fa },
1301 { '.', '6', 0x30fb },
1302 { '-', '6', 0x30fc },
1303 { '*', '6', 0x30fd },
1304 { '+', '6', 0x30fe },
1305 { 'b', '4', 0x3105 },
1306 { 'p', '4', 0x3106 },
1307 { 'm', '4', 0x3107 },
1308 { 'f', '4', 0x3108 },
1309 { 'd', '4', 0x3109 },
1310 { 't', '4', 0x310a },
1311 { 'n', '4', 0x310b },
1312 { 'l', '4', 0x310c },
1313 { 'g', '4', 0x310d },
1314 { 'k', '4', 0x310e },
1315 { 'h', '4', 0x310f },
1316 { 'j', '4', 0x3110 },
1317 { 'q', '4', 0x3111 },
1318 { 'x', '4', 0x3112 },
1319 { 'z', 'h', 0x3113 },
1320 { 'c', 'h', 0x3114 },
1321 { 's', 'h', 0x3115 },
1322 { 'r', '4', 0x3116 },
1323 { 'z', '4', 0x3117 },
1324 { 'c', '4', 0x3118 },
1325 { 's', '4', 0x3119 },
1326 { 'a', '4', 0x311a },
1327 { 'o', '4', 0x311b },
1328 { 'e', '4', 0x311c },
1329 { 'a', 'i', 0x311e },
1330 { 'e', 'i', 0x311f },
1331 { 'a', 'u', 0x3120 },
1332 { 'o', 'u', 0x3121 },
1333 { 'a', 'n', 0x3122 },
1334 { 'e', 'n', 0x3123 },
1335 { 'a', 'N', 0x3124 },
1336 { 'e', 'N', 0x3125 },
1337 { 'e', 'r', 0x3126 },
1338 { 'i', '4', 0x3127 },
1339 { 'u', '4', 0x3128 },
1340 { 'i', 'u', 0x3129 },
1341 { 'v', '4', 0x312a },
1342 { 'n', 'G', 0x312b },
1343 { 'g', 'n', 0x312c },
1344 { '1', 'c', 0x3220 },
1345 { '2', 'c', 0x3221 },
1346 { '3', 'c', 0x3222 },
1347 { '4', 'c', 0x3223 },
1348 { '5', 'c', 0x3224 },
1349 { '6', 'c', 0x3225 },
1350 { '7', 'c', 0x3226 },
1351 { '8', 'c', 0x3227 },
1352 { '9', 'c', 0x3228 },
1353
1354 // code points 0xe000 - 0xefff excluded, they have no assigned
1355 // characters, only used in proposals.
1356 { 'f', 'f', 0xfb00 },
1357 { 'f', 'i', 0xfb01 },
1358 { 'f', 'l', 0xfb02 },
1359 { 'f', 't', 0xfb05 },
1360 { 's', 't', 0xfb06 },
1361
1362 // extra alternatives, easier to remember
1363 { 'W', '`', 0x1e80 },
1364 { 'w', '`', 0x1e81 },
1365 { 'Y', '`', 0x1ef2 },
1366 { 'y', '`', 0x1ef3 },
1367
1368 // Vim 5.x compatible digraphs that don't conflict with the above
1369 { '~', '!', 161 }, // ¡
1370 { 'c', '|', 162 }, // ¢
1371 { '$', '$', 163 }, // £
1372 { 'o', 'x', 164 }, // ¤ - currency symbol in ISO 8859-1
1373 { 'Y', '-', 165 }, // ¥
1374 { '|', '|', 166 }, // ¦
1375 { 'c', 'O', 169 }, // ©
1376 { '-', ',', 172 }, // ¬
1377 { '-', '=', 175 }, // ¯
1378 { '~', 'o', 176 }, // °
1379 { '2', '2', 178 }, // ²
1380 { '3', '3', 179 }, // ³
1381 { 'p', 'p', 182 }, // ¶
1382 { '~', '.', 183 }, // ·
1383 { '1', '1', 185 }, // ¹
1384 { '~', '?', 191 }, // ¿
1385 { 'A', '`', 192 }, // À
1386 { 'A', '^', 194 }, // Â
1387 { 'A', '~', 195 }, // Ã
1388 { 'A', '"', 196 }, // Ä
1389 { 'A', '@', 197 }, // Å
1390 { 'E', '`', 200 }, // È
1391 { 'E', '^', 202 }, // Ê
1392 { 'E', '"', 203 }, // Ë
1393 { 'I', '`', 204 }, // Ì
1394 { 'I', '^', 206 }, // Î
1395 { 'I', '"', 207 }, // Ï
1396 { 'N', '~', 209 }, // Ñ
1397 { 'O', '`', 210 }, // Ò
1398 { 'O', '^', 212 }, // Ô
1399 { 'O', '~', 213 }, // Õ
1400 { '/', '\\', 215 }, // × - multiplication symbol in ISO 8859-1
1401 { 'U', '`', 217 }, // Ù
1402 { 'U', '^', 219 }, // Û
1403 { 'I', 'p', 222 }, // Þ
1404 { 'a', '`', 224 }, // à
1405 { 'a', '^', 226 }, // â
1406 { 'a', '~', 227 }, // ã
1407 { 'a', '"', 228 }, // ä
1408 { 'a', '@', 229 }, // å
1409 { 'e', '`', 232 }, // è
1410 { 'e', '^', 234 }, // ê
1411 { 'e', '"', 235 }, // ë
1412 { 'i', '`', 236 }, // ì
1413 { 'i', '^', 238 }, // î
1414 { 'n', '~', 241 }, // ñ
1415 { 'o', '`', 242 }, // ò
1416 { 'o', '^', 244 }, // ô
1417 { 'o', '~', 245 }, // õ
1418 { 'u', '`', 249 }, // ù
1419 { 'u', '^', 251 }, // û
1420 { 'y', '"', 255 }, // x XX
1421
1422 { NUL, NUL, NUL }
1423};
1424
1425/// handle digraphs after typing a character
1426///
1427/// @param c
1428///
1429/// @return The digraph.
1430int do_digraph(int c)
1431{
1432 static int backspaced; // character before K_BS
1433 static int lastchar; // last typed character
1434
1435 if (c == -1) { // init values
1436 backspaced = -1;
1437 } else if (p_dg) {
1438 if (backspaced >= 0) {
1439 c = getdigraph(backspaced, c, FALSE);
1440 }
1441 backspaced = -1;
1442
1443 if (((c == K_BS) || (c == Ctrl_H)) && (lastchar >= 0)) {
1444 backspaced = lastchar;
1445 }
1446 }
1447 lastchar = c;
1448 return c;
1449}
1450
1451/// Find a digraph for "val". If found return the string to display it.
1452/// If not found return NULL.
1453char_u *get_digraph_for_char(int val)
1454{
1455 digr_T *dp;
1456 static char_u r[3];
1457
1458 for (int use_defaults = 0; use_defaults <= 1; use_defaults++) {
1459 if (use_defaults == 0) {
1460 dp = (digr_T *)user_digraphs.ga_data;
1461 } else {
1462 dp = digraphdefault;
1463 }
1464 for (int i = 0;
1465 use_defaults ? dp->char1 != NUL : i < user_digraphs.ga_len; i++) {
1466 if (dp->result == val) {
1467 r[0] = dp->char1;
1468 r[1] = dp->char2;
1469 r[2] = NUL;
1470 return r;
1471 }
1472 dp++;
1473 }
1474 }
1475 return NULL;
1476}
1477
1478/// Get a digraph. Used after typing CTRL-K on the command line or in normal
1479/// mode.
1480///
1481/// @param cmdline TRUE when called from the cmdline
1482///
1483/// @returns composed character, or NUL when ESC was used.
1484int get_digraph(int cmdline)
1485{
1486 int cc;
1487 no_mapping++;
1488 int c = plain_vgetc();
1489 no_mapping--;
1490
1491 if (c != ESC) {
1492 // ESC cancels CTRL-K
1493 if (IS_SPECIAL(c)) {
1494 // insert special key code
1495 return c;
1496 }
1497
1498 if (cmdline) {
1499 if ((char2cells(c) == 1) && c < 128 && (cmdline_star == 0)) {
1500 putcmdline((char)c, true);
1501 }
1502 } else {
1503 add_to_showcmd(c);
1504 }
1505 no_mapping++;
1506 cc = plain_vgetc();
1507 no_mapping--;
1508
1509 if (cc != ESC) {
1510 // ESC cancels CTRL-K
1511 return getdigraph(c, cc, TRUE);
1512 }
1513 }
1514 return NUL;
1515}
1516
1517/// Lookup the pair "char1", "char2" in the digraph tables.
1518///
1519/// @param char1
1520/// @param char2
1521/// @param meta_char
1522///
1523/// @return If no match, return "char2". If "meta_char" is TRUE and "char1"
1524// is a space, return "char2" | 0x80.
1525static int getexactdigraph(int char1, int char2, int meta_char)
1526{
1527 int retval = 0;
1528
1529 if (IS_SPECIAL(char1) || IS_SPECIAL(char2)) {
1530 return char2;
1531 }
1532
1533 // Search user digraphs first.
1534 digr_T *dp = (digr_T *)user_digraphs.ga_data;
1535 for (int i = 0; i < user_digraphs.ga_len; ++i) {
1536 if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) {
1537 retval = dp->result;
1538 break;
1539 }
1540 ++dp;
1541 }
1542
1543 // Search default digraphs.
1544 if (retval == 0) {
1545 dp = digraphdefault;
1546
1547 for (int i = 0; dp->char1 != 0; ++i) {
1548 if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) {
1549 retval = dp->result;
1550 break;
1551 }
1552 ++dp;
1553 }
1554 }
1555
1556 if (retval == 0) {
1557 // digraph deleted or not found
1558 if ((char1 == ' ') && meta_char) {
1559 // <space> <char> --> meta-char
1560 return char2 | 0x80;
1561 }
1562 return char2;
1563 }
1564 return retval;
1565}
1566
1567/// Get digraph.
1568/// Allow for both char1-char2 and char2-char1
1569///
1570/// @param char1
1571/// @param char2
1572/// @param meta_char
1573///
1574/// @return The digraph.
1575int getdigraph(int char1, int char2, int meta_char)
1576{
1577 int retval;
1578
1579 if (((retval = getexactdigraph(char1, char2, meta_char)) == char2)
1580 && (char1 != char2)
1581 && ((retval = getexactdigraph(char2, char1, meta_char)) // -V764
1582 == char1)) {
1583 return char2;
1584 }
1585 return retval;
1586}
1587
1588/// Add the digraphs in the argument to the digraph table.
1589/// format: {c1}{c2} char {c1}{c2} char ...
1590///
1591/// @param str
1592void putdigraph(char_u *str)
1593{
1594 char_u char1, char2;
1595 digr_T *dp;
1596
1597 while (*str != NUL) {
1598 str = skipwhite(str);
1599
1600 if (*str == NUL) {
1601 return;
1602 }
1603 char1 = *str++;
1604 char2 = *str++;
1605
1606 if (char2 == 0) {
1607 EMSG(_(e_invarg));
1608 return;
1609 }
1610
1611 if ((char1 == ESC) || (char2 == ESC)) {
1612 EMSG(_("E104: Escape not allowed in digraph"));
1613 return;
1614 }
1615 str = skipwhite(str);
1616
1617 if (!ascii_isdigit(*str)) {
1618 EMSG(_(e_number_exp));
1619 return;
1620 }
1621 int n = getdigits_int(&str, true, 0);
1622
1623 // If the digraph already exists, replace the result.
1624 dp = (digr_T *)user_digraphs.ga_data;
1625
1626 int i;
1627 for (i = 0; i < user_digraphs.ga_len; ++i) {
1628 if (((int)dp->char1 == char1) && ((int)dp->char2 == char2)) {
1629 dp->result = n;
1630 break;
1631 }
1632 ++dp;
1633 }
1634
1635 // Add a new digraph to the table.
1636 if (i == user_digraphs.ga_len) {
1637 dp = GA_APPEND_VIA_PTR(digr_T, &user_digraphs);
1638 dp->char1 = char1;
1639 dp->char2 = char2;
1640 dp->result = n;
1641 }
1642 }
1643}
1644
1645void listdigraphs(void)
1646{
1647 digr_T *dp;
1648
1649 msg_putchar('\n');
1650
1651 dp = digraphdefault;
1652
1653 for (int i = 0; dp->char1 != NUL && !got_int; ++i) {
1654 digr_T tmp;
1655
1656 // May need to convert the result to 'encoding'.
1657 tmp.char1 = dp->char1;
1658 tmp.char2 = dp->char2;
1659 tmp.result = getexactdigraph(tmp.char1, tmp.char2, FALSE);
1660
1661 if ((tmp.result != 0)
1662 && (tmp.result != tmp.char2)) {
1663 printdigraph(&tmp);
1664 }
1665 dp++;
1666 fast_breakcheck();
1667 }
1668
1669 dp = (digr_T *)user_digraphs.ga_data;
1670 for (int i = 0; i < user_digraphs.ga_len && !got_int; ++i) {
1671 printdigraph(dp);
1672 fast_breakcheck();
1673 dp++;
1674 }
1675}
1676
1677static void printdigraph(digr_T *dp)
1678{
1679 char_u buf[30];
1680 char_u *p;
1681
1682 int list_width;
1683
1684 list_width = 13;
1685
1686 if (dp->result != 0) {
1687 if (msg_col > Columns - list_width) {
1688 msg_putchar('\n');
1689 }
1690
1691
1692 // Make msg_col a multiple of list_width by using spaces.
1693 if (msg_col % list_width != 0) {
1694 int spaces = (msg_col / list_width + 1) * list_width - msg_col;
1695 while (spaces--) {
1696 msg_putchar(' ');
1697 }
1698 }
1699
1700 p = &buf[0];
1701 *p++ = dp->char1;
1702 *p++ = dp->char2;
1703 *p++ = ' ';
1704 *p = NUL;
1705 msg_outtrans(buf);
1706 p = buf;
1707
1708 // add a space to draw a composing char on
1709 if (utf_iscomposing(dp->result)) {
1710 *p++ = ' ';
1711 }
1712 p += utf_char2bytes(dp->result, p);
1713
1714 *p = NUL;
1715 msg_outtrans_attr(buf, HL_ATTR(HLF_8));
1716 p = buf;
1717 if (char2cells(dp->result) == 1) {
1718 *p++ = ' ';
1719 }
1720 assert(p >= buf);
1721 vim_snprintf((char *)p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result);
1722 msg_outtrans(buf);
1723 }
1724}
1725
1726/// structure used for b_kmap_ga.ga_data
1727typedef struct {
1728 char_u *from;
1729 char_u *to;
1730} kmap_T;
1731
1732#define KMAP_MAXLEN 20 // maximum length of "from" or "to"
1733
1734
1735/// Set up key mapping tables for the 'keymap' option.
1736///
1737/// @return NULL if OK, an error message for failure. This only needs to be
1738/// used when setting the option, not later when the value has already
1739/// been checked.
1740char_u* keymap_init(void)
1741{
1742 curbuf->b_kmap_state &= ~KEYMAP_INIT;
1743
1744 if (*curbuf->b_p_keymap == NUL) {
1745 // Stop any active keymap and clear the table. Also remove
1746 // b:keymap_name, as no keymap is active now.
1747 keymap_unload();
1748 do_cmdline_cmd("unlet! b:keymap_name");
1749 } else {
1750 char *buf;
1751 size_t buflen;
1752
1753 // Source the keymap file. It will contain a ":loadkeymap" command
1754 // which will call ex_loadkeymap() below.
1755 buflen = STRLEN(curbuf->b_p_keymap) + STRLEN(p_enc) + 14;
1756 buf = xmalloc(buflen);
1757
1758 // try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath'
1759 vim_snprintf(buf, buflen, "keymap/%s_%s.vim",
1760 curbuf->b_p_keymap, p_enc);
1761
1762 if (source_runtime((char_u *)buf, 0) == FAIL) {
1763 // try finding "keymap/'keymap'.vim" in 'runtimepath'
1764 vim_snprintf(buf, buflen, "keymap/%s.vim",
1765 curbuf->b_p_keymap);
1766
1767 if (source_runtime((char_u *)buf, 0) == FAIL) {
1768 xfree(buf);
1769 return (char_u *)N_("E544: Keymap file not found");
1770 }
1771 }
1772 xfree(buf);
1773 }
1774
1775 return NULL;
1776}
1777
1778/// ":loadkeymap" command: load the following lines as the keymap.
1779///
1780/// @param eap
1781void ex_loadkeymap(exarg_T *eap)
1782{
1783 char_u *line;
1784 char_u *p;
1785 char_u *s;
1786
1787#define KMAP_LLEN 200 // max length of "to" and "from" together
1788 char_u buf[KMAP_LLEN + 11];
1789 char_u *save_cpo = p_cpo;
1790
1791 if (!getline_equal(eap->getline, eap->cookie, getsourceline)) {
1792 EMSG(_("E105: Using :loadkeymap not in a sourced file"));
1793 return;
1794 }
1795
1796 // Stop any active keymap and clear the table.
1797 keymap_unload();
1798
1799 curbuf->b_kmap_state = 0;
1800 ga_init(&curbuf->b_kmap_ga, (int)sizeof(kmap_T), 20);
1801
1802 // Set 'cpoptions' to "C" to avoid line continuation.
1803 p_cpo = (char_u *)"C";
1804
1805 // Get each line of the sourced file, break at the end.
1806 for (;;) {
1807 line = eap->getline(0, eap->cookie, 0);
1808
1809 if (line == NULL) {
1810 break;
1811 }
1812
1813 p = skipwhite(line);
1814
1815 if ((*p != '"') && (*p != NUL)) {
1816 kmap_T *kp = GA_APPEND_VIA_PTR(kmap_T, &curbuf->b_kmap_ga);
1817 s = skiptowhite(p);
1818 kp->from = vim_strnsave(p, (size_t)(s - p));
1819 p = skipwhite(s);
1820 s = skiptowhite(p);
1821 kp->to = vim_strnsave(p, (size_t)(s - p));
1822
1823 if ((STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN)
1824 || (*kp->from == NUL)
1825 || (*kp->to == NUL)) {
1826 if (*kp->to == NUL) {
1827 EMSG(_("E791: Empty keymap entry"));
1828 }
1829 xfree(kp->from);
1830 xfree(kp->to);
1831 --curbuf->b_kmap_ga.ga_len;
1832 }
1833 }
1834 xfree(line);
1835 }
1836
1837 // setup ":lmap" to map the keys
1838 for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) {
1839 vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s %s",
1840 ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from,
1841 ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to);
1842 (void)do_map(0, buf, LANGMAP, false);
1843 }
1844
1845 p_cpo = save_cpo;
1846
1847 curbuf->b_kmap_state |= KEYMAP_LOADED;
1848 status_redraw_curbuf();
1849}
1850
1851/// Frees the buf_T.b_kmap_ga field of a buffer.
1852void keymap_ga_clear(garray_T *kmap_ga)
1853{
1854 kmap_T *kp = (kmap_T *)kmap_ga->ga_data;
1855 for (int i = 0; i < kmap_ga->ga_len; i++) {
1856 xfree(kp[i].from);
1857 xfree(kp[i].to);
1858 }
1859}
1860
1861/// Stop using 'keymap'.
1862static void keymap_unload(void)
1863{
1864 char_u buf[KMAP_MAXLEN + 10];
1865 char_u *save_cpo = p_cpo;
1866 kmap_T *kp;
1867
1868 if (!(curbuf->b_kmap_state & KEYMAP_LOADED)) {
1869 return;
1870 }
1871
1872 // Set 'cpoptions' to "C" to avoid line continuation.
1873 p_cpo = (char_u *)"C";
1874
1875 // clear the ":lmap"s
1876 kp = (kmap_T *)curbuf->b_kmap_ga.ga_data;
1877
1878 for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) {
1879 vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from);
1880 (void)do_map(1, buf, LANGMAP, false);
1881 }
1882 keymap_ga_clear(&curbuf->b_kmap_ga);
1883
1884 p_cpo = save_cpo;
1885
1886 ga_clear(&curbuf->b_kmap_ga);
1887 curbuf->b_kmap_state &= ~KEYMAP_LOADED;
1888 status_redraw_curbuf();
1889}
1890