libxml2.pas 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. unit libxml2;
  2. {$mode objfpc}
  3. {$macro on}
  4. {$ALIGN 8}
  5. {$MINENUMSIZE 4}
  6. interface
  7. uses
  8. ctypes;
  9. //{$IF Sizeof(cbool) <> Sizeof(cint)}
  10. // {$ERROR 'cbool size mismatch!'}
  11. //{$ENDIF}
  12. {$IFDEF WINDOWS}
  13. {$DEFINE DYNLINK}
  14. {$ENDIF}
  15. {$IFDEF DYNLINK}
  16. const
  17. {$IF Defined(WINDOWS)}
  18. libxml2lib = 'libxml2.dll';
  19. {$ELSEIF Defined(UNIX)}
  20. libxml2lib = 'libxml2.so';
  21. {$ELSE}
  22. {$MESSAGE ERROR 'DYNLINK not supported'}
  23. {$IFEND}
  24. {$ELSE}
  25. {$LINKLIB xml2}
  26. {$ENDIF}
  27. {$i xmlexports.inc}
  28. {$i xmlversion.inc}
  29. type
  30. iconv_t = pointer;
  31. PFILE = pointer;
  32. va_list = pointer;
  33. size_t = {$IF Sizeof(pointer) = 8}qword{$ELSE}longword{$IFEND};
  34. (*
  35. include pointers (forwarding)
  36. *)
  37. {$DEFINE POINTER}
  38. {$i catalog.inc}
  39. {$i chvalid.inc}
  40. {$i dict.inc}
  41. {$i encoding.inc}
  42. {$i tree.inc}
  43. {$i list.inc}
  44. {$i entities.inc}
  45. {$i xmlerror.inc}
  46. {$i xmlmemory.inc}
  47. {$i hash.inc}
  48. {$i pattern.inc}
  49. {$i schemasInternals.inc}
  50. {$i valid.inc}
  51. {$i parser.inc}
  52. {$i parserInternals.inc}
  53. {$i schematron.inc}
  54. {$i threads.inc}
  55. {$i uri.inc}
  56. {$i relaxng.inc}
  57. {$i globals.inc}
  58. {$i nanoftp.inc}
  59. {$i nanohttp.inc}
  60. {$i SAX.inc}
  61. {$i SAX2.inc}
  62. {$i HTMLtree.inc}
  63. {$i HTMLparser.inc}
  64. {$i xmlautomata.inc}
  65. {$i xmlIO.inc}
  66. {$i xmlmodule.inc}
  67. {$i xmlreader.inc}
  68. {$i xmlregexp.inc}
  69. {$i xmlsave.inc}
  70. {$i xmlschemas.inc}
  71. {$i xmlschemastypes.inc}
  72. {$i xmlstring.inc}
  73. {$i xmlunicode.inc}
  74. {$i xmlwriter.inc}
  75. {$i c14n.inc}
  76. {$i xpath.inc}
  77. {$i xpathInternals.inc}
  78. {$i xlink.inc}
  79. {$i xinclude.inc}
  80. {$i xpointer.inc}
  81. {$UNDEF POINTER}
  82. (*
  83. include types
  84. *)
  85. {$DEFINE TYPE}
  86. {$i catalog.inc}
  87. {$i chvalid.inc}
  88. {$i dict.inc}
  89. {$i encoding.inc}
  90. {$i tree.inc}
  91. {$i list.inc}
  92. {$i entities.inc}
  93. {$i xmlerror.inc}
  94. {$i xmlmemory.inc}
  95. {$i hash.inc}
  96. {$i pattern.inc}
  97. {$i schemasInternals.inc}
  98. {$i valid.inc}
  99. {$i parser.inc}
  100. {$i parserInternals.inc}
  101. {$i schematron.inc}
  102. {$i threads.inc}
  103. {$i uri.inc}
  104. {$i relaxng.inc}
  105. {$i globals.inc}
  106. {$i nanoftp.inc}
  107. {$i nanohttp.inc}
  108. {$i SAX.inc}
  109. {$i SAX2.inc}
  110. {$i HTMLtree.inc}
  111. {$i HTMLparser.inc}
  112. {$i xmlautomata.inc}
  113. {$i xmlIO.inc}
  114. {$i xmlmodule.inc}
  115. {$i xmlreader.inc}
  116. {$i xmlregexp.inc}
  117. {$i xmlsave.inc}
  118. {$i xmlschemas.inc}
  119. {$i xmlschemastypes.inc}
  120. {$i xmlstring.inc}
  121. {$i xmlunicode.inc}
  122. {$i xmlwriter.inc}
  123. {$i c14n.inc}
  124. {$i xpath.inc}
  125. {$i xpathInternals.inc}
  126. {$i xlink.inc}
  127. {$i xinclude.inc}
  128. {$i xpointer.inc}
  129. {$UNDEF TYPE}
  130. (*
  131. include constants
  132. *)
  133. {$DEFINE CONST}
  134. const
  135. {$i catalog.inc}
  136. {$i chvalid.inc}
  137. {$i dict.inc}
  138. {$i encoding.inc}
  139. {$i tree.inc}
  140. {$i list.inc}
  141. {$i entities.inc}
  142. {$i xmlerror.inc}
  143. {$i xmlmemory.inc}
  144. {$i pattern.inc}
  145. {$i schemasInternals.inc}
  146. {$i hash.inc}
  147. {$i valid.inc}
  148. {$i parser.inc}
  149. {$i parserInternals.inc}
  150. {$i schematron.inc}
  151. {$i threads.inc}
  152. {$i uri.inc}
  153. {$i relaxng.inc}
  154. {$i globals.inc}
  155. {$i nanoftp.inc}
  156. {$i nanohttp.inc}
  157. {$i SAX.inc}
  158. {$i SAX2.inc}
  159. {$i HTMLtree.inc}
  160. {$i HTMLparser.inc}
  161. {$i xmlautomata.inc}
  162. {$i xmlIO.inc}
  163. {$i xmlmodule.inc}
  164. {$i xmlreader.inc}
  165. {$i xmlregexp.inc}
  166. {$i xmlsave.inc}
  167. {$i xmlschemas.inc}
  168. {$i xmlschemastypes.inc}
  169. {$i xmlstring.inc}
  170. {$i xmlunicode.inc}
  171. {$i xmlwriter.inc}
  172. {$i c14n.inc}
  173. {$i xpath.inc}
  174. {$i xpathInternals.inc}
  175. {$i xlink.inc}
  176. {$i xinclude.inc}
  177. {$i xpointer.inc}
  178. {$UNDEF CONST}
  179. (*
  180. include functions
  181. *)
  182. {$DEFINE FUNCTION}
  183. {$i catalog.inc}
  184. {$i chvalid.inc}
  185. {$i dict.inc}
  186. {$i encoding.inc}
  187. {$i tree.inc}
  188. {$i list.inc}
  189. {$i entities.inc}
  190. {$i xmlerror.inc}
  191. {$i xmlmemory.inc}
  192. {$i pattern.inc}
  193. {$i schemasInternals.inc}
  194. {$i hash.inc}
  195. {$i valid.inc}
  196. {$i parser.inc}
  197. {$i parserInternals.inc}
  198. {$i schematron.inc}
  199. {$i threads.inc}
  200. {$i uri.inc}
  201. {$i relaxng.inc}
  202. {$i globals.inc}
  203. {$i nanoftp.inc}
  204. {$i nanohttp.inc}
  205. {$i SAX.inc}
  206. {$i SAX2.inc}
  207. {$i HTMLtree.inc}
  208. {$i HTMLparser.inc}
  209. {$i xmlautomata.inc}
  210. {$i xmlIO.inc}
  211. {$i xmlmodule.inc}
  212. {$i xmlreader.inc}
  213. {$i xmlregexp.inc}
  214. {$i xmlsave.inc}
  215. {$i xmlschemas.inc}
  216. {$i xmlschemastypes.inc}
  217. {$i xmlstring.inc}
  218. {$i xmlunicode.inc}
  219. {$i xmlwriter.inc}
  220. {$i c14n.inc}
  221. {$i xpath.inc}
  222. {$i xpathInternals.inc}
  223. {$i xlink.inc}
  224. {$i xinclude.inc}
  225. {$i xpointer.inc}
  226. {$UNDEF FUNCTION}
  227. implementation
  228. procedure fpcxmlFree(mem: pointer); XMLCALL;
  229. begin
  230. FreeMem(mem);
  231. end;
  232. function fpcxmlMalloc(size: size_t): pointer; XMLCALL;
  233. begin
  234. GetMem(Result, size);
  235. end;
  236. function fpcxmlRealloc(mem: pointer; size: size_t): pointer; XMLCALL;
  237. begin
  238. Result := mem;
  239. ReallocMem(Result, size);
  240. end;
  241. procedure fpcxmlGenericErrorHandler(ctx: pointer; msg: pchar; args: array of const); XMLCDECL;
  242. begin
  243. writeln(msg);
  244. end;
  245. procedure fpcxmlStructuredErrorHandler(userData: pointer; error: xmlErrorPtr); XMLCALL;
  246. begin
  247. writeln('struct error');
  248. end;
  249. (*
  250. * macros from xmlversion.inc
  251. *)
  252. procedure LIBXML_TEST_VERSION;
  253. begin
  254. xmlCheckVersion(LIBXML_VERSION);
  255. end;
  256. (*
  257. * macros from xmlversion.inc
  258. *)
  259. function BAD_CAST(str: pchar): xmlCharPtr;
  260. begin
  261. result := xmlCharPtr(str);
  262. end;
  263. function BAD_CAST(str: string): xmlCharPtr;
  264. begin
  265. result := xmlCharPtr(PChar(str));
  266. end;
  267. (*
  268. * macros from chvalid.inc
  269. *)
  270. function xmlIsBaseChar_ch(c: cint): cbool;
  271. begin
  272. Result :=
  273. ((c >= $41) and (c <= $5A)) or
  274. ((c >= $61) and (c <= $7A)) or
  275. ((c >= $C0) and (c <= $D6)) or
  276. ((c >= $D8) and (c <= $F6)) or
  277. (c >= $F8);
  278. end;
  279. function xmlIsBaseCharQ(c: cint): cbool;
  280. begin
  281. if c < $100 then
  282. Result := xmlIsBaseChar_ch(c)
  283. else
  284. Result := xmlCharInRange(c, @xmlIsBaseCharGroup);
  285. end;
  286. function xmlIsBlank_ch(c: cint): cbool;
  287. begin
  288. Result := (c = $20) or ((c >= $9) and (c <= $A)) or (c = $D);
  289. end;
  290. function xmlIsBlankQ(c: cint): cbool;
  291. begin
  292. if c < $100 then
  293. Result := xmlIsBaseChar_ch(c)
  294. else
  295. Result := false;
  296. end;
  297. function xmlIsChar_ch(c: cint): cbool;
  298. begin
  299. Result := ((c >= $9) and (c <= $A)) or (c = $D) or (c >= $20);
  300. end;
  301. function xmlIsCharQ(c: cint): cbool;
  302. begin
  303. if c < $100 then
  304. Result := xmlIsChar_ch(c)
  305. else
  306. Result :=
  307. ((c >= $000100) and (c <= $00D7FF)) or
  308. ((c >= $00E000) and (c <= $00FFFD)) or
  309. ((c >= $010000) and (c <= $10FFFF));
  310. end;
  311. function xmlIsCombiningQ(c: cint): cbool;
  312. begin
  313. if c < $100 then
  314. Result := false
  315. else
  316. Result := xmlCharInRange(c, @xmlIsCombiningGroup);
  317. end;
  318. function xmlIsDigit_ch(c: cint): cbool;
  319. begin
  320. Result := (c >= $30) and (c <= $39);
  321. end;
  322. function xmlIsDigitQ(c: cint): cbool;
  323. begin
  324. if c < $100 then
  325. Result := xmlIsDigit_ch(c)
  326. else
  327. Result := xmlCharInRange(c, @xmlIsDigitGroup);
  328. end;
  329. function xmlIsExtender_ch(c: cint): cbool;
  330. begin
  331. Result := c = $B7;
  332. end;
  333. function xmlIsExtenderQ(c: cint): cbool;
  334. begin
  335. if c < $100 then
  336. Result := xmlIsExtender_ch(c)
  337. else
  338. Result := xmlCharInRange(c, @xmlIsExtenderGroup);
  339. end;
  340. function xmlIsIdeographicQ(c: cint): cbool;
  341. begin
  342. if c < $100 then
  343. Result := false
  344. else
  345. Result :=
  346. ((c >= $4E00) and (c <= $9FA5)) or
  347. (c = $3007) or
  348. ((c >= $3021) and (c <= $3029));
  349. end;
  350. function xmlIsPubidChar_ch(c: cint): cbool;
  351. begin
  352. if (c >= 0) and (c <= 255) then
  353. Result := xmlIsPubidChar_tab[c]
  354. else
  355. Result := false;
  356. end;
  357. function xmlIsPubidCharQ(c: cint): cbool;
  358. begin
  359. if c < $100 then
  360. Result := xmlIsPubidChar_ch(c)
  361. else
  362. Result := false;
  363. end;
  364. (*
  365. * macros from HTMLparser.inc
  366. *)
  367. function htmlDefaultSubelement(elt: htmlElemDescPtr): pchar;
  368. begin
  369. Result := elt^.defaultsubelt;
  370. end;
  371. function htmlElementAllowedHereDesc(parent: htmlElemDescPtr; elt: htmlElemDescPtr): cint;
  372. begin
  373. Result := htmlElementAllowedHere(parent, elt^.name);
  374. end;
  375. function htmlRequiredAttrs(elt: htmlElemDescPtr): ppchar;
  376. begin
  377. Result := elt^.attrs_req;
  378. end;
  379. (*
  380. * macros from tree.inc
  381. *)
  382. function XML_GET_CONTENT(n: pointer): xmlCharPtr;
  383. begin
  384. if xmlNodePtr(n)^._type = XML_ELEMENT_NODE then
  385. Result := nil
  386. else
  387. Result := xmlNodePtr(n)^.content;
  388. end;
  389. (*
  390. * macros from xpath.inc
  391. *)
  392. function xmlXPathNodeSetGetLength(ns: xmlNodeSetPtr): cint;
  393. begin
  394. if assigned(ns) then
  395. Result := ns^.nodeNr
  396. else
  397. Result := 0;
  398. end;
  399. function xmlXPathNodeSetItem(ns: xmlNodeSetPtr; index: cint): xmlNodePtr;
  400. begin
  401. if assigned(ns) and (index >= 0) and (index < ns^.nodeNr) then
  402. Result := ns^.nodeTab[index]
  403. else
  404. Result := nil;
  405. end;
  406. function xmlXPathNodeSetIsEmpty(ns: xmlNodeSetPtr): boolean;
  407. begin
  408. Result := not assigned(ns) or (ns^.nodeNr = 0) or (ns^.nodeTab = nil);
  409. end;
  410. initialization
  411. (*
  412. * this initialize the library and check potential ABI mismatches
  413. * between the version it was compiled for and the actual shared
  414. * library used.
  415. *)
  416. LIBXML_TEST_VERSION;
  417. (*
  418. * overloading the memory functions
  419. *)
  420. xmlMemSetup(@fpcxmlFree, @fpcxmlMalloc, @fpcxmlRealloc, nil);
  421. (*
  422. * overloading the error functions
  423. *)
  424. //xmlSetGenericErrorFunc(nil, @fpcxmlGenericErrorHandler);
  425. //xmlSetStructuredErrorFunc(nil, @fpcxmlStructuredErrorHandler);
  426. finalization
  427. (*
  428. * Cleanup function for the XML library.
  429. *)
  430. //xmlCleanupParser();
  431. (*
  432. * this is to debug memory for regression tests
  433. *)
  434. xmlMemoryDump();
  435. end.