8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libeti / panel / common / misc.c
blob825a7ae569f48e8d04ad9090796ce27d3dc1eafe
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
31 /* A panels subsystem built on curses--Miscellaneous routines */
33 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4 */
35 /*LINTLIBRARY*/
37 #include <sys/types.h>
38 #include <stdlib.h>
39 #include <curses.h>
40 #include "private.h"
42 PANEL *_Bottom_panel;
43 PANEL *_Top_panel;
44 int _Panel_cnt;
46 static _obscured_list *_Free_list;
47 static int _Free_list_cnt;
50 /* panel_window - Return the window pointer */
51 WINDOW *
52 panel_window(PANEL *panel)
54 return (panel ? panel -> win : 0);
57 /* panel_userptr - Return the user pointer */
58 char *
59 panel_userptr(PANEL *panel)
61 return (panel ? panel -> user : 0);
64 /* set_panel_userptr - set the user pointer */
65 int
66 set_panel_userptr(PANEL *panel, char *ptr)
68 if (panel) {
69 panel -> user = ptr;
70 return (OK);
71 } else
72 return (ERR);
76 * panel_above - Return the panel above the
77 * given panel (or the bottom panel in 0)
79 PANEL *
80 panel_above(PANEL *panel)
83 if (!panel)
84 return (_Bottom_panel);
86 return ((panel == panel -> below) ? ((PANEL *) 0) : panel -> above);
91 * panel_below - Return the panel below the
92 * given panel (or the top panel in 0)
94 PANEL *
95 panel_below(PANEL *panel)
98 if (!panel)
99 return (_Top_panel);
101 return ((panel == panel -> below) ? ((PANEL *) 0) : panel -> below);
104 /* panel_hidden - Return TRUE if the panel is hidden, FALSE if not. */
106 panel_hidden(PANEL *panel)
108 return ((!panel || (panel != panel -> below)) ? FALSE : TRUE);
111 /* _get_overlap - Get an overlap node from the free list. */
112 static _obscured_list *
113 _get_overlap(void)
115 _obscured_list *overlap;
117 if (_Free_list_cnt-- > 0) {
118 overlap = _Free_list;
119 _Free_list = _Free_list -> next;
120 } else {
121 _Free_list_cnt = 0;
122 overlap = 0;
125 return (overlap);
130 * _unlink_obs - Find the obscured node, if any,
131 * in the first panel which refers the second panel.
133 _obscured_list *
134 _unlink_obs(PANEL *pnl, PANEL *panel)
136 _obscured_list *obs;
137 _obscured_list *prev_obs;
139 if (!pnl -> obscured || !_panels_intersect(pnl, panel))
140 return ((_obscured_list *) 0);
142 obs = pnl -> obscured;
143 do {
144 prev_obs = obs;
145 obs = obs -> next;
147 while (obs->panel_p != panel && obs != pnl->obscured);
148 if (obs -> panel_p != panel) {
149 #ifdef DEBUG
150 fprintf(stderr, "_unlink_obs: Obscured panel lost\n");
151 #endif
152 return ((_obscured_list *) 0);
155 if (obs == prev_obs)
156 pnl -> obscured = 0;
157 else {
158 prev_obs -> next = obs -> next;
159 if (obs == pnl -> obscured)
160 pnl -> obscured = prev_obs;
162 return (obs);
166 * add_obs - Add an obscured node to a panel, ensuring
167 * that the obscured list is ordered from top to bottom.
169 static void
170 add_obs(PANEL *panel, _obscured_list *obs)
172 PANEL *pnl;
173 _obscured_list *curr_obs;
174 _obscured_list *prev_obs;
176 if ((prev_obs = panel -> obscured) == 0) {
177 panel -> obscured = obs -> next = obs;
178 return;
181 curr_obs = prev_obs -> next;
183 for (pnl = _Top_panel; pnl != panel; pnl = pnl->below) {
184 if (curr_obs -> panel_p == pnl) {
185 prev_obs = curr_obs;
186 curr_obs = curr_obs -> next;
187 if (prev_obs == panel -> obscured) {
188 panel -> obscured = obs;
189 break;
194 obs -> next = curr_obs;
195 prev_obs -> next = obs;
200 * _intersect_panel
201 * Create an obscured node for each panel that the given panel intersects.
202 * The overlap record is always attached to the panel which is covered up.
204 * This routine assumes that _alloc_overlap() has been called to ensure
205 * that there are enough overlap nodes to satisfy the requests.
207 void
208 _intersect_panel(PANEL *panel)
210 PANEL *pnl;
211 _obscured_list *obs;
212 int above_panel;
214 above_panel = FALSE;
216 for (pnl = _Bottom_panel; pnl; pnl = pnl -> above) {
217 if (pnl == panel) {
218 above_panel = TRUE;
219 continue;
222 if (!_panels_intersect(pnl, panel))
223 continue; /* no overlap */
225 obs = _get_overlap();
226 obs->start = (panel->wstarty >= pnl->wstarty) ?
227 panel->wstarty : pnl->wstarty;
228 obs->end = (panel->wendy <= pnl->wendy) ?
229 panel->wendy : pnl->wendy;
231 if (above_panel) {
232 obs -> panel_p = pnl;
233 if (panel -> obscured) {
234 obs -> next = panel -> obscured -> next;
235 panel -> obscured -> next = obs;
236 } else
237 obs -> next = panel -> obscured = obs;
238 } else {
239 obs -> panel_p = panel;
240 add_obs(pnl, obs);
247 * _alloc_overlap
248 * Create enough obscured nodes to record all overlaps of a given
249 * panel. The obscured nodes must be pre-allocated by this routine
250 * to preserve the integrity of the pile during move.
251 * If the move operation fails, the pile is supposed to remain
252 * unchanged. If the obscured nodes are not allocated in advance,
253 * then an allocation failure in the middle of a move could
254 * leave the pile in a corrupted state with possibly no way to
255 * restore the pile to its original state.
257 * The cnt parameter is the(worst case) number of overlap nodes which
258 * are required to satisfy any request. Return 0 on error, else non-zero
261 _alloc_overlap(int cnt)
263 _obscured_list *overlap;
264 int i;
266 for (i = cnt-_Free_list_cnt; i > 0; i--) {
267 if (!(overlap = (_obscured_list *)
268 malloc(sizeof (_obscured_list))))
269 return (0);
271 overlap -> next = _Free_list;
272 _Free_list = overlap;
273 _Free_list_cnt++;
276 return (1);
281 * _free_overlap - Free a single overlap node. Don't
282 * really free it; just save it on a list.
284 void
285 _free_overlap(_obscured_list *overlap)
287 overlap -> next = _Free_list;
288 _Free_list = overlap;
289 _Free_list_cnt++;