2 ** Copyright (c) 2001-2006 Expat maintainers.
4 ** Permission is hereby granted, free of charge, to any person obtaining
5 ** a copy of this software and associated documentation files (the
6 ** "Software"), to deal in the Software without restriction, including
7 ** without limitation the rights to use, copy, modify, merge, publish,
8 ** distribute, sublicense, and/or sell copies of the Software, and to
9 ** permit persons to whom the Software is furnished to do so, subject to
10 ** the following conditions:
12 ** The above copyright notice and this permission notice shall be included
13 ** in all copies or substantial portions of the Software.
15 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include <proto/exec.h>
27 #define LIBNAME "expat.library"
31 #define VSTRING "expat.library 4.1 (18.3.2005)" /* dd.mm.yyyy */
34 static const char* __attribute__((used
)) verstag
= "\0$VER: " VSTRING
;
38 struct Library libNode
;
44 struct ExpatBase
* libInit(struct ExpatBase
*libBase
, BPTR seglist
, struct ExecIFace
*ISys
);
45 uint32
libObtain (struct LibraryManagerInterface
*Self
);
46 uint32
libRelease (struct LibraryManagerInterface
*Self
);
47 struct ExpatBase
*libOpen (struct LibraryManagerInterface
*Self
, uint32 version
);
48 BPTR
libClose (struct LibraryManagerInterface
*Self
);
49 BPTR
libExpunge (struct LibraryManagerInterface
*Self
);
52 static APTR lib_manager_vectors
[] = {
65 static struct TagItem lib_managerTags
[] = {
66 { MIT_Name
, (uint32
)"__library" },
67 { MIT_VectorTable
, (uint32
)lib_manager_vectors
},
73 extern void *main_vectors
[];
75 static struct TagItem lib_mainTags
[] = {
76 { MIT_Name
, (uint32
)"main" },
77 { MIT_VectorTable
, (uint32
)main_vectors
},
83 static APTR libInterfaces
[] = {
90 static struct TagItem libCreateTags
[] = {
91 { CLT_DataSize
, sizeof(struct ExpatBase
) },
92 { CLT_InitFunc
, (uint32
)libInit
},
93 { CLT_Interfaces
, (uint32
)libInterfaces
},
98 static struct Resident
__attribute__((used
)) lib_res
= {
99 RTC_MATCHWORD
, // rt_MatchWord
100 &lib_res
, // rt_MatchTag
101 &lib_res
+1, // rt_EndSkip
102 RTF_NATIVE
| RTF_AUTOINIT
, // rt_Flags
103 VERSION
, // rt_Version
104 NT_LIBRARY
, // rt_Type
107 VSTRING
, // rt_IdString
108 libCreateTags
// rt_Init
112 struct Library
*DOSLib
= 0;
113 struct Library
*UtilityBase
= 0;
115 struct ExecIFace
*IExec
= 0;
116 struct DOSIFace
*IDOS
= 0;
117 struct UtilityIFace
*IUtility
= 0;
125 struct ExpatBase
*libInit(struct ExpatBase
*libBase
, BPTR seglist
, struct ExecIFace
*ISys
)
127 libBase
->libNode
.lib_Node
.ln_Type
= NT_LIBRARY
;
128 libBase
->libNode
.lib_Node
.ln_Pri
= LIBPRI
;
129 libBase
->libNode
.lib_Node
.ln_Name
= LIBNAME
;
130 libBase
->libNode
.lib_Flags
= LIBF_SUMUSED
|LIBF_CHANGED
;
131 libBase
->libNode
.lib_Version
= VERSION
;
132 libBase
->libNode
.lib_Revision
= REVISION
;
133 libBase
->libNode
.lib_IdString
= VSTRING
;
134 libBase
->SegList
= seglist
;
138 DOSLib
= OpenLibrary("dos.library", 51);
140 IDOS
= (struct DOSIFace
*)GetInterface(DOSLib
, "main", 1, NULL
);
142 UtilityBase
= OpenLibrary("utility.library", 51);
143 if ( UtilityBase
!= 0 ) {
144 IUtility
= (struct UtilityIFace
*)GetInterface(UtilityBase
, "main", 1, NULL
);
145 if ( IUtility
!= 0 ) {
149 CloseLibrary(UtilityBase
);
152 DropInterface((struct Interface
*)IDOS
);
155 CloseLibrary(DOSLib
);
162 uint32
libObtain( struct LibraryManagerInterface
*Self
)
164 ++Self
->Data
.RefCount
;
165 return Self
->Data
.RefCount
;
169 uint32
libRelease( struct LibraryManagerInterface
*Self
)
171 --Self
->Data
.RefCount
;
172 return Self
->Data
.RefCount
;
176 struct ExpatBase
*libOpen( struct LibraryManagerInterface
*Self
, uint32 version
)
178 struct ExpatBase
*libBase
;
180 libBase
= (struct ExpatBase
*)Self
->Data
.LibBase
;
182 ++libBase
->libNode
.lib_OpenCnt
;
183 libBase
->libNode
.lib_Flags
&= ~LIBF_DELEXP
;
189 BPTR
libClose( struct LibraryManagerInterface
*Self
)
191 struct ExpatBase
*libBase
;
193 libBase
= (struct ExpatBase
*)Self
->Data
.LibBase
;
195 --libBase
->libNode
.lib_OpenCnt
;
196 if ( libBase
->libNode
.lib_OpenCnt
) {
200 if ( libBase
->libNode
.lib_Flags
& LIBF_DELEXP
) {
201 return (BPTR
)Self
->LibExpunge();
209 BPTR
libExpunge( struct LibraryManagerInterface
*Self
)
211 struct ExpatBase
*libBase
;
214 libBase
= (struct ExpatBase
*)Self
->Data
.LibBase
;
216 if (libBase
->libNode
.lib_OpenCnt
== 0) {
217 Remove(&libBase
->libNode
.lib_Node
);
219 result
= libBase
->SegList
;
221 DropInterface((struct Interface
*)IUtility
);
222 CloseLibrary(UtilityBase
);
223 DropInterface((struct Interface
*)IDOS
);
224 CloseLibrary(DOSLib
);
226 DeleteLibrary(&libBase
->libNode
);
229 libBase
->libNode
.lib_Flags
|= LIBF_DELEXP
;