Oops - repercussions of the close-on-exit stuff which I forgot to
[u/mdw/putty] / ldisc.c
diff --git a/ldisc.c b/ldisc.c
index e464c13..a149c6d 100644 (file)
--- a/ldisc.c
+++ b/ldisc.c
@@ -5,22 +5,22 @@
  * depending on what's currently configured.
  */
 
-#include <windows.h>
 #include <stdio.h>
 #include <ctype.h>
 
 #include "putty.h"
+#include "terminal.h"
 
 #define ECHOING (cfg.localecho == LD_YES || \
                  (cfg.localecho == LD_BACKEND && \
-                      (back->ldisc(LD_ECHO) || term_ldisc(LD_ECHO))))
+                      (back->ldisc(LD_ECHO) || term_ldisc(term, LD_ECHO))))
 #define EDITING (cfg.localedit == LD_YES || \
                  (cfg.localedit == LD_BACKEND && \
-                      (back->ldisc(LD_EDIT) || term_ldisc(LD_EDIT))))
+                      (back->ldisc(LD_EDIT) || term_ldisc(term, LD_EDIT))))
 
 static void c_write(char *buf, int len)
 {
-    from_backend(0, buf, len);
+    from_backend(term, 0, buf, len);
 }
 
 static char *term_buf = NULL;
@@ -28,7 +28,7 @@ static int term_buflen = 0, term_bufsiz = 0, term_quotenext = 0;
 
 static int plen(unsigned char c)
 {
-    if ((c >= 32 && c <= 126) || (c >= 160 && !in_utf))
+    if ((c >= 32 && c <= 126) || (c >= 160 && !in_utf(term)))
        return 1;
     else if (c < 128)
        return 2;                      /* ^x for some x */
@@ -38,7 +38,7 @@ static int plen(unsigned char c)
 
 static void pwrite(unsigned char c)
 {
-    if ((c >= 32 && c <= 126) || (c >= 160 && !in_utf)) {
+    if ((c >= 32 && c <= 126) || (c >= 160 && !in_utf(term))) {
        c_write(&c, 1);
     } else if (c < 128) {
        char cc[2];
@@ -71,8 +71,15 @@ void ldisc_send(char *buf, int len, int interactive)
     if (len == 0) {
        void ldisc_update(int echo, int edit);
        ldisc_update(ECHOING, EDITING);
+       return;
     }
     /*
+     * Notify the front end that something was pressed, in case
+     * it's depending on finding out (e.g. keypress termination for
+     * Close On Exit). 
+     */
+    frontend_keypress();
+    /*
      * Less than zero means null terminated special string.
      */
     if (len < 0) {
@@ -200,7 +207,7 @@ void ldisc_send(char *buf, int len, int interactive)
                        back->send(term_buf, term_buflen);
                    if (cfg.protocol == PROT_RAW)
                        back->send("\r\n", 2);
-                   else if (cfg.protocol == PROT_TELNET)
+                   else if (cfg.protocol == PROT_TELNET && cfg.telnet_newline)
                        back->special(TS_EOL);
                    else
                        back->send("\r", 1);
@@ -237,7 +244,10 @@ void ldisc_send(char *buf, int len, int interactive)
            if (keyflag && cfg.protocol == PROT_TELNET && len == 1) {
                switch (buf[0]) {
                  case CTRL('M'):
-                   back->special(TS_EOL);
+                   if (cfg.protocol == PROT_TELNET && cfg.telnet_newline)
+                       back->special(TS_EOL);
+                   else
+                       back->send("\r", 1);
                    break;
                  case CTRL('?'):
                  case CTRL('H'):