Mirror of the Vim source from https://github.com/vim/vim
Revisão | a4365075d05c40606c2ace3340e9484a6b045f32 (tree) |
---|---|
Hora | 2007-08-30 20:53:22 |
Autor | vimboss |
Commiter | vimboss |
updated for version 7.1-093
@@ -801,7 +801,7 @@ | ||
801 | 801 | EXTERN int (*mb_char2bytes) __ARGS((int c, char_u *buf)) INIT(= latin_char2bytes); |
802 | 802 | EXTERN int (*mb_ptr2cells) __ARGS((char_u *p)) INIT(= latin_ptr2cells); |
803 | 803 | EXTERN int (*mb_char2cells) __ARGS((int c)) INIT(= latin_char2cells); |
804 | -EXTERN int (*mb_off2cells) __ARGS((unsigned off)) INIT(= latin_off2cells); | |
804 | +EXTERN int (*mb_off2cells) __ARGS((unsigned off, unsigned max_off)) INIT(= latin_off2cells); | |
805 | 805 | EXTERN int (*mb_ptr2char) __ARGS((char_u *p)) INIT(= latin_ptr2char); |
806 | 806 | EXTERN int (*mb_head_off) __ARGS((char_u *base, char_u *p)) INIT(= latin_head_off); |
807 | 807 |
@@ -1080,7 +1080,8 @@ | ||
1080 | 1080 | cur_width = gui.char_width; |
1081 | 1081 | } |
1082 | 1082 | #ifdef FEAT_MBYTE |
1083 | - if (has_mbyte && (*mb_off2cells)(LineOffset[gui.row] + gui.col) > 1) | |
1083 | + if (has_mbyte && (*mb_off2cells)(LineOffset[gui.row] + gui.col, | |
1084 | + LineOffset[gui.row] + screen_Columns) > 1) | |
1084 | 1085 | { |
1085 | 1086 | /* Double wide character. */ |
1086 | 1087 | if (shape_table[idx].shape != SHAPE_VER) |
@@ -1159,7 +1160,7 @@ | ||
1159 | 1160 | #endif |
1160 | 1161 | |
1161 | 1162 | # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \ |
1162 | - || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_MAC)) | |
1163 | + || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_MAC)) | |
1163 | 1164 | if (gui_has_tabline()) |
1164 | 1165 | text_area_y += gui.tabline_height; |
1165 | 1166 | #endif |
@@ -1310,20 +1310,26 @@ | ||
1310 | 1310 | /* |
1311 | 1311 | * mb_off2cells() function pointer. |
1312 | 1312 | * Return number of display cells for char at ScreenLines[off]. |
1313 | - * Caller must make sure "off" and "off + 1" are valid! | |
1313 | + * We make sure that the offset used is less than "max_off". | |
1314 | 1314 | */ |
1315 | 1315 | /*ARGSUSED*/ |
1316 | 1316 | int |
1317 | -latin_off2cells(off) | |
1317 | +latin_off2cells(off, max_off) | |
1318 | 1318 | unsigned off; |
1319 | + unsigned max_off; | |
1319 | 1320 | { |
1320 | 1321 | return 1; |
1321 | 1322 | } |
1322 | 1323 | |
1323 | 1324 | int |
1324 | -dbcs_off2cells(off) | |
1325 | +dbcs_off2cells(off, max_off) | |
1325 | 1326 | unsigned off; |
1327 | + unsigned max_off; | |
1326 | 1328 | { |
1329 | + /* never check beyond end of the line */ | |
1330 | + if (off >= max_off) | |
1331 | + return 1; | |
1332 | + | |
1327 | 1333 | /* Number of cells is equal to number of bytes, except for euc-jp when |
1328 | 1334 | * the first byte is 0x8e. */ |
1329 | 1335 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
@@ -1332,10 +1338,11 @@ | ||
1332 | 1338 | } |
1333 | 1339 | |
1334 | 1340 | int |
1335 | -utf_off2cells(off) | |
1341 | +utf_off2cells(off, max_off) | |
1336 | 1342 | unsigned off; |
1343 | + unsigned max_off; | |
1337 | 1344 | { |
1338 | - return ScreenLines[off + 1] == 0 ? 2 : 1; | |
1345 | + return (off + 1 < max_off && ScreenLines[off + 1] == 0) ? 2 : 1; | |
1339 | 1346 | } |
1340 | 1347 | |
1341 | 1348 | /* |
@@ -2899,12 +2906,8 @@ | ||
2899 | 2906 | if (composing_hangul) |
2900 | 2907 | return TRUE; |
2901 | 2908 | #endif |
2902 | - if (enc_dbcs != 0) | |
2903 | - return dbcs_off2cells(LineOffset[row] + col) > 1; | |
2904 | - if (enc_utf8) | |
2905 | - return (col + 1 < Columns | |
2906 | - && ScreenLines[LineOffset[row] + col + 1] == 0); | |
2907 | - return FALSE; | |
2909 | + return (*mb_off2cells)(LineOffset[row] + col, | |
2910 | + LineOffset[row] + screen_Columns) > 1; | |
2908 | 2911 | } |
2909 | 2912 | |
2910 | 2913 | # if defined(FEAT_CLIPBOARD) || defined(FEAT_GUI) || defined(FEAT_RIGHTLEFT) \ |
@@ -12,9 +12,9 @@ | ||
12 | 12 | int utf_ptr2cells __ARGS((char_u *p)); |
13 | 13 | int dbcs_ptr2cells __ARGS((char_u *p)); |
14 | 14 | int latin_char2cells __ARGS((int c)); |
15 | -int latin_off2cells __ARGS((unsigned off)); | |
16 | -int dbcs_off2cells __ARGS((unsigned off)); | |
17 | -int utf_off2cells __ARGS((unsigned off)); | |
15 | +int latin_off2cells __ARGS((unsigned off, unsigned max_off)); | |
16 | +int dbcs_off2cells __ARGS((unsigned off, unsigned max_off)); | |
17 | +int utf_off2cells __ARGS((unsigned off, unsigned max_off)); | |
18 | 18 | int latin_ptr2char __ARGS((char_u *p)); |
19 | 19 | int utf_ptr2char __ARGS((char_u *p)); |
20 | 20 | int mb_ptr2char_adv __ARGS((char_u **pp)); |
@@ -1024,7 +1024,7 @@ | ||
1024 | 1024 | type = VALID; |
1025 | 1025 | } |
1026 | 1026 | |
1027 | - /* Trick: we want to avoid clearning the screen twice. screenclear() will | |
1027 | + /* Trick: we want to avoid clearing the screen twice. screenclear() will | |
1028 | 1028 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
1029 | 1029 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
1030 | 1030 | * called. */ |
@@ -4632,7 +4632,7 @@ | ||
4632 | 4632 | |
4633 | 4633 | /* |
4634 | 4634 | * At end of screen line and there is more to come: Display the line |
4635 | - * so far. If there is no more to display it is catched above. | |
4635 | + * so far. If there is no more to display it is caught above. | |
4636 | 4636 | */ |
4637 | 4637 | if (( |
4638 | 4638 | #ifdef FEAT_RIGHTLEFT |
@@ -4709,9 +4709,13 @@ | ||
4709 | 4709 | #endif |
4710 | 4710 | #ifdef FEAT_MBYTE |
4711 | 4711 | && !(has_mbyte |
4712 | - && ((*mb_off2cells)(LineOffset[screen_row]) == 2 | |
4712 | + && ((*mb_off2cells)(LineOffset[screen_row], | |
4713 | + LineOffset[screen_row] + screen_Columns) | |
4714 | + == 2 | |
4713 | 4715 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
4714 | - + (int)Columns - 2) == 2)) | |
4716 | + + (int)Columns - 2, | |
4717 | + LineOffset[screen_row] + screen_Columns) | |
4718 | + == 2)) | |
4715 | 4719 | #endif |
4716 | 4720 | ) |
4717 | 4721 | { |
@@ -4871,6 +4875,10 @@ | ||
4871 | 4875 | { |
4872 | 4876 | unsigned off_from; |
4873 | 4877 | unsigned off_to; |
4878 | +#ifdef FEAT_MBYTE | |
4879 | + unsigned max_off_from; | |
4880 | + unsigned max_off_to; | |
4881 | +#endif | |
4874 | 4882 | int col = 0; |
4875 | 4883 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) |
4876 | 4884 | int hl; |
@@ -4897,6 +4905,10 @@ | ||
4897 | 4905 | |
4898 | 4906 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
4899 | 4907 | off_to = LineOffset[row] + coloff; |
4908 | +#ifdef FEAT_MBYTE | |
4909 | + max_off_from = off_from + screen_Columns; | |
4910 | + max_off_to = LineOffset[row] + screen_Columns; | |
4911 | +#endif | |
4900 | 4912 | |
4901 | 4913 | #ifdef FEAT_RIGHTLEFT |
4902 | 4914 | if (rlflag) |
@@ -4931,7 +4943,7 @@ | ||
4931 | 4943 | { |
4932 | 4944 | #ifdef FEAT_MBYTE |
4933 | 4945 | if (has_mbyte && (col + 1 < endcol)) |
4934 | - char_cells = (*mb_off2cells)(off_from); | |
4946 | + char_cells = (*mb_off2cells)(off_from, max_off_from); | |
4935 | 4947 | else |
4936 | 4948 | char_cells = 1; |
4937 | 4949 | #endif |
@@ -5008,7 +5020,7 @@ | ||
5008 | 5020 | * ScreenLinesUC[] is sufficient. */ |
5009 | 5021 | if (char_cells == 1 |
5010 | 5022 | && col + 1 < endcol |
5011 | - && (*mb_off2cells)(off_to) > 1) | |
5023 | + && (*mb_off2cells)(off_to, max_off_to) > 1) | |
5012 | 5024 | { |
5013 | 5025 | /* Writing a single-cell character over a double-cell |
5014 | 5026 | * character: need to redraw the next cell. */ |
@@ -5017,8 +5029,8 @@ | ||
5017 | 5029 | } |
5018 | 5030 | else if (char_cells == 2 |
5019 | 5031 | && col + 2 < endcol |
5020 | - && (*mb_off2cells)(off_to) == 1 | |
5021 | - && (*mb_off2cells)(off_to + 1) > 1) | |
5032 | + && (*mb_off2cells)(off_to, max_off_to) == 1 | |
5033 | + && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
5022 | 5034 | { |
5023 | 5035 | /* Writing the second half of a double-cell character over |
5024 | 5036 | * a double-cell character: need to redraw the second |
@@ -5037,10 +5049,10 @@ | ||
5037 | 5049 | * char over the left halve of an existing one. */ |
5038 | 5050 | if (has_mbyte && col + char_cells == endcol |
5039 | 5051 | && ((char_cells == 1 |
5040 | - && (*mb_off2cells)(off_to) > 1) | |
5052 | + && (*mb_off2cells)(off_to, max_off_to) > 1) | |
5041 | 5053 | || (char_cells == 2 |
5042 | - && (*mb_off2cells)(off_to) == 1 | |
5043 | - && (*mb_off2cells)(off_to + 1) > 1))) | |
5054 | + && (*mb_off2cells)(off_to, max_off_to) == 1 | |
5055 | + && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
5044 | 5056 | clear_next = TRUE; |
5045 | 5057 | #endif |
5046 | 5058 |
@@ -5180,10 +5192,11 @@ | ||
5180 | 5192 | /* find previous character by counting from first |
5181 | 5193 | * column and get its width. */ |
5182 | 5194 | unsigned off = LineOffset[row]; |
5195 | + unsigned max_off = LineOffset[row] + screen_Columns; | |
5183 | 5196 | |
5184 | 5197 | while (off < off_to) |
5185 | 5198 | { |
5186 | - prev_cells = (*mb_off2cells)(off); | |
5199 | + prev_cells = (*mb_off2cells)(off, max_off); | |
5187 | 5200 | off += prev_cells; |
5188 | 5201 | } |
5189 | 5202 | } |
@@ -5369,7 +5382,7 @@ | ||
5369 | 5382 | static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
5370 | 5383 | |
5371 | 5384 | /* |
5372 | - * Get the lenght of an item as it will be shown in the status line. | |
5385 | + * Get the length of an item as it will be shown in the status line. | |
5373 | 5386 | */ |
5374 | 5387 | static int |
5375 | 5388 | status_match_len(xp, s) |
@@ -5435,7 +5448,7 @@ | ||
5435 | 5448 | int row; |
5436 | 5449 | char_u *buf; |
5437 | 5450 | int len; |
5438 | - int clen; /* lenght in screen cells */ | |
5451 | + int clen; /* length in screen cells */ | |
5439 | 5452 | int fillchar; |
5440 | 5453 | int attr; |
5441 | 5454 | int i; |
@@ -6187,6 +6200,7 @@ | ||
6187 | 6200 | char_u *ptr = text; |
6188 | 6201 | int c; |
6189 | 6202 | #ifdef FEAT_MBYTE |
6203 | + unsigned max_off; | |
6190 | 6204 | int mbyte_blen = 1; |
6191 | 6205 | int mbyte_cells = 1; |
6192 | 6206 | int u8c = 0; |
@@ -6203,6 +6217,9 @@ | ||
6203 | 6217 | return; |
6204 | 6218 | |
6205 | 6219 | off = LineOffset[row] + col; |
6220 | +#ifdef FEAT_MBYTE | |
6221 | + max_off = LineOffset[row] + screen_Columns; | |
6222 | +#endif | |
6206 | 6223 | while (col < screen_Columns |
6207 | 6224 | && (len < 0 || (int)(ptr - text) < len) |
6208 | 6225 | && *ptr != NUL) |
@@ -6326,19 +6343,19 @@ | ||
6326 | 6343 | else if (has_mbyte |
6327 | 6344 | && (len < 0 ? ptr[mbyte_blen] == NUL |
6328 | 6345 | : ptr + mbyte_blen >= text + len) |
6329 | - && ((mbyte_cells == 1 && (*mb_off2cells)(off) > 1) | |
6346 | + && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) | |
6330 | 6347 | || (mbyte_cells == 2 |
6331 | - && (*mb_off2cells)(off) == 1 | |
6332 | - && (*mb_off2cells)(off + 1) > 1))) | |
6348 | + && (*mb_off2cells)(off, max_off) == 1 | |
6349 | + && (*mb_off2cells)(off + 1, max_off) > 1))) | |
6333 | 6350 | clear_next_cell = TRUE; |
6334 | 6351 | |
6335 | 6352 | /* Make sure we never leave a second byte of a double-byte behind, |
6336 | 6353 | * it confuses mb_off2cells(). */ |
6337 | 6354 | if (enc_dbcs |
6338 | - && ((mbyte_cells == 1 && (*mb_off2cells)(off) > 1) | |
6355 | + && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) | |
6339 | 6356 | || (mbyte_cells == 2 |
6340 | - && (*mb_off2cells)(off) == 1 | |
6341 | - && (*mb_off2cells)(off + 1) > 1))) | |
6357 | + && (*mb_off2cells)(off, max_off) == 1 | |
6358 | + && (*mb_off2cells)(off + 1, max_off) > 1))) | |
6342 | 6359 | ScreenLines[off + mbyte_blen] = 0; |
6343 | 6360 | #endif |
6344 | 6361 | ScreenLines[off] = c; |
@@ -6924,6 +6941,9 @@ | ||
6924 | 6941 | { |
6925 | 6942 | int r, c; |
6926 | 6943 | int off; |
6944 | +#ifdef FEAT_MBYTE | |
6945 | + int max_off; | |
6946 | +#endif | |
6927 | 6947 | |
6928 | 6948 | /* Can't use ScreenLines unless initialized */ |
6929 | 6949 | if (ScreenLines == NULL) |
@@ -6934,10 +6954,13 @@ | ||
6934 | 6954 | for (r = row; r < row + height; ++r) |
6935 | 6955 | { |
6936 | 6956 | off = LineOffset[r]; |
6957 | +#ifdef FEAT_MBYTE | |
6958 | + max_off = off + screen_Columns; | |
6959 | +#endif | |
6937 | 6960 | for (c = col; c < col + width; ++c) |
6938 | 6961 | { |
6939 | 6962 | #ifdef FEAT_MBYTE |
6940 | - if (enc_dbcs != 0 && dbcs_off2cells(off + c) > 1) | |
6963 | + if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) | |
6941 | 6964 | { |
6942 | 6965 | screen_char_2(off + c, r, c); |
6943 | 6966 | ++c; |
@@ -6947,7 +6970,7 @@ | ||
6947 | 6970 | { |
6948 | 6971 | screen_char(off + c, r, c); |
6949 | 6972 | #ifdef FEAT_MBYTE |
6950 | - if (utf_off2cells(off + c) > 1) | |
6973 | + if (utf_off2cells(off + c, max_off) > 1) | |
6951 | 6974 | ++c; |
6952 | 6975 | #endif |
6953 | 6976 | } |
@@ -667,6 +667,8 @@ | ||
667 | 667 | static int included_patches[] = |
668 | 668 | { /* Add new patch number below this line */ |
669 | 669 | /**/ |
670 | + 93, | |
671 | +/**/ | |
670 | 672 | 92, |
671 | 673 | /**/ |
672 | 674 | 91, |