#include <windows.h>
-#ifndef AUTO_WINSOCK
-#ifdef WINSOCK_TWO
-#include <winsock2.h>
-#else
-#include <winsock.h>
-#endif
-#endif
#include <stdio.h>
#include <stdlib.h>
+#include <ctype.h>
#include "putty.h"
ctx = get_ctx();
if (ctx) {
if ( (seen_key_event && (cfg.scroll_on_key)) ||
- (seen_disp_event && (!cfg.scroll_on_key)) ) {
+ (seen_disp_event && (cfg.scroll_on_disp)) ) {
disptop = scrtop;
seen_disp_event = seen_key_event = 0;
update_sbar();
term_update();
}
+static void clipme(unsigned long *top, unsigned long *bottom, char *workbuf) {
+ char *wbptr; /* where next char goes within workbuf */
+ int wblen = 0; /* workbuf len */
+ int buflen; /* amount of memory allocated to workbuf */
+
+ if ( workbuf != NULL ) { /* user supplied buffer? */
+ buflen = -1; /* assume buffer passed in is big enough */
+ wbptr = workbuf; /* start filling here */
+ }
+ else
+ buflen = 0; /* No data is available yet */
+
+ while (top < bottom) {
+ int nl = FALSE;
+ unsigned long *lineend = top - (top-text) % (cols+1) + cols;
+ unsigned long *nlpos = lineend;
+
+ if (!(*nlpos & ATTR_WRAPPED)) {
+ while ((nlpos[-1] & CHAR_MASK) == 0x20 && nlpos > top)
+ nlpos--;
+ if (nlpos < bottom)
+ nl = TRUE;
+ }
+ while (top < nlpos && top < bottom)
+ {
+#if 0
+ /* VT Specials -> ISO8859-1 */
+ static const char poorman2[] =
+"* # HTFFCRLF\xB0 \xB1 NLVT+ + + + + - - - - - + + + + | <=>=PI!=\xA3 \xB7 ";
+#endif
+
+ int ch = (*top & CHAR_MASK);
+
+#if 0
+ if ((*top & ATTR_LINEDRW) && ch >= 0x60 && ch < 0x7F) {
+ int x;
+ *wbptr++ = poorman2[2*(ch-0x60)];
+ if ( (x = poorman2[2*(ch-0x60)+1]) != ' ')
+ *wbptr++ = x;
+ } else
+#endif
+#if 0
+ if ((*top & ATTR_GBCHR) && ch == '#')
+ *wbptr++ = (unsigned char) 0xA3;
+ else
+#endif
+ if ( wblen == buflen )
+ {
+ workbuf = srealloc(workbuf, buflen += 100);
+ wbptr = workbuf + wblen;
+ }
+ wblen++;
+ *wbptr++ = (unsigned char) ch;
+ top++;
+ }
+ if (nl) {
+ int i;
+ for (i=0; i<sizeof(sel_nl); i++)
+ {
+ if ( wblen == buflen )
+ {
+ workbuf = srealloc(workbuf, buflen += 100);
+ wbptr = workbuf + wblen;
+ }
+ wblen++;
+ *wbptr++ = sel_nl[i];
+ }
+ }
+ top = lineend + 1; /* start of next line */
+ }
+ write_clip (workbuf, wblen, FALSE); /* transfer to clipboard */
+ if ( buflen > 0 ) /* indicates we allocated this buffer */
+ sfree(workbuf);
+
+}
+void term_copyall (void) {
+ clipme(sbtop, cpos, NULL /* dynamic allocation */);
+}
+
/*
* Spread the selection outwards according to the selection mode.
*/
* We've completed a selection. We now transfer the
* data to the clipboard.
*/
- unsigned char *p = selspace;
- unsigned long *q = selstart;
-
- while (q < selend) {
- int nl = FALSE;
- unsigned long *lineend = q - (q-text) % (cols+1) + cols;
- unsigned long *nlpos = lineend;
-
- if (!(*nlpos & ATTR_WRAPPED)) {
- while ((nlpos[-1] & CHAR_MASK) == 0x20 && nlpos > q)
- nlpos--;
- if (nlpos < selend)
- nl = TRUE;
- }
- while (q < nlpos && q < selend)
- {
-#if 0
- /* VT Specials -> ISO8859-1 */
- static const char poorman2[] =
- "* # HTFFCRLF\xB0 \xB1 NLVT+ + + + + - - - - - + + + + | <=>=PI!=\xA3 \xB7 ";
-#endif
-
- int ch = (*q & CHAR_MASK);
-
-#if 0
- if ((*q & ATTR_LINEDRW) && ch >= 0x60 && ch < 0x7F) {
- int x;
- *p++ = poorman2[2*(ch-0x60)];
- if ( (x = poorman2[2*(ch-0x60)+1]) != ' ')
- *p++ = x;
- } else
-#endif
-#if 0
- if ((*q & ATTR_GBCHR) && ch == '#')
- *p++ = (unsigned char) 0xA3;
- else
-#endif
- *p++ = (unsigned char) ch;
- q++;
- }
- if (nl) {
- int i;
- for (i=0; i<sizeof(sel_nl); i++)
- *p++ = sel_nl[i];
- }
- q = lineend + 1; /* start of next line */
- }
- write_clip (selspace, p - selspace, FALSE);
+ clipme(selstart, selend, selspace);
selstate = SELECTED;
} else
selstate = NO_SELECTION;
}
void term_paste() {
-static long last_paste = 0;
+ static long last_paste = 0;
long now, paste_diff;
if(paste_len == 0) return;
while(paste_pos<paste_len)
{
- char c = paste_buffer[paste_pos++];
- ldisc->send (&c, 1);
+ int n = 0;
+ while (n + paste_pos < paste_len) {
+ if (paste_buffer[paste_pos + n++] == '\r')
+ break;
+ }
+ ldisc->send (paste_buffer+paste_pos, n);
+ paste_pos += n;
- if (c =='\r') {
+ if (paste_pos < paste_len) {
paste_hold = 1;
return;
}
deselect();
term_update();
}
+
+/*
+ * from_backend(), to get data from the backend for the terminal.
+ */
+void from_backend(int is_stderr, char *data, int len) {
+ while (len--) {
+ if (inbuf_head >= INBUF_SIZE)
+ term_out();
+ inbuf[inbuf_head++] = *data++;
+ }
+}