1 {
2 Translation of the libxml2 headers for FreePascal
3 Copyright (C) 2008 by Ivo Steinmann
4 }
5
6 unit xml2;
7
8 {$mode objfpc}
9 {$H+}
10 {$macro on}
11
12 {$ALIGN 8}
13 {$MINENUMSIZE 4}
14
15 interface
16
17 uses
18 dynlibs,
19 ctypes;
20
21 const
22 {$IF Defined(WINDOWS)}
23 xml2lib = 'libxml2.'+sharedsuffix;
24 {$DEFINE EXTDECL := cdecl}
25 {$DEFINE NO_EXTERNAL_VARS}
26 {$ELSEIF Defined(UNIX)}
27 xml2lib = 'libxml2.'+sharedsuffix;
28 {$DEFINE EXTDECL := cdecl}
29 {$ELSE}
30 {$MESSAGE ERROR 'Platform not supported right now'}
31 {$IFEND}
32
33 {$i xml2.inc}
34
35 implementation
36
37 {$IFDEF NO_EXTERNAL_VARS}
GetxmlMallocnull38 function GetxmlMalloc: xmlMallocFunc; inline;
39 begin
40 Result := varxmlMalloc^;
41 end;
42
43 procedure SetxmlMalloc(AValue: xmlMallocFunc); inline;
44 begin
45 varxmlMalloc^ := AValue;
46 end;
47
GetxmlMallocAtomicnull48 function GetxmlMallocAtomic: xmlMallocFunc; inline;
49 begin
50 Result := varxmlMallocAtomic^;
51 end;
52
53 procedure SetxmlMallocAtomic(AValue: xmlMallocFunc); inline;
54 begin
55 varxmlMallocAtomic^ := AValue;
56 end;
57
GetxmlReallocnull58 function GetxmlRealloc: xmlReallocFunc; inline;
59 begin
60 Result := varxmlRealloc^;
61 end;
62
63 procedure SetxmlRealloc(AValue: xmlReallocFunc); inline;
64 begin
65 varxmlRealloc^ := AValue;
66 end;
67
GetxmlFreenull68 function GetxmlFree: xmlFreeFunc; inline;
69 begin
70 Result := varxmlFree^;
71 end;
72
73 procedure SetxmlFree(AValue: xmlFreeFunc); inline;
74 begin
75 varxmlFree^ := AValue;
76 end;
77
GetxmlMemStrdupnull78 function GetxmlMemStrdup: xmlStrdupFunc; inline;
79 begin
80 Result := varxmlMemStrdup^;
81 end;
82
83 procedure SetxmlMemStrdup(AValue: xmlStrdupFunc); inline;
84 begin
85 varxmlMemStrdup^ := AValue;
86 end;
87 {$ENDIF}
88
89 procedure fpcxmlFree(mem: pointer); EXTDECL;
90 begin
91 FreeMem(mem);
92 end;
93
fpcxmlMallocnull94 function fpcxmlMalloc(size: csize_t): pointer; EXTDECL;
95 begin
96 GetMem(Result, size);
97 end;
98
fpcxmlReallocnull99 function fpcxmlRealloc(mem: pointer; size: csize_t): pointer; EXTDECL;
100 begin
101 Result := mem;
102 ReallocMem(Result, size);
103 end;
104
fpcxmlStrdupnull105 function fpcxmlStrdup(str: pchar): pchar; EXTDECL;
106 var
107 L: SizeInt;
108 begin
109 L := Length(str) + 1;
110 Getmem(Result, L);
111 if Result <> nil then
112 Move(str^, Result^, L);
113 end;
114
115 procedure fpcxmlStructuredErrorHandler(userData: pointer; error: xmlErrorPtr); EXTDECL;
116 begin
117 writeln('struct error');
118 end;
119
120
121 (*
122 * macros from xmlversion.inc
123 *)
124
125 procedure LIBXML_TEST_VERSION;
126 begin
127 xmlCheckVersion(LIBXML_VERSION);
128 end;
129
130
131 (*
132 * macros from xmlversion.inc
133 *)
134
135
136 (*
137 * macros from chvalid.inc
138 *)
139
xmlIsBaseChar_chnull140 function xmlIsBaseChar_ch(c: cint): cbool;
141 begin
142 Result :=
143 ((c >= $41) and (c <= $5A)) or
144 ((c >= $61) and (c <= $7A)) or
145 ((c >= $C0) and (c <= $D6)) or
146 ((c >= $D8) and (c <= $F6)) or
147 (c >= $F8);
148 end;
149
xmlIsBaseCharQnull150 function xmlIsBaseCharQ(c: cint): cbool;
151 begin
152 if c < $100 then
153 Result := xmlIsBaseChar_ch(c)
154 else
155 Result := xmlCharInRange(c, __xmlIsBaseCharGroup);
156 end;
157
xmlIsBlank_chnull158 function xmlIsBlank_ch(c: cint): cbool;
159 begin
160 Result := (c = $20) or ((c >= $9) and (c <= $A)) or (c = $D);
161 end;
162
xmlIsBlankQnull163 function xmlIsBlankQ(c: cint): cbool;
164 begin
165 if c < $100 then
166 Result := xmlIsBaseChar_ch(c)
167 else
168 Result := false;
169 end;
170
xmlIsChar_chnull171 function xmlIsChar_ch(c: cint): cbool;
172 begin
173 Result := ((c >= $9) and (c <= $A)) or (c = $D) or (c >= $20);
174 end;
175
xmlIsCharQnull176 function xmlIsCharQ(c: cint): cbool;
177 begin
178 if c < $100 then
179 Result := xmlIsChar_ch(c)
180 else
181 Result :=
182 ((c >= $000100) and (c <= $00D7FF)) or
183 ((c >= $00E000) and (c <= $00FFFD)) or
184 ((c >= $010000) and (c <= $10FFFF));
185 end;
186
xmlIsCombiningQnull187 function xmlIsCombiningQ(c: cint): cbool;
188 begin
189 if c < $100 then
190 Result := false
191 else
192 Result := xmlCharInRange(c, __xmlIsCombiningGroup);
193 end;
194
xmlIsDigit_chnull195 function xmlIsDigit_ch(c: cint): cbool;
196 begin
197 Result := (c >= $30) and (c <= $39);
198 end;
199
xmlIsDigitQnull200 function xmlIsDigitQ(c: cint): cbool;
201 begin
202 if c < $100 then
203 Result := xmlIsDigit_ch(c)
204 else
205 Result := xmlCharInRange(c, __xmlIsDigitGroup);
206 end;
207
xmlIsExtender_chnull208 function xmlIsExtender_ch(c: cint): cbool;
209 begin
210 Result := c = $B7;
211 end;
212
xmlIsExtenderQnull213 function xmlIsExtenderQ(c: cint): cbool;
214 begin
215 if c < $100 then
216 Result := xmlIsExtender_ch(c)
217 else
218 Result := xmlCharInRange(c, __xmlIsExtenderGroup);
219 end;
220
xmlIsIdeographicQnull221 function xmlIsIdeographicQ(c: cint): cbool;
222 begin
223 if c < $100 then
224 Result := false
225 else
226 Result :=
227 ((c >= $4E00) and (c <= $9FA5)) or
228 (c = $3007) or
229 ((c >= $3021) and (c <= $3029));
230 end;
231
xmlIsPubidChar_chnull232 function xmlIsPubidChar_ch(c: cint): cbool;
233 begin
234 if (c >= 0) and (c <= 255) then
235 Result := __xmlIsPubidChar_tab^[c]
236 else
237 Result := false;
238 end;
239
xmlIsPubidCharQnull240 function xmlIsPubidCharQ(c: cint): cbool;
241 begin
242 if c < $100 then
243 Result := xmlIsPubidChar_ch(c)
244 else
245 Result := false;
246 end;
247
248
249 (*
250 * macros from HTMLparser.inc
251 *)
252
htmlDefaultSubelementnull253 function htmlDefaultSubelement(elt: htmlElemDescPtr): pchar;
254 begin
255 Result := elt^.defaultsubelt;
256 end;
257
htmlElementAllowedHereDescnull258 function htmlElementAllowedHereDesc(parent: htmlElemDescPtr; elt: htmlElemDescPtr): cint;
259 begin
260 Result := htmlElementAllowedHere(parent, xmlCharPtr(elt^.name));
261 end;
262
htmlRequiredAttrsnull263 function htmlRequiredAttrs(elt: htmlElemDescPtr): ppchar;
264 begin
265 Result := elt^.attrs_req;
266 end;
267
268
269 (*
270 * macros from tree.inc
271 *)
272
XML_GET_CONTENTnull273 function XML_GET_CONTENT(n: pointer): xmlCharPtr;
274 begin
275 if xmlNodePtr(n)^._type = XML_ELEMENT_NODE then
276 Result := nil
277 else
278 Result := xmlNodePtr(n)^.content;
279 end;
280
281
282 (*
283 * macros from xpath.inc
284 *)
285
xmlXPathNodeSetGetLengthnull286 function xmlXPathNodeSetGetLength(ns: xmlNodeSetPtr): cint;
287 begin
288 if assigned(ns) then
289 Result := ns^.nodeNr
290 else
291 Result := 0;
292 end;
293
xmlXPathNodeSetItemnull294 function xmlXPathNodeSetItem(ns: xmlNodeSetPtr; index: cint): xmlNodePtr;
295 begin
296 if assigned(ns) and (index >= 0) and (index < ns^.nodeNr) then
297 Result := ns^.nodeTab[index]
298 else
299 Result := nil;
300 end;
301
xmlXPathNodeSetIsEmptynull302 function xmlXPathNodeSetIsEmpty(ns: xmlNodeSetPtr): boolean;
303 begin
304 Result := not assigned(ns) or (ns^.nodeNr = 0) or (ns^.nodeTab = nil);
305 end;
306
307 {$IFDEF NO_EXTERNAL_VARS}
308 procedure LoadExternalVariables;
309 var
310 libHandle: THandle;
311 begin
312 libHandle := LoadLibrary(xml2lib);
313 if libHandle <> 0 then
314 begin
315 { xmlregexp.inc }
316 {__emptyExp := xmlExpNodePtrPtr(GetProcAddress(libHandle, 'emptyExp'));
317 __forbiddenExp := xmlExpNodePtrPtr(GetProcAddress(libHandle, 'forbiddenExp'));}
318
319 { paserInternals.inc }
320 //__xmlParserMaxDepth := PCardinal(GetProcAddress(libHandle, 'xmlParserMaxDepth'));
321
322 { }
323 {xmlStringComment := PChar(GetProcAddress(libHandle, 'xmlStringComment'));
324 xmlStringText := PChar(GetProcAddress(libHandle, 'xmlStringText'));
325 xmlStringTextNoenc := PChar(GetProcAddress(libHandle, 'xmlStringTextNoenc'));}
326
327 { chvalid.inc }
328 __xmlIsBaseCharGroup := xmlChRangeGroupPtr(GetProcAddress(libHandle, 'xmlIsBaseCharGroup'));
329 __xmlIsCharGroup := xmlChRangeGroupPtr(GetProcAddress(libHandle, 'xmlIsCharGroup'));
330 __xmlIsCombiningGroup := xmlChRangeGroupPtr(GetProcAddress(libHandle, 'xmlIsCombiningGroup'));
331 __xmlIsDigitGroup := xmlChRangeGroupPtr(GetProcAddress(libHandle, 'xmlIsDigitGroup'));
332 __xmlIsExtenderGroup := xmlChRangeGroupPtr(GetProcAddress(libHandle, 'xmlIsExtenderGroup'));
333 __xmlIsIdeographicGroup := xmlChRangeGroupPtr(GetProcAddress(libHandle, 'xmlIsIdeographicGroup'));
334 __xmlIsPubidChar_tab := GetProcAddress(libHandle, 'xmlIsPubidChar_tab');
335
336 { globals.inc }
337 varxmlMalloc := PxmlMallocFunc(GetProcAddress(libHandle, 'xmlMalloc'));
338 varxmlMallocAtomic := PxmlMallocFunc(GetProcAddress(libHandle, 'xmlMallocAtomic'));
339 varxmlRealloc := PxmlReallocFunc(GetProcAddress(libHandle, 'xmlRealloc'));
340 varxmlFree := PxmlFreeFunc(GetProcAddress(libHandle, 'xmlFree'));
341 varxmlMemStrdup := PxmlStrdupFunc(GetProcAddress(libHandle, 'xmlMemStrdup'));
342
343 { xpath.inc }
344 {__xmlXPathNAN := PDouble(GetProcAddress(libHandle, 'xmlXPathNAN'));
345 __xmlXPathNINF := PDouble(GetProcAddress(libHandle, 'xmlXPathNINF'));
346 __xmlXPathPINF := PDouble(GetProcAddress(libHandle, 'xmlXPathPINF'));}
347
348 FreeLibrary(libHandle);
349 end;
350 end;
351 {$ENDIF}
352
353 initialization
354 {$IFDEF NO_EXTERNAL_VARS}
355 LoadExternalVariables;
356 {$ENDIF}
357
358 (*
359 * overloading the memory functions
360 *)
361 xmlMemSetup(@fpcxmlFree, @fpcxmlMalloc, @fpcxmlRealloc, @fpcxmlStrdup);
362
363 (*
364 * this initialize the library and check potential ABI mismatches
365 * between the version it was compiled for and the actual shared
366 * library used.
367 *)
368 LIBXML_TEST_VERSION;
369
370 (*
371 * overloading the error functions
372 *)
373 //xmlSetGenericErrorFunc(nil, @fpcxmlGenericErrorHandler);
374 //xmlSetStructuredErrorFunc(nil, @fpcxmlStructuredErrorHandler);
375
376 finalization
377 (*
378 * Cleanup function for the XML library.
379 *)
380 xmlCleanupParser();
381
382 (*
383 * this is to debug memory for regression tests
384 *)
385 //xmlMemoryDump();
386
387 end.
388