Mercurial > vim
annotate src/winclip.c @ 36081:f36c3455e686 v9.1.0709
patch 9.1.0709: GUIEnter event not found in Turkish locale
Commit: https://github.com/vim/vim/commit/84e3175c4e70486b52e15cc6c40095fa311c1107
Author: Christian Brabandt <cb@256bit.org>
Date: Mon Sep 2 09:59:18 2024 +0200
patch 9.1.0709: GUIEnter event not found in Turkish locale
Problem: GUIEnter not found in Turkish locale
(James McCoy, after v9.1.0256, the issue was there before,
but v9.1.0256 made it more apparent)
Solution: explicitly compare autocommand events by ASCII value and
ignoring locale, because according to the documentation,
events are case insensitive (:h autocommand-events)
fixes: #15574
closes: #15603
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 02 Sep 2024 10:15:03 +0200 |
parents | 1009c33499e7 |
children |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
8140
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
4168 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * winclip.c | |
12 * | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
13 * Routines for Win32 clipboard handling. |
4168 | 14 * Also used by Cygwin, using os_unix.c. |
15 */ | |
16 | |
17 #include "vim.h" | |
18 | |
19 /* | |
20 * Compile only the clipboard handling features when compiling for cygwin | |
21 * posix environment. | |
22 */ | |
23 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD | |
24 # define WIN32_LEAN_AND_MEAN | |
25 # include <windows.h> | |
26 # include "winclip.pro" | |
27 #endif | |
28 | |
29 /* | |
30 * When generating prototypes for Win32 on Unix, these lines make the syntax | |
31 * errors disappear. They do not need to be correct. | |
32 */ | |
33 #ifdef PROTO | |
34 #define WINAPI | |
35 #define WINBASEAPI | |
36 typedef int DWORD; | |
37 typedef int LPBOOL; | |
38 typedef int LPCSTR; | |
39 typedef int LPCWSTR; | |
40 typedef int LPSTR; | |
41 typedef int LPWSTR; | |
42 typedef int UINT; | |
43 #endif | |
44 | |
45 /* | |
46 * Convert an UTF-8 string to UTF-16. | |
47 * "instr[inlen]" is the input. "inlen" is in bytes. | |
48 * When "outstr" is NULL only return the number of UTF-16 words produced. | |
49 * Otherwise "outstr" must be a buffer of sufficient size. | |
50 * Returns the number of UTF-16 words produced. | |
51 */ | |
52 int | |
53 utf8_to_utf16(char_u *instr, int inlen, short_u *outstr, int *unconvlenp) | |
54 { | |
55 int outlen = 0; | |
56 char_u *p = instr; | |
57 int todo = inlen; | |
58 int l; | |
59 int ch; | |
60 | |
61 while (todo > 0) | |
62 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
63 // Only convert if we have a complete sequence. |
4168 | 64 l = utf_ptr2len_len(p, todo); |
65 if (l > todo) | |
66 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
67 // Return length of incomplete sequence. |
4168 | 68 if (unconvlenp != NULL) |
69 *unconvlenp = todo; | |
70 break; | |
71 } | |
72 | |
73 ch = utf_ptr2char(p); | |
74 if (ch >= 0x10000) | |
75 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
76 // non-BMP character, encoding with surrogate pairs |
4168 | 77 ++outlen; |
78 if (outstr != NULL) | |
79 { | |
80 *outstr++ = (0xD800 - (0x10000 >> 10)) + (ch >> 10); | |
81 *outstr++ = 0xDC00 | (ch & 0x3FF); | |
82 } | |
83 } | |
84 else if (outstr != NULL) | |
85 *outstr++ = ch; | |
86 ++outlen; | |
87 p += l; | |
88 todo -= l; | |
89 } | |
90 | |
91 return outlen; | |
92 } | |
93 | |
94 /* | |
95 * Convert an UTF-16 string to UTF-8. | |
96 * The input is "instr[inlen]" with "inlen" in number of UTF-16 words. | |
97 * When "outstr" is NULL only return the required number of bytes. | |
98 * Otherwise "outstr" must be a buffer of sufficient size. | |
99 * Return the number of bytes produced. | |
100 */ | |
101 int | |
102 utf16_to_utf8(short_u *instr, int inlen, char_u *outstr) | |
103 { | |
104 int outlen = 0; | |
105 int todo = inlen; | |
106 short_u *p = instr; | |
107 int l; | |
108 int ch, ch2; | |
109 | |
110 while (todo > 0) | |
111 { | |
112 ch = *p; | |
113 if (ch >= 0xD800 && ch <= 0xDBFF && todo > 1) | |
114 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
115 // surrogate pairs handling |
4168 | 116 ch2 = p[1]; |
117 if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) | |
118 { | |
119 ch = ((ch - 0xD800) << 10) + (ch2 & 0x3FF) + 0x10000; | |
120 ++p; | |
121 --todo; | |
122 } | |
123 } | |
124 if (outstr != NULL) | |
125 { | |
126 l = utf_char2bytes(ch, outstr); | |
127 outstr += l; | |
128 } | |
129 else | |
130 l = utf_char2len(ch); | |
131 ++p; | |
132 outlen += l; | |
133 --todo; | |
134 } | |
135 | |
136 return outlen; | |
137 } | |
138 | |
139 /* | |
140 * Call MultiByteToWideChar() and allocate memory for the result. | |
141 * Returns the result in "*out[*outlen]" with an extra zero appended. | |
142 * "outlen" is in words. | |
143 */ | |
144 void | |
145 MultiByteToWideChar_alloc(UINT cp, DWORD flags, | |
146 LPCSTR in, int inlen, | |
147 LPWSTR *out, int *outlen) | |
148 { | |
149 *outlen = MultiByteToWideChar(cp, flags, in, inlen, 0, 0); | |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
20976
diff
changeset
|
150 // Add one word to avoid a zero-length alloc(). |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
151 *out = ALLOC_MULT(WCHAR, *outlen + 1); |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
152 if (*out == NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
153 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
154 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
155 MultiByteToWideChar(cp, flags, in, inlen, *out, *outlen); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
156 (*out)[*outlen] = 0; |
4168 | 157 } |
158 | |
159 /* | |
160 * Call WideCharToMultiByte() and allocate memory for the result. | |
161 * Returns the result in "*out[*outlen]" with an extra NUL appended. | |
162 */ | |
163 void | |
164 WideCharToMultiByte_alloc(UINT cp, DWORD flags, | |
165 LPCWSTR in, int inlen, | |
166 LPSTR *out, int *outlen, | |
167 LPCSTR def, LPBOOL useddef) | |
168 { | |
169 *outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef); | |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
20976
diff
changeset
|
170 // Add one byte to avoid a zero-length alloc(). |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
171 *out = alloc(*outlen + 1); |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
172 if (*out == NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
173 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
174 WideCharToMultiByte(cp, flags, in, inlen, *out, *outlen, def, useddef); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
175 (*out)[*outlen] = 0; |
4168 | 176 } |
177 | |
178 | |
179 #ifdef FEAT_CLIPBOARD | |
180 /* | |
181 * Clipboard stuff, for cutting and pasting text to other windows. | |
182 */ | |
183 | |
184 void | |
185 win_clip_init(void) | |
186 { | |
187 clip_init(TRUE); | |
188 | |
189 /* | |
190 * Vim's own clipboard format recognises whether the text is char, line, | |
191 * or rectangular block. Only useful for copying between two Vims. | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
192 * "Clipboard_T" was used for previous versions, using the first |
4168 | 193 * character to specify MCHAR, MLINE or MBLOCK. |
194 */ | |
195 clip_star.format = RegisterClipboardFormat("VimClipboard2"); | |
196 clip_star.format_raw = RegisterClipboardFormat("VimRawBytes"); | |
197 } | |
198 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
199 // Type used for the clipboard type of Vim's data. |
4168 | 200 typedef struct |
201 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
202 int type; // MCHAR, MBLOCK or MLINE |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
203 int txtlen; // length of CF_TEXT in bytes |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
204 int ucslen; // length of CF_UNICODETEXT in words |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
205 int rawlen; // length of clip_star.format_raw, including encoding, |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
206 // excluding terminating NUL |
4168 | 207 } VimClipType_t; |
208 | |
209 /* | |
210 * Make vim the owner of the current selection. Return OK upon success. | |
211 */ | |
212 int | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
213 clip_mch_own_selection(Clipboard_T *cbd UNUSED) |
4168 | 214 { |
215 /* | |
216 * Never actually own the clipboard. If another application sets the | |
217 * clipboard, we don't want to think that we still own it. | |
218 */ | |
219 return FAIL; | |
220 } | |
221 | |
222 /* | |
223 * Make vim NOT the owner of the current selection. | |
224 */ | |
225 void | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
226 clip_mch_lose_selection(Clipboard_T *cbd UNUSED) |
4168 | 227 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
228 // Nothing needs to be done here |
4168 | 229 } |
230 | |
231 /* | |
232 * Copy "str[*size]" into allocated memory, changing CR-NL to NL. | |
233 * Return the allocated result and the size in "*size". | |
234 * Returns NULL when out of memory. | |
235 */ | |
236 static char_u * | |
237 crnl_to_nl(const char_u *str, int *size) | |
238 { | |
239 int pos = 0; | |
240 int str_len = *size; | |
241 char_u *ret; | |
242 char_u *retp; | |
243 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
244 // Avoid allocating zero bytes, it generates an error message. |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
245 ret = alloc(str_len == 0 ? 1 : str_len); |
4168 | 246 if (ret != NULL) |
247 { | |
248 retp = ret; | |
249 for (pos = 0; pos < str_len; ++pos) | |
250 { | |
251 if (str[pos] == '\r' && str[pos + 1] == '\n') | |
252 { | |
253 ++pos; | |
254 --(*size); | |
255 } | |
256 *retp++ = str[pos]; | |
257 } | |
258 } | |
259 | |
260 return ret; | |
261 } | |
262 | |
263 /* | |
264 * Wait for another process to Close the Clipboard. | |
265 * Returns TRUE for success. | |
266 */ | |
267 static int | |
268 vim_open_clipboard(void) | |
269 { | |
270 int delay = 10; | |
271 | |
272 while (!OpenClipboard(NULL)) | |
273 { | |
274 if (delay > 500) | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
275 return FALSE; // waited too long, give up |
4168 | 276 Sleep(delay); |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
277 delay *= 2; // wait for 10, 20, 40, 80, etc. msec |
4168 | 278 } |
279 return TRUE; | |
280 } | |
281 | |
282 /* | |
283 * Get the current selection and put it in the clipboard register. | |
284 * | |
285 * NOTE: Must use GlobalLock/Unlock here to ensure Win32s compatibility. | |
286 * On NT/W95 the clipboard data is a fixed global memory object and | |
287 * so its handle = its pointer. | |
288 * On Win32s, however, co-operation with the Win16 system means that | |
289 * the clipboard data is moveable and its handle is not a pointer at all, | |
290 * so we can't just cast the return value of GetClipboardData to (char_u*). | |
291 * <VN> | |
292 */ | |
293 void | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
294 clip_mch_request_selection(Clipboard_T *cbd) |
4168 | 295 { |
296 VimClipType_t metadata = { -1, -1, -1, -1 }; | |
297 HGLOBAL hMem = NULL; | |
298 char_u *str = NULL; | |
299 char_u *to_free = NULL; | |
300 HGLOBAL rawh = NULL; | |
301 int str_size = 0; | |
302 int maxlen; | |
303 size_t n; | |
304 | |
305 /* | |
306 * Don't pass GetActiveWindow() as an argument to OpenClipboard() because | |
307 * then we can't paste back into the same window for some reason - webb. | |
308 */ | |
309 if (!vim_open_clipboard()) | |
310 return; | |
311 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
312 // Check for vim's own clipboard format first. This only gets the type of |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
313 // the data, still need to use CF_UNICODETEXT or CF_TEXT for the text. |
4168 | 314 if (IsClipboardFormatAvailable(cbd->format)) |
315 { | |
316 VimClipType_t *meta_p; | |
317 HGLOBAL meta_h; | |
318 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
319 // We have metadata on the clipboard; try to get it. |
4168 | 320 if ((meta_h = GetClipboardData(cbd->format)) != NULL |
321 && (meta_p = (VimClipType_t *)GlobalLock(meta_h)) != NULL) | |
322 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
323 // The size of "VimClipType_t" changed, "rawlen" was added later. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
324 // Only copy what is available for backwards compatibility. |
4168 | 325 n = sizeof(VimClipType_t); |
326 if (GlobalSize(meta_h) < n) | |
327 n = GlobalSize(meta_h); | |
328 memcpy(&metadata, meta_p, n); | |
329 GlobalUnlock(meta_h); | |
330 } | |
331 } | |
332 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
333 // Check for Vim's raw clipboard format first. This is used without |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
334 // conversion, but only if 'encoding' matches. |
4168 | 335 if (IsClipboardFormatAvailable(cbd->format_raw) |
336 && metadata.rawlen > (int)STRLEN(p_enc)) | |
337 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
338 // We have raw data on the clipboard; try to get it. |
4168 | 339 if ((rawh = GetClipboardData(cbd->format_raw)) != NULL) |
340 { | |
341 char_u *rawp; | |
342 | |
343 rawp = (char_u *)GlobalLock(rawh); | |
344 if (rawp != NULL && STRCMP(p_enc, rawp) == 0) | |
345 { | |
346 n = STRLEN(p_enc) + 1; | |
347 str = rawp + n; | |
348 str_size = (int)(metadata.rawlen - n); | |
349 } | |
350 else | |
351 { | |
352 GlobalUnlock(rawh); | |
353 rawh = NULL; | |
354 } | |
355 } | |
356 } | |
357 if (str == NULL) | |
358 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
359 // Try to get the clipboard in Unicode if it's not an empty string. |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
360 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
361 { |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
362 HGLOBAL hMemW; |
4168 | 363 |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
364 if ((hMemW = GetClipboardData(CF_UNICODETEXT)) != NULL) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
365 { |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
366 WCHAR *hMemWstr = (WCHAR *)GlobalLock(hMemW); |
4168 | 367 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
368 // Use the length of our metadata if possible, but limit it to |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
369 // the GlobalSize() for safety. |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
370 maxlen = (int)(GlobalSize(hMemW) / sizeof(WCHAR)); |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
371 if (metadata.ucslen >= 0) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
372 { |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
373 if (metadata.ucslen > maxlen) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
374 str_size = maxlen; |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
375 else |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
376 str_size = metadata.ucslen; |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
377 } |
4168 | 378 else |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
379 { |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
380 for (str_size = 0; str_size < maxlen; ++str_size) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
381 if (hMemWstr[str_size] == NUL) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
382 break; |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
383 } |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
384 to_free = str = utf16_to_enc((short_u *)hMemWstr, &str_size); |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
385 GlobalUnlock(hMemW); |
4168 | 386 } |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
387 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
388 // Get the clipboard in the Active codepage. |
15957
209f65bb155f
patch 8.1.0984: unnecessary #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
389 else if (IsClipboardFormatAvailable(CF_TEXT)) |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
390 { |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
391 if ((hMem = GetClipboardData(CF_TEXT)) != NULL) |
4168 | 392 { |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
393 str = (char_u *)GlobalLock(hMem); |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
394 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
395 // The length is either what our metadata says or the strlen(). |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
396 // But limit it to the GlobalSize() for safety. |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
397 maxlen = (int)GlobalSize(hMem); |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
398 if (metadata.txtlen >= 0) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
399 { |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
400 if (metadata.txtlen > maxlen) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
401 str_size = maxlen; |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
402 else |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
403 str_size = metadata.txtlen; |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
404 } |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
405 else |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
406 { |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
407 for (str_size = 0; str_size < maxlen; ++str_size) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
408 if (str[str_size] == NUL) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
409 break; |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
410 } |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
411 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
412 // The text is in the active codepage. Convert to |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
413 // 'encoding', going through UTF-16. |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
414 acp_to_enc(str, str_size, &to_free, &maxlen); |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
415 if (to_free != NULL) |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
416 { |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
417 str_size = maxlen; |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
418 str = to_free; |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
10783
diff
changeset
|
419 } |
4168 | 420 } |
421 } | |
422 } | |
423 | |
20976
599b29b6e540
patch 8.2.1039: cannot put NUL byte on clipboard
Bram Moolenaar <Bram@vim.org>
parents:
19380
diff
changeset
|
424 if (str != NULL && metadata.txtlen != 0) |
4168 | 425 { |
426 char_u *temp_clipboard; | |
427 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
428 // If the type is not known detect it. |
4168 | 429 if (metadata.type == -1) |
430 metadata.type = MAUTO; | |
431 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
432 // Translate <CR><NL> into <NL>. |
4168 | 433 temp_clipboard = crnl_to_nl(str, &str_size); |
434 if (temp_clipboard != NULL) | |
435 { | |
436 clip_yank_selection(metadata.type, temp_clipboard, str_size, cbd); | |
437 vim_free(temp_clipboard); | |
438 } | |
439 } | |
440 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
441 // unlock the global object |
4168 | 442 if (hMem != NULL) |
443 GlobalUnlock(hMem); | |
444 if (rawh != NULL) | |
445 GlobalUnlock(rawh); | |
446 CloseClipboard(); | |
447 vim_free(to_free); | |
448 } | |
449 | |
450 /* | |
451 * Send the current selection to the clipboard. | |
452 */ | |
453 void | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
454 clip_mch_set_selection(Clipboard_T *cbd) |
4168 | 455 { |
456 char_u *str = NULL; | |
457 VimClipType_t metadata; | |
458 long_u txtlen; | |
459 HGLOBAL hMemRaw = NULL; | |
460 HGLOBAL hMem = NULL; | |
461 HGLOBAL hMemVim = NULL; | |
462 HGLOBAL hMemW = NULL; | |
463 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
464 // If the '*' register isn't already filled in, fill it in now |
4168 | 465 cbd->owned = TRUE; |
466 clip_get_selection(cbd); | |
467 cbd->owned = FALSE; | |
468 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
469 // Get the text to be put on the clipboard, with CR-LF. |
4168 | 470 metadata.type = clip_convert_selection(&str, &txtlen, cbd); |
471 if (metadata.type < 0) | |
472 return; | |
473 metadata.txtlen = (int)txtlen; | |
474 metadata.ucslen = 0; | |
475 metadata.rawlen = 0; | |
476 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
477 // Always set the raw bytes: 'encoding', NUL and the text. This is used |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
478 // when copy/paste from/to Vim with the same 'encoding', so that illegal |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
479 // bytes can also be copied and no conversion is needed. |
4168 | 480 { |
481 LPSTR lpszMemRaw; | |
482 | |
483 metadata.rawlen = (int)(txtlen + STRLEN(p_enc) + 1); | |
484 hMemRaw = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, | |
485 metadata.rawlen + 1); | |
486 lpszMemRaw = (LPSTR)GlobalLock(hMemRaw); | |
487 if (lpszMemRaw != NULL) | |
488 { | |
489 STRCPY(lpszMemRaw, p_enc); | |
490 memcpy(lpszMemRaw + STRLEN(p_enc) + 1, str, txtlen + 1); | |
491 GlobalUnlock(hMemRaw); | |
492 } | |
493 else | |
494 metadata.rawlen = 0; | |
495 } | |
496 | |
497 { | |
498 WCHAR *out; | |
499 int len = metadata.txtlen; | |
500 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
501 // Convert the text to UTF-16. This is put on the clipboard as |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
502 // CF_UNICODETEXT. |
4168 | 503 out = (WCHAR *)enc_to_utf16(str, &len); |
504 if (out != NULL) | |
505 { | |
506 WCHAR *lpszMemW; | |
507 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
508 // Convert the text for CF_TEXT to Active codepage. Otherwise it's |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
509 // p_enc, which has no relation to the Active codepage. |
4168 | 510 metadata.txtlen = WideCharToMultiByte(GetACP(), 0, out, len, |
511 NULL, 0, 0, 0); | |
512 vim_free(str); | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
513 str = alloc(metadata.txtlen == 0 ? 1 : metadata.txtlen); |
4168 | 514 if (str == NULL) |
515 { | |
516 vim_free(out); | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
517 return; // out of memory |
4168 | 518 } |
519 WideCharToMultiByte(GetACP(), 0, out, len, | |
5082
7b20dc804164
updated for version 7.3.1284
Bram Moolenaar <bram@vim.org>
parents:
4168
diff
changeset
|
520 (LPSTR)str, metadata.txtlen, 0, 0); |
4168 | 521 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
522 // Allocate memory for the UTF-16 text, add one NUL word to |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
523 // terminate the string. |
4168 | 524 hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, |
525 (len + 1) * sizeof(WCHAR)); | |
526 lpszMemW = (WCHAR *)GlobalLock(hMemW); | |
527 if (lpszMemW != NULL) | |
528 { | |
529 memcpy(lpszMemW, out, len * sizeof(WCHAR)); | |
530 lpszMemW[len] = NUL; | |
531 GlobalUnlock(hMemW); | |
532 } | |
533 vim_free(out); | |
534 metadata.ucslen = len; | |
535 } | |
536 } | |
537 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
538 // Allocate memory for the text, add one NUL byte to terminate the string. |
4168 | 539 hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, metadata.txtlen + 1); |
540 { | |
541 LPSTR lpszMem = (LPSTR)GlobalLock(hMem); | |
542 | |
543 if (lpszMem) | |
544 { | |
20976
599b29b6e540
patch 8.2.1039: cannot put NUL byte on clipboard
Bram Moolenaar <Bram@vim.org>
parents:
19380
diff
changeset
|
545 mch_memmove((char_u *)lpszMem, str, metadata.txtlen); |
4168 | 546 GlobalUnlock(hMem); |
547 } | |
548 } | |
549 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
550 // Set up metadata: |
4168 | 551 { |
552 VimClipType_t *lpszMemVim = NULL; | |
553 | |
554 hMemVim = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, | |
555 sizeof(VimClipType_t)); | |
556 lpszMemVim = (VimClipType_t *)GlobalLock(hMemVim); | |
557 memcpy(lpszMemVim, &metadata, sizeof(metadata)); | |
558 GlobalUnlock(hMemVim); | |
559 } | |
560 | |
561 /* | |
562 * Open the clipboard, clear it and put our text on it. | |
563 * Always set our Vim format. Put Unicode and plain text on it. | |
564 * | |
565 * Don't pass GetActiveWindow() as an argument to OpenClipboard() | |
566 * because then we can't paste back into the same window for some | |
567 * reason - webb. | |
568 */ | |
569 if (vim_open_clipboard()) | |
570 { | |
571 if (EmptyClipboard()) | |
572 { | |
573 SetClipboardData(cbd->format, hMemVim); | |
574 hMemVim = 0; | |
575 if (hMemW != NULL) | |
576 { | |
577 if (SetClipboardData(CF_UNICODETEXT, hMemW) != NULL) | |
578 hMemW = NULL; | |
579 } | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
580 // Always use CF_TEXT. On Win98 Notepad won't obtain the |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
581 // CF_UNICODETEXT text, only CF_TEXT. |
4168 | 582 SetClipboardData(CF_TEXT, hMem); |
583 hMem = 0; | |
584 } | |
585 CloseClipboard(); | |
586 } | |
587 | |
588 vim_free(str); | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
589 // Free any allocations we didn't give to the clipboard: |
4168 | 590 if (hMemRaw) |
591 GlobalFree(hMemRaw); | |
592 if (hMem) | |
593 GlobalFree(hMem); | |
594 if (hMemW) | |
595 GlobalFree(hMemW); | |
596 if (hMemVim) | |
597 GlobalFree(hMemVim); | |
598 } | |
599 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
600 #endif // FEAT_CLIPBOARD |
4168 | 601 |
602 /* | |
603 * Note: the following two functions are only guaranteed to work when using | |
604 * valid MS-Windows codepages or when iconv() is available. | |
605 */ | |
606 | |
607 /* | |
608 * Convert "str" from 'encoding' to UTF-16. | |
609 * Input in "str" with length "*lenp". When "lenp" is NULL, use strlen(). | |
610 * Output is returned as an allocated string. "*lenp" is set to the length of | |
611 * the result. A trailing NUL is always added. | |
612 * Returns NULL when out of memory. | |
613 */ | |
614 short_u * | |
615 enc_to_utf16(char_u *str, int *lenp) | |
616 { | |
617 vimconv_T conv; | |
618 WCHAR *ret; | |
619 char_u *allocbuf = NULL; | |
620 int len_loc; | |
621 int length; | |
622 | |
623 if (lenp == NULL) | |
624 { | |
625 len_loc = (int)STRLEN(str) + 1; | |
626 lenp = &len_loc; | |
627 } | |
628 | |
629 if (enc_codepage > 0) | |
630 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
631 // We can do any CP### -> UTF-16 in one pass, and we can do it |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
632 // without iconv() (convert_* may need iconv). |
5082
7b20dc804164
updated for version 7.3.1284
Bram Moolenaar <bram@vim.org>
parents:
4168
diff
changeset
|
633 MultiByteToWideChar_alloc(enc_codepage, 0, (LPCSTR)str, *lenp, |
7b20dc804164
updated for version 7.3.1284
Bram Moolenaar <bram@vim.org>
parents:
4168
diff
changeset
|
634 &ret, &length); |
4168 | 635 } |
636 else | |
637 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
638 // Use "latin1" by default, we might be called before we have p_enc |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
639 // set up. Convert to utf-8 first, works better with iconv(). Does |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
640 // nothing if 'encoding' is "utf-8". |
4168 | 641 conv.vc_type = CONV_NONE; |
642 if (convert_setup(&conv, p_enc ? p_enc : (char_u *)"latin1", | |
643 (char_u *)"utf-8") == FAIL) | |
644 return NULL; | |
645 if (conv.vc_type != CONV_NONE) | |
646 { | |
647 str = allocbuf = string_convert(&conv, str, lenp); | |
648 if (str == NULL) | |
649 return NULL; | |
650 } | |
651 convert_setup(&conv, NULL, NULL); | |
652 | |
653 length = utf8_to_utf16(str, *lenp, NULL, NULL); | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
654 ret = ALLOC_MULT(WCHAR, length + 1); |
4168 | 655 if (ret != NULL) |
656 { | |
657 utf8_to_utf16(str, *lenp, (short_u *)ret, NULL); | |
658 ret[length] = 0; | |
659 } | |
660 | |
661 vim_free(allocbuf); | |
662 } | |
663 | |
664 *lenp = length; | |
665 return (short_u *)ret; | |
666 } | |
667 | |
668 /* | |
669 * Convert an UTF-16 string to 'encoding'. | |
670 * Input in "str" with length (counted in wide characters) "*lenp". When | |
671 * "lenp" is NULL, use wcslen(). | |
672 * Output is returned as an allocated string. If "*lenp" is not NULL it is | |
673 * set to the length of the result. | |
674 * Returns NULL when out of memory. | |
675 */ | |
676 char_u * | |
677 utf16_to_enc(short_u *str, int *lenp) | |
678 { | |
679 vimconv_T conv; | |
680 char_u *utf8_str = NULL, *enc_str = NULL; | |
681 int len_loc; | |
682 | |
683 if (lenp == NULL) | |
684 { | |
685 len_loc = (int)wcslen(str) + 1; | |
686 lenp = &len_loc; | |
687 } | |
688 | |
689 if (enc_codepage > 0) | |
690 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
691 // We can do any UTF-16 -> CP### in one pass. |
4168 | 692 int length; |
693 | |
694 WideCharToMultiByte_alloc(enc_codepage, 0, str, *lenp, | |
695 (LPSTR *)&enc_str, &length, 0, 0); | |
696 *lenp = length; | |
697 return enc_str; | |
698 } | |
699 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
700 // Avoid allocating zero bytes, it generates an error message. |
4168 | 701 utf8_str = alloc(utf16_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL)); |
702 if (utf8_str != NULL) | |
703 { | |
704 *lenp = utf16_to_utf8(str, *lenp, utf8_str); | |
705 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
706 // We might be called before we have p_enc set up. |
4168 | 707 conv.vc_type = CONV_NONE; |
708 convert_setup(&conv, (char_u *)"utf-8", | |
709 p_enc? p_enc: (char_u *)"latin1"); | |
710 if (conv.vc_type == CONV_NONE) | |
711 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
712 // p_enc is utf-8, so we're done. |
4168 | 713 enc_str = utf8_str; |
714 } | |
715 else | |
716 { | |
717 enc_str = string_convert(&conv, utf8_str, lenp); | |
718 vim_free(utf8_str); | |
719 } | |
720 | |
721 convert_setup(&conv, NULL, NULL); | |
722 } | |
723 | |
724 return enc_str; | |
725 } | |
726 | |
727 /* | |
728 * Convert from the active codepage to 'encoding'. | |
729 * Input is "str[str_size]". | |
31140
a52697bcffa6
patch 9.0.0904: various comment and indent flaws
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
730 * The result is in allocated memory: "out[outlen]". "outlen" includes the |
a52697bcffa6
patch 9.0.0904: various comment and indent flaws
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
731 * terminating NUL. |
4168 | 732 */ |
733 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
5714
diff
changeset
|
734 acp_to_enc( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
5714
diff
changeset
|
735 char_u *str, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
5714
diff
changeset
|
736 int str_size, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
5714
diff
changeset
|
737 char_u **out, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
5714
diff
changeset
|
738 int *outlen) |
4168 | 739 |
740 { | |
741 LPWSTR widestr; | |
742 | |
5082
7b20dc804164
updated for version 7.3.1284
Bram Moolenaar <bram@vim.org>
parents:
4168
diff
changeset
|
743 MultiByteToWideChar_alloc(GetACP(), 0, (LPCSTR)str, str_size, |
7b20dc804164
updated for version 7.3.1284
Bram Moolenaar <bram@vim.org>
parents:
4168
diff
changeset
|
744 &widestr, outlen); |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
745 if (widestr == NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
746 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
747 ++*outlen; // Include the 0 after the string |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
748 *out = utf16_to_enc((short_u *)widestr, outlen); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
749 vim_free(widestr); |
4168 | 750 } |
5714 | 751 |
752 /* | |
753 * Convert from 'encoding' to the active codepage. | |
754 * Input is "str[str_size]". | |
755 * The result is in allocated memory: "out[outlen]". With terminating NUL. | |
756 */ | |
757 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
5714
diff
changeset
|
758 enc_to_acp( |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
5714
diff
changeset
|
759 char_u *str, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
5714
diff
changeset
|
760 int str_size, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
5714
diff
changeset
|
761 char_u **out, |
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
5714
diff
changeset
|
762 int *outlen) |
5714 | 763 |
764 { | |
765 LPWSTR widestr; | |
766 int len = str_size; | |
767 | |
768 widestr = (WCHAR *)enc_to_utf16(str, &len); | |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
769 if (widestr == NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
770 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
771 WideCharToMultiByte_alloc(GetACP(), 0, widestr, len, |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
772 (LPSTR *)out, outlen, 0, 0); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31140
diff
changeset
|
773 vim_free(widestr); |
5714 | 774 } |