aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii1999-01-06 10:14:25 +0000
committerEli Zaretskii1999-01-06 10:14:25 +0000
commit0265f89f7c2bdc2159338d71785ccb995872fa54 (patch)
tree6b7ad94634719b96786aa6cdaec8abf6bf66803e /src
parent1787769bcc30584809916593e35412771f39043a (diff)
downloademacs-0265f89f7c2bdc2159338d71785ccb995872fa54.tar.gz
emacs-0265f89f7c2bdc2159338d71785ccb995872fa54.zip
(set_clipboard_data): Terminate the text with a null
character. Don't allow to put binary data into the clipboard. Return zero in case of success, 1 or 2 otherwise. (get_clipboard_data): Only bail out if the null character is in the last 32-byte chunk of clipboard data (Fw16_set_clipboard_data): Make ok and put_status be unsigned. If they save binary data, print a message in the echo area saying the text was not put into the clipboard.
Diffstat (limited to 'src')
-rw-r--r--src/w16select.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/src/w16select.c b/src/w16select.c
index 85cdd852c95..5f9ce1b64a7 100644
--- a/src/w16select.c
+++ b/src/w16select.c
@@ -224,7 +224,7 @@ free_xfer_buf ()
224 } 224 }
225} 225}
226 226
227/* Copy data into the clipboard, return non-zero if successfull. */ 227/* Copy data into the clipboard, return zero if successfull. */
228unsigned 228unsigned
229set_clipboard_data (Format, Data, Size, Raw) 229set_clipboard_data (Format, Data, Size, Raw)
230 unsigned Format; 230 unsigned Format;
@@ -243,7 +243,7 @@ set_clipboard_data (Format, Data, Size, Raw)
243 /* need to know final size after '\r' chars are inserted (the 243 /* need to know final size after '\r' chars are inserted (the
244 standard CF_OEMTEXT clipboard format uses CRLF line endings, 244 standard CF_OEMTEXT clipboard format uses CRLF line endings,
245 while Emacs uses just LF internally). */ 245 while Emacs uses just LF internally). */
246 truelen = Size; 246 truelen = Size + 1; /* +1 for the terminating null */
247 247
248 if (!Raw) 248 if (!Raw)
249 { 249 {
@@ -271,12 +271,20 @@ set_clipboard_data (Format, Data, Size, Raw)
271 _farsetsel (_dos_ds); 271 _farsetsel (_dos_ds);
272 while (Size--) 272 while (Size--)
273 { 273 {
274 /* Don't allow them to put binary data into the clipboard, since
275 it will cause yanked data to be truncated at the first null. */
276 if (*dp == '\0')
277 return 2;
274 if (*dp == '\n') 278 if (*dp == '\n')
275 _farnspokeb (buf_offset++, '\r'); 279 _farnspokeb (buf_offset++, '\r');
276 _farnspokeb (buf_offset++, *dp++); 280 _farnspokeb (buf_offset++, *dp++);
277 } 281 }
278 } 282 }
279 283
284 /* Terminate with a null, otherwise Windows does strange things when
285 the text size is an integral multiple of 32 bytes. */
286 _farnspokeb (buf_offset, *dp);
287
280 /* Calls Int 2Fh/AX=1703h with: 288 /* Calls Int 2Fh/AX=1703h with:
281 DX = WinOldAp-Supported Clipboard format 289 DX = WinOldAp-Supported Clipboard format
282 ES:BX = Pointer to data 290 ES:BX = Pointer to data
@@ -293,7 +301,8 @@ set_clipboard_data (Format, Data, Size, Raw)
293 301
294 free_xfer_buf (); 302 free_xfer_buf ();
295 303
296 return regs.x.ax; 304 /* Zero means success, otherwise (1 or 2) it's an error. */
305 return regs.x.ax > 0 ? 0 : 1;
297} 306}
298 307
299/* Return the size of the clipboard data of format FORMAT. */ 308/* Return the size of the clipboard data of format FORMAT. */
@@ -326,9 +335,12 @@ get_clipboard_data (Format, Data, Size, Raw)
326 int Raw; 335 int Raw;
327{ 336{
328 __dpmi_regs regs; 337 __dpmi_regs regs;
329 unsigned datalen = 0;
330 unsigned long xbuf_addr; 338 unsigned long xbuf_addr;
331 unsigned char *dp = Data; 339 unsigned char *dp = Data;
340 /* The last 32-byte aligned block of data. See commentary below. */
341 unsigned char *last_block = dp + ((Size & 0x1f)
342 ? (Size & 0x20)
343 : Size - 0x20);
332 344
333 if (Format != CF_OEMTEXT) 345 if (Format != CF_OEMTEXT)
334 return 0; 346 return 0;
@@ -364,21 +376,20 @@ get_clipboard_data (Format, Data, Size, Raw)
364 dp--; 376 dp--;
365 *dp++ = '\n'; 377 *dp++ = '\n';
366 xbuf_addr++; 378 xbuf_addr++;
379 last_block--; /* adjust the beginning of the last 32 bytes */
367 } 380 }
368 /* Windows reportedly rounds up the size of clipboard data 381 /* Windows reportedly rounds up the size of clipboard data
369 (passed in SIZE) to a multiple of 32. We therefore bail 382 (passed in SIZE) to a multiple of 32. We therefore bail
370 out when we see the first null character. */ 383 out when we see the first null character in the last 32-byte
371 else if (c == '\0') 384 block. */
372 { 385 else if (c == '\0' && dp > last_block)
373 datalen = dp - (unsigned char *)Data - 1; 386 break;
374 break;
375 }
376 } 387 }
377 } 388 }
378 389
379 free_xfer_buf (); 390 free_xfer_buf ();
380 391
381 return datalen; 392 return (unsigned) (dp - (unsigned char *)Data - 1);
382} 393}
383 394
384/* Close clipboard, return non-zero if successfull. */ 395/* Close clipboard, return non-zero if successfull. */
@@ -415,13 +426,15 @@ clipboard_compact (Size)
415 426
416static char no_mem_msg[] = 427static char no_mem_msg[] =
417 "(Not enough DOS memory to put saved text into clipboard.)"; 428 "(Not enough DOS memory to put saved text into clipboard.)";
429static char binary_msg[] =
430 "(Binary characters in saved text; clipboard data not set.)";
418 431
419DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_data, 1, 2, 0, 432DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_data, 1, 2, 0,
420 "This sets the clipboard data to the given text.") 433 "This sets the clipboard data to the given text.")
421 (string, frame) 434 (string, frame)
422 Lisp_Object string, frame; 435 Lisp_Object string, frame;
423{ 436{
424 int ok = 1, ok1 = 1; 437 unsigned ok = 1, put_status = 0;
425 int nbytes; 438 int nbytes;
426 unsigned char *src, *dst = NULL; 439 unsigned char *src, *dst = NULL;
427 int charsets[MAX_CHARSET + 1]; 440 int charsets[MAX_CHARSET + 1];
@@ -482,7 +495,9 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
482 goto error; 495 goto error;
483 496
484 ok = empty_clipboard () 497 ok = empty_clipboard ()
485 && (ok1 = set_clipboard_data (CF_OEMTEXT, src, nbytes, no_crlf_conversion)); 498 && ((put_status
499 = set_clipboard_data (CF_OEMTEXT, src, nbytes, no_crlf_conversion))
500 == 0);
486 501
487 if (!no_crlf_conversion) 502 if (!no_crlf_conversion)
488 Vlast_coding_system_used = Qraw_text; 503 Vlast_coding_system_used = Qraw_text;
@@ -504,15 +519,23 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
504 depending on user system configuration.) If we just silently 519 depending on user system configuration.) If we just silently
505 fail the function, people might wonder why their text sometimes 520 fail the function, people might wonder why their text sometimes
506 doesn't make it to the clipboard. */ 521 doesn't make it to the clipboard. */
507 if (ok1 == 0) 522 if (put_status)
508 { 523 {
509 message2 (no_mem_msg, sizeof (no_mem_msg) - 1, 0); 524 switch (put_status)
525 {
526 case 1:
527 message2 (no_mem_msg, sizeof (no_mem_msg) - 1, 0);
528 break;
529 case 2:
530 message2 (binary_msg, sizeof (binary_msg) - 1, 0);
531 break;
532 }
510 sit_for (2, 0, 0, 1, 1); 533 sit_for (2, 0, 0, 1, 1);
511 } 534 }
512 535
513 done: 536 done:
514 537
515 return (ok ? string : Qnil); 538 return (ok && put_status == 0 ? string : Qnil);
516} 539}
517 540
518DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_data, 0, 1, 0, 541DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_data, 0, 1, 0,