1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
|
diff -Naur xterm-200/VTPrsTbl.c xterm-200-new/VTPrsTbl.c
--- xterm-200/VTPrsTbl.c 2004-11-30 20:27:46.000000000 -0500
+++ xterm-200-new/VTPrsTbl.c 2005-04-05 22:35:40.000000000 -0400
@@ -399,6 +399,330 @@
CASE_PRINT,
};
+Const PARSE_T take_table[] = /* TAKE Base64 SELECTION DATA */
+{
+/* NUL SOH STX ETX */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* EOT ENQ ACK BEL */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* BS HT NL VT */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* NP CR SO SI */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* DLE DC1 DC2 DC3 */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* DC4 NAK SYN ETB */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* CAN EM SUB ESC */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* FS GS RS US */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* SP ! " # */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* $ % & ' */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* ( ) * + */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE,
+/* , - . / */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE,
+/* 0 1 2 3 */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* 4 5 6 7 */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* 8 9 : ; */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* < = > ? */
+CASE_TAKE_DONE,
+CASE_IGNORE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* @ A B C */
+CASE_TAKE_DONE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* D E F G */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* H I J K */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* L M N O */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* P Q R S */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* T U V W */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* X Y Z [ */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE_DONE,
+/* \ ] ^ _ */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* ` a b c */
+CASE_TAKE_DONE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* d e f g */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* h i j k */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* l m n o */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* p q r s */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* t u v w */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+/* x y z { */
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE,
+CASE_TAKE_DONE,
+/* | } ~ DEL */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* 0x80 0x81 0x82 0x83 */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* 0x84 0x85 0x86 0x87 */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* 0x88 0x89 0x8a 0x8b */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* 0x8c 0x8d 0x8e 0x8f */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* 0x90 0x91 0x92 0x93 */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* 0x94 0x95 0x96 0x97 */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* 0x98 0x99 0x9a 0x9b */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* 0x9c 0x9d 0x9e 0x9f */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* nobreakspace exclamdown cent sterling */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* currency yen brokenbar section */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* diaeresis copyright ordfeminine guillemotleft */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* notsign hyphen registered macron */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* degree plusminus twosuperior threesuperior */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* acute mu paragraph periodcentered */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* cedilla onesuperior masculine guillemotright */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* onequarter onehalf threequarters questiondown */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* Agrave Aacute Acircumflex Atilde */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* Adiaeresis Aring AE Ccedilla */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* Egrave Eacute Ecircumflex Ediaeresis */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* Igrave Iacute Icircumflex Idiaeresis */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* Eth Ntilde Ograve Oacute */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* Ocircumflex Otilde Odiaeresis multiply */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* Ooblique Ugrave Uacute Ucircumflex */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* Udiaeresis Yacute Thorn ssharp */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* agrave aacute acircumflex atilde */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* adiaeresis aring ae ccedilla */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* egrave eacute ecircumflex ediaeresis */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* igrave iacute icircumflex idiaeresis */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* eth ntilde ograve oacute */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* ocircumflex otilde odiaeresis division */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* oslash ugrave uacute ucircumflex */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+/* udiaeresis yacute thorn ydiaeresis */
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE,
+CASE_TAKE_DONE
+};
+
Const PARSE_T csi_table[] = /* CSI */
{
/* NUL SOH STX ETX */
@@ -877,7 +1201,7 @@
CASE_GROUND_STATE,
/* x y z { */
CASE_DECREQTPARM,
-CASE_GROUND_STATE,
+CASE_PASTE,
CASE_GROUND_STATE,
CASE_GROUND_STATE,
/* | } ~ DEL */
@@ -2774,7 +3098,7 @@
CASE_GROUND_STATE,
CASE_GROUND_STATE,
/* P Q R S */
-CASE_GROUND_STATE,
+CASE_PASTE,
CASE_GROUND_STATE,
CASE_GROUND_STATE,
CASE_GROUND_STATE,
diff -Naur xterm-200/VTparse.def xterm-200-new/VTparse.def
--- xterm-200/VTparse.def 2004-11-30 20:27:46.000000000 -0500
+++ xterm-200-new/VTparse.def 2005-04-05 22:29:16.000000000 -0400
@@ -140,3 +140,6 @@
CASE_DECCARA
CASE_DECRARA
CASE_CSI_STAR_STATE
+CASE_PASTE
+CASE_TAKE
+CASE_TAKE_DONE
diff -Naur xterm-200/VTparse.h xterm-200-new/VTparse.h
--- xterm-200/VTparse.h 2004-11-30 20:27:46.000000000 -0500
+++ xterm-200-new/VTparse.h 2005-04-06 11:52:19.000000000 -0400
@@ -82,6 +82,7 @@
extern Const PARSE_T scrtable[];
extern Const PARSE_T scstable[];
extern Const PARSE_T sos_table[];
+extern Const PARSE_T take_table[];
#if OPT_DEC_LOCATOR
extern Const PARSE_T csi_tick_table[];
@@ -244,5 +245,8 @@
#define CASE_DECCARA 128
#define CASE_DECRARA 129
#define CASE_CSI_STAR_STATE 130
+#define CASE_PASTE 131
+#define CASE_TAKE 132
+#define CASE_TAKE_DONE 133
#endif /* included_VTparse_h */
diff -Naur xterm-200/button.c xterm-200-new/button.c
--- xterm-200/button.c 2005-02-06 16:42:37.000000000 -0500
+++ xterm-200-new/button.c 2005-04-06 11:31:46.000000000 -0400
@@ -1174,7 +1174,9 @@
return cutbuffer;
}
-static void
+int base64_paste = 0; /* Set if paste data should be sent as base64 */
+
+void
_GetSelection(Widget w,
Time ev_time,
String * params, /* selections in precedence order */
@@ -1208,19 +1210,34 @@
int fmt8 = 8;
Atom type = XA_STRING;
char *line;
+ int x;
+
+ /* Selection from X server */
+
+#if OPT_WIDE_CHARS
+ /* Joe Allen - 2005-4-4: assume X's cut buffer is UTF-8 if
+ the xterm is UTF-8 */
+ if (term->screen.utf8_mode)
+ type = XA_UTF8_STRING(XtDisplay(w));
+#endif
/* 'line' is freed in SelectionReceived */
line = XFetchBuffer(XtDisplay(w), &inbytes, cutbuffer);
nbytes = (unsigned long) inbytes;
+
if (nbytes > 0)
SelectionReceived(w, NULL, &selection, &type, (XtPointer) line,
&nbytes, &fmt8);
else if (num_params > 1)
_GetSelection(w, ev_time, params + 1, num_params - 1, NULL);
+ else
+ base64_paste = 0;
return;
} else {
struct _SelectionList *list;
+ /* Selection owned by someone */
+
if (targets == NULL || targets[0] == None) {
targets = _SelectionTargets(w);
}
@@ -1280,9 +1297,65 @@
# define tty_vwrite(pty,lag,l) v_write(pty,lag,l)
#endif /* defined VMS */
+/* Return base64 code character given 6-bit number */
+
+char base64_code[]="\
+ABCDEFGHIJKLMNOPQRSTUVWXYZ\
+abcdefghijklmnopqrstuvwxyz\
+0123456789+/";
+
+/* Be careful: _qWriteSelectionData expects these to be initialized
+ to zero. Base64_flush() is the last step of the conversion, it
+ clears these variables. */
+
+int base64_accu = 0;
+int base64_count = 0;
+int base64_pad = 0;
+
static void
_qWriteSelectionData(TScreen * screen, Char * lag, unsigned length)
{
+ if (base64_paste) {
+ /* Send data as base64 */
+ unsigned char *p = (unsigned char *)lag;
+ Char buf[64];
+ unsigned x = 0;
+ while (length--) {
+ switch (base64_count) {
+ case 0:
+ buf[x++] = base64_code[*p >> 2];
+ base64_accu = (*p & 0x3);
+ base64_count = 2;
+ ++p;
+ break;
+ case 2:
+ buf[x++] = base64_code[(base64_accu << 4) + (*p >> 4)];
+ base64_accu = (*p & 0xF);
+ base64_count = 4;
+ ++p;
+ break;
+ case 4:
+ buf[x++] = base64_code[(base64_accu << 2) + (*p >> 6)];
+ buf[x++] = base64_code[*p & 0x3F];
+ base64_accu = 0;
+ base64_count = 0;
+ ++p;
+ break;
+ }
+ if (x >= 63) {
+ /* Write 63 or 64 characters */
+ base64_pad += x;
+ tty_vwrite(screen->respond, buf, x);
+ x = 0;
+ }
+ }
+ if (x != 0) {
+ base64_pad += x;
+ tty_vwrite(screen->respond, buf, x);
+ }
+ return;
+ }
+
#if OPT_READLINE
if (SCREEN_FLAG(screen, paste_quotes)) {
while (length--) {
@@ -1295,6 +1368,29 @@
}
static void
+base64_flush(TScreen *screen)
+{
+ unsigned char x;
+ switch (base64_count) {
+ case 0:
+ break;
+ case 2:
+ x = base64_code[base64_accu << 4];
+ tty_vwrite(screen->respond, &x, 1);
+ break;
+ case 4:
+ x = base64_code[base64_accu << 2];
+ tty_vwrite(screen->respond, &x, 1);
+ break;
+ }
+ if (base64_pad & 3)
+ tty_vwrite(screen->respond, "===", 4 - (base64_pad & 3));
+ base64_count = 0;
+ base64_accu = 0;
+ base64_pad = 0;
+}
+
+static void
_WriteSelectionData(TScreen * screen, Char * line, int length)
{
/* Write data to pty a line at a time. */
@@ -1325,13 +1421,14 @@
if (lag != end) {
_qWriteSelectionData(screen, lag, (unsigned) (end - lag));
}
+ if (base64_paste)
+ base64_flush(screen);
#ifdef VMS
tt_pasting = False;
tt_start_read(); /* reenable reads or a character may be lost */
#endif
}
-#if OPT_READLINE
static void
_WriteKey(TScreen * screen, Char * in)
{
@@ -1350,7 +1447,6 @@
line[count++] = '~';
tty_vwrite(screen->respond, line, count);
}
-#endif /* OPT_READLINE */
/* SelectionReceived: stuff received selection text into pty */
@@ -1434,18 +1530,20 @@
if (text_list != NULL && text_list_count != 0) {
int i;
-#if OPT_READLINE
- if (SCREEN_FLAG(screen, paste_brackets))
+ if (base64_paste)
+ _WriteKey(screen, "202");
+ else if (screen->paste_brackets)
_WriteKey(screen, "200");
-#endif
for (i = 0; i < text_list_count; i++) {
int len = strlen(text_list[i]);
_WriteSelectionData(screen, (Char *) text_list[i], len);
}
-#if OPT_READLINE
- if (SCREEN_FLAG(screen, paste_brackets))
+ if (base64_paste) {
+ tty_vwrite(screen->respond, "\33", 1);
+ base64_paste = 0;
+ }
+ else if (screen->paste_brackets)
_WriteKey(screen, "201");
-#endif
XFreeStringList(text_list);
} else
goto fail;
@@ -1461,6 +1559,8 @@
_GetSelection(w, list->time,
list->params, list->count, list->targets);
XtFree((char *) client_data);
+ } else {
+ base64_paste = 0;
}
return;
}
@@ -2452,6 +2552,96 @@
_OwnSelection(term, params, num_params);
}
+void ClearSelectionBuffer()
+{
+ TScreen *screen = &term->screen;
+ screen->selection_length = 0;
+ base64_count = 0;
+}
+
+void AppendStrToSelectionBuffer(Char *text,int len)
+{
+ TScreen *screen = &term->screen;
+ if (len != 0) {
+ int j = screen->selection_length + len; /* New length */
+ int k = j + (j >> 2) + 80; /* New size if we grow buffer: grow by ~50% */
+ if (j + 1 >= screen->selection_size) {
+ if (!screen->selection_length) {
+ /* New buffer */
+ Char *line;
+ if ((line = (Char *) malloc((unsigned) k)) == 0)
+ SysError(ERROR_BMALLOC2);
+ XtFree((char *) screen->selection_data);
+ screen->selection_data = line;
+ } else {
+ /* Realloc buffer */
+ screen->selection_data = (Char *) realloc(screen->selection_data, (unsigned) k);
+ if (screen->selection_data == 0)
+ SysError(ERROR_BMALLOC2);
+ }
+ screen->selection_size = k;
+ }
+ memcpy(screen->selection_data + screen->selection_length, text, len);
+ screen->selection_length += len;
+ screen->selection_data[screen->selection_length] = 0;
+ }
+}
+
+void AppendToSelectionBuffer(unsigned c)
+{
+ int six;
+ Char ch;
+
+ /* Decode base64 character */
+ if (c >= 'A' && c <= 'Z')
+ six = c - 'A';
+ else if (c >= 'a' && c <= 'z')
+ six = c - 'a' + 26;
+ else if (c >= '0' && c <= '9')
+ six = c - '0' + 52;
+ else if (c == '+')
+ six = 62;
+ else
+ six = 63;
+
+ /* Accumulate bytes */
+ switch (base64_count) {
+ case 0:
+ base64_accu = six;
+ base64_count = 6;
+ break;
+
+ case 2:
+ ch = (base64_accu << 6) + six;
+ base64_count = 0;
+ AppendStrToSelectionBuffer(&ch, 1);
+ break;
+
+ case 4:
+ ch = (base64_accu << 4) + (six >> 2);
+ base64_accu = (six & 0x3);
+ base64_count = 2;
+ AppendStrToSelectionBuffer(&ch, 1);
+ break;
+
+ case 6:
+ ch = (base64_accu << 2) + (six >> 4);
+ base64_accu = (six & 0xF);
+ base64_count = 4;
+ AppendStrToSelectionBuffer(&ch, 1);
+ break;
+ }
+}
+
+extern char *select_args[]; /* in charproc.c */
+
+void CompleteSelection()
+{
+ base64_count = 0;
+ base64_accu = 0;
+ _OwnSelection(term, select_args, 2);
+}
+
static Bool
_ConvertSelectionHelper(Widget w,
Atom * type, XtPointer *value,
@@ -2715,9 +2905,14 @@
*/
unsigned long length = termw->screen.selection_length;
Char *data = termw->screen.selection_data;
+#ifdef junk
+/* These days it's better to assume that X server's cut & paste buffers
+ are UTF-8 when the locale is UTF-8.
+ Joe Allen, 2005-04-04 */
if_OPT_WIDE_CHARS((&(termw->screen)), {
data = UTF8toLatin1(data, length, &length);
});
+#endif
TRACE(("XStoreBuffer(%d)\n", cutbuffer));
XStoreBuffer(XtDisplay((Widget) termw),
(char *) data,
@@ -2885,6 +3080,18 @@
return (result);
}
+/* 32 + following 7-bit word:
+
+ 1:0 Button no: 0, 1, 2. 3=release.
+ 2 shift
+ 3 meta
+ 4 ctrl
+ 5 set for motion notify
+ 6 set for wheel
+*/
+
+/* Position: 32 - 255. */
+
static int
BtnCode(XButtonEvent * event, int button)
{
@@ -2904,6 +3111,16 @@
#define MOUSE_LIMIT (255 - 32)
+/* When screen->out_of_frame set, coordinates can go outside
+ of frame as follows:
+ Code Coord
+ ---- -----
+ 33 - 240 1 - 208 (208 positive coordinates)
+ 32, 255 - 241 0, -1 - -15 (16 negative coordinates)
+
+ When range is exceeded, the maximum closest value is sent
+*/
+
static void
EditorButton(XButtonEvent * event)
{
@@ -2923,20 +3140,41 @@
row = (event->y - screen->border) / FontHeight(screen);
col = (event->x - OriginX(screen)) / FontWidth(screen);
- /* Limit to screen dimensions */
- if (row < 0)
- row = 0;
- else if (row > screen->max_row)
- row = screen->max_row;
- else if (row > MOUSE_LIMIT)
- row = MOUSE_LIMIT;
-
- if (col < 0)
- col = 0;
- else if (col > screen->max_col)
- col = screen->max_col;
- else if (col > MOUSE_LIMIT)
- col = MOUSE_LIMIT;
+ if (screen->out_of_frame) {
+ if (row > 207)
+ row = 207;
+ else if (row < -16)
+ row = 208;
+ else if (row == -1)
+ row = -1;
+ else if (row < 0)
+ row = 224 + row;
+
+ if (col > 207)
+ col = 207;
+ else if (col < -16)
+ col = 208;
+ else if (col == -1)
+ col = -1;
+ else if (col < 0)
+ col = 224 + col;
+
+ } else {
+ /* Limit to screen dimensions */
+ if (row < 0)
+ row = 0;
+ else if (row > screen->max_row)
+ row = screen->max_row;
+ else if (row > MOUSE_LIMIT)
+ row = MOUSE_LIMIT;
+
+ if (col < 0)
+ col = 0;
+ else if (col > screen->max_col)
+ col = screen->max_col;
+ else if (col > MOUSE_LIMIT)
+ col = MOUSE_LIMIT;
+ }
/* Build key sequence starting with \E[M */
if (screen->control_eight_bits) {
diff -Naur xterm-200/charproc.c xterm-200-new/charproc.c
--- xterm-200/charproc.c 2005-02-06 16:42:38.000000000 -0500
+++ xterm-200-new/charproc.c 2005-04-06 11:32:53.000000000 -0400
@@ -1098,6 +1098,20 @@
static struct ParseState myState;
+extern Widget current_widget;
+extern XEvent *current_event;
+extern String *current_params;
+extern Cardinal *current_num_params;
+
+char *select_args[]=
+{
+ "PRIMARY",
+ "CUT_BUFFER0",
+ 0
+};
+
+extern int base64_paste;
+
static Boolean
doparsing(unsigned c, struct ParseState *sp)
{
@@ -1121,7 +1135,19 @@
do {
#if OPT_WIDE_CHARS
- if (screen->wide_chars
+
+ /* Feed wide characters into state machine when we're
+ reading in a selection */
+ if (sp->parsestate == take_table) {
+ if (c < 256)
+ sp->nextstate = sp->parsestate[E2A(c)];
+ else
+ sp->nextstate = CASE_TAKE;
+ goto just_take_it;
+ }
+
+ /* Jhallen: this code was very very slow, so I put in the (c >= 0x300) */
+ if (c >= 0x300 && screen->wide_chars
&& my_wcwidth((int) c) == 0) {
int prev, precomposed;
@@ -1366,6 +1392,8 @@
string_used = 0;
}
+ just_take_it:
+
TRACE(("parse %04X -> %d %s\n", c, sp->nextstate, which_table(sp->parsestate)));
switch (sp->nextstate) {
@@ -1654,6 +1682,38 @@
sp->parsestate = sp->groundtable;
break;
+ case CASE_PASTE: {
+ int cmd = param[0];
+ TRACE(("CASE_PASTE - cut & paste\n"));
+ if (cmd < 2)
+ cmd = 0;
+ if (cmd == 0) {
+ TRACE(("CASE_PASTE - paste selection\n"));
+ /* Paste current selection */
+ base64_paste = 1; /* Tells _GetSelection data is base64 encoded */
+ _GetSelection(current_widget, 0, select_args, 2, NULL);
+ /* _GetSelection clears base64_paste */
+ sp->parsestate = sp->groundtable;
+ } else if (cmd == 2) {
+ TRACE(("CASE_PASTE - taking selection data\n"));
+ ClearSelectionBuffer();
+ sp->parsestate = take_table;
+ } else
+ sp->parsestate = sp->groundtable;
+ break;
+ }
+
+ case CASE_TAKE: {
+ AppendToSelectionBuffer(c);
+ sp->parsestate = take_table;
+ break;
+ }
+
+ case CASE_TAKE_DONE:
+ CompleteSelection();
+ sp->parsestate = sp->groundtable;
+ break;
+
case CASE_ECH:
TRACE(("CASE_ECH - erase char\n"));
/* ECH */
@@ -3877,6 +3937,12 @@
set_keyboard_type(keyboardIsVT220, func == bitset);
break;
#endif
+ case SET_PASTE_IN_BRACKET:
+ screen->paste_brackets = (func == bitset);
+ break;
+ case SET_OUT_OF_FRAME:
+ screen->out_of_frame = (func == bitset);
+ break;
#if OPT_READLINE
case SET_BUTTON1_MOVE_POINT:
set_mouseflag(click1_moves);
@@ -3887,9 +3953,6 @@
case SET_DBUTTON3_DELETE:
set_mouseflag(dclick3_deletes);
break;
- case SET_PASTE_IN_BRACKET:
- set_mouseflag(paste_brackets);
- break;
case SET_PASTE_QUOTE:
set_mouseflag(paste_quotes);
break;
@@ -3993,6 +4056,12 @@
CursorSave(termw);
}
break;
+ case SET_PASTE_IN_BRACKET:
+ DoSM(DP_PASTE_BRACKETS, screen->paste_brackets);
+ break;
+ case SET_OUT_OF_FRAME:
+ DoSM(DP_OUT_OF_FRAME, screen->out_of_frame);
+ break;
#if OPT_READLINE
case SET_BUTTON1_MOVE_POINT:
SCREEN_FLAG_save(screen, click1_moves);
@@ -4003,9 +4072,6 @@
case SET_DBUTTON3_DELETE:
SCREEN_FLAG_save(screen, dclick3_deletes);
break;
- case SET_PASTE_IN_BRACKET:
- SCREEN_FLAG_save(screen, paste_brackets);
- break;
case SET_PASTE_QUOTE:
SCREEN_FLAG_save(screen, paste_quotes);
break;
@@ -4156,6 +4222,11 @@
CursorRestore(termw);
}
break;
+ case SET_PASTE_IN_BRACKET:
+ DoRM(DP_PASTE_BRACKETS, screen->paste_brackets);
+ break;
+ case SET_OUT_OF_FRAME:
+ DoRM(DP_OUT_OF_FRAME, screen->out_of_frame);
#if OPT_READLINE
case SET_BUTTON1_MOVE_POINT:
SCREEN_FLAG_restore(screen, click1_moves);
@@ -4166,9 +4237,6 @@
case SET_DBUTTON3_DELETE:
SCREEN_FLAG_restore(screen, dclick3_deletes);
break;
- case SET_PASTE_IN_BRACKET:
- SCREEN_FLAG_restore(screen, paste_brackets);
- break;
case SET_PASTE_QUOTE:
SCREEN_FLAG_restore(screen, paste_quotes);
break;
diff -Naur xterm-200/ctlseqs.ms xterm-200-new/ctlseqs.ms
--- xterm-200/ctlseqs.ms 2005-01-13 20:50:00.000000000 -0500
+++ xterm-200-new/ctlseqs.ms 2005-04-06 11:45:04.000000000 -0400
@@ -792,6 +792,8 @@
\*(Ps = \*1\*0\*5\*3 \(-> Set SCO function-key mode.
\*(Ps = \*1\*0\*6\*0 \(-> Set legacy keyboard emulation (X11R6).
\*(Ps = \*1\*0\*6\*1 \(-> Set Sun/PC keyboard emulation of VT220 keyboard.
+ \*(Ps = \*2\*0\*0\*4 \(-> Set bracketed paste mode.
+ \*(Ps = \*2\*0\*0\*7 \(-> Allow mouse coordinates beyond frame.
.
.IP \\*(Cs\\*(Pm\\*s\\*i
Media Copy (MC)
@@ -869,6 +871,8 @@
\*(Ps = \*1\*0\*5\*3 \(-> Reset SCO function-key mode.
\*(Ps = \*1\*0\*6\*0 \(-> Reset legacy keyboard emulation (X11R6).
\*(Ps = \*1\*0\*6\*1 \(-> Reset Sun/PC keyboard emulation of VT220 keyboard.
+ \*(Ps = \*2\*0\*0\*4 \(-> Reset bracketed paste mode.
+ \*(Ps = \*2\*0\*0\*7 \(-> Mouse coordinates constrained within frame.
.
.IP \\*(Cs\\*(Pm\\*s\\*m
Character Attributes (SGR)
@@ -1086,6 +1090,15 @@
\*(Pc is the character to use.
\*(Pt\*;\*(Pl\*;\*(Pb\*;\*(Pr denotes the rectangle.
.
+.IP \\*(Cs\\*?\\*(Ps\\*s\\*P
+Cut and Paste.
+ \*(Ps = \*1 \(-> Paste (default). The current selection is sent to the program in Base64:
+ESC [ ? 202 ~ <base64-data> ESC.
+ \*(Ps = \*2 \(-> Select. Give Base64 encoded selection
+data to Xterm. Base64 encoded data is sent to the XTerm following this command. The Data
+is terminated with a single ESC. This data becomes the new selection, which is then
+available for pasting by other applications.
+.
.IP \\*(Cs\\*(Ps\\*s\\*;\\*(Pu\\*s\\*(qu\\*z
Enable Locator Reporting (DECELR)
.br
@@ -1563,6 +1576,14 @@
to make the details of switching independent of the application that
requests the switch.
.SH
+Bracketed Paste Mode
+.ds RH Bracketed Paste Mode
+.LP
+When bracketed paste mode is set, pasted text is bracketed with control
+sequences so that the program can differentiate pasted text from typed-in
+text. When bracketed paste mode is set, the program will receive: ESC [ 200 ~,
+followed by the pasted text, followed by ESC [ 201 ~.
+.SH
Mouse Tracking
.ds RH Mouse Tracking
.LP
@@ -1592,6 +1613,7 @@
#define SET_VT200_HIGHLIGHT_MOUSE 1001
#define SET_BTN_EVENT_MOUSE 1002
#define SET_ANY_EVENT_MOUSE 1003
+#define SET_OUT_OF_FRAME 2007
.DE
.LP
The motion reporting modes are strictly \fIxterm\fP extensions, and are not
@@ -1605,6 +1627,13 @@
For example, \*! specifies the value 1.
The upper left character position on the terminal is denoted as 1,1.
+If OUT_OF_FRAME mode is enabled, and the mouse goes beyond the window frame,
+coordinates beyond the frame are sent to the program. Coordinate values 1 -
+208 are sent as usual, as byte values between 33 and 240. The coordinate
+value 0 (the first cell above or to the left of the frame) is sent as SPACE
+(32). The coordinate values -15 through -1 are sent as byte values 241
+through 255.
+
X10 compatibility mode sends an escape sequence only on button press,
encoding the location and the mouse button pressed.
It is enabled by specifying parameter 9 to DECSET.
diff -Naur xterm-200/misc.c xterm-200-new/misc.c
--- xterm-200/misc.c 2005-01-29 17:17:32.000000000 -0500
+++ xterm-200-new/misc.c 2005-03-27 17:29:23.000000000 -0500
@@ -228,6 +228,11 @@
return (c);
}
+Widget current_widget;
+XEvent *current_event;
+String *current_params;
+Cardinal *current_num_params;
+
/* ARGSUSED */
void
HandleKeyPressed(Widget w GCC_UNUSED,
@@ -238,9 +243,14 @@
TScreen *screen = &term->screen;
TRACE(("Handle 7bit-key\n"));
+ current_widget = w;
+ current_event = event;
+ current_params = params;
+ current_num_params = nparams;
#ifdef ACTIVEWINDOWINPUTONLY
if (w == CURRENT_EMU(screen))
#endif
+
Input(&term->keyboard, screen, &event->xkey, False);
}
diff -Naur xterm-200/paste xterm-200-new/paste
--- xterm-200/paste 1969-12-31 19:00:00.000000000 -0500
+++ xterm-200-new/paste 2005-04-06 11:46:10.000000000 -0400
@@ -0,0 +1 @@
+[?P
diff -Naur xterm-200/ptyx.h xterm-200-new/ptyx.h
--- xterm-200/ptyx.h 2005-01-13 20:50:03.000000000 -0500
+++ xterm-200-new/ptyx.h 2005-03-28 22:48:06.000000000 -0500
@@ -1108,6 +1108,8 @@
#if OPT_TOOLBAR
DP_TOOLBAR,
#endif
+ DP_PASTE_BRACKETS,
+ DP_OUT_OF_FRAME,
DP_LAST
} SaveModes;
@@ -1269,11 +1271,12 @@
unsigned long event_mask;
unsigned short send_mouse_pos; /* user wants mouse transition */
/* and position information */
+ unsigned paste_brackets;
+ unsigned out_of_frame;
#if OPT_READLINE
unsigned click1_moves;
unsigned paste_moves;
unsigned dclick3_deletes;
- unsigned paste_brackets;
unsigned paste_quotes;
unsigned paste_literal_nl;
#endif /* OPT_READLINE */
diff -Naur xterm-200/select xterm-200-new/select
--- xterm-200/select 1969-12-31 19:00:00.000000000 -0500
+++ xterm-200-new/select 2005-04-06 11:47:39.000000000 -0400
@@ -0,0 +1,2 @@
+[?2PSGVsbG8sIHdvcmxkIQo=
+
diff -Naur xterm-200/xcharmouse.h xterm-200-new/xcharmouse.h
--- xterm-200/xcharmouse.h 2002-08-24 14:54:39.000000000 -0400
+++ xterm-200-new/xcharmouse.h 2005-03-28 22:39:35.000000000 -0500
@@ -50,6 +50,8 @@
#define SET_PASTE_IN_BRACKET 2004 /* Surround paste by escapes */
#define SET_PASTE_QUOTE 2005 /* Quote each char during paste */
#define SET_PASTE_LITERAL_NL 2006 /* Paste "\n" as C-j */
+#define SET_OUT_OF_FRAME 2007 /* Give mouse coords even when cursor
+ is outside of frame */
#if OPT_DEC_LOCATOR
diff -Naur xterm-200/xterm.h xterm-200-new/xterm.h
--- xterm-200/xterm.h 2005-01-13 20:50:03.000000000 -0500
+++ xterm-200-new/xterm.h 2005-03-30 22:35:45.000000000 -0500
@@ -603,6 +603,9 @@
extern void DisownSelection (XtermWidget termw);
extern void HandleGINInput PROTO_XT_ACTIONS_ARGS;
extern void HandleInsertSelection PROTO_XT_ACTIONS_ARGS;
+
+extern void _GetSelection (Widget w, Time ev_time, String *params, Cardinal num_params, Atom *targets);
+
extern void HandleKeyboardSelectEnd PROTO_XT_ACTIONS_ARGS;
extern void HandleKeyboardSelectStart PROTO_XT_ACTIONS_ARGS;
extern void HandleKeyboardStartExtend PROTO_XT_ACTIONS_ARGS;
@@ -630,6 +633,10 @@
extern Bool iswide(int i);
#endif
+extern void ClearSelectionBuffer ();
+extern void AppendToSelectionBuffer (unsigned c);
+extern void CompleteSelection ();
+
/* charproc.c */
extern int VTInit (void);
extern int v_write (int f, Char *d, unsigned len);
@@ -1052,4 +1059,6 @@
}
#endif
+
+
#endif /* included_xterm_h */
|