|
Lines 1174-1180
Link Here
|
| 1174 |
return cutbuffer; |
1174 |
return cutbuffer; |
| 1175 |
} |
1175 |
} |
| 1176 |
|
1176 |
|
| 1177 |
static void |
1177 |
int base64_paste = 0; /* Set if paste data should be sent as base64 */ |
|
|
1178 |
|
| 1179 |
void |
| 1178 |
_GetSelection(Widget w, |
1180 |
_GetSelection(Widget w, |
| 1179 |
Time ev_time, |
1181 |
Time ev_time, |
| 1180 |
String * params, /* selections in precedence order */ |
1182 |
String * params, /* selections in precedence order */ |
|
Lines 1208-1226
Link Here
|
| 1208 |
int fmt8 = 8; |
1210 |
int fmt8 = 8; |
| 1209 |
Atom type = XA_STRING; |
1211 |
Atom type = XA_STRING; |
| 1210 |
char *line; |
1212 |
char *line; |
|
|
1213 |
int x; |
| 1214 |
|
| 1215 |
/* Selection from X server */ |
| 1216 |
|
| 1217 |
#if OPT_WIDE_CHARS |
| 1218 |
/* Joe Allen - 2005-4-4: assume X's cut buffer is UTF-8 if |
| 1219 |
the xterm is UTF-8 */ |
| 1220 |
if (term->screen.utf8_mode) |
| 1221 |
type = XA_UTF8_STRING(XtDisplay(w)); |
| 1222 |
#endif |
| 1211 |
|
1223 |
|
| 1212 |
/* 'line' is freed in SelectionReceived */ |
1224 |
/* 'line' is freed in SelectionReceived */ |
| 1213 |
line = XFetchBuffer(XtDisplay(w), &inbytes, cutbuffer); |
1225 |
line = XFetchBuffer(XtDisplay(w), &inbytes, cutbuffer); |
| 1214 |
nbytes = (unsigned long) inbytes; |
1226 |
nbytes = (unsigned long) inbytes; |
|
|
1227 |
|
| 1215 |
if (nbytes > 0) |
1228 |
if (nbytes > 0) |
| 1216 |
SelectionReceived(w, NULL, &selection, &type, (XtPointer) line, |
1229 |
SelectionReceived(w, NULL, &selection, &type, (XtPointer) line, |
| 1217 |
&nbytes, &fmt8); |
1230 |
&nbytes, &fmt8); |
| 1218 |
else if (num_params > 1) |
1231 |
else if (num_params > 1) |
| 1219 |
_GetSelection(w, ev_time, params + 1, num_params - 1, NULL); |
1232 |
_GetSelection(w, ev_time, params + 1, num_params - 1, NULL); |
|
|
1233 |
else |
| 1234 |
base64_paste = 0; |
| 1220 |
return; |
1235 |
return; |
| 1221 |
} else { |
1236 |
} else { |
| 1222 |
struct _SelectionList *list; |
1237 |
struct _SelectionList *list; |
| 1223 |
|
1238 |
|
|
|
1239 |
/* Selection owned by someone */ |
| 1240 |
|
| 1224 |
if (targets == NULL || targets[0] == None) { |
1241 |
if (targets == NULL || targets[0] == None) { |
| 1225 |
targets = _SelectionTargets(w); |
1242 |
targets = _SelectionTargets(w); |
| 1226 |
} |
1243 |
} |
|
Lines 1280-1288
Link Here
|
| 1280 |
# define tty_vwrite(pty,lag,l) v_write(pty,lag,l) |
1297 |
# define tty_vwrite(pty,lag,l) v_write(pty,lag,l) |
| 1281 |
#endif /* defined VMS */ |
1298 |
#endif /* defined VMS */ |
| 1282 |
|
1299 |
|
|
|
1300 |
/* Return base64 code character given 6-bit number */ |
| 1301 |
|
| 1302 |
char base64_code[]="\ |
| 1303 |
ABCDEFGHIJKLMNOPQRSTUVWXYZ\ |
| 1304 |
abcdefghijklmnopqrstuvwxyz\ |
| 1305 |
0123456789+/"; |
| 1306 |
|
| 1307 |
/* Be careful: _qWriteSelectionData expects these to be initialized |
| 1308 |
to zero. Base64_flush() is the last step of the conversion, it |
| 1309 |
clears these variables. */ |
| 1310 |
|
| 1311 |
int base64_accu = 0; |
| 1312 |
int base64_count = 0; |
| 1313 |
int base64_pad = 0; |
| 1314 |
|
| 1283 |
static void |
1315 |
static void |
| 1284 |
_qWriteSelectionData(TScreen * screen, Char * lag, unsigned length) |
1316 |
_qWriteSelectionData(TScreen * screen, Char * lag, unsigned length) |
| 1285 |
{ |
1317 |
{ |
|
|
1318 |
if (base64_paste) { |
| 1319 |
/* Send data as base64 */ |
| 1320 |
unsigned char *p = (unsigned char *)lag; |
| 1321 |
Char buf[64]; |
| 1322 |
unsigned x = 0; |
| 1323 |
while (length--) { |
| 1324 |
switch (base64_count) { |
| 1325 |
case 0: |
| 1326 |
buf[x++] = base64_code[*p >> 2]; |
| 1327 |
base64_accu = (*p & 0x3); |
| 1328 |
base64_count = 2; |
| 1329 |
++p; |
| 1330 |
break; |
| 1331 |
case 2: |
| 1332 |
buf[x++] = base64_code[(base64_accu << 4) + (*p >> 4)]; |
| 1333 |
base64_accu = (*p & 0xF); |
| 1334 |
base64_count = 4; |
| 1335 |
++p; |
| 1336 |
break; |
| 1337 |
case 4: |
| 1338 |
buf[x++] = base64_code[(base64_accu << 2) + (*p >> 6)]; |
| 1339 |
buf[x++] = base64_code[*p & 0x3F]; |
| 1340 |
base64_accu = 0; |
| 1341 |
base64_count = 0; |
| 1342 |
++p; |
| 1343 |
break; |
| 1344 |
} |
| 1345 |
if (x >= 63) { |
| 1346 |
/* Write 63 or 64 characters */ |
| 1347 |
base64_pad += x; |
| 1348 |
tty_vwrite(screen->respond, buf, x); |
| 1349 |
x = 0; |
| 1350 |
} |
| 1351 |
} |
| 1352 |
if (x != 0) { |
| 1353 |
base64_pad += x; |
| 1354 |
tty_vwrite(screen->respond, buf, x); |
| 1355 |
} |
| 1356 |
return; |
| 1357 |
} |
| 1358 |
|
| 1286 |
#if OPT_READLINE |
1359 |
#if OPT_READLINE |
| 1287 |
if (SCREEN_FLAG(screen, paste_quotes)) { |
1360 |
if (SCREEN_FLAG(screen, paste_quotes)) { |
| 1288 |
while (length--) { |
1361 |
while (length--) { |
|
Lines 1295-1300
Link Here
|
| 1295 |
} |
1368 |
} |
| 1296 |
|
1369 |
|
| 1297 |
static void |
1370 |
static void |
|
|
1371 |
base64_flush(TScreen *screen) |
| 1372 |
{ |
| 1373 |
unsigned char x; |
| 1374 |
switch (base64_count) { |
| 1375 |
case 0: |
| 1376 |
break; |
| 1377 |
case 2: |
| 1378 |
x = base64_code[base64_accu << 4]; |
| 1379 |
tty_vwrite(screen->respond, &x, 1); |
| 1380 |
break; |
| 1381 |
case 4: |
| 1382 |
x = base64_code[base64_accu << 2]; |
| 1383 |
tty_vwrite(screen->respond, &x, 1); |
| 1384 |
break; |
| 1385 |
} |
| 1386 |
if (base64_pad & 3) |
| 1387 |
tty_vwrite(screen->respond, "===", 4 - (base64_pad & 3)); |
| 1388 |
base64_count = 0; |
| 1389 |
base64_accu = 0; |
| 1390 |
base64_pad = 0; |
| 1391 |
} |
| 1392 |
|
| 1393 |
static void |
| 1298 |
_WriteSelectionData(TScreen * screen, Char * line, int length) |
1394 |
_WriteSelectionData(TScreen * screen, Char * line, int length) |
| 1299 |
{ |
1395 |
{ |
| 1300 |
/* Write data to pty a line at a time. */ |
1396 |
/* Write data to pty a line at a time. */ |
|
Lines 1325-1337
Link Here
|
| 1325 |
if (lag != end) { |
1421 |
if (lag != end) { |
| 1326 |
_qWriteSelectionData(screen, lag, (unsigned) (end - lag)); |
1422 |
_qWriteSelectionData(screen, lag, (unsigned) (end - lag)); |
| 1327 |
} |
1423 |
} |
|
|
1424 |
if (base64_paste) |
| 1425 |
base64_flush(screen); |
| 1328 |
#ifdef VMS |
1426 |
#ifdef VMS |
| 1329 |
tt_pasting = False; |
1427 |
tt_pasting = False; |
| 1330 |
tt_start_read(); /* reenable reads or a character may be lost */ |
1428 |
tt_start_read(); /* reenable reads or a character may be lost */ |
| 1331 |
#endif |
1429 |
#endif |
| 1332 |
} |
1430 |
} |
| 1333 |
|
1431 |
|
| 1334 |
#if OPT_READLINE |
|
|
| 1335 |
static void |
1432 |
static void |
| 1336 |
_WriteKey(TScreen * screen, Char * in) |
1433 |
_WriteKey(TScreen * screen, Char * in) |
| 1337 |
{ |
1434 |
{ |
|
Lines 1350-1356
Link Here
|
| 1350 |
line[count++] = '~'; |
1447 |
line[count++] = '~'; |
| 1351 |
tty_vwrite(screen->respond, line, count); |
1448 |
tty_vwrite(screen->respond, line, count); |
| 1352 |
} |
1449 |
} |
| 1353 |
#endif /* OPT_READLINE */ |
|
|
| 1354 |
|
1450 |
|
| 1355 |
/* SelectionReceived: stuff received selection text into pty */ |
1451 |
/* SelectionReceived: stuff received selection text into pty */ |
| 1356 |
|
1452 |
|
|
Lines 1434-1451
Link Here
|
| 1434 |
if (text_list != NULL && text_list_count != 0) { |
1530 |
if (text_list != NULL && text_list_count != 0) { |
| 1435 |
int i; |
1531 |
int i; |
| 1436 |
|
1532 |
|
| 1437 |
#if OPT_READLINE |
1533 |
if (base64_paste) |
| 1438 |
if (SCREEN_FLAG(screen, paste_brackets)) |
1534 |
_WriteKey(screen, "202"); |
|
|
1535 |
else if (screen->paste_brackets) |
| 1439 |
_WriteKey(screen, "200"); |
1536 |
_WriteKey(screen, "200"); |
| 1440 |
#endif |
|
|
| 1441 |
for (i = 0; i < text_list_count; i++) { |
1537 |
for (i = 0; i < text_list_count; i++) { |
| 1442 |
int len = strlen(text_list[i]); |
1538 |
int len = strlen(text_list[i]); |
| 1443 |
_WriteSelectionData(screen, (Char *) text_list[i], len); |
1539 |
_WriteSelectionData(screen, (Char *) text_list[i], len); |
| 1444 |
} |
1540 |
} |
| 1445 |
#if OPT_READLINE |
1541 |
if (base64_paste) { |
| 1446 |
if (SCREEN_FLAG(screen, paste_brackets)) |
1542 |
tty_vwrite(screen->respond, "\33", 1); |
|
|
1543 |
base64_paste = 0; |
| 1544 |
} |
| 1545 |
else if (screen->paste_brackets) |
| 1447 |
_WriteKey(screen, "201"); |
1546 |
_WriteKey(screen, "201"); |
| 1448 |
#endif |
|
|
| 1449 |
XFreeStringList(text_list); |
1547 |
XFreeStringList(text_list); |
| 1450 |
} else |
1548 |
} else |
| 1451 |
goto fail; |
1549 |
goto fail; |
|
Lines 1461-1466
Link Here
|
| 1461 |
_GetSelection(w, list->time, |
1559 |
_GetSelection(w, list->time, |
| 1462 |
list->params, list->count, list->targets); |
1560 |
list->params, list->count, list->targets); |
| 1463 |
XtFree((char *) client_data); |
1561 |
XtFree((char *) client_data); |
|
|
1562 |
} else { |
| 1563 |
base64_paste = 0; |
| 1464 |
} |
1564 |
} |
| 1465 |
return; |
1565 |
return; |
| 1466 |
} |
1566 |
} |
|
Lines 2452-2457
Link Here
|
| 2452 |
_OwnSelection(term, params, num_params); |
2552 |
_OwnSelection(term, params, num_params); |
| 2453 |
} |
2553 |
} |
| 2454 |
|
2554 |
|
|
|
2555 |
void ClearSelectionBuffer() |
| 2556 |
{ |
| 2557 |
TScreen *screen = &term->screen; |
| 2558 |
screen->selection_length = 0; |
| 2559 |
base64_count = 0; |
| 2560 |
} |
| 2561 |
|
| 2562 |
void AppendStrToSelectionBuffer(Char *text,int len) |
| 2563 |
{ |
| 2564 |
TScreen *screen = &term->screen; |
| 2565 |
if (len != 0) { |
| 2566 |
int j = screen->selection_length + len; /* New length */ |
| 2567 |
int k = j + (j >> 2) + 80; /* New size if we grow buffer: grow by ~50% */ |
| 2568 |
if (j + 1 >= screen->selection_size) { |
| 2569 |
if (!screen->selection_length) { |
| 2570 |
/* New buffer */ |
| 2571 |
Char *line; |
| 2572 |
if ((line = (Char *) malloc((unsigned) k)) == 0) |
| 2573 |
SysError(ERROR_BMALLOC2); |
| 2574 |
XtFree((char *) screen->selection_data); |
| 2575 |
screen->selection_data = line; |
| 2576 |
} else { |
| 2577 |
/* Realloc buffer */ |
| 2578 |
screen->selection_data = (Char *) realloc(screen->selection_data, (unsigned) k); |
| 2579 |
if (screen->selection_data == 0) |
| 2580 |
SysError(ERROR_BMALLOC2); |
| 2581 |
} |
| 2582 |
screen->selection_size = k; |
| 2583 |
} |
| 2584 |
memcpy(screen->selection_data + screen->selection_length, text, len); |
| 2585 |
screen->selection_length += len; |
| 2586 |
screen->selection_data[screen->selection_length] = 0; |
| 2587 |
} |
| 2588 |
} |
| 2589 |
|
| 2590 |
void AppendToSelectionBuffer(unsigned c) |
| 2591 |
{ |
| 2592 |
int six; |
| 2593 |
Char ch; |
| 2594 |
|
| 2595 |
/* Decode base64 character */ |
| 2596 |
if (c >= 'A' && c <= 'Z') |
| 2597 |
six = c - 'A'; |
| 2598 |
else if (c >= 'a' && c <= 'z') |
| 2599 |
six = c - 'a' + 26; |
| 2600 |
else if (c >= '0' && c <= '9') |
| 2601 |
six = c - '0' + 52; |
| 2602 |
else if (c == '+') |
| 2603 |
six = 62; |
| 2604 |
else |
| 2605 |
six = 63; |
| 2606 |
|
| 2607 |
/* Accumulate bytes */ |
| 2608 |
switch (base64_count) { |
| 2609 |
case 0: |
| 2610 |
base64_accu = six; |
| 2611 |
base64_count = 6; |
| 2612 |
break; |
| 2613 |
|
| 2614 |
case 2: |
| 2615 |
ch = (base64_accu << 6) + six; |
| 2616 |
base64_count = 0; |
| 2617 |
AppendStrToSelectionBuffer(&ch, 1); |
| 2618 |
break; |
| 2619 |
|
| 2620 |
case 4: |
| 2621 |
ch = (base64_accu << 4) + (six >> 2); |
| 2622 |
base64_accu = (six & 0x3); |
| 2623 |
base64_count = 2; |
| 2624 |
AppendStrToSelectionBuffer(&ch, 1); |
| 2625 |
break; |
| 2626 |
|
| 2627 |
case 6: |
| 2628 |
ch = (base64_accu << 2) + (six >> 4); |
| 2629 |
base64_accu = (six & 0xF); |
| 2630 |
base64_count = 4; |
| 2631 |
AppendStrToSelectionBuffer(&ch, 1); |
| 2632 |
break; |
| 2633 |
} |
| 2634 |
} |
| 2635 |
|
| 2636 |
extern char *select_args[]; /* in charproc.c */ |
| 2637 |
|
| 2638 |
void CompleteSelection() |
| 2639 |
{ |
| 2640 |
base64_count = 0; |
| 2641 |
base64_accu = 0; |
| 2642 |
_OwnSelection(term, select_args, 2); |
| 2643 |
} |
| 2644 |
|
| 2455 |
static Bool |
2645 |
static Bool |
| 2456 |
_ConvertSelectionHelper(Widget w, |
2646 |
_ConvertSelectionHelper(Widget w, |
| 2457 |
Atom * type, XtPointer *value, |
2647 |
Atom * type, XtPointer *value, |
|
Lines 2715-2723
Link Here
|
| 2715 |
*/ |
2905 |
*/ |
| 2716 |
unsigned long length = termw->screen.selection_length; |
2906 |
unsigned long length = termw->screen.selection_length; |
| 2717 |
Char *data = termw->screen.selection_data; |
2907 |
Char *data = termw->screen.selection_data; |
|
|
2908 |
#ifdef junk |
| 2909 |
/* These days it's better to assume that X server's cut & paste buffers |
| 2910 |
are UTF-8 when the locale is UTF-8. |
| 2911 |
Joe Allen, 2005-04-04 */ |
| 2718 |
if_OPT_WIDE_CHARS((&(termw->screen)), { |
2912 |
if_OPT_WIDE_CHARS((&(termw->screen)), { |
| 2719 |
data = UTF8toLatin1(data, length, &length); |
2913 |
data = UTF8toLatin1(data, length, &length); |
| 2720 |
}); |
2914 |
}); |
|
|
2915 |
#endif |
| 2721 |
TRACE(("XStoreBuffer(%d)\n", cutbuffer)); |
2916 |
TRACE(("XStoreBuffer(%d)\n", cutbuffer)); |
| 2722 |
XStoreBuffer(XtDisplay((Widget) termw), |
2917 |
XStoreBuffer(XtDisplay((Widget) termw), |
| 2723 |
(char *) data, |
2918 |
(char *) data, |
|
Lines 2885-2890
Link Here
|
| 2885 |
return (result); |
3080 |
return (result); |
| 2886 |
} |
3081 |
} |
| 2887 |
|
3082 |
|
|
|
3083 |
/* 32 + following 7-bit word: |
| 3084 |
|
| 3085 |
1:0 Button no: 0, 1, 2. 3=release. |
| 3086 |
2 shift |
| 3087 |
3 meta |
| 3088 |
4 ctrl |
| 3089 |
5 set for motion notify |
| 3090 |
6 set for wheel |
| 3091 |
*/ |
| 3092 |
|
| 3093 |
/* Position: 32 - 255. */ |
| 3094 |
|
| 2888 |
static int |
3095 |
static int |
| 2889 |
BtnCode(XButtonEvent * event, int button) |
3096 |
BtnCode(XButtonEvent * event, int button) |
| 2890 |
{ |
3097 |
{ |
|
Lines 2904-2909
Link Here
|
| 2904 |
|
3111 |
|
| 2905 |
#define MOUSE_LIMIT (255 - 32) |
3112 |
#define MOUSE_LIMIT (255 - 32) |
| 2906 |
|
3113 |
|
|
|
3114 |
/* When screen->out_of_frame set, coordinates can go outside |
| 3115 |
of frame as follows: |
| 3116 |
Code Coord |
| 3117 |
---- ----- |
| 3118 |
33 - 240 1 - 208 (208 positive coordinates) |
| 3119 |
32, 255 - 241 0, -1 - -15 (16 negative coordinates) |
| 3120 |
|
| 3121 |
When range is exceeded, the maximum closest value is sent |
| 3122 |
*/ |
| 3123 |
|
| 2907 |
static void |
3124 |
static void |
| 2908 |
EditorButton(XButtonEvent * event) |
3125 |
EditorButton(XButtonEvent * event) |
| 2909 |
{ |
3126 |
{ |
|
Lines 2923-2942
Link Here
|
| 2923 |
row = (event->y - screen->border) / FontHeight(screen); |
3140 |
row = (event->y - screen->border) / FontHeight(screen); |
| 2924 |
col = (event->x - OriginX(screen)) / FontWidth(screen); |
3141 |
col = (event->x - OriginX(screen)) / FontWidth(screen); |
| 2925 |
|
3142 |
|
| 2926 |
/* Limit to screen dimensions */ |
3143 |
if (screen->out_of_frame) { |
| 2927 |
if (row < 0) |
3144 |
if (row > 207) |
| 2928 |
row = 0; |
3145 |
row = 207; |
| 2929 |
else if (row > screen->max_row) |
3146 |
else if (row < -16) |
| 2930 |
row = screen->max_row; |
3147 |
row = 208; |
| 2931 |
else if (row > MOUSE_LIMIT) |
3148 |
else if (row == -1) |
| 2932 |
row = MOUSE_LIMIT; |
3149 |
row = -1; |
| 2933 |
|
3150 |
else if (row < 0) |
| 2934 |
if (col < 0) |
3151 |
row = 224 + row; |
| 2935 |
col = 0; |
3152 |
|
| 2936 |
else if (col > screen->max_col) |
3153 |
if (col > 207) |
| 2937 |
col = screen->max_col; |
3154 |
col = 207; |
| 2938 |
else if (col > MOUSE_LIMIT) |
3155 |
else if (col < -16) |
| 2939 |
col = MOUSE_LIMIT; |
3156 |
col = 208; |
|
|
3157 |
else if (col == -1) |
| 3158 |
col = -1; |
| 3159 |
else if (col < 0) |
| 3160 |
col = 224 + col; |
| 3161 |
|
| 3162 |
} else { |
| 3163 |
/* Limit to screen dimensions */ |
| 3164 |
if (row < 0) |
| 3165 |
row = 0; |
| 3166 |
else if (row > screen->max_row) |
| 3167 |
row = screen->max_row; |
| 3168 |
else if (row > MOUSE_LIMIT) |
| 3169 |
row = MOUSE_LIMIT; |
| 3170 |
|
| 3171 |
if (col < 0) |
| 3172 |
col = 0; |
| 3173 |
else if (col > screen->max_col) |
| 3174 |
col = screen->max_col; |
| 3175 |
else if (col > MOUSE_LIMIT) |
| 3176 |
col = MOUSE_LIMIT; |
| 3177 |
} |
| 2940 |
|
3178 |
|
| 2941 |
/* Build key sequence starting with \E[M */ |
3179 |
/* Build key sequence starting with \E[M */ |
| 2942 |
if (screen->control_eight_bits) { |
3180 |
if (screen->control_eight_bits) { |