-# ifdef DEBUG
- fprintf(outf, "MAKENEW: nc = %d\n", nc);
-# endif
- win->_cury = win->_curx = 0;
- win->_clear = FALSE;
- win->_maxy = nl;
- win->_maxx = nc;
- win->_begy = by;
- win->_begx = bx;
- win->_flags = 0;
- win->_scroll = win->_leave = FALSE;
- _swflags_(win);
-# ifdef DEBUG
- fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear);
- fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave);
- fprintf(outf, "MAKENEW: win->_scroll = %d\n", win->_scroll);
- fprintf(outf, "MAKENEW: win->_flags = %0.2o\n", win->_flags);
- fprintf(outf, "MAKENEW: win->_maxy = %d\n", win->_maxy);
- fprintf(outf, "MAKENEW: win->_maxx = %d\n", win->_maxx);
- fprintf(outf, "MAKENEW: win->_begy = %d\n", win->_begy);
- fprintf(outf, "MAKENEW: win->_begx = %d\n", win->_begx);
-# endif
- return win;
+ if ((win->lspace = malloc (nl * sizeof(__LINE))) == NULL) {
+ free (win);
+ free (win->lines);
+ return NULL;
+ }
+
+ /* Don't allocate window and line space if it's a subwindow */
+ if (!sub) {
+ /*
+ * Allocate window space in one chunk.
+ */
+ if ((win->wspace =
+ malloc(nc * nl * sizeof(__LDATA))) == NULL) {
+ free(win->lines);
+ free(win->lspace);
+ free(win);
+ return NULL;
+ }
+
+ /*
+ * Point line pointers to line space, and lines themselves into
+ * window space.
+ */
+ for (lp = win->lspace, i = 0; i < nl; i++, lp++) {
+ win->lines[i] = lp;
+ lp->line = &win->wspace[i * nc];
+ lp->firstchp = &lp->firstch;
+ lp->lastchp = &lp->lastch;
+ lp->firstch = 0;
+ lp->lastch = 0;
+ }
+ }
+#ifdef DEBUG
+ __CTRACE("makenew: nc = %d\n", nc);
+#endif
+ win->cury = win->curx = 0;
+ win->maxy = nl;
+ win->maxx = nc;
+
+ win->begy = by;
+ win->begx = bx;
+ win->flags = 0;
+ __swflags(win);
+#ifdef DEBUG
+ __CTRACE("makenew: win->flags = %0.2o\n", win->flags);
+ __CTRACE("makenew: win->maxy = %d\n", win->maxy);
+ __CTRACE("makenew: win->maxx = %d\n", win->maxx);
+ __CTRACE("makenew: win->begy = %d\n", win->begy);
+ __CTRACE("makenew: win->begx = %d\n", win->begx);
+#endif
+ return (win);