Jacob's patch to make passphrase boxes work more sanely
[u/mdw/putty] / terminal.c
index 3762510..657aff7 100644 (file)
@@ -297,7 +297,7 @@ void term_init(void) {
 void term_size(int newrows, int newcols, int newsavelines) {
     tree234 *newsb, *newscreen, *newalt;
     unsigned long *newdisp, *newwant, *oldline, *line;
-    int i, j, crows, ccols;
+    int i, j, ccols;
     int posn, oldposn, furthest_back, oldsbsize;
     int save_alt_which = alt_which;
 
@@ -369,7 +369,7 @@ void term_size(int newrows, int newcols, int newsavelines) {
     for (i=0; i<newrows; i++) {
        line = smalloc(TSIZE * (newcols+1));
        for (j = 0; j <= newcols; j++)
-           line[i] = erase_char;
+           line[j] = erase_char;
        addpos234(newalt, line, i);
     }
     if (alt_screen) {
@@ -416,7 +416,6 @@ void term_size(int newrows, int newcols, int newsavelines) {
  */
 static void swap_screen (int which) {
     int t;
-    unsigned long tt;
     tree234 *ttr;
 
     if (which == alt_which)
@@ -442,7 +441,7 @@ static void swap_screen (int which) {
  * Update the scroll bar.
  */
 static void update_sbar(void) {
-    int nscreen, nscroll;
+    int nscroll;
 
     nscroll = count234(scrollback);
 
@@ -462,12 +461,17 @@ static void check_selection (pos from, pos to) {
  * Scroll the screen. (`lines' is +ve for scrolling forward, -ve
  * for backward.) `sb' is TRUE if the scrolling is permitted to
  * affect the scrollback buffer.
+ * 
+ * NB this function invalidates all pointers into lines of the
+ * screen data structures. In particular, you MUST call fix_cpos
+ * after calling scroll() and before doing anything else that
+ * uses the cpos shortcut pointer.
  */
 static void scroll (int topline, int botline, int lines, int sb) {
     unsigned long *line, *line2;
     int i;
 
-    if (topline != 0)
+    if (topline != 0 || alt_which != 0)
        sb = FALSE;
 
     if (lines < 0) {
@@ -593,7 +597,7 @@ static void save_cursor(int save) {
  * whole line, or parts thereof.
  */
 static void erase_lots (int line_only, int from_begin, int to_end) {
-    pos start, end, here;
+    pos start, end;
     int erase_lattr;
     unsigned long *ldata;
 
@@ -1245,12 +1249,14 @@ void term_out(void) {
                compatibility(VT102);
                if (curs.y <= marg_b)
                    scroll (curs.y, marg_b, -def(esc_args[0], 1), FALSE);
+                fix_cpos;
                seen_disp_event = TRUE;
                break;
              case 'M':                /* delete lines */
                compatibility(VT102);
                if (curs.y <= marg_b)
                    scroll (curs.y, marg_b, def(esc_args[0], 1), TRUE);
+                fix_cpos;
                seen_disp_event = TRUE;
                break;
              case '@':                /* insert chars */
@@ -1683,7 +1689,6 @@ void term_out(void) {
            break;
          case SEEN_ESCHASH:
            {
-               unsigned long *p;
                unsigned long nlattr;
                unsigned long *ldata;
                int i, j;
@@ -2037,7 +2042,7 @@ static void clipme(pos top, pos bottom, char *workbuf) {
     while (poslt(top, bottom)) {
        int nl = FALSE;
        unsigned long *ldata = lineptr(top.y);
-       pos lineend, nlpos;
+       pos nlpos;
 
        nlpos.y = top.y;
        nlpos.x = cols;
@@ -2112,7 +2117,6 @@ void term_copyall (void) {
  */
 static pos sel_spread_half (pos p, int dir) {
     unsigned long *ldata;
-    int x;
     short wvalue;
 
     ldata = lineptr(p.y);
@@ -2221,7 +2225,7 @@ void term_mouse (Mouse_Button b, Mouse_Action a, int x, int y) {
        } else {
            selstart = selanchor;
            selend = selpoint;
-           incpos(selpoint);
+           incpos(selend);
        }
        sel_spread();
     } else if ((b == MB_SELECT || b == MB_EXTEND) && a == MA_RELEASE) {