Mercurial > vim
comparison src/winclip.c @ 18816:15539899a112 v8.1.2396
patch 8.1.2396: using old C style comments
Commit: https://github.com/vim/vim/commit/e38eab22c1fb950127f0307a9904de6d4561dc70
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 5 21:50:01 2019 +0100
patch 8.1.2396: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 05 Dec 2019 22:00:04 +0100 |
parents | 3147c7c2e86b |
children | 1e78bf92f168 |
comparison
equal
deleted
inserted
replaced
18815:404220424246 | 18816:15539899a112 |
---|---|
59 int l; | 59 int l; |
60 int ch; | 60 int ch; |
61 | 61 |
62 while (todo > 0) | 62 while (todo > 0) |
63 { | 63 { |
64 /* Only convert if we have a complete sequence. */ | 64 // Only convert if we have a complete sequence. |
65 l = utf_ptr2len_len(p, todo); | 65 l = utf_ptr2len_len(p, todo); |
66 if (l > todo) | 66 if (l > todo) |
67 { | 67 { |
68 /* Return length of incomplete sequence. */ | 68 // Return length of incomplete sequence. |
69 if (unconvlenp != NULL) | 69 if (unconvlenp != NULL) |
70 *unconvlenp = todo; | 70 *unconvlenp = todo; |
71 break; | 71 break; |
72 } | 72 } |
73 | 73 |
74 ch = utf_ptr2char(p); | 74 ch = utf_ptr2char(p); |
75 if (ch >= 0x10000) | 75 if (ch >= 0x10000) |
76 { | 76 { |
77 /* non-BMP character, encoding with surrogate pairs */ | 77 // non-BMP character, encoding with surrogate pairs |
78 ++outlen; | 78 ++outlen; |
79 if (outstr != NULL) | 79 if (outstr != NULL) |
80 { | 80 { |
81 *outstr++ = (0xD800 - (0x10000 >> 10)) + (ch >> 10); | 81 *outstr++ = (0xD800 - (0x10000 >> 10)) + (ch >> 10); |
82 *outstr++ = 0xDC00 | (ch & 0x3FF); | 82 *outstr++ = 0xDC00 | (ch & 0x3FF); |
111 while (todo > 0) | 111 while (todo > 0) |
112 { | 112 { |
113 ch = *p; | 113 ch = *p; |
114 if (ch >= 0xD800 && ch <= 0xDBFF && todo > 1) | 114 if (ch >= 0xD800 && ch <= 0xDBFF && todo > 1) |
115 { | 115 { |
116 /* surrogate pairs handling */ | 116 // surrogate pairs handling |
117 ch2 = p[1]; | 117 ch2 = p[1]; |
118 if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) | 118 if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) |
119 { | 119 { |
120 ch = ((ch - 0xD800) << 10) + (ch2 & 0x3FF) + 0x10000; | 120 ch = ((ch - 0xD800) << 10) + (ch2 & 0x3FF) + 0x10000; |
121 ++p; | 121 ++p; |
146 MultiByteToWideChar_alloc(UINT cp, DWORD flags, | 146 MultiByteToWideChar_alloc(UINT cp, DWORD flags, |
147 LPCSTR in, int inlen, | 147 LPCSTR in, int inlen, |
148 LPWSTR *out, int *outlen) | 148 LPWSTR *out, int *outlen) |
149 { | 149 { |
150 *outlen = MultiByteToWideChar(cp, flags, in, inlen, 0, 0); | 150 *outlen = MultiByteToWideChar(cp, flags, in, inlen, 0, 0); |
151 /* Add one one word to avoid a zero-length alloc(). */ | 151 // Add one one word to avoid a zero-length alloc(). |
152 *out = ALLOC_MULT(WCHAR, *outlen + 1); | 152 *out = ALLOC_MULT(WCHAR, *outlen + 1); |
153 if (*out != NULL) | 153 if (*out != NULL) |
154 { | 154 { |
155 MultiByteToWideChar(cp, flags, in, inlen, *out, *outlen); | 155 MultiByteToWideChar(cp, flags, in, inlen, *out, *outlen); |
156 (*out)[*outlen] = 0; | 156 (*out)[*outlen] = 0; |
166 LPCWSTR in, int inlen, | 166 LPCWSTR in, int inlen, |
167 LPSTR *out, int *outlen, | 167 LPSTR *out, int *outlen, |
168 LPCSTR def, LPBOOL useddef) | 168 LPCSTR def, LPBOOL useddef) |
169 { | 169 { |
170 *outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef); | 170 *outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef); |
171 /* Add one one byte to avoid a zero-length alloc(). */ | 171 // Add one one byte to avoid a zero-length alloc(). |
172 *out = alloc(*outlen + 1); | 172 *out = alloc(*outlen + 1); |
173 if (*out != NULL) | 173 if (*out != NULL) |
174 { | 174 { |
175 WideCharToMultiByte(cp, flags, in, inlen, *out, *outlen, def, useddef); | 175 WideCharToMultiByte(cp, flags, in, inlen, *out, *outlen, def, useddef); |
176 (*out)[*outlen] = 0; | 176 (*out)[*outlen] = 0; |
196 */ | 196 */ |
197 clip_star.format = RegisterClipboardFormat("VimClipboard2"); | 197 clip_star.format = RegisterClipboardFormat("VimClipboard2"); |
198 clip_star.format_raw = RegisterClipboardFormat("VimRawBytes"); | 198 clip_star.format_raw = RegisterClipboardFormat("VimRawBytes"); |
199 } | 199 } |
200 | 200 |
201 /* Type used for the clipboard type of Vim's data. */ | 201 // Type used for the clipboard type of Vim's data. |
202 typedef struct | 202 typedef struct |
203 { | 203 { |
204 int type; /* MCHAR, MBLOCK or MLINE */ | 204 int type; // MCHAR, MBLOCK or MLINE |
205 int txtlen; /* length of CF_TEXT in bytes */ | 205 int txtlen; // length of CF_TEXT in bytes |
206 int ucslen; /* length of CF_UNICODETEXT in words */ | 206 int ucslen; // length of CF_UNICODETEXT in words |
207 int rawlen; /* length of clip_star.format_raw, including encoding, | 207 int rawlen; // length of clip_star.format_raw, including encoding, |
208 excluding terminating NUL */ | 208 // excluding terminating NUL |
209 } VimClipType_t; | 209 } VimClipType_t; |
210 | 210 |
211 /* | 211 /* |
212 * Make vim the owner of the current selection. Return OK upon success. | 212 * Make vim the owner of the current selection. Return OK upon success. |
213 */ | 213 */ |
225 * Make vim NOT the owner of the current selection. | 225 * Make vim NOT the owner of the current selection. |
226 */ | 226 */ |
227 void | 227 void |
228 clip_mch_lose_selection(Clipboard_T *cbd UNUSED) | 228 clip_mch_lose_selection(Clipboard_T *cbd UNUSED) |
229 { | 229 { |
230 /* Nothing needs to be done here */ | 230 // Nothing needs to be done here |
231 } | 231 } |
232 | 232 |
233 /* | 233 /* |
234 * Copy "str[*size]" into allocated memory, changing CR-NL to NL. | 234 * Copy "str[*size]" into allocated memory, changing CR-NL to NL. |
235 * Return the allocated result and the size in "*size". | 235 * Return the allocated result and the size in "*size". |
241 int pos = 0; | 241 int pos = 0; |
242 int str_len = *size; | 242 int str_len = *size; |
243 char_u *ret; | 243 char_u *ret; |
244 char_u *retp; | 244 char_u *retp; |
245 | 245 |
246 /* Avoid allocating zero bytes, it generates an error message. */ | 246 // Avoid allocating zero bytes, it generates an error message. |
247 ret = alloc(str_len == 0 ? 1 : str_len); | 247 ret = alloc(str_len == 0 ? 1 : str_len); |
248 if (ret != NULL) | 248 if (ret != NULL) |
249 { | 249 { |
250 retp = ret; | 250 retp = ret; |
251 for (pos = 0; pos < str_len; ++pos) | 251 for (pos = 0; pos < str_len; ++pos) |
272 int delay = 10; | 272 int delay = 10; |
273 | 273 |
274 while (!OpenClipboard(NULL)) | 274 while (!OpenClipboard(NULL)) |
275 { | 275 { |
276 if (delay > 500) | 276 if (delay > 500) |
277 return FALSE; /* waited too long, give up */ | 277 return FALSE; // waited too long, give up |
278 Sleep(delay); | 278 Sleep(delay); |
279 delay *= 2; /* wait for 10, 20, 40, 80, etc. msec */ | 279 delay *= 2; // wait for 10, 20, 40, 80, etc. msec |
280 } | 280 } |
281 return TRUE; | 281 return TRUE; |
282 } | 282 } |
283 | 283 |
284 /* | 284 /* |
309 * then we can't paste back into the same window for some reason - webb. | 309 * then we can't paste back into the same window for some reason - webb. |
310 */ | 310 */ |
311 if (!vim_open_clipboard()) | 311 if (!vim_open_clipboard()) |
312 return; | 312 return; |
313 | 313 |
314 /* Check for vim's own clipboard format first. This only gets the type of | 314 // Check for vim's own clipboard format first. This only gets the type of |
315 * the data, still need to use CF_UNICODETEXT or CF_TEXT for the text. */ | 315 // the data, still need to use CF_UNICODETEXT or CF_TEXT for the text. |
316 if (IsClipboardFormatAvailable(cbd->format)) | 316 if (IsClipboardFormatAvailable(cbd->format)) |
317 { | 317 { |
318 VimClipType_t *meta_p; | 318 VimClipType_t *meta_p; |
319 HGLOBAL meta_h; | 319 HGLOBAL meta_h; |
320 | 320 |
321 /* We have metadata on the clipboard; try to get it. */ | 321 // We have metadata on the clipboard; try to get it. |
322 if ((meta_h = GetClipboardData(cbd->format)) != NULL | 322 if ((meta_h = GetClipboardData(cbd->format)) != NULL |
323 && (meta_p = (VimClipType_t *)GlobalLock(meta_h)) != NULL) | 323 && (meta_p = (VimClipType_t *)GlobalLock(meta_h)) != NULL) |
324 { | 324 { |
325 /* The size of "VimClipType_t" changed, "rawlen" was added later. | 325 // The size of "VimClipType_t" changed, "rawlen" was added later. |
326 * Only copy what is available for backwards compatibility. */ | 326 // Only copy what is available for backwards compatibility. |
327 n = sizeof(VimClipType_t); | 327 n = sizeof(VimClipType_t); |
328 if (GlobalSize(meta_h) < n) | 328 if (GlobalSize(meta_h) < n) |
329 n = GlobalSize(meta_h); | 329 n = GlobalSize(meta_h); |
330 memcpy(&metadata, meta_p, n); | 330 memcpy(&metadata, meta_p, n); |
331 GlobalUnlock(meta_h); | 331 GlobalUnlock(meta_h); |
332 } | 332 } |
333 } | 333 } |
334 | 334 |
335 /* Check for Vim's raw clipboard format first. This is used without | 335 // Check for Vim's raw clipboard format first. This is used without |
336 * conversion, but only if 'encoding' matches. */ | 336 // conversion, but only if 'encoding' matches. |
337 if (IsClipboardFormatAvailable(cbd->format_raw) | 337 if (IsClipboardFormatAvailable(cbd->format_raw) |
338 && metadata.rawlen > (int)STRLEN(p_enc)) | 338 && metadata.rawlen > (int)STRLEN(p_enc)) |
339 { | 339 { |
340 /* We have raw data on the clipboard; try to get it. */ | 340 // We have raw data on the clipboard; try to get it. |
341 if ((rawh = GetClipboardData(cbd->format_raw)) != NULL) | 341 if ((rawh = GetClipboardData(cbd->format_raw)) != NULL) |
342 { | 342 { |
343 char_u *rawp; | 343 char_u *rawp; |
344 | 344 |
345 rawp = (char_u *)GlobalLock(rawh); | 345 rawp = (char_u *)GlobalLock(rawh); |
356 } | 356 } |
357 } | 357 } |
358 } | 358 } |
359 if (str == NULL) | 359 if (str == NULL) |
360 { | 360 { |
361 /* Try to get the clipboard in Unicode if it's not an empty string. */ | 361 // Try to get the clipboard in Unicode if it's not an empty string. |
362 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0) | 362 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0) |
363 { | 363 { |
364 HGLOBAL hMemW; | 364 HGLOBAL hMemW; |
365 | 365 |
366 if ((hMemW = GetClipboardData(CF_UNICODETEXT)) != NULL) | 366 if ((hMemW = GetClipboardData(CF_UNICODETEXT)) != NULL) |
367 { | 367 { |
368 WCHAR *hMemWstr = (WCHAR *)GlobalLock(hMemW); | 368 WCHAR *hMemWstr = (WCHAR *)GlobalLock(hMemW); |
369 | 369 |
370 /* Use the length of our metadata if possible, but limit it to | 370 // Use the length of our metadata if possible, but limit it to |
371 * the GlobalSize() for safety. */ | 371 // the GlobalSize() for safety. |
372 maxlen = (int)(GlobalSize(hMemW) / sizeof(WCHAR)); | 372 maxlen = (int)(GlobalSize(hMemW) / sizeof(WCHAR)); |
373 if (metadata.ucslen >= 0) | 373 if (metadata.ucslen >= 0) |
374 { | 374 { |
375 if (metadata.ucslen > maxlen) | 375 if (metadata.ucslen > maxlen) |
376 str_size = maxlen; | 376 str_size = maxlen; |
385 } | 385 } |
386 to_free = str = utf16_to_enc((short_u *)hMemWstr, &str_size); | 386 to_free = str = utf16_to_enc((short_u *)hMemWstr, &str_size); |
387 GlobalUnlock(hMemW); | 387 GlobalUnlock(hMemW); |
388 } | 388 } |
389 } | 389 } |
390 /* Get the clipboard in the Active codepage. */ | 390 // Get the clipboard in the Active codepage. |
391 else if (IsClipboardFormatAvailable(CF_TEXT)) | 391 else if (IsClipboardFormatAvailable(CF_TEXT)) |
392 { | 392 { |
393 if ((hMem = GetClipboardData(CF_TEXT)) != NULL) | 393 if ((hMem = GetClipboardData(CF_TEXT)) != NULL) |
394 { | 394 { |
395 str = (char_u *)GlobalLock(hMem); | 395 str = (char_u *)GlobalLock(hMem); |
396 | 396 |
397 /* The length is either what our metadata says or the strlen(). | 397 // The length is either what our metadata says or the strlen(). |
398 * But limit it to the GlobalSize() for safety. */ | 398 // But limit it to the GlobalSize() for safety. |
399 maxlen = (int)GlobalSize(hMem); | 399 maxlen = (int)GlobalSize(hMem); |
400 if (metadata.txtlen >= 0) | 400 if (metadata.txtlen >= 0) |
401 { | 401 { |
402 if (metadata.txtlen > maxlen) | 402 if (metadata.txtlen > maxlen) |
403 str_size = maxlen; | 403 str_size = maxlen; |
409 for (str_size = 0; str_size < maxlen; ++str_size) | 409 for (str_size = 0; str_size < maxlen; ++str_size) |
410 if (str[str_size] == NUL) | 410 if (str[str_size] == NUL) |
411 break; | 411 break; |
412 } | 412 } |
413 | 413 |
414 /* The text is in the active codepage. Convert to | 414 // The text is in the active codepage. Convert to |
415 * 'encoding', going through UTF-16. */ | 415 // 'encoding', going through UTF-16. |
416 acp_to_enc(str, str_size, &to_free, &maxlen); | 416 acp_to_enc(str, str_size, &to_free, &maxlen); |
417 if (to_free != NULL) | 417 if (to_free != NULL) |
418 { | 418 { |
419 str_size = maxlen; | 419 str_size = maxlen; |
420 str = to_free; | 420 str = to_free; |
425 | 425 |
426 if (str != NULL && *str != NUL) | 426 if (str != NULL && *str != NUL) |
427 { | 427 { |
428 char_u *temp_clipboard; | 428 char_u *temp_clipboard; |
429 | 429 |
430 /* If the type is not known detect it. */ | 430 // If the type is not known detect it. |
431 if (metadata.type == -1) | 431 if (metadata.type == -1) |
432 metadata.type = MAUTO; | 432 metadata.type = MAUTO; |
433 | 433 |
434 /* Translate <CR><NL> into <NL>. */ | 434 // Translate <CR><NL> into <NL>. |
435 temp_clipboard = crnl_to_nl(str, &str_size); | 435 temp_clipboard = crnl_to_nl(str, &str_size); |
436 if (temp_clipboard != NULL) | 436 if (temp_clipboard != NULL) |
437 { | 437 { |
438 clip_yank_selection(metadata.type, temp_clipboard, str_size, cbd); | 438 clip_yank_selection(metadata.type, temp_clipboard, str_size, cbd); |
439 vim_free(temp_clipboard); | 439 vim_free(temp_clipboard); |
440 } | 440 } |
441 } | 441 } |
442 | 442 |
443 /* unlock the global object */ | 443 // unlock the global object |
444 if (hMem != NULL) | 444 if (hMem != NULL) |
445 GlobalUnlock(hMem); | 445 GlobalUnlock(hMem); |
446 if (rawh != NULL) | 446 if (rawh != NULL) |
447 GlobalUnlock(rawh); | 447 GlobalUnlock(rawh); |
448 CloseClipboard(); | 448 CloseClipboard(); |
461 HGLOBAL hMemRaw = NULL; | 461 HGLOBAL hMemRaw = NULL; |
462 HGLOBAL hMem = NULL; | 462 HGLOBAL hMem = NULL; |
463 HGLOBAL hMemVim = NULL; | 463 HGLOBAL hMemVim = NULL; |
464 HGLOBAL hMemW = NULL; | 464 HGLOBAL hMemW = NULL; |
465 | 465 |
466 /* If the '*' register isn't already filled in, fill it in now */ | 466 // If the '*' register isn't already filled in, fill it in now |
467 cbd->owned = TRUE; | 467 cbd->owned = TRUE; |
468 clip_get_selection(cbd); | 468 clip_get_selection(cbd); |
469 cbd->owned = FALSE; | 469 cbd->owned = FALSE; |
470 | 470 |
471 /* Get the text to be put on the clipboard, with CR-LF. */ | 471 // Get the text to be put on the clipboard, with CR-LF. |
472 metadata.type = clip_convert_selection(&str, &txtlen, cbd); | 472 metadata.type = clip_convert_selection(&str, &txtlen, cbd); |
473 if (metadata.type < 0) | 473 if (metadata.type < 0) |
474 return; | 474 return; |
475 metadata.txtlen = (int)txtlen; | 475 metadata.txtlen = (int)txtlen; |
476 metadata.ucslen = 0; | 476 metadata.ucslen = 0; |
477 metadata.rawlen = 0; | 477 metadata.rawlen = 0; |
478 | 478 |
479 /* Always set the raw bytes: 'encoding', NUL and the text. This is used | 479 // Always set the raw bytes: 'encoding', NUL and the text. This is used |
480 * when copy/paste from/to Vim with the same 'encoding', so that illegal | 480 // when copy/paste from/to Vim with the same 'encoding', so that illegal |
481 * bytes can also be copied and no conversion is needed. */ | 481 // bytes can also be copied and no conversion is needed. |
482 { | 482 { |
483 LPSTR lpszMemRaw; | 483 LPSTR lpszMemRaw; |
484 | 484 |
485 metadata.rawlen = (int)(txtlen + STRLEN(p_enc) + 1); | 485 metadata.rawlen = (int)(txtlen + STRLEN(p_enc) + 1); |
486 hMemRaw = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, | 486 hMemRaw = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, |
498 | 498 |
499 { | 499 { |
500 WCHAR *out; | 500 WCHAR *out; |
501 int len = metadata.txtlen; | 501 int len = metadata.txtlen; |
502 | 502 |
503 /* Convert the text to UTF-16. This is put on the clipboard as | 503 // Convert the text to UTF-16. This is put on the clipboard as |
504 * CF_UNICODETEXT. */ | 504 // CF_UNICODETEXT. |
505 out = (WCHAR *)enc_to_utf16(str, &len); | 505 out = (WCHAR *)enc_to_utf16(str, &len); |
506 if (out != NULL) | 506 if (out != NULL) |
507 { | 507 { |
508 WCHAR *lpszMemW; | 508 WCHAR *lpszMemW; |
509 | 509 |
510 /* Convert the text for CF_TEXT to Active codepage. Otherwise it's | 510 // Convert the text for CF_TEXT to Active codepage. Otherwise it's |
511 * p_enc, which has no relation to the Active codepage. */ | 511 // p_enc, which has no relation to the Active codepage. |
512 metadata.txtlen = WideCharToMultiByte(GetACP(), 0, out, len, | 512 metadata.txtlen = WideCharToMultiByte(GetACP(), 0, out, len, |
513 NULL, 0, 0, 0); | 513 NULL, 0, 0, 0); |
514 vim_free(str); | 514 vim_free(str); |
515 str = alloc(metadata.txtlen == 0 ? 1 : metadata.txtlen); | 515 str = alloc(metadata.txtlen == 0 ? 1 : metadata.txtlen); |
516 if (str == NULL) | 516 if (str == NULL) |
517 { | 517 { |
518 vim_free(out); | 518 vim_free(out); |
519 return; /* out of memory */ | 519 return; // out of memory |
520 } | 520 } |
521 WideCharToMultiByte(GetACP(), 0, out, len, | 521 WideCharToMultiByte(GetACP(), 0, out, len, |
522 (LPSTR)str, metadata.txtlen, 0, 0); | 522 (LPSTR)str, metadata.txtlen, 0, 0); |
523 | 523 |
524 /* Allocate memory for the UTF-16 text, add one NUL word to | 524 // Allocate memory for the UTF-16 text, add one NUL word to |
525 * terminate the string. */ | 525 // terminate the string. |
526 hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, | 526 hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, |
527 (len + 1) * sizeof(WCHAR)); | 527 (len + 1) * sizeof(WCHAR)); |
528 lpszMemW = (WCHAR *)GlobalLock(hMemW); | 528 lpszMemW = (WCHAR *)GlobalLock(hMemW); |
529 if (lpszMemW != NULL) | 529 if (lpszMemW != NULL) |
530 { | 530 { |
535 vim_free(out); | 535 vim_free(out); |
536 metadata.ucslen = len; | 536 metadata.ucslen = len; |
537 } | 537 } |
538 } | 538 } |
539 | 539 |
540 /* Allocate memory for the text, add one NUL byte to terminate the string. | 540 // Allocate memory for the text, add one NUL byte to terminate the string. |
541 */ | |
542 hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, metadata.txtlen + 1); | 541 hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, metadata.txtlen + 1); |
543 { | 542 { |
544 LPSTR lpszMem = (LPSTR)GlobalLock(hMem); | 543 LPSTR lpszMem = (LPSTR)GlobalLock(hMem); |
545 | 544 |
546 if (lpszMem) | 545 if (lpszMem) |
548 vim_strncpy((char_u *)lpszMem, str, metadata.txtlen); | 547 vim_strncpy((char_u *)lpszMem, str, metadata.txtlen); |
549 GlobalUnlock(hMem); | 548 GlobalUnlock(hMem); |
550 } | 549 } |
551 } | 550 } |
552 | 551 |
553 /* Set up metadata: */ | 552 // Set up metadata: |
554 { | 553 { |
555 VimClipType_t *lpszMemVim = NULL; | 554 VimClipType_t *lpszMemVim = NULL; |
556 | 555 |
557 hMemVim = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, | 556 hMemVim = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, |
558 sizeof(VimClipType_t)); | 557 sizeof(VimClipType_t)); |
578 if (hMemW != NULL) | 577 if (hMemW != NULL) |
579 { | 578 { |
580 if (SetClipboardData(CF_UNICODETEXT, hMemW) != NULL) | 579 if (SetClipboardData(CF_UNICODETEXT, hMemW) != NULL) |
581 hMemW = NULL; | 580 hMemW = NULL; |
582 } | 581 } |
583 /* Always use CF_TEXT. On Win98 Notepad won't obtain the | 582 // Always use CF_TEXT. On Win98 Notepad won't obtain the |
584 * CF_UNICODETEXT text, only CF_TEXT. */ | 583 // CF_UNICODETEXT text, only CF_TEXT. |
585 SetClipboardData(CF_TEXT, hMem); | 584 SetClipboardData(CF_TEXT, hMem); |
586 hMem = 0; | 585 hMem = 0; |
587 } | 586 } |
588 CloseClipboard(); | 587 CloseClipboard(); |
589 } | 588 } |
590 | 589 |
591 vim_free(str); | 590 vim_free(str); |
592 /* Free any allocations we didn't give to the clipboard: */ | 591 // Free any allocations we didn't give to the clipboard: |
593 if (hMemRaw) | 592 if (hMemRaw) |
594 GlobalFree(hMemRaw); | 593 GlobalFree(hMemRaw); |
595 if (hMem) | 594 if (hMem) |
596 GlobalFree(hMem); | 595 GlobalFree(hMem); |
597 if (hMemW) | 596 if (hMemW) |
598 GlobalFree(hMemW); | 597 GlobalFree(hMemW); |
599 if (hMemVim) | 598 if (hMemVim) |
600 GlobalFree(hMemVim); | 599 GlobalFree(hMemVim); |
601 } | 600 } |
602 | 601 |
603 #endif /* FEAT_CLIPBOARD */ | 602 #endif // FEAT_CLIPBOARD |
604 | 603 |
605 /* | 604 /* |
606 * Note: the following two functions are only guaranteed to work when using | 605 * Note: the following two functions are only guaranteed to work when using |
607 * valid MS-Windows codepages or when iconv() is available. | 606 * valid MS-Windows codepages or when iconv() is available. |
608 */ | 607 */ |
629 lenp = &len_loc; | 628 lenp = &len_loc; |
630 } | 629 } |
631 | 630 |
632 if (enc_codepage > 0) | 631 if (enc_codepage > 0) |
633 { | 632 { |
634 /* We can do any CP### -> UTF-16 in one pass, and we can do it | 633 // We can do any CP### -> UTF-16 in one pass, and we can do it |
635 * without iconv() (convert_* may need iconv). */ | 634 // without iconv() (convert_* may need iconv). |
636 MultiByteToWideChar_alloc(enc_codepage, 0, (LPCSTR)str, *lenp, | 635 MultiByteToWideChar_alloc(enc_codepage, 0, (LPCSTR)str, *lenp, |
637 &ret, &length); | 636 &ret, &length); |
638 } | 637 } |
639 else | 638 else |
640 { | 639 { |
641 /* Use "latin1" by default, we might be called before we have p_enc | 640 // Use "latin1" by default, we might be called before we have p_enc |
642 * set up. Convert to utf-8 first, works better with iconv(). Does | 641 // set up. Convert to utf-8 first, works better with iconv(). Does |
643 * nothing if 'encoding' is "utf-8". */ | 642 // nothing if 'encoding' is "utf-8". |
644 conv.vc_type = CONV_NONE; | 643 conv.vc_type = CONV_NONE; |
645 if (convert_setup(&conv, p_enc ? p_enc : (char_u *)"latin1", | 644 if (convert_setup(&conv, p_enc ? p_enc : (char_u *)"latin1", |
646 (char_u *)"utf-8") == FAIL) | 645 (char_u *)"utf-8") == FAIL) |
647 return NULL; | 646 return NULL; |
648 if (conv.vc_type != CONV_NONE) | 647 if (conv.vc_type != CONV_NONE) |
689 lenp = &len_loc; | 688 lenp = &len_loc; |
690 } | 689 } |
691 | 690 |
692 if (enc_codepage > 0) | 691 if (enc_codepage > 0) |
693 { | 692 { |
694 /* We can do any UTF-16 -> CP### in one pass. */ | 693 // We can do any UTF-16 -> CP### in one pass. |
695 int length; | 694 int length; |
696 | 695 |
697 WideCharToMultiByte_alloc(enc_codepage, 0, str, *lenp, | 696 WideCharToMultiByte_alloc(enc_codepage, 0, str, *lenp, |
698 (LPSTR *)&enc_str, &length, 0, 0); | 697 (LPSTR *)&enc_str, &length, 0, 0); |
699 *lenp = length; | 698 *lenp = length; |
700 return enc_str; | 699 return enc_str; |
701 } | 700 } |
702 | 701 |
703 /* Avoid allocating zero bytes, it generates an error message. */ | 702 // Avoid allocating zero bytes, it generates an error message. |
704 utf8_str = alloc(utf16_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL)); | 703 utf8_str = alloc(utf16_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL)); |
705 if (utf8_str != NULL) | 704 if (utf8_str != NULL) |
706 { | 705 { |
707 *lenp = utf16_to_utf8(str, *lenp, utf8_str); | 706 *lenp = utf16_to_utf8(str, *lenp, utf8_str); |
708 | 707 |
709 /* We might be called before we have p_enc set up. */ | 708 // We might be called before we have p_enc set up. |
710 conv.vc_type = CONV_NONE; | 709 conv.vc_type = CONV_NONE; |
711 convert_setup(&conv, (char_u *)"utf-8", | 710 convert_setup(&conv, (char_u *)"utf-8", |
712 p_enc? p_enc: (char_u *)"latin1"); | 711 p_enc? p_enc: (char_u *)"latin1"); |
713 if (conv.vc_type == CONV_NONE) | 712 if (conv.vc_type == CONV_NONE) |
714 { | 713 { |
715 /* p_enc is utf-8, so we're done. */ | 714 // p_enc is utf-8, so we're done. |
716 enc_str = utf8_str; | 715 enc_str = utf8_str; |
717 } | 716 } |
718 else | 717 else |
719 { | 718 { |
720 enc_str = string_convert(&conv, utf8_str, lenp); | 719 enc_str = string_convert(&conv, utf8_str, lenp); |
744 | 743 |
745 MultiByteToWideChar_alloc(GetACP(), 0, (LPCSTR)str, str_size, | 744 MultiByteToWideChar_alloc(GetACP(), 0, (LPCSTR)str, str_size, |
746 &widestr, outlen); | 745 &widestr, outlen); |
747 if (widestr != NULL) | 746 if (widestr != NULL) |
748 { | 747 { |
749 ++*outlen; /* Include the 0 after the string */ | 748 ++*outlen; // Include the 0 after the string |
750 *out = utf16_to_enc((short_u *)widestr, outlen); | 749 *out = utf16_to_enc((short_u *)widestr, outlen); |
751 vim_free(widestr); | 750 vim_free(widestr); |
752 } | 751 } |
753 } | 752 } |
754 | 753 |