2 ** openurl.library - universal URL display and browser
5 ** Written by Troels Walsted Hansen <troels@thule.no>
6 ** Placed in the public domain.
9 ** - Alfonso Ranieri <alforan@tin.it>
10 ** - Stefan Kost <ensonic@sonicpulse.de>
12 ** Ported to OS4 by Alexandre Balaban <alexandre@balaban.name>
17 #include "openurl.library_rev.h"
19 /****************************************************************************/
21 UBYTE lib_name
[] = PRG
;
22 UBYTE lib_ver
[] = VSTRING
;
23 UBYTE lib_fullName
[] = PRGNAME
;
24 ULONG lib_version
= VERSION
;
25 ULONG lib_revision
= REVISION
;
27 struct ExecBase
*SysBase
= NULL
;
28 struct DosLibrary
*DOSBase
= NULL
;
29 struct Library
*UtilityBase
= NULL
;
30 struct Library
*IFFParseBase
= NULL
;
31 struct RxsLib
*RexxSysBase
= NULL
;
33 struct SignalSemaphore lib_sem
= {0};
34 struct SignalSemaphore lib_prefsSem
= {0};
35 struct SignalSemaphore lib_memSem
= {0};
38 struct URL_Prefs
*lib_prefs
= NULL
;
40 struct Library
*lib_base
= NULL
;
41 ULONG lib_segList
= (ULONG
)NULL
;
45 /****************************************************************************/
48 #include <exec/resident.h>
50 static struct Library
*initLib ( struct Library
*base
, BPTR segList
, struct ExecBase
*sys
);
51 static struct Library
*openLib ( void );
52 static ULONG
expungeLib ( void );
53 static ULONG
closeLib ( void );
54 static ULONG
nil (void );
55 static ULONG
first(void) __attribute((unused
));
57 /****************************************************************************/
65 /****************************************************************************/
67 static const APTR funcTable
[] =
69 (APTR
)FUNCARRAY_BEGIN
,
70 (APTR
)FUNCARRAY_32BIT_NATIVE
,
77 (APTR
)LIB_URL_OldGetPrefs
,
78 (APTR
)LIB_URL_OldFreePrefs
,
79 (APTR
)LIB_URL_OldSetPrefs
,
80 (APTR
)LIB_URL_OldGetDefaultPrefs
,
81 (APTR
)LIB_URL_OldLaunchPrefsApp
,
84 (APTR
)FUNCARRAY_32BIT_D0D1A0A1SR_NATIVE
,
88 (APTR
)FUNCARRAY_32BIT_NATIVE
,
89 (APTR
)LIB_URL_GetPrefsA
,
90 (APTR
)LIB_URL_FreePrefsA
,
91 (APTR
)LIB_URL_SetPrefsA
,
92 (APTR
)LIB_URL_LaunchPrefsAppA
,
93 (APTR
)LIB_URL_GetAttr
,
99 static const ULONG initTable
[] =
101 sizeof(struct Library
),
107 const struct Resident romTag
=
110 (struct Resident
*)&romTag
,
111 (struct Resident
*)&romTag
+1,
112 RTF_AUTOINIT
|RTF_PPC
|RTF_EXTENDED
,
123 const ULONG __abox__
= 1;
125 #elif defined(__amigaos4__)
126 #include <proto/exec.h>
127 /* amigaos4 *****************************************************************/
129 struct ExecIFace
*IExec
= NULL
;
130 struct DOSIFace
*IDOS
= NULL
;
131 struct UtilityIFace
*IUtility
= NULL
;
132 struct IFFParseIFace
*IIFFParse
= NULL
;
133 struct RexxSysIFace
*IRexxSys
= NULL
;
135 /* amigaos4 *****************************************************************/
137 struct Library
* SAVEDS ASM
initLib (REG(a0
,ULONG segList
), REG(a6
,struct ExecBase
*sys
), REG(d0
, struct Library
*base
));
138 //uint32 libObtain (struct LibraryManagerInterface *Self);
139 //uint32 libRelease (struct LibraryManagerInterface *Self);
140 struct Library
* SAVEDS ASM
openLib (REG(a6
,struct Library
*base
));
141 ULONG SAVEDS ASM
closeLib(REG(a6
,struct Library
*base
));
142 ULONG SAVEDS ASM
expungeLib (REG(a6
,struct Library
*base
));
144 struct Library
* mgr_Init (struct Library
*base
, BPTR segList
, struct ExecIFace
*ISys
);
145 uint32
mgr_Obtain (struct LibraryManagerInterface
*Self
);
146 uint32
mgr_Release (struct LibraryManagerInterface
*Self
);
147 struct Library
* mgr_Open (struct LibraryManagerInterface
*Self
, uint32 version
);
148 APTR
mgr_Close (struct LibraryManagerInterface
*Self
);
149 APTR
mgr_Expunge (struct LibraryManagerInterface
*Self
);
151 uint32 VARARGS68K
OS4_URL_Obtain( struct OpenURLIFace
*Self
);
152 uint32 VARARGS68K
OS4_URL_Release( struct OpenURLIFace
*Self
);
154 /* amigaos4 *****************************************************************/
156 static BOOL bAlreadyHasSemaphore
= FALSE
;
158 /* amigaos4 *****************************************************************/
160 static APTR lib_manager_vectors
[] = {
172 static struct TagItem lib_managerTags
[] = {
173 { MIT_Name
, (uint32
)"__library" },
174 { MIT_VectorTable
, (uint32
)lib_manager_vectors
},
179 void *main_vectors
[] = {
180 (void *) OS4_URL_Obtain
,
181 (void *) OS4_URL_Release
,
184 (void *) OS4_URL_OpenA
,
185 (void *) OS4_URL_Open
,
186 (void *) OS4_URL_OldGetPrefs
,
187 (void *) OS4_URL_OldFreePrefs
,
188 (void *) OS4_URL_OldSetPrefs
,
189 (void *) OS4_URL_OldGetDefaultPrefs
,
190 (void *) OS4_URL_OldLaunchPrefsApp
,
191 (void *) OS4_dispatch
,
192 (void *) OS4_URL_GetPrefsA
,
193 (void *) OS4_URL_GetPrefs
,
194 (void *) OS4_URL_FreePrefsA
,
195 (void *) OS4_URL_FreePrefs
,
196 (void *) OS4_URL_SetPrefsA
,
197 (void *) OS4_URL_SetPrefs
,
198 (void *) OS4_URL_LaunchPrefsAppA
,
199 (void *) OS4_URL_LaunchPrefsApp
,
200 (void *) OS4_URL_GetAttr
,
204 static struct TagItem lib_mainTags
[] = {
205 { MIT_Name
, (uint32
)"main" },
206 { MIT_VectorTable
, (uint32
)main_vectors
},
211 static APTR libInterfaces
[] = {
217 extern uint32 VecTable68K
[];
219 static struct TagItem libCreateTags
[] = {
220 { CLT_DataSize
, (uint32
)sizeof(struct Library
) },
221 { CLT_InitFunc
, (uint32
)mgr_Init
},
222 { CLT_Interfaces
, (uint32
)libInterfaces
},
223 { CLT_Vector68K
, (uint32
)VecTable68K
},
228 static struct Resident
__attribute__((used
)) romTag
= {
230 static struct Resident romTag
= {
232 RTC_MATCHWORD
, // rt_MatchWord
233 &romTag
, // rt_MatchTag
234 &romTag
+1, // rt_EndSkip
235 RTF_NATIVE
| RTF_AUTOINIT
, // rt_Flags
236 VERSION
, // rt_Version
237 NT_LIBRARY
, // rt_Type
240 lib_ver
, // rt_IdString
241 libCreateTags
// rt_Init
246 /****************************************************************************/
249 static struct Library *initLib(struct Library *base,BPTR segList,struct ExecBase *sys)
250 #elif defined(__amigaos4__)
251 struct Library * initLib(struct Library *base, BPTR segList, struct ExecIFace *ISys)
253 struct Library *SAVEDS ASM initLib(REG(a0,ULONG segList),REG(a6,struct ExecBase *sys),REG(d0, struct Library *base))
256 #if defined(__amigaos4__)
257 base->lib_Node.ln_Type = NT_LIBRARY;
258 base->lib_Node.ln_Pri = 0;
259 base->lib_Node.ln_Name = lib_name;
260 base->lib_Flags = LIBF_SUMUSED|LIBF_CHANGED;
261 base->lib_Version = lib_version;
262 base->lib_Revision = lib_revision;
263 base->lib_IdString = lib_ver;
267 SysBase = (struct ExecBase*)ISys->Data.LibBase;
272 InitSemaphore(&lib_sem);
273 InitSemaphore(&lib_prefsSem);
274 InitSemaphore(&lib_memSem);
276 lib_segList = segList;
278 return lib_base = base;
282 static struct Library
*initLib(struct Library
*base
,BPTR segList
,struct ExecBase
*sys
)
284 struct Library
* SAVEDS ASM
initLib (REG(a0
,ULONG segList
), REG(a6
,struct ExecBase
*sys
), REG(d0
, struct Library
*base
))
289 InitSemaphore(&lib_sem
);
290 InitSemaphore(&lib_prefsSem
);
291 InitSemaphore(&lib_memSem
);
293 lib_segList
= segList
;
295 return lib_base
= base
;
298 /****************************************************************************/
301 static struct Library
*openLib(void)
303 struct Library
*base
= (struct Library
*)REG_A6
;
305 struct Library
* SAVEDS ASM
openLib(REG(a6
,struct Library
*base
))
311 ObtainSemaphore(&lib_sem
);
314 base
->lib_Flags
&= ~LIBF_DELEXP
;
316 if (!(lib_flags
& BASEFLG_Init
) && !initBase())
323 ReleaseSemaphore(&lib_sem
);
328 /****************************************************************************/
331 static ULONG
expungeLib(void)
333 struct Library
*base
= (struct Library
*)REG_A6
;
335 ULONG SAVEDS ASM
expungeLib(REG(a6
,struct Library
*base
))
341 #if defined(__amigaos4__)
342 // prevents a deadlock if called from closeLib
343 if( !bAlreadyHasSemaphore
)
345 ObtainSemaphore(&lib_sem
);
347 if (!base
->lib_OpenCnt
&& !lib_use
)
349 Remove((struct Node
*)base
);
351 #if defined(__amigaos4__)
355 FreeMem((UBYTE
*)base
-base
->lib_NegSize
,base
->lib_NegSize
+base
->lib_PosSize
);
362 base
->lib_Flags
|= LIBF_DELEXP
;
366 #if defined(__amigaos4__)
367 // prevents a deadlock if called from closeLib
368 if( !bAlreadyHasSemaphore
)
370 ReleaseSemaphore(&lib_sem
);
375 /****************************************************************************/
378 static ULONG
closeLib(void)
380 struct Library
*base
= (struct Library
*)REG_A6
;
382 ULONG SAVEDS ASM
closeLib(REG(a6
,struct Library
*base
))
386 ULONG res
= (ULONG
)NULL
;
388 ObtainSemaphore(&lib_sem
);
392 if (!base
->lib_OpenCnt
&& !lib_use
)
396 if (base
->lib_Flags
& LIBF_DELEXP
)
398 #if defined(__amigaos4__)
399 bAlreadyHasSemaphore
= TRUE
;
400 res
= (ULONG
)expungeLib( base
);
401 bAlreadyHasSemaphore
= FALSE
;
403 Remove((struct Node
*)base
);
404 FreeMem((UBYTE
*)base
-base
->lib_NegSize
,base
->lib_NegSize
+base
->lib_PosSize
);
411 ReleaseSemaphore(&lib_sem
);
416 /****************************************************************************/
419 static ULONG
nil(void)
425 /****************************************************************************/