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