diff src/fileio.c @ 15595:1ec942f1b648 v8.1.0805

patch 8.1.0805: too many #ifdefs commit https://github.com/vim/vim/commit/135059724f140ceac889c9f8136bd1bf5c41d49d Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 15:04:48 2019 +0100 patch 8.1.0805: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate FEAT_MBYTE, part 1.
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 15:15:06 +0100
parents d89c5b339c2a
children 2dcaa860e3fc
line wrap: on
line diff
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -27,11 +27,9 @@
 /* Is there any system that doesn't have access()? */
 #define USE_MCH_ACCESS
 
-#ifdef FEAT_MBYTE
 static char_u *next_fenc(char_u **pp);
-# ifdef FEAT_EVAL
+#ifdef FEAT_EVAL
 static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp);
-# endif
 #endif
 #ifdef FEAT_VIMINFO
 static void check_marks_read(void);
@@ -47,31 +45,29 @@ static int time_differs(long t1, long t2
 static int apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf, exarg_T *eap);
 static int au_find_group(char_u *name);
 
-# define AUGROUP_DEFAULT    -1	    /* default autocmd group */
-# define AUGROUP_ERROR	    -2	    /* erroneous autocmd group */
-# define AUGROUP_ALL	    -3	    /* all autocmd groups */
-
-#if defined(FEAT_CRYPT) || defined(FEAT_MBYTE)
-# define HAS_BW_FLAGS
-# define FIO_LATIN1	0x01	/* convert Latin1 */
-# define FIO_UTF8	0x02	/* convert UTF-8 */
-# define FIO_UCS2	0x04	/* convert UCS-2 */
-# define FIO_UCS4	0x08	/* convert UCS-4 */
-# define FIO_UTF16	0x10	/* convert UTF-16 */
-# ifdef WIN3264
-#  define FIO_CODEPAGE	0x20	/* convert MS-Windows codepage */
-#  define FIO_PUT_CP(x) (((x) & 0xffff) << 16)	/* put codepage in top word */
-#  define FIO_GET_CP(x)	(((x)>>16) & 0xffff)	/* get codepage from top word */
-# endif
-# ifdef MACOS_CONVERT
-#  define FIO_MACROMAN	0x20	/* convert MacRoman */
-# endif
-# define FIO_ENDIAN_L	0x80	/* little endian */
-# define FIO_ENCRYPTED	0x1000	/* encrypt written bytes */
-# define FIO_NOCONVERT	0x2000	/* skip encoding conversion */
-# define FIO_UCSBOM	0x4000	/* check for BOM at start of file */
-# define FIO_ALL	-1	/* allow all formats */
-#endif
+#define AUGROUP_DEFAULT    -1	    /* default autocmd group */
+#define AUGROUP_ERROR	    -2	    /* erroneous autocmd group */
+#define AUGROUP_ALL	    -3	    /* all autocmd groups */
+
+#define HAS_BW_FLAGS
+#define FIO_LATIN1	0x01	/* convert Latin1 */
+#define FIO_UTF8	0x02	/* convert UTF-8 */
+#define FIO_UCS2	0x04	/* convert UCS-2 */
+#define FIO_UCS4	0x08	/* convert UCS-4 */
+#define FIO_UTF16	0x10	/* convert UTF-16 */
+#ifdef WIN3264
+# define FIO_CODEPAGE	0x20	/* convert MS-Windows codepage */
+# define FIO_PUT_CP(x) (((x) & 0xffff) << 16)	/* put codepage in top word */
+# define FIO_GET_CP(x)	(((x)>>16) & 0xffff)	/* get codepage from top word */
+#endif
+#ifdef MACOS_CONVERT
+# define FIO_MACROMAN	0x20	/* convert MacRoman */
+#endif
+#define FIO_ENDIAN_L	0x80	/* little endian */
+#define FIO_ENCRYPTED	0x1000	/* encrypt written bytes */
+#define FIO_NOCONVERT	0x2000	/* skip encoding conversion */
+#define FIO_UCSBOM	0x4000	/* check for BOM at start of file */
+#define FIO_ALL	-1	/* allow all formats */
 
 /* When converting, a read() or write() may leave some bytes to be converted
  * for the next call.  The value is guessed... */
@@ -95,7 +91,6 @@ struct bw_info
 #ifdef FEAT_CRYPT
     buf_T	*bw_buffer;	/* buffer being written */
 #endif
-#ifdef FEAT_MBYTE
     char_u	bw_rest[CONV_RESTLEN]; /* not converted bytes */
     int		bw_restlen;	/* nr of bytes in bw_rest[] */
     int		bw_first;	/* first write call */
@@ -104,27 +99,24 @@ struct bw_info
     int		bw_conv_error;	/* set for conversion error */
     linenr_T	bw_conv_error_lnum;  /* first line with error or zero */
     linenr_T	bw_start_lnum;  /* line number at start of buffer */
-# ifdef USE_ICONV
+#ifdef USE_ICONV
     iconv_t	bw_iconv_fd;	/* descriptor for iconv() or -1 */
-# endif
 #endif
 };
 
 static int  buf_write_bytes(struct bw_info *ip);
 
-#ifdef FEAT_MBYTE
 static linenr_T readfile_linenr(linenr_T linecnt, char_u *p, char_u *endp);
 static int ucs2bytes(unsigned c, char_u **pp, int flags);
 static int need_conversion(char_u *fenc);
 static int get_fio_flags(char_u *ptr);
 static char_u *check_for_bom(char_u *p, long size, int *lenp, int flags);
 static int make_bom(char_u *buf, char_u *name);
-# ifdef WIN3264
+#ifdef WIN3264
 static int get_win_fio_flags(char_u *ptr);
-# endif
-# ifdef MACOS_CONVERT
+#endif
+#ifdef MACOS_CONVERT
 static int get_mac_fio_flags(char_u *ptr);
-# endif
 #endif
 static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name");
 
@@ -265,7 +257,6 @@ readfile(
     int		try_dos;
     int		try_unix;
     int		file_rewind = FALSE;
-#ifdef FEAT_MBYTE
     int		can_retry;
     linenr_T	conv_error = 0;		/* line nr with conversion error */
     linenr_T	illegal_byte = 0;	/* line nr with illegal byte */
@@ -281,19 +272,18 @@ readfile(
     char_u	*fenc_next = NULL;	/* next item in 'fencs' or NULL */
     int		advance_fenc = FALSE;
     long	real_size = 0;
-# ifdef USE_ICONV
+#ifdef USE_ICONV
     iconv_t	iconv_fd = (iconv_t)-1;	/* descriptor for iconv() or -1 */
-#  ifdef FEAT_EVAL
+# ifdef FEAT_EVAL
     int		did_iconv = FALSE;	/* TRUE when iconv() failed and trying
 					   'charconvert' next */
-#  endif
 # endif
+#endif
     int		converted = FALSE;	/* TRUE if conversion done */
     int		notconverted = FALSE;	/* TRUE if conversion wanted but it
 					   wasn't possible */
     char_u	conv_rest[CONV_RESTLEN];
     int		conv_restlen = 0;	/* nr of bytes in conv_rest[] */
-#endif
     buf_T	*old_curbuf;
     char_u	*old_b_ffname;
     char_u	*old_b_fname;
@@ -609,11 +599,9 @@ readfile(
 		     * edited before and deleted.  Get the old marks. */
 		    check_marks_read();
 #endif
-#ifdef FEAT_MBYTE
 		    /* Set forced 'fileencoding'.  */
 		    if (eap != NULL)
 			set_forced_fenc(eap);
-#endif
 		    apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname,
 							  FALSE, curbuf, eap);
 		    /* remember the current fileformat */
@@ -658,10 +646,8 @@ readfile(
 	    curbuf->b_p_eol = TRUE;
 	    curbuf->b_start_eol = TRUE;
 	}
-#ifdef FEAT_MBYTE
 	curbuf->b_p_bomb = FALSE;
 	curbuf->b_start_bomb = FALSE;
-#endif
     }
 
     /* Create a swap file now, so that other Vims are warned that we are
@@ -846,7 +832,6 @@ readfile(
      */
     linecnt = curbuf->b_ml.ml_line_count;
 
-#ifdef FEAT_MBYTE
     /* "++bad=" argument. */
     if (eap != NULL && eap->bad_char != 0)
     {
@@ -926,7 +911,6 @@ readfile(
 	fenc = next_fenc(&fenc_next);
 	fenc_alloced = TRUE;
     }
-#endif
 
     /*
      * Jump back here to retry reading the file in different ways.
@@ -966,14 +950,12 @@ retry:
 	while (lnum > from)
 	    ml_delete(lnum--, FALSE);
 	file_rewind = FALSE;
-#ifdef FEAT_MBYTE
 	if (set_options)
 	{
 	    curbuf->b_p_bomb = FALSE;
 	    curbuf->b_start_bomb = FALSE;
 	}
 	conv_error = 0;
-#endif
     }
 
     /*
@@ -997,15 +979,14 @@ retry:
 	    fileformat = EOL_UNKNOWN;		/* detect from file */
     }
 
-#ifdef FEAT_MBYTE
-# ifdef USE_ICONV
+#ifdef USE_ICONV
     if (iconv_fd != (iconv_t)-1)
     {
 	/* aborted conversion with iconv(), close the descriptor */
 	iconv_close(iconv_fd);
 	iconv_fd = (iconv_t)-1;
     }
-# endif
+#endif
 
     if (advance_fenc)
     {
@@ -1073,49 +1054,49 @@ retry:
 	else if (enc_utf8 || STRCMP(p_enc, "latin1") == 0)
 	    fio_flags = get_fio_flags(fenc);
 
-# ifdef WIN3264
+#ifdef WIN3264
 	/*
 	 * Conversion from an MS-Windows codepage to UTF-8 or another codepage
 	 * is handled with MultiByteToWideChar().
 	 */
 	if (fio_flags == 0)
 	    fio_flags = get_win_fio_flags(fenc);
-# endif
-
-# ifdef MACOS_CONVERT
+#endif
+
+#ifdef MACOS_CONVERT
 	/* Conversion from Apple MacRoman to latin1 or UTF-8 */
 	if (fio_flags == 0)
 	    fio_flags = get_mac_fio_flags(fenc);
-# endif
-
-# ifdef USE_ICONV
+#endif
+
+#ifdef USE_ICONV
 	/*
 	 * Try using iconv() if we can't convert internally.
 	 */
 	if (fio_flags == 0
-#  ifdef FEAT_EVAL
+# ifdef FEAT_EVAL
 		&& !did_iconv
-#  endif
+# endif
 		)
 	    iconv_fd = (iconv_t)my_iconv_open(
 				  enc_utf8 ? (char_u *)"utf-8" : p_enc, fenc);
-# endif
-
-# ifdef FEAT_EVAL
+#endif
+
+#ifdef FEAT_EVAL
 	/*
 	 * Use the 'charconvert' expression when conversion is required
 	 * and we can't do it internally or with iconv().
 	 */
 	if (fio_flags == 0 && !read_stdin && !read_buffer && *p_ccv != NUL
 						    && !read_fifo
-#  ifdef USE_ICONV
+# ifdef USE_ICONV
 						    && iconv_fd == (iconv_t)-1
-#  endif
+# endif
 		)
 	{
-#  ifdef USE_ICONV
+# ifdef USE_ICONV
 	    did_iconv = FALSE;
-#  endif
+# endif
 	    /* Skip conversion when it's already done (retry for wrong
 	     * "fileformat"). */
 	    if (tmpname == NULL)
@@ -1137,12 +1118,12 @@ retry:
 	    }
 	}
 	else
-# endif
+#endif
 	{
 	    if (fio_flags == 0
-# ifdef USE_ICONV
+#ifdef USE_ICONV
 		    && iconv_fd == (iconv_t)-1
-# endif
+#endif
 	       )
 	    {
 		/* Conversion wanted but we can't.
@@ -1157,7 +1138,6 @@ retry:
      * another "fenc" value.  It's FALSE when no other "fenc" to try, reading
      * stdin or fixed at a specific encoding. */
     can_retry = (*fenc != NUL && !read_stdin && !read_fifo && !keep_dest_enc);
-#endif
 
     if (!skip_read)
     {
@@ -1165,9 +1145,7 @@ retry:
 	filesize = 0;
 	skip_count = lines_to_skip;
 	read_count = lines_to_read;
-#ifdef FEAT_MBYTE
 	conv_restlen = 0;
-#endif
 #ifdef FEAT_PERSISTENT_UNDO
 	read_undo_file = (newfile && (flags & READ_KEEP_UNDO) == 0
 				  && curbuf->b_ffname != NULL
@@ -1253,7 +1231,6 @@ retry:
 		ptr = buffer + linerest;
 		line_start = buffer;
 
-#ifdef FEAT_MBYTE
 		/* May need room to translate into.
 		 * For iconv() we don't really know the required space, use a
 		 * factor ICONV_MULT.
@@ -1265,11 +1242,11 @@ retry:
 		 * ucs-4 to utf-8: 4 bytes become up to 6 bytes, size must be
 		 * multiple of 4 */
 		real_size = (int)size;
-# ifdef USE_ICONV
+#ifdef USE_ICONV
 		if (iconv_fd != (iconv_t)-1)
 		    size = size / ICONV_MULT;
 		else
-# endif
+#endif
 		    if (fio_flags & FIO_LATIN1)
 		    size = size / 2;
 		else if (fio_flags & (FIO_UCS2 | FIO_UTF16))
@@ -1278,17 +1255,15 @@ retry:
 		    size = (size * 2 / 3) & ~3;
 		else if (fio_flags == FIO_UCSBOM)
 		    size = size / ICONV_MULT;	/* worst case */
-# ifdef WIN3264
+#ifdef WIN3264
 		else if (fio_flags & FIO_CODEPAGE)
 		    size = size / ICONV_MULT;	/* also worst case */
-# endif
-# ifdef MACOS_CONVERT
+#endif
+#ifdef MACOS_CONVERT
 		else if (fio_flags & FIO_MACROMAN)
 		    size = size / ICONV_MULT;	/* also worst case */
-# endif
-#endif
-
-#ifdef FEAT_MBYTE
+#endif
+
 		if (conv_restlen > 0)
 		{
 		    /* Insert unconverted bytes from previous line. */
@@ -1296,7 +1271,6 @@ retry:
 		    ptr += conv_restlen;
 		    size -= conv_restlen;
 		}
-#endif
 
 		if (read_buffer)
 		{
@@ -1445,7 +1419,6 @@ retry:
 		{
 		    if (size < 0)		    /* read error */
 			error = TRUE;
-#ifdef FEAT_MBYTE
 		    else if (conv_restlen > 0)
 		    {
 			/*
@@ -1455,9 +1428,9 @@ retry:
 
 			/* When we did a conversion report an error. */
 			if (fio_flags != 0
-# ifdef USE_ICONV
+#ifdef USE_ICONV
 				|| iconv_fd != (iconv_t)-1
-# endif
+#endif
 			   )
 			{
 			    if (can_retry)
@@ -1482,9 +1455,9 @@ retry:
 			     * leave the UTF8 checking code to do it, as it
 			     * works slightly differently. */
 			    if (bad_char_behavior != BAD_KEEP && (fio_flags != 0
-# ifdef USE_ICONV
+#ifdef USE_ICONV
 				    || iconv_fd != (iconv_t)-1
-# endif
+#endif
 			       ))
 			    {
 				while (conv_restlen > 0)
@@ -1494,21 +1467,19 @@ retry:
 				}
 			    }
 			    fio_flags = 0;	/* don't convert this */
-# ifdef USE_ICONV
+#ifdef USE_ICONV
 			    if (iconv_fd != (iconv_t)-1)
 			    {
 				iconv_close(iconv_fd);
 				iconv_fd = (iconv_t)-1;
 			    }
-# endif
+#endif
 			}
 		    }
-#endif
 		}
 	    }
 	    skip_read = FALSE;
 
-#ifdef FEAT_MBYTE
 	    /*
 	     * At start of file (or after crypt magic number): Check for BOM.
 	     * Also check for a BOM for other Unicode encodings, but not after
@@ -1516,11 +1487,11 @@ retry:
 	     * found.
 	     */
 	    if ((filesize == 0
-# ifdef FEAT_CRYPT
+#ifdef FEAT_CRYPT
 		   || (cryptkey != NULL
 			&& filesize == crypt_get_header_len(
 						 crypt_get_method_nr(curbuf)))
-# endif
+#endif
 		       )
 		    && (fio_flags == FIO_UCSBOM
 			|| (!curbuf->b_p_bomb
@@ -1574,16 +1545,14 @@ retry:
 	    ptr -= conv_restlen;
 	    size += conv_restlen;
 	    conv_restlen = 0;
-#endif
 	    /*
 	     * Break here for a read error or end-of-file.
 	     */
 	    if (size <= 0)
 		break;
 
-#ifdef FEAT_MBYTE
-
-# ifdef USE_ICONV
+
+#ifdef USE_ICONV
 	    if (iconv_fd != (iconv_t)-1)
 	    {
 		/*
@@ -1645,9 +1614,9 @@ retry:
 		mch_memmove(line_start, buffer, (size_t)linerest);
 		size = (long)((char_u *)top - ptr);
 	    }
-# endif
-
-# ifdef WIN3264
+#endif
+
+#ifdef WIN3264
 	    if (fio_flags & FIO_CODEPAGE)
 	    {
 		char_u	*src, *dst;
@@ -1813,8 +1782,8 @@ retry:
 		size = (long)(dst - ptr);
 	    }
 	    else
-# endif
-# ifdef MACOS_CONVERT
+#endif
+#ifdef MACOS_CONVERT
 	    if (fio_flags & FIO_MACROMAN)
 	    {
 		/*
@@ -1825,7 +1794,7 @@ retry:
 		    goto rewind_retry;
 	    }
 	    else
-# endif
+#endif
 	    if (fio_flags != 0)
 	    {
 		int	u8c;
@@ -2089,11 +2058,11 @@ retry:
 			     * file is more likely than a conversion error. */
 			    if (can_retry && !incomplete_tail)
 				break;
-# ifdef USE_ICONV
+#ifdef USE_ICONV
 			    /* When we did a conversion report an error. */
 			    if (iconv_fd != (iconv_t)-1 && conv_error == 0)
 				conv_error = readfile_linenr(linecnt, ptr, p);
-# endif
+#endif
 			    /* Remember the first linenr with an illegal byte */
 			    if (conv_error == 0 && illegal_byte == 0)
 				illegal_byte = readfile_linenr(linecnt, ptr, p);
@@ -2117,19 +2086,18 @@ retry:
 		    /* Detected a UTF-8 error. */
 rewind_retry:
 		    /* Retry reading with another conversion. */
-# if defined(FEAT_EVAL) && defined(USE_ICONV)
+#if defined(FEAT_EVAL) && defined(USE_ICONV)
 		    if (*p_ccv != NUL && iconv_fd != (iconv_t)-1)
 			/* iconv() failed, try 'charconvert' */
 			did_iconv = TRUE;
 		    else
-# endif
+#endif
 			/* use next item from 'fileencodings' */
 			advance_fenc = TRUE;
 		    file_rewind = TRUE;
 		    goto retry;
 		}
 	    }
-#endif
 
 	    /* count the number of characters (after conversion!) */
 	    filesize += size;
@@ -2371,7 +2339,6 @@ failed:
      * encryption was used. */
 #endif
 
-#ifdef FEAT_MBYTE
     /* If editing a new file: set 'fenc' for the current buffer.
      * Also for ":read ++edit file". */
     if (set_options)
@@ -2379,13 +2346,12 @@ failed:
 						       OPT_FREE|OPT_LOCAL, 0);
     if (fenc_alloced)
 	vim_free(fenc);
-# ifdef USE_ICONV
+#ifdef USE_ICONV
     if (iconv_fd != (iconv_t)-1)
     {
 	iconv_close(iconv_fd);
 	iconv_fd = (iconv_t)-1;
     }
-# endif
 #endif
 
     if (!read_buffer && !read_stdin)
@@ -2409,13 +2375,11 @@ failed:
     }
 #endif
 
-#ifdef FEAT_MBYTE
     if (tmpname != NULL)
     {
 	mch_remove(tmpname);		/* delete converted file */
 	vim_free(tmpname);
     }
-#endif
     --no_wait_return;			/* may wait for return now */
 
     /*
@@ -2528,7 +2492,6 @@ failed:
 		STRCAT(IObuff, _("[long lines split]"));
 		c = TRUE;
 	    }
-#ifdef FEAT_MBYTE
 	    if (notconverted)
 	    {
 		STRCAT(IObuff, _("[NOT converted]"));
@@ -2539,7 +2502,6 @@ failed:
 		STRCAT(IObuff, _("[converted]"));
 		c = TRUE;
 	    }
-#endif
 #ifdef FEAT_CRYPT
 	    if (cryptkey != NULL)
 	    {
@@ -2547,7 +2509,6 @@ failed:
 		c = TRUE;
 	    }
 #endif
-#ifdef FEAT_MBYTE
 	    if (conv_error != 0)
 	    {
 		sprintf((char *)IObuff + STRLEN(IObuff),
@@ -2560,9 +2521,7 @@ failed:
 			 _("[ILLEGAL BYTE in line %ld]"), (long)illegal_byte);
 		c = TRUE;
 	    }
-	    else
-#endif
-		if (error)
+	    else if (error)
 	    {
 		STRCAT(IObuff, _("[READ ERRORS]"));
 		c = TRUE;
@@ -2601,11 +2560,8 @@ failed:
 
 	/* with errors writing the file requires ":w!" */
 	if (newfile && (error
-#ifdef FEAT_MBYTE
 		    || conv_error != 0
-		    || (illegal_byte > 0 && bad_char_behavior != BAD_KEEP)
-#endif
-		    ))
+		    || (illegal_byte > 0 && bad_char_behavior != BAD_KEEP)))
 	    curbuf->b_p_ro = TRUE;
 
 	u_clearline();	    /* cannot use "U" command after adding lines */
@@ -2745,8 +2701,6 @@ is_dev_fd_file(char_u *fname)
 }
 #endif
 
-#ifdef FEAT_MBYTE
-
 /*
  * From the current line count and characters read after that, estimate the
  * line number where we are now.
@@ -2767,7 +2721,6 @@ readfile_linenr(
 	    ++lnum;
     return lnum;
 }
-#endif
 
 /*
  * Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary to be
@@ -2777,21 +2730,13 @@ readfile_linenr(
     int
 prep_exarg(exarg_T *eap, buf_T *buf)
 {
-    eap->cmd = alloc(15
-#ifdef FEAT_MBYTE
-		+ (unsigned)STRLEN(buf->b_p_fenc)
-#endif
-	    );
+    eap->cmd = alloc(15 + (unsigned)STRLEN(buf->b_p_fenc));
     if (eap->cmd == NULL)
 	return FAIL;
 
-#ifdef FEAT_MBYTE
     sprintf((char *)eap->cmd, "e ++enc=%s", buf->b_p_fenc);
     eap->force_enc = 8;
     eap->bad_char = buf->b_bad_char;
-#else
-    sprintf((char *)eap->cmd, "e");
-#endif
     eap->force_ff = *buf->b_p_ff;
 
     eap->force_bin = buf->b_p_bin ? FORCE_BIN : FORCE_NOBIN;
@@ -2825,7 +2770,6 @@ set_file_options(int set_options, exarg_
     }
 }
 
-#if defined(FEAT_MBYTE) || defined(PROTO)
 /*
  * Set forced 'fileencoding'.
  */
@@ -2886,7 +2830,7 @@ next_fenc(char_u **pp)
     return r;
 }
 
-# ifdef FEAT_EVAL
+#ifdef FEAT_EVAL
 /*
  * Convert a file with the 'charconvert' expression.
  * This closes the file which is to be read, converts it and opens the
@@ -2937,9 +2881,8 @@ readfile_charconvert(
 
     return tmpname;
 }
-# endif
-
-#endif
+#endif
+
 
 #ifdef FEAT_VIMINFO
 /*
@@ -3176,12 +3119,10 @@ buf_write(
     int		    fileformat;
     int		    write_bin;
     struct bw_info  write_info;		/* info for buf_write_bytes() */
-#ifdef FEAT_MBYTE
     int		    converted = FALSE;
     int		    notconverted = FALSE;
     char_u	    *fenc;		/* effective 'fileencoding' */
     char_u	    *fenc_tofree = NULL; /* allocated "fenc" */
-#endif
 #ifdef HAS_BW_FLAGS
     int		    wb_flags = 0;
 #endif
@@ -3219,15 +3160,13 @@ buf_write(
 	return FAIL;
     }
 
-#ifdef FEAT_MBYTE
     /* must init bw_conv_buf and bw_iconv_fd before jumping to "fail" */
     write_info.bw_conv_buf = NULL;
     write_info.bw_conv_error = FALSE;
     write_info.bw_conv_error_lnum = 0;
     write_info.bw_restlen = 0;
-# ifdef USE_ICONV
+#ifdef USE_ICONV
     write_info.bw_iconv_fd = (iconv_t)-1;
-# endif
 #endif
 #ifdef FEAT_CRYPT
     write_info.bw_buffer = buf;
@@ -4227,7 +4166,6 @@ buf_write(
      * multi-byte conversion. */
     wfname = fname;
 
-#ifdef FEAT_MBYTE
     /* Check for forced 'fileencoding' from "++opt=val" argument. */
     if (eap != NULL && eap->force_enc != 0)
     {
@@ -4265,7 +4203,7 @@ buf_write(
 	}
     }
 
-# ifdef WIN3264
+#ifdef WIN3264
     if (converted && wb_flags == 0 && (wb_flags = get_win_fio_flags(fenc)) != 0)
     {
 	/* Convert UTF-8 -> UCS-2 and UCS-2 -> DBCS.  Worst-case * 4: */
@@ -4275,9 +4213,9 @@ buf_write(
 	if (write_info.bw_conv_buf == NULL)
 	    end = 0;
     }
-# endif
-
-# ifdef MACOS_CONVERT
+#endif
+
+#ifdef MACOS_CONVERT
     if (converted && wb_flags == 0 && (wb_flags = get_mac_fio_flags(fenc)) != 0)
     {
 	write_info.bw_conv_buflen = bufsize * 3;
@@ -4286,12 +4224,12 @@ buf_write(
 	if (write_info.bw_conv_buf == NULL)
 	    end = 0;
     }
-# endif
-
-# if defined(FEAT_EVAL) || defined(USE_ICONV)
+#endif
+
+#if defined(FEAT_EVAL) || defined(USE_ICONV)
     if (converted && wb_flags == 0)
     {
-#  ifdef USE_ICONV
+# ifdef USE_ICONV
 	/*
 	 * Use iconv() conversion when conversion is needed and it's not done
 	 * internally.
@@ -4308,12 +4246,12 @@ buf_write(
 		end = 0;
 	    write_info.bw_first = TRUE;
 	}
-#   ifdef FEAT_EVAL
+#  ifdef FEAT_EVAL
 	else
-#   endif
 #  endif
-
-#  ifdef FEAT_EVAL
+# endif
+
+# ifdef FEAT_EVAL
 	    /*
 	     * When the file needs to be converted with 'charconvert' after
 	     * writing, write to a temp file instead and let the conversion
@@ -4328,16 +4266,16 @@ buf_write(
 		    goto restore_backup;
 		}
 	    }
-#  endif
-    }
 # endif
+    }
+#endif
     if (converted && wb_flags == 0
-#  ifdef USE_ICONV
+#ifdef USE_ICONV
 	    && write_info.bw_iconv_fd == (iconv_t)-1
-#  endif
-#  ifdef FEAT_EVAL
+# endif
+# ifdef FEAT_EVAL
 	    && wfname == fname
-#  endif
+# endif
 	    )
     {
 	if (!forceit)
@@ -4347,7 +4285,6 @@ buf_write(
 	}
 	notconverted = TRUE;
     }
-#endif
 
     /*
      * If conversion is taking place, we may first pretend to write and check
@@ -4362,9 +4299,7 @@ buf_write(
 	 * - we make a backup file, that can be restored in case of conversion
 	 *   failure.
 	 */
-#ifdef FEAT_MBYTE
 	if (!converted || dobackup)
-#endif
 	    checking_conversion = FALSE;
 
 	if (checking_conversion)
@@ -4477,10 +4412,8 @@ restore_backup:
 			end = 0;
 		}
 
-#ifdef FEAT_MBYTE
 		if (wfname != fname)
 		    vim_free(wfname);
-#endif
 		goto fail;
 	    }
 	    write_info.bw_fd = fd;
@@ -4563,7 +4496,6 @@ restore_backup:
 	else
 	    write_bin = buf->b_p_bin;
 
-#ifdef FEAT_MBYTE
 	/*
 	 * The BOM is written just after the encryption magic number.
 	 * Skip it when appending and the file already existed, the BOM only
@@ -4583,7 +4515,6 @@ restore_backup:
 	    }
 	}
 	write_info.bw_start_lnum = start;
-#endif
 
 #ifdef FEAT_PERSISTENT_UNDO
 	write_undo_file = (buf->b_p_udf
@@ -4635,9 +4566,7 @@ restore_backup:
 		nchars += bufsize;
 		s = buffer;
 		len = 0;
-#ifdef FEAT_MBYTE
 		write_info.bw_start_lnum = lnum;
-#endif
 	    }
 	    /* write failed or last line has no EOL: stop here */
 	    if (end == 0
@@ -4841,7 +4770,7 @@ restore_backup:
 	}
 #endif
 
-#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
+#if defined(FEAT_EVAL)
 	if (wfname != fname)
 	{
 	    /*
@@ -4870,7 +4799,6 @@ restore_backup:
 	 */
 	if (errmsg == NULL)
 	{
-#ifdef FEAT_MBYTE
 	    if (write_info.bw_conv_error)
 	    {
 		if (write_info.bw_conv_error_lnum == 0)
@@ -4883,12 +4811,10 @@ restore_backup:
 					 (long)write_info.bw_conv_error_lnum);
 		}
 	    }
+	    else if (got_int)
+		errmsg = (char_u *)_(e_interr);
 	    else
-#endif
-		if (got_int)
-		    errmsg = (char_u *)_(e_interr);
-		else
-		    errmsg = (char_u *)_("E514: write error (file system full?)");
+		errmsg = (char_u *)_("E514: write error (file system full?)");
 	}
 
 	/*
@@ -4953,7 +4879,6 @@ restore_backup:
     {
 	msg_add_fname(buf, fname);	/* put fname in IObuff with quotes */
 	c = FALSE;
-#ifdef FEAT_MBYTE
 	if (write_info.bw_conv_error)
 	{
 	    STRCAT(IObuff, _(" CONVERSION ERROR"));
@@ -4972,7 +4897,6 @@ restore_backup:
 	    STRCAT(IObuff, _("[converted]"));
 	    c = TRUE;
 	}
-#endif
 	if (device)
 	{
 	    STRCAT(IObuff, _("[Device]"));
@@ -5013,11 +4937,8 @@ restore_backup:
     /* When written everything correctly: reset 'modified'.  Unless not
      * writing to the original file and '+' is not in 'cpoptions'. */
     if (reset_changed && whole && !append
-#ifdef FEAT_MBYTE
 	    && !write_info.bw_conv_error
-#endif
-	    && (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL)
-	    )
+	    && (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL))
     {
 	unchanged(buf, TRUE);
 	/* b:changedtick is always incremented in unchanged() but that
@@ -5113,16 +5034,14 @@ nofail:
     vim_free(backup);
     if (buffer != smallbuf)
 	vim_free(buffer);
-#ifdef FEAT_MBYTE
     vim_free(fenc_tofree);
     vim_free(write_info.bw_conv_buf);
-# ifdef USE_ICONV
+#ifdef USE_ICONV
     if (write_info.bw_iconv_fd != (iconv_t)-1)
     {
 	iconv_close(write_info.bw_iconv_fd);
 	write_info.bw_iconv_fd = (iconv_t)-1;
     }
-# endif
 #endif
 #ifdef HAVE_ACL
     mch_free_acl(acl);
@@ -5411,7 +5330,6 @@ buf_write_bytes(struct bw_info *ip)
     int		flags = ip->bw_flags;	/* extra flags */
 #endif
 
-#ifdef FEAT_MBYTE
     /*
      * Skip conversion when writing the crypt magic number or the BOM.
      */
@@ -5521,7 +5439,7 @@ buf_write_bytes(struct bw_info *ip)
 	    }
 	}
 
-# ifdef WIN3264
+#ifdef WIN3264
 	else if (flags & FIO_CODEPAGE)
 	{
 	    /*
@@ -5617,7 +5535,7 @@ buf_write_bytes(struct bw_info *ip)
 
 	    fromlen = to - ip->bw_conv_buf;
 	    buf = to;
-#  ifdef CP_UTF8	/* VC 4.1 doesn't define CP_UTF8 */
+# ifdef CP_UTF8	/* VC 4.1 doesn't define CP_UTF8 */
 	    if (FIO_GET_CP(flags) == CP_UTF8)
 	    {
 		/* Convert from UCS-2 to UTF-8, using the remainder of the
@@ -5636,7 +5554,7 @@ buf_write_bytes(struct bw_info *ip)
 		len = (int)(to - buf);
 	    }
 	    else
-#endif
+# endif
 	    {
 		/* Convert from UCS-2 to the codepage, using the remainder of
 		 * the conversion buffer.  If the conversion uses the default
@@ -5653,9 +5571,9 @@ buf_write_bytes(struct bw_info *ip)
 		}
 	    }
 	}
-# endif
-
-# ifdef MACOS_CONVERT
+#endif
+
+#ifdef MACOS_CONVERT
 	else if (flags & FIO_MACROMAN)
 	{
 	    /*
@@ -5689,9 +5607,9 @@ buf_write_bytes(struct bw_info *ip)
 	    }
 	    buf = ip->bw_conv_buf;
 	}
-# endif
-
-# ifdef USE_ICONV
+#endif
+
+#ifdef USE_ICONV
 	if (ip->bw_iconv_fd != (iconv_t)-1)
 	{
 	    const char	*from;
@@ -5759,9 +5677,8 @@ buf_write_bytes(struct bw_info *ip)
 	    buf = ip->bw_conv_buf;
 	    len = (int)((char_u *)to - ip->bw_conv_buf);
 	}
-# endif
-    }
-#endif /* FEAT_MBYTE */
+#endif
+    }
 
     if (ip->bw_fd < 0)
 	/* Only checking conversion, which is OK if we get here. */
@@ -5798,7 +5715,6 @@ buf_write_bytes(struct bw_info *ip)
     return (wlen < len) ? FAIL : OK;
 }
 
-#ifdef FEAT_MBYTE
 /*
  * Convert a Unicode character to bytes.
  * Return TRUE for an error, FALSE when it's OK.
@@ -6089,7 +6005,6 @@ make_bom(char_u *buf, char_u *name)
     (void)ucs2bytes(0xfeff, &p, flags);
     return (int)(p - buf);
 }
-#endif
 
 /*
  * Try to find a shortname by comparing the fullname with the current
@@ -7639,13 +7554,10 @@ forward_slash(char_u *fname)
     if (path_with_url(fname))
 	return;
     for (p = fname; *p != NUL; ++p)
-# ifdef  FEAT_MBYTE
 	/* The Big5 encoding can have '\' in the trail byte. */
 	if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1)
 	    ++p;
-	else
-# endif
-	if (*p == '\\')
+	else if (*p == '\\')
 	    *p = '/';
 }
 #endif
@@ -10340,13 +10252,11 @@ file_pat_to_reg_pat(
 #endif
 	    default:
 		size++;
-# ifdef FEAT_MBYTE
 		if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1)
 		{
 		    ++p;
 		    ++size;
 		}
-# endif
 		break;
 	}
     }
@@ -10479,12 +10389,9 @@ file_pat_to_reg_pat(
 		    reg_pat[i++] = ',';
 		break;
 	    default:
-# ifdef  FEAT_MBYTE
 		if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1)
 		    reg_pat[i++] = *p++;
-		else
-# endif
-		if (allow_dirs != NULL && vim_ispathsep(*p))
+		else if (allow_dirs != NULL && vim_ispathsep(*p))
 		    *allow_dirs = TRUE;
 		reg_pat[i++] = *p;
 		break;