diff src/ops.c @ 15597:536dd2bc5ac9 v8.1.0806

patch 8.1.0806: too many #ifdefs commit https://github.com/vim/vim/commit/fc3abf47fbe1e426f2b676c316c81ee9ff607075 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 15:54:21 2019 +0100 patch 8.1.0806: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate FEAT_MBYTE, part 2.
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 16:00:08 +0100
parents d89c5b339c2a
children 6f1c7e9a6393
line wrap: on
line diff
--- a/src/ops.c
+++ b/src/ops.c
@@ -97,9 +97,7 @@ static void	put_reedit_in_typebuf(int si
 static int	put_in_typebuf(char_u *s, int esc, int colon,
 								 int silent);
 static void	stuffescaped(char_u *arg, int literally);
-#ifdef FEAT_MBYTE
 static void	mb_adjust_opend(oparg_T *oap);
-#endif
 static void	free_yank_all(void);
 static int	yank_copy_line(struct block_def *bd, long y_idx);
 #ifdef FEAT_CLIPBOARD
@@ -421,7 +419,6 @@ shift_block(oparg_T *oap, int amount)
 	ws_vcol = bd.start_vcol - bd.pre_whitesp;
 	if (bd.startspaces)
 	{
-#ifdef FEAT_MBYTE
 	    if (has_mbyte)
 	    {
 		if ((*mb_ptr2len)(bd.textstart) == 1)
@@ -433,7 +430,6 @@ shift_block(oparg_T *oap, int amount)
 		}
 	    }
 	    else
-#endif
 		++bd.textstart;
 	}
 	for ( ; VIM_ISWHITE(*bd.textstart); )
@@ -632,7 +628,6 @@ block_insert(
 	    }
 	}
 
-#ifdef FEAT_MBYTE
 	if (has_mbyte && spaces > 0)
 	{
 	    int off;
@@ -650,7 +645,6 @@ block_insert(
 	    spaces -= off;
 	    count -= off;
 	}
-#endif
 
 	newp = alloc_check((unsigned)(STRLEN(oldp)) + s_len + count + 1);
 	if (newp == NULL)
@@ -1491,11 +1485,9 @@ stuffescaped(char_u *arg, int literally)
 	/* stuff a single special character */
 	if (*arg != NUL)
 	{
-#ifdef FEAT_MBYTE
 	    if (has_mbyte)
 		c = mb_cptr2char_adv(&arg);
 	    else
-#endif
 		c = *arg++;
 	    if (literally && ((c < ' ' && c != TAB) || c == DEL))
 		stuffcharReadbuff(Ctrl_V);
@@ -1774,10 +1766,8 @@ op_delete(oparg_T *oap)
     adjust_clip_reg(&oap->regname);
 #endif
 
-#ifdef FEAT_MBYTE
     if (has_mbyte)
 	mb_adjust_opend(oap);
-#endif
 
     /*
      * Imitate the strange Vi behaviour: If the delete spans more than one
@@ -2109,7 +2099,6 @@ setmarks:
     return OK;
 }
 
-#ifdef FEAT_MBYTE
 /*
  * Adjust end of operating area for ending on a multi-byte character.
  * Used for deletion.
@@ -2125,10 +2114,7 @@ mb_adjust_opend(oparg_T *oap)
 	oap->end.col += mb_tail_off(p, p + oap->end.col);
     }
 }
-#endif
-
-
-#ifdef FEAT_MBYTE
+
 /*
  * Replace the character under the cursor with "c".
  * This takes care of multi-byte characters.
@@ -2144,7 +2130,6 @@ replace_character(int c)
     /* Backup to the replaced character. */
     dec_cursor();
 }
-#endif
 
 /*
  * Replace a whole area with one character.
@@ -2153,9 +2138,7 @@ replace_character(int c)
 op_replace(oparg_T *oap, int c)
 {
     int			n, numc;
-#ifdef FEAT_MBYTE
     int			num_chars;
-#endif
     char_u		*newp, *oldp;
     size_t		oldlen;
     struct block_def	bd;
@@ -2176,10 +2159,8 @@ op_replace(oparg_T *oap, int c)
 	c = NL;
     }
 
-#ifdef FEAT_MBYTE
     if (has_mbyte)
 	mb_adjust_opend(oap);
-#endif
 
     if (u_save((linenr_T)(oap->start.lnum - 1),
 				       (linenr_T)(oap->end.lnum + 1)) == FAIL)
@@ -2230,7 +2211,6 @@ op_replace(oparg_T *oap, int c)
 	    if (bd.is_short && (!virtual_op || bd.is_MAX))
 		numc -= (oap->end_vcol - bd.end_vcol) + 1;
 
-#ifdef FEAT_MBYTE
 	    /* A double-wide character can be replaced only up to half the
 	     * times. */
 	    if ((*mb_char2cells)(c) > 1)
@@ -2246,7 +2226,6 @@ op_replace(oparg_T *oap, int c)
 	    /* Compute bytes needed, move character count to num_chars. */
 	    num_chars = numc;
 	    numc *= (*mb_char2len)(c);
-#endif
 	    /* oldlen includes textlen, so don't double count */
 	    n += numc - bd.textlen;
 
@@ -2266,7 +2245,6 @@ op_replace(oparg_T *oap, int c)
 	     * literally. */
 	    if (had_ctrl_v_cr || (c != '\r' && c != '\n'))
 	    {
-#ifdef FEAT_MBYTE
 		if (has_mbyte)
 		{
 		    n = (int)STRLEN(newp);
@@ -2274,7 +2252,6 @@ op_replace(oparg_T *oap, int c)
 			n += (*mb_char2bytes)(c, newp + n);
 		}
 		else
-#endif
 		    vim_memset(newp + STRLEN(newp), c, (size_t)numc);
 		if (!bd.is_short)
 		{
@@ -2324,7 +2301,6 @@ op_replace(oparg_T *oap, int c)
 	    n = gchar_cursor();
 	    if (n != NUL)
 	    {
-#ifdef FEAT_MBYTE
 		if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1)
 		{
 		    /* This is slow, but it handles replacing a single-byte
@@ -2334,7 +2310,6 @@ op_replace(oparg_T *oap, int c)
 		    replace_character(c);
 		}
 		else
-#endif
 		{
 #ifdef FEAT_VIRTUALEDIT
 		    if (n == TAB)
@@ -2372,11 +2347,9 @@ op_replace(oparg_T *oap, int c)
 		curwin->w_cursor.col -= (virtcols + 1);
 		for (; virtcols >= 0; virtcols--)
 		{
-# ifdef FEAT_MBYTE
                    if ((*mb_char2len)(c) > 1)
 		       replace_character(c);
                    else
-# endif
 			PBYTE(curwin->w_cursor, c);
 		   if (inc(&curwin->w_cursor) == -1)
 		       break;
@@ -2530,7 +2503,6 @@ swapchars(int op_type, pos_T *pos, int l
 
     for (todo = length; todo > 0; --todo)
     {
-# ifdef FEAT_MBYTE
 	if (has_mbyte)
 	{
 	    int len = (*mb_ptr2len)(ml_get_pos(pos));
@@ -2539,7 +2511,6 @@ swapchars(int op_type, pos_T *pos, int l
 	    if (len > 0)
 		todo -= len - 1;
 	}
-# endif
 	did_change |= swapchar(op_type, pos);
 	if (inc(pos) == -1)    /* at end of file */
 	    break;
@@ -2566,7 +2537,6 @@ swapchar(int op_type, pos_T *pos)
     if (c >= 0x80 && op_type == OP_ROT13)
 	return FALSE;
 
-#ifdef FEAT_MBYTE
     if (op_type == OP_UPPER && c == 0xdf
 		      && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0))
     {
@@ -2583,7 +2553,6 @@ swapchar(int op_type, pos_T *pos)
 
     if (enc_dbcs != 0 && c >= 0x100)	/* No lower/uppercase letter */
 	return FALSE;
-#endif
     nc = c;
     if (MB_ISLOWER(c))
     {
@@ -2601,7 +2570,6 @@ swapchar(int op_type, pos_T *pos)
     }
     if (nc != c)
     {
-#ifdef FEAT_MBYTE
 	if (enc_utf8 && (c >= 0x80 || nc >= 0x80))
 	{
 	    pos_T   sp = curwin->w_cursor;
@@ -2613,7 +2581,6 @@ swapchar(int op_type, pos_T *pos)
 	    curwin->w_cursor = sp;
 	}
 	else
-#endif
 	    PBYTE(*pos, nc);
 	return TRUE;
     }
@@ -3216,13 +3183,10 @@ op_yank(oparg_T *oap, int deleting, int 
 			{
 			    getvcol(curwin, &oap->end, &cs, NULL, &ce);
 			    if (p[endcol] == NUL || (cs + oap->end.coladd < ce
-# ifdef FEAT_MBYTE
 					/* Don't add space for double-wide
 					 * char; endcol will be on last byte
 					 * of multi-byte char. */
-					&& (*mb_head_off)(p, p + endcol) == 0
-# endif
-					))
+					&& (*mb_head_off)(p, p + endcol) == 0))
 			    {
 				if (oap->start.lnum == oap->end.lnum
 					    && oap->start.col == oap->end.col)
@@ -3745,12 +3709,10 @@ do_put(
 #endif
 		getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col);
 
-#ifdef FEAT_MBYTE
 	    if (has_mbyte)
 		/* move to start of next multi-byte character */
 		curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor());
 	    else
-#endif
 #ifdef FEAT_VIRTUALEDIT
 	    if (c != TAB || ve_flags != VE_ALL)
 #endif
@@ -3820,10 +3782,8 @@ do_put(
 		bd.startspaces = incr - bd.endspaces;
 		--bd.textcol;
 		delcount = 1;
-#ifdef FEAT_MBYTE
 		if (has_mbyte)
 		    bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol);
-#endif
 		if (oldp[bd.textcol] != TAB)
 		{
 		    /* Only a Tab can be split into spaces.  Other
@@ -3919,7 +3879,6 @@ do_put(
 	     * char */
 	    if (dir == FORWARD && gchar_cursor() != NUL)
 	    {
-#ifdef FEAT_MBYTE
 		if (has_mbyte)
 		{
 		    int bytelen = (*mb_ptr2len)(ml_get_cursor());
@@ -3933,7 +3892,6 @@ do_put(
 		    }
 		}
 		else
-#endif
 		{
 		    ++col;
 		    if (yanklen)
@@ -4279,11 +4237,7 @@ ex_display(exarg_T *eap)
     int		name;
     int		attr;
     char_u	*arg = eap->arg;
-#ifdef FEAT_MBYTE
     int		clen;
-#else
-# define clen 1
-#endif
 
     if (arg != NULL && *arg == NUL)
 	arg = NULL;
@@ -4344,13 +4298,9 @@ ex_display(exarg_T *eap)
 		}
 		for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p)
 		{
-#ifdef FEAT_MBYTE
 		    clen = (*mb_ptr2len)(p);
-#endif
 		    msg_outtrans_len(p, clen);
-#ifdef FEAT_MBYTE
 		    p += clen - 1;
-#endif
 		}
 	    }
 	    if (n > 1 && yb->y_type == MLINE)
@@ -4438,23 +4388,19 @@ dis_msg(
     int		skip_esc)	    /* if TRUE, ignore trailing ESC */
 {
     int		n;
-#ifdef FEAT_MBYTE
     int		l;
-#endif
 
     n = (int)Columns - 6;
     while (*p != NUL
 	    && !(*p == ESC && skip_esc && *(p + 1) == NUL)
 	    && (n -= ptr2cells(p)) >= 0)
     {
-#ifdef FEAT_MBYTE
 	if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
 	{
 	    msg_outtrans_len(p, l);
 	    p += l;
 	}
 	else
-#endif
 	    msg_outtrans_len(p++, 1);
     }
     ui_breakcheck();
@@ -4631,12 +4577,10 @@ do_join(
 	{
 	    curr = skipwhite(curr);
 	    if (*curr != ')' && currsize != 0 && endcurr1 != TAB
-#ifdef FEAT_MBYTE
 		    && (!has_format_option(FO_MBYTE_JOIN)
 			|| (mb_ptr2char(curr) < 0x100 && endcurr1 < 0x100))
 		    && (!has_format_option(FO_MBYTE_JOIN2)
 			|| mb_ptr2char(curr) < 0x100 || endcurr1 < 0x100)
-#endif
 	       )
 	    {
 		/* don't add a space if the line is ending in a space */
@@ -4657,7 +4601,6 @@ do_join(
 	endcurr1 = endcurr2 = NUL;
 	if (insert_space && currsize > 0)
 	{
-#ifdef FEAT_MBYTE
 	    if (has_mbyte)
 	    {
 		cend = curr + currsize;
@@ -4670,7 +4613,6 @@ do_join(
 		}
 	    }
 	    else
-#endif
 	    {
 		endcurr1 = *(curr + currsize - 1);
 		if (currsize > 1)
@@ -5715,20 +5657,16 @@ do_addsub(
 	    while (col > 0 && vim_isbdigit(ptr[col]))
 	    {
 		--col;
-#ifdef FEAT_MBYTE
 		if (has_mbyte)
 		    col -= (*mb_head_off)(ptr, ptr + col);
-#endif
 	    }
 
 	if (dohex)
 	    while (col > 0 && vim_isxdigit(ptr[col]))
 	    {
 		--col;
-#ifdef FEAT_MBYTE
 		if (has_mbyte)
 		    col -= (*mb_head_off)(ptr, ptr + col);
-#endif
 	    }
 
 	if (       dobin
@@ -5737,10 +5675,8 @@ do_addsub(
 		    && (ptr[col] == 'X'
 			|| ptr[col] == 'x')
 		    && ptr[col - 1] == '0'
-#ifdef FEAT_MBYTE
 		    && (!has_mbyte ||
 			!(*mb_head_off)(ptr, ptr + col - 1))
-#endif
 		    && vim_isxdigit(ptr[col + 1]))))
 	{
 
@@ -5751,10 +5687,8 @@ do_addsub(
 	    while (col > 0 && vim_isdigit(ptr[col]))
 	    {
 		col--;
-#ifdef FEAT_MBYTE
 		if (has_mbyte)
 		    col -= (*mb_head_off)(ptr, ptr + col);
-#endif
 	    }
 	}
 
@@ -5763,28 +5697,22 @@ do_addsub(
 		&& (ptr[col] == 'X'
 		    || ptr[col] == 'x')
 		&& ptr[col - 1] == '0'
-#ifdef FEAT_MBYTE
 		&& (!has_mbyte ||
 		    !(*mb_head_off)(ptr, ptr + col - 1))
-#endif
 		&& vim_isxdigit(ptr[col + 1])) ||
 	    (       dobin
 		&& col > 0
 		&& (ptr[col] == 'B'
 		    || ptr[col] == 'b')
 		&& ptr[col - 1] == '0'
-#ifdef FEAT_MBYTE
 		&& (!has_mbyte ||
 		    !(*mb_head_off)(ptr, ptr + col - 1))
-#endif
 		&& vim_isbdigit(ptr[col + 1])))
 	{
 	    /* Found hexadecimal or binary number, move to its start. */
 	    --col;
-#ifdef FEAT_MBYTE
 	    if (has_mbyte)
 		col -= (*mb_head_off)(ptr, ptr + col);
-#endif
 	}
 	else
 	{
@@ -5803,10 +5731,8 @@ do_addsub(
 		    && !(doalp && ASCII_ISALPHA(ptr[col])))
 	    {
 		--col;
-#ifdef FEAT_MBYTE
 		if (has_mbyte)
 		    col -= (*mb_head_off)(ptr, ptr + col);
-#endif
 	    }
 	}
     }
@@ -5827,11 +5753,7 @@ do_addsub(
 	    goto theend;
 
 	if (col > pos->col && ptr[col - 1] == '-'
-#ifdef FEAT_MBYTE
-		&& (!has_mbyte ||
-		    !(*mb_head_off)(ptr, ptr + col - 1))
-#endif
-	   )
+		&& (!has_mbyte || !(*mb_head_off)(ptr, ptr + col - 1)))
 	{
 	    negative = TRUE;
 	    was_positive = FALSE;
@@ -5895,10 +5817,8 @@ do_addsub(
     else
     {
 	if (col > 0 && ptr[col - 1] == '-'
-#ifdef FEAT_MBYTE
 		&& (!has_mbyte ||
 		    !(*mb_head_off)(ptr, ptr + col - 1))
-#endif
 		&& !visual)
 	{
 	    /* negative number */
@@ -6539,7 +6459,6 @@ x11_export_final_selection(void)
     if (dpy != NULL && str != NULL && motion_type >= 0
 					       && len < 1024*1024 && len > 0)
     {
-#ifdef FEAT_MBYTE
 	int ok = TRUE;
 
 	/* The CUT_BUFFER0 is supposed to always contain latin1.  Convert from
@@ -6579,7 +6498,6 @@ x11_export_final_selection(void)
 	/* Do not store the string if conversion failed.  Better to use any
 	 * other selection than garbled text. */
 	if (ok)
-#endif
 	{
 	    XStoreBuffer(dpy, (char *)str, (int)len, 0);
 	    XFlush(dpy);
@@ -7349,11 +7267,7 @@ line_count_info(
 	else if (!vim_isspace(line[i]))
 	    is_word = 1;
 	++chars;
-#ifdef FEAT_MBYTE
 	i += (*mb_ptr2len)(line + i);
-#else
-	++i;
-#endif
     }
 
     if (is_word)
@@ -7384,9 +7298,7 @@ cursor_pos_info(dict_T *dict)
     char_u	buf2[40];
     linenr_T	lnum;
     varnumber_T	byte_count = 0;
-#ifdef FEAT_MBYTE
     varnumber_T	bom_count  = 0;
-#endif
     varnumber_T	byte_count_cursor = 0;
     varnumber_T	char_count = 0;
     varnumber_T	char_count_cursor = 0;
@@ -7609,12 +7521,10 @@ cursor_pos_info(dict_T *dict)
 	    }
 	}
 
-#ifdef FEAT_MBYTE
 	bom_count = bomb_size();
 	if (bom_count > 0)
 	    vim_snprintf((char *)IObuff + STRLEN(IObuff), IOSIZE,
-				   _("(+%lld for BOM)"), (long_long_T)bom_count);
-#endif
+				 _("(+%lld for BOM)"), (long_long_T)bom_count);
 	if (dict == NULL)
 	{
 	    /* Don't shorten this message, the user asked for it. */
@@ -7629,11 +7539,7 @@ cursor_pos_info(dict_T *dict)
     {
 	dict_add_number(dict, "words", word_count);
 	dict_add_number(dict, "chars", char_count);
-	dict_add_number(dict, "bytes", byte_count
-# ifdef FEAT_MBYTE
-		+ bom_count
-# endif
-		);
+	dict_add_number(dict, "bytes", byte_count + bom_count);
 	dict_add_number(dict, VIsual_active ? "visual_bytes" : "cursor_bytes",
 		byte_count_cursor);
 	dict_add_number(dict, VIsual_active ? "visual_chars" : "cursor_chars",