Mercurial > vim
comparison src/ui.c @ 15605:62b3805506b3 v8.1.0810
patch 8.1.0810: too many #ifdefs
commit https://github.com/vim/vim/commit/264b74fa545edfb92c0d7d08a02c26331cc5b168
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jan 24 17:18:42 2019 +0100
patch 8.1.0810: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_MBYTE, part 4.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 24 Jan 2019 17:30:08 +0100 |
parents | d89c5b339c2a |
children | 6f1c7e9a6393 |
comparison
equal
deleted
inserted
replaced
15604:5d64befd4ab4 | 15605:62b3805506b3 |
---|---|
38 #endif | 38 #endif |
39 #ifndef NO_CONSOLE | 39 #ifndef NO_CONSOLE |
40 /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */ | 40 /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */ |
41 if (!(silent_mode && p_verbose == 0)) | 41 if (!(silent_mode && p_verbose == 0)) |
42 { | 42 { |
43 #if defined(FEAT_MBYTE) && !defined(WIN3264) | 43 #if !defined(WIN3264) |
44 char_u *tofree = NULL; | 44 char_u *tofree = NULL; |
45 | 45 |
46 if (output_conv.vc_type != CONV_NONE) | 46 if (output_conv.vc_type != CONV_NONE) |
47 { | 47 { |
48 /* Convert characters from 'encoding' to 'termencoding'. */ | 48 /* Convert characters from 'encoding' to 'termencoding'. */ |
52 } | 52 } |
53 #endif | 53 #endif |
54 | 54 |
55 mch_write(s, len); | 55 mch_write(s, len); |
56 | 56 |
57 #if defined(FEAT_MBYTE) && !defined(WIN3264) | 57 # if !defined(WIN3264) |
58 if (output_conv.vc_type != CONV_NONE) | 58 if (output_conv.vc_type != CONV_NONE) |
59 vim_free(tofree); | 59 vim_free(tofree); |
60 #endif | 60 # endif |
61 } | 61 } |
62 #endif | 62 #endif |
63 } | 63 } |
64 | 64 |
65 #if defined(UNIX) || defined(VMS) || defined(PROTO) || defined(WIN3264) | 65 #if defined(UNIX) || defined(VMS) || defined(PROTO) || defined(WIN3264) |
514 { | 514 { |
515 if (LT_POS(VIsual, curwin->w_cursor)) | 515 if (LT_POS(VIsual, curwin->w_cursor)) |
516 { | 516 { |
517 start = VIsual; | 517 start = VIsual; |
518 end = curwin->w_cursor; | 518 end = curwin->w_cursor; |
519 #ifdef FEAT_MBYTE | |
520 if (has_mbyte) | 519 if (has_mbyte) |
521 end.col += (*mb_ptr2len)(ml_get_cursor()) - 1; | 520 end.col += (*mb_ptr2len)(ml_get_cursor()) - 1; |
522 #endif | |
523 } | 521 } |
524 else | 522 else |
525 { | 523 { |
526 start = curwin->w_cursor; | 524 start = curwin->w_cursor; |
527 end = VIsual; | 525 end = VIsual; |
819 if (cb->state == SELECT_DONE) | 817 if (cb->state == SELECT_DONE) |
820 clip_clear_selection(cb); | 818 clip_clear_selection(cb); |
821 | 819 |
822 row = check_row(row); | 820 row = check_row(row); |
823 col = check_col(col); | 821 col = check_col(col); |
824 #ifdef FEAT_MBYTE | |
825 col = mb_fix_col(col, row); | 822 col = mb_fix_col(col, row); |
826 #endif | |
827 | 823 |
828 cb->start.lnum = row; | 824 cb->start.lnum = row; |
829 cb->start.col = col; | 825 cb->start.col = col; |
830 cb->end = cb->start; | 826 cb->end = cb->start; |
831 cb->origin_row = (short_u)cb->start.lnum; | 827 cb->origin_row = (short_u)cb->start.lnum; |
925 return; | 921 return; |
926 } | 922 } |
927 | 923 |
928 row = check_row(row); | 924 row = check_row(row); |
929 col = check_col(col); | 925 col = check_col(col); |
930 #ifdef FEAT_MBYTE | |
931 col = mb_fix_col(col, row); | 926 col = mb_fix_col(col, row); |
932 #endif | |
933 | 927 |
934 if (col == (int)cb->prev.col && row == cb->prev.lnum && !repeated_click) | 928 if (col == (int)cb->prev.col && row == cb->prev.lnum && !repeated_click) |
935 return; | 929 return; |
936 | 930 |
937 /* | 931 /* |
993 if (col >= (int)cb->word_end_col) | 987 if (col >= (int)cb->word_end_col) |
994 clip_update_modeless_selection(cb, cb->origin_row, | 988 clip_update_modeless_selection(cb, cb->origin_row, |
995 cb->origin_start_col, row, (int)Columns); | 989 cb->origin_start_col, row, (int)Columns); |
996 else | 990 else |
997 { | 991 { |
998 #ifdef FEAT_MBYTE | |
999 if (has_mbyte && mb_lefthalve(row, col)) | 992 if (has_mbyte && mb_lefthalve(row, col)) |
1000 slen = 2; | 993 slen = 2; |
1001 #endif | |
1002 clip_update_modeless_selection(cb, cb->origin_row, | 994 clip_update_modeless_selection(cb, cb->origin_row, |
1003 cb->origin_start_col, row, col + slen); | 995 cb->origin_start_col, row, col + slen); |
1004 } | 996 } |
1005 } | 997 } |
1006 else | 998 else |
1007 { | 999 { |
1008 #ifdef FEAT_MBYTE | |
1009 if (has_mbyte | 1000 if (has_mbyte |
1010 && mb_lefthalve(cb->origin_row, cb->origin_start_col)) | 1001 && mb_lefthalve(cb->origin_row, cb->origin_start_col)) |
1011 slen = 2; | 1002 slen = 2; |
1012 #endif | |
1013 if (col >= (int)cb->word_end_col) | 1003 if (col >= (int)cb->word_end_col) |
1014 clip_update_modeless_selection(cb, row, cb->word_end_col, | 1004 clip_update_modeless_selection(cb, row, cb->word_end_col, |
1015 cb->origin_row, cb->origin_start_col + slen); | 1005 cb->origin_row, cb->origin_start_col + slen); |
1016 else | 1006 else |
1017 clip_update_modeless_selection(cb, row, col, | 1007 clip_update_modeless_selection(cb, row, col, |
1241 int start_col; | 1231 int start_col; |
1242 int end_col; | 1232 int end_col; |
1243 int line_end_col; | 1233 int line_end_col; |
1244 int add_newline_flag = FALSE; | 1234 int add_newline_flag = FALSE; |
1245 int len; | 1235 int len; |
1246 #ifdef FEAT_MBYTE | |
1247 char_u *p; | 1236 char_u *p; |
1248 #endif | |
1249 int row1 = clip_star.start.lnum; | 1237 int row1 = clip_star.start.lnum; |
1250 int col1 = clip_star.start.col; | 1238 int col1 = clip_star.start.col; |
1251 int row2 = clip_star.end.lnum; | 1239 int row2 = clip_star.end.lnum; |
1252 int col2 = clip_star.end.col; | 1240 int col2 = clip_star.end.col; |
1253 | 1241 |
1265 } | 1253 } |
1266 else if (row1 == row2 && col1 > col2) | 1254 else if (row1 == row2 && col1 > col2) |
1267 { | 1255 { |
1268 row = col1; col1 = col2; col2 = row; | 1256 row = col1; col1 = col2; col2 = row; |
1269 } | 1257 } |
1270 #ifdef FEAT_MBYTE | |
1271 /* correct starting point for being on right halve of double-wide char */ | 1258 /* correct starting point for being on right halve of double-wide char */ |
1272 p = ScreenLines + LineOffset[row1]; | 1259 p = ScreenLines + LineOffset[row1]; |
1273 if (enc_dbcs != 0) | 1260 if (enc_dbcs != 0) |
1274 col1 -= (*mb_head_off)(p, p + col1); | 1261 col1 -= (*mb_head_off)(p, p + col1); |
1275 else if (enc_utf8 && p[col1] == 0) | 1262 else if (enc_utf8 && p[col1] == 0) |
1276 --col1; | 1263 --col1; |
1277 #endif | |
1278 | 1264 |
1279 /* Create a temporary buffer for storing the text */ | 1265 /* Create a temporary buffer for storing the text */ |
1280 len = (row2 - row1 + 1) * Columns + 1; | 1266 len = (row2 - row1 + 1) * Columns + 1; |
1281 #ifdef FEAT_MBYTE | |
1282 if (enc_dbcs != 0) | 1267 if (enc_dbcs != 0) |
1283 len *= 2; /* max. 2 bytes per display cell */ | 1268 len *= 2; /* max. 2 bytes per display cell */ |
1284 else if (enc_utf8) | 1269 else if (enc_utf8) |
1285 len *= MB_MAXBYTES; | 1270 len *= MB_MAXBYTES; |
1286 #endif | |
1287 buffer = lalloc((long_u)len, TRUE); | 1271 buffer = lalloc((long_u)len, TRUE); |
1288 if (buffer == NULL) /* out of memory */ | 1272 if (buffer == NULL) /* out of memory */ |
1289 return; | 1273 return; |
1290 | 1274 |
1291 /* Process each row in the selection */ | 1275 /* Process each row in the selection */ |
1320 if (row > row1 && !LineWraps[row - 1]) | 1304 if (row > row1 && !LineWraps[row - 1]) |
1321 *bufp++ = NL; | 1305 *bufp++ = NL; |
1322 | 1306 |
1323 if (row < screen_Rows && end_col <= screen_Columns) | 1307 if (row < screen_Rows && end_col <= screen_Columns) |
1324 { | 1308 { |
1325 #ifdef FEAT_MBYTE | |
1326 if (enc_dbcs != 0) | 1309 if (enc_dbcs != 0) |
1327 { | 1310 { |
1328 int i; | 1311 int i; |
1329 | 1312 |
1330 p = ScreenLines + LineOffset[row]; | 1313 p = ScreenLines + LineOffset[row]; |
1371 if (ScreenLines[off + i + 1] == 0) | 1354 if (ScreenLines[off + i + 1] == 0) |
1372 ++i; | 1355 ++i; |
1373 } | 1356 } |
1374 } | 1357 } |
1375 else | 1358 else |
1376 #endif | |
1377 { | 1359 { |
1378 STRNCPY(bufp, ScreenLines + LineOffset[row] + start_col, | 1360 STRNCPY(bufp, ScreenLines + LineOffset[row] + start_col, |
1379 end_col - start_col); | 1361 end_col - start_col); |
1380 bufp += end_col - start_col; | 1362 bufp += end_col - start_col; |
1381 } | 1363 } |
1419 clip_get_word_boundaries(VimClipboard *cb, int row, int col) | 1401 clip_get_word_boundaries(VimClipboard *cb, int row, int col) |
1420 { | 1402 { |
1421 int start_class; | 1403 int start_class; |
1422 int temp_col; | 1404 int temp_col; |
1423 char_u *p; | 1405 char_u *p; |
1424 #ifdef FEAT_MBYTE | |
1425 int mboff; | 1406 int mboff; |
1426 #endif | |
1427 | 1407 |
1428 if (row >= screen_Rows || col >= screen_Columns || ScreenLines == NULL) | 1408 if (row >= screen_Rows || col >= screen_Columns || ScreenLines == NULL) |
1429 return; | 1409 return; |
1430 | 1410 |
1431 p = ScreenLines + LineOffset[row]; | 1411 p = ScreenLines + LineOffset[row]; |
1432 #ifdef FEAT_MBYTE | |
1433 /* Correct for starting in the right halve of a double-wide char */ | 1412 /* Correct for starting in the right halve of a double-wide char */ |
1434 if (enc_dbcs != 0) | 1413 if (enc_dbcs != 0) |
1435 col -= dbcs_screen_head_off(p, p + col); | 1414 col -= dbcs_screen_head_off(p, p + col); |
1436 else if (enc_utf8 && p[col] == 0) | 1415 else if (enc_utf8 && p[col] == 0) |
1437 --col; | 1416 --col; |
1438 #endif | |
1439 start_class = CHAR_CLASS(p[col]); | 1417 start_class = CHAR_CLASS(p[col]); |
1440 | 1418 |
1441 temp_col = col; | 1419 temp_col = col; |
1442 for ( ; temp_col > 0; temp_col--) | 1420 for ( ; temp_col > 0; temp_col--) |
1443 #ifdef FEAT_MBYTE | |
1444 if (enc_dbcs != 0 | 1421 if (enc_dbcs != 0 |
1445 && (mboff = dbcs_screen_head_off(p, p + temp_col - 1)) > 0) | 1422 && (mboff = dbcs_screen_head_off(p, p + temp_col - 1)) > 0) |
1446 temp_col -= mboff; | 1423 temp_col -= mboff; |
1447 else | 1424 else if (CHAR_CLASS(p[temp_col - 1]) != start_class |
1448 #endif | 1425 && !(enc_utf8 && p[temp_col - 1] == 0)) |
1449 if (CHAR_CLASS(p[temp_col - 1]) != start_class | |
1450 #ifdef FEAT_MBYTE | |
1451 && !(enc_utf8 && p[temp_col - 1] == 0) | |
1452 #endif | |
1453 ) | |
1454 break; | 1426 break; |
1455 cb->word_start_col = temp_col; | 1427 cb->word_start_col = temp_col; |
1456 | 1428 |
1457 temp_col = col; | 1429 temp_col = col; |
1458 for ( ; temp_col < screen_Columns; temp_col++) | 1430 for ( ; temp_col < screen_Columns; temp_col++) |
1459 #ifdef FEAT_MBYTE | |
1460 if (enc_dbcs != 0 && dbcs_ptr2cells(p + temp_col) == 2) | 1431 if (enc_dbcs != 0 && dbcs_ptr2cells(p + temp_col) == 2) |
1461 ++temp_col; | 1432 ++temp_col; |
1462 else | 1433 else if (CHAR_CLASS(p[temp_col]) != start_class |
1463 #endif | 1434 && !(enc_utf8 && p[temp_col] == 0)) |
1464 if (CHAR_CLASS(p[temp_col]) != start_class | |
1465 #ifdef FEAT_MBYTE | |
1466 && !(enc_utf8 && p[temp_col] == 0) | |
1467 #endif | |
1468 ) | |
1469 break; | 1435 break; |
1470 cb->word_end_col = temp_col; | 1436 cb->word_end_col = temp_col; |
1471 } | 1437 } |
1472 | 1438 |
1473 /* | 1439 /* |
1818 { | 1784 { |
1819 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) | 1785 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
1820 int len; | 1786 int len; |
1821 int try; | 1787 int try; |
1822 static int did_read_something = FALSE; | 1788 static int did_read_something = FALSE; |
1823 # ifdef FEAT_MBYTE | |
1824 static char_u *rest = NULL; /* unconverted rest of previous read */ | 1789 static char_u *rest = NULL; /* unconverted rest of previous read */ |
1825 static int restlen = 0; | 1790 static int restlen = 0; |
1826 int unconverted; | 1791 int unconverted; |
1827 # endif | |
1828 #endif | 1792 #endif |
1829 | 1793 |
1830 #ifdef FEAT_GUI | 1794 #ifdef FEAT_GUI |
1831 if (gui.in_use | 1795 if (gui.in_use |
1832 # ifdef NO_CONSOLE_INPUT | 1796 # ifdef NO_CONSOLE_INPUT |
1858 ; | 1822 ; |
1859 len = inbufcount; | 1823 len = inbufcount; |
1860 inbufcount = 0; | 1824 inbufcount = 0; |
1861 # else | 1825 # else |
1862 | 1826 |
1863 # ifdef FEAT_MBYTE | |
1864 if (rest != NULL) | 1827 if (rest != NULL) |
1865 { | 1828 { |
1866 /* Use remainder of previous call, starts with an invalid character | 1829 /* Use remainder of previous call, starts with an invalid character |
1867 * that may become valid when reading more. */ | 1830 * that may become valid when reading more. */ |
1868 if (restlen > INBUFLEN - inbufcount) | 1831 if (restlen > INBUFLEN - inbufcount) |
1879 } | 1842 } |
1880 inbufcount += unconverted; | 1843 inbufcount += unconverted; |
1881 } | 1844 } |
1882 else | 1845 else |
1883 unconverted = 0; | 1846 unconverted = 0; |
1884 # endif | |
1885 | 1847 |
1886 len = 0; /* to avoid gcc warning */ | 1848 len = 0; /* to avoid gcc warning */ |
1887 for (try = 0; try < 100; ++try) | 1849 for (try = 0; try < 100; ++try) |
1888 { | 1850 { |
1889 size_t readlen = (size_t)((INBUFLEN - inbufcount) | 1851 size_t readlen = (size_t)((INBUFLEN - inbufcount) |
1890 # ifdef FEAT_MBYTE | 1852 / input_conv.vc_factor); |
1891 / input_conv.vc_factor | |
1892 # endif | |
1893 ); | |
1894 # ifdef VMS | 1853 # ifdef VMS |
1895 len = vms_read((char *)inbuf + inbufcount, readlen); | 1854 len = vms_read((char *)inbuf + inbufcount, readlen); |
1896 # else | 1855 # else |
1897 len = read(read_cmd_fd, (char *)inbuf + inbufcount, readlen); | 1856 len = read(read_cmd_fd, (char *)inbuf + inbufcount, readlen); |
1898 # endif | 1857 # endif |
1934 inbuf[0] = 3; | 1893 inbuf[0] = 3; |
1935 inbufcount = 1; | 1894 inbufcount = 1; |
1936 } | 1895 } |
1937 else | 1896 else |
1938 { | 1897 { |
1939 # ifdef FEAT_MBYTE | |
1940 /* | 1898 /* |
1941 * May perform conversion on the input characters. | 1899 * May perform conversion on the input characters. |
1942 * Include the unconverted rest of the previous call. | 1900 * Include the unconverted rest of the previous call. |
1943 * If there is an incomplete char at the end it is kept for the next | 1901 * If there is an incomplete char at the end it is kept for the next |
1944 * time, reading more bytes should make conversion possible. | 1902 * time, reading more bytes should make conversion possible. |
1950 inbufcount -= unconverted; | 1908 inbufcount -= unconverted; |
1951 len = convert_input_safe(inbuf + inbufcount, | 1909 len = convert_input_safe(inbuf + inbufcount, |
1952 len + unconverted, INBUFLEN - inbufcount, | 1910 len + unconverted, INBUFLEN - inbufcount, |
1953 rest == NULL ? &rest : NULL, &restlen); | 1911 rest == NULL ? &rest : NULL, &restlen); |
1954 } | 1912 } |
1955 # endif | |
1956 while (len-- > 0) | 1913 while (len-- > 0) |
1957 { | 1914 { |
1958 /* | 1915 /* |
1959 * if a CTRL-C was typed, remove it from the buffer and set got_int | 1916 * if a CTRL-C was typed, remove it from the buffer and set got_int |
1960 */ | 1917 */ |
2012 { | 1969 { |
2013 ui_cursor_shape_forced(FALSE); | 1970 ui_cursor_shape_forced(FALSE); |
2014 } | 1971 } |
2015 #endif | 1972 #endif |
2016 | 1973 |
2017 #if defined(FEAT_CLIPBOARD) || defined(FEAT_GUI) || defined(FEAT_RIGHTLEFT) \ | |
2018 || defined(FEAT_MBYTE) || defined(PROTO) | |
2019 /* | 1974 /* |
2020 * Check bounds for column number | 1975 * Check bounds for column number |
2021 */ | 1976 */ |
2022 int | 1977 int |
2023 check_col(int col) | 1978 check_col(int col) |
2039 return 0; | 1994 return 0; |
2040 if (row >= (int)screen_Rows) | 1995 if (row >= (int)screen_Rows) |
2041 return (int)screen_Rows - 1; | 1996 return (int)screen_Rows - 1; |
2042 return row; | 1997 return row; |
2043 } | 1998 } |
2044 #endif | |
2045 | 1999 |
2046 /* | 2000 /* |
2047 * Stuff for the X clipboard. Shared between VMS and Unix. | 2001 * Stuff for the X clipboard. Shared between VMS and Unix. |
2048 */ | 2002 */ |
2049 | 2003 |
2064 app_context = XtCreateApplicationContext(); | 2018 app_context = XtCreateApplicationContext(); |
2065 } | 2019 } |
2066 } | 2020 } |
2067 | 2021 |
2068 static Atom vim_atom; /* Vim's own special selection format */ | 2022 static Atom vim_atom; /* Vim's own special selection format */ |
2069 #ifdef FEAT_MBYTE | |
2070 static Atom vimenc_atom; /* Vim's extended selection format */ | 2023 static Atom vimenc_atom; /* Vim's extended selection format */ |
2071 static Atom utf8_atom; | 2024 static Atom utf8_atom; |
2072 #endif | |
2073 static Atom compound_text_atom; | 2025 static Atom compound_text_atom; |
2074 static Atom text_atom; | 2026 static Atom text_atom; |
2075 static Atom targets_atom; | 2027 static Atom targets_atom; |
2076 static Atom timestamp_atom; /* Used to get a timestamp */ | 2028 static Atom timestamp_atom; /* Used to get a timestamp */ |
2077 | 2029 |
2078 void | 2030 void |
2079 x11_setup_atoms(Display *dpy) | 2031 x11_setup_atoms(Display *dpy) |
2080 { | 2032 { |
2081 vim_atom = XInternAtom(dpy, VIM_ATOM_NAME, False); | 2033 vim_atom = XInternAtom(dpy, VIM_ATOM_NAME, False); |
2082 #ifdef FEAT_MBYTE | |
2083 vimenc_atom = XInternAtom(dpy, VIMENC_ATOM_NAME,False); | 2034 vimenc_atom = XInternAtom(dpy, VIMENC_ATOM_NAME,False); |
2084 utf8_atom = XInternAtom(dpy, "UTF8_STRING", False); | 2035 utf8_atom = XInternAtom(dpy, "UTF8_STRING", False); |
2085 #endif | |
2086 compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False); | 2036 compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False); |
2087 text_atom = XInternAtom(dpy, "TEXT", False); | 2037 text_atom = XInternAtom(dpy, "TEXT", False); |
2088 targets_atom = XInternAtom(dpy, "TARGETS", False); | 2038 targets_atom = XInternAtom(dpy, "TARGETS", False); |
2089 clip_star.sel_atom = XA_PRIMARY; | 2039 clip_star.sel_atom = XA_PRIMARY; |
2090 clip_plus.sel_atom = XInternAtom(dpy, "CLIPBOARD", False); | 2040 clip_plus.sel_atom = XInternAtom(dpy, "CLIPBOARD", False); |
2168 int motion_type = MAUTO; | 2118 int motion_type = MAUTO; |
2169 long_u len; | 2119 long_u len; |
2170 char_u *p; | 2120 char_u *p; |
2171 char **text_list = NULL; | 2121 char **text_list = NULL; |
2172 VimClipboard *cbd; | 2122 VimClipboard *cbd; |
2173 #ifdef FEAT_MBYTE | |
2174 char_u *tmpbuf = NULL; | 2123 char_u *tmpbuf = NULL; |
2175 #endif | |
2176 | 2124 |
2177 if (*sel_atom == clip_plus.sel_atom) | 2125 if (*sel_atom == clip_plus.sel_atom) |
2178 cbd = &clip_plus; | 2126 cbd = &clip_plus; |
2179 else | 2127 else |
2180 cbd = &clip_star; | 2128 cbd = &clip_star; |
2191 { | 2139 { |
2192 motion_type = *p++; | 2140 motion_type = *p++; |
2193 len--; | 2141 len--; |
2194 } | 2142 } |
2195 | 2143 |
2196 #ifdef FEAT_MBYTE | |
2197 else if (*type == vimenc_atom) | 2144 else if (*type == vimenc_atom) |
2198 { | 2145 { |
2199 char_u *enc; | 2146 char_u *enc; |
2200 vimconv_T conv; | 2147 vimconv_T conv; |
2201 int convlen; | 2148 int convlen; |
2219 if (tmpbuf != NULL) | 2166 if (tmpbuf != NULL) |
2220 p = tmpbuf; | 2167 p = tmpbuf; |
2221 convert_setup(&conv, NULL, NULL); | 2168 convert_setup(&conv, NULL, NULL); |
2222 } | 2169 } |
2223 } | 2170 } |
2224 #endif | |
2225 | 2171 |
2226 else if (*type == compound_text_atom | 2172 else if (*type == compound_text_atom |
2227 #ifdef FEAT_MBYTE | |
2228 || *type == utf8_atom | 2173 || *type == utf8_atom |
2229 #endif | 2174 || (enc_dbcs != 0 && *type == text_atom)) |
2230 || ( | |
2231 #ifdef FEAT_MBYTE | |
2232 enc_dbcs != 0 && | |
2233 #endif | |
2234 *type == text_atom)) | |
2235 { | 2175 { |
2236 XTextProperty text_prop; | 2176 XTextProperty text_prop; |
2237 int n_text = 0; | 2177 int n_text = 0; |
2238 int status; | 2178 int status; |
2239 | 2179 |
2240 text_prop.value = (unsigned char *)value; | 2180 text_prop.value = (unsigned char *)value; |
2241 text_prop.encoding = *type; | 2181 text_prop.encoding = *type; |
2242 text_prop.format = *format; | 2182 text_prop.format = *format; |
2243 text_prop.nitems = len; | 2183 text_prop.nitems = len; |
2244 #if defined(FEAT_MBYTE) && defined(X_HAVE_UTF8_STRING) | 2184 #if defined(X_HAVE_UTF8_STRING) |
2245 if (*type == utf8_atom) | 2185 if (*type == utf8_atom) |
2246 status = Xutf8TextPropertyToTextList(X_DISPLAY, &text_prop, | 2186 status = Xutf8TextPropertyToTextList(X_DISPLAY, &text_prop, |
2247 &text_list, &n_text); | 2187 &text_list, &n_text); |
2248 else | 2188 else |
2249 #endif | 2189 #endif |
2259 } | 2199 } |
2260 clip_yank_selection(motion_type, p, (long)len, cbd); | 2200 clip_yank_selection(motion_type, p, (long)len, cbd); |
2261 | 2201 |
2262 if (text_list != NULL) | 2202 if (text_list != NULL) |
2263 XFreeStringList(text_list); | 2203 XFreeStringList(text_list); |
2264 #ifdef FEAT_MBYTE | |
2265 vim_free(tmpbuf); | 2204 vim_free(tmpbuf); |
2266 #endif | |
2267 XtFree((char *)value); | 2205 XtFree((char *)value); |
2268 *(int *)success = TRUE; | 2206 *(int *)success = TRUE; |
2269 } | 2207 } |
2270 | 2208 |
2271 void | 2209 void |
2279 static int success; | 2217 static int success; |
2280 int i; | 2218 int i; |
2281 time_t start_time; | 2219 time_t start_time; |
2282 int timed_out = FALSE; | 2220 int timed_out = FALSE; |
2283 | 2221 |
2284 for (i = | 2222 for (i = 0; i < 6; i++) |
2285 #ifdef FEAT_MBYTE | |
2286 0 | |
2287 #else | |
2288 1 | |
2289 #endif | |
2290 ; i < 6; i++) | |
2291 { | 2223 { |
2292 switch (i) | 2224 switch (i) |
2293 { | 2225 { |
2294 #ifdef FEAT_MBYTE | |
2295 case 0: type = vimenc_atom; break; | 2226 case 0: type = vimenc_atom; break; |
2296 #endif | |
2297 case 1: type = vim_atom; break; | 2227 case 1: type = vim_atom; break; |
2298 #ifdef FEAT_MBYTE | |
2299 case 2: type = utf8_atom; break; | 2228 case 2: type = utf8_atom; break; |
2300 #endif | |
2301 case 3: type = compound_text_atom; break; | 2229 case 3: type = compound_text_atom; break; |
2302 case 4: type = text_atom; break; | 2230 case 4: type = text_atom; break; |
2303 default: type = XA_STRING; | 2231 default: type = XA_STRING; |
2304 } | 2232 } |
2305 #ifdef FEAT_MBYTE | |
2306 if (type == utf8_atom | 2233 if (type == utf8_atom |
2307 # if defined(X_HAVE_UTF8_STRING) | 2234 # if defined(X_HAVE_UTF8_STRING) |
2308 && !enc_utf8 | 2235 && !enc_utf8 |
2309 # endif | 2236 # endif |
2310 ) | 2237 ) |
2311 /* Only request utf-8 when 'encoding' is utf8 and | 2238 /* Only request utf-8 when 'encoding' is utf8 and |
2312 * Xutf8TextPropertyToTextList is available. */ | 2239 * Xutf8TextPropertyToTextList is available. */ |
2313 continue; | 2240 continue; |
2314 #endif | |
2315 success = MAYBE; | 2241 success = MAYBE; |
2316 XtGetSelectionValue(myShell, cbd->sel_atom, type, | 2242 XtGetSelectionValue(myShell, cbd->sel_atom, type, |
2317 clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); | 2243 clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); |
2318 | 2244 |
2319 /* Make sure the request for the selection goes out before waiting for | 2245 /* Make sure the request for the selection goes out before waiting for |
2404 static Atom array[7]; | 2330 static Atom array[7]; |
2405 | 2331 |
2406 *value = (XtPointer)array; | 2332 *value = (XtPointer)array; |
2407 i = 0; | 2333 i = 0; |
2408 array[i++] = targets_atom; | 2334 array[i++] = targets_atom; |
2409 #ifdef FEAT_MBYTE | |
2410 array[i++] = vimenc_atom; | 2335 array[i++] = vimenc_atom; |
2411 #endif | |
2412 array[i++] = vim_atom; | 2336 array[i++] = vim_atom; |
2413 #ifdef FEAT_MBYTE | |
2414 if (enc_utf8) | 2337 if (enc_utf8) |
2415 array[i++] = utf8_atom; | 2338 array[i++] = utf8_atom; |
2416 #endif | |
2417 array[i++] = XA_STRING; | 2339 array[i++] = XA_STRING; |
2418 array[i++] = text_atom; | 2340 array[i++] = text_atom; |
2419 array[i++] = compound_text_atom; | 2341 array[i++] = compound_text_atom; |
2420 | 2342 |
2421 *type = XA_ATOM; | 2343 *type = XA_ATOM; |
2425 *length = i; | 2347 *length = i; |
2426 return True; | 2348 return True; |
2427 } | 2349 } |
2428 | 2350 |
2429 if ( *target != XA_STRING | 2351 if ( *target != XA_STRING |
2430 #ifdef FEAT_MBYTE | |
2431 && *target != vimenc_atom | 2352 && *target != vimenc_atom |
2432 && (*target != utf8_atom || !enc_utf8) | 2353 && (*target != utf8_atom || !enc_utf8) |
2433 #endif | |
2434 && *target != vim_atom | 2354 && *target != vim_atom |
2435 && *target != text_atom | 2355 && *target != text_atom |
2436 && *target != compound_text_atom) | 2356 && *target != compound_text_atom) |
2437 return False; | 2357 return False; |
2438 | 2358 |
2443 | 2363 |
2444 /* For our own format, the first byte contains the motion type */ | 2364 /* For our own format, the first byte contains the motion type */ |
2445 if (*target == vim_atom) | 2365 if (*target == vim_atom) |
2446 (*length)++; | 2366 (*length)++; |
2447 | 2367 |
2448 #ifdef FEAT_MBYTE | |
2449 /* Our own format with encoding: motion 'encoding' NUL text */ | 2368 /* Our own format with encoding: motion 'encoding' NUL text */ |
2450 if (*target == vimenc_atom) | 2369 if (*target == vimenc_atom) |
2451 *length += STRLEN(p_enc) + 2; | 2370 *length += STRLEN(p_enc) + 2; |
2452 #endif | |
2453 | 2371 |
2454 if (save_length < *length || save_length / 2 >= *length) | 2372 if (save_length < *length || save_length / 2 >= *length) |
2455 *value = XtRealloc((char *)save_result, (Cardinal)*length + 1); | 2373 *value = XtRealloc((char *)save_result, (Cardinal)*length + 1); |
2456 else | 2374 else |
2457 *value = save_result; | 2375 *value = save_result; |
2461 return False; | 2379 return False; |
2462 } | 2380 } |
2463 save_result = (char_u *)*value; | 2381 save_result = (char_u *)*value; |
2464 save_length = *length; | 2382 save_length = *length; |
2465 | 2383 |
2466 if (*target == XA_STRING | 2384 if (*target == XA_STRING || (*target == utf8_atom && enc_utf8)) |
2467 #ifdef FEAT_MBYTE | |
2468 || (*target == utf8_atom && enc_utf8) | |
2469 #endif | |
2470 ) | |
2471 { | 2385 { |
2472 mch_memmove(save_result, string, (size_t)(*length)); | 2386 mch_memmove(save_result, string, (size_t)(*length)); |
2473 *type = *target; | 2387 *type = *target; |
2474 } | 2388 } |
2475 else if (*target == compound_text_atom || *target == text_atom) | 2389 else if (*target == compound_text_atom || *target == text_atom) |
2493 *type = compound_text_atom; | 2407 *type = compound_text_atom; |
2494 XtFree((char *)save_result); | 2408 XtFree((char *)save_result); |
2495 save_result = (char_u *)*value; | 2409 save_result = (char_u *)*value; |
2496 save_length = *length; | 2410 save_length = *length; |
2497 } | 2411 } |
2498 #ifdef FEAT_MBYTE | |
2499 else if (*target == vimenc_atom) | 2412 else if (*target == vimenc_atom) |
2500 { | 2413 { |
2501 int l = STRLEN(p_enc); | 2414 int l = STRLEN(p_enc); |
2502 | 2415 |
2503 save_result[0] = motion_type; | 2416 save_result[0] = motion_type; |
2504 STRCPY(save_result + 1, p_enc); | 2417 STRCPY(save_result + 1, p_enc); |
2505 mch_memmove(save_result + l + 2, string, (size_t)(*length - l - 2)); | 2418 mch_memmove(save_result + l + 2, string, (size_t)(*length - l - 2)); |
2506 *type = vimenc_atom; | 2419 *type = vimenc_atom; |
2507 } | 2420 } |
2508 #endif | |
2509 else | 2421 else |
2510 { | 2422 { |
2511 save_result[0] = motion_type; | 2423 save_result[0] = motion_type; |
2512 mch_memmove(save_result + 1, string, (size_t)(*length - 1)); | 2424 mch_memmove(save_result + 1, string, (size_t)(*length - 1)); |
2513 *type = vim_atom; | 2425 *type = vim_atom; |
2597 int nbytes = 0; | 2509 int nbytes = 0; |
2598 char_u *buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0); | 2510 char_u *buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0); |
2599 | 2511 |
2600 if (nbytes > 0) | 2512 if (nbytes > 0) |
2601 { | 2513 { |
2602 #ifdef FEAT_MBYTE | |
2603 int done = FALSE; | 2514 int done = FALSE; |
2604 | 2515 |
2605 /* CUT_BUFFER0 is supposed to be always latin1. Convert to 'enc' when | 2516 /* CUT_BUFFER0 is supposed to be always latin1. Convert to 'enc' when |
2606 * using a multi-byte encoding. Conversion between two 8-bit | 2517 * using a multi-byte encoding. Conversion between two 8-bit |
2607 * character sets usually fails and the text might actually be in | 2518 * character sets usually fails and the text might actually be in |
2623 } | 2534 } |
2624 convert_setup(&vc, NULL, NULL); | 2535 convert_setup(&vc, NULL, NULL); |
2625 } | 2536 } |
2626 } | 2537 } |
2627 if (!done) /* use the text without conversion */ | 2538 if (!done) /* use the text without conversion */ |
2628 #endif | |
2629 clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd); | 2539 clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd); |
2630 XFree((void *)buffer); | 2540 XFree((void *)buffer); |
2631 if (p_verbose > 0) | 2541 if (p_verbose > 0) |
2632 { | 2542 { |
2633 verbose_enter(); | 2543 verbose_enter(); |