81500d1e6074bb9da26c53d76f1f212f713b0c4f
* Copyright (c) 1981 Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)newwin.c 5.6 (Berkeley) %G%";
#undef nl /* Don't need it here, and it interferes. */
static WINDOW
*makenew
__P((int, int, int, int));
* Allocate space for and set up defaults for a new window.
newwin(num_lines
, num_cols
, begy
, begx
)
int num_lines
, num_cols
, begy
, begx
;
register int by
, bx
, i
, j
, nl
, nc
;
if ((win
= makenew(nl
, nc
, by
, bx
)) == NULL
)
if ((win
->_firstch
= malloc(nl
* sizeof(win
->_firstch
[0]))) == NULL
) {
if ((win
->_lastch
= malloc(nl
* sizeof(win
->_lastch
[0]))) == NULL
) {
for (i
= 0; i
< nl
; i
++) {
win
->_firstch
[i
] = _NOCHANGE
;
win
->_lastch
[i
] = _NOCHANGE
;
if ((win
->_y
[i
] = malloc(nc
* sizeof(win
->_y
[0]))) == NULL
) {
for (sp
= win
->_y
[i
]; sp
< win
->_y
[i
] + nc
;)
__TRACE("newwin: win->_ch_off = %d\n", win
->_ch_off
);
subwin(orig
, num_lines
, num_cols
, begy
, begx
)
int num_lines
, num_cols
, begy
, begx
;
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
;
j
= win
->_begy
- orig
->_begy
;
k
= win
->_begx
- orig
->_begx
;
__TRACE("__set_subwin: win->_ch_off = %d\n", win
->_ch_off
);
win
->_firstch
= &orig
->_firstch
[j
];
win
->_lastch
= &orig
->_lastch
[j
];
for (i
= 0; i
< win
->_maxy
; i
++, j
++)
win
->_y
[i
] = &orig
->_y
[j
][k
];
* Set up a window buffer and returns a pointer to it.
makenew(num_lines
, num_cols
, begy
, begx
)
int num_lines
, num_cols
, begy
, begx
;
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
);
if ((win
->_y
= malloc(nl
* sizeof(win
->_y
[0]))) == NULL
) {
__TRACE("makenew: nc = %d\n", nc
);
win
->_cury
= win
->_curx
= 0;
win
->_scroll
= win
->_leave
= 0;
__TRACE("makenew: win->_clear = %d\n", win
->_clear
);
__TRACE("makenew: win->_leave = %d\n", win
->_leave
);
__TRACE("makenew: win->_scroll = %d\n", win
->_scroll
);
__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
);
win
->_flags
&= ~(_ENDLINE
| _FULLLINE
| _FULLWIN
| _SCROLLWIN
);
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
;