diff src/winclip.c @ 15605:62b3805506b3 v8.1.0810

patch 8.1.0810: too many #ifdefs commit https://github.com/vim/vim/commit/264b74fa545edfb92c0d7d08a02c26331cc5b168 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 17:18:42 2019 +0100 patch 8.1.0810: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate FEAT_MBYTE, part 4.
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 17:30:08 +0100
parents 04eb70c77cf4
children 7fad90423bd2
line wrap: on
line diff
--- a/src/winclip.c
+++ b/src/winclip.c
@@ -44,7 +44,6 @@ typedef int LPWSTR;
 typedef int UINT;
 #endif
 
-#if defined(FEAT_MBYTE) || defined(PROTO)
 /*
  * Convert an UTF-8 string to UTF-16.
  * "instr[inlen]" is the input.  "inlen" is in bytes.
@@ -179,7 +178,6 @@ WideCharToMultiByte_alloc(UINT cp, DWORD
     }
 }
 
-#endif /* FEAT_MBYTE */
 
 #ifdef FEAT_CLIPBOARD
 /*
@@ -301,12 +299,10 @@ clip_mch_request_selection(VimClipboard 
     VimClipType_t	metadata = { -1, -1, -1, -1 };
     HGLOBAL		hMem = NULL;
     char_u		*str = NULL;
-#if defined(FEAT_MBYTE) && defined(WIN3264)
+#if defined(WIN3264)
     char_u		*to_free = NULL;
 #endif
-#ifdef FEAT_MBYTE
     HGLOBAL		rawh = NULL;
-#endif
     int			str_size = 0;
     int			maxlen;
     size_t		n;
@@ -339,7 +335,6 @@ clip_mch_request_selection(VimClipboard 
 	}
     }
 
-#ifdef FEAT_MBYTE
     /* Check for Vim's raw clipboard format first.  This is used without
      * conversion, but only if 'encoding' matches. */
     if (IsClipboardFormatAvailable(cbd->format_raw)
@@ -366,79 +361,75 @@ clip_mch_request_selection(VimClipboard 
     }
     if (str == NULL)
     {
-#endif
+#if defined(WIN3264)
+	/* Try to get the clipboard in Unicode if it's not an empty string. */
+	if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0)
+	{
+	    HGLOBAL hMemW;
 
-#if defined(FEAT_MBYTE) && defined(WIN3264)
-    /* Try to get the clipboard in Unicode if it's not an empty string. */
-    if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0)
-    {
-	HGLOBAL hMemW;
-
-	if ((hMemW = GetClipboardData(CF_UNICODETEXT)) != NULL)
-	{
-	    WCHAR *hMemWstr = (WCHAR *)GlobalLock(hMemW);
+	    if ((hMemW = GetClipboardData(CF_UNICODETEXT)) != NULL)
+	    {
+		WCHAR *hMemWstr = (WCHAR *)GlobalLock(hMemW);
 
-	    /* Use the length of our metadata if possible, but limit it to the
-	     * GlobalSize() for safety. */
-	    maxlen = (int)(GlobalSize(hMemW) / sizeof(WCHAR));
-	    if (metadata.ucslen >= 0)
-	    {
-		if (metadata.ucslen > maxlen)
-		    str_size = maxlen;
+		/* Use the length of our metadata if possible, but limit it to
+		 * the GlobalSize() for safety. */
+		maxlen = (int)(GlobalSize(hMemW) / sizeof(WCHAR));
+		if (metadata.ucslen >= 0)
+		{
+		    if (metadata.ucslen > maxlen)
+			str_size = maxlen;
+		    else
+			str_size = metadata.ucslen;
+		}
 		else
-		    str_size = metadata.ucslen;
+		{
+		    for (str_size = 0; str_size < maxlen; ++str_size)
+			if (hMemWstr[str_size] == NUL)
+			    break;
+		}
+		to_free = str = utf16_to_enc((short_u *)hMemWstr, &str_size);
+		GlobalUnlock(hMemW);
 	    }
-	    else
+	}
+	else
+#endif
+	    /* Get the clipboard in the Active codepage. */
+	    if (IsClipboardFormatAvailable(CF_TEXT))
+	{
+	    if ((hMem = GetClipboardData(CF_TEXT)) != NULL)
 	    {
-		for (str_size = 0; str_size < maxlen; ++str_size)
-		    if (hMemWstr[str_size] == NUL)
-			break;
+		str = (char_u *)GlobalLock(hMem);
+
+		/* The length is either what our metadata says or the strlen().
+		 * But limit it to the GlobalSize() for safety. */
+		maxlen = (int)GlobalSize(hMem);
+		if (metadata.txtlen >= 0)
+		{
+		    if (metadata.txtlen > maxlen)
+			str_size = maxlen;
+		    else
+			str_size = metadata.txtlen;
+		}
+		else
+		{
+		    for (str_size = 0; str_size < maxlen; ++str_size)
+			if (str[str_size] == NUL)
+			    break;
+		}
+
+#if defined(WIN3264)
+		/* The text is in the active codepage.  Convert to
+		 * 'encoding', going through UTF-16. */
+		acp_to_enc(str, str_size, &to_free, &maxlen);
+		if (to_free != NULL)
+		{
+		    str_size = maxlen;
+		    str = to_free;
+		}
+#endif
 	    }
-	    to_free = str = utf16_to_enc((short_u *)hMemWstr, &str_size);
-	    GlobalUnlock(hMemW);
 	}
     }
-    else
-#endif
-    /* Get the clipboard in the Active codepage. */
-    if (IsClipboardFormatAvailable(CF_TEXT))
-    {
-	if ((hMem = GetClipboardData(CF_TEXT)) != NULL)
-	{
-	    str = (char_u *)GlobalLock(hMem);
-
-	    /* The length is either what our metadata says or the strlen().
-	     * But limit it to the GlobalSize() for safety. */
-	    maxlen = (int)GlobalSize(hMem);
-	    if (metadata.txtlen >= 0)
-	    {
-		if (metadata.txtlen > maxlen)
-		    str_size = maxlen;
-		else
-		    str_size = metadata.txtlen;
-	    }
-	    else
-	    {
-		for (str_size = 0; str_size < maxlen; ++str_size)
-		    if (str[str_size] == NUL)
-			break;
-	    }
-
-# if defined(FEAT_MBYTE) && defined(WIN3264)
-	    /* The text is in the active codepage.  Convert to 'encoding',
-	     * going through UTF-16. */
-	    acp_to_enc(str, str_size, &to_free, &maxlen);
-	    if (to_free != NULL)
-	    {
-		str_size = maxlen;
-		str = to_free;
-	    }
-# endif
-	}
-    }
-#ifdef FEAT_MBYTE
-    }
-#endif
 
     if (str != NULL && *str != NUL)
     {
@@ -460,12 +451,10 @@ clip_mch_request_selection(VimClipboard 
     /* unlock the global object */
     if (hMem != NULL)
 	GlobalUnlock(hMem);
-#ifdef FEAT_MBYTE
     if (rawh != NULL)
 	GlobalUnlock(rawh);
-#endif
     CloseClipboard();
-#if defined(FEAT_MBYTE) && defined(WIN3264)
+#if defined(WIN3264)
     vim_free(to_free);
 #endif
 }
@@ -482,7 +471,7 @@ clip_mch_set_selection(VimClipboard *cbd
     HGLOBAL		hMemRaw = NULL;
     HGLOBAL		hMem = NULL;
     HGLOBAL		hMemVim = NULL;
-# if defined(FEAT_MBYTE) && defined(WIN3264)
+# if defined(WIN3264)
     HGLOBAL		hMemW = NULL;
 # endif
 
@@ -499,7 +488,6 @@ clip_mch_set_selection(VimClipboard *cbd
     metadata.ucslen = 0;
     metadata.rawlen = 0;
 
-#ifdef FEAT_MBYTE
     /* Always set the raw bytes: 'encoding', NUL and the text.  This is used
      * when copy/paste from/to Vim with the same 'encoding', so that illegal
      * bytes can also be copied and no conversion is needed. */
@@ -519,9 +507,8 @@ clip_mch_set_selection(VimClipboard *cbd
 	else
 	    metadata.rawlen = 0;
     }
-#endif
 
-# if defined(FEAT_MBYTE) && defined(WIN3264)
+# if defined(WIN3264)
     {
 	WCHAR		*out;
 	int		len = metadata.txtlen;
@@ -603,7 +590,7 @@ clip_mch_set_selection(VimClipboard *cbd
 	{
 	    SetClipboardData(cbd->format, hMemVim);
 	    hMemVim = 0;
-# if defined(FEAT_MBYTE) && defined(WIN3264)
+# if defined(WIN3264)
 	    if (hMemW != NULL)
 	    {
 		if (SetClipboardData(CF_UNICODETEXT, hMemW) != NULL)
@@ -624,7 +611,7 @@ clip_mch_set_selection(VimClipboard *cbd
 	GlobalFree(hMemRaw);
     if (hMem)
 	GlobalFree(hMem);
-# if defined(FEAT_MBYTE) && defined(WIN3264)
+# if defined(WIN3264)
     if (hMemW)
 	GlobalFree(hMemW);
 # endif
@@ -634,7 +621,6 @@ clip_mch_set_selection(VimClipboard *cbd
 
 #endif /* FEAT_CLIPBOARD */
 
-#if defined(FEAT_MBYTE) || defined(PROTO)
 /*
  * Note: the following two functions are only guaranteed to work when using
  * valid MS-Windows codepages or when iconv() is available.
@@ -759,9 +745,8 @@ utf16_to_enc(short_u *str, int *lenp)
 
     return enc_str;
 }
-#endif /* FEAT_MBYTE */
 
-#if (defined(FEAT_MBYTE) && defined(WIN3264)) || defined(PROTO)
+#if defined(WIN3264) || defined(PROTO)
 /*
  * Convert from the active codepage to 'encoding'.
  * Input is "str[str_size]".