Mercurial > emacs
comparison src/w32select.c @ 23835:ad04307ef465
(Fw32_get_clipboard_data): Do not delete isolated CR
characters, only convert CRLF to LF.
author | Geoff Voelker <voelker@cs.washington.edu> |
---|---|
date | Wed, 09 Dec 1998 00:03:09 +0000 |
parents | 5f3243813b18 |
children | 122a362c5024 |
comparison
equal
deleted
inserted
replaced
23834:ce563c147515 | 23835:ad04307ef465 |
---|---|
128 | 128 |
129 if (!num || (num == 1 && charsets[CHARSET_ASCII])) | 129 if (!num || (num == 1 && charsets[CHARSET_ASCII])) |
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; |
139 /* avoid using strchr because it recomputes the length everytime */ | 139 /* avoid using strchr because it recomputes the length everytime */ |
140 while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL) | 140 while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL) |
247 { | 247 { |
248 unsigned char *src; | 248 unsigned char *src; |
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; |
256 | 256 |
257 nbytes = strlen (src); | 257 nbytes = strlen (src); |
262 #else | 262 #else |
263 ! NILP (buffer_defaults.enable_multibyte_characters) | 263 ! NILP (buffer_defaults.enable_multibyte_characters) |
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 |
271 for (i = 0; i < nbytes; i++) | 271 for (i = 0; i < nbytes; i++) |
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; |
285 struct coding_system coding; | 285 struct coding_system coding; |
286 | 286 |
300 ret = make_string_from_bytes ((char *) buf, truelen, coding.produced); | 300 ret = make_string_from_bytes ((char *) buf, truelen, coding.produced); |
301 xfree (buf); | 301 xfree (buf); |
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) |
325 { | 327 { |
326 unsigned char *next; | 328 unsigned char *next; |
329 if (next) | 331 if (next) |
330 { | 332 { |
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; |
340 } | 344 } |
341 | 345 |