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