delint type punned pointer
[AROS.git] / workbench / system / Wanderer / main.c
blob8cd8dd27a4add4857a0c1960d5bdb7cb2ab2262e
1 /*
2 Copyright © 2002-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
5 #include "portable_macros.h"
7 #ifdef __AROS__
8 #define MUIMASTER_YES_INLINE_STDARG
10 #define DEBUG 0
11 #include <aros/debug.h>
12 #endif
14 #include <dos/dos.h>
15 #include <libraries/mui.h>
17 #if defined(__AMIGA__) && !defined(__PPC__)
18 #define NO_INLINE_STDARG
19 #endif
21 #include <proto/alib.h>
22 #include <proto/intuition.h>
23 #include <proto/muimaster.h>
24 #include <proto/wb.h>
25 #include <proto/dos.h>
27 #include "locale.h"
28 #include "wanderer.h"
30 #ifndef __AROS__
31 #define DEBUG 1
33 #ifdef DEBUG
34 #define D(x) if (DEBUG) x
35 #ifdef __amigaos4__
36 #define bug DebugPrintF
37 #else
38 #define bug kprintf
39 #endif
40 #else
41 #define D(...)
42 #endif
43 #endif
45 #ifndef __AROS__
47 #ifdef __MORPHOS__
48 struct Library *LocaleBase = NULL;
49 struct Library *UtilityBase = NULL;
50 #elif __amigaos4__
51 struct Library *LocaleBase=NULL;
52 struct UtilityBase *UtilityBase;
53 #else
54 struct LocaleBase *LocaleBase = NULL;
55 struct UtilityBase *UtilityBase = NULL;
56 #endif
58 struct GfxBase *GfxBase = NULL;
59 struct IntuitionBase *IntuitionBase = NULL;
60 struct Library *IFFParseBase = NULL;
61 struct LayersBase *LayersBase = NULL;
62 struct Library *WorkbenchBase = NULL;
63 struct IconBase *IconBase = NULL;
64 struct DataTypesBase *DataTypesBase = NULL;
65 struct DiskfontBase *DiskfontBase = NULL;
67 struct Library *MUIMasterBase = NULL;
68 struct Library *CyberGfxBase = NULL;
71 #ifdef __amigaos4__
72 struct UtilityIFace *IUtility;
73 struct GraphicsIFace *IGraphics;
74 struct LayersIFace *ILayers;
75 struct DataTypesIFace *IDataTypes;
76 struct IconIFace *IIcon;
77 struct WorkbenchIFace *IWorkbench;
78 struct DiskfontIFace *IDiskfont;
79 struct IntuitionIFace *IIntuition;
80 struct IFFParseIFace *IIFFParse;
81 struct LocaleIFace *ILocale;
82 struct MUIMasterIFace *IMUIMaster;
83 struct CyberGfxIFace *ICyberGfx;
84 #endif
85 #endif
87 /* global variables */
88 Object *_WandererIntern_AppObj = NULL;
89 Class *_WandererIntern_CLASS = NULL;
91 /* Don't output errors to the console, open requesters instead */
92 int __forceerrorrequester = 1;
95 #ifndef __AROS__
96 //struct MUI_CustomClass *IconWindow_Class = NULL;
98 struct MUI_CustomClass *IconList_Class = NULL;
99 struct MUI_CustomClass *IconDrawerList_Class = NULL;
100 struct MUI_CustomClass *IconListview_Class = NULL;
101 struct MUI_CustomClass *IconVolumeList_Class = NULL;
103 ///deInitLibs()
104 void deInitLibs(void)
106 if (MUIMasterBase)
110 if (IconWindowIconNetworkBrowserList_CLASS)
111 IconWindowIconNetworkBrowserList_Deinitialize();
112 D(bug("2\n"));*/
113 if (WandererPrefs_CLASS)
114 WandererPrefs_Deinitialize();
116 if (Wanderer_CLASS)
117 Wanderer_Deinitialize();
119 if (IconWindowIconVolumeList_CLASS)
120 IconWindowIconVolumeList_Deinitialize();
122 if (IconWindowIconDrawerList_CLASS)
123 IconWindowIconDrawerList_Deinitialize();
126 if (IconVolumeList_Class)
127 MUI_DeleteCustomClass(IconVolumeList_Class);
129 if (IconListview_Class)
130 MUI_DeleteCustomClass(IconListview_Class);
132 if (IconDrawerList_Class)
133 MUI_DeleteCustomClass(IconDrawerList_Class);
135 if (IconList_Class)
136 MUI_DeleteCustomClass(IconList_Class);
138 if (IconWindow_CLASS)
139 IconWindow_Deinitialize();
142 #ifdef __amigaos4__
143 if (IMUIMaster)
144 DropInterface((struct Interface *)IMUIMaster);
145 #endif
147 CloseLibrary(MUIMasterBase);
150 if (LocaleBase)
152 Locale_Deinitialize();
153 #ifdef __amigaos4__
154 if (ILocale)
155 DropInterface((struct Interface *)ILocale);
156 #endif
157 CloseLibrary((struct Library *)LocaleBase);
160 #ifdef __amigaos4__
161 if (IIFFParse)
162 DropInterface((struct Interface *)IIFFParse);
164 if (ICyberGfx)
165 DropInterface((struct Interface *)ICyberGfx);
167 if (IWorkbench)
168 DropInterface((struct Interface *)IWorkbench);
170 if (IIcon)
171 DropInterface((struct Interface *)IIcon);
174 if (IDataTypes)
175 DropInterface((struct Interface *)IDataTypes);
177 if (IDiskfont)
178 DropInterface((struct Interface *)IDiskfont);
180 if (IIntuition)
181 DropInterface((struct Interface *)IIntuition);
183 if (IUtility)
184 DropInterface((struct Interface *)IUtility);
186 if (ILayers)
187 DropInterface((struct Interface *)ILayers);
189 if (IGraphics)
190 DropInterface((struct Interface *)IGraphics);
191 #endif
193 if (IFFParseBase) CloseLibrary(IFFParseBase);
197 if (WorkbenchBase) CloseLibrary((struct Library *)WorkbenchBase);
199 if (IconBase) CloseLibrary((struct Library *)IconBase);
201 if (DiskfontBase) CloseLibrary((struct Library *)DiskfontBase);
203 if (DataTypesBase) CloseLibrary((struct Library *)DataTypesBase);
205 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
207 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
209 if (UtilityBase) CloseLibrary((struct Library *)UtilityBase);
211 if (LayersBase) CloseLibrary((struct Library *)LayersBase);
213 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
218 ///initLibs()
219 int initLibs(void)
222 if (!(GfxBase =(struct GfxBase *) OpenLibrary("graphics.library",40))
223 #ifdef __amigaos4__
224 || !(IGraphics = (struct GraphicsIFace *) GetInterface((struct Library *)GfxBase,
225 "main",
227 NULL))
228 #endif
230 return 1;
232 if(!(LayersBase =(struct LayersBase *) OpenLibrary((CONST_STRPTR)"layers.library",40))
233 #ifdef __amigaos4__
234 || !(ILayers = (struct LayersIFace *) GetInterface((struct Library *)LayersBase,
235 "main",
237 NULL))
238 #endif
240 return 1;
244 #ifdef __MORPHOS__
245 if (!(UtilityBase = (struct Library *)OpenLibrary("utility.library",40))
246 #else
247 if (!(UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library",40))
248 #endif
249 #ifdef __amigaos4__
250 || !(IUtility = (struct UtilityIFace *) GetInterface((struct Library *)UtilityBase,
251 "main",
253 NULL))
254 #endif
256 return 1;
260 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary((CONST_STRPTR)"intuition.library",40))
261 #ifdef __amigaos4__
262 || !(IIntuition = (struct IntuitionIFace *) GetInterface((struct Library *)IntuitionBase,
263 "main",
265 NULL))
266 #endif
268 return 1;
271 if (!(MUIMasterBase = OpenLibrary((CONST_STRPTR)"muimaster.library",19))
272 #ifdef __amigaos4__
273 || !(IMUIMaster = (struct MUIMasterIFace *) GetInterface((struct Library *)MUIMasterBase,
274 "main",
276 NULL))
277 #endif
279 return 1;
282 #ifdef __MORPHOS__
283 if (!(LocaleBase = OpenLibrary((CONST_STRPTR)"locale.library",39))
284 #elif __amigaos4__
285 if (!(LocaleBase =(struct Library *) OpenLibrary("locale.library",39))
286 #else
287 if (!(LocaleBase =(struct LocaleBase *) OpenLibrary("locale.library",39))
288 #endif
289 #ifdef __amigaos4__
290 || !(ILocale = (struct LocaleIFace *) GetInterface((struct Library *)LocaleBase,
291 "main",
293 NULL))
294 #endif
296 return 1;
300 Locale_Initialize();
302 if (!(IFFParseBase = OpenLibrary((CONST_STRPTR)"iffparse.library",40))
303 #ifdef __amigaos4__
304 || !(IIFFParse = (struct IFFParseIFace *) GetInterface((struct Library *)IFFParseBase,
305 "main",
307 NULL))
308 #endif
310 return 1;
314 if(!(CyberGfxBase = OpenLibrary("cybergraphics.library",41))
315 #ifdef __amigaos4__
316 || !(ICyberGfx = (struct CyberGfxIFace *) GetInterface((struct Library *)CyberGfxBase,
317 "main",
319 NULL))
320 #endif
322 return 1;
324 if(!(WorkbenchBase = OpenLibrary("workbench.library",40))
325 #ifdef __amigaos4__
326 || !(IWorkbench = (struct WorkbenchIFace *) GetInterface((struct Library *)WorkbenchBase,
327 "main",
329 NULL))
330 #endif
332 return 1;
334 if(!(DiskfontBase = (struct DiskfontBase *)OpenLibrary((CONST_STRPTR)"diskfont.library",40))
335 #ifdef __amigaos4__
336 || !(IDiskfont = (struct DiskfontIFace *) GetInterface((struct Library *)DiskfontBase,
337 "main",
339 NULL))
340 #endif
342 return 1;
344 if(!(IconBase = (struct IconBase *)OpenLibrary((CONST_STRPTR)"icon.library",41))
345 #ifdef __amigaos4__
346 || !(IIcon = (struct IconIFace *) GetInterface((struct Library *)IconBase,
347 "main",
349 NULL))
350 #endif
352 return 1;
354 if(!(DataTypesBase = (struct DataTypesBase *)OpenLibrary((CONST_STRPTR)"datatypes.library",40))
355 #ifdef __amigaos4__
356 || !(IDataTypes = (struct DataTypesIFace *) GetInterface((struct Library *)DataTypesBase,
357 "main",
359 NULL))
360 #endif
362 return 1;
366 if (!initIconWindowClass())
367 return 1;
369 // if (!(IconWindow_Class = (struct MUI_CustomClass *) initIconWindowClass()))
370 // return 1;
372 if (!(IconList_Class = (struct MUI_CustomClass *) initIconListClass()))
373 return 1;
375 if (!(IconDrawerList_Class = (struct MUI_CustomClass *) initIconDrawerListClass()))
376 return 1;
378 if (!(IconListview_Class = (struct MUI_CustomClass *) initIconListviewClass()))
379 return 1;
381 if (!(IconVolumeList_Class = (struct MUI_CustomClass *) initIconVolumeListClass()))
382 return 1;
385 IconWindowIconDrawerList_Initialize();
387 IconWindowIconVolumeList_Initialize();
389 // IconWindowIconNetworkBrowserList_Initialize();
392 Wanderer_Initialize();
394 WandererPrefs_Initialize();
396 return 0;
400 #endif
402 ///main()
403 int main(void)
405 LONG retval = RETURN_ERROR;
407 /* WB programs have NULL pr_ConsoleTask */
408 SetConsoleTask(NULL);
410 #ifndef __AROS__
411 if (initLibs())
412 return retval;
413 #endif
416 struct Task *me = (struct Task *)FindTask(NULL);
418 bug("[Wanderer] %s: This Task @ %p \n", __PRETTY_FUNCTION__, me);
419 bug("[Wanderer] %s: SPLower @ %p \n", __PRETTY_FUNCTION__, me->tc_SPLower);
420 bug("[Wanderer] %s: SPUpper @ %p \n", __PRETTY_FUNCTION__, me->tc_SPUpper);
423 D(bug("[Wanderer] %s: Wanderer Initialising .. \n", __PRETTY_FUNCTION__));
424 if ((_WandererIntern_AppObj = NewObject(Wanderer_CLASS->mcc_Class, NULL, TAG_DONE)) != NULL)
426 D(bug("[Wanderer] %s: Launching WBStartup items .. \n", __PRETTY_FUNCTION__));
427 OpenWorkbenchObject("Wanderer:Tools/ExecuteStartup", TAG_DONE);
429 D(bug("[Wanderer] %s: Handing control over to Zune .. \n", __PRETTY_FUNCTION__));
430 retval = DoMethod(_WandererIntern_AppObj, MUIM_Application_Execute);
432 D(bug("[Wanderer] %s: Returned from Zune's control .. \n", __PRETTY_FUNCTION__));
433 MUI_DisposeObject(_WandererIntern_AppObj);
436 D(bug("[Wanderer] %s: Exiting .. \n", __PRETTY_FUNCTION__));
438 #ifndef __AROS__
439 deInitLibs();
440 #endif
442 return retval;