5 /****************************************************************/
6 /* Makenew() allocates all data for a new window except the */
7 /* Actual lines themselves. */
8 /****************************************************************/
10 _PROTOTYPE(static WINDOW
*makenew
, (int nlines
, int ncols
, int begy
,int begx
));
12 static WINDOW
*makenew(num_lines
, num_columns
, begy
, begx
)
13 int num_lines
, num_columns
, begy
, begx
;
18 /* Allocate the window structure itself */
19 if ((win
= (WINDOW
*) malloc(sizeof(WINDOW
))) == NULL
)
20 return((WINDOW
*) ERR
);
22 /* Allocate the line pointer array */
23 if ((win
->_line
= (int **) calloc(num_lines
, sizeof(int *))) == NULL
) {
25 return((WINDOW
*) ERR
);
28 /* Allocate the minchng and maxchng arrays */
29 if ((win
->_minchng
= (int *) calloc(num_lines
, sizeof(int))) == NULL
) {
32 return((WINDOW
*) ERR
);
34 if ((win
->_maxchng
= (int *) calloc(num_lines
, sizeof(int))) == NULL
) {
38 return((WINDOW
*) ERR
);
41 /* Initialize window variables */
44 win
->_maxy
= num_lines
- 1;
45 win
->_maxx
= num_columns
- 1;
49 win
->_attrs
= ATR_NRM
;
54 win
->_nodelay
= FALSE
;
57 win
->_regbottom
= num_lines
- 1;
59 /* Init to say window unchanged */
60 for (i
= 0; i
< num_lines
; i
++) {
62 win
->_maxchng
[i
] = num_columns
- 1;
65 /* Set flags for window properties */
66 if ((begy
+ num_lines
) == LINES
) {
67 win
->_flags
|= _ENDLINE
;
68 if ((begx
== 0) && (num_columns
== COLS
) && (begy
== 0))
69 win
->_flags
|= _FULLWIN
;
71 if (((begy
+ num_lines
) == LINES
) && ((begx
+ num_columns
) == COLS
))
72 win
->_flags
|= _SCROLLWIN
;
77 /****************************************************************/
78 /* Newwin() creates a new window with size num_lines * num_co- */
79 /* Lumns, and origin begx,begy relative to the SCREEN. Special */
80 /* Case: if num_lines and/or num_columns is 0, the remainder of */
81 /* The screen is used. */
82 /****************************************************************/
83 WINDOW
*newwin(num_lines
, num_columns
, begy
, begx
)
84 int num_lines
, num_columns
, begy
, begx
;
90 if (num_lines
== 0) num_lines
= LINES
- begy
;
91 if (num_columns
== 0) num_columns
= COLS
- begx
;
92 if ((win
= makenew(num_lines
, num_columns
, begy
, begx
)) == (WINDOW
*) ERR
)
93 return((WINDOW
*) ERR
);
94 for (i
= 0; i
< num_lines
; i
++) { /* make and clear the lines */
95 if ((win
->_line
[i
] = (int *)calloc(num_columns
, sizeof(int))) == NULL
){
96 for (j
= 0; j
< i
; j
++) /* if error, free all the data */
102 return((WINDOW
*) ERR
);
104 for (ptr
= win
->_line
[i
]; ptr
< win
->_line
[i
] + num_columns
;)
105 *ptr
++ = ' ' | ATR_NRM
;
112 /****************************************************************/
113 /* Subwin() creates a sub-window in the 'orig' window, with */
114 /* Size num_lines * num_columns, and with origin begx, begy */
115 /* Relative to the SCREEN. Special case: if num_lines and/or */
116 /* Num_columns is 0, the remainder of the original window is */
117 /* Used. The subwindow uses the original window's line buffers */
118 /* To store it's own lines. */
119 /****************************************************************/
120 WINDOW
*subwin(orig
, num_lines
, num_columns
, begy
, begx
)
122 int num_lines
, num_columns
, begy
, begx
;
127 /* Make sure window fits inside the original one */
128 if (begy
< orig
->_begy
|| begx
< orig
->_begx
||
129 (begy
+ num_lines
) > (orig
->_begy
+ orig
->_maxy
) ||
130 (begx
+ num_columns
) > (orig
->_begx
+ orig
->_maxx
) )
131 return((WINDOW
*) ERR
);
133 if (num_lines
== 0) num_lines
= orig
->_maxy
- (begy
- orig
->_begy
);
134 if (num_columns
== 0) num_columns
= orig
->_maxx
- (begx
- orig
->_begx
);
135 if ((win
= makenew(num_lines
, num_columns
, begy
, begx
)) == (WINDOW
*) ERR
)
136 return((WINDOW
*) ERR
);
138 /* Set line pointers the same as in the original window */
139 j
= begy
- orig
->_begy
;
140 k
= begx
- orig
->_begx
;
141 for (i
= 0; i
< num_lines
; i
++) win
->_line
[i
] = (orig
->_line
[j
++]) + k
;
142 win
->_flags
|= _SUBWIN
;