Cleanups from yesterday's destabilisation: lots of stuff in
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 23 Oct 2002 12:41:35 +0000 (12:41 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 23 Oct 2002 12:41:35 +0000 (12:41 +0000)
terminal.c was apparently relying on implicit initialisation to
zero, and also I've removed the backends' dependency on terminal.h
by having terminal sizes explicitly passed in to back->size().

git-svn-id: svn://svn.tartarus.org/sgt/putty@2117 cda61777-01e9-0310-a592-d414129be87e

putty.h
rlogin.c
ssh.c
telnet.c
terminal.c
unix/pty.c

diff --git a/putty.h b/putty.h
index 646761f..99b1918 100644 (file)
--- a/putty.h
+++ b/putty.h
@@ -194,7 +194,7 @@ struct backend_tag {
     int (*send) (char *buf, int len);
     /* back->sendbuffer() does the same thing but without attempting a send */
     int (*sendbuffer) (void);
-    void (*size) (void);
+    void (*size) (int width, int height);
     void (*special) (Telnet_Special code);
     Socket(*socket) (void);
     int (*exitcode) (void);
index 4baada7..b566db7 100644 (file)
--- a/rlogin.c
+++ b/rlogin.c
@@ -4,7 +4,6 @@
 #include <ctype.h>
 
 #include "putty.h"
-#include "terminal.h"
 
 #ifndef FALSE
 #define FALSE 0
@@ -17,6 +16,7 @@
 
 static Socket s = NULL;
 static int rlogin_bufsize;
+static int rlogin_term_width, rlogin_term_height;
 static void *frontend;
 
 static void rlogin_size(void);
@@ -103,6 +103,8 @@ static char *rlogin_init(void *frontend_handle,
     char *err;
 
     frontend = frontend_handle;
+    rlogin_term_width = cfg.width;
+    rlogin_term_height = cfg.height;
 
     /*
      * Try to find host.
@@ -180,17 +182,20 @@ static int rlogin_sendbuffer(void)
 /*
  * Called to set the size of the window
  */
-static void rlogin_size(void)
+static void rlogin_size(int width, int height)
 {
     char b[12] = { '\xFF', '\xFF', 0x73, 0x73, 0, 0, 0, 0, 0, 0, 0, 0 };
 
-    if (s == NULL || term == NULL)
+    rlogin_term_width = width;
+    rlogin_term_height = height;
+
+    if (s == NULL)
        return;
-    
-    b[6] = term->cols >> 8;
-    b[7] = term->cols & 0xFF;
-    b[4] = term->rows >> 8;
-    b[5] = term->rows & 0xFF;
+
+    b[6] = rlogin_term_width >> 8;
+    b[7] = rlogin_term_width & 0xFF;
+    b[4] = rlogin_term_height >> 8;
+    b[5] = rlogin_term_height & 0xFF;
     rlogin_bufsize = sk_write(s, b, 12);
     return;
 }
diff --git a/ssh.c b/ssh.c
index 31d4cc4..127ebee 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -5,7 +5,6 @@
 #include <assert.h>
 
 #include "putty.h"
-#include "terminal.h"
 #include "tree234.h"
 #include "ssh.h"
 
@@ -536,6 +535,8 @@ static int ssh_echoing, ssh_editing;
 
 static void *frontend;
 
+static int ssh_term_width, ssh_term_height;
+
 static tree234 *ssh_channels;         /* indexed by local id */
 static struct ssh_channel *mainchan;   /* primary session channel */
 static int ssh_exitcode = -1;
@@ -3127,8 +3128,8 @@ static void ssh1_protocol(unsigned char *in, int inlen, int ispkt)
     if (!cfg.nopty) {
        send_packet(SSH1_CMSG_REQUEST_PTY,
                    PKT_STR, cfg.termtype,
-                   PKT_INT, term ? term->rows : 24,
-                   PKT_INT, term ? term->cols : 80,
+                   PKT_INT, ssh_term_height,
+                   PKT_INT, ssh_term_width,
                    PKT_INT, 0, PKT_INT, 0, PKT_CHAR, 0, PKT_END);
        ssh_state = SSH_STATE_INTERMED;
        do {
@@ -5146,8 +5147,8 @@ static void do_ssh2_authconn(unsigned char *in, int inlen, int ispkt)
        ssh2_pkt_addstring("pty-req");
        ssh2_pkt_addbool(1);           /* want reply */
        ssh2_pkt_addstring(cfg.termtype);
-       ssh2_pkt_adduint32(term ? term->cols : 80);
-       ssh2_pkt_adduint32(term ? term->rows : 24);
+       ssh2_pkt_adduint32(ssh_term_width);
+       ssh2_pkt_adduint32(ssh_term_height);
        ssh2_pkt_adduint32(0);         /* pixel width */
        ssh2_pkt_adduint32(0);         /* pixel height */
        ssh2_pkt_addstring_start();
@@ -5721,6 +5722,8 @@ static char *ssh_init(void *frontend_handle,
 #endif
 
     frontend = frontend_handle;
+    ssh_term_width = cfg.width;
+    ssh_term_height = cfg.height;
 
     ssh_send_ok = 0;
     ssh_editing = 0;
@@ -5782,8 +5785,11 @@ static int ssh_sendbuffer(void)
 /*
  * Called to set the size of the window from SSH's POV.
  */
-static void ssh_size(void)
+static void ssh_size(int width, int height)
 {
+    ssh_term_width = width;
+    ssh_term_height = height;
+
     switch (ssh_state) {
       case SSH_STATE_BEFORE_SIZE:
       case SSH_STATE_PREPACKET:
@@ -5798,15 +5804,15 @@ static void ssh_size(void)
                return;
            if (ssh_version == 1) {
                send_packet(SSH1_CMSG_WINDOW_SIZE,
-                           PKT_INT, term->rows, PKT_INT, term->cols,
+                           PKT_INT, ssh_term_height, PKT_INT, ssh_term_width,
                            PKT_INT, 0, PKT_INT, 0, PKT_END);
            } else {
                ssh2_pkt_init(SSH2_MSG_CHANNEL_REQUEST);
                ssh2_pkt_adduint32(mainchan->remoteid);
                ssh2_pkt_addstring("window-change");
                ssh2_pkt_addbool(0);
-               ssh2_pkt_adduint32(term->cols);
-               ssh2_pkt_adduint32(term->rows);
+               ssh2_pkt_adduint32(ssh_term_width);
+               ssh2_pkt_adduint32(ssh_term_height);
                ssh2_pkt_adduint32(0);
                ssh2_pkt_adduint32(0);
                ssh2_pkt_send();
index 9aba9ea..b8ce417 100644 (file)
--- a/telnet.c
+++ b/telnet.c
@@ -3,7 +3,6 @@
 #include <stdlib.h>
 
 #include "putty.h"
-#include "terminal.h"
 
 #ifndef FALSE
 #define FALSE 0
@@ -15,6 +14,7 @@
 static Socket s = NULL;
 
 static void *frontend;
+static int telnet_term_width, telnet_term_height;
 
 #define        IAC     255                    /* interpret as command: */
 #define        DONT    254                    /* you are not to use option */
@@ -618,6 +618,8 @@ static char *telnet_init(void *frontend_handle,
     char *err;
 
     frontend = frontend_handle;
+    telnet_term_width = cfg.width;
+    telnet_term_height = cfg.height;
 
     /*
      * Try to find host.
@@ -719,20 +721,23 @@ static int telnet_sendbuffer(void)
 /*
  * Called to set the size of the window from Telnet's POV.
  */
-static void telnet_size(void)
+static void telnet_size(int width, int height)
 {
     unsigned char b[16];
     char logbuf[50];
 
-    if (s == NULL || term == NULL || o_naws.state != ACTIVE)
+    telnet_term_width = width;
+    telnet_term_height = height;
+
+    if (s == NULL || o_naws.state != ACTIVE)
        return;
     b[0] = IAC;
     b[1] = SB;
     b[2] = TELOPT_NAWS;
-    b[3] = term->cols >> 8;
-    b[4] = term->cols & 0xFF;
-    b[5] = term->rows >> 8;
-    b[6] = term->rows & 0xFF;
+    b[3] = telnet_term_width >> 8;
+    b[4] = telnet_term_width & 0xFF;
+    b[5] = telnet_term_height >> 8;
+    b[6] = telnet_term_height & 0xFF;
     b[7] = IAC;
     b[8] = SE;
     telnet_bufsize = sk_write(s, b, 9);
index d0a09a3..f412244 100644 (file)
@@ -148,12 +148,14 @@ static void power_on(Terminal *term)
            term->tabs[i] = (i % 8 == 0 ? TRUE : FALSE);
     }
     term->alt_om = term->dec_om = cfg.dec_om;
-    term->alt_wnext = term->wrapnext = term->alt_ins = term->insert = FALSE;
+    term->alt_ins = term->insert = FALSE;
+    term->alt_wnext = term->wrapnext = term->save_wnext = FALSE;
     term->alt_wrap = term->wrap = cfg.wrap_mode;
-    term->alt_cset = term->cset = 0;
-    term->alt_utf = term->utf = 0;
-    term->alt_sco_acs = term->sco_acs = 0;
-    term->cset_attr[0] = term->cset_attr[1] = ATTR_ASCII;
+    term->alt_cset = term->cset = term->save_cset = 0;
+    term->alt_utf = term->utf = term->save_utf = 0;
+    term->utf_state = 0;
+    term->alt_sco_acs = term->sco_acs = term->save_sco_acs = 0;
+    term->cset_attr[0] = term->cset_attr[1] = term->save_csattr = ATTR_ASCII;
     term->rvideo = 0;
     term->in_vbell = FALSE;
     term->cursor_on = 1;
@@ -302,6 +304,18 @@ Terminal *term_init(void)
     term->last_paste = 0;
     bufchain_init(&term->inbuf);
     bufchain_init(&term->printer_buf);
+    term->printing = term->only_printing = FALSE;
+    term->print_job = NULL;
+    term->vt52_mode = FALSE;
+    term->cr_lf_return = FALSE;
+    term->seen_disp_event = FALSE;
+    term->xterm_mouse = FALSE;
+    term->reset_132 = FALSE;
+    term->blinker = term->tblinker = 0;
+    term->has_focus = 1;
+    term->repeat_off = FALSE;
+    term->termstate = TOPLEVEL;
+    term->selstate = NO_SELECTION;
 
     term->screen = term->alt_screen = term->scrollback = NULL;
     term->disptop = 0;
@@ -441,7 +455,7 @@ void term_size(Terminal *term, int newrows, int newcols, int newsavelines)
 
     update_sbar(term);
     term_update(term);
-    back->size();
+    back->size(term->cols, term->rows);
 }
 
 /*
@@ -2887,12 +2901,15 @@ static void do_paint(Terminal *term, Context ctx, int may_optimise)
                    tattr |= ATTR_WIDE;
 
            /* Video reversing things */
-           if (term->seltype == LEXICOGRAPHIC)
-               selected = (posle(term->selstart, scrpos) &&
-                           poslt(scrpos, term->selend));
-           else
-               selected = (posPle(term->selstart, scrpos) &&
-                           posPlt(scrpos, term->selend));
+           if (term->selstate == DRAGGING || term->selstate == SELECTED) {
+               if (term->seltype == LEXICOGRAPHIC)
+                   selected = (posle(term->selstart, scrpos) &&
+                               poslt(scrpos, term->selend));
+               else
+                   selected = (posPle(term->selstart, scrpos) &&
+                               posPlt(scrpos, term->selend));
+           } else
+               selected = FALSE;
            tattr = (tattr ^ rv
                     ^ (selected ? ATTR_REVERSE : 0));
 
@@ -3710,7 +3727,7 @@ void term_nopaste(Terminal *term)
     if (term->paste_len == 0)
        return;
     sfree(term->paste_buffer);
-    term->paste_buffer = 0;
+    term->paste_buffer = NULL;
     term->paste_len = 0;
 }
 
index 98ea4f2..42ccec1 100644 (file)
@@ -18,7 +18,6 @@
 #include <sys/ioctl.h>
 
 #include "putty.h"
-#include "terminal.h"
 
 #ifndef FALSE
 #define FALSE 0
@@ -60,6 +59,7 @@ static char pty_name[FILENAME_MAX];
 static int pty_stamped_utmp = 0;
 static int pty_child_pid;
 static int pty_utmp_helper_pid, pty_utmp_helper_pipe;
+static int pty_term_width, pty_term_height;
 static sig_atomic_t pty_child_dead;
 #ifndef OMIT_UTMP
 static struct utmp utmp_entry;
@@ -71,8 +71,6 @@ int pty_child_is_dead(void)
     return pty_child_dead;
 }
 
-static void pty_size(void);
-
 static void setup_utmp(char *ttyname, char *location)
 {
 #ifndef OMIT_UTMP
@@ -379,6 +377,9 @@ static char *pty_init(void *frontend,
     int slavefd;
     pid_t pid, pgrp;
 
+    pty_term_width = cfg.width;
+    pty_term_height = cfg.height;
+
     if (pty_master_fd < 0)
        pty_open_master();
 
@@ -519,14 +520,17 @@ static int pty_sendbuffer(void)
 /*
  * Called to set the size of the window
  */
-static void pty_size(void)
+static void pty_size(int width, int height)
 {
     struct winsize size;
 
-    size.ws_row = (unsigned short)term->rows;
-    size.ws_col = (unsigned short)term->cols;
-    size.ws_xpixel = (unsigned short) term->cols * font_dimension(0);
-    size.ws_ypixel = (unsigned short) term->rows * font_dimension(1);
+    pty_term_width = width;
+    pty_term_height = height;
+
+    size.ws_row = (unsigned short)pty_term_height;
+    size.ws_col = (unsigned short)pty_term_width;
+    size.ws_xpixel = (unsigned short) pty_term_width * font_dimension(0);
+    size.ws_ypixel = (unsigned short) pty_term_height * font_dimension(1);
     ioctl(pty_master_fd, TIOCSWINSZ, (void *)&size);
     return;
 }