summaryrefslogtreecommitdiff
path: root/src/w32select.c
diff options
context:
space:
mode:
authorGeoff Voelker <voelker@cs.washington.edu>1998-12-09 00:03:09 +0000
committerGeoff Voelker <voelker@cs.washington.edu>1998-12-09 00:03:09 +0000
commitc0ca703bd4183db7689bff4f0e36b1502c01c64f (patch)
treea4386a88745f686409f7be607e7c49d571f18a5b /src/w32select.c
parent9c148db6a38853b57318dbe25af8106394753c0e (diff)
downloademacs-c0ca703bd4183db7689bff4f0e36b1502c01c64f.tar.gz
(Fw32_get_clipboard_data): Do not delete isolated CR
characters, only convert CRLF to LF.
Diffstat (limited to 'src/w32select.c')
-rw-r--r--src/w32select.c32
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
{
/* No multibyte character in OBJ. We need not encode it. */
- /* need to know final size after '\r' chars are inserted (the
+ /* Need to know final size after CR chars are inserted (the
standard CF_TEXT clipboard format uses CRLF line endings,
- while Emacs uses just LF internally) */
+ while Emacs uses just LF internally). */
truelen = nbytes;
dst = src;
@@ -249,7 +249,7 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat
unsigned char *dst;
int nbytes;
int truelen;
- int require_encoding = 0;
+ int require_decoding = 0;
if ((src = (unsigned char *) GlobalLock (htext)) == NULL)
goto closeclip;
@@ -264,7 +264,7 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat
#endif
)
{
- /* If the clipboard data contains any 8-bit Latin-1 code, we
+ /* If the clipboard data contains any non-ascii code, we
need to decode it. */
int i;
@@ -272,13 +272,13 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat
{
if (src[i] >= 0x80)
{
- require_encoding = 1;
+ require_decoding = 1;
break;
}
}
}
- if (require_encoding)
+ if (require_decoding)
{
int bufsize;
unsigned char *buf;
@@ -302,23 +302,25 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat
}
else
{
- /* need to know final size after '\r' chars are removed because
- we can't change the string size manually, and doing an extra
- copy is silly */
+ /* Need to know final size after CR chars are removed because we
+ can't change the string size manually, and doing an extra
+ copy is silly. Note that we only remove CR when it appears
+ as part of CRLF. */
truelen = nbytes;
dst = src;
/* avoid using strchr because it recomputes the length everytime */
while ((dst = memchr (dst, '\r', nbytes - (dst - src))) != NULL)
{
- truelen--;
+ if (dst[1] == '\n') /* safe because of trailing '\0' */
+ truelen--;
dst++;
}
ret = make_uninit_string (truelen);
- /* convert CRLF line endings (the standard CF_TEXT clipboard
- format) to LF endings as used internally by Emacs */
+ /* Convert CRLF line endings (the standard CF_TEXT clipboard
+ format) to LF endings as used internally by Emacs. */
dst = XSTRING (ret)->data;
while (1)
@@ -331,9 +333,11 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat
/* copied one line ending with '\r' */
int copied = next - dst;
nbytes -= copied;
- dst += copied - 1; /* overwrite '\r' */
+ dst += copied;
src += copied;
- }
+ if (*src == '\n')
+ dst--; /* overwrite '\r' with '\n' */
+ }
else
/* copied remaining partial line -> now finished */
break;