Corrections to SVN properties.
[AROS.git] / external / openurl / library / init.c
blobd56d1179bdf44333d5284e1f5d097be0e664e2a9
1 /***************************************************************************
3 openurl.library - universal URL display and browser launcher library
4 Copyright (C) 1998-2005 by Troels Walsted Hansen, et al.
5 Copyright (C) 2005-2009 by openurl.library Open Source Team
7 This library is free software; it has been placed in the public domain
8 and you can freely redistribute it and/or modify it. Please note, however,
9 that some components may be under the LGPL or GPL license.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 openurl.library project: http://sourceforge.net/projects/openurllib/
17 $Id$
19 ***************************************************************************/
21 #include "lib.h"
23 #include "debug.h"
25 #if defined(__amigaos4__)
26 struct Library *DOSBase = NULL;
27 struct Library *UtilityBase = NULL;
28 struct Library *RexxSysBase = NULL;
29 struct Library *IFFParseBase = NULL;
31 struct DOSIFace* IDOS = NULL;
32 struct UtilityIFace* IUtility = NULL;
33 struct RexxSysIFace* IRexxSys = NULL;
34 struct IFFParseIFace* IIFFParse = NULL;
36 #if !defined(__NEWLIB__)
37 extern struct Library *__UtilityBase;
38 extern struct UtilityIFace* __IUtility;
39 #endif
41 #else
42 struct DosLibrary *DOSBase = NULL;
43 #if defined(__AROS__)
44 struct UtilityBase *UtilityBase = NULL;
45 #else
46 struct Library *UtilityBase = NULL;
47 struct Library *__UtilityBase = NULL; // required by clib2 & libnix
48 #endif
49 #if defined(__MORPHOS__)
50 struct Library *RexxSysBase = NULL;
51 #else
52 struct RxsLib *RexxSysBase = NULL;
53 #endif
54 struct Library *IFFParseBase = NULL;
55 #endif
57 /***********************************************************************/
59 ULONG
60 freeBase(struct LibraryHeader *lib)
62 ENTER();
64 D(DBF_STARTUP, "freeing all resources of openurl.library");
66 if(lib->prefs != NULL)
68 URL_FreePrefsA(lib->prefs,NULL);
69 lib->prefs = NULL;
72 if(RexxSysBase)
74 DROPINTERFACE(IRexxSys);
75 CloseLibrary((struct Library *)RexxSysBase);
76 RexxSysBase = NULL;
79 if(IFFParseBase)
81 DROPINTERFACE(IIFFParse);
82 CloseLibrary(IFFParseBase);
83 IFFParseBase = NULL;
86 // delete our private memory pool
87 if(lib->pool != NULL)
89 #if defined(__amigaos4__)
90 FreeSysObject(ASOT_MEMPOOL, lib->pool);
91 #else
92 DeletePool(lib->pool);
93 #endif
94 lib->pool = NULL;
97 if(UtilityBase)
99 DROPINTERFACE(IUtility);
100 CloseLibrary((struct Library *)UtilityBase);
101 UtilityBase = NULL;
104 if(DOSBase)
106 DROPINTERFACE(IDOS);
107 CloseLibrary((struct Library *)DOSBase);
108 DOSBase = NULL;
111 CLEAR_FLAG(lib->flags, BASEFLG_Init);
113 RETURN(TRUE);
114 return TRUE;
117 /***********************************************************************/
119 ULONG
120 initBase(struct LibraryHeader *lib)
122 ENTER();
124 if((DOSBase = (APTR)OpenLibrary("dos.library", 37)) &&
125 GETINTERFACE(IDOS, DOSBase))
127 if((UtilityBase = (APTR)OpenLibrary("utility.library", 37)) &&
128 GETINTERFACE(IUtility, UtilityBase))
130 // we have to please the internal utilitybase
131 // pointers of libnix and clib2
132 #if !defined(__NEWLIB__) && !defined(__AROS__)
133 __UtilityBase = (APTR)UtilityBase;
134 #if defined(__amigaos4__)
135 __IUtility = IUtility;
136 #endif
137 #endif
139 // setup the debugging stuff
140 #if defined(DEBUG)
141 SetupDebug();
142 #endif
144 if((IFFParseBase = OpenLibrary("iffparse.library", 37)) &&
145 GETINTERFACE(IIFFParse, IFFParseBase))
146 if((RexxSysBase = (APTR)OpenLibrary("rexxsyslib.library", 36)) &&
147 GETINTERFACE(IRexxSys, RexxSysBase))
149 #if defined(__amigaos4__)
150 lib->pool = AllocSysObjectTags(ASOT_MEMPOOL, ASOPOOL_MFlags, MEMF_SHARED|MEMF_CLEAR,
151 ASOPOOL_Puddle, 4096,
152 ASOPOOL_Threshold, 512,
153 ASOPOOL_Name, "openurl.library pool",
154 ASOPOOL_LockMem, FALSE,
155 TAG_DONE);
156 #else
157 lib->pool = CreatePool(MEMF_CLEAR, 4096, 512);
158 #endif
159 if(lib->pool != NULL)
161 lib->prefs = loadPrefsNotFail();
163 if(lib->prefs != NULL)
165 SET_FLAG(lib->flags, BASEFLG_Init);
167 RETURN(TRUE);
168 return TRUE;
175 freeBase(lib);
177 RETURN(FALSE);
178 return FALSE;
181 /***********************************************************************/