aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii1999-02-04 15:53:37 +0000
committerEli Zaretskii1999-02-04 15:53:37 +0000
commit5033894e975e0eee9fc18aab79ab3887291d6428 (patch)
tree4686d0664e041d24e23dcfb296c31a7d8340be71
parentfc9b48d7f3ce4e0075863450f3d3358642277d20 (diff)
downloademacs-5033894e975e0eee9fc18aab79ab3887291d6428.tar.gz
emacs-5033894e975e0eee9fc18aab79ab3887291d6428.zip
(last_clipboard_text, clipboard_storage_size): New
static variables. (set_clipboard_data): Save a copy of the text we put into clipboard in last_clipboard_text. (get_clipboard_data): If the clipboard text is identical to what last_clipboard_text holds, pretend there's no data in the clipboard.
-rw-r--r--src/w16select.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/w16select.c b/src/w16select.c
index a6491a18dcc..68e958fa427 100644
--- a/src/w16select.c
+++ b/src/w16select.c
@@ -77,11 +77,21 @@ static Lisp_Object Vnext_selection_coding_system;
77 77
78/* The segment address and the size of the buffer in low 78/* The segment address and the size of the buffer in low
79 memory used to move data between us and WinOldAp module. */ 79 memory used to move data between us and WinOldAp module. */
80
81static struct { 80static struct {
82 unsigned long size; 81 unsigned long size;
83 unsigned short rm_segment; 82 unsigned short rm_segment;
84} clipboard_xfer_buf_info; 83} clipboard_xfer_buf_info;
84
85/* The last text we put into the clipboard. This is used to prevent
86 passing back our own text from the clipboard, instead of using the
87 kill ring. The former is undesirable because the clipboard data
88 could be MULEtilated by inappropriately chosen
89 (next-)selection-coding-system. For this reason, we must store the
90 text *after* it was encoded/Unix-to-DOS-converted. */
91static unsigned char *last_clipboard_text;
92
93/* The size of allocated storage for storing the clipboard data. */
94static size_t clipboard_storage_size;
85 95
86/* Emulation of `__dpmi_int' and friends for DJGPP v1.x */ 96/* Emulation of `__dpmi_int' and friends for DJGPP v1.x */
87 97
@@ -291,6 +301,18 @@ set_clipboard_data (Format, Data, Size, Raw)
291 _farnspokeb (buf_offset, '\0'); 301 _farnspokeb (buf_offset, '\0');
292 } 302 }
293 303
304 /* Stash away the data we are about to put into the clipboard, so we
305 could later check inside get_clipboard_data whether the clipboard
306 still holds our data. */
307 if (clipboard_storage_size < truelen)
308 {
309 clipboard_storage_size = truelen + 100;
310 last_clipboard_text =
311 (char *) xrealloc (last_clipboard_text, clipboard_storage_size);
312 }
313 if (last_clipboard_text)
314 dosmemget (xbuf_addr, truelen, last_clipboard_text);
315
294 /* Calls Int 2Fh/AX=1703h with: 316 /* Calls Int 2Fh/AX=1703h with:
295 DX = WinOldAp-Supported Clipboard format 317 DX = WinOldAp-Supported Clipboard format
296 ES:BX = Pointer to data 318 ES:BX = Pointer to data
@@ -307,6 +329,10 @@ set_clipboard_data (Format, Data, Size, Raw)
307 329
308 free_xfer_buf (); 330 free_xfer_buf ();
309 331
332 /* If the above failed, invalidate the local copy of the clipboard. */
333 if (regs.x.ax == 0)
334 *last_clipboard_text = '\0';
335
310 /* Zero means success, otherwise (1 or 2) it's an error. */ 336 /* Zero means success, otherwise (1 or 2) it's an error. */
311 return regs.x.ax > 0 ? 0 : 1; 337 return regs.x.ax > 0 ? 0 : 1;
312} 338}
@@ -370,6 +396,14 @@ get_clipboard_data (Format, Data, Size, Raw)
370 __dpmi_int(0x2f, &regs); 396 __dpmi_int(0x2f, &regs);
371 if (regs.x.ax != 0) 397 if (regs.x.ax != 0)
372 { 398 {
399 unsigned char null_char = '\0';
400 unsigned long xbuf_beg = xbuf_addr;
401
402 /* If last_clipboard_text is NULL, we don't want to slow down
403 the next loop by an additional test. */
404 register unsigned char *lcdp =
405 last_clipboard_text == NULL ? &null_char : last_clipboard_text;
406
373 /* Copy data from low memory, remove CR 407 /* Copy data from low memory, remove CR
374 characters before LF if needed. */ 408 characters before LF if needed. */
375 _farsetsel (_dos_ds); 409 _farsetsel (_dos_ds);
@@ -377,12 +411,17 @@ get_clipboard_data (Format, Data, Size, Raw)
377 { 411 {
378 register unsigned char c = _farnspeekb (xbuf_addr++); 412 register unsigned char c = _farnspeekb (xbuf_addr++);
379 413
414 if (*lcdp == c)
415 lcdp++;
416
380 if ((*dp++ = c) == '\r' && !Raw && _farnspeekb (xbuf_addr) == '\n') 417 if ((*dp++ = c) == '\r' && !Raw && _farnspeekb (xbuf_addr) == '\n')
381 { 418 {
382 dp--; 419 dp--;
383 *dp++ = '\n'; 420 *dp++ = '\n';
384 xbuf_addr++; 421 xbuf_addr++;
385 last_block--; /* adjust the beginning of the last 32 bytes */ 422 last_block--; /* adjust the beginning of the last 32 bytes */
423 if (*lcdp == '\n')
424 lcdp++;
386 } 425 }
387 /* Windows reportedly rounds up the size of clipboard data 426 /* Windows reportedly rounds up the size of clipboard data
388 (passed in SIZE) to a multiple of 32. We therefore bail 427 (passed in SIZE) to a multiple of 32. We therefore bail
@@ -391,6 +430,14 @@ get_clipboard_data (Format, Data, Size, Raw)
391 else if (c == '\0' && dp > last_block) 430 else if (c == '\0' && dp > last_block)
392 break; 431 break;
393 } 432 }
433
434 /* If the text in clipboard is identical to what we put there
435 last time set_clipboard_data was called, pretend there's no
436 data in the clipboard. This is so we don't pass our own text
437 from the clipboard. */
438 if (last_clipboard_text &&
439 xbuf_addr - xbuf_beg == (long)(lcdp - last_clipboard_text))
440 dp = (unsigned char *)Data + 1;
394 } 441 }
395 442
396 free_xfer_buf (); 443 free_xfer_buf ();