History

win32: convert clipboard to and from CR+LF

aiju committed 8 years ago

Commit 658bdec1 parent ee260881 file · +39 −4Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t