grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / popupmenu / pminit.c
blob8f3743e8bf423d76d09c3f5ea4df3b86e8a2a510
1 //
2 // PopupMenu
3 // ©1996-2000 Henrik Isaksson
4 //
5 // Library init & cleanup
6 //
8 #define INIT 1
10 #include "pmpriv.h"
14 // Libraries we need
17 struct Library *UtilityBase=NULL;
18 struct IntuitionBase *IntuitionBase=NULL;
19 struct GfxBase *GfxBase=NULL;
20 struct DosLibrary *DOSBase=NULL;
21 struct Library *CxBase=NULL;
22 struct Library *LayersBase=NULL;
23 struct Library *CyberGfxBase=NULL;
25 extern struct ExecBase *SysBase;
27 APTR MemPool = NULL;
29 BOOL V40Gfx=FALSE;
30 BOOL CyberGfx=FALSE;
32 void CloseLibs(void)
34 if(MemPool) DeletePool(MemPool);
35 if(UtilityBase) CloseLibrary((struct Library *)UtilityBase);
36 if(GfxBase) CloseLibrary((struct Library *)GfxBase);
37 if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
38 if(DOSBase) CloseLibrary((struct Library *)DOSBase);
39 if(CxBase) CloseLibrary((struct Library *)CxBase);
40 if(LayersBase) CloseLibrary((struct Library *)LayersBase);
41 if(CyberGfxBase) CloseLibrary((struct Library *)CyberGfxBase);
43 MemPool = NULL;
44 UtilityBase=NULL;
45 GfxBase=NULL;
46 IntuitionBase=NULL;
47 DOSBase=NULL;
48 CxBase=NULL;
49 LayersBase=NULL;
50 CyberGfxBase=NULL;
53 BOOL __asm __saveds OpenLibs(register __a6 struct PopupMenuBase *l)
55 if(UtilityBase) return TRUE;
57 l->pmb_UtilityBase=OpenLibrary("utility.library",37L);
58 if(l->pmb_UtilityBase) {
59 UtilityBase=l->pmb_UtilityBase;
60 l->pmb_GfxBase=OpenLibrary("graphics.library",40L);
61 if(!l->pmb_GfxBase) l->pmb_GfxBase=OpenLibrary("graphics.library",37L);
62 else V40Gfx=TRUE;
63 if(l->pmb_GfxBase) {
64 GfxBase=(struct GfxBase *)l->pmb_GfxBase;
65 l->pmb_IntuitionBase=OpenLibrary("intuition.library",37L);
66 if(l->pmb_IntuitionBase) {
67 IntuitionBase=(struct IntuitionBase *)l->pmb_IntuitionBase;
68 l->pmb_DOSBase=OpenLibrary("dos.library",0L);
69 if(l->pmb_DOSBase) {
70 DOSBase=(struct DosLibrary *)l->pmb_DOSBase;
71 l->pmb_ExecBase = (struct Library *)SysBase;
72 l->pmb_CxBase=OpenLibrary("commodities.library",37L);
73 if(l->pmb_CxBase) {
74 CxBase=l->pmb_CxBase;
75 LayersBase=OpenLibrary("layers.library",0);
76 l->pmb_LayersBase=LayersBase;
77 if(LayersBase) {
78 CyberGfxBase=OpenLibrary("cybergraphics.library",39L);
79 if(CyberGfxBase)
80 CyberGfx=TRUE;
81 l->pmb_CyberGfxBase=CyberGfxBase;
82 #if defined(__AROS__) || defined(__MORPHOS)
83 if((MemPool = CreatePool(MEMF_ANY | MEMF_CLEAR | MEMF_SEM_PROTECTED, 10240L, 10240L))) {
84 #else
85 if((MemPool = CreatePool(MEMF_ANY, 10240L, 10240L))) {
86 #endif
88 PM_Prefs_Load(PMP_PATH);
90 return TRUE;
99 return FALSE;
103 // Library initializtion
106 int __asm __saveds __UserLibInit(register __a6 struct PopupMenuBase *l)
108 //kprintf("UserLibInit, pmbase = %08lx\n", l);
110 #ifdef __AROS__
111 SysBase = (struct ExecBase *)l->pmb_ExecBase;
112 #else
113 SysBase=*((struct ExecBase **)4);
114 #endif
115 if(!OpenLibs(l)) return -1;
117 //kprintf("UserLibInit failed\n");
119 return 0;
122 void __asm __saveds __UserLibCleanup(register __a6 struct PopupMenuBase *l)
125 //kprintf("UserLibCleanUp, pmbase = %08lx\n", l);
127 //PM_FreeAllImages();
129 PM_Prefs_Free();
131 //CloseLibs();
133 if(MemPool) DeletePool(MemPool);
134 if(UtilityBase) CloseLibrary((struct Library *)UtilityBase);
135 if(GfxBase) CloseLibrary((struct Library *)GfxBase);
136 if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
137 if(DOSBase) CloseLibrary((struct Library *)DOSBase);
138 if(CxBase) CloseLibrary((struct Library *)CxBase);
139 if(LayersBase) CloseLibrary((struct Library *)LayersBase);
140 if(CyberGfxBase) CloseLibrary((struct Library *)CyberGfxBase);
142 //kprintf("UserLibCleanUp done.\n");
145 #ifdef __AROS__
146 #include <aros/symbolsets.h>
147 #include <aros/debug.h>
149 static int AROS__UserLibInit(struct PopupMenuBase *PopupMenuBase)
151 return (__UserLibInit(PopupMenuBase) == 0) ? TRUE : FALSE;
154 static int AROS__UserLibCleanup(struct PopupMenuBase *PopupMenuBase)
156 __UserLibCleanup(PopupMenuBase);
158 return TRUE;
161 ADD2INITLIB(AROS__UserLibInit, 0);
162 ADD2EXPUNGELIB(AROS__UserLibCleanup, 0);
163 #endif