| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | * testHTML.c : a small tester program for HTML input. | 
|  | 3 | * | 
|  | 4 | * See Copyright for the status of this software. | 
|  | 5 | * | 
| Daniel Veillard | c5d6434 | 2001-06-24 12:13:24 +0000 | [diff] [blame] | 6 | * daniel@veillard.com | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 7 | */ | 
|  | 8 |  | 
| Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 9 | #include "libxml.h" | 
| Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 10 |  | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 11 | #ifdef LIBXML_HTML_ENABLED | 
|  | 12 |  | 
| Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 13 | #include <string.h> | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 14 | #include <stdarg.h> | 
|  | 15 |  | 
| Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 16 |  | 
|  | 17 | #ifdef HAVE_SYS_TYPES_H | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 18 | #include <sys/types.h> | 
| Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 19 | #endif | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 20 | #ifdef HAVE_SYS_STAT_H | 
|  | 21 | #include <sys/stat.h> | 
|  | 22 | #endif | 
|  | 23 | #ifdef HAVE_FCNTL_H | 
|  | 24 | #include <fcntl.h> | 
|  | 25 | #endif | 
|  | 26 | #ifdef HAVE_UNISTD_H | 
|  | 27 | #include <unistd.h> | 
|  | 28 | #endif | 
| Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 29 | #ifdef HAVE_STDLIB_H | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 30 | #include <stdlib.h> | 
| Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 31 | #endif | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 32 |  | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 33 | #include <libxml/xmlmemory.h> | 
|  | 34 | #include <libxml/HTMLparser.h> | 
|  | 35 | #include <libxml/HTMLtree.h> | 
|  | 36 | #include <libxml/debugXML.h> | 
| Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 37 | #include <libxml/xmlerror.h> | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 38 |  | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 39 | #ifdef LIBXML_DEBUG_ENABLED | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 40 | static int debug = 0; | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 41 | #endif | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 42 | static int copy = 0; | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 43 | static int sax = 0; | 
|  | 44 | static int repeat = 0; | 
|  | 45 | static int noout = 0; | 
| Daniel Veillard | 5e5c623 | 1999-12-29 12:49:06 +0000 | [diff] [blame] | 46 | static int push = 0; | 
| Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 47 | static char *encoding = NULL; | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 48 |  | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 49 | xmlSAXHandler emptySAXHandlerStruct = { | 
|  | 50 | NULL, /* internalSubset */ | 
|  | 51 | NULL, /* isStandalone */ | 
|  | 52 | NULL, /* hasInternalSubset */ | 
|  | 53 | NULL, /* hasExternalSubset */ | 
|  | 54 | NULL, /* resolveEntity */ | 
|  | 55 | NULL, /* getEntity */ | 
|  | 56 | NULL, /* entityDecl */ | 
|  | 57 | NULL, /* notationDecl */ | 
|  | 58 | NULL, /* attributeDecl */ | 
|  | 59 | NULL, /* elementDecl */ | 
|  | 60 | NULL, /* unparsedEntityDecl */ | 
|  | 61 | NULL, /* setDocumentLocator */ | 
|  | 62 | NULL, /* startDocument */ | 
|  | 63 | NULL, /* endDocument */ | 
|  | 64 | NULL, /* startElement */ | 
|  | 65 | NULL, /* endElement */ | 
|  | 66 | NULL, /* reference */ | 
|  | 67 | NULL, /* characters */ | 
|  | 68 | NULL, /* ignorableWhitespace */ | 
|  | 69 | NULL, /* processingInstruction */ | 
|  | 70 | NULL, /* comment */ | 
|  | 71 | NULL, /* xmlParserWarning */ | 
|  | 72 | NULL, /* xmlParserError */ | 
|  | 73 | NULL, /* xmlParserError */ | 
|  | 74 | NULL, /* getParameterEntity */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 75 | NULL, /* cdataBlock */ | 
| Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 76 | NULL, /* externalSubset */ | 
|  | 77 | 1 | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 78 | }; | 
|  | 79 |  | 
|  | 80 | xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct; | 
|  | 81 | extern xmlSAXHandlerPtr debugSAXHandler; | 
|  | 82 |  | 
|  | 83 | /************************************************************************ | 
|  | 84 | *									* | 
|  | 85 | *				Debug Handlers				* | 
|  | 86 | *									* | 
|  | 87 | ************************************************************************/ | 
|  | 88 |  | 
|  | 89 | /** | 
|  | 90 | * isStandaloneDebug: | 
|  | 91 | * @ctxt:  An XML parser context | 
|  | 92 | * | 
|  | 93 | * Is this document tagged standalone ? | 
|  | 94 | * | 
|  | 95 | * Returns 1 if true | 
|  | 96 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 97 | static int | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 98 | isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 99 | { | 
|  | 100 | fprintf(stdout, "SAX.isStandalone()\n"); | 
|  | 101 | return(0); | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | /** | 
|  | 105 | * hasInternalSubsetDebug: | 
|  | 106 | * @ctxt:  An XML parser context | 
|  | 107 | * | 
|  | 108 | * Does this document has an internal subset | 
|  | 109 | * | 
|  | 110 | * Returns 1 if true | 
|  | 111 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 112 | static int | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 113 | hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 114 | { | 
|  | 115 | fprintf(stdout, "SAX.hasInternalSubset()\n"); | 
|  | 116 | return(0); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | /** | 
|  | 120 | * hasExternalSubsetDebug: | 
|  | 121 | * @ctxt:  An XML parser context | 
|  | 122 | * | 
|  | 123 | * Does this document has an external subset | 
|  | 124 | * | 
|  | 125 | * Returns 1 if true | 
|  | 126 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 127 | static int | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 128 | hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 129 | { | 
|  | 130 | fprintf(stdout, "SAX.hasExternalSubset()\n"); | 
|  | 131 | return(0); | 
|  | 132 | } | 
|  | 133 |  | 
|  | 134 | /** | 
|  | 135 | * hasInternalSubsetDebug: | 
|  | 136 | * @ctxt:  An XML parser context | 
|  | 137 | * | 
|  | 138 | * Does this document has an internal subset | 
|  | 139 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 140 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 141 | internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 142 | const xmlChar *ExternalID, const xmlChar *SystemID) | 
|  | 143 | { | 
| Daniel Veillard | 808a3f1 | 2000-08-17 13:50:51 +0000 | [diff] [blame] | 144 | fprintf(stdout, "SAX.internalSubset(%s,", name); | 
|  | 145 | if (ExternalID == NULL) | 
|  | 146 | fprintf(stdout, " ,"); | 
|  | 147 | else | 
|  | 148 | fprintf(stdout, " %s,", ExternalID); | 
|  | 149 | if (SystemID == NULL) | 
|  | 150 | fprintf(stdout, " )\n"); | 
|  | 151 | else | 
|  | 152 | fprintf(stdout, " %s)\n", SystemID); | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 153 | } | 
|  | 154 |  | 
|  | 155 | /** | 
|  | 156 | * resolveEntityDebug: | 
|  | 157 | * @ctxt:  An XML parser context | 
|  | 158 | * @publicId: The public ID of the entity | 
|  | 159 | * @systemId: The system ID of the entity | 
|  | 160 | * | 
|  | 161 | * Special entity resolver, better left to the parser, it has | 
|  | 162 | * more context than the application layer. | 
|  | 163 | * The default behaviour is to NOT resolve the entities, in that case | 
|  | 164 | * the ENTITY_REF nodes are built in the structure (and the parameter | 
|  | 165 | * values). | 
|  | 166 | * | 
|  | 167 | * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. | 
|  | 168 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 169 | static xmlParserInputPtr | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 170 | resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 171 | { | 
|  | 172 | /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ | 
|  | 173 |  | 
|  | 174 |  | 
|  | 175 | fprintf(stdout, "SAX.resolveEntity("); | 
|  | 176 | if (publicId != NULL) | 
|  | 177 | fprintf(stdout, "%s", (char *)publicId); | 
|  | 178 | else | 
|  | 179 | fprintf(stdout, " "); | 
|  | 180 | if (systemId != NULL) | 
|  | 181 | fprintf(stdout, ", %s)\n", (char *)systemId); | 
|  | 182 | else | 
|  | 183 | fprintf(stdout, ", )\n"); | 
|  | 184 | /********* | 
|  | 185 | if (systemId != NULL) { | 
|  | 186 | return(xmlNewInputFromFile(ctxt, (char *) systemId)); | 
|  | 187 | } | 
|  | 188 | *********/ | 
|  | 189 | return(NULL); | 
|  | 190 | } | 
|  | 191 |  | 
|  | 192 | /** | 
|  | 193 | * getEntityDebug: | 
|  | 194 | * @ctxt:  An XML parser context | 
|  | 195 | * @name: The entity name | 
|  | 196 | * | 
|  | 197 | * Get an entity by name | 
|  | 198 | * | 
|  | 199 | * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. | 
|  | 200 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 201 | static xmlEntityPtr | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 202 | getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 203 | { | 
|  | 204 | fprintf(stdout, "SAX.getEntity(%s)\n", name); | 
|  | 205 | return(NULL); | 
|  | 206 | } | 
|  | 207 |  | 
|  | 208 | /** | 
|  | 209 | * getParameterEntityDebug: | 
|  | 210 | * @ctxt:  An XML parser context | 
|  | 211 | * @name: The entity name | 
|  | 212 | * | 
|  | 213 | * Get a parameter entity by name | 
|  | 214 | * | 
|  | 215 | * Returns the xmlParserInputPtr | 
|  | 216 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 217 | static xmlEntityPtr | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 218 | getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 219 | { | 
|  | 220 | fprintf(stdout, "SAX.getParameterEntity(%s)\n", name); | 
|  | 221 | return(NULL); | 
|  | 222 | } | 
|  | 223 |  | 
|  | 224 |  | 
|  | 225 | /** | 
|  | 226 | * entityDeclDebug: | 
|  | 227 | * @ctxt:  An XML parser context | 
|  | 228 | * @name:  the entity name | 
|  | 229 | * @type:  the entity type | 
|  | 230 | * @publicId: The public ID of the entity | 
|  | 231 | * @systemId: The system ID of the entity | 
|  | 232 | * @content: the entity value (without processing). | 
|  | 233 | * | 
|  | 234 | * An entity definition has been parsed | 
|  | 235 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 236 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 237 | entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 238 | const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) | 
|  | 239 | { | 
|  | 240 | fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", | 
|  | 241 | name, type, publicId, systemId, content); | 
|  | 242 | } | 
|  | 243 |  | 
|  | 244 | /** | 
|  | 245 | * attributeDeclDebug: | 
|  | 246 | * @ctxt:  An XML parser context | 
|  | 247 | * @name:  the attribute name | 
|  | 248 | * @type:  the attribute type | 
|  | 249 | * | 
|  | 250 | * An attribute definition has been parsed | 
|  | 251 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 252 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 253 | attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *elem, const xmlChar *name, | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 254 | int type, int def, const xmlChar *defaultValue, | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 255 | xmlEnumerationPtr tree ATTRIBUTE_UNUSED) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 256 | { | 
|  | 257 | fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", | 
|  | 258 | elem, name, type, def, defaultValue); | 
|  | 259 | } | 
|  | 260 |  | 
|  | 261 | /** | 
|  | 262 | * elementDeclDebug: | 
|  | 263 | * @ctxt:  An XML parser context | 
|  | 264 | * @name:  the element name | 
|  | 265 | * @type:  the element type | 
|  | 266 | * @content: the element value (without processing). | 
|  | 267 | * | 
|  | 268 | * An element definition has been parsed | 
|  | 269 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 270 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 271 | elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, | 
|  | 272 | xmlElementContentPtr content ATTRIBUTE_UNUSED) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 273 | { | 
|  | 274 | fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n", | 
|  | 275 | name, type); | 
|  | 276 | } | 
|  | 277 |  | 
|  | 278 | /** | 
|  | 279 | * notationDeclDebug: | 
|  | 280 | * @ctxt:  An XML parser context | 
|  | 281 | * @name: The name of the notation | 
|  | 282 | * @publicId: The public ID of the entity | 
|  | 283 | * @systemId: The system ID of the entity | 
|  | 284 | * | 
|  | 285 | * What to do when a notation declaration has been parsed. | 
|  | 286 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 287 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 288 | notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 289 | const xmlChar *publicId, const xmlChar *systemId) | 
|  | 290 | { | 
|  | 291 | fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n", | 
|  | 292 | (char *) name, (char *) publicId, (char *) systemId); | 
|  | 293 | } | 
|  | 294 |  | 
|  | 295 | /** | 
|  | 296 | * unparsedEntityDeclDebug: | 
|  | 297 | * @ctxt:  An XML parser context | 
|  | 298 | * @name: The name of the entity | 
|  | 299 | * @publicId: The public ID of the entity | 
|  | 300 | * @systemId: The system ID of the entity | 
|  | 301 | * @notationName: the name of the notation | 
|  | 302 | * | 
|  | 303 | * What to do when an unparsed entity declaration is parsed | 
|  | 304 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 305 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 306 | unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 307 | const xmlChar *publicId, const xmlChar *systemId, | 
|  | 308 | const xmlChar *notationName) | 
|  | 309 | { | 
|  | 310 | fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n", | 
|  | 311 | (char *) name, (char *) publicId, (char *) systemId, | 
|  | 312 | (char *) notationName); | 
|  | 313 | } | 
|  | 314 |  | 
|  | 315 | /** | 
|  | 316 | * setDocumentLocatorDebug: | 
|  | 317 | * @ctxt:  An XML parser context | 
|  | 318 | * @loc: A SAX Locator | 
|  | 319 | * | 
|  | 320 | * Receive the document locator at startup, actually xmlDefaultSAXLocator | 
|  | 321 | * Everything is available on the context, so this is useless in our case. | 
|  | 322 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 323 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 324 | setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 325 | { | 
|  | 326 | fprintf(stdout, "SAX.setDocumentLocator()\n"); | 
|  | 327 | } | 
|  | 328 |  | 
|  | 329 | /** | 
|  | 330 | * startDocumentDebug: | 
|  | 331 | * @ctxt:  An XML parser context | 
|  | 332 | * | 
|  | 333 | * called when the document start being processed. | 
|  | 334 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 335 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 336 | startDocumentDebug(void *ctx ATTRIBUTE_UNUSED) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 337 | { | 
|  | 338 | fprintf(stdout, "SAX.startDocument()\n"); | 
|  | 339 | } | 
|  | 340 |  | 
|  | 341 | /** | 
|  | 342 | * endDocumentDebug: | 
|  | 343 | * @ctxt:  An XML parser context | 
|  | 344 | * | 
|  | 345 | * called when the document end has been detected. | 
|  | 346 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 347 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 348 | endDocumentDebug(void *ctx ATTRIBUTE_UNUSED) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 349 | { | 
|  | 350 | fprintf(stdout, "SAX.endDocument()\n"); | 
|  | 351 | } | 
|  | 352 |  | 
|  | 353 | /** | 
|  | 354 | * startElementDebug: | 
|  | 355 | * @ctxt:  An XML parser context | 
|  | 356 | * @name:  The element name | 
|  | 357 | * | 
|  | 358 | * called when an opening tag has been processed. | 
|  | 359 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 360 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 361 | startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 362 | { | 
|  | 363 | int i; | 
|  | 364 |  | 
|  | 365 | fprintf(stdout, "SAX.startElement(%s", (char *) name); | 
|  | 366 | if (atts != NULL) { | 
|  | 367 | for (i = 0;(atts[i] != NULL);i++) { | 
| Daniel Veillard | 808a3f1 | 2000-08-17 13:50:51 +0000 | [diff] [blame] | 368 | fprintf(stdout, ", %s", atts[i++]); | 
| Daniel Veillard | e010c17 | 2000-08-28 10:04:51 +0000 | [diff] [blame] | 369 | if (atts[i] != NULL) { | 
|  | 370 | unsigned char output[40]; | 
|  | 371 | const unsigned char *att = atts[i]; | 
|  | 372 | int outlen, attlen; | 
|  | 373 | fprintf(stdout, "='"); | 
|  | 374 | while ((attlen = strlen((char*)att)) > 0) { | 
|  | 375 | outlen = sizeof output - 1; | 
|  | 376 | htmlEncodeEntities(output, &outlen, att, &attlen, '\''); | 
|  | 377 | fprintf(stdout, "%.*s", outlen, output); | 
|  | 378 | att += attlen; | 
|  | 379 | } | 
|  | 380 | fprintf(stdout, "'"); | 
|  | 381 | } | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 382 | } | 
|  | 383 | } | 
|  | 384 | fprintf(stdout, ")\n"); | 
|  | 385 | } | 
|  | 386 |  | 
|  | 387 | /** | 
|  | 388 | * endElementDebug: | 
|  | 389 | * @ctxt:  An XML parser context | 
|  | 390 | * @name:  The element name | 
|  | 391 | * | 
|  | 392 | * called when the end of an element has been detected. | 
|  | 393 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 394 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 395 | endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 396 | { | 
|  | 397 | fprintf(stdout, "SAX.endElement(%s)\n", (char *) name); | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | /** | 
|  | 401 | * charactersDebug: | 
|  | 402 | * @ctxt:  An XML parser context | 
|  | 403 | * @ch:  a xmlChar string | 
|  | 404 | * @len: the number of xmlChar | 
|  | 405 | * | 
|  | 406 | * receiving some chars from the parser. | 
|  | 407 | * Question: how much at a time ??? | 
|  | 408 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 409 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 410 | charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 411 | { | 
| Daniel Veillard | e010c17 | 2000-08-28 10:04:51 +0000 | [diff] [blame] | 412 | unsigned char output[40]; | 
| Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 413 | int inlen = len, outlen = 30; | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 414 |  | 
| Daniel Veillard | 4948eb4 | 2000-08-29 09:41:15 +0000 | [diff] [blame] | 415 | htmlEncodeEntities(output, &outlen, ch, &inlen, 0); | 
| Daniel Veillard | e010c17 | 2000-08-28 10:04:51 +0000 | [diff] [blame] | 416 | output[outlen] = 0; | 
| Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 417 |  | 
|  | 418 | fprintf(stdout, "SAX.characters(%s, %d)\n", output, len); | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 419 | } | 
|  | 420 |  | 
|  | 421 | /** | 
| Daniel Veillard | 7eda845 | 2000-10-14 23:38:43 +0000 | [diff] [blame] | 422 | * cdataDebug: | 
|  | 423 | * @ctxt:  An XML parser context | 
|  | 424 | * @ch:  a xmlChar string | 
|  | 425 | * @len: the number of xmlChar | 
|  | 426 | * | 
|  | 427 | * receiving some cdata chars from the parser. | 
|  | 428 | * Question: how much at a time ??? | 
|  | 429 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 430 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 431 | cdataDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) | 
| Daniel Veillard | 7eda845 | 2000-10-14 23:38:43 +0000 | [diff] [blame] | 432 | { | 
|  | 433 | unsigned char output[40]; | 
|  | 434 | int inlen = len, outlen = 30; | 
|  | 435 |  | 
|  | 436 | htmlEncodeEntities(output, &outlen, ch, &inlen, 0); | 
|  | 437 | output[outlen] = 0; | 
|  | 438 |  | 
|  | 439 | fprintf(stdout, "SAX.cdata(%s, %d)\n", output, len); | 
|  | 440 | } | 
|  | 441 |  | 
|  | 442 | /** | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 443 | * referenceDebug: | 
|  | 444 | * @ctxt:  An XML parser context | 
|  | 445 | * @name:  The entity name | 
|  | 446 | * | 
|  | 447 | * called when an entity reference is detected. | 
|  | 448 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 449 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 450 | referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 451 | { | 
|  | 452 | fprintf(stdout, "SAX.reference(%s)\n", name); | 
|  | 453 | } | 
|  | 454 |  | 
|  | 455 | /** | 
|  | 456 | * ignorableWhitespaceDebug: | 
|  | 457 | * @ctxt:  An XML parser context | 
|  | 458 | * @ch:  a xmlChar string | 
|  | 459 | * @start: the first char in the string | 
|  | 460 | * @len: the number of xmlChar | 
|  | 461 | * | 
|  | 462 | * receiving some ignorable whitespaces from the parser. | 
|  | 463 | * Question: how much at a time ??? | 
|  | 464 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 465 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 466 | ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 467 | { | 
| Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 468 | char output[40]; | 
|  | 469 | int i; | 
|  | 470 |  | 
|  | 471 | for (i = 0;(i<len) && (i < 30);i++) | 
|  | 472 | output[i] = ch[i]; | 
|  | 473 | output[i] = 0; | 
|  | 474 |  | 
|  | 475 | fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len); | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 476 | } | 
|  | 477 |  | 
|  | 478 | /** | 
|  | 479 | * processingInstructionDebug: | 
|  | 480 | * @ctxt:  An XML parser context | 
|  | 481 | * @target:  the target name | 
|  | 482 | * @data: the PI data's | 
|  | 483 | * @len: the number of xmlChar | 
|  | 484 | * | 
|  | 485 | * A processing instruction has been parsed. | 
|  | 486 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 487 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 488 | processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target, | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 489 | const xmlChar *data) | 
|  | 490 | { | 
|  | 491 | fprintf(stdout, "SAX.processingInstruction(%s, %s)\n", | 
|  | 492 | (char *) target, (char *) data); | 
|  | 493 | } | 
|  | 494 |  | 
|  | 495 | /** | 
|  | 496 | * commentDebug: | 
|  | 497 | * @ctxt:  An XML parser context | 
|  | 498 | * @value:  the comment content | 
|  | 499 | * | 
|  | 500 | * A comment has been parsed. | 
|  | 501 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 502 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 503 | commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 504 | { | 
|  | 505 | fprintf(stdout, "SAX.comment(%s)\n", value); | 
|  | 506 | } | 
|  | 507 |  | 
|  | 508 | /** | 
|  | 509 | * warningDebug: | 
|  | 510 | * @ctxt:  An XML parser context | 
|  | 511 | * @msg:  the message to display/transmit | 
|  | 512 | * @...:  extra parameters for the message display | 
|  | 513 | * | 
|  | 514 | * Display and format a warning messages, gives file, line, position and | 
|  | 515 | * extra parameters. | 
|  | 516 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 517 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 518 | warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 519 | { | 
|  | 520 | va_list args; | 
|  | 521 |  | 
|  | 522 | va_start(args, msg); | 
|  | 523 | fprintf(stdout, "SAX.warning: "); | 
|  | 524 | vfprintf(stdout, msg, args); | 
|  | 525 | va_end(args); | 
|  | 526 | } | 
|  | 527 |  | 
|  | 528 | /** | 
|  | 529 | * errorDebug: | 
|  | 530 | * @ctxt:  An XML parser context | 
|  | 531 | * @msg:  the message to display/transmit | 
|  | 532 | * @...:  extra parameters for the message display | 
|  | 533 | * | 
|  | 534 | * Display and format a error messages, gives file, line, position and | 
|  | 535 | * extra parameters. | 
|  | 536 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 537 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 538 | errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 539 | { | 
|  | 540 | va_list args; | 
|  | 541 |  | 
|  | 542 | va_start(args, msg); | 
|  | 543 | fprintf(stdout, "SAX.error: "); | 
|  | 544 | vfprintf(stdout, msg, args); | 
|  | 545 | va_end(args); | 
|  | 546 | } | 
|  | 547 |  | 
|  | 548 | /** | 
|  | 549 | * fatalErrorDebug: | 
|  | 550 | * @ctxt:  An XML parser context | 
|  | 551 | * @msg:  the message to display/transmit | 
|  | 552 | * @...:  extra parameters for the message display | 
|  | 553 | * | 
|  | 554 | * Display and format a fatalError messages, gives file, line, position and | 
|  | 555 | * extra parameters. | 
|  | 556 | */ | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 557 | static void | 
| Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 558 | fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 559 | { | 
|  | 560 | va_list args; | 
|  | 561 |  | 
|  | 562 | va_start(args, msg); | 
|  | 563 | fprintf(stdout, "SAX.fatalError: "); | 
|  | 564 | vfprintf(stdout, msg, args); | 
|  | 565 | va_end(args); | 
|  | 566 | } | 
|  | 567 |  | 
|  | 568 | xmlSAXHandler debugSAXHandlerStruct = { | 
|  | 569 | internalSubsetDebug, | 
|  | 570 | isStandaloneDebug, | 
|  | 571 | hasInternalSubsetDebug, | 
|  | 572 | hasExternalSubsetDebug, | 
|  | 573 | resolveEntityDebug, | 
|  | 574 | getEntityDebug, | 
|  | 575 | entityDeclDebug, | 
|  | 576 | notationDeclDebug, | 
|  | 577 | attributeDeclDebug, | 
|  | 578 | elementDeclDebug, | 
|  | 579 | unparsedEntityDeclDebug, | 
|  | 580 | setDocumentLocatorDebug, | 
|  | 581 | startDocumentDebug, | 
|  | 582 | endDocumentDebug, | 
|  | 583 | startElementDebug, | 
|  | 584 | endElementDebug, | 
|  | 585 | referenceDebug, | 
|  | 586 | charactersDebug, | 
|  | 587 | ignorableWhitespaceDebug, | 
|  | 588 | processingInstructionDebug, | 
|  | 589 | commentDebug, | 
|  | 590 | warningDebug, | 
|  | 591 | errorDebug, | 
|  | 592 | fatalErrorDebug, | 
|  | 593 | getParameterEntityDebug, | 
| Daniel Veillard | 7eda845 | 2000-10-14 23:38:43 +0000 | [diff] [blame] | 594 | cdataDebug, | 
| Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 595 | NULL, | 
|  | 596 | 1 | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 597 | }; | 
|  | 598 |  | 
|  | 599 | xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct; | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 600 | /************************************************************************ | 
|  | 601 | *									* | 
|  | 602 | *				Debug					* | 
|  | 603 | *									* | 
|  | 604 | ************************************************************************/ | 
|  | 605 |  | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 606 | static void | 
|  | 607 | parseSAXFile(char *filename) { | 
| Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 608 | htmlDocPtr doc = NULL; | 
|  | 609 |  | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 610 | /* | 
|  | 611 | * Empty callbacks for checking | 
|  | 612 | */ | 
| Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 613 | if (push) { | 
|  | 614 | FILE *f; | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 615 |  | 
| Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 616 | f = fopen(filename, "r"); | 
|  | 617 | if (f != NULL) { | 
|  | 618 | int res, size = 3; | 
|  | 619 | char chars[4096]; | 
|  | 620 | htmlParserCtxtPtr ctxt; | 
|  | 621 |  | 
|  | 622 | /* if (repeat) */ | 
|  | 623 | size = 4096; | 
|  | 624 | res = fread(chars, 1, 4, f); | 
|  | 625 | if (res > 0) { | 
|  | 626 | ctxt = htmlCreatePushParserCtxt(emptySAXHandler, NULL, | 
|  | 627 | chars, res, filename, 0); | 
|  | 628 | while ((res = fread(chars, 1, size, f)) > 0) { | 
|  | 629 | htmlParseChunk(ctxt, chars, res, 0); | 
|  | 630 | } | 
|  | 631 | htmlParseChunk(ctxt, chars, 0, 1); | 
|  | 632 | doc = ctxt->myDoc; | 
|  | 633 | htmlFreeParserCtxt(ctxt); | 
|  | 634 | } | 
|  | 635 | if (doc != NULL) { | 
|  | 636 | fprintf(stdout, "htmlSAXParseFile returned non-NULL\n"); | 
|  | 637 | xmlFreeDoc(doc); | 
|  | 638 | } | 
|  | 639 | fclose(f); | 
|  | 640 | } | 
|  | 641 | if (!noout) { | 
|  | 642 | f = fopen(filename, "r"); | 
|  | 643 | if (f != NULL) { | 
|  | 644 | int res, size = 3; | 
|  | 645 | char chars[4096]; | 
|  | 646 | htmlParserCtxtPtr ctxt; | 
|  | 647 |  | 
|  | 648 | /* if (repeat) */ | 
|  | 649 | size = 4096; | 
|  | 650 | res = fread(chars, 1, 4, f); | 
|  | 651 | if (res > 0) { | 
|  | 652 | ctxt = htmlCreatePushParserCtxt(debugSAXHandler, NULL, | 
|  | 653 | chars, res, filename, 0); | 
|  | 654 | while ((res = fread(chars, 1, size, f)) > 0) { | 
|  | 655 | htmlParseChunk(ctxt, chars, res, 0); | 
|  | 656 | } | 
|  | 657 | htmlParseChunk(ctxt, chars, 0, 1); | 
|  | 658 | doc = ctxt->myDoc; | 
|  | 659 | htmlFreeParserCtxt(ctxt); | 
|  | 660 | } | 
|  | 661 | if (doc != NULL) { | 
|  | 662 | fprintf(stdout, "htmlSAXParseFile returned non-NULL\n"); | 
|  | 663 | xmlFreeDoc(doc); | 
|  | 664 | } | 
|  | 665 | fclose(f); | 
|  | 666 | } | 
|  | 667 | } | 
|  | 668 | } else { | 
|  | 669 | doc = htmlSAXParseFile(filename, NULL, emptySAXHandler, NULL); | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 670 | if (doc != NULL) { | 
|  | 671 | fprintf(stdout, "htmlSAXParseFile returned non-NULL\n"); | 
|  | 672 | xmlFreeDoc(doc); | 
|  | 673 | } | 
| Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 674 |  | 
|  | 675 | if (!noout) { | 
|  | 676 | /* | 
|  | 677 | * Debug callback | 
|  | 678 | */ | 
|  | 679 | doc = htmlSAXParseFile(filename, NULL, debugSAXHandler, NULL); | 
|  | 680 | if (doc != NULL) { | 
|  | 681 | fprintf(stdout, "htmlSAXParseFile returned non-NULL\n"); | 
|  | 682 | xmlFreeDoc(doc); | 
|  | 683 | } | 
|  | 684 | } | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 685 | } | 
|  | 686 | } | 
|  | 687 |  | 
| Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 688 | static void | 
|  | 689 | parseAndPrintFile(char *filename) { | 
| Daniel Veillard | 2eac503 | 2000-01-09 21:08:56 +0000 | [diff] [blame] | 690 | htmlDocPtr doc = NULL, tmp; | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 691 |  | 
|  | 692 | /* | 
|  | 693 | * build an HTML tree from a string; | 
|  | 694 | */ | 
| Daniel Veillard | 5e5c623 | 1999-12-29 12:49:06 +0000 | [diff] [blame] | 695 | if (push) { | 
|  | 696 | FILE *f; | 
|  | 697 |  | 
|  | 698 | f = fopen(filename, "r"); | 
|  | 699 | if (f != NULL) { | 
|  | 700 | int res, size = 3; | 
| Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 701 | char chars[4096]; | 
| Daniel Veillard | 5e5c623 | 1999-12-29 12:49:06 +0000 | [diff] [blame] | 702 | htmlParserCtxtPtr ctxt; | 
|  | 703 |  | 
| Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 704 | /* if (repeat) */ | 
|  | 705 | size = 4096; | 
| Daniel Veillard | 5e5c623 | 1999-12-29 12:49:06 +0000 | [diff] [blame] | 706 | res = fread(chars, 1, 4, f); | 
|  | 707 | if (res > 0) { | 
|  | 708 | ctxt = htmlCreatePushParserCtxt(NULL, NULL, | 
|  | 709 | chars, res, filename, 0); | 
|  | 710 | while ((res = fread(chars, 1, size, f)) > 0) { | 
|  | 711 | htmlParseChunk(ctxt, chars, res, 0); | 
|  | 712 | } | 
|  | 713 | htmlParseChunk(ctxt, chars, 0, 1); | 
|  | 714 | doc = ctxt->myDoc; | 
|  | 715 | htmlFreeParserCtxt(ctxt); | 
|  | 716 | } | 
| Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 717 | fclose(f); | 
| Daniel Veillard | 5e5c623 | 1999-12-29 12:49:06 +0000 | [diff] [blame] | 718 | } | 
|  | 719 | } else { | 
|  | 720 | doc = htmlParseFile(filename, NULL); | 
|  | 721 | } | 
|  | 722 | if (doc == NULL) { | 
| Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 723 | xmlGenericError(xmlGenericErrorContext, | 
|  | 724 | "Could not parse %s\n", filename); | 
| Daniel Veillard | 5e5c623 | 1999-12-29 12:49:06 +0000 | [diff] [blame] | 725 | } | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 726 |  | 
|  | 727 | /* | 
|  | 728 | * test intermediate copy if needed. | 
|  | 729 | */ | 
|  | 730 | if (copy) { | 
|  | 731 | tmp = doc; | 
|  | 732 | doc = xmlCopyDoc(doc, 1); | 
|  | 733 | xmlFreeDoc(tmp); | 
|  | 734 | } | 
|  | 735 |  | 
|  | 736 | /* | 
|  | 737 | * print it. | 
|  | 738 | */ | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 739 | if (!noout) { | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 740 | #ifdef LIBXML_DEBUG_ENABLED | 
| Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 741 | if (!debug) { | 
|  | 742 | if (encoding) | 
|  | 743 | htmlSaveFileEnc("-", doc, encoding); | 
|  | 744 | else | 
|  | 745 | htmlDocDump(stdout, doc); | 
|  | 746 | } else | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 747 | xmlDebugDumpDocument(stdout, doc); | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 748 | #else | 
| Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 749 | if (encoding) | 
|  | 750 | htmlSaveFileEnc("-", doc, encoding); | 
|  | 751 | else | 
|  | 752 | htmlDocDump(stdout, doc); | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 753 | #endif | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 754 | } | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 755 |  | 
|  | 756 | /* | 
|  | 757 | * free it. | 
|  | 758 | */ | 
|  | 759 | xmlFreeDoc(doc); | 
|  | 760 | } | 
|  | 761 |  | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 762 | int main(int argc, char **argv) { | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 763 | int i, count; | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 764 | int files = 0; | 
|  | 765 |  | 
|  | 766 | for (i = 1; i < argc ; i++) { | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 767 | #ifdef LIBXML_DEBUG_ENABLED | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 768 | if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) | 
|  | 769 | debug++; | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 770 | else | 
|  | 771 | #endif | 
|  | 772 | if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 773 | copy++; | 
| Daniel Veillard | 5e5c623 | 1999-12-29 12:49:06 +0000 | [diff] [blame] | 774 | else if ((!strcmp(argv[i], "-push")) || (!strcmp(argv[i], "--push"))) | 
|  | 775 | push++; | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 776 | else if ((!strcmp(argv[i], "-sax")) || (!strcmp(argv[i], "--sax"))) | 
|  | 777 | sax++; | 
|  | 778 | else if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout"))) | 
|  | 779 | noout++; | 
|  | 780 | else if ((!strcmp(argv[i], "-repeat")) || | 
|  | 781 | (!strcmp(argv[i], "--repeat"))) | 
|  | 782 | repeat++; | 
| Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 783 | else if ((!strcmp(argv[i], "-encode")) || | 
|  | 784 | (!strcmp(argv[i], "--encode"))) { | 
|  | 785 | i++; | 
|  | 786 | encoding = argv[i]; | 
|  | 787 | } | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 788 | } | 
|  | 789 | for (i = 1; i < argc ; i++) { | 
| Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 790 | if ((!strcmp(argv[i], "-encode")) || | 
|  | 791 | (!strcmp(argv[i], "--encode"))) { | 
|  | 792 | i++; | 
|  | 793 | continue; | 
|  | 794 | } | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 795 | if (argv[i][0] != '-') { | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 796 | if (repeat) { | 
|  | 797 | for (count = 0;count < 100 * repeat;count++) { | 
|  | 798 | if (sax) | 
|  | 799 | parseSAXFile(argv[i]); | 
|  | 800 | else | 
|  | 801 | parseAndPrintFile(argv[i]); | 
|  | 802 | } | 
|  | 803 | } else { | 
|  | 804 | if (sax) | 
|  | 805 | parseSAXFile(argv[i]); | 
|  | 806 | else | 
|  | 807 | parseAndPrintFile(argv[i]); | 
|  | 808 | } | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 809 | files ++; | 
|  | 810 | } | 
|  | 811 | } | 
|  | 812 | if (files == 0) { | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 813 | printf("Usage : %s [--debug] [--copy] [--copy] HTMLfiles ...\n", | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 814 | argv[0]); | 
|  | 815 | printf("\tParse the HTML files and output the result of the parsing\n"); | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 816 | #ifdef LIBXML_DEBUG_ENABLED | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 817 | printf("\t--debug : dump a debug tree of the in-memory document\n"); | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 818 | #endif | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 819 | printf("\t--copy : used to test the internal copy implementation\n"); | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 820 | printf("\t--sax : debug the sequence of SAX callbacks\n"); | 
| Daniel Veillard | 5e5c623 | 1999-12-29 12:49:06 +0000 | [diff] [blame] | 821 | printf("\t--repeat : parse the file 100 times, for timing\n"); | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 822 | printf("\t--noout : do not print the result\n"); | 
| Daniel Veillard | 5e5c623 | 1999-12-29 12:49:06 +0000 | [diff] [blame] | 823 | printf("\t--push : use the push mode parser\n"); | 
| Daniel Veillard | 32bc74e | 2000-07-14 14:49:25 +0000 | [diff] [blame] | 824 | printf("\t--encode encoding : output in the given encoding\n"); | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 825 | } | 
| Daniel Veillard | f5c2c87 | 1999-12-01 09:51:45 +0000 | [diff] [blame] | 826 | xmlCleanupParser(); | 
| Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 827 | xmlMemoryDump(); | 
| Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 828 |  | 
|  | 829 | return(0); | 
|  | 830 | } | 
| Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 831 | #else /* !LIBXML_HTML_ENABLED */ | 
|  | 832 | #include <stdio.h> | 
|  | 833 | int main(int argc, char **argv) { | 
|  | 834 | printf("%s : HTML support not compiled in\n", argv[0]); | 
|  | 835 | return(0); | 
|  | 836 | } | 
|  | 837 | #endif |