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