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