Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * DOCBparser.c : an attempt to parse SGML Docbook documents |
| 3 | * |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 4 | * This is deprecated !!! |
| 5 | * Code removed with release 2.6.0 it was broken. |
Daniel Veillard | 3648fcb | 2003-10-01 12:21:31 +0000 | [diff] [blame] | 6 | * The doc are expect to be migrated to XML DocBook |
Daniel Veillard | e95e239 | 2001-06-06 10:46:28 +0000 | [diff] [blame] | 7 | * |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 8 | * See Copyright for the status of this software. |
| 9 | * |
Daniel Veillard | c5d6434 | 2001-06-24 12:13:24 +0000 | [diff] [blame] | 10 | * daniel@veillard.com |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
Daniel Veillard | 34ce8be | 2002-03-18 19:37:11 +0000 | [diff] [blame] | 13 | #define IN_LIBXML |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 14 | #include "libxml.h" |
| 15 | #ifdef LIBXML_DOCB_ENABLED |
| 16 | |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 17 | #include <libxml/xmlerror.h> |
| 18 | #include <libxml/DOCBparser.h> |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * docbEncodeEntities: |
| 22 | * @out: a pointer to an array of bytes to store the result |
| 23 | * @outlen: the length of @out |
| 24 | * @in: a pointer to an array of UTF-8 chars |
| 25 | * @inlen: the length of @in |
| 26 | * @quoteChar: the quote character to escape (' or ") or zero. |
| 27 | * |
| 28 | * Take a block of UTF-8 chars in and try to convert it to an ASCII |
| 29 | * plus SGML entities block of chars out. |
| 30 | * |
| 31 | * Returns 0 if success, -2 if the transcoding fails, or -1 otherwise |
| 32 | * The value of @inlen after return is the number of octets consumed |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 33 | * as the return value is positive, else unpredictable. |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 34 | * The value of @outlen after return is the number of octets consumed. |
| 35 | */ |
| 36 | int |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 37 | docbEncodeEntities(unsigned char *out ATTRIBUTE_UNUSED, |
| 38 | int *outlen ATTRIBUTE_UNUSED, |
| 39 | const unsigned char *in ATTRIBUTE_UNUSED, |
| 40 | int *inlen ATTRIBUTE_UNUSED, |
| 41 | int quoteChar ATTRIBUTE_UNUSED) |
Daniel Veillard | 84666b3 | 2001-06-11 17:31:08 +0000 | [diff] [blame] | 42 | { |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 43 | static int deprecated = 0; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 44 | |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 45 | if (!deprecated) { |
| 46 | xmlGenericError(xmlGenericErrorContext, |
| 47 | "docbEncodeEntities() deprecated function reached\n"); |
| 48 | deprecated = 1; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 49 | } |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 50 | return(-1); |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 54 | * docbParseDocument: |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 55 | * @ctxt: an SGML parser context |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 56 | * |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 57 | * parse an SGML document (and build a tree if using the standard SAX |
| 58 | * interface). |
| 59 | * |
| 60 | * Returns 0, -1 in case of error. the parser context is augmented |
| 61 | * as a result of the parsing. |
| 62 | */ |
| 63 | |
| 64 | int |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 65 | docbParseDocument(docbParserCtxtPtr ctxt ATTRIBUTE_UNUSED) |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 66 | { |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 67 | static int deprecated = 0; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 68 | |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 69 | if (!deprecated) { |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 70 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 71 | "docbParseDocument() deprecated function reached\n"); |
| 72 | deprecated = 1; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 73 | } |
Daniel Veillard | 3648fcb | 2003-10-01 12:21:31 +0000 | [diff] [blame] | 74 | return (xmlParseDocument(ctxt)); |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| 78 | * docbFreeParserCtxt: |
| 79 | * @ctxt: an SGML parser context |
| 80 | * |
| 81 | * Free all the memory used by a parser context. However the parsed |
| 82 | * document in ctxt->myDoc is not freed. |
| 83 | */ |
| 84 | |
| 85 | void |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 86 | docbFreeParserCtxt(docbParserCtxtPtr ctxt ATTRIBUTE_UNUSED) |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 87 | { |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 88 | static int deprecated = 0; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 89 | |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 90 | if (!deprecated) { |
| 91 | xmlGenericError(xmlGenericErrorContext, |
| 92 | "docbFreeParserCtxt() deprecated function reached\n"); |
| 93 | deprecated = 1; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 94 | } |
Daniel Veillard | 3648fcb | 2003-10-01 12:21:31 +0000 | [diff] [blame] | 95 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
| 99 | * docbParseChunk: |
| 100 | * @ctxt: an XML parser context |
| 101 | * @chunk: an char array |
| 102 | * @size: the size in byte of the chunk |
| 103 | * @terminate: last chunk indicator |
| 104 | * |
| 105 | * Parse a Chunk of memory |
| 106 | * |
| 107 | * Returns zero if no error, the xmlParserErrors otherwise. |
| 108 | */ |
| 109 | int |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 110 | docbParseChunk(docbParserCtxtPtr ctxt ATTRIBUTE_UNUSED, |
| 111 | const char *chunk ATTRIBUTE_UNUSED, |
| 112 | int size ATTRIBUTE_UNUSED, |
| 113 | int terminate ATTRIBUTE_UNUSED) |
| 114 | { |
| 115 | static int deprecated = 0; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 116 | |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 117 | if (!deprecated) { |
| 118 | xmlGenericError(xmlGenericErrorContext, |
| 119 | "docbParseChunk() deprecated function reached\n"); |
| 120 | deprecated = 1; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 121 | } |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 122 | |
Daniel Veillard | 3648fcb | 2003-10-01 12:21:31 +0000 | [diff] [blame] | 123 | return (xmlParseChunk(ctxt, chunk, size, terminate)); |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 126 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 127 | * docbCreatePushParserCtxt: |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 128 | * @sax: a SAX handler |
| 129 | * @user_data: The user data returned on SAX callbacks |
| 130 | * @chunk: a pointer to an array of chars |
| 131 | * @size: number of chars in the array |
| 132 | * @filename: an optional file name or URI |
| 133 | * @enc: an optional encoding |
| 134 | * |
| 135 | * Create a parser context for using the DocBook SGML parser in push mode |
| 136 | * To allow content encoding detection, @size should be >= 4 |
| 137 | * The value of @filename is used for fetching external entities |
| 138 | * and error/warning reports. |
| 139 | * |
| 140 | * Returns the new parser context or NULL |
| 141 | */ |
| 142 | docbParserCtxtPtr |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 143 | docbCreatePushParserCtxt(docbSAXHandlerPtr sax ATTRIBUTE_UNUSED, |
| 144 | void *user_data ATTRIBUTE_UNUSED, |
| 145 | const char *chunk ATTRIBUTE_UNUSED, |
| 146 | int size ATTRIBUTE_UNUSED, |
| 147 | const char *filename ATTRIBUTE_UNUSED, |
| 148 | xmlCharEncoding enc ATTRIBUTE_UNUSED) |
| 149 | { |
| 150 | static int deprecated = 0; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 151 | |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 152 | if (!deprecated) { |
| 153 | xmlGenericError(xmlGenericErrorContext, |
| 154 | "docbParseChunk() deprecated function reached\n"); |
| 155 | deprecated = 1; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Daniel Veillard | 3648fcb | 2003-10-01 12:21:31 +0000 | [diff] [blame] | 158 | return(xmlCreatePushParserCtxt(sax, user_data, chunk, size, filename)); |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 162 | * docbSAXParseDoc: |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 163 | * @cur: a pointer to an array of xmlChar |
| 164 | * @encoding: a free form C string describing the SGML document encoding, or NULL |
| 165 | * @sax: the SAX handler block |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 166 | * @userData: if using SAX, this pointer will be provided on callbacks. |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 167 | * |
| 168 | * parse an SGML in-memory document and build a tree. |
| 169 | * It use the given SAX function block to handle the parsing callback. |
| 170 | * If sax is NULL, fallback to the default DOM tree building routines. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 171 | * |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 172 | * Returns the resulting document tree |
| 173 | */ |
| 174 | |
| 175 | docbDocPtr |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 176 | docbSAXParseDoc(xmlChar * cur ATTRIBUTE_UNUSED, |
| 177 | const char *encoding ATTRIBUTE_UNUSED, |
| 178 | docbSAXHandlerPtr sax ATTRIBUTE_UNUSED, |
| 179 | void *userData ATTRIBUTE_UNUSED) |
| 180 | { |
| 181 | static int deprecated = 0; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 182 | |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 183 | if (!deprecated) { |
| 184 | xmlGenericError(xmlGenericErrorContext, |
| 185 | "docbParseChunk() deprecated function reached\n"); |
| 186 | deprecated = 1; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Daniel Veillard | 3648fcb | 2003-10-01 12:21:31 +0000 | [diff] [blame] | 189 | return (xmlSAXParseMemoryWithData(sax, (const char *)cur, |
| 190 | xmlStrlen((const xmlChar *) cur), 0, userData)); |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 194 | * docbParseDoc: |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 195 | * @cur: a pointer to an array of xmlChar |
| 196 | * @encoding: a free form C string describing the SGML document encoding, or NULL |
| 197 | * |
| 198 | * parse an SGML in-memory document and build a tree. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 199 | * |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 200 | * Returns the resulting document tree |
| 201 | */ |
| 202 | |
| 203 | docbDocPtr |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 204 | docbParseDoc(xmlChar * cur ATTRIBUTE_UNUSED, |
| 205 | const char *encoding ATTRIBUTE_UNUSED) |
| 206 | { |
| 207 | static int deprecated = 0; |
| 208 | |
| 209 | if (!deprecated) { |
| 210 | xmlGenericError(xmlGenericErrorContext, |
| 211 | "docbParseChunk() deprecated function reached\n"); |
| 212 | deprecated = 1; |
| 213 | } |
| 214 | |
Daniel Veillard | 3648fcb | 2003-10-01 12:21:31 +0000 | [diff] [blame] | 215 | return (xmlParseDoc(cur)); |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | |
| 219 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 220 | * docbCreateFileParserCtxt: |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 221 | * @filename: the filename |
Daniel Veillard | 1034da2 | 2001-04-25 19:06:28 +0000 | [diff] [blame] | 222 | * @encoding: the SGML document encoding, or NULL |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 223 | * |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 224 | * Create a parser context for a file content. |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 225 | * Automatic support for ZLIB/Compress compressed document is provided |
| 226 | * by default if found at compile-time. |
| 227 | * |
| 228 | * Returns the new parser context or NULL |
| 229 | */ |
| 230 | docbParserCtxtPtr |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 231 | docbCreateFileParserCtxt(const char *filename ATTRIBUTE_UNUSED, |
| 232 | const char *encoding ATTRIBUTE_UNUSED) |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 233 | { |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 234 | static int deprecated = 0; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 235 | |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 236 | if (!deprecated) { |
| 237 | xmlGenericError(xmlGenericErrorContext, |
| 238 | "docbCreateFileParserCtxt() deprecated function reached\n"); |
| 239 | deprecated = 1; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 240 | } |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 241 | |
Daniel Veillard | 3648fcb | 2003-10-01 12:21:31 +0000 | [diff] [blame] | 242 | return (xmlCreateFileParserCtxt(filename)); |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 246 | * docbSAXParseFile: |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 247 | * @filename: the filename |
| 248 | * @encoding: a free form C string describing the SGML document encoding, or NULL |
| 249 | * @sax: the SAX handler block |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 250 | * @userData: if using SAX, this pointer will be provided on callbacks. |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 251 | * |
| 252 | * parse an SGML file and build a tree. Automatic support for ZLIB/Compress |
| 253 | * compressed document is provided by default if found at compile-time. |
| 254 | * It use the given SAX function block to handle the parsing callback. |
| 255 | * If sax is NULL, fallback to the default DOM tree building routines. |
| 256 | * |
| 257 | * Returns the resulting document tree |
| 258 | */ |
| 259 | |
| 260 | docbDocPtr |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 261 | docbSAXParseFile(const char *filename ATTRIBUTE_UNUSED, |
| 262 | const char *encoding ATTRIBUTE_UNUSED, |
| 263 | docbSAXHandlerPtr sax ATTRIBUTE_UNUSED, |
| 264 | void *userData ATTRIBUTE_UNUSED) |
| 265 | { |
| 266 | static int deprecated = 0; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 267 | |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 268 | if (!deprecated) { |
| 269 | xmlGenericError(xmlGenericErrorContext, |
| 270 | "docbSAXParseFile() deprecated function reached\n"); |
| 271 | deprecated = 1; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Daniel Veillard | 3648fcb | 2003-10-01 12:21:31 +0000 | [diff] [blame] | 274 | return (xmlSAXParseFileWithData(sax, filename, 0, userData)); |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 278 | * docbParseFile: |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 279 | * @filename: the filename |
| 280 | * @encoding: a free form C string describing document encoding, or NULL |
| 281 | * |
| 282 | * parse a Docbook SGML file and build a tree. Automatic support for |
| 283 | * ZLIB/Compress compressed document is provided by default if found |
| 284 | * at compile-time. |
| 285 | * |
| 286 | * Returns the resulting document tree |
| 287 | */ |
| 288 | |
| 289 | docbDocPtr |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 290 | docbParseFile(const char *filename ATTRIBUTE_UNUSED, |
| 291 | const char *encoding ATTRIBUTE_UNUSED) |
| 292 | { |
| 293 | static int deprecated = 0; |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 294 | |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 295 | if (!deprecated) { |
| 296 | xmlGenericError(xmlGenericErrorContext, |
| 297 | "docbParseFile() deprecated function reached\n"); |
| 298 | deprecated = 1; |
| 299 | } |
| 300 | |
Daniel Veillard | 3648fcb | 2003-10-01 12:21:31 +0000 | [diff] [blame] | 301 | return (xmlParseFile(filename)); |
Daniel Veillard | 877a7bd | 2003-09-13 00:16:32 +0000 | [diff] [blame] | 302 | } |
Daniel Veillard | 5d4644e | 2005-04-01 13:11:58 +0000 | [diff] [blame] | 303 | #define bottom_DOCBparser |
| 304 | #include "elfgcchack.h" |
Daniel Veillard | eae522a | 2001-04-23 13:41:34 +0000 | [diff] [blame] | 305 | #endif /* LIBXML_DOCB_ENABLED */ |