Bring in expat 2.1.0 from vendor.
[AROS.git] / workbench / libs / expat / amiga / expat_lib.c
blob70e91b101aa5adaf793361ad1494b070df566b5a
1 /*
2 ** Copyright (c) 2001-2009 Expat maintainers.
3 **
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.
24 #ifdef __USE_INLINE__
25 #undef __USE_INLINE__
26 #endif
28 #define __NOLIBBASE__
29 #define __NOGLOBALIFACE__
31 #include <dos/dos.h>
32 #include <proto/exec.h>
34 #include "expat_base.h"
37 #define LIBNAME "expat.library"
38 #define LIBPRI 0
39 #define VERSION 53
40 #define REVISION 1
41 #define VSTRING "expat.library 53.1 (7.8.2009)" /* dd.mm.yyyy */
44 static const char* __attribute__((used)) verstag = "\0$VER: " VSTRING;
47 struct Interface *INewlib = 0;
50 struct ExpatBase * libInit(struct ExpatBase *libBase, BPTR seglist, struct ExecIFace *ISys);
51 uint32 libObtain (struct LibraryManagerInterface *Self);
52 uint32 libRelease (struct LibraryManagerInterface *Self);
53 struct ExpatBase *libOpen (struct LibraryManagerInterface *Self, uint32 version);
54 BPTR libClose (struct LibraryManagerInterface *Self);
55 BPTR libExpunge (struct LibraryManagerInterface *Self);
56 struct Interface *openInterface(struct ExecIFace *IExec, CONST_STRPTR libName, uint32 libVer);
57 void closeInterface(struct ExecIFace *IExec, struct Interface *iface);
60 static APTR lib_manager_vectors[] = {
61 libObtain,
62 libRelease,
63 NULL,
64 NULL,
65 libOpen,
66 libClose,
67 libExpunge,
68 NULL,
69 (APTR)-1,
73 static struct TagItem lib_managerTags[] = {
74 { MIT_Name, (uint32)"__library" },
75 { MIT_VectorTable, (uint32)lib_manager_vectors },
76 { MIT_Version, 1 },
77 { TAG_END, 0 }
81 extern void *main_vectors[];
83 static struct TagItem lib_mainTags[] = {
84 { MIT_Name, (uint32)"main" },
85 { MIT_VectorTable, (uint32)main_vectors },
86 { MIT_Version, 1 },
87 { TAG_END, 0 }
91 static APTR libInterfaces[] = {
92 lib_managerTags,
93 lib_mainTags,
94 NULL
98 extern void *VecTable68K[];
100 static struct TagItem libCreateTags[] = {
101 { CLT_DataSize, sizeof(struct ExpatBase) },
102 { CLT_InitFunc, (uint32)libInit },
103 { CLT_Interfaces, (uint32)libInterfaces },
104 { CLT_Vector68K, (uint32)VecTable68K },
105 { TAG_END, 0 }
109 static struct Resident __attribute__((used)) lib_res = {
110 RTC_MATCHWORD, // rt_MatchWord
111 &lib_res, // rt_MatchTag
112 &lib_res+1, // rt_EndSkip
113 RTF_NATIVE | RTF_AUTOINIT, // rt_Flags
114 VERSION, // rt_Version
115 NT_LIBRARY, // rt_Type
116 LIBPRI, // rt_Pri
117 LIBNAME, // rt_Name
118 VSTRING, // rt_IdString
119 libCreateTags // rt_Init
123 int32 _start()
125 return RETURN_FAIL;
129 struct ExpatBase *libInit(struct ExpatBase *libBase, BPTR seglist, struct ExecIFace *iexec)
131 libBase->libNode.lib_Node.ln_Type = NT_LIBRARY;
132 libBase->libNode.lib_Node.ln_Pri = LIBPRI;
133 libBase->libNode.lib_Node.ln_Name = LIBNAME;
134 libBase->libNode.lib_Flags = LIBF_SUMUSED|LIBF_CHANGED;
135 libBase->libNode.lib_Version = VERSION;
136 libBase->libNode.lib_Revision = REVISION;
137 libBase->libNode.lib_IdString = VSTRING;
139 libBase->SegList = seglist;
141 libBase->IExec = iexec;
142 INewlib = openInterface(iexec, "newlib.library", 0);
144 if ( INewlib != 0 ) {
145 return libBase;
148 closeInterface(iexec, INewlib);
149 INewlib = 0;
151 iexec->DeleteLibrary(&libBase->libNode);
153 return NULL;
157 uint32 libObtain( struct LibraryManagerInterface *Self )
159 ++Self->Data.RefCount;
160 return Self->Data.RefCount;
164 uint32 libRelease( struct LibraryManagerInterface *Self )
166 --Self->Data.RefCount;
167 return Self->Data.RefCount;
171 struct ExpatBase *libOpen( struct LibraryManagerInterface *Self, uint32 version )
173 struct ExpatBase *libBase;
175 libBase = (struct ExpatBase *)Self->Data.LibBase;
177 ++libBase->libNode.lib_OpenCnt;
178 libBase->libNode.lib_Flags &= ~LIBF_DELEXP;
180 return libBase;
184 BPTR libClose( struct LibraryManagerInterface *Self )
186 struct ExpatBase *libBase;
188 libBase = (struct ExpatBase *)Self->Data.LibBase;
190 --libBase->libNode.lib_OpenCnt;
191 if ( libBase->libNode.lib_OpenCnt ) {
192 return 0;
195 if ( libBase->libNode.lib_Flags & LIBF_DELEXP ) {
196 return (BPTR)Self->LibExpunge();
198 else {
199 return ZERO;
204 BPTR libExpunge( struct LibraryManagerInterface *Self )
206 struct ExpatBase *libBase = (struct ExpatBase *)Self->Data.LibBase;
207 BPTR result = ZERO;
209 if (libBase->libNode.lib_OpenCnt == 0) {
210 libBase->IExec->Remove(&libBase->libNode.lib_Node);
212 result = libBase->SegList;
214 closeInterface(libBase->IExec, INewlib);
215 INewlib = 0;
217 libBase->IExec->DeleteLibrary(&libBase->libNode);
219 else {
220 libBase->libNode.lib_Flags |= LIBF_DELEXP;
223 return result;
227 struct Interface *openInterface(struct ExecIFace *IExec, CONST_STRPTR libName, uint32 libVer)
229 struct Library *base = IExec->OpenLibrary(libName, libVer);
230 struct Interface *iface = IExec->GetInterface(base, "main", 1, 0);
231 if (iface == 0) {
232 IExec->CloseLibrary(base);
235 return iface;
239 void closeInterface(struct ExecIFace *IExec, struct Interface *iface)
241 if (iface != 0)
243 struct Library *base = iface->Data.LibBase;
244 IExec->DropInterface(iface);
245 IExec->CloseLibrary(base);