2 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
21 sccsid
[] = "@(#)newwin.c 1.7 89/07/13 SMI"; /* from UCB 5.1 85/06/07 */
25 * allocate space for and set up defaults for a new window
32 #define SMALLOC (short *)malloc
34 /* forward declaration */
35 static WINDOW
*makenew(int, int, int, int);
37 #undef nl /* don't need it here, and it interferes */
40 newwin(int num_lines
, int num_cols
, int begy
, int begx
)
44 int i
, by
, bx
, nl
, nc
;
56 if ((win
= makenew(nl
, nc
, by
, bx
)) == NULL
)
58 if ((win
->_firstch
= SMALLOC(nl
* sizeof (win
->_firstch
[0]))) == NULL
) {
63 if ((win
->_lastch
= SMALLOC(nl
* sizeof (win
->_lastch
[0]))) == NULL
) {
70 for (i
= 0; i
< nl
; i
++) {
71 win
->_firstch
[i
] = _NOCHANGE
;
72 win
->_lastch
[i
] = _NOCHANGE
;
74 for (i
= 0; i
< nl
; i
++)
75 if ((win
->_y
[i
] = malloc(nc
* sizeof (win
->_y
[0]))) == NULL
) {
76 for (j
= 0; j
< i
; j
++)
85 for (sp
= win
->_y
[i
]; sp
< win
->_y
[i
] + nc
; )
89 fprintf(outf
, "NEWWIN: win->_ch_off = %d\n", win
->_ch_off
);
95 subwin(WINDOW
*orig
, int num_lines
, int num_cols
, int begy
, int begx
)
106 * make sure window fits inside the original one
109 fprintf(outf
, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig
, nl
, nc
, by
, bx
);
111 if (by
< orig
->_begy
|| bx
< orig
->_begx
||
112 by
+ nl
> orig
->_maxy
+ orig
->_begy
||
113 bx
+ nc
> orig
->_maxx
+ orig
->_begx
)
116 nl
= orig
->_maxy
+ orig
->_begy
- by
;
118 nc
= orig
->_maxx
+ orig
->_begx
- bx
;
119 if ((win
= makenew(nl
, nc
, by
, bx
)) == NULL
)
121 win
->_nextp
= orig
->_nextp
;
124 _set_subwin_(orig
, win
);
129 * this code is shared with mvwin()
133 _set_subwin_(WINDOW
*orig
, WINDOW
*win
)
137 j
= win
->_begy
- orig
->_begy
;
138 k
= win
->_begx
- orig
->_begx
;
139 win
->_ch_off
= (short)k
;
141 fprintf(outf
, "_SET_SUBWIN_: win->_ch_off = %d\n", win
->_ch_off
);
143 win
->_firstch
= &orig
->_firstch
[j
];
144 win
->_lastch
= &orig
->_lastch
[j
];
145 for (i
= 0; i
< win
->_maxy
; i
++, j
++)
146 win
->_y
[i
] = &orig
->_y
[j
][k
];
151 * This routine sets up a window buffer and returns a pointer to it.
155 makenew(int num_lines
, int num_cols
, int begy
, int begx
)
166 fprintf(outf
, "MAKENEW(%d, %d, %d, %d)\n", nl
, nc
, by
, bx
);
168 if ((win
= (WINDOW
*) malloc(sizeof (*win
))) == NULL
)
171 fprintf(outf
, "MAKENEW: nl = %d\n", nl
);
173 if ((win
->_y
= (char **)malloc(nl
* sizeof (win
->_y
[0]))) == NULL
) {
178 fprintf(outf
, "MAKENEW: nc = %d\n", nc
);
180 win
->_cury
= win
->_curx
= 0;
182 win
->_maxy
= (short)nl
;
183 win
->_maxx
= (short)nc
;
184 win
->_begy
= (short)by
;
185 win
->_begx
= (short)bx
;
187 win
->_scroll
= win
->_leave
= FALSE
;
191 fprintf(outf
, "MAKENEW: win->_clear = %d\n", win
->_clear
);
192 fprintf(outf
, "MAKENEW: win->_leave = %d\n", win
->_leave
);
193 fprintf(outf
, "MAKENEW: win->_scroll = %d\n", win
->_scroll
);
194 fprintf(outf
, "MAKENEW: win->_flags = %0.2o\n", win
->_flags
);
195 fprintf(outf
, "MAKENEW: win->_maxy = %d\n", win
->_maxy
);
196 fprintf(outf
, "MAKENEW: win->_maxx = %d\n", win
->_maxx
);
197 fprintf(outf
, "MAKENEW: win->_begy = %d\n", win
->_begy
);
198 fprintf(outf
, "MAKENEW: win->_begx = %d\n", win
->_begx
);
204 _swflags_(WINDOW
*win
)
206 win
->_flags
&= ~(_ENDLINE
|_FULLLINE
|_FULLWIN
|_SCROLLWIN
);
207 if (win
->_begx
+ win
->_maxx
== COLS
) {
208 win
->_flags
|= _ENDLINE
;
209 if (win
->_begx
== 0) {
211 win
->_flags
|= _FULLLINE
;
212 if (win
->_maxy
== LINES
&& win
->_begy
== 0)
213 win
->_flags
|= _FULLWIN
;
215 if (win
->_begy
+ win
->_maxy
== LINES
)
216 win
->_flags
|= _SCROLLWIN
;