BSD 4_3_Net_2 release
[unix-history] / usr / src / lib / libcurses / refresh.c
index 3a29b57..a4937c5 100644 (file)
@@ -1,8 +1,43 @@
+/*
+ * Copyright (c) 1981 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)refresh.c  5.5 (Berkeley) 3/3/91";
+#endif /* not lint */
+
 /*
  * make the current screen look like "win" over the area coverd by
  * win.
 /*
  * make the current screen look like "win" over the area coverd by
  * win.
- *
- * %G% (Berkeley) @(#)refresh.c        1.7
  */
 
 # include      "curses.ext"
  */
 
 # include      "curses.ext"
@@ -19,11 +54,14 @@ STATIC bool curwin;
 
 WINDOW *_win = NULL;
 
 
 WINDOW *_win = NULL;
 
+STATIC int     domvcur(), makech();
+
 wrefresh(win)
 reg WINDOW     *win;
 {
        reg short       wy;
        reg int         retval;
 wrefresh(win)
 reg WINDOW     *win;
 {
        reg short       wy;
        reg int         retval;
+       reg WINDOW      *orig;
 
        /*
         * make sure were in visual state
 
        /*
         * make sure were in visual state
@@ -61,7 +99,7 @@ reg WINDOW    *win;
        }
        if (!CA) {
                if (win->_curx != 0)
        }
        if (!CA) {
                if (win->_curx != 0)
-                       putchar('\n');
+                       _putchar('\n');
                if (!curwin)
                        werase(curscr);
        }
                if (!curwin)
                        werase(curscr);
        }
@@ -71,32 +109,50 @@ reg WINDOW *win;
 # endif
        for (wy = 0; wy < win->_maxy; wy++) {
 # ifdef DEBUG
 # endif
        for (wy = 0; wy < win->_maxy; wy++) {
 # ifdef DEBUG
-               fprintf(outf, "%d\t%d\t%d\n", wy, win->_firstch[wy], win->_lastch[wy]);
+               fprintf(outf, "%d\t%d\t%d\n", wy, win->_firstch[wy],
+                       win->_lastch[wy]);
 # endif
                if (win->_firstch[wy] != _NOCHANGE)
                        if (makech(win, wy) == ERR)
                                return ERR;
 # endif
                if (win->_firstch[wy] != _NOCHANGE)
                        if (makech(win, wy) == ERR)
                                return ERR;
-                       else
-                               win->_firstch[wy] = _NOCHANGE;
+                       else {
+                               if (win->_firstch[wy] >= win->_ch_off)
+                                       win->_firstch[wy] = win->_maxx +
+                                                           win->_ch_off;
+                               if (win->_lastch[wy] < win->_maxx +
+                                                      win->_ch_off)
+                                       win->_lastch[wy] = win->_ch_off;
+                               if (win->_lastch[wy] < win->_firstch[wy])
+                                       win->_firstch[wy] = _NOCHANGE;
+                       }
+# ifdef DEBUG
+               fprintf(outf, "\t%d\t%d\n", win->_firstch[wy],
+                       win->_lastch[wy]);
+# endif
        }
        }
+
        if (win == curscr)
                domvcur(ly, lx, win->_cury, win->_curx);
        if (win == curscr)
                domvcur(ly, lx, win->_cury, win->_curx);
-       else if (win->_leave) {
-               curscr->_cury = ly;
-               curscr->_curx = lx;
-               ly -= win->_begy;
-               lx -= win->_begx;
-               if (ly >= 0 && ly < win->_maxy && lx >= 0 && lx < win->_maxx) {
-                       win->_cury = ly;
-                       win->_curx = lx;
-               }
-               else
-                       win->_cury = win->_curx = 0;
-       }
        else {
        else {
-               domvcur(ly, lx, win->_cury+win->_begy, win->_curx+win->_begx);
-               curscr->_cury = win->_cury + win->_begy;
-               curscr->_curx = win->_curx + win->_begx;
+               if (win->_leave) {
+                       curscr->_cury = ly;
+                       curscr->_curx = lx;
+                       ly -= win->_begy;
+                       lx -= win->_begx;
+                       if (ly >= 0 && ly < win->_maxy && lx >= 0 &&
+                           lx < win->_maxx) {
+                               win->_cury = ly;
+                               win->_curx = lx;
+                       }
+                       else
+                               win->_cury = win->_curx = 0;
+               }
+               else {
+                       domvcur(ly, lx, win->_cury + win->_begy,
+                               win->_curx + win->_begx);
+                       curscr->_cury = win->_cury + win->_begy;
+                       curscr->_curx = win->_curx + win->_begx;
+               }
        }
        retval = OK;
 ret:
        }
        retval = OK;
 ret:
@@ -117,13 +173,23 @@ short             wy;
        reg short       wx, lch, y;
        reg int         nlsp, clsp;     /* last space in lines          */
 
        reg short       wx, lch, y;
        reg int         nlsp, clsp;     /* last space in lines          */
 
-       wx = win->_firstch[wy];
+       wx = win->_firstch[wy] - win->_ch_off;
+       if (wx >= win->_maxx)
+               return OK;
+       else if (wx < 0)
+               wx = 0;
+       lch = win->_lastch[wy] - win->_ch_off;
+       if (lch < 0)
+               return OK;
+       else if (lch >= win->_maxx)
+               lch = win->_maxx - 1;;
        y = wy + win->_begy;
        y = wy + win->_begy;
-       lch = win->_lastch[wy];
+
        if (curwin)
                csp = " ";
        else
                csp = &curscr->_y[wy + win->_begy][wx + win->_begx];
        if (curwin)
                csp = " ";
        else
                csp = &curscr->_y[wy + win->_begy][wx + win->_begx];
+
        nsp = &win->_y[wy][wx];
        if (CE && !curwin) {
                for (ce = &win->_y[wy][win->_maxx - 1]; *ce == ' '; ce--)
        nsp = &win->_y[wy][wx];
        if (CE && !curwin) {
                for (ce = &win->_y[wy][win->_maxx - 1]; *ce == ' '; ce--)
@@ -131,10 +197,12 @@ short             wy;
                                break;
                nlsp = ce - win->_y[wy];
        }
                                break;
                nlsp = ce - win->_y[wy];
        }
+
        if (!curwin)
                ce = CE;
        else
                ce = NULL;
        if (!curwin)
                ce = CE;
        else
                ce = NULL;
+
        while (wx <= lch) {
                if (*nsp != *csp) {
                        domvcur(ly, lx, y, wx + win->_begx);
        while (wx <= lch) {
                if (*nsp != *csp) {
                        domvcur(ly, lx, y, wx + win->_begx);
@@ -165,7 +233,7 @@ short               wy;
                                                lx = wx + win->_begx;
                                                while (wx++ <= clsp)
                                                        *csp++ = ' ';
                                                lx = wx + win->_begx;
                                                while (wx++ <= clsp)
                                                        *csp++ = ' ';
-                                               goto ret;
+                                               return OK;
                                        }
                                        ce = NULL;
                                }
                                        }
                                        ce = NULL;
                                }
@@ -192,10 +260,9 @@ short              wy;
                                                        curscr->_flags &= ~_STANDOUT;
                                                    }
                                            if (!curwin)
                                                        curscr->_flags &= ~_STANDOUT;
                                                    }
                                            if (!curwin)
-                                               putchar((*csp = *nsp) & 0177);
+                                               _putchar((*csp = *nsp) & 0177);
                                            else
                                            else
-                                               putchar(*nsp & 0177);
-                                           scroll(win);
+                                               _putchar(*nsp & 0177);
                                            if (win->_flags&_FULLWIN && !curwin)
                                                scroll(curscr);
                                            ly = win->_begy+win->_cury;
                                            if (win->_flags&_FULLWIN && !curwin)
                                                scroll(curscr);
                                            ly = win->_begy+win->_cury;
@@ -207,11 +274,15 @@ short             wy;
                                            return ERR;
                                        }
                                if (!curwin)
                                            return ERR;
                                        }
                                if (!curwin)
-                                       putchar((*csp++ = *nsp) & 0177);
+                                       _putchar((*csp++ = *nsp) & 0177);
                                else
                                else
-                                       putchar(*nsp & 0177);
+                                       _putchar(*nsp & 0177);
+# ifdef FULLDEBUG
+                               fprintf(outf,
+                                       "MAKECH:putchar(%c)\n", *nsp & 0177);
+# endif
                                if (UC && (*nsp & _STANDOUT)) {
                                if (UC && (*nsp & _STANDOUT)) {
-                                       putchar('\b');
+                                       _putchar('\b');
                                        _puts(UC);
                                }
                                nsp++;
                                        _puts(UC);
                                }
                                nsp++;
@@ -222,9 +293,21 @@ short              wy;
                        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) {
+                               lx = 0;
+                               ly++;
+                               /*
+                                * xn glitch: chomps a newline after auto-wrap.
+                                * we just feed it now and forget about it.
+                                */
+                               if (XN) {
+                                       _putchar('\n');
+                                       _putchar('\r');
+                               }
+                       }
                }
                }
-               else if (wx < lch)
-                       while (*nsp == *csp) {
+               else if (wx <= lch)
+                       while (*nsp == *csp && wx <= lch) {
                                nsp++;
                                if (!curwin)
                                        csp++;
                                nsp++;
                                if (!curwin)
                                        csp++;
@@ -236,19 +319,16 @@ short             wy;
                fprintf(outf, "MAKECH: 3: wx = %d, lx = %d\n", wx, lx);
 # endif        
        }
                fprintf(outf, "MAKECH: 3: wx = %d, lx = %d\n", wx, lx);
 # endif        
        }
-ret:
        return OK;
 }
 
 /*
  * perform a mvcur, leaving standout mode if necessary
  */
        return OK;
 }
 
 /*
  * perform a mvcur, leaving standout mode if necessary
  */
-static
+STATIC
 domvcur(oy, ox, ny, nx)
 int    oy, ox, ny, nx; {
 
 domvcur(oy, ox, ny, nx)
 int    oy, ox, ny, nx; {
 
-       if (ny == 0 && nx == 0)
-               abort();
        if (curscr->_flags & _STANDOUT && !MS) {
                _puts(SE);
                curscr->_flags &= ~_STANDOUT;
        if (curscr->_flags & _STANDOUT && !MS) {
                _puts(SE);
                curscr->_flags &= ~_STANDOUT;