comparison src/digraph.c @ 15595:1ec942f1b648 v8.1.0805

patch 8.1.0805: too many #ifdefs commit https://github.com/vim/vim/commit/135059724f140ceac889c9f8136bd1bf5c41d49d Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 15:04:48 2019 +0100 patch 8.1.0805: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate FEAT_MBYTE, part 1.
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 15:15:06 +0100
parents 55ccc2d353bd
children ef00b6bc186b
comparison
equal deleted inserted replaced
15594:7a8983fe4f97 15595:1ec942f1b648
13 13
14 #include "vim.h" 14 #include "vim.h"
15 15
16 #if defined(FEAT_DIGRAPHS) || defined(PROTO) 16 #if defined(FEAT_DIGRAPHS) || defined(PROTO)
17 17
18 #ifdef FEAT_MBYTE
19 typedef int result_T; 18 typedef int result_T;
20 #else
21 typedef char_u result_T;
22 #endif
23 19
24 typedef struct digraph 20 typedef struct digraph
25 { 21 {
26 char_u char1; 22 char_u char1;
27 char_u char2; 23 char_u char2;
36 /* 32 /*
37 * Note: Characters marked with XX are not included literally, because some 33 * Note: Characters marked with XX are not included literally, because some
38 * compilers cannot handle them (Amiga SAS/C is the most picky one). 34 * compilers cannot handle them (Amiga SAS/C is the most picky one).
39 */ 35 */
40 static digr_T digraphdefault[] = 36 static digr_T digraphdefault[] =
37
41 #ifdef __MINT__ 38 #ifdef __MINT__
42
43 /* 39 /*
44 * ATARI digraphs 40 * ATARI digraphs
45 */ 41 */
46 {{'C', ',', 128}, /* ~@ XX */ 42 {{'C', ',', 128}, /* ~@ XX */
47 {'u', '"', 129}, /* */ 43 {'u', '"', 129}, /* */
318 {'U', '\'', 254}, /* */ 314 {'U', '\'', 254}, /* */
319 {NUL, NUL, NUL} 315 {NUL, NUL, NUL}
320 }; 316 };
321 317
322 # else 318 # else
323 # if defined(MACOS_X) && !defined(FEAT_MBYTE) 319 # ifdef OLD_DIGRAPHS
324
325 /*
326 * Macintosh digraphs
327 */
328 {{'a', 't', 64}, /* @ */
329 {'A', '"', 128}, /* ~@ XX */
330 {'A', 'o', 129}, /* */
331 {'C', ',', 130}, /* */
332 {'E', '\'', 131}, /* */
333 {'N', '~', 132}, /* */
334 {'O', '"', 133}, /* */
335 {'U', '"', 134}, /* */
336 {'a', '\'', 135}, /* ~G XX */
337 {'a', '`', 136}, /* ~H XX */
338 {'a', '^', 137}, /* */
339 {'a', '"', 138}, /* */
340 {'a', '~', 139}, /* */
341 {'a', 'o', 140}, /* */
342 {'c', ',', 141}, /* */
343 {'e', '\'', 142}, /* */
344 {'e', '`', 143}, /* */
345 {'e', '^', 144}, /* */
346 {'e', '"', 145}, /* */
347 {'i', '\'', 146}, /* */
348 {'i', '`', 147}, /* */
349 {'i', '^', 148}, /* */
350 {'i', '"', 149}, /* */
351 {'n', '~', 150}, /* */
352 {'o', '\'', 151}, /* */
353 {'o', '`', 152}, /* */
354 {'o', '^', 153}, /* */
355 {'o', '"', 154}, /* */
356 {'o', '~', 155}, /* o */
357 {'u', '\'', 156}, /* */
358 {'u', '`', 157}, /* ~] XX */
359 {'u', '^', 158}, /* */
360 {'u', '"', 159}, /* */
361 {'+', '_', 160}, /* */
362 {'~', 'o', 161}, /* */
363 {'c', '|', 162}, /* */
364 {'$', '$', 163}, /* */
365 {'p', 'a', 164}, /* */
366 {'.', '.', 165}, /* * */
367 {'P', 'P', 166}, /* */
368 {'s', 's', 167}, /* */
369 {'r', 'O', 168}, /* */
370 {'c', 'O', 169}, /* */
371 {'T', 'M', 170}, /* */
372 {'=', '/', 173}, /* */
373 {'A', 'E', 174}, /* */
374 {'O', '/', 175}, /* */
375 {'0', '0', 176}, /* */
376 {'+', '-', 177}, /* */
377 {'<', '=', 178}, /* */
378 {'>', '=', 179}, /* */
379 {'Y', '-', 180}, /* */
380 {'j', 'u', 181}, /* */
381 {'m', 'u', 181}, /* */
382 {'d', 'd', 182}, /* */
383 {'S', 'S', 183}, /* */
384 {'S', 'I', 183}, /* */
385 {'P', 'I', 184}, /* */
386 {'p', 'i', 185}, /* */
387 {'I', 'I', 186}, /* */
388 {'a', '-', 187}, /* */
389 {'o', '-', 188}, /* */
390 {'O', 'M', 189}, /* */
391 {'a', 'e', 190}, /* */
392 {'o', '/', 191}, /* */
393 {'~', '?', 192}, /* */
394 {'~', '!', 193}, /* */
395 {'-', ',', 194}, /* */
396 {'v', '-', 195}, /* ~H XX */
397 {'f', '-', 196}, /* */
398 {'~', '~', 197}, /* */
399 {'D', 'E', 198}, /* */
400 {'<', '<', 199}, /* */
401 {'>', '>', 200}, /* */
402 {'.', ':', 201}, /* */
403 {'A', '`', 203}, /* */
404 {'A', '~', 204}, /* */
405 {'O', '~', 205}, /* */
406 {'O', 'E', 206}, /* */
407 {'o', 'e', 207}, /* */
408 {'-', '.', 208}, /* - */
409 {'-', '-', 209}, /* - */
410 {'`', '`', 210}, /* " */
411 {'\'', '\'', 211}, /* " */
412 {'`', ' ', 212}, /* ' */
413 {'\'', ' ', 213}, /* ' */
414 {'-', ':', 214}, /* */
415 {'D', 'I', 215}, /* */
416 {'y', ':', 216}, /* */
417 {'Y', ':', 217}, /* */
418 {'/', '/', 218}, /* */
419 {'E', '=', 219}, /* Euro System >=8.5 */
420 {'o', 'x', 219}, /* Currency System <=8.1*/
421 {'<', ' ', 220}, /* */
422 {'>', ' ', 221}, /* */
423 {'f', 'i', 222}, /* */
424 {'f', 'l', 223}, /* */
425 {'+', '+', 224}, /* */
426 {'~', '.', 225}, /* */
427 {',', ' ', 226}, /* */
428 {',', ',', 227}, /* */
429 {'%', '.', 228}, /* */
430 {'%', '0', 228}, /* */
431 {'A', '^', 229}, /* */
432 {'E', '^', 230}, /* */
433 {'A', '\'', 231}, /* */
434 {'E', '"', 232}, /* */
435 {'E', '`', 233}, /* */
436 {'I', '\'', 234}, /* */
437 {'I', '^', 235}, /* */
438 {'I', '"', 236}, /* */
439 {'I', '`', 237}, /* */
440 {'O', '\'', 238}, /* */
441 {'O', '^', 239}, /* */
442 {'A', 'P', 240}, /* */
443 {'O', '`', 241}, /* */
444 {'U', '\'', 242}, /* */
445 {'U', '^', 243}, /* */
446 {'U', '`', 244}, /* */
447 {'i', '.', 245}, /* */
448 {NUL, NUL, NUL}
449 };
450
451 # else /* !MACOS_X */
452
453 # ifdef OLD_DIGRAPHS
454 320
455 /* 321 /*
456 * digraphs compatible with Vim 5.x 322 * digraphs compatible with Vim 5.x
457 */ 323 */
458 {{'~', '!', 161}, /* */ 324 {{'~', '!', 161}, /* */
555 {'y', '\'', 253}, /* */ 421 {'y', '\'', 253}, /* */
556 {'i', 'p', 254}, /* */ 422 {'i', 'p', 254}, /* */
557 {'y', '"', 255}, /* x XX */ 423 {'y', '"', 255}, /* x XX */
558 {NUL, NUL, NUL} 424 {NUL, NUL, NUL}
559 }; 425 };
560 # else /* OLD_DIGRAPHS */ 426 # else /* OLD_DIGRAPHS */
561 427
562 /* 428 /*
563 * digraphs for Unicode from RFC1345 429 * digraphs for Unicode from RFC1345
564 * (also work for ISO-8859-1 aka latin1) 430 * (also work for ISO-8859-1 aka latin1)
565 */ 431 */
790 {'y', '\'', 0xfd}, 656 {'y', '\'', 0xfd},
791 {'t', 'h', 0xfe}, 657 {'t', 'h', 0xfe},
792 {'y', ':', 0xff}, 658 {'y', ':', 0xff},
793 {'y', '"', 0xff}, // x XX Vim 5.x compatible 659 {'y', '"', 0xff}, // x XX Vim 5.x compatible
794 660
795 # ifdef FEAT_MBYTE
796 # define USE_UNICODE_DIGRAPHS 661 # define USE_UNICODE_DIGRAPHS
797 662
798 {'A', '-', 0x0100}, 663 {'A', '-', 0x0100},
799 {'a', '-', 0x0101}, 664 {'a', '-', 0x0101},
800 {'A', '(', 0x0102}, 665 {'A', '(', 0x0102},
1955 {'f', 'f', 0xfb00}, 1820 {'f', 'f', 0xfb00},
1956 {'f', 'i', 0xfb01}, 1821 {'f', 'i', 0xfb01},
1957 {'f', 'l', 0xfb02}, 1822 {'f', 'l', 0xfb02},
1958 {'f', 't', 0xfb05}, 1823 {'f', 't', 0xfb05},
1959 {'s', 't', 0xfb06}, 1824 {'s', 't', 0xfb06},
1960 # endif /* FEAT_MBYTE */
1961 1825
1962 {NUL, NUL, NUL} 1826 {NUL, NUL, NUL}
1963 }; 1827 };
1964 1828
1965 # endif /* OLD_DIGRAPHS */ 1829 # endif /* OLD_DIGRAPHS */
1966
1967 # endif /* Macintosh */
1968 # endif /* EBCDIC */ 1830 # endif /* EBCDIC */
1969 # endif /* !HPUX_DIGRAPHS */ 1831 # endif /* !HPUX_DIGRAPHS */
1970 #endif /* !__MINT__ */ 1832 #endif /* !__MINT__ */
1971 1833
1972 /* 1834 /*
2139 break; 2001 break;
2140 } 2002 }
2141 ++dp; 2003 ++dp;
2142 } 2004 }
2143 } 2005 }
2144 #ifdef FEAT_MBYTE 2006 #ifdef USE_UNICODE_DIGRAPHS
2145 # ifdef USE_UNICODE_DIGRAPHS
2146 if (retval != 0 && !enc_utf8) 2007 if (retval != 0 && !enc_utf8)
2147 { 2008 {
2148 char_u buf[6], *to; 2009 char_u buf[6], *to;
2149 vimconv_T vc; 2010 vimconv_T vc;
2150 2011
2164 vim_free(to); 2025 vim_free(to);
2165 } 2026 }
2166 (void)convert_setup(&vc, NULL, NULL); 2027 (void)convert_setup(&vc, NULL, NULL);
2167 } 2028 }
2168 } 2029 }
2169 # endif 2030 #endif
2170 2031
2171 /* Ignore multi-byte characters when not in multi-byte mode. */ 2032 /* Ignore multi-byte characters when not in multi-byte mode. */
2172 if (!has_mbyte && retval > 0xff) 2033 if (!has_mbyte && retval > 0xff)
2173 retval = 0; 2034 retval = 0;
2174 #endif
2175 2035
2176 if (retval == 0) /* digraph deleted or not found */ 2036 if (retval == 0) /* digraph deleted or not found */
2177 { 2037 {
2178 if (char1 == ' ' && meta_char) /* <space> <char> --> meta-char */ 2038 if (char1 == ' ' && meta_char) /* <space> <char> --> meta-char */
2179 return (char2 | 0x80); 2039 return (char2 | 0x80);
2295 && (has_mbyte || tmp.result <= 255)) 2155 && (has_mbyte || tmp.result <= 255))
2296 printdigraph(&tmp, use_headers ? &previous : NULL); 2156 printdigraph(&tmp, use_headers ? &previous : NULL);
2297 #else 2157 #else
2298 2158
2299 if (getexactdigraph(dp->char1, dp->char2, FALSE) == dp->result 2159 if (getexactdigraph(dp->char1, dp->char2, FALSE) == dp->result
2300 # ifdef FEAT_MBYTE 2160 && (has_mbyte || dp->result <= 255))
2301 && (has_mbyte || dp->result <= 255)
2302 # endif
2303 )
2304 printdigraph(dp, use_headers ? &previous : NULL); 2161 printdigraph(dp, use_headers ? &previous : NULL);
2305 #endif 2162 #endif
2306 ++dp; 2163 ++dp;
2307 ui_breakcheck(); 2164 ui_breakcheck();
2308 } 2165 }
2362 char_u buf[30]; 2219 char_u buf[30];
2363 char_u *p; 2220 char_u *p;
2364 2221
2365 int list_width; 2222 int list_width;
2366 2223
2367 if ((dy_flags & DY_UHEX) 2224 if ((dy_flags & DY_UHEX) || has_mbyte)
2368 #ifdef FEAT_MBYTE
2369 || has_mbyte
2370 #endif
2371 )
2372 list_width = 13; 2225 list_width = 13;
2373 else 2226 else
2374 list_width = 11; 2227 list_width = 11;
2375 2228
2376 if (dp->result != 0) 2229 if (dp->result != 0)
2402 *p++ = dp->char2; 2255 *p++ = dp->char2;
2403 *p++ = ' '; 2256 *p++ = ' ';
2404 *p = NUL; 2257 *p = NUL;
2405 msg_outtrans(buf); 2258 msg_outtrans(buf);
2406 p = buf; 2259 p = buf;
2407 #ifdef FEAT_MBYTE
2408 if (has_mbyte) 2260 if (has_mbyte)
2409 { 2261 {
2410 /* add a space to draw a composing char on */ 2262 /* add a space to draw a composing char on */
2411 if (enc_utf8 && utf_iscomposing(dp->result)) 2263 if (enc_utf8 && utf_iscomposing(dp->result))
2412 *p++ = ' '; 2264 *p++ = ' ';
2413 p += (*mb_char2bytes)(dp->result, p); 2265 p += (*mb_char2bytes)(dp->result, p);
2414 } 2266 }
2415 else 2267 else
2416 #endif
2417 *p++ = (char_u)dp->result; 2268 *p++ = (char_u)dp->result;
2418 *p = NUL; 2269 *p = NUL;
2419 msg_outtrans_attr(buf, HL_ATTR(HLF_8)); 2270 msg_outtrans_attr(buf, HL_ATTR(HLF_8));
2420 p = buf; 2271 p = buf;
2421 if (char2cells(dp->result) == 1) 2272 if (char2cells(dp->result) == 1)
2463 char_u *buf; 2314 char_u *buf;
2464 size_t buflen; 2315 size_t buflen;
2465 2316
2466 /* Source the keymap file. It will contain a ":loadkeymap" command 2317 /* Source the keymap file. It will contain a ":loadkeymap" command
2467 * which will call ex_loadkeymap() below. */ 2318 * which will call ex_loadkeymap() below. */
2468 buflen = STRLEN(curbuf->b_p_keymap) 2319 buflen = STRLEN(curbuf->b_p_keymap) + STRLEN(p_enc) + 14;
2469 # ifdef FEAT_MBYTE
2470 + STRLEN(p_enc)
2471 # endif
2472 + 14;
2473 buf = alloc((unsigned)buflen); 2320 buf = alloc((unsigned)buflen);
2474 if (buf == NULL) 2321 if (buf == NULL)
2475 return e_outofmem; 2322 return e_outofmem;
2476 2323
2477 # ifdef FEAT_MBYTE
2478 /* try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath' */ 2324 /* try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath' */
2479 vim_snprintf((char *)buf, buflen, "keymap/%s_%s.vim", 2325 vim_snprintf((char *)buf, buflen, "keymap/%s_%s.vim",
2480 curbuf->b_p_keymap, p_enc); 2326 curbuf->b_p_keymap, p_enc);
2481 if (source_runtime(buf, 0) == FAIL) 2327 if (source_runtime(buf, 0) == FAIL)
2482 # endif
2483 { 2328 {
2484 /* try finding "keymap/'keymap'.vim" in 'runtimepath' */ 2329 /* try finding "keymap/'keymap'.vim" in 'runtimepath' */
2485 vim_snprintf((char *)buf, buflen, "keymap/%s.vim", 2330 vim_snprintf((char *)buf, buflen, "keymap/%s.vim",
2486 curbuf->b_p_keymap); 2331 curbuf->b_p_keymap);
2487 if (source_runtime(buf, 0) == FAIL) 2332 if (source_runtime(buf, 0) == FAIL)