diff options
| author | Geoff Voelker | 1998-12-09 00:03:09 +0000 |
|---|---|---|
| committer | Geoff Voelker | 1998-12-09 00:03:09 +0000 |
| commit | c0ca703bd4183db7689bff4f0e36b1502c01c64f (patch) | |
| tree | a4386a88745f686409f7be607e7c49d571f18a5b | |
| parent | 9c148db6a38853b57318dbe25af8106394753c0e (diff) | |
| download | emacs-c0ca703bd4183db7689bff4f0e36b1502c01c64f.tar.gz emacs-c0ca703bd4183db7689bff4f0e36b1502c01c64f.zip | |
(Fw32_get_clipboard_data): Do not delete isolated CR
characters, only convert CRLF to LF.
| -rw-r--r-- | src/w32select.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/w32select.c b/src/w32select.c index da01576ddf3..6579b0e152b 100644 --- a/src/w32select.c +++ b/src/w32select.c | |||
| @@ -130,9 +130,9 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_dat | |||
| 130 | { | 130 | { |
| 131 | /* No multibyte character in OBJ. We need not encode it. */ | 131 | /* No multibyte character in OBJ. We need not encode it. */ |
| 132 | 132 | ||
| 133 | /* need to know final size after '\r' chars are inserted (the | 133 | /* Need to know final size after CR chars are inserted (the |
| 134 | standard CF_TEXT clipboard format uses CRLF line endings, | 134 | standard CF_TEXT clipboard format uses CRLF line endings, |
| 135 | while Emacs uses just LF internally) */ | 135 | while Emacs uses just LF internally). */ |
| 136 | 136 | ||
| 137 | truelen = nbytes; | 137 | truelen = nbytes; |
| 138 | dst = src; | 138 | dst = src; |
| @@ -249,7 +249,7 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat | |||
| 249 | unsigned char *dst; | 249 | unsigned char *dst; |
| 250 | int nbytes; | 250 | int nbytes; |
| 251 | int truelen; | 251 | int truelen; |
| 252 | int require_encoding = 0; | 252 | int require_decoding = 0; |
| 253 | 253 | ||
| 254 | if ((src = (unsigned char *) GlobalLock (htext)) == NULL) | 254 | if ((src = (unsigned char *) GlobalLock (htext)) == NULL) |
| 255 | goto closeclip; | 255 | goto closeclip; |
| @@ -264,7 +264,7 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat | |||
| 264 | #endif | 264 | #endif |
| 265 | ) | 265 | ) |
| 266 | { | 266 | { |
| 267 | /* If the clipboard data contains any 8-bit Latin-1 code, we | 267 | /* If the clipboard data contains any non-ascii code, we |
| 268 | need to decode it. */ | 268 | need to decode it. */ |
| 269 | int i; | 269 | int i; |
| 270 | 270 | ||
| @@ -272,13 +272,13 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat | |||
| 272 | { | 272 | { |
| 273 | if (src[i] >= 0x80) | 273 | if (src[i] >= 0x80) |
| 274 | { | 274 | { |
| 275 | require_encoding = 1; | 275 | require_decoding = 1; |
| 276 | break; | 276 | break; |
| 277 | } | 277 | } |
| 278 | } | 278 | } |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | if (require_encoding) | 281 | if (require_decoding) |
| 282 | { | 282 | { |
| 283 | int bufsize; | 283 | int bufsize; |
| 284 | unsigned char *buf; | 284 | unsigned char *buf; |
| @@ -302,23 +302,25 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat | |||
| 302 | } | 302 | } |
| 303 | else | 303 | else |
| 304 | { | 304 | { |
| 305 | /* need to know final size after '\r' chars are removed because | 305 | /* Need to know final size after CR chars are removed because we |
| 306 | we can't change the string size manually, and doing an extra | 306 | can't change the string size manually, and doing an extra |
| 307 | copy is silly */ | 307 | copy is silly. Note that we only remove CR when it appears |
| 308 | as part of CRLF. */ | ||
| 308 | 309 | ||
| 309 | truelen = nbytes; | 310 | truelen = nbytes; |
| 310 | dst = src; | 311 | dst = src; |
| 311 | /* avoid using strchr because it recomputes the length everytime */ | 312 | /* avoid using strchr because it recomputes the length everytime */ |
| 312 | while ((dst = memchr (dst, '\r', nbytes - (dst - src))) != NULL) | 313 | while ((dst = memchr (dst, '\r', nbytes - (dst - src))) != NULL) |
| 313 | { | 314 | { |
| 314 | truelen--; | 315 | if (dst[1] == '\n') /* safe because of trailing '\0' */ |
| 316 | truelen--; | ||
| 315 | dst++; | 317 | dst++; |
| 316 | } | 318 | } |
| 317 | 319 | ||
| 318 | ret = make_uninit_string (truelen); | 320 | ret = make_uninit_string (truelen); |
| 319 | 321 | ||
| 320 | /* convert CRLF line endings (the standard CF_TEXT clipboard | 322 | /* Convert CRLF line endings (the standard CF_TEXT clipboard |
| 321 | format) to LF endings as used internally by Emacs */ | 323 | format) to LF endings as used internally by Emacs. */ |
| 322 | 324 | ||
| 323 | dst = XSTRING (ret)->data; | 325 | dst = XSTRING (ret)->data; |
| 324 | while (1) | 326 | while (1) |
| @@ -331,9 +333,11 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat | |||
| 331 | /* copied one line ending with '\r' */ | 333 | /* copied one line ending with '\r' */ |
| 332 | int copied = next - dst; | 334 | int copied = next - dst; |
| 333 | nbytes -= copied; | 335 | nbytes -= copied; |
| 334 | dst += copied - 1; /* overwrite '\r' */ | 336 | dst += copied; |
| 335 | src += copied; | 337 | src += copied; |
| 336 | } | 338 | if (*src == '\n') |
| 339 | dst--; /* overwrite '\r' with '\n' */ | ||
| 340 | } | ||
| 337 | else | 341 | else |
| 338 | /* copied remaining partial line -> now finished */ | 342 | /* copied remaining partial line -> now finished */ |
| 339 | break; | 343 | break; |