delete spurious debug abort()
[unix-history] / usr / src / lib / libcurses / newwin.c
index 9485bff..acf3bbe 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * allocate space for and set up defaults for a new window
  *
 /*
  * allocate space for and set up defaults for a new window
  *
- * %G% (Berkeley) %W
+ * %G% (Berkeley) @(#)newwin.c 1.6
  */
 
 # include      "curses.ext"
  */
 
 # include      "curses.ext"
@@ -47,6 +47,7 @@ int   num_lines, num_cols, begy, begx;
                else
                        for (sp = win->_y[i]; sp < win->_y[i] + nc; )
                                *sp++ = ' ';
                else
                        for (sp = win->_y[i]; sp < win->_y[i] + nc; )
                                *sp++ = ' ';
+       win->_nextp = win;
        return win;
 }
 
        return win;
 }
 
@@ -72,19 +73,29 @@ int         num_lines, num_cols, begy, begx; {
        fprintf(outf, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx);
 # endif
        if (by < orig->_begy || bx < orig->_begx
        fprintf(outf, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx);
 # endif
        if (by < orig->_begy || bx < orig->_begx
-           || by + nl > orig->_maxy || bx + nc > orig->_maxx)
+           || by + nl > orig->_maxy + orig->_begy
+           || bx + nc > orig->_maxx + orig->_begx) {
+# ifdef        DEBUG
+               fprintf(stderr, "returning ERR (1)\n");
+               fprintf(stderr, "SUBWIN(begx = %d, begy = %d,maxx = %d, maxy = %d, nl = %d, nc = %d, by = %d, bx = %d)\n", orig->_begx,orig->_begy,orig->_maxx,orig->_maxy, nl, nc, by, bx);
+# endif
                return ERR;
                return ERR;
+       }
        if (nl == 0)
        if (nl == 0)
-               nl = orig->_maxy - orig->_begy - by;
+               nl = orig->_maxy + orig->_begy - by;
        if (nc == 0)
        if (nc == 0)
-               nc = orig->_maxx - orig->_begx - bx;
-       if ((win = makenew(nl, nc, by, bx)) == NULL)
+               nc = orig->_maxx + orig->_begx - bx;
+       if ((win = makenew(nl, nc, by, bx)) == NULL) {
+               fprintf(stderr, "returning ERR (2)\n");
                return ERR;
                return ERR;
-       j = orig->_begy + by;
-       k = orig->_begx + bx;
+       }
+       j = by - orig->_begy;
+       k = bx - orig->_begx;
        for (i = 0; i < nl; i++)
                win->_y[i] = &orig->_y[j++][k];
        for (i = 0; i < nl; i++)
                win->_y[i] = &orig->_y[j++][k];
-       win->_flags = _SUBWIN;
+       win->_nextp = orig->_nextp;
+       orig->_nextp = win;
+       win->_orig = orig;
        return win;
 }
 
        return win;
 }
 
@@ -107,7 +118,7 @@ int num_lines, num_cols, begy, begx; {
 # ifdef        DEBUG
        fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx);
 # endif
 # ifdef        DEBUG
        fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx);
 # endif
-       if ((win = (WINDOW *) malloc(sizeof (WINDOW))) == NULL)
+       if ((win = (WINDOW *) calloc(1, sizeof (WINDOW))) == NULL)
                return NULL;
 # ifdef DEBUG
        fprintf(outf, "MAKENEW: nl = %d\n", nl);
                return NULL;
 # ifdef DEBUG
        fprintf(outf, "MAKENEW: nl = %d\n", nl);
@@ -136,6 +147,7 @@ int num_lines, num_cols, begy, begx; {
        win->_maxx = nc;
        win->_begy = by;
        win->_begx = bx;
        win->_maxx = nc;
        win->_begy = by;
        win->_begx = bx;
+       win->_flags = 0;
        win->_scroll = win->_leave = FALSE;
        for (i = 0; i < nl; i++)
                win->_firstch[i] = win->_lastch[i] = _NOCHANGE;
        win->_scroll = win->_leave = FALSE;
        for (i = 0; i < nl; i++)
                win->_firstch[i] = win->_lastch[i] = _NOCHANGE;