* Copyright (c) 1981 Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)newwin.c 5.10 (Berkeley) %G%";
#undef nl /* Don't need it here, and it interferes. */
static WINDOW
*makenew
__P((int, int, int, int));
static void __swflags
__P((WINDOW
*));
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
)) == 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
)) == NULL
)
win
->nextp
= orig
->nextp
;
* This code is shared with mvwin().
register WINDOW
*orig
, *win
;
register int j
, k
, ocnt
, cnt
;
register __LINE
*lp
, *olp
;
j
= win
->begy
- orig
->begy
;
k
= win
->begx
- orig
->begx
;
__TRACE("__set_subwin: win->ch_off = %d\n", win
->ch_off
);
for (ocnt
= j
, cnt
= 0; ocnt
< orig
->maxy
&& cnt
< win
->maxy
;
lp
->firstch
= olp
->firstch
;
lp
->lastch
= olp
->lastch
;
lp
->line
= &olp
->line
[k
];
* Set up a window buffer and returns a pointer to it.
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
);
* 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.
if ((win
->wspace
= 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
];
__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
;