* Copyright (c) 1981 Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)newwin.c 5.13 (Berkeley) %G%";
#undef nl /* Don't need it here, and it interferes. */
static WINDOW
*__makenew
__P((int, int, int, int, int));
void __set_subwin
__P((WINDOW
*, WINDOW
*));
* Allocate space for and set up defaults for a new window.
register int nl
, nc
, by
, bx
;
if ((win
= __makenew(nl
, nc
, by
, bx
, 0)) == NULL
)
__TRACE("newwin: win->ch_off = %d\n", win
->ch_off
);
for (lp
= win
->lines
[0], i
= 0; i
< nl
; i
++, lp
= win
->lines
[i
]) {
for (sp
= lp
->line
, j
= 0; j
< nc
; j
++, sp
++) {
lp
->hash
= __hash(lp
->line
, nc
* __LDATASIZE
);
subwin(orig
, nl
, nc
, by
, bx
)
register int by
, bx
, nl
, nc
;
/* Make sure window fits inside the original one. */
__TRACE("subwin: (%0.2o, %d, %d, %d, %d)\n", orig
, nl
, nc
, by
, bx
);
if (by
< orig
->begy
|| bx
< orig
->begx
|| by
+ nl
> orig
->maxy
+ orig
->begy
|| bx
+ nc
> orig
->maxx
+ orig
->begx
)
nl
= orig
->maxy
+ orig
->begy
- by
;
nc
= orig
->maxx
+ orig
->begx
- bx
;
if ((win
= __makenew(nl
, nc
, by
, bx
, 1)) == NULL
)
win
->nextp
= orig
->nextp
;
* This code is shared with mvwin().
register WINDOW
*orig
, *win
;
win
->ch_off
= win
->begx
- orig
->begx
;
win
->lines
= &orig
->lines
[win
->begy
];
__TRACE("__set_subwin: win->ch_off = %d\n", win
->ch_off
);
* Set up a window buffer and returns a pointer to it.
__makenew(nl
, nc
, by
, bx
, sub
)
register int by
, bx
, nl
, nc
;
__TRACE("makenew: (%d, %d, %d, %d)\n", nl
, nc
, by
, bx
);
if ((win
= malloc(sizeof(*win
))) == NULL
)
__TRACE("makenew: nl = %d\n", nl
);
/* Don't allocate space if it's a subwindow */
* Set up line pointer array and line space.
if ((win
->lines
= malloc (nl
* sizeof(__LINE
*))) == NULL
) {
if ((win
->lspace
= malloc (nl
* sizeof(__LINE
))) == NULL
) {
* Allocate window space in one chunk.
malloc(nc
* nl
* sizeof(__LDATA
))) == NULL
) {
* Point line pointers to line space, and lines themselves into
for (lp
= win
->lspace
, i
= 0; i
< nl
; i
++, lp
++) {
lp
->line
= &win
->wspace
[i
* nc
];
lp
->firstchp
= &lp
->firstch
;
lp
->lastchp
= &lp
->lastch
;
__TRACE("makenew: nc = %d\n", nc
);
win
->cury
= win
->curx
= 0;
__TRACE("makenew: win->flags = %0.2o\n", win
->flags
);
__TRACE("makenew: win->maxy = %d\n", win
->maxy
);
__TRACE("makenew: win->maxx = %d\n", win
->maxx
);
__TRACE("makenew: win->begy = %d\n", win
->begy
);
__TRACE("makenew: win->begx = %d\n", win
->begx
);
~(__ENDLINE
| __FULLLINE
| __FULLWIN
| __SCROLLWIN
| __LEAVEOK
);
if (win
->begx
+ win
->maxx
== COLS
) {
win
->flags
|= __FULLLINE
;
if (win
->maxy
== LINES
&& win
->begy
== 0)
if (win
->begy
+ win
->maxy
== LINES
)
win
->flags
|= __SCROLLWIN
;