mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 05:28:33 +00:00
vim-patch:8.1.0806: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_MBYTE, part 2.
fc3abf47fb
This commit is contained in:
@@ -242,9 +242,7 @@ static int coladvance2(
|
||||
}
|
||||
|
||||
// Prevent from moving onto a trail byte.
|
||||
if (has_mbyte) {
|
||||
mark_mb_adjustpos(curbuf, pos);
|
||||
}
|
||||
mark_mb_adjustpos(curbuf, pos);
|
||||
|
||||
if (wcol < 0 || col < wcol) {
|
||||
return FAIL;
|
||||
@@ -378,9 +376,7 @@ void check_cursor_col_win(win_T *win)
|
||||
} else {
|
||||
win->w_cursor.col = len - 1;
|
||||
// Move the cursor to the head byte.
|
||||
if (has_mbyte) {
|
||||
mark_mb_adjustpos(win->w_buffer, &win->w_cursor);
|
||||
}
|
||||
mark_mb_adjustpos(win->w_buffer, &win->w_cursor);
|
||||
}
|
||||
} else if (win->w_cursor.col < 0) {
|
||||
win->w_cursor.col = 0;
|
||||
|
@@ -4152,9 +4152,7 @@ void goto_byte(long cnt)
|
||||
check_cursor();
|
||||
|
||||
// Make sure the cursor is on the first byte of a multi-byte char.
|
||||
if (has_mbyte) {
|
||||
mb_adjust_cursor();
|
||||
}
|
||||
mb_adjust_cursor();
|
||||
}
|
||||
|
||||
/// Increment the line pointer "lp" crossing line boundaries as necessary.
|
||||
|
@@ -400,12 +400,12 @@ void trunc_string(char_u *s, char_u *buf, int room_in, int buflen)
|
||||
}
|
||||
len += n;
|
||||
buf[e] = s[e];
|
||||
if (has_mbyte)
|
||||
for (n = (*mb_ptr2len)(s + e); --n > 0; ) {
|
||||
if (++e == buflen)
|
||||
break;
|
||||
buf[e] = s[e];
|
||||
for (n = utfc_ptr2len(s + e); --n > 0; ) {
|
||||
if (++e == buflen) {
|
||||
break;
|
||||
}
|
||||
buf[e] = s[e];
|
||||
}
|
||||
}
|
||||
|
||||
// Last part: End of the string.
|
||||
@@ -873,19 +873,17 @@ char_u *msg_may_trunc(int force, char_u *s)
|
||||
room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1;
|
||||
if ((force || (shortmess(SHM_TRUNC) && !exmode_active))
|
||||
&& (n = (int)STRLEN(s) - room) > 0) {
|
||||
if (has_mbyte) {
|
||||
int size = vim_strsize(s);
|
||||
int size = vim_strsize(s);
|
||||
|
||||
/* There may be room anyway when there are multibyte chars. */
|
||||
if (size <= room)
|
||||
return s;
|
||||
|
||||
for (n = 0; size >= room; ) {
|
||||
size -= utf_ptr2cells(s + n);
|
||||
n += utfc_ptr2len(s + n);
|
||||
}
|
||||
--n;
|
||||
// There may be room anyway when there are multibyte chars.
|
||||
if (size <= room) {
|
||||
return s;
|
||||
}
|
||||
for (n = 0; size >= room; ) {
|
||||
size -= utf_ptr2cells(s + n);
|
||||
n += utfc_ptr2len(s + n);
|
||||
}
|
||||
n--;
|
||||
s += n;
|
||||
*s = '<';
|
||||
}
|
||||
@@ -1430,7 +1428,7 @@ int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr)
|
||||
|
||||
// If the string starts with a composing character first draw a space on
|
||||
// which the composing char can be drawn.
|
||||
if (enc_utf8 && utf_iscomposing(utf_ptr2char(msgstr))) {
|
||||
if (utf_iscomposing(utf_ptr2char(msgstr))) {
|
||||
msg_puts_attr(" ", attr);
|
||||
}
|
||||
|
||||
@@ -2489,8 +2487,9 @@ static void t_puts(int *t_col, const char_u *t_s, const char_u *s, int attr)
|
||||
*t_col = 0;
|
||||
/* If the string starts with a composing character don't increment the
|
||||
* column position for it. */
|
||||
if (enc_utf8 && utf_iscomposing(utf_ptr2char(t_s)))
|
||||
--msg_col;
|
||||
if (utf_iscomposing(utf_ptr2char(t_s))) {
|
||||
msg_col--;
|
||||
}
|
||||
if (msg_col >= Columns) {
|
||||
msg_col = 0;
|
||||
++msg_row;
|
||||
@@ -3391,12 +3390,12 @@ do_dialog (
|
||||
* Copy one character from "*from" to "*to", taking care of multi-byte
|
||||
* characters. Return the length of the character in bytes.
|
||||
*/
|
||||
static int
|
||||
copy_char (
|
||||
char_u *from,
|
||||
static int copy_char(
|
||||
const char_u *from,
|
||||
char_u *to,
|
||||
int lowercase /* make character lower case */
|
||||
bool lowercase // make character lower case
|
||||
)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
if (lowercase) {
|
||||
int c = mb_tolower(utf_ptr2char(from));
|
||||
@@ -3408,7 +3407,7 @@ copy_char (
|
||||
}
|
||||
|
||||
#define HAS_HOTKEY_LEN 30
|
||||
#define HOTK_LEN (has_mbyte ? MB_MAXBYTES : 1)
|
||||
#define HOTK_LEN MB_MAXBYTES
|
||||
|
||||
/// Allocates memory for dialog string & for storing hotkeys
|
||||
///
|
||||
@@ -3512,7 +3511,7 @@ static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
|
||||
|
||||
// Define first default hotkey. Keep the hotkey string NUL
|
||||
// terminated to avoid reading past the end.
|
||||
hotkeys_ptr[copy_char(buttons, hotkeys_ptr, TRUE)] = NUL;
|
||||
hotkeys_ptr[copy_char(buttons, hotkeys_ptr, true)] = NUL;
|
||||
|
||||
// Remember where the choices start, displaying starts here when
|
||||
// "hotkeys_ptr" typed at the more prompt.
|
||||
@@ -3532,8 +3531,8 @@ static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
|
||||
*msgp++ = ' '; // '\n' -> ', '
|
||||
|
||||
// Advance to next hotkey and set default hotkey
|
||||
hotkeys_ptr += (has_mbyte) ? STRLEN(hotkeys_ptr): 1;
|
||||
hotkeys_ptr[copy_char(r + 1, hotkeys_ptr, TRUE)] = NUL;
|
||||
hotkeys_ptr += STRLEN(hotkeys_ptr);
|
||||
hotkeys_ptr[copy_char(r + 1, hotkeys_ptr, true)] = NUL;
|
||||
|
||||
if (default_button_idx) {
|
||||
default_button_idx--;
|
||||
@@ -3555,15 +3554,15 @@ static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
|
||||
} else {
|
||||
// '&a' -> '[a]'
|
||||
*msgp++ = (default_button_idx == 1) ? '[' : '(';
|
||||
msgp += copy_char(r, msgp, FALSE);
|
||||
msgp += copy_char(r, msgp, false);
|
||||
*msgp++ = (default_button_idx == 1) ? ']' : ')';
|
||||
|
||||
// redefine hotkey
|
||||
hotkeys_ptr[copy_char(r, hotkeys_ptr, TRUE)] = NUL;
|
||||
hotkeys_ptr[copy_char(r, hotkeys_ptr, true)] = NUL;
|
||||
}
|
||||
} else {
|
||||
// everything else copy literally
|
||||
msgp += copy_char(r, msgp, FALSE);
|
||||
msgp += copy_char(r, msgp, false);
|
||||
}
|
||||
|
||||
// advance to the next character
|
||||
|
@@ -717,11 +717,9 @@ int curwin_col_off2(void)
|
||||
return win_col_off2(curwin);
|
||||
}
|
||||
|
||||
/*
|
||||
* compute curwin->w_wcol and curwin->w_virtcol.
|
||||
* Also updates curwin->w_wrow and curwin->w_cline_row.
|
||||
* Also updates curwin->w_leftcol.
|
||||
*/
|
||||
// Compute curwin->w_wcol and curwin->w_virtcol.
|
||||
// Also updates curwin->w_wrow and curwin->w_cline_row.
|
||||
// Also updates curwin->w_leftcol.
|
||||
void curs_columns(
|
||||
int may_scroll /* when true, may scroll horizontally */
|
||||
)
|
||||
|
@@ -1725,14 +1725,15 @@ int do_set(
|
||||
#endif
|
||||
)
|
||||
arg++; // remove backslash
|
||||
if (has_mbyte
|
||||
&& (i = (*mb_ptr2len)(arg)) > 1) {
|
||||
i = utfc_ptr2len(arg);
|
||||
if (i > 1) {
|
||||
// copy multibyte char
|
||||
memmove(s, arg, (size_t)i);
|
||||
arg += i;
|
||||
s += i;
|
||||
} else
|
||||
} else {
|
||||
*s++ = *arg++;
|
||||
}
|
||||
}
|
||||
*s = NUL;
|
||||
|
||||
@@ -2864,39 +2865,26 @@ ambw_end:
|
||||
errmsg = e_invarg;
|
||||
}
|
||||
} else if (gvarp == &p_mps) { // 'matchpairs'
|
||||
if (has_mbyte) {
|
||||
for (p = *varp; *p != NUL; p++) {
|
||||
int x2 = -1;
|
||||
int x3 = -1;
|
||||
for (p = *varp; *p != NUL; p++) {
|
||||
int x2 = -1;
|
||||
int x3 = -1;
|
||||
|
||||
if (*p != NUL) {
|
||||
p += mb_ptr2len(p);
|
||||
}
|
||||
if (*p != NUL) {
|
||||
x2 = *p++;
|
||||
}
|
||||
if (*p != NUL) {
|
||||
x3 = utf_ptr2char(p);
|
||||
p += mb_ptr2len(p);
|
||||
}
|
||||
if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) {
|
||||
errmsg = e_invarg;
|
||||
break;
|
||||
}
|
||||
if (*p == NUL) {
|
||||
break;
|
||||
}
|
||||
if (*p != NUL) {
|
||||
p += utfc_ptr2len(p);
|
||||
}
|
||||
} else {
|
||||
// Check for "x:y,x:y"
|
||||
for (p = *varp; *p != NUL; p += 4) {
|
||||
if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ',')) {
|
||||
errmsg = e_invarg;
|
||||
break;
|
||||
}
|
||||
if (p[3] == NUL) {
|
||||
break;
|
||||
}
|
||||
if (*p != NUL) {
|
||||
x2 = *p++;
|
||||
}
|
||||
if (*p != NUL) {
|
||||
x3 = utf_ptr2char(p);
|
||||
p += utfc_ptr2len(p);
|
||||
}
|
||||
if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) {
|
||||
errmsg = e_invarg;
|
||||
break;
|
||||
}
|
||||
if (*p == NUL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (gvarp == &p_com) { // 'comments'
|
||||
|
@@ -260,13 +260,13 @@ char_u *shorten_dir(char_u *str)
|
||||
*d++ = *s;
|
||||
skip = false;
|
||||
} else if (!skip) {
|
||||
*d++ = *s; /* copy next char */
|
||||
if (*s != '~' && *s != '.') /* and leading "~" and "." */
|
||||
*d++ = *s; // copy next char
|
||||
if (*s != '~' && *s != '.') { // and leading "~" and "."
|
||||
skip = true;
|
||||
if (has_mbyte) {
|
||||
int l = mb_ptr2len(s);
|
||||
while (--l > 0)
|
||||
*d++ = *++s;
|
||||
}
|
||||
int l = utfc_ptr2len(s);
|
||||
while (--l > 0) {
|
||||
*d++ = *++s;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -608,13 +608,10 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
|
||||
)) {
|
||||
e = p;
|
||||
}
|
||||
if (has_mbyte) {
|
||||
len = (size_t)(*mb_ptr2len)(path_end);
|
||||
memcpy(p, path_end, len);
|
||||
p += len;
|
||||
path_end += len;
|
||||
} else
|
||||
*p++ = *path_end++;
|
||||
len = (size_t)(utfc_ptr2len(path_end));
|
||||
memcpy(p, path_end, len);
|
||||
p += len;
|
||||
path_end += len;
|
||||
}
|
||||
e = p;
|
||||
*e = NUL;
|
||||
|
@@ -94,8 +94,8 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars,
|
||||
*/
|
||||
size_t length = 1; // count the trailing NUL
|
||||
for (const char_u *p = string; *p; p++) {
|
||||
size_t l;
|
||||
if (has_mbyte && (l = (size_t)(*mb_ptr2len)(p)) > 1) {
|
||||
const size_t l = (size_t)(utfc_ptr2len(p));
|
||||
if (l > 1) {
|
||||
length += l; // count a multibyte char
|
||||
p += l - 1;
|
||||
continue;
|
||||
@@ -108,8 +108,8 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars,
|
||||
char_u *escaped_string = xmalloc(length);
|
||||
char_u *p2 = escaped_string;
|
||||
for (const char_u *p = string; *p; p++) {
|
||||
size_t l;
|
||||
if (has_mbyte && (l = (size_t)(*mb_ptr2len)(p)) > 1) {
|
||||
const size_t l = (size_t)(utfc_ptr2len(p));
|
||||
if (l > 1) {
|
||||
memcpy(p2, p, l);
|
||||
p2 += l;
|
||||
p += l - 1; /* skip multibyte char */
|
||||
@@ -349,7 +349,7 @@ char *strcase_save(const char *const orig, bool upper)
|
||||
// thus it's OK to do another malloc()/free().
|
||||
int newl = utf_char2len(uc);
|
||||
if (newl != l) {
|
||||
// TODO(philix): use xrealloc() in strup_save()
|
||||
// TODO(philix): use xrealloc() in strcase_save()
|
||||
char *s = xmalloc(STRLEN(res) + (size_t)(1 + newl - l));
|
||||
memcpy(s, res, (size_t)(p - res));
|
||||
STRCPY(s + (p - res) + newl, p + l);
|
||||
|
Reference in New Issue
Block a user