* Copyright (c) 1981 Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)newwin.c 5.4 (Berkeley) %G%";
* allocate space for and set up defaults for a new window
# define SMALLOC (short *) malloc
static WINDOW
*makenew();
# undef nl /* don't need it here, and it interferes */
newwin(num_lines
, num_cols
, begy
, begx
)
int num_lines
, num_cols
, begy
, begx
;
reg
int i
, by
, bx
, nl
, nc
;
if ((win
= makenew(nl
, nc
, by
, bx
)) == NULL
)
if ((win
->_firstch
= SMALLOC(nl
* sizeof win
->_firstch
[0])) == NULL
) {
if ((win
->_lastch
= SMALLOC(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
; )
fprintf(outf
, "NEWWIN: win->_ch_off = %d\n", win
->_ch_off
);
subwin(orig
, num_lines
, num_cols
, begy
, begx
)
int num_lines
, num_cols
, begy
, begx
;
* make sure window fits inside the original one
fprintf(outf
, "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
;
fprintf(outf
, "_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
];
* This routine sets up a window buffer and returns a pointer to it.
makenew(num_lines
, num_cols
, begy
, begx
)
int num_lines
, num_cols
, begy
, begx
; {
fprintf(outf
, "MAKENEW(%d, %d, %d, %d)\n", nl
, nc
, by
, bx
);
if ((win
= (WINDOW
*) malloc(sizeof *win
)) == NULL
)
fprintf(outf
, "MAKENEW: nl = %d\n", nl
);
if ((win
->_y
= (char **) malloc(nl
* sizeof win
->_y
[0])) == NULL
) {
fprintf(outf
, "MAKENEW: nc = %d\n", nc
);
win
->_cury
= win
->_curx
= 0;
win
->_scroll
= win
->_leave
= FALSE
;
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
);
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
;