This should solve an error which made the nightly build fail with:
[AROS-Contrib.git] / bgui / lib.c
blob5d42406bcff77926728d513ec5160cd8c38fe966
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * lib.c
7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
13 * $Log$
14 * Revision 42.13 2004/07/11 17:10:21 stegerg
15 * LibInit() function may not leave out D0 param, even if unused,
16 * otherwise it crashes on machines where all arguments are passed
17 * on stack.
19 * Revision 42.12 2004/06/20 12:24:31 verhaegs
20 * Use REGFUNC macro's in BGUI source code, not AROS_UFH
22 * Revision 42.11 2004/06/19 20:27:48 verhaegs
23 * Added AROS_LIBFUNC_INIT/EXIT
25 * Revision 42.10 2003/01/18 19:09:58 chodorowski
26 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
28 * Revision 42.9 2002/03/07 21:33:00 stegerg
29 * These used still AROS_LHA for the arguments of libinit,
30 * instead of AROS_UFHA.
32 * Revision 42.8 2001/01/28 04:53:21 bergers
33 * Fixed some compiler complaints (some casts were missing.).
35 * Revision 42.7 2000/08/08 20:57:26 chodorowski
36 * Minor fixes to build on Amiga.
38 * Revision 42.6 2000/08/08 14:08:00 chodorowski
39 * Minor fixes to make BGUI compile on Amiga.
41 * Revision 42.5 2000/07/06 16:44:03 stegerg
42 * AddTaskMember can now be called. Problem was Cli()->cli_CommandName
43 * which BGUI expected to be a BSTR with size in first byte.
45 * Revision 42.4 2000/07/03 20:45:44 bergers
46 * Update. Test1 now successfully opens the library. In LibOpen the AddTaskMember function seems to trash the stack somehow (return address is trashed) and therefore I had to take it out.
48 * Revision 42.3 2000/06/01 01:41:37 bergers
49 * Only 2 linker problems left: stch_l & stcu_d. Somebody might want to replace them (embraced by #ifdef __AROS__), please.
51 * Revision 42.2 2000/05/31 01:23:10 bergers
52 * Changes to make BGUI compilable and linkable.
54 * Revision 42.1 2000/05/29 00:40:24 bergers
55 * Update to compile with AROS now. Should also still compile with SASC etc since I only made changes that test the define __AROS__. The compilation is still very noisy but it does the trick for the main directory. Maybe members of the BGUI team should also have a look at the compiler warnings because some could also cause problems on other systems... (Comparison always TRUE due to datatype (or something like that)). And please compile it on an Amiga to see whether it still works... Thanks.
57 * Revision 42.0 2000/05/09 22:09:20 mlemos
58 * Bumped to revision 42.0 before handing BGUI to AROS team
60 * Revision 41.11 2000/05/09 19:54:31 mlemos
61 * Merged with the branch Manuel_Lemos_fixes.
63 * Revision 41.10.2.4 1999/07/24 17:08:08 mlemos
64 * Removed the code that flushed the memory to remove the current catalog.
66 * Revision 41.10.2.3 1998/10/01 04:25:58 mlemos
67 * Made the library call the functions to allocate and free the memory for the
68 * pre-allocated stack memory space for use by the input.device task.
70 * Revision 41.10.2.2 1998/06/18 23:14:15 mlemos
71 * Added code to outdate a given library build.
73 * Revision 41.10.2.1 1998/03/01 02:21:57 mlemos
74 * Added new memory allocation debugging functions to the library
76 * Revision 41.10 1998/02/25 21:12:24 mlemos
77 * Bumping to 41.10
79 * Revision 1.1 1998/02/25 17:08:46 mlemos
80 * Ian sources
85 #define NO_MEMORY_ALLOCATION_DEBUG_ALIASING
87 #include "include/classdefs.h"
89 #ifdef __AROS__
90 #include <aros/debug.h>
91 #endif
94 * Global data (written to once at initalization time).
96 BPTR SegList = 0;
97 #ifndef ENHANCED
98 makeproto BOOL OS30 = FALSE;
99 #endif
101 struct Library *BGUIBase = NULL;
102 struct DosLibrary *DOSBase = NULL;
103 struct ExecBase *SysBase = NULL;
104 struct IntuitionBase *IntuitionBase = NULL;
105 struct GfxBase *GfxBase = NULL;
106 struct Library *GadToolsBase = NULL; /* Menu stuff. */
107 #ifdef __AROS__
108 struct UtilityBase *UtilityBase = NULL;
109 #else
110 struct Library *UtilityBase = NULL;
111 #endif
112 struct Library *LayersBase = NULL;
113 struct Library *AslBase = NULL;
114 struct Library *CxBase = NULL;
115 struct Library *KeymapBase = NULL;
116 struct Library *IFFParseBase = NULL;
117 struct Library *DataTypesBase = NULL;
118 struct LocaleBase *LocaleBase = NULL;
119 struct Library *WorkbenchBase = NULL;
120 struct Catalog *Catalog = NULL;
122 struct Task *InputDevice = NULL;
123 APTR InputStack = NULL;
126 #ifdef __AROS__
127 AROS_LD1(struct Library *, LibOpen,
128 AROS_LHA(ULONG, version, D0),
129 struct Library *, lib, 1, BGUI);
131 AROS_LD0(BPTR, LibClose,
132 struct Library *, lib, 2, BGUI);
134 AROS_LD1(BPTR, LibExpunge,
135 AROS_LHA(struct Library *, lib, D0),
136 struct ExecBase *, sysBase, 3, BGUI);
138 AROS_LD0(LONG, LibVoid,
139 struct Library *, lib, 4, BGUI);
141 extern BGUI_BGUI_GetClassPtr();
142 extern BGUI_BGUI_NewObjectA();
143 extern BGUI_BGUI_RequestA();
144 extern BGUI_BGUI_Help();
145 extern BGUI_BGUI_LockWindow();
146 extern BGUI_BGUI_UnlockWindow();
147 extern BGUI_BGUI_DoGadgetMethodA();
149 * Private routines.
151 extern BGUI_BGUI_AllocPoolMem();
152 extern BGUI_BGUI_FreePoolMem();
154 * Public routines.
156 extern BGUI_BGUI_AllocBitMap();
157 extern BGUI_BGUI_FreeBitMap();
158 extern BGUI_BGUI_CreateRPortBitMap();
159 extern BGUI_BGUI_FreeRPortBitMap();
160 extern BGUI_BGUI_InfoTextSize();
161 extern BGUI_BGUI_InfoText();
162 extern BGUI_BGUI_GetLocaleStr();
163 extern BGUI_BGUI_GetCatalogStr();
164 extern BGUI_BGUI_FillRectPattern();
165 extern BGUI_BGUI_PostRender();
166 extern BGUI_BGUI_MakeClassA();
167 extern BGUI_BGUI_FreeClass();
168 extern BGUI_BGUI_PackStructureTags();
169 extern BGUI_BGUI_UnpackStructureTags();
171 * Private routines.
173 extern BGUI_BGUI_GetDefaultTags();
174 extern BGUI_BGUI_DefaultPrefs();
175 extern BGUI_BGUI_LoadPrefs();
176 extern BGUI_BGUI_AllocPoolMemDebug();
177 extern BGUI_BGUI_FreePoolMemDebug();
178 #endif
181 * Library function table.
183 STATIC const IPTR Vectors[] = {
184 #ifdef __AROS__
186 * System interface.
188 (IPTR)BGUI_LibOpen,
189 (IPTR)BGUI_LibClose,
190 (IPTR)BGUI_LibExpunge,
191 (IPTR)BGUI_LibVoid,
193 * Public routines.
195 (IPTR)BGUI_BGUI_GetClassPtr,
196 (IPTR)BGUI_BGUI_NewObjectA,
197 (IPTR)BGUI_BGUI_RequestA,
198 (IPTR)BGUI_BGUI_Help,
199 (IPTR)BGUI_BGUI_LockWindow,
200 (IPTR)BGUI_BGUI_UnlockWindow,
201 (IPTR)BGUI_BGUI_DoGadgetMethodA,
203 * Private routines.
205 (IPTR)BGUI_BGUI_AllocPoolMem,
206 (IPTR)BGUI_BGUI_FreePoolMem,
208 * Public routines.
210 (IPTR)BGUI_BGUI_AllocBitMap,
211 (IPTR)BGUI_BGUI_FreeBitMap,
212 (IPTR)BGUI_BGUI_CreateRPortBitMap,
213 (IPTR)BGUI_BGUI_FreeRPortBitMap,
214 (IPTR)BGUI_BGUI_InfoTextSize,
215 (IPTR)BGUI_BGUI_InfoText,
216 (IPTR)BGUI_BGUI_GetLocaleStr,
217 (IPTR)BGUI_BGUI_GetCatalogStr,
218 (IPTR)BGUI_BGUI_FillRectPattern,
219 (IPTR)BGUI_BGUI_PostRender,
220 (IPTR)BGUI_BGUI_MakeClassA,
221 (IPTR)BGUI_BGUI_FreeClass,
222 (IPTR)BGUI_BGUI_PackStructureTags,
223 (IPTR)BGUI_BGUI_UnpackStructureTags,
225 * Private routines.
227 (IPTR)BGUI_BGUI_GetDefaultTags,
228 (IPTR)BGUI_BGUI_DefaultPrefs,
229 (IPTR)BGUI_BGUI_LoadPrefs,
230 (IPTR)BGUI_BGUI_AllocPoolMemDebug,
231 (IPTR)BGUI_BGUI_FreePoolMemDebug,
232 #else
234 * System interface.
236 (IPTR)LibOpen,
237 (IPTR)LibClose,
238 (IPTR)LibExpunge,
239 (IPTR)LibVoid,
241 * Public routines.
244 (IPTR)BGUI_GetClassPtr,
245 (IPTR)BGUI_NewObjectA,
246 (IPTR)BGUI_RequestA,
247 (IPTR)BGUI_Help,
248 (IPTR)BGUI_LockWindow,
249 (IPTR)BGUI_UnlockWindow,
250 (IPTR)BGUI_DoGadgetMethodA,
252 * Private routines.
254 (IPTR)BGUI_AllocPoolMem,
255 (IPTR)BGUI_FreePoolMem,
257 * Public routines.
259 (IPTR)BGUI_AllocBitMap,
260 (IPTR)BGUI_FreeBitMap,
261 (IPTR)BGUI_CreateRPortBitMap,
262 (IPTR)BGUI_FreeRPortBitMap,
263 (IPTR)BGUI_InfoTextSize,
264 (IPTR)BGUI_InfoText,
265 (IPTR)BGUI_GetLocaleStr,
266 (IPTR)BGUI_GetCatalogStr,
267 (IPTR)BGUI_FillRectPattern,
268 (IPTR)BGUI_PostRender,
269 (LONG)BGUI_MakeClassA,
270 (IPTR)BGUI_FreeClass,
271 (IPTR)BGUI_PackStructureTags,
272 (IPTR)BGUI_UnpackStructureTags,
274 * Private routines.
276 (IPTR)BGUI_GetDefaultTags,
277 (IPTR)BGUI_DefaultPrefs,
278 (IPTR)BGUI_LoadPrefs,
279 (IPTR)BGUI_AllocPoolMemDebug,
280 (IPTR)BGUI_FreePoolMemDebug,
281 #endif
283 * Table end marker.
289 * Close opened libraries.
291 SAVEDS STATIC VOID CloseLibs(void)
293 if( LocaleBase ) CloseLibrary( (struct Library *) LocaleBase);
294 if( KeymapBase ) CloseLibrary( KeymapBase );
295 if( CxBase ) CloseLibrary( CxBase );
296 if( AslBase ) CloseLibrary( AslBase );
297 if( LayersBase ) CloseLibrary( LayersBase );
298 if( UtilityBase ) CloseLibrary( (struct Library *) UtilityBase );
299 if( GadToolsBase ) CloseLibrary( GadToolsBase );
300 if( DataTypesBase ) CloseLibrary( DataTypesBase );
301 if( IFFParseBase ) CloseLibrary( IFFParseBase );
302 if( WorkbenchBase ) CloseLibrary( WorkbenchBase );
303 if( GfxBase ) CloseLibrary( (struct Library *) GfxBase );
304 if( IntuitionBase ) CloseLibrary( (struct Library *) IntuitionBase );
305 if( DOSBase ) CloseLibrary( (struct Library *) DOSBase );
309 * Setup localized strings.
311 makeproto VOID InitLocale(void)
313 UWORD num;
316 * locale.library opened?
318 if ( LocaleBase
319 && Catalog==NULL) {
321 * Obtain lock.
323 ObtainSemaphore( &TaskLock );
326 * Open up the catalog.
328 if ( Catalog = OpenCatalog( NULL, "BGUI.catalog", OC_BuiltInLanguage, "english", OC_Version, 2, TAG_END )) {
330 * Get strings.
332 for ( num = 0; num < NumCatCompStrings; num++ )
333 CatCompArray[ num ].cca_Str = GetCatalogStr( Catalog, num, CatCompArray[ num ].cca_Str );
337 * Free access.
339 ReleaseSemaphore( &TaskLock );
344 * Library initialization.
346 //makeproto SAVEDS ASM struct Library *LibInit(REG(a0) BPTR segment, REG(a6) struct ExecBase *syslib)
347 #ifndef __AROS__
348 makeproto SAVEDS
349 #else
350 makeproto
351 #endif
352 ASM REGFUNC3(struct Library *, LibInit,
353 REGPARAM(D0, ULONG, dummy),
354 REGPARAM(A0, BPTR, segment),
355 REGPARAM(A6, struct ExecBase *, syslib)
358 struct Library *lib;
361 * Assign SysBase.
364 SysBase = syslib;
367 * Open up system libraries.
369 #ifdef ENHANCED
370 DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 39);
371 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39);
372 GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 39);
373 #else
374 OS30 = (((struct Library *)SysBase)->lib_Version >= 39);
376 DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37);
377 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
378 GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37);
379 #endif
381 LocaleBase = (struct LocaleBase *) OpenLibrary("locale.library", 38);
383 GadToolsBase = OpenLibrary("gadtools.library", 37);
384 UtilityBase = (struct UtilityBase *) OpenLibrary("utility.library", 37);
385 LayersBase = OpenLibrary("layers.library", 37);
386 AslBase = OpenLibrary("asl.library", 37);
387 CxBase = OpenLibrary("commodities.library", 37);
388 KeymapBase = OpenLibrary("keymap.library", 37);
389 IFFParseBase = OpenLibrary("iffparse.library", 37);
390 WorkbenchBase = OpenLibrary("workbench.library", 37);
391 DataTypesBase = OpenLibrary("datatypes.library", 39);
393 #ifdef __AROS__
394 #warning Commented InitInputStack
395 #else
396 InitInputStack();
397 #endif
399 #ifdef OUTDATE_BUILD
400 if(DOSBase)
402 static struct DateStamp expiry_date=
404 OUTDATE_BUILD,0,0
406 struct DateStamp today;
408 DateStamp(&today);
409 if(CompareDates(&today,&expiry_date)<0)
411 CloseLibs();
412 return(NULL);
415 #endif
417 * All libraries open?
419 if (DOSBase && IntuitionBase && GfxBase && GadToolsBase && UtilityBase && LayersBase && IFFParseBase && WorkbenchBase
420 && AslBase && CxBase && KeymapBase)
423 * Create the library.
425 if (BGUIBase = lib = MakeLibrary((APTR)Vectors, NULL, NULL, sizeof(struct Library), NULL))
428 * Initialize library structure.
430 lib->lib_Node.ln_Type = NT_LIBRARY;
431 lib->lib_Node.ln_Name = (UBYTE *)LibName;
432 lib->lib_Flags = LIBF_CHANGED | LIBF_SUMUSED;
433 lib->lib_Version = LIBVER;
434 lib->lib_Revision = LIBREV;
435 lib->lib_IdString = (APTR)LibID;
438 * Globally assign the seglist.
440 SegList = segment;
443 * Add us to the system.
445 AddLibrary(lib);
448 * Initialize the task-list.
450 InitTaskList();
452 return(lib);
455 CloseLibs();
456 return NULL;
458 REGFUNC_END
461 * Open library.
463 #ifdef __AROS__
464 makeproto
465 AROS_LH1(struct Library *, LibOpen,
466 AROS_LHA(ULONG, version, D0),
467 struct Library *, lib, 1, BGUI)
468 #else
469 makeproto SAVEDS ASM struct Library *LibOpen(REG(a6) struct Library *lib, REG(d0) ULONG libver)
470 #endif
472 AROS_LIBFUNC_INIT
474 UWORD tc;
477 * Add this task to the list.
480 if ((tc = AddTaskMember()) != TASK_FAILED)
483 * Increase open counter when necessary.
485 if (tc == TASK_ADDED)
486 lib->lib_OpenCnt++;
489 * Clear delayed expunge flag.
491 lib->lib_Flags &= ~LIBF_DELEXP;
494 * Return library base or NULL upon failure.
496 return lib;
499 return NULL;
501 AROS_LIBFUNC_EXIT
505 * Close library.
507 #ifdef __AROS__
508 AROS_LH0(BPTR, LibClose,
509 struct Library *, lib, 2, BGUI)
510 #else
511 makeproto SAVEDS ASM BPTR LibClose(REG(a6) struct Library *lib)
512 #endif
514 AROS_LIBFUNC_INIT
517 * Remove the task from the member list.
519 if (!FreeTaskMember())
520 return NULL;
523 * Of course we do not expunge when we still have accessors.
525 if (lib->lib_OpenCnt && --lib->lib_OpenCnt)
526 return NULL;
529 * Delayed expunge pending?
531 if (lib->lib_Flags & LIBF_DELEXP)
532 #ifdef __AROS__
533 return AROS_UFC2(BPTR, BGUI_LibExpunge,
534 AROS_UFCA(struct Library *, lib, D0),
535 AROS_UFCA(struct ExecBase *, SysBase, A6));
536 #else
537 return LibExpunge(lib);
538 #endif
540 * Otherwise we remain in memory.
542 return NULL;
544 AROS_LIBFUNC_EXIT
548 * Expunge library.
550 #ifdef __AROS__
551 AROS_LH1(BPTR, LibExpunge,
552 AROS_LHA(struct Library *, lib, D0),
553 struct ExecBase *, sysBase, 3, BGUI)
554 #else
555 makeproto SAVEDS ASM BPTR LibExpunge(REG(a6) struct Library *lib)
556 #endif
558 AROS_LIBFUNC_INIT
561 * No expunge when we still
562 * have accessors or when the classes
563 * fail to free.
565 if (lib->lib_OpenCnt || (!FreeClasses()))
568 * Set delayed expunge flag.
570 lib->lib_Flags |= LIBF_DELEXP;
571 return NULL;
575 * Cleanup locale stuff.
577 if (Catalog)
578 CloseCatalog(Catalog);
580 #ifdef __AROS__
581 #warning Commented FreeInputStack
582 #else
583 FreeInputStack();
584 #endif
587 * Close system libraries.
589 CloseLibs();
591 FreeTaskList();
594 * Remove us from the system and deallocate
595 * the memory we took up.
597 Remove(&lib->lib_Node);
598 FreeMem((char *)lib - lib->lib_NegSize, lib->lib_NegSize + lib->lib_PosSize);
601 * Return the seglist so that the
602 * system can unload us.
604 return SegList;
606 AROS_LIBFUNC_EXIT
610 * Reserved routine.
612 #ifdef __AROS__
613 AROS_LH0(LONG, LibVoid,
614 struct Library *, lib, 4, BGUI)
615 #else
616 makeproto SAVEDS LONG LibVoid(void)
617 #endif
619 AROS_LIBFUNC_INIT
621 return 0;
623 AROS_LIBFUNC_EXIT