aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Innes1999-03-25 22:59:18 +0000
committerAndrew Innes1999-03-25 22:59:18 +0000
commit0ece9ef6bf6e757d7f3c4243ee1dc4c79e85be8c (patch)
tree171ec7194fa3dbc5b7ff734116278c8364aef8d3 /src
parenta7976df8196202f98fb8f040e3da91eab9d275ef (diff)
downloademacs-0ece9ef6bf6e757d7f3c4243ee1dc4c79e85be8c.tar.gz
emacs-0ece9ef6bf6e757d7f3c4243ee1dc4c79e85be8c.zip
(Fw32_set_clipboard_data): Take into account line
ends when calculating clipboard storage needed for non-ASCII text.
Diffstat (limited to 'src')
-rw-r--r--src/w32select.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/w32select.c b/src/w32select.c
index 115d323ddbc..cb506aefb42 100644
--- a/src/w32select.c
+++ b/src/w32select.c
@@ -99,10 +99,10 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_dat
99 BOOL ok = TRUE; 99 BOOL ok = TRUE;
100 HANDLE htext; 100 HANDLE htext;
101 int nbytes; 101 int nbytes;
102 int truelen; 102 int truelen, nlines = 0;
103 unsigned char *src; 103 unsigned char *src;
104 unsigned char *dst; 104 unsigned char *dst;
105 105
106 CHECK_STRING (string, 0); 106 CHECK_STRING (string, 0);
107 107
108 if (!NILP (frame)) 108 if (!NILP (frame))
@@ -112,6 +112,16 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_dat
112 112
113 nbytes = STRING_BYTES (XSTRING (string)) + 1; 113 nbytes = STRING_BYTES (XSTRING (string)) + 1;
114 src = XSTRING (string)->data; 114 src = XSTRING (string)->data;
115 dst = src;
116
117 /* We need to know how many lines there are, since we need CRLF line
118 termination for compatibility with other Windows Programs.
119 avoid using strchr because it recomputes the length every time */
120 while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL)
121 {
122 nlines++;
123 dst++;
124 }
115 125
116 { 126 {
117 /* Since we are now handling multilingual text, we must consider 127 /* Since we are now handling multilingual text, we must consider
@@ -134,14 +144,7 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_dat
134 standard CF_TEXT clipboard format uses CRLF line endings, 144 standard CF_TEXT clipboard format uses CRLF line endings,
135 while Emacs uses just LF internally). */ 145 while Emacs uses just LF internally). */
136 146
137 truelen = nbytes; 147 truelen = nbytes + nlines;
138 dst = src;
139 /* avoid using strchr because it recomputes the length everytime */
140 while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL)
141 {
142 truelen++;
143 dst++;
144 }
145 148
146 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL) 149 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL)
147 goto error; 150 goto error;
@@ -191,7 +194,7 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_dat
191 (Fcheck_coding_system (Vnext_selection_coding_system), &coding); 194 (Fcheck_coding_system (Vnext_selection_coding_system), &coding);
192 Vnext_selection_coding_system = Qnil; 195 Vnext_selection_coding_system = Qnil;
193 coding.mode |= CODING_MODE_LAST_BLOCK; 196 coding.mode |= CODING_MODE_LAST_BLOCK;
194 bufsize = encoding_buffer_size (&coding, nbytes); 197 bufsize = encoding_buffer_size (&coding, nbytes) + nlines;
195 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize)) == NULL) 198 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize)) == NULL)
196 goto error; 199 goto error;
197 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) 200 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL)