X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=ldisc.c;h=320a93607c3cb6204732bf0e4889e4a9db9e32ba;hb=4c67f0b060a8eb392063b055839d85c6d9913e94;hp=f2853f4b303c4749e6a33a1e10b85e14767932ba;hpb=7531c7d3d49cfa774f6940e69d6210e1565979ad;p=PuTTY.git diff --git a/ldisc.c b/ldisc.c index f2853f4b..320a9360 100644 --- a/ldisc.c +++ b/ldisc.c @@ -7,21 +7,22 @@ #include #include +#include #include "putty.h" #include "terminal.h" #include "ldisc.h" -#define ECHOING (ldisc->cfg->localecho == FORCE_ON || \ - (ldisc->cfg->localecho == AUTO && \ +#define ECHOING (ldisc->localecho == FORCE_ON || \ + (ldisc->localecho == AUTO && \ (ldisc->back->ldisc(ldisc->backhandle, LD_ECHO) || \ term_ldisc(ldisc->term, LD_ECHO)))) -#define EDITING (ldisc->cfg->localedit == FORCE_ON || \ - (ldisc->cfg->localedit == AUTO && \ +#define EDITING (ldisc->localedit == FORCE_ON || \ + (ldisc->localedit == AUTO && \ (ldisc->back->ldisc(ldisc->backhandle, LD_EDIT) || \ term_ldisc(ldisc->term, LD_EDIT)))) -static void c_write(Ldisc ldisc, char *buf, int len) +static void c_write(Ldisc ldisc, const char *buf, int len) { from_backend(ldisc->frontend, 0, buf, len); } @@ -76,7 +77,7 @@ static void bsb(Ldisc ldisc, int n) #define CTRL(x) (x^'@') #define KCTRL(x) ((x^'@') | 0x100) -void *ldisc_create(Config *mycfg, Terminal *term, +void *ldisc_create(Conf *conf, Terminal *term, Backend *back, void *backhandle, void *frontend) { @@ -87,12 +88,13 @@ void *ldisc_create(Config *mycfg, Terminal *term, ldisc->bufsiz = 0; ldisc->quotenext = 0; - ldisc->cfg = mycfg; ldisc->back = back; ldisc->backhandle = backhandle; ldisc->term = term; ldisc->frontend = frontend; + ldisc_configure(ldisc, conf); + /* Link ourselves into the backend and the terminal */ if (term) term->ldisc = ldisc; @@ -102,6 +104,17 @@ void *ldisc_create(Config *mycfg, Terminal *term, return ldisc; } +void ldisc_configure(void *handle, Conf *conf) +{ + Ldisc ldisc = (Ldisc) handle; + + ldisc->telnet_keyboard = conf_get_int(conf, CONF_telnet_keyboard); + ldisc->telnet_newline = conf_get_int(conf, CONF_telnet_newline); + ldisc->protocol = conf_get_int(conf, CONF_protocol); + ldisc->localecho = conf_get_int(conf, CONF_localecho); + ldisc->localedit = conf_get_int(conf, CONF_localedit); +} + void ldisc_free(void *handle) { Ldisc ldisc = (Ldisc) handle; @@ -115,18 +128,20 @@ void ldisc_free(void *handle) sfree(ldisc); } -void ldisc_send(void *handle, char *buf, int len, int interactive) +void ldisc_echoedit_update(void *handle) +{ + Ldisc ldisc = (Ldisc) handle; + frontend_echoedit_update(ldisc->frontend, ECHOING, EDITING); +} + +void ldisc_send(void *handle, const char *buf, int len, int interactive) { Ldisc ldisc = (Ldisc) handle; int keyflag = 0; - /* - * Called with len=0 when the options change. We must inform - * the front end in case it needs to know. - */ - if (len == 0) { - ldisc_update(ldisc->frontend, ECHOING, EDITING); - return; - } + + assert(ldisc->term); + assert(len); + /* * Notify the front end that something was pressed, in case * it's depending on finding out (e.g. keypress termination for @@ -134,6 +149,18 @@ void ldisc_send(void *handle, char *buf, int len, int interactive) */ frontend_keypress(ldisc->frontend); + if (interactive) { + /* + * Interrupt a paste from the clipboard, if one was in + * progress when the user pressed a key. This is easier than + * buffering the current piece of data and saving it until the + * terminal has finished pasting, and has the potential side + * benefit of permitting a user to cancel an accidental huge + * paste. + */ + term_nopaste(ldisc->term); + } + /* * Less than zero means null terminated special string. */ @@ -203,7 +230,7 @@ void ldisc_send(void *handle, char *buf, int len, int interactive) * configured telnet specials off! This breaks * talkers otherwise. */ - if (!ldisc->cfg->telnet_keyboard) + if (!ldisc->telnet_keyboard) goto default_case; if (c == CTRL('C')) ldisc->back->special(ldisc->backhandle, TS_IP); @@ -255,7 +282,7 @@ void ldisc_send(void *handle, char *buf, int len, int interactive) * default clause because of the break. */ case CTRL('J'): - if (ldisc->cfg->protocol == PROT_RAW && + if (ldisc->protocol == PROT_RAW && ldisc->buflen > 0 && ldisc->buf[ldisc->buflen - 1] == '\r') { if (ECHOING) bsb(ldisc, plen(ldisc, ldisc->buf[ldisc->buflen - 1])); @@ -264,9 +291,9 @@ void ldisc_send(void *handle, char *buf, int len, int interactive) case KCTRL('M'): /* send with newline */ if (ldisc->buflen > 0) ldisc->back->send(ldisc->backhandle, ldisc->buf, ldisc->buflen); - if (ldisc->cfg->protocol == PROT_RAW) + if (ldisc->protocol == PROT_RAW) ldisc->back->send(ldisc->backhandle, "\r\n", 2); - else if (ldisc->cfg->protocol == PROT_TELNET && ldisc->cfg->telnet_newline) + else if (ldisc->protocol == PROT_TELNET && ldisc->telnet_newline) ldisc->back->special(ldisc->backhandle, TS_EOL); else ldisc->back->send(ldisc->backhandle, "\r", 1); @@ -300,27 +327,27 @@ void ldisc_send(void *handle, char *buf, int len, int interactive) if (len > 0) { if (ECHOING) c_write(ldisc, buf, len); - if (keyflag && ldisc->cfg->protocol == PROT_TELNET && len == 1) { + if (keyflag && ldisc->protocol == PROT_TELNET && len == 1) { switch (buf[0]) { case CTRL('M'): - if (ldisc->cfg->protocol == PROT_TELNET && ldisc->cfg->telnet_newline) + if (ldisc->protocol == PROT_TELNET && ldisc->telnet_newline) ldisc->back->special(ldisc->backhandle, TS_EOL); else ldisc->back->send(ldisc->backhandle, "\r", 1); break; case CTRL('?'): case CTRL('H'): - if (ldisc->cfg->telnet_keyboard) { + if (ldisc->telnet_keyboard) { ldisc->back->special(ldisc->backhandle, TS_EC); break; } case CTRL('C'): - if (ldisc->cfg->telnet_keyboard) { + if (ldisc->telnet_keyboard) { ldisc->back->special(ldisc->backhandle, TS_IP); break; } case CTRL('Z'): - if (ldisc->cfg->telnet_keyboard) { + if (ldisc->telnet_keyboard) { ldisc->back->special(ldisc->backhandle, TS_SUSP); break; }