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