BSD 4_4 release
[unix-history] / usr / src / lib / libcurses / newwin.c
index 40df07d..a2f577a 100644 (file)
@@ -1,12 +1,38 @@
 /*
 /*
- * 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%
+ * 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
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)newwin.c   5.17 (Berkeley) %G%";
+static char sccsid[] = "@(#)newwin.c   8.1 (Berkeley) 7/20/93";
 #endif /* not lint */
 
 #include <curses.h>
 #endif /* not lint */
 
 #include <curses.h>
@@ -41,12 +67,14 @@ newwin(nl, nc, by, bx)
 
        win->nextp = win;
        win->ch_off = 0;
 
        win->nextp = win;
        win->ch_off = 0;
+       win->orig = NULL;
 
 #ifdef DEBUG
        __CTRACE("newwin: win->ch_off = %d\n", win->ch_off);
 #endif
 
 
 #ifdef DEBUG
        __CTRACE("newwin: win->ch_off = %d\n", win->ch_off);
 #endif
 
-       for (lp = win->lines[0], i = 0; i < nl; i++, lp = win->lines[i]) {
+       for (i = 0; i < nl; i++) {
+               lp = win->lines[i];
                lp->flags = 0;
                for (sp = lp->line, j = 0; j < nc; j++, sp++) {
                        sp->ch = ' ';
                lp->flags = 0;
                for (sp = lp->line, j = 0; j < nc; j++, sp++) {
                        sp->ch = ' ';
@@ -62,6 +90,8 @@ subwin(orig, nl, nc, by, bx)
        register WINDOW *orig;
        register int by, bx, nl, nc;
 {
        register WINDOW *orig;
        register int by, bx, nl, nc;
 {
+       int i;
+       __LINE *lp;
        register WINDOW *win;
 
        /* Make sure window fits inside the original one. */
        register WINDOW *win;
 
        /* Make sure window fits inside the original one. */
@@ -81,6 +111,10 @@ subwin(orig, nl, nc, by, bx)
        win->nextp = orig->nextp;
        orig->nextp = win;
        win->orig = orig;
        win->nextp = orig->nextp;
        orig->nextp = win;
        win->orig = orig;
+
+       /* Initialize flags here so that refresh can also use __set_subwin. */
+       for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++)
+               lp->flags = 0;
        __set_subwin(orig, win);
        return (win);
 }
        __set_subwin(orig, win);
        return (win);
 }
@@ -103,7 +137,6 @@ __set_subwin(orig, win)
                lp->line = &olp->line[win->begx];
                lp->firstchp = &olp->firstch;
                lp->lastchp = &olp->lastch;
                lp->line = &olp->line[win->begx];
                lp->firstchp = &olp->firstch;
                lp->lastchp = &olp->lastch;
-               lp->flags = 0;
                lp->hash = __hash((char *) lp->line, win->maxx * __LDATASIZE);
        }
 
                lp->hash = __hash((char *) lp->line, win->maxx * __LDATASIZE);
        }