diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-01-24 17:18:42 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-01-24 17:18:42 +0100 |
commit | 264b74fa545edfb92c0d7d08a02c26331cc5b168 (patch) | |
tree | 2cd0e8517c498f4ce1442492572032be9815654d /src/winclip.c | |
parent | a12a161b8ce09d024ed71c2134149fa323f8ee8e (diff) | |
download | vim-git-264b74fa545edfb92c0d7d08a02c26331cc5b168.tar.gz |
patch 8.1.0810: too many #ifdefsv8.1.0810
Problem: Too many #ifdefs.
Solution: Graduate FEAT_MBYTE, part 4.
Diffstat (limited to 'src/winclip.c')
-rw-r--r-- | src/winclip.c | 141 |
1 files changed, 63 insertions, 78 deletions
diff --git a/src/winclip.c b/src/winclip.c index 4bafa8d73..0285dc592 100644 --- 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 flags, } } -#endif /* FEAT_MBYTE */ #ifdef FEAT_CLIPBOARD /* @@ -301,12 +299,10 @@ clip_mch_request_selection(VimClipboard *cbd) 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 *cbd) } } -#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 *cbd) } if (str == NULL) { -#endif - -#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) +#if defined(WIN3264) + /* Try to get the clipboard in Unicode if it's not an empty string. */ + if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0) { - WCHAR *hMemWstr = (WCHAR *)GlobalLock(hMemW); + HGLOBAL 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 ((hMemW = GetClipboardData(CF_UNICODETEXT)) != NULL) { - if (metadata.ucslen > maxlen) - str_size = maxlen; + 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; + else + str_size = metadata.ucslen; + } else - str_size = metadata.ucslen; - } - else - { - for (str_size = 0; str_size < maxlen; ++str_size) - if (hMemWstr[str_size] == NUL) - break; + { + 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); } - 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) + /* Get the clipboard in the Active codepage. */ + if (IsClipboardFormatAvailable(CF_TEXT)) { - 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 ((hMem = GetClipboardData(CF_TEXT)) != NULL) { - if (metadata.txtlen > maxlen) - str_size = maxlen; + 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 - 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; + { + 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 } -# endif } } -#ifdef FEAT_MBYTE - } -#endif if (str != NULL && *str != NUL) { @@ -460,12 +451,10 @@ clip_mch_request_selection(VimClipboard *cbd) /* 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]". |