mirror of
https://github.com/neovim/neovim.git
synced 2025-09-26 13:08: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.
|
// 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) {
|
if (wcol < 0 || col < wcol) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@@ -378,9 +376,7 @@ void check_cursor_col_win(win_T *win)
|
|||||||
} else {
|
} else {
|
||||||
win->w_cursor.col = len - 1;
|
win->w_cursor.col = len - 1;
|
||||||
// Move the cursor to the head byte.
|
// 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) {
|
} else if (win->w_cursor.col < 0) {
|
||||||
win->w_cursor.col = 0;
|
win->w_cursor.col = 0;
|
||||||
|
@@ -4152,9 +4152,7 @@ void goto_byte(long cnt)
|
|||||||
check_cursor();
|
check_cursor();
|
||||||
|
|
||||||
// Make sure the cursor is on the first byte of a multi-byte char.
|
// 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.
|
/// 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;
|
len += n;
|
||||||
buf[e] = s[e];
|
buf[e] = s[e];
|
||||||
if (has_mbyte)
|
for (n = utfc_ptr2len(s + e); --n > 0; ) {
|
||||||
for (n = (*mb_ptr2len)(s + e); --n > 0; ) {
|
if (++e == buflen) {
|
||||||
if (++e == buflen)
|
break;
|
||||||
break;
|
|
||||||
buf[e] = s[e];
|
|
||||||
}
|
}
|
||||||
|
buf[e] = s[e];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last part: End of the string.
|
// 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;
|
room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1;
|
||||||
if ((force || (shortmess(SHM_TRUNC) && !exmode_active))
|
if ((force || (shortmess(SHM_TRUNC) && !exmode_active))
|
||||||
&& (n = (int)STRLEN(s) - room) > 0) {
|
&& (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. */
|
// There may be room anyway when there are multibyte chars.
|
||||||
if (size <= room)
|
if (size <= room) {
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
for (n = 0; size >= room; ) {
|
|
||||||
size -= utf_ptr2cells(s + n);
|
|
||||||
n += utfc_ptr2len(s + n);
|
|
||||||
}
|
|
||||||
--n;
|
|
||||||
}
|
}
|
||||||
|
for (n = 0; size >= room; ) {
|
||||||
|
size -= utf_ptr2cells(s + n);
|
||||||
|
n += utfc_ptr2len(s + n);
|
||||||
|
}
|
||||||
|
n--;
|
||||||
s += n;
|
s += n;
|
||||||
*s = '<';
|
*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
|
// If the string starts with a composing character first draw a space on
|
||||||
// which the composing char can be drawn.
|
// 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);
|
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;
|
*t_col = 0;
|
||||||
/* If the string starts with a composing character don't increment the
|
/* If the string starts with a composing character don't increment the
|
||||||
* column position for it. */
|
* column position for it. */
|
||||||
if (enc_utf8 && utf_iscomposing(utf_ptr2char(t_s)))
|
if (utf_iscomposing(utf_ptr2char(t_s))) {
|
||||||
--msg_col;
|
msg_col--;
|
||||||
|
}
|
||||||
if (msg_col >= Columns) {
|
if (msg_col >= Columns) {
|
||||||
msg_col = 0;
|
msg_col = 0;
|
||||||
++msg_row;
|
++msg_row;
|
||||||
@@ -3391,12 +3390,12 @@ do_dialog (
|
|||||||
* Copy one character from "*from" to "*to", taking care of multi-byte
|
* Copy one character from "*from" to "*to", taking care of multi-byte
|
||||||
* characters. Return the length of the character in bytes.
|
* characters. Return the length of the character in bytes.
|
||||||
*/
|
*/
|
||||||
static int
|
static int copy_char(
|
||||||
copy_char (
|
const char_u *from,
|
||||||
char_u *from,
|
|
||||||
char_u *to,
|
char_u *to,
|
||||||
int lowercase /* make character lower case */
|
bool lowercase // make character lower case
|
||||||
)
|
)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
if (lowercase) {
|
if (lowercase) {
|
||||||
int c = mb_tolower(utf_ptr2char(from));
|
int c = mb_tolower(utf_ptr2char(from));
|
||||||
@@ -3408,7 +3407,7 @@ copy_char (
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define HAS_HOTKEY_LEN 30
|
#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
|
/// 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
|
// Define first default hotkey. Keep the hotkey string NUL
|
||||||
// terminated to avoid reading past the end.
|
// 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
|
// Remember where the choices start, displaying starts here when
|
||||||
// "hotkeys_ptr" typed at the more prompt.
|
// "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' -> ', '
|
*msgp++ = ' '; // '\n' -> ', '
|
||||||
|
|
||||||
// Advance to next hotkey and set default hotkey
|
// Advance to next hotkey and set default hotkey
|
||||||
hotkeys_ptr += (has_mbyte) ? STRLEN(hotkeys_ptr): 1;
|
hotkeys_ptr += STRLEN(hotkeys_ptr);
|
||||||
hotkeys_ptr[copy_char(r + 1, hotkeys_ptr, TRUE)] = NUL;
|
hotkeys_ptr[copy_char(r + 1, hotkeys_ptr, true)] = NUL;
|
||||||
|
|
||||||
if (default_button_idx) {
|
if (default_button_idx) {
|
||||||
default_button_idx--;
|
default_button_idx--;
|
||||||
@@ -3555,15 +3554,15 @@ static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
|
|||||||
} else {
|
} else {
|
||||||
// '&a' -> '[a]'
|
// '&a' -> '[a]'
|
||||||
*msgp++ = (default_button_idx == 1) ? '[' : '(';
|
*msgp++ = (default_button_idx == 1) ? '[' : '(';
|
||||||
msgp += copy_char(r, msgp, FALSE);
|
msgp += copy_char(r, msgp, false);
|
||||||
*msgp++ = (default_button_idx == 1) ? ']' : ')';
|
*msgp++ = (default_button_idx == 1) ? ']' : ')';
|
||||||
|
|
||||||
// redefine hotkey
|
// redefine hotkey
|
||||||
hotkeys_ptr[copy_char(r, hotkeys_ptr, TRUE)] = NUL;
|
hotkeys_ptr[copy_char(r, hotkeys_ptr, true)] = NUL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// everything else copy literally
|
// everything else copy literally
|
||||||
msgp += copy_char(r, msgp, FALSE);
|
msgp += copy_char(r, msgp, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// advance to the next character
|
// advance to the next character
|
||||||
|
@@ -717,11 +717,9 @@ int curwin_col_off2(void)
|
|||||||
return win_col_off2(curwin);
|
return win_col_off2(curwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Compute curwin->w_wcol and curwin->w_virtcol.
|
||||||
* compute curwin->w_wcol and curwin->w_virtcol.
|
// Also updates curwin->w_wrow and curwin->w_cline_row.
|
||||||
* Also updates curwin->w_wrow and curwin->w_cline_row.
|
// Also updates curwin->w_leftcol.
|
||||||
* Also updates curwin->w_leftcol.
|
|
||||||
*/
|
|
||||||
void curs_columns(
|
void curs_columns(
|
||||||
int may_scroll /* when true, may scroll horizontally */
|
int may_scroll /* when true, may scroll horizontally */
|
||||||
)
|
)
|
||||||
|
@@ -1725,14 +1725,15 @@ int do_set(
|
|||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
arg++; // remove backslash
|
arg++; // remove backslash
|
||||||
if (has_mbyte
|
i = utfc_ptr2len(arg);
|
||||||
&& (i = (*mb_ptr2len)(arg)) > 1) {
|
if (i > 1) {
|
||||||
// copy multibyte char
|
// copy multibyte char
|
||||||
memmove(s, arg, (size_t)i);
|
memmove(s, arg, (size_t)i);
|
||||||
arg += i;
|
arg += i;
|
||||||
s += i;
|
s += i;
|
||||||
} else
|
} else {
|
||||||
*s++ = *arg++;
|
*s++ = *arg++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*s = NUL;
|
*s = NUL;
|
||||||
|
|
||||||
@@ -2864,39 +2865,26 @@ ambw_end:
|
|||||||
errmsg = e_invarg;
|
errmsg = e_invarg;
|
||||||
}
|
}
|
||||||
} else if (gvarp == &p_mps) { // 'matchpairs'
|
} else if (gvarp == &p_mps) { // 'matchpairs'
|
||||||
if (has_mbyte) {
|
for (p = *varp; *p != NUL; p++) {
|
||||||
for (p = *varp; *p != NUL; p++) {
|
int x2 = -1;
|
||||||
int x2 = -1;
|
int x3 = -1;
|
||||||
int x3 = -1;
|
|
||||||
|
|
||||||
if (*p != NUL) {
|
if (*p != NUL) {
|
||||||
p += mb_ptr2len(p);
|
p += utfc_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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
if (*p != NUL) {
|
||||||
// Check for "x:y,x:y"
|
x2 = *p++;
|
||||||
for (p = *varp; *p != NUL; p += 4) {
|
}
|
||||||
if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ',')) {
|
if (*p != NUL) {
|
||||||
errmsg = e_invarg;
|
x3 = utf_ptr2char(p);
|
||||||
break;
|
p += utfc_ptr2len(p);
|
||||||
}
|
}
|
||||||
if (p[3] == NUL) {
|
if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) {
|
||||||
break;
|
errmsg = e_invarg;
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
if (*p == NUL) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (gvarp == &p_com) { // 'comments'
|
} else if (gvarp == &p_com) { // 'comments'
|
||||||
|
@@ -260,13 +260,13 @@ char_u *shorten_dir(char_u *str)
|
|||||||
*d++ = *s;
|
*d++ = *s;
|
||||||
skip = false;
|
skip = false;
|
||||||
} else if (!skip) {
|
} else if (!skip) {
|
||||||
*d++ = *s; /* copy next char */
|
*d++ = *s; // copy next char
|
||||||
if (*s != '~' && *s != '.') /* and leading "~" and "." */
|
if (*s != '~' && *s != '.') { // and leading "~" and "."
|
||||||
skip = true;
|
skip = true;
|
||||||
if (has_mbyte) {
|
}
|
||||||
int l = mb_ptr2len(s);
|
int l = utfc_ptr2len(s);
|
||||||
while (--l > 0)
|
while (--l > 0) {
|
||||||
*d++ = *++s;
|
*d++ = *++s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -608,13 +608,10 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
|
|||||||
)) {
|
)) {
|
||||||
e = p;
|
e = p;
|
||||||
}
|
}
|
||||||
if (has_mbyte) {
|
len = (size_t)(utfc_ptr2len(path_end));
|
||||||
len = (size_t)(*mb_ptr2len)(path_end);
|
memcpy(p, path_end, len);
|
||||||
memcpy(p, path_end, len);
|
p += len;
|
||||||
p += len;
|
path_end += len;
|
||||||
path_end += len;
|
|
||||||
} else
|
|
||||||
*p++ = *path_end++;
|
|
||||||
}
|
}
|
||||||
e = p;
|
e = p;
|
||||||
*e = NUL;
|
*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
|
size_t length = 1; // count the trailing NUL
|
||||||
for (const char_u *p = string; *p; p++) {
|
for (const char_u *p = string; *p; p++) {
|
||||||
size_t l;
|
const size_t l = (size_t)(utfc_ptr2len(p));
|
||||||
if (has_mbyte && (l = (size_t)(*mb_ptr2len)(p)) > 1) {
|
if (l > 1) {
|
||||||
length += l; // count a multibyte char
|
length += l; // count a multibyte char
|
||||||
p += l - 1;
|
p += l - 1;
|
||||||
continue;
|
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 *escaped_string = xmalloc(length);
|
||||||
char_u *p2 = escaped_string;
|
char_u *p2 = escaped_string;
|
||||||
for (const char_u *p = string; *p; p++) {
|
for (const char_u *p = string; *p; p++) {
|
||||||
size_t l;
|
const size_t l = (size_t)(utfc_ptr2len(p));
|
||||||
if (has_mbyte && (l = (size_t)(*mb_ptr2len)(p)) > 1) {
|
if (l > 1) {
|
||||||
memcpy(p2, p, l);
|
memcpy(p2, p, l);
|
||||||
p2 += l;
|
p2 += l;
|
||||||
p += l - 1; /* skip multibyte char */
|
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().
|
// thus it's OK to do another malloc()/free().
|
||||||
int newl = utf_char2len(uc);
|
int newl = utf_char2len(uc);
|
||||||
if (newl != l) {
|
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));
|
char *s = xmalloc(STRLEN(res) + (size_t)(1 + newl - l));
|
||||||
memcpy(s, res, (size_t)(p - res));
|
memcpy(s, res, (size_t)(p - res));
|
||||||
STRCPY(s + (p - res) + newl, p + l);
|
STRCPY(s + (p - res) + newl, p + l);
|
||||||
|
Reference in New Issue
Block a user