4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / lib / libcurses / refresh.c
index 29b6282..6de5beb 100644 (file)
@@ -1,12 +1,12 @@
 /*
 /*
- * Copyright (c) 1981 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1981, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
  *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)refresh.c  5.34 (Berkeley) %G%";
+static char sccsid[] = "@(#)refresh.c  8.1 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <curses.h>
 #endif /* not lint */
 
 #include <curses.h>
@@ -15,8 +15,6 @@ static char sccsid[] = "@(#)refresh.c 5.34 (Berkeley) %G%";
 static int curwin;
 static short ly, lx;
 
 static int curwin;
 static short ly, lx;
 
-WINDOW *_win;
-
 static void    domvcur __P((int, int, int, int));
 static int     makech __P((WINDOW *, int));
 static void    quickch __P((WINDOW *));        
 static void    domvcur __P((int, int, int, int));
 static int     makech __P((WINDOW *, int));
 static void    quickch __P((WINDOW *));        
@@ -40,7 +38,6 @@ wrefresh(win)
        ly = curscr->cury;
        lx = curscr->curx;
        wy = 0;
        ly = curscr->cury;
        lx = curscr->curx;
        wy = 0;
-       _win = win;
        curwin = (win == curscr);
 
        if (!curwin)
        curwin = (win == curscr);
 
        if (!curwin)
@@ -48,7 +45,7 @@ wrefresh(win)
                        wlp = win->lines[wy];
                        if (wlp->flags & __ISDIRTY)
                                wlp->hash = 
                        wlp = win->lines[wy];
                        if (wlp->flags & __ISDIRTY)
                                wlp->hash = 
-                                  __hash(wlp->line, win->maxx * __LDATASIZE);
+                                  __hash((char *) wlp->line, win->maxx * __LDATASIZE);
                }
 
        if (win->flags & __CLEAROK || curscr->flags & __CLEAROK || curwin) {
                }
 
        if (win->flags & __CLEAROK || curscr->flags & __CLEAROK || curwin) {
@@ -73,8 +70,8 @@ wrefresh(win)
                        werase(curscr);
        }
 #ifdef DEBUG
                        werase(curscr);
        }
 #ifdef DEBUG
-       __TRACE("wrefresh: (%0.2o): curwin = %d\n", win, curwin);
-       __TRACE("wrefresh: \tfirstch\tlastch\n");
+       __CTRACE("wrefresh: (%0.2o): curwin = %d\n", win, curwin);
+       __CTRACE("wrefresh: \tfirstch\tlastch\n");
 #endif
 
 #ifndef NOQCH
 #endif
 
 #ifndef NOQCH
@@ -90,14 +87,44 @@ wrefresh(win)
                        quickch(win);
        }
 #endif
                        quickch(win);
        }
 #endif
+
+#ifdef DEBUG
+{ int i, j;
+               __CTRACE("#####################################\n");
+               for (i = 0; i < curscr->maxy; i++) {
+                       __CTRACE("C: %d:", i);
+                       __CTRACE(" 0x%x \n", curscr->lines[i]->hash);
+                       for (j = 0; j < curscr->maxx; j++) 
+                               __CTRACE("%c", 
+                                  curscr->lines[i]->line[j].ch);
+                       __CTRACE("\n");
+                       for (j = 0; j < curscr->maxx; j++) 
+                               __CTRACE("%x", 
+                                  curscr->lines[i]->line[j].attr);
+                       __CTRACE("\n");
+                       __CTRACE("W: %d:", i);
+                       __CTRACE(" 0x%x \n", win->lines[i]->hash);
+                       __CTRACE(" 0x%x ", win->lines[i]->flags);
+                       for (j = 0; j < win->maxx; j++) 
+                               __CTRACE("%c", 
+                                  win->lines[i]->line[j].ch);
+                       __CTRACE("\n");
+                       for (j = 0; j < win->maxx; j++) 
+                               __CTRACE("%x", 
+                                  win->lines[i]->line[j].attr);
+                       __CTRACE("\n");
+               }
+}
+#endif /* DEBUG */
+
        for (wy = 0; wy < win->maxy; wy++) {
 #ifdef DEBUG
        for (wy = 0; wy < win->maxy; wy++) {
 #ifdef DEBUG
-               __TRACE("%d\t%d\t%d\n",
+               __CTRACE("%d\t%d\t%d\n",
                    wy, *win->lines[wy]->firstchp, *win->lines[wy]->lastchp);
 #endif
                if (!curwin)
                        curscr->lines[wy]->hash = win->lines[wy]->hash;
                    wy, *win->lines[wy]->firstchp, *win->lines[wy]->lastchp);
 #endif
                if (!curwin)
                        curscr->lines[wy]->hash = win->lines[wy]->hash;
-               if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT))
+               if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT)) {
                        if (makech(win, wy) == ERR)
                                return (ERR);
                        else {
                        if (makech(win, wy) == ERR)
                                return (ERR);
                        else {
@@ -110,19 +137,21 @@ wrefresh(win)
                                if (*win->lines[wy]->lastchp < 
                                    *win->lines[wy]->firstchp) {
 #ifdef DEBUG
                                if (*win->lines[wy]->lastchp < 
                                    *win->lines[wy]->firstchp) {
 #ifdef DEBUG
-                                       __TRACE("wrefresh: line %d notdirty \n", wy);
+                                       __CTRACE("wrefresh: line %d notdirty \n", wy);
 #endif
                                        win->lines[wy]->flags &= ~__ISDIRTY;
                                }
                        }
 #endif
                                        win->lines[wy]->flags &= ~__ISDIRTY;
                                }
                        }
+
+               }
 #ifdef DEBUG
 #ifdef DEBUG
-               __TRACE("\t%d\t%d\n", *win->lines[wy]->firstchp, 
+               __CTRACE("\t%d\t%d\n", *win->lines[wy]->firstchp, 
                        *win->lines[wy]->lastchp);
 #endif
        }
        
 #ifdef DEBUG
                        *win->lines[wy]->lastchp);
 #endif
        }
        
 #ifdef DEBUG
-       __TRACE("refresh: ly=%d, lx=%d\n", ly, lx);
+       __CTRACE("refresh: ly=%d, lx=%d\n", ly, lx);
 #endif
 
        if (win == curscr)
 #endif
 
        if (win == curscr)
@@ -148,7 +177,6 @@ wrefresh(win)
        }
        retval = OK;
 
        }
        retval = OK;
 
-       _win = NULL;
        (void)fflush(stdout);
        return (retval);
 }
        (void)fflush(stdout);
        return (retval);
 }
@@ -162,31 +190,28 @@ makech(win, wy)
        register WINDOW *win;
        int wy;
 {
        register WINDOW *win;
        int wy;
 {
-       register int nlsp;              /* Last space in lines. */
-       register short wx, lch, y;
-       register __LDATA *nsp, *csp, *cp;
+       static __LDATA blank = {' ', 0};
+       register int nlsp, clsp;                /* Last space in lines. */
+       register int wx, lch, y;
+       register __LDATA *nsp, *csp, *cp, *cep;
        u_int force;
        char *ce;
        u_int force;
        char *ce;
-       __LDATA blank = {' ', 0};
 
        /* Is the cursor still on the end of the last line? */
        if (wy > 0 && win->lines[wy - 1]->flags & __ISPASTEOL) {
 
        /* Is the cursor still on the end of the last line? */
        if (wy > 0 && win->lines[wy - 1]->flags & __ISPASTEOL) {
-               win->lines[wy - 1]->flags &= ~__ISPASTEOL;
                domvcur(ly, lx, ly + 1, 0);
                ly++;
                lx = 0;
        }
                domvcur(ly, lx, ly + 1, 0);
                ly++;
                lx = 0;
        }
-       if (!(win->lines[wy]->flags & __ISDIRTY))
-               return (OK);
        wx = *win->lines[wy]->firstchp - win->ch_off;
        wx = *win->lines[wy]->firstchp - win->ch_off;
-       if (wx >= win->maxx)
-               return (OK);
-       else if (wx < 0)
+       if (wx < 0)
                wx = 0;
                wx = 0;
+       else if (wx >= win->maxx)
+               return (OK);
        lch = *win->lines[wy]->lastchp - win->ch_off;
        if (lch < 0)
                return (OK);
        lch = *win->lines[wy]->lastchp - win->ch_off;
        if (lch < 0)
                return (OK);
-       else if (lch >= win->maxx)
+       else if (lch >= (int) win->maxx)
                lch = win->maxx - 1;
        y = wy + win->begy;
 
                lch = win->maxx - 1;
        y = wy + win->begy;
 
@@ -215,14 +240,14 @@ makech(win, wy)
                        tputs(tgoto(CM, lx, ly), 0, __cputchar);
                else {
                        tputs(HO, 0, __cputchar);
                        tputs(tgoto(CM, lx, ly), 0, __cputchar);
                else {
                        tputs(HO, 0, __cputchar);
-                       mvcur(0, 0, ly, lx);
+                       __mvcur(0, 0, ly, lx, 1);
                }
        }
        while (wx <= lch) {
                if (!force && memcmp(nsp, csp, sizeof(__LDATA)) == 0) {
                        if (wx <= lch) {
                }
        }
        while (wx <= lch) {
                if (!force && memcmp(nsp, csp, sizeof(__LDATA)) == 0) {
                        if (wx <= lch) {
-                               while (memcmp(nsp, csp, sizeof(__LDATA)) == 0 &&
-                                   wx <= lch) {
+                               while (wx <= lch &&
+                                      memcmp(nsp, csp, sizeof(__LDATA)) == 0) {
                                            nsp++;
                                            if (!curwin)
                                                    csp++;
                                            nsp++;
                                            if (!curwin)
                                                    csp++;
@@ -235,7 +260,7 @@ makech(win, wy)
                domvcur(ly, lx, y, wx + win->begx);
 
 #ifdef DEBUG
                domvcur(ly, lx, y, wx + win->begx);
 
 #ifdef DEBUG
-               __TRACE("makech: 1: wx = %d, ly= %d, lx = %d, newy = %d, newx = %d, force =%d\n", 
+               __CTRACE("makech: 1: wx = %d, ly= %d, lx = %d, newy = %d, newx = %d, force =%d\n", 
                    wx, ly, lx, y, wx + win->begx, force);
 #endif
                ly = y;
                    wx, ly, lx, y, wx + win->begx, force);
 #endif
                ly = y;
@@ -243,6 +268,36 @@ makech(win, wy)
                while ((force || memcmp(nsp, csp, sizeof(__LDATA)) != 0) 
                    && wx <= lch) {
 
                while ((force || memcmp(nsp, csp, sizeof(__LDATA)) != 0) 
                    && wx <= lch) {
 
+                       if (ce != NULL && win->maxx + win->begx == 
+                           curscr->maxx && wx >= nlsp && nsp->ch == ' ') {
+                               /* Check for clear to end-of-line. */
+                               cep = &curscr->lines[wy]->line[win->maxx - 1];
+                               while (cep->ch == ' ' && cep->attr == 0)
+                                       if (cep-- <= csp)
+                                               break;
+                               clsp = cep - curscr->lines[wy]->line - 
+                                      win->begx * __LDATASIZE;
+#ifdef DEBUG
+                       __CTRACE("makech: clsp = %d, nlsp = %d\n", clsp, nlsp);
+#endif
+                               if ((clsp - nlsp >= strlen(CE) 
+                                   && clsp < win->maxx * __LDATASIZE) ||
+                                   wy == win->maxy - 1) {
+#ifdef DEBUG
+                                       __CTRACE("makech: using CE\n");
+#endif
+                                       tputs(CE, 0, __cputchar);
+                                       lx = wx + win->begx;
+                                       while (wx++ <= clsp) {
+                                               csp->ch = ' ';
+                                               csp->attr = 0;
+                                               csp++;
+                                       }
+                                       return (OK);
+                               }
+                               ce = NULL;
+                       }
+
                        /* Enter/exit standout mode as appropriate. */
                        if (SO && (nsp->attr & __STANDOUT) !=
                            (curscr->flags & __WSTANDOUT)) {
                        /* Enter/exit standout mode as appropriate. */
                        if (SO && (nsp->attr & __STANDOUT) !=
                            (curscr->flags & __WSTANDOUT)) {
@@ -266,12 +321,13 @@ makech(win, wy)
                                                        curscr->flags &=
                                                            ~__WSTANDOUT;
                                                }
                                                        curscr->flags &=
                                                            ~__WSTANDOUT;
                                                }
-                                       if (!curwin) {
-                                               csp->attr = nsp->attr;
-                                               putchar(csp->ch = nsp->ch);
-                                       } else
-                                               putchar(nsp->ch);
-
+                                       if (!(win->flags & __SCROLLWIN)) {
+                                               if (!curwin) {
+                                                       csp->attr = nsp->attr;
+                                                       putchar(csp->ch = nsp->ch);
+                                               } else
+                                                       putchar(nsp->ch);
+                                       }
                                        if (wx + win->begx < curscr->maxx) {
                                                domvcur(ly, wx + win->begx, 
                                                    win->begy + win->maxy - 1,
                                        if (wx + win->begx < curscr->maxx) {
                                                domvcur(ly, wx + win->begx, 
                                                    win->begy + win->maxy - 1,
@@ -280,46 +336,40 @@ makech(win, wy)
                                        ly = win->begy + win->maxy - 1;
                                        lx = win->begx + win->maxx - 1;
                                        return (OK);
                                        ly = win->begy + win->maxy - 1;
                                        lx = win->begx + win->maxx - 1;
                                        return (OK);
-                               } else
-                                       if (win->flags & __SCROLLWIN) {
-                                               lx = --wx;
-                                               return (ERR);
-                                       }
-                       if (!curwin) {
-                               csp->attr = nsp->attr;
-                               putchar(csp->ch = nsp->ch);
-                               csp++;
-                       } else
-                               putchar(nsp->ch);
-                       
+                               } 
+                       if (wx < win->maxx || wy < win->maxy - 1 || 
+                           !(win->flags & __SCROLLWIN)) {
+                               if (!curwin) {
+                                       csp->attr = nsp->attr;
+                                       putchar(csp->ch = nsp->ch);
+                                       csp++;
+                               } else 
+                                       putchar(nsp->ch);
+                       }
 #ifdef DEBUG
 #ifdef DEBUG
-                       __TRACE("makech: putchar(%c)\n", nsp->ch & 0177);
+                       __CTRACE("makech: putchar(%c)\n", nsp->ch & 0177);
 #endif
                        if (UC && (nsp->attr & __STANDOUT)) {
                                putchar('\b');
                                tputs(UC, 0, __cputchar);
                        }
                        nsp++;
 #endif
                        if (UC && (nsp->attr & __STANDOUT)) {
                                putchar('\b');
                                tputs(UC, 0, __cputchar);
                        }
                        nsp++;
-               }
 #ifdef DEBUG
 #ifdef DEBUG
-               __TRACE("makech: 2: wx = %d, lx = %d\n", wx, lx);
+               __CTRACE("makech: 2: wx = %d, lx = %d\n", wx, lx);
 #endif
 #endif
+               }
                if (lx == wx + win->begx)       /* If no change. */
                        break;
                lx = wx + win->begx;
                if (lx == wx + win->begx)       /* If no change. */
                        break;
                lx = wx + win->begx;
-               if (lx >= COLS && AM) {
-                       if (wy != LINES)
-                               win->lines[wy]->flags |= __ISPASTEOL;
+               if (lx >= COLS && AM)
                        lx = COLS - 1;
                        lx = COLS - 1;
-               } else if (wx >= win->maxx) {
-                       if (wy != win->maxy)
-                               win->lines[wy]->flags |= __ISPASTEOL;
+               else if (wx >= win->maxx) {
                        domvcur(ly, lx, ly, win->maxx + win->begx - 1);
                        lx = win->maxx + win->begx - 1;
                }
 
 #ifdef DEBUG
                        domvcur(ly, lx, ly, win->maxx + win->begx - 1);
                        lx = win->maxx + win->begx - 1;
                }
 
 #ifdef DEBUG
-               __TRACE("makech: 3: wx = %d, lx = %d\n", wx, lx);
+               __CTRACE("makech: 3: wx = %d, lx = %d\n", wx, lx);
 #endif
        }
        return (OK);
 #endif
        }
        return (OK);
@@ -338,7 +388,7 @@ domvcur(oy, ox, ny, nx)
                curscr->flags &= ~__WSTANDOUT;
        }
 
                curscr->flags &= ~__WSTANDOUT;
        }
 
-       mvcur(oy, ox, ny, nx);
+       __mvcur(oy, ox, ny, nx, 1);
 }
 
 /*
 }
 
 /*
@@ -347,7 +397,6 @@ domvcur(oy, ox, ny, nx)
  * repainting the screen line by line.
  */
 
  * repainting the screen line by line.
  */
 
-
 static void
 quickch(win)
        WINDOW *win;
 static void
 quickch(win)
        WINDOW *win;
@@ -385,6 +434,17 @@ quickch(win)
                else
                        win->lines[bot]->flags &= ~__ISDIRTY;
 
                else
                        win->lines[bot]->flags &= ~__ISDIRTY;
 
+#ifdef NO_JERKINESS
+       /*
+        * If we have a bottom unchanged region return.  Scrolling the
+        * bottom region up and then back down causes a screen jitter.
+        * This will increase the number of characters sent to the screen
+        * but it looks better.
+        */
+       if (bot < win->maxy - 1)
+               return;
+#endif /* NO_JERKINESS */
+
        /*
         * Search for the largest block of text not changed.
         * Invariants of the loop:
        /*
         * Search for the largest block of text not changed.
         * Invariants of the loop:
@@ -420,7 +480,7 @@ quickch(win)
                return;
 
 #ifdef DEBUG
                return;
 
 #ifdef DEBUG
-       __TRACE("quickch:bsize=%d,starts=%d,startw=%d,curw=%d,curs=%d,top=%d,bot=%d\n", 
+       __CTRACE("quickch:bsize=%d,starts=%d,startw=%d,curw=%d,curs=%d,top=%d,bot=%d\n", 
                bsize, starts, startw, curw, curs, top, bot);
 #endif
 
                bsize, starts, startw, curw, curs, top, bot);
 #endif
 
@@ -436,40 +496,38 @@ quickch(win)
        n = startw - starts;
 
 #ifdef DEBUG
        n = startw - starts;
 
 #ifdef DEBUG
-               __TRACE("#####################################\n");
+               __CTRACE("#####################################\n");
                for (i = 0; i < curscr->maxy; i++) {
                for (i = 0; i < curscr->maxy; i++) {
-                       __TRACE("C: %d:", i);
-                       __TRACE(" 0x%x \n", curscr->lines[i]->hash);
+                       __CTRACE("C: %d:", i);
+                       __CTRACE(" 0x%x \n", curscr->lines[i]->hash);
                        for (j = 0; j < curscr->maxx; j++) 
                        for (j = 0; j < curscr->maxx; j++) 
-                               __TRACE("%c", 
+                               __CTRACE("%c", 
                                   curscr->lines[i]->line[j].ch);
                                   curscr->lines[i]->line[j].ch);
-                       __TRACE("\n");
+                       __CTRACE("\n");
                        for (j = 0; j < curscr->maxx; j++) 
                        for (j = 0; j < curscr->maxx; j++) 
-                               __TRACE("%x", 
+                               __CTRACE("%x", 
                                   curscr->lines[i]->line[j].attr);
                                   curscr->lines[i]->line[j].attr);
-                       __TRACE("\n");
-                       __TRACE("W: %d:", i);
-                       __TRACE(" 0x%x \n", win->lines[i]->hash);
-                       __TRACE(" 0x%x ", win->lines[i]->flags);
+                       __CTRACE("\n");
+                       __CTRACE("W: %d:", i);
+                       __CTRACE(" 0x%x \n", win->lines[i]->hash);
+                       __CTRACE(" 0x%x ", win->lines[i]->flags);
                        for (j = 0; j < win->maxx; j++) 
                        for (j = 0; j < win->maxx; j++) 
-                               __TRACE("%c", 
+                               __CTRACE("%c", 
                                   win->lines[i]->line[j].ch);
                                   win->lines[i]->line[j].ch);
-                       __TRACE("\n");
+                       __CTRACE("\n");
                        for (j = 0; j < win->maxx; j++) 
                        for (j = 0; j < win->maxx; j++) 
-                               __TRACE("%x", 
+                               __CTRACE("%x", 
                                   win->lines[i]->line[j].attr);
                                   win->lines[i]->line[j].attr);
-                       __TRACE("\n");
+                       __CTRACE("\n");
                }
 #endif 
                }
 #endif 
-       if (n != 0)
-               scrolln(win, starts, startw, curs, bot, top);
        
        /* So we don't have to call __hash() each time */
        for (i = 0; i < win->maxx; i++) {
                buf[i].ch = ' ';
                buf[i].attr = 0;
        }
        
        /* So we don't have to call __hash() each time */
        for (i = 0; i < win->maxx; i++) {
                buf[i].ch = ' ';
                buf[i].attr = 0;
        }
-       blank_hash = __hash(buf, win->maxx * __LDATASIZE);
+       blank_hash = __hash((char *) buf, win->maxx * __LDATASIZE);
 
        /*
         * Perform the rotation to maintain the consistency of curscr.
 
        /*
         * Perform the rotation to maintain the consistency of curscr.
@@ -514,13 +572,13 @@ quickch(win)
                /* Mark block as clean and blank out scrolled lines. */
                clp = curscr->lines[target];
 #ifdef DEBUG
                /* Mark block as clean and blank out scrolled lines. */
                clp = curscr->lines[target];
 #ifdef DEBUG
-               __TRACE("quickch: n=%d startw=%d curw=%d i = %d target=%d ",
+               __CTRACE("quickch: n=%d startw=%d curw=%d i = %d target=%d ",
                        n, startw, curw, i, target);
 #endif
                if ((target >= startw && target < curw) || target < top 
                    || target > bot) {
 #ifdef DEBUG
                        n, startw, curw, i, target);
 #endif
                if ((target >= startw && target < curw) || target < top 
                    || target > bot) {
 #ifdef DEBUG
-                       __TRACE("-- notdirty");
+                       __CTRACE("-- notdirty");
 #endif
                        win->lines[target]->flags &= ~__ISDIRTY;
                } else if ((n > 0 && target >= top && target < top + n) ||
 #endif
                        win->lines[target]->flags &= ~__ISDIRTY;
                } else if ((n > 0 && target >= top && target < top + n) ||
@@ -530,24 +588,24 @@ quickch(win)
                                (void)memcpy(clp->line,  buf,
                                    win->maxx * __LDATASIZE);
 #ifdef DEBUG
                                (void)memcpy(clp->line,  buf,
                                    win->maxx * __LDATASIZE);
 #ifdef DEBUG
-                               __TRACE("-- blanked out: dirty");
+                               __CTRACE("-- blanked out: dirty");
 #endif
                                clp->hash = blank_hash;
                                __touchline(win, target, 0, win->maxx - 1, 0);
                        } else {
                                __touchline(win, target, 0, win->maxx - 1, 0);
 #ifdef DEBUG
 #endif
                                clp->hash = blank_hash;
                                __touchline(win, target, 0, win->maxx - 1, 0);
                        } else {
                                __touchline(win, target, 0, win->maxx - 1, 0);
 #ifdef DEBUG
-                               __TRACE(" -- blank line already: dirty");
+                               __CTRACE(" -- blank line already: dirty");
 #endif
                        }
                } else {
 #ifdef DEBUG
 #endif
                        }
                } else {
 #ifdef DEBUG
-                       __TRACE(" -- dirty");
+                       __CTRACE(" -- dirty");
 #endif
                        __touchline(win, target, 0, win->maxx - 1, 0);
                }
 #ifdef DEBUG
 #endif
                        __touchline(win, target, 0, win->maxx - 1, 0);
                }
 #ifdef DEBUG
-               __TRACE("\n");
+               __CTRACE("\n");
 #endif
                if (target == cur_period) {
                        i = target + 1;
 #endif
                if (target == cur_period) {
                        i = target + 1;
@@ -559,20 +617,30 @@ quickch(win)
                }
        }
 #ifdef DEBUG
                }
        }
 #ifdef DEBUG
-               __TRACE("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
+               __CTRACE("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
                for (i = 0; i < curscr->maxy; i++) {
                for (i = 0; i < curscr->maxy; i++) {
-                       __TRACE("C: %d:", i);
+                       __CTRACE("C: %d:", i);
                        for (j = 0; j < curscr->maxx; j++) 
                        for (j = 0; j < curscr->maxx; j++) 
-                               __TRACE("%c", 
+                               __CTRACE("%c", 
                                   curscr->lines[i]->line[j].ch);
                                   curscr->lines[i]->line[j].ch);
-                       __TRACE("\n");
-                       __TRACE("W: %d:", i);
+                       __CTRACE("\n");
+                       __CTRACE("W: %d:", i);
                        for (j = 0; j < win->maxx; j++) 
                        for (j = 0; j < win->maxx; j++) 
-                               __TRACE("%c", 
+                               __CTRACE("%c", 
                                   win->lines[i]->line[j].ch);
                                   win->lines[i]->line[j].ch);
-                       __TRACE("\n");
+                       __CTRACE("\n");
                }
 #endif
                }
 #endif
+       if (n != 0) {
+               WINDOW *wp;
+               scrolln(win, starts, startw, curs, bot, top);
+               /*
+                * Need to repoint any subwindow lines to the rotated
+                * line structured. 
+                */
+               for (wp = win->nextp; wp != win; wp = wp->nextp)
+                       __set_subwin(win, wp);
+       }
 }
 
 /*
 }
 
 /*
@@ -590,7 +658,7 @@ scrolln(win, starts, startw, curs, bot, top)
        n = starts - startw;
 
        if (n > 0) {
        n = starts - startw;
 
        if (n > 0) {
-               mvcur(oy, ox, top, 0);
+               __mvcur(oy, ox, top, 0, 1);
                /* Scroll up the block */
                if (DL)
                        tputs(__tscroll(DL, n), 0, __cputchar);
                /* Scroll up the block */
                if (DL)
                        tputs(__tscroll(DL, n), 0, __cputchar);
@@ -601,22 +669,22 @@ scrolln(win, starts, startw, curs, bot, top)
                /* 
                 * Push down the bottom region.
                 */
                /* 
                 * Push down the bottom region.
                 */
-               mvcur(top, 0, bot - n + 1, 0);
+               __mvcur(top, 0, bot - n + 1, 0, 1);
                if (AL) 
                        tputs(__tscroll(AL, n), 0, __cputchar);
                else
                        for(i = 0; i < n; i++)
                                tputs(al, 0, __cputchar);
                if (AL) 
                        tputs(__tscroll(AL, n), 0, __cputchar);
                else
                        for(i = 0; i < n; i++)
                                tputs(al, 0, __cputchar);
-               mvcur(bot - n + 1, 0, oy, ox);
+               __mvcur(bot - n + 1, 0, oy, ox, 1);
        } else {
                /* Preserve the bottom lines */
        } else {
                /* Preserve the bottom lines */
-               mvcur(oy, ox, bot + n + 1, 0);  /* n < 0 */
+               __mvcur(oy, ox, bot + n + 1, 0, 1);     /* n < 0 */
                if (DL)
                        tputs(__tscroll(DL, -n), 0, __cputchar);
                else
                        for(i = n; i < 0; i++)
                                tputs(dl, 0, __cputchar);
                if (DL)
                        tputs(__tscroll(DL, -n), 0, __cputchar);
                else
                        for(i = n; i < 0; i++)
                                tputs(dl, 0, __cputchar);
-               mvcur(bot + n + 1, 0, top, 0);
+               __mvcur(bot + n + 1, 0, top, 0, 1);
 
                /* Scroll the block down */
                if (AL) 
 
                /* Scroll the block down */
                if (AL) 
@@ -624,8 +692,6 @@ scrolln(win, starts, startw, curs, bot, top)
                else
                        for(i = n; i < 0; i++)
                                tputs(al, 0, __cputchar);
                else
                        for(i = n; i < 0; i++)
                                tputs(al, 0, __cputchar);
-               mvcur(top, 0, oy, ox);
+               __mvcur(top, 0, oy, ox, 1);
        }               
 }
        }               
 }
-
-