First phase of porting. pterm now compiles and runs under Linux+gtk.
[u/mdw/putty] / ldisc.c
diff --git a/ldisc.c b/ldisc.c
index b307d4e..e6a110b 100644 (file)
--- a/ldisc.c
+++ b/ldisc.c
@@ -5,7 +5,6 @@
  * depending on what's currently configured.
  */
 
-#include <windows.h>
 #include <stdio.h>
 #include <ctype.h>
 
@@ -28,7 +27,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))
+    if ((c >= 32 && c <= 126) || (c >= 160 && !in_utf))
        return 1;
     else if (c < 128)
        return 2;                      /* ^x for some x */
@@ -38,7 +37,7 @@ static int plen(unsigned char c)
 
 static void pwrite(unsigned char c)
 {
-    if ((c >= 32 && c <= 126) || (c >= 160)) {
+    if ((c >= 32 && c <= 126) || (c >= 160 && !in_utf)) {
        c_write(&c, 1);
     } else if (c < 128) {
        char cc[2];
@@ -61,7 +60,7 @@ static void bsb(int n)
 #define CTRL(x) (x^'@')
 #define KCTRL(x) ((x^'@') | 0x100)
 
-void ldisc_send(char *buf, int len)
+void ldisc_send(char *buf, int len, int interactive)
 {
     int keyflag = 0;
     /*
@@ -86,6 +85,8 @@ void ldisc_send(char *buf, int len)
        while (len--) {
            int c;
            c = *buf++ + keyflag;
+           if (!interactive && c == '\r')
+               c += KCTRL('@');
            switch (term_quotenext ? ' ' : c) {
                /*
                 * ^h/^?: delete one char and output one BSB
@@ -130,6 +131,13 @@ void ldisc_send(char *buf, int len)
                    term_buflen--;
                }
                back->special(TS_EL);
+                /*
+                 * We don't send IP, SUSP or ABORT if the user has
+                 * configured telnet specials off! This breaks
+                 * talkers otherwise.
+                 */
+                if (!cfg.telnet_keyboard)
+                    goto default_case;
                if (c == CTRL('C'))
                    back->special(TS_IP);
                if (c == CTRL('Z'))
@@ -191,7 +199,7 @@ void ldisc_send(char *buf, int len)
                        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);
@@ -202,6 +210,7 @@ void ldisc_send(char *buf, int len)
                }
                /* FALLTHROUGH */
              default:                 /* get to this label from ^V handler */
+                default_case:
                if (term_buflen >= term_bufsiz) {
                    term_bufsiz = term_buflen + 256;
                    term_buf = saferealloc(term_buf, term_bufsiz);
@@ -227,7 +236,10 @@ void ldisc_send(char *buf, int len)
            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'):