1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 /*LINTLIBRARY*/
41 
42 #include	<stdlib.h>
43 #include	<string.h>
44 #include	<sys/types.h>
45 #include	"curses_inc.h"
46 
47 /* This routine sets up a window buffer and returns a pointer to it. */
48 
49 WINDOW	*
_makenew(int nlines,int ncols,int begy,int begx)50 _makenew(int nlines, int ncols, int begy, int begx)
51 {
52 	/* order the register allocations against highest usage */
53 	WINDOW	*win;
54 
55 #ifdef	DEBUG
56 	if (outf)
57 		fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n",
58 		    nlines, ncols, begy, begx);
59 #endif	/* DEBUG */
60 
61 	if ((win = (WINDOW *) malloc(sizeof (WINDOW))) == NULL)
62 		goto out_no_win;
63 	if ((win->_y = (chtype **) malloc(nlines * sizeof (chtype *))) == NULL)
64 		goto out_win;
65 #ifdef	_VR3_COMPAT_CODE
66 	if ((_y16update) && ((win->_y16 = (_ochtype **)
67 	    calloc(1, nlines * sizeof (_ochtype *))) == NULL)) {
68 		goto out_y16;
69 	}
70 #endif	/* _VR3_COMPAT_CODE */
71 	if ((win->_firstch = (short *) malloc(2 * nlines * sizeof (short)))
72 	    == NULL) {
73 #ifdef	_VR3_COMPAT_CODE
74 		if ((_y16update) && (win->_y16 != NULL))
75 			free((char *) win->_y16);
76 out_y16:
77 #endif	/* _VR3_COMPAT_CODE */
78 		free((char *) win->_y);
79 out_win:
80 		free((char *) win);
81 out_no_win:
82 		curs_errno = CURS_BAD_MALLOC;
83 #ifdef	DEBUG
84 		strcpy(curs_parm_err, "_makenew");
85 #endif	/* DEBUG */
86 		return ((WINDOW *) NULL);
87 	} else
88 		win->_lastch = win->_firstch + nlines;
89 
90 	win->_cury = win->_curx = 0;
91 	/*LINTED*/
92 	win->_maxy = (short) nlines;
93 	/*LINTED*/
94 	win->_maxx = (short) ncols;
95 	/*LINTED*/
96 	win->_begy = (short) begy;
97 	/*LINTED*/
98 	win->_begx = (short) begx;
99 	win->_clear = (((begy + SP->Yabove + begx) == 0) &&
100 	    (nlines >= (LINES + SP->Yabove)) && (ncols >= COLS));
101 	win->_leave = win->_scroll = win->_use_idl = win->_use_keypad =
102 	    win->_notimeout = win->_immed = win->_sync = FALSE;
103 	win->_use_idc = TRUE;
104 	win->_ndescs = win->_tmarg = 0;
105 	win->_bmarg = nlines - 1;
106 	win->_bkgd = _BLNKCHAR;
107 	win->_delay = win->_parx = win->_pary = -1;
108 	win->_attrs = A_NORMAL;
109 	win->_flags = _WINCHANGED;
110 	win->_parent = win->_padwin = (WINDOW *) NULL;
111 	(void) memset((char *) win->_firstch, 0, (nlines * sizeof (short)));
112 	{
113 		short	*lastch = win->_lastch,
114 			*elastch = lastch + nlines;
115 
116 		ncols--;
117 		while (lastch < elastch)
118 		    /*LINTED*/
119 		    *lastch++ = (short) ncols;
120 	}
121 
122 	win->_insmode = FALSE;
123 	win->_index = 0;
124 	win->_nbyte = -1;
125 
126 #ifdef	DEBUG
127 	if (outf) {
128 		fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear);
129 		fprintf(outf, "MAKENEW: win->_flags = %0.2o\n", win->_flags);
130 		fprintf(outf, "MAKENEW: win->_maxy = %d\n", win->_maxy);
131 		fprintf(outf, "MAKENEW: win->_maxx = %d\n", win->_maxx);
132 		fprintf(outf, "MAKENEW: win->_begy = %d\n", win->_begy);
133 		fprintf(outf, "MAKENEW: win->_begx = %d\n", win->_begx);
134 	}
135 #endif	/* DEBUG */
136 	return (win);
137 }
138