* Copyright (c) 1981 Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)newwin.c 5.9 (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
->topline
, i
= 0; i
< nl
; i
++, lp
= lp
->next
) {
lp
->flags
&= ~__ISPASTEOL
;
for (sp
= lp
->line
; sp
< lp
->line
+ nc
; sp
++) {
*(sp
+ nc
) &= ~__STANDOUT
;
lp
->hash
= __hash(lp
->line
, nc
);
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
;
j
= win
->begy
- orig
->begy
;
k
= win
->begx
- orig
->begx
;
__TRACE("__set_subwin: win->ch_off = %d\n", win
->ch_off
);
for (ocnt
= 0; ocnt
< orig
->maxy
&& cnt
< win
->maxy
; ocnt
++) {
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
;
register LINE
*cur
, *prev
;
__TRACE("makenew: (%d, %d, %d, %d)\n", nl
, nc
, by
, bx
);
if ((win
= malloc(sizeof(*win
))) == NULL
)
__TRACE("makenew: nl = %d\n", nl
);
* Allocate structure of lines in a window.
if ((win
->topline
= malloc (nl
* sizeof (LINE
))) == NULL
) {
* Allocate window space in one chunk.
if ((win
->wspace
= malloc(2 * nc
* nl
)) == NULL
) {
* Link up the lines, set up line pointer array and point line pointers
* to the line space, and point standout arrays to follow lines.
if ((win
->lines
= malloc (nl
* sizeof (LINE
*))) == NULL
) {
prev
= &win
->topline
[nl
- 1];
for (i
= 1; i
<= nl
; i
++, prev
= cur
, cur
= cur
->next
) {
cur
->next
= &win
->topline
[i
% nl
];
cur
->line
= &win
->wspace
[(i
- 1) * 2 * nc
];
cur
->standout
= cur
->line
+ 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
;