add a missing section header table index conversion
[tangerine.git] / compiler / arossupport / rt_intuition.c
blob7bfd0089d17cba8bff14a9632ba656401e33b1b0
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Basic functions for ressource tracking
6 Lang: english
7 */
9 #include "rt.h"
10 #if 0
11 #define ENABLE_RT 0 /* no RT inside this file */
12 #define RT_INTERNAL 1
13 #include <aros/rt.h>
15 #include <exec/lists.h>
16 #include <aros/system.h>
17 #include <exec/tasks.h>
18 #include <exec/ports.h>
19 #include <exec/memory.h>
20 #include <exec/execbase.h>
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <proto/alib.h>
25 #include "etask.h"
26 #endif
27 #include <proto/exec.h>
28 #include <proto/arossupport.h>
29 #include <proto/intuition.h>
31 typedef struct
33 RTNode Node;
34 struct Screen * Screen;
36 ScreenResource;
38 typedef struct
40 RTNode Node;
41 struct Window * Window;
43 WindowResource;
45 static IPTR RT_OpenScreen (RTData * rtd, ScreenResource * rt, va_list args, BOOL * success);
46 static IPTR RT_CloseScreen (RTData * rtd, ScreenResource * rt);
47 static IPTR RT_ShowErrorScreen (RTData * rtd, int, ScreenResource *, IPTR, int, const char * file, ULONG line, va_list);
48 static IPTR RT_CheckScreen (RTData * rtd, int desc, const char * file, ULONG line, ULONG op, va_list args);
50 static IPTR RT_OpenWindow (RTData * rtd, WindowResource * rt, va_list args, BOOL * success);
51 static IPTR RT_CloseWindow (RTData * rtd, WindowResource * rt);
52 static IPTR RT_ShowErrorWindow (RTData * rtd, int, WindowResource *, IPTR, int, const char * file, ULONG line, va_list);
53 static IPTR RT_CheckWindow (RTData * rtd, int desc, const char * file, ULONG line, ULONG op, va_list args);
55 static const RTDesc RT_IntuitionResources[] =
57 { /* RTT_SCREEN */
58 sizeof (ScreenResource),
59 (RT_AllocFunc) RT_OpenScreen,
60 (RT_FreeFunc) RT_CloseScreen,
61 RT_Search,
62 (RT_ShowError) RT_ShowErrorScreen,
63 (RT_CheckFunc) RT_CheckScreen,
65 { /* RTT_WINDOW */
66 sizeof (WindowResource),
67 (RT_AllocFunc) RT_OpenWindow,
68 (RT_FreeFunc) RT_CloseWindow,
69 RT_Search,
70 (RT_ShowError) RT_ShowErrorWindow,
71 (RT_CheckFunc) RT_CheckWindow,
75 void RT_InitIntuition (void)
77 RT_Resources[RTT_SCREEN] = &RT_IntuitionResources[0];
78 RT_Resources[RTT_WINDOW] = &RT_IntuitionResources[1];
81 void RT_ExitIntuition (void)
85 /**************************************
86 RT Screens
87 **************************************/
89 static IPTR RT_OpenScreen (RTData * rtd, ScreenResource * rt, va_list args, BOOL * success)
91 struct NewScreen * ns;
92 struct TagItem * tags = NULL;
93 int op;
95 op = va_arg (args, int);
96 ns = va_arg (args, struct NewScreen *);
98 switch (op)
100 case RTTO_OpenScreenTags:
101 tags = (struct TagItem *)args;
102 break;
104 case RTTO_OpenScreenTagList:
105 tags = va_arg (args, struct TagItem *);
106 break;
110 if (!CheckPtr (ns, NULL_PTR))
112 kprintf ("OpenScreen(): Illegal NewScreen pointer\n"
113 " NewScreen=%p at %s:%d\n"
114 , ns
115 , rt->Node.File, rt->Node.Line
117 return 0ul;
119 else if (!CheckPtr (tags, NULL_PTR))
121 kprintf ("OpenScreenTagList(): Illegal TagItem pointer\n"
122 " tagList=%p at %s:%d\n"
123 , tags
124 , rt->Node.File, rt->Node.Line
126 return 0ul;
129 rt->Screen = OpenScreenTagList (ns, tags);
131 if (rt->Screen)
132 *success = TRUE;
134 return (IPTR)(rt->Screen);
135 } /* RT_OpenScreen */
137 static IPTR RT_CloseScreen (RTData * rtd, ScreenResource * rt)
139 if (rt->Screen->FirstWindow)
141 struct Window * win;
142 WindowResource * rtwin;
143 APTR prtwin = &rtwin;
145 kprintf ("CloseScreen(): There are still windows open on this screen\n"
146 " Screen=%p opened at %s:%d\n"
147 , rt->Screen
148 , rt->Node.File, rt->Node.Line
151 while ((win = rt->Screen->FirstWindow))
153 if (RT_Search (rtd, RTT_WINDOW, (RTNode **)prtwin, NULL) == RT_SEARCH_FOUND)
155 RT_FreeResource (rtd, RTT_WINDOW, (RTNode *)rtwin);
157 else
159 kprintf (" Window=%p not tracked by the RT system\n"
160 , win
162 CloseWindow (win);
165 } /* Check for windows */
167 /* Close the screen */
168 CloseScreen (rt->Screen);
170 return TRUE;
171 } /* RT_CloseScreen */
173 static IPTR RT_ShowErrorScreen (RTData * rtd, int rtt, ScreenResource * rt,
174 IPTR ret, int mode, const char * file, ULONG line, va_list args)
176 if (mode != RT_EXIT)
178 const char * modestr = (mode == RT_FREE) ? "Close" : "Check";
179 struct Screen * scr;
181 scr = va_arg (args, struct Screen *);
183 switch (ret)
185 case RT_SEARCH_FOUND:
186 if (rt->Node.Flags & RTNF_DONT_FREE)
188 kprintf ("RT%s: Try to free read-only resource: Screen\n"
189 " %s at %s:%d\n"
190 " Added at %s:%d\n"
191 " Screen=%p\n"
192 , modestr
193 , modestr
194 , file, line
195 , rt->Node.File, rt->Node.Line
196 , rt->Screen
199 break;
201 case RT_SEARCH_NOT_FOUND:
202 kprintf ("RT%s: Screen not found\n"
203 " %s at %s:%d\n"
204 " Screen=%p\n"
205 , modestr
206 , modestr
207 , file, line
208 , scr
210 break;
212 } /* switch */
214 else
216 kprintf ("RTExit: Screen was not closed\n"
217 " Opened at %s:%d\n"
218 " Screen=%p\n"
219 , rt->Node.File, rt->Node.Line
220 , rt->Screen
224 return ret;
225 } /* RT_ShowErrorScreen */
227 static IPTR RT_CheckScreen (RTData * rtd, int rtt,
228 const char * file, ULONG line,
229 ULONG op, va_list args)
231 ScreenResource * rt;
232 APTR prt = &rt;
234 if (RT_Search (rtd, rtt, (RTNode **)prt, args) != RT_SEARCH_FOUND)
235 rt = NULL;
237 switch (op)
239 case RTTO_ScreenToFront:
241 struct Screen * scr = va_arg (args, struct Screen *);
243 if (!rt)
245 kprintf ("ScreenToFont(): Illegal window pointer\n"
246 " Screen=%p at %s:%d\n"
247 , scr
248 , file, line
251 return -1;
254 ScreenToFront (scr);
256 return 0;
259 case RTTO_ScreenToBack:
261 struct Screen * scr = va_arg (args, struct Screen *);
263 if (!rt)
265 kprintf ("ScreenToBack(): Illegal window pointer\n"
266 " Screen=%p at %s:%d\n"
267 , scr
268 , file, line
271 return -1;
274 ScreenToBack (scr);
276 return 0;
281 return 0L;
282 } /* RT_CheckScreen */
285 /**************************************
286 RT Windows
287 **************************************/
289 static IPTR RT_OpenWindow (RTData * rtd, WindowResource * rt, va_list args, BOOL * success)
291 struct NewWindow * nw;
292 struct TagItem * tags = NULL;
293 int op;
295 op = va_arg (args, int);
296 nw = va_arg (args, struct NewWindow *);
298 switch (op)
300 case RTTO_OpenWindowTags:
301 tags = (struct TagItem *)args;
302 break;
304 case RTTO_OpenWindowTagList:
305 tags = va_arg (args, struct TagItem *);
306 break;
310 if (!CheckPtr (nw, NULL_PTR))
312 kprintf ("OpenWindow(): Illegal NewWindow pointer\n"
313 " NewWindow=%p at %s:%d\n"
314 , nw
315 , rt->Node.File, rt->Node.Line
317 return 0ul;
319 else if (!CheckPtr (tags, NULL_PTR))
321 kprintf ("OpenWindowTagList(): Illegal TagList pointer\n"
322 " tagList=%p at %s:%d\n"
323 , nw
324 , rt->Node.File, rt->Node.Line
326 return 0ul;
329 rt->Window = OpenWindowTagList (nw, tags);
331 if (rt->Window->UserPort)
332 RT_IntTrack (RTT_PORT, __FILE__, __LINE__, rt->Window->UserPort);
334 if (rt->Window)
335 *success = TRUE;
337 return (IPTR)(rt->Window);
338 } /* RT_OpenWindow */
340 static IPTR RT_CloseWindow (RTData * rtd, WindowResource * rt)
342 CloseWindow (rt->Window);
344 return TRUE;
345 } /* RT_CloseWindow */
347 static IPTR RT_ShowErrorWindow (RTData * rtd, int rtt, WindowResource * rt,
348 IPTR ret, int mode, const char * file, ULONG line, va_list args)
350 if (mode != RT_EXIT)
352 const char * modestr = (mode == RT_FREE) ? "Close" : "Check";
353 struct Window * win;
355 win = va_arg (args, struct Window *);
357 switch (ret)
359 case RT_SEARCH_FOUND:
360 if (rt->Node.Flags & RTNF_DONT_FREE)
362 kprintf ("RT%s: Try to free read-only resource: Window\n"
363 " %s at %s:%d\n"
364 " Added at %s:%d\n"
365 " Window=%p\n"
366 , modestr
367 , modestr
368 , file, line
369 , rt->Node.File, rt->Node.Line
370 , rt->Window
373 break;
375 case RT_SEARCH_NOT_FOUND:
376 kprintf ("RT%s: Window not found\n"
377 " %s at %s:%d\n"
378 " Window=%p\n"
379 , modestr
380 , modestr
381 , file, line
382 , win
384 break;
386 } /* switch */
388 else
390 kprintf ("RTExit: Window was not closed\n"
391 " Opened at %s:%d\n"
392 " Window=%p\n"
393 , rt->Node.File, rt->Node.Line
394 , rt->Window
398 return ret;
399 } /* RT_ShowErrorWindow */
401 static IPTR RT_CheckWindow (RTData * rtd, int rtt,
402 const char * file, ULONG line,
403 ULONG op, va_list args)
405 WindowResource * rt;
406 APTR prt = &rt;
408 if (RT_Search (rtd, rtt, (RTNode **)prt, args) != RT_SEARCH_FOUND)
409 rt = NULL;
411 switch (op)
413 case RTTO_WindowToFront:
415 struct Window * win = va_arg (args, struct Window *);
417 if (!rt)
419 kprintf ("WindowToFont(): Illegal window pointer\n"
420 " Window=%p at %s:%d\n"
421 , win
422 , file, line
425 return -1;
428 WindowToFront (win);
430 return 0;
433 case RTTO_WindowToBack:
435 struct Window * win = va_arg (args, struct Window *);
437 if (!rt)
439 kprintf ("WindowToBack(): Illegal window pointer\n"
440 " Window=%p at %s:%d\n"
441 , win
442 , file, line
445 return -1;
448 WindowToBack (win);
450 return 0;
453 } /* switch (op) */
455 return 0L;
456 } /* RT_CheckWindow */