patch 8.1.0805: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_MBYTE, part 1.
diff --git a/src/ex_getln.c b/src/ex_getln.c
index f7dfc32..7136968 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -89,9 +89,7 @@
static int cmdline_charsize(int idx);
static void set_cmdspos(void);
static void set_cmdspos_cursor(void);
-#ifdef FEAT_MBYTE
static void correct_cmdspos(int idx, int cells);
-#endif
static void alloc_cmdbuff(int len);
static int realloc_cmdbuff(int len);
static void draw_cmdline(int start, int len);
@@ -769,7 +767,6 @@
stuffcharReadbuff(*c);
*c = '\\';
}
-#ifdef FEAT_MBYTE
// add any composing characters
if (mb_char2len(*c) != mb_ptr2len(ml_get_cursor()))
{
@@ -783,7 +780,6 @@
}
*c = save_c;
}
-#endif
return FAIL;
}
}
@@ -1253,10 +1249,8 @@
i = (int)(xpc.xp_pattern - ccline.cmdbuff);
while (--j > i)
{
-#ifdef FEAT_MBYTE
if (has_mbyte)
j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j);
-#endif
if (vim_ispathsep(ccline.cmdbuff[j]))
{
found = TRUE;
@@ -1281,10 +1275,8 @@
i = (int)(xpc.xp_pattern - ccline.cmdbuff);
while (--j > i)
{
-#ifdef FEAT_MBYTE
if (has_mbyte)
j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j);
-#endif
if (vim_ispathsep(ccline.cmdbuff[j])
#ifdef BACKSLASH_IN_FILENAME
&& vim_strchr((char_u *)" *?[{`$%#",
@@ -1616,18 +1608,15 @@
*/
if (c == K_DEL && ccline.cmdpos != ccline.cmdlen)
++ccline.cmdpos;
-#ifdef FEAT_MBYTE
if (has_mbyte && c == K_DEL)
ccline.cmdpos += mb_off_next(ccline.cmdbuff,
ccline.cmdbuff + ccline.cmdpos);
-#endif
if (ccline.cmdpos > 0)
{
char_u *p;
j = ccline.cmdpos;
p = ccline.cmdbuff + j;
-#ifdef FEAT_MBYTE
if (has_mbyte)
{
p = mb_prevptr(ccline.cmdbuff, p);
@@ -1642,9 +1631,7 @@
p += (*mb_ptr2len)(p);
}
}
- else
-#endif
- if (c == Ctrl_W)
+ else if (c == Ctrl_W)
{
while (p > ccline.cmdbuff && vim_isspace(p[-1]))
--p;
@@ -1893,21 +1880,17 @@
if (KeyTyped && ccline.cmdspos + i >= Columns * Rows)
break;
ccline.cmdspos += i;
-#ifdef FEAT_MBYTE
if (has_mbyte)
ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff
+ ccline.cmdpos);
else
-#endif
++ccline.cmdpos;
}
while ((c == K_S_RIGHT || c == K_C_RIGHT
|| (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)))
&& ccline.cmdbuff[ccline.cmdpos] != ' ');
-#ifdef FEAT_MBYTE
if (has_mbyte)
set_cmdspos_cursor();
-#endif
goto cmdline_not_changed;
case K_LEFT:
@@ -1918,21 +1901,17 @@
do
{
--ccline.cmdpos;
-#ifdef FEAT_MBYTE
if (has_mbyte) /* move to first byte of char */
ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff,
ccline.cmdbuff + ccline.cmdpos);
-#endif
ccline.cmdspos -= cmdline_charsize(ccline.cmdpos);
}
while (ccline.cmdpos > 0
&& (c == K_S_LEFT || c == K_C_LEFT
|| (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)))
&& ccline.cmdbuff[ccline.cmdpos - 1] != ' ');
-#ifdef FEAT_MBYTE
if (has_mbyte)
set_cmdspos_cursor();
-#endif
goto cmdline_not_changed;
case K_IGNORE:
@@ -2030,7 +2009,6 @@
if (mouse_row <= cmdline_row + ccline.cmdspos / Columns
&& mouse_col < ccline.cmdspos % Columns + i)
break;
-# ifdef FEAT_MBYTE
if (has_mbyte)
{
/* Count ">" for double-wide char that doesn't fit. */
@@ -2038,7 +2016,6 @@
ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff
+ ccline.cmdpos) - 1;
}
-# endif
ccline.cmdspos += i;
}
goto cmdline_not_changed;
@@ -2301,7 +2278,6 @@
c = get_literal(); /* get next (two) character(s) */
do_abbr = FALSE; /* don't do abbreviation now */
extra_char = NUL;
-#ifdef FEAT_MBYTE
/* may need to remove ^ when composing char was typed */
if (enc_utf8 && utf_iscomposing(c) && !cmd_silent)
{
@@ -2309,7 +2285,6 @@
msg_putchar(' ');
cursorcmd();
}
-#endif
break;
#ifdef FEAT_DIGRAPHS
@@ -2374,13 +2349,12 @@
* We come here if we have a normal character.
*/
- if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr(
-#ifdef FEAT_MBYTE
- /* Add ABBR_OFF for characters above 0x100, this is
- * what check_abbr() expects. */
- (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) :
-#endif
- c) || c == Ctrl_RSB))
+ if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c))
+ && (ccheck_abbr(
+ // Add ABBR_OFF for characters above 0x100, this is
+ // what check_abbr() expects.
+ (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : c)
+ || c == Ctrl_RSB))
goto cmdline_changed;
/*
@@ -2390,7 +2364,6 @@
put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE);
else
{
-#ifdef FEAT_MBYTE
if (has_mbyte)
{
j = (*mb_char2bytes)(c, IObuff);
@@ -2398,7 +2371,6 @@
put_on_cmdline(IObuff, j, TRUE);
}
else
-#endif
{
IObuff[0] = c;
put_on_cmdline(IObuff, 1, TRUE);
@@ -2687,11 +2659,9 @@
for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i)
{
c = cmdline_charsize(i);
-#ifdef FEAT_MBYTE
/* Count ">" for double-wide multi-byte char that doesn't fit. */
if (has_mbyte)
correct_cmdspos(i, c);
-#endif
/* If the cmdline doesn't fit, show cursor on last visible char.
* Don't move the cursor itself, so we can still append. */
if ((ccline.cmdspos += c) >= m)
@@ -2699,14 +2669,11 @@
ccline.cmdspos -= c;
break;
}
-#ifdef FEAT_MBYTE
if (has_mbyte)
i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1;
-#endif
}
}
-#ifdef FEAT_MBYTE
/*
* Check if the character at "idx", which is "cells" wide, is a multi-byte
* character that doesn't fit, so that a ">" must be displayed.
@@ -2719,7 +2686,6 @@
&& ccline.cmdspos % Columns + cells > Columns)
ccline.cmdspos++;
}
-#endif
/*
* Get an Ex command line for the ":" command.
@@ -2849,7 +2815,6 @@
{
if (line_ga.ga_len > 0)
{
-#ifdef FEAT_MBYTE
if (has_mbyte)
{
p = (char_u *)line_ga.ga_data;
@@ -2858,7 +2823,6 @@
line_ga.ga_len -= len;
}
else
-#endif
--line_ga.ga_len;
goto redraw;
}
@@ -2962,12 +2926,10 @@
if (IS_SPECIAL(c1))
c1 = '?';
-#ifdef FEAT_MBYTE
if (has_mbyte)
len = (*mb_char2bytes)(c1,
(char_u *)line_ga.ga_data + line_ga.ga_len);
else
-#endif
{
len = 1;
((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1;
@@ -3070,7 +3032,6 @@
if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen)
return MAXCOL;
-# ifdef FEAT_MBYTE
if (has_mbyte)
{
colnr_T col;
@@ -3082,7 +3043,6 @@
return col;
}
else
-# endif
return ccline.cmdpos;
}
#endif
@@ -3111,7 +3071,6 @@
old_col = msg_col;
cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent;
-# ifdef FEAT_MBYTE
if (has_mbyte)
{
for (col = 0; col < preedit_start_col
@@ -3122,7 +3081,6 @@
}
}
else
-# endif
{
cmdspos += preedit_start_col;
cmdpos += preedit_start_col;
@@ -3142,11 +3100,9 @@
if (char_attr < 0)
break; /* end of preedit string */
-# ifdef FEAT_MBYTE
if (has_mbyte)
char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos);
else
-# endif
char_len = 1;
msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr);
@@ -3245,10 +3201,8 @@
for (i = 0; i < len; ++i)
{
msg_putchar('*');
-# ifdef FEAT_MBYTE
if (has_mbyte)
i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1;
-# endif
}
else
#endif
@@ -3382,11 +3336,9 @@
msg_no_more = TRUE;
if (ccline.cmdlen == ccline.cmdpos)
msg_putchar(' ');
-#ifdef FEAT_MBYTE
else if (has_mbyte)
draw_cmdline(ccline.cmdpos,
(*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos));
-#endif
else
draw_cmdline(ccline.cmdpos, 1);
msg_no_more = FALSE;
@@ -3429,7 +3381,6 @@
}
else
{
-#ifdef FEAT_MBYTE
if (has_mbyte)
{
/* Count nr of characters in the new string. */
@@ -3450,15 +3401,12 @@
else
ccline.cmdlen = ccline.cmdpos + len;
}
- else
-#endif
- if (ccline.cmdpos + len > ccline.cmdlen)
+ else if (ccline.cmdpos + len > ccline.cmdlen)
ccline.cmdlen = ccline.cmdpos + len;
}
mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len);
ccline.cmdbuff[ccline.cmdlen] = NUL;
-#ifdef FEAT_MBYTE
if (enc_utf8)
{
/* When the inserted text starts with a composing character,
@@ -3474,7 +3422,7 @@
len += i;
c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos);
}
-# ifdef FEAT_ARABIC
+#ifdef FEAT_ARABIC
if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c))
{
/* Check the previous character for Arabic combining pair. */
@@ -3489,7 +3437,7 @@
else
i = 0;
}
-# endif
+#endif
if (i != 0)
{
/* Also backup the cursor position. */
@@ -3503,7 +3451,6 @@
}
}
}
-#endif
if (redraw && !cmd_silent)
{
@@ -3535,17 +3482,15 @@
for (i = 0; i < len; ++i)
{
c = cmdline_charsize(ccline.cmdpos);
-#ifdef FEAT_MBYTE
/* count ">" for a double-wide char that doesn't fit. */
if (has_mbyte)
correct_cmdspos(ccline.cmdpos, c);
-#endif
/* Stop cursor at the end of the screen, but do increment the
* insert position, so that entering a very long command
* works, even though you can't see it. */
if (ccline.cmdspos + c < m)
ccline.cmdspos += c;
-#ifdef FEAT_MBYTE
+
if (has_mbyte)
{
c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1;
@@ -3554,7 +3499,6 @@
ccline.cmdpos += c;
i += c;
}
-#endif
++ccline.cmdpos;
}
}
@@ -3654,7 +3598,6 @@
/* Locate start of last word in the cmd buffer. */
for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; )
{
-#ifdef FEAT_MBYTE
if (has_mbyte)
{
len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1;
@@ -3663,7 +3606,6 @@
w -= len;
}
else
-#endif
{
if (!vim_iswordc(w[-1]))
break;
@@ -3703,11 +3645,9 @@
cv = *s;
if (cv == Ctrl_V && s[1])
++s;
-#ifdef FEAT_MBYTE
if (has_mbyte)
c = mb_cptr2char_adv(&s);
else
-#endif
c = *s++;
if (cv == Ctrl_V || c == ESC || c == Ctrl_C
|| c == CAR || c == NL || c == Ctrl_L
@@ -4237,22 +4177,18 @@
for (len = 0; xp->xp_files[0][len]; len += mb_len)
{
-#ifdef FEAT_MBYTE
if (has_mbyte)
{
mb_len = (*mb_ptr2len)(&xp->xp_files[0][len]);
c0 =(* mb_ptr2char)(&xp->xp_files[0][len]);
}
else
-#endif
c0 = xp->xp_files[0][len];
for (i = 1; i < xp->xp_numfiles; ++i)
{
-#ifdef FEAT_MBYTE
if (has_mbyte)
ci =(* mb_ptr2char)(&xp->xp_files[i][len]);
else
-#endif
ci = xp->xp_files[i][len];
if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
|| xp->xp_context == EXPAND_FILES