Unified · Split
| @@ -594,7 +594,7 @@ char* · 593 unmodified lines | ||
| 594 | 594 | clipread(void) |
| 595 | 595 | { |
| 596 | 596 | HANDLE h; |
| 597 | − char *p; | |
| 597 | + char *p, *q, *r; | |
| 598 | 598 | |
| 599 | 599 | if(!OpenClipboard(window)){ |
| 600 | 600 | oserror(); |
| @@ -609,18 +609,50 @@ clipread(void) · 8 unmodified lines | ||
| 609 | 609 | oserror(); |
| 610 | 610 | return strdup(""); |
| 611 | 611 | } |
| 612 | + | |
| 613 | + for(q = r = p; *q != 0; q++) | |
| 614 | + if(*q != '\r') | |
| 615 | + *r++ = *q; | |
| 616 | + *r = 0; | |
| 612 | 617 | |
| 613 | 618 | CloseClipboard(); |
| 614 | 619 | return p; |
| 615 | 620 | } |
| 616 | 621 | |
| 622 | +static char * | |
| 623 | +addcr(char *buf, int *lp) | |
| 624 | +{ | |
| 625 | + int nlen; | |
| 626 | + char *r, *p, *q; | |
| 627 | + | |
| 628 | + nlen = 0; | |
| 629 | + for(p = buf; *p != 0; p++){ | |
| 630 | + if(*p == '\n') | |
| 631 | + nlen++; | |
| 632 | + nlen++; | |
| 633 | + } | |
| 634 | + *lp = nlen; | |
| 635 | + r = malloc(nlen + 1); | |
| 636 | + if(r == nil) | |
| 637 | + panic("malloc: %r"); | |
| 638 | + q = r; | |
| 639 | + for(p = buf; *p != 0; p++){ | |
| 640 | + if(*p == '\n') | |
| 641 | + *q++ = '\r'; | |
| 642 | + *q++ = *p; | |
| 643 | + } | |
| 644 | + *q = 0; | |
| 645 | + return r; | |
| 646 | +} | |
| 647 | + | |
| 617 | 648 | int |
| 618 | 649 | clipwrite(char *buf) |
| 619 | 650 | { |
| 620 | 651 | HANDLE h; |
| 621 | 652 | char *p; |
| 622 | 653 | Rune16 *rp; |
| 623 | − int n = strlen(buf); | |
| 654 | + char *crbuf; | |
| 655 | + int n; | |
| 624 | 656 | |
| 625 | 657 | if(!OpenClipboard(window)) { |
| 626 | 658 | oserror(); |
| @@ -633,11 +665,13 @@ clipwrite(char *buf) · 6 unmodified lines | ||
| 633 | 665 | return -1; |
| 634 | 666 | } |
| 635 | 667 | |
| 668 | + crbuf = addcr(buf, &n); | |
| 669 | + | |
| 636 | 670 | h = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, (n+1)*sizeof(Rune)); |
| 637 | 671 | if(h == NULL) |
| 638 | 672 | panic("out of memory"); |
| 639 | 673 | rp = GlobalLock(h); |
| 640 | − utftorunes16(rp, buf, n+1); | |
| 674 | + utftorunes16(rp, crbuf, n+1); | |
| 641 | 675 | GlobalUnlock(h); |
| 642 | 676 | |
| 643 | 677 | SetClipboardData(CF_UNICODETEXT, h); |
| @@ -646,13 +680,14 @@ clipwrite(char *buf) · 2 unmodified lines | ||
| 646 | 680 | if(h == NULL) |
| 647 | 681 | panic("out of memory"); |
| 648 | 682 | p = GlobalLock(h); |
| 649 | − memcpy(p, buf, n); | |
| 683 | + memcpy(p, crbuf, n); | |
| 650 | 684 | p[n] = 0; |
| 651 | 685 | GlobalUnlock(h); |
| 652 | 686 | |
| 653 | 687 | SetClipboardData(CF_TEXT, h); |
| 654 | 688 | |
| 655 | 689 | CloseClipboard(); |
| 690 | + free(crbuf); | |
| 656 | 691 | return n; |
| 657 | 692 | } |
| 658 | 693 | |