Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 1 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2 | * testSAX.c : a small tester program for parsing using the SAX API. |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 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 | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 47 | static int noent = 0; |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 48 | static int quiet = 0; |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 49 | static int nonull = 0; |
| 50 | static int sax2 = 0; |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 51 | static int callbacks = 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 | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 80 | NULL, /* externalSubset; */ |
| 81 | 1, |
| 82 | NULL, |
| 83 | NULL, /* startElementNs */ |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 84 | NULL /* endElementNs */ |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct; |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 88 | extern xmlSAXHandlerPtr debugSAXHandler; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 89 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 90 | /************************************************************************ |
| 91 | * * |
| 92 | * Debug Handlers * |
| 93 | * * |
| 94 | ************************************************************************/ |
| 95 | |
| 96 | /** |
| 97 | * isStandaloneDebug: |
| 98 | * @ctxt: An XML parser context |
| 99 | * |
| 100 | * Is this document tagged standalone ? |
| 101 | * |
| 102 | * Returns 1 if true |
| 103 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 104 | static int |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 105 | isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 106 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 107 | callbacks++; |
| 108 | if (quiet) |
| 109 | return(0); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 110 | fprintf(stdout, "SAX.isStandalone()\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 111 | return(0); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * hasInternalSubsetDebug: |
| 116 | * @ctxt: An XML parser context |
| 117 | * |
| 118 | * Does this document has an internal subset |
| 119 | * |
| 120 | * Returns 1 if true |
| 121 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 122 | static int |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 123 | hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 124 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 125 | callbacks++; |
| 126 | if (quiet) |
| 127 | return(0); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 128 | fprintf(stdout, "SAX.hasInternalSubset()\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 129 | return(0); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * hasExternalSubsetDebug: |
| 134 | * @ctxt: An XML parser context |
| 135 | * |
| 136 | * Does this document has an external subset |
| 137 | * |
| 138 | * Returns 1 if true |
| 139 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 140 | static int |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 141 | hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 142 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 143 | callbacks++; |
| 144 | if (quiet) |
| 145 | return(0); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 146 | fprintf(stdout, "SAX.hasExternalSubset()\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 147 | return(0); |
| 148 | } |
| 149 | |
| 150 | /** |
Daniel Veillard | 0604743 | 2000-04-24 11:33:38 +0000 | [diff] [blame] | 151 | * internalSubsetDebug: |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 152 | * @ctxt: An XML parser context |
| 153 | * |
| 154 | * Does this document has an internal subset |
| 155 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 156 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 157 | internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 158 | const xmlChar *ExternalID, const xmlChar *SystemID) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 159 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 160 | callbacks++; |
| 161 | if (quiet) |
| 162 | return; |
Daniel Veillard | 808a3f1 | 2000-08-17 13:50:51 +0000 | [diff] [blame] | 163 | fprintf(stdout, "SAX.internalSubset(%s,", name); |
| 164 | if (ExternalID == NULL) |
| 165 | fprintf(stdout, " ,"); |
| 166 | else |
| 167 | fprintf(stdout, " %s,", ExternalID); |
| 168 | if (SystemID == NULL) |
| 169 | fprintf(stdout, " )\n"); |
| 170 | else |
| 171 | fprintf(stdout, " %s)\n", SystemID); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /** |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 175 | * externalSubsetDebug: |
| 176 | * @ctxt: An XML parser context |
| 177 | * |
| 178 | * Does this document has an external subset |
| 179 | */ |
| 180 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 181 | externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 182 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 183 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 184 | callbacks++; |
| 185 | if (quiet) |
| 186 | return; |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 187 | fprintf(stdout, "SAX.externalSubset(%s,", name); |
| 188 | if (ExternalID == NULL) |
| 189 | fprintf(stdout, " ,"); |
| 190 | else |
| 191 | fprintf(stdout, " %s,", ExternalID); |
| 192 | if (SystemID == NULL) |
| 193 | fprintf(stdout, " )\n"); |
| 194 | else |
| 195 | fprintf(stdout, " %s)\n", SystemID); |
| 196 | } |
| 197 | |
| 198 | /** |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 199 | * resolveEntityDebug: |
| 200 | * @ctxt: An XML parser context |
| 201 | * @publicId: The public ID of the entity |
| 202 | * @systemId: The system ID of the entity |
| 203 | * |
| 204 | * Special entity resolver, better left to the parser, it has |
| 205 | * more context than the application layer. |
| 206 | * The default behaviour is to NOT resolve the entities, in that case |
| 207 | * the ENTITY_REF nodes are built in the structure (and the parameter |
| 208 | * values). |
| 209 | * |
| 210 | * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. |
| 211 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 212 | static xmlParserInputPtr |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 213 | resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 214 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 215 | callbacks++; |
| 216 | if (quiet) |
| 217 | return(NULL); |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 218 | /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 219 | |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 220 | |
| 221 | fprintf(stdout, "SAX.resolveEntity("); |
| 222 | if (publicId != NULL) |
| 223 | fprintf(stdout, "%s", (char *)publicId); |
| 224 | else |
| 225 | fprintf(stdout, " "); |
| 226 | if (systemId != NULL) |
| 227 | fprintf(stdout, ", %s)\n", (char *)systemId); |
| 228 | else |
| 229 | fprintf(stdout, ", )\n"); |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 230 | /********* |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 231 | if (systemId != NULL) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 232 | return(xmlNewInputFromFile(ctxt, (char *) systemId)); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 233 | } |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 234 | *********/ |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 235 | return(NULL); |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * getEntityDebug: |
| 240 | * @ctxt: An XML parser context |
| 241 | * @name: The entity name |
| 242 | * |
| 243 | * Get an entity by name |
| 244 | * |
| 245 | * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. |
| 246 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 247 | static xmlEntityPtr |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 248 | getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 249 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 250 | callbacks++; |
| 251 | if (quiet) |
| 252 | return(NULL); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 253 | fprintf(stdout, "SAX.getEntity(%s)\n", name); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 254 | return(NULL); |
| 255 | } |
| 256 | |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 257 | /** |
| 258 | * getParameterEntityDebug: |
| 259 | * @ctxt: An XML parser context |
| 260 | * @name: The entity name |
| 261 | * |
| 262 | * Get a parameter entity by name |
| 263 | * |
| 264 | * Returns the xmlParserInputPtr |
| 265 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 266 | static xmlEntityPtr |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 267 | getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 268 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 269 | callbacks++; |
| 270 | if (quiet) |
| 271 | return(NULL); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 272 | fprintf(stdout, "SAX.getParameterEntity(%s)\n", name); |
| 273 | return(NULL); |
| 274 | } |
| 275 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * entityDeclDebug: |
| 279 | * @ctxt: An XML parser context |
| 280 | * @name: the entity name |
| 281 | * @type: the entity type |
| 282 | * @publicId: The public ID of the entity |
| 283 | * @systemId: The system ID of the entity |
| 284 | * @content: the entity value (without processing). |
| 285 | * |
| 286 | * An entity definition has been parsed |
| 287 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 288 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 289 | entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 290 | const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 291 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 292 | callbacks++; |
| 293 | if (quiet) |
| 294 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 295 | fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 296 | name, type, publicId, systemId, content); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * attributeDeclDebug: |
| 301 | * @ctxt: An XML parser context |
| 302 | * @name: the attribute name |
| 303 | * @type: the attribute type |
| 304 | * |
| 305 | * An attribute definition has been parsed |
| 306 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 307 | static void |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 308 | attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar * elem, |
| 309 | const xmlChar * name, int type, int def, |
| 310 | const xmlChar * defaultValue, xmlEnumerationPtr tree) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 311 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 312 | callbacks++; |
| 313 | if (quiet) |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 314 | return; |
Daniel Veillard | 7e99c63 | 2000-10-06 12:59:53 +0000 | [diff] [blame] | 315 | if (defaultValue == NULL) |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 316 | fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n", |
| 317 | elem, name, type, def); |
Daniel Veillard | 7e99c63 | 2000-10-06 12:59:53 +0000 | [diff] [blame] | 318 | else |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 319 | fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", |
| 320 | elem, name, type, def, defaultValue); |
| 321 | xmlFreeEnumeration(tree); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /** |
| 325 | * elementDeclDebug: |
| 326 | * @ctxt: An XML parser context |
| 327 | * @name: the element name |
| 328 | * @type: the element type |
| 329 | * @content: the element value (without processing). |
| 330 | * |
| 331 | * An element definition has been parsed |
| 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 | elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, |
| 335 | xmlElementContentPtr content ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 336 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 337 | callbacks++; |
| 338 | if (quiet) |
| 339 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 340 | fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n", |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 341 | name, type); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * notationDeclDebug: |
| 346 | * @ctxt: An XML parser context |
| 347 | * @name: The name of the notation |
| 348 | * @publicId: The public ID of the entity |
| 349 | * @systemId: The system ID of the entity |
| 350 | * |
| 351 | * What to do when a notation declaration has been parsed. |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 352 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 353 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 354 | notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 355 | const xmlChar *publicId, const xmlChar *systemId) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 356 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 357 | callbacks++; |
| 358 | if (quiet) |
| 359 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 360 | fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n", |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 361 | (char *) name, (char *) publicId, (char *) systemId); |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * unparsedEntityDeclDebug: |
| 366 | * @ctxt: An XML parser context |
| 367 | * @name: The name of the entity |
| 368 | * @publicId: The public ID of the entity |
| 369 | * @systemId: The system ID of the entity |
| 370 | * @notationName: the name of the notation |
| 371 | * |
| 372 | * What to do when an unparsed entity declaration is parsed |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 373 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 374 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 375 | unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 376 | const xmlChar *publicId, const xmlChar *systemId, |
| 377 | const xmlChar *notationName) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 378 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 379 | callbacks++; |
| 380 | if (quiet) |
| 381 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 382 | fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n", |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 383 | (char *) name, (char *) publicId, (char *) systemId, |
| 384 | (char *) notationName); |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * setDocumentLocatorDebug: |
| 389 | * @ctxt: An XML parser context |
| 390 | * @loc: A SAX Locator |
| 391 | * |
| 392 | * Receive the document locator at startup, actually xmlDefaultSAXLocator |
| 393 | * Everything is available on the context, so this is useless in our case. |
| 394 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 395 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 396 | setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 397 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 398 | callbacks++; |
| 399 | if (quiet) |
| 400 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 401 | fprintf(stdout, "SAX.setDocumentLocator()\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /** |
| 405 | * startDocumentDebug: |
| 406 | * @ctxt: An XML parser context |
| 407 | * |
| 408 | * called when the document start being processed. |
| 409 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 410 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 411 | startDocumentDebug(void *ctx ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 412 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 413 | callbacks++; |
| 414 | if (quiet) |
| 415 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 416 | fprintf(stdout, "SAX.startDocument()\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /** |
| 420 | * endDocumentDebug: |
| 421 | * @ctxt: An XML parser context |
| 422 | * |
| 423 | * called when the document end has been detected. |
| 424 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 425 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 426 | endDocumentDebug(void *ctx ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 427 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 428 | callbacks++; |
| 429 | if (quiet) |
| 430 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 431 | fprintf(stdout, "SAX.endDocument()\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /** |
| 435 | * startElementDebug: |
| 436 | * @ctxt: An XML parser context |
| 437 | * @name: The element name |
| 438 | * |
| 439 | * called when an opening tag has been processed. |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 440 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 441 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 442 | startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 443 | { |
| 444 | int i; |
| 445 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 446 | callbacks++; |
| 447 | if (quiet) |
| 448 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 449 | fprintf(stdout, "SAX.startElement(%s", (char *) name); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 450 | if (atts != NULL) { |
| 451 | for (i = 0;(atts[i] != NULL);i++) { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 452 | fprintf(stdout, ", %s='", atts[i++]); |
Daniel Veillard | 808a3f1 | 2000-08-17 13:50:51 +0000 | [diff] [blame] | 453 | if (atts[i] != NULL) |
| 454 | fprintf(stdout, "%s'", atts[i]); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 455 | } |
| 456 | } |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 457 | fprintf(stdout, ")\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /** |
| 461 | * endElementDebug: |
| 462 | * @ctxt: An XML parser context |
| 463 | * @name: The element name |
| 464 | * |
| 465 | * called when the end of an element has been detected. |
| 466 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 467 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 468 | endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 469 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 470 | callbacks++; |
| 471 | if (quiet) |
| 472 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 473 | fprintf(stdout, "SAX.endElement(%s)\n", (char *) name); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | /** |
| 477 | * charactersDebug: |
| 478 | * @ctxt: An XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 479 | * @ch: a xmlChar string |
| 480 | * @len: the number of xmlChar |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 481 | * |
| 482 | * receiving some chars from the parser. |
| 483 | * Question: how much at a time ??? |
| 484 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 485 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 486 | charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 487 | { |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 488 | char output[40]; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 489 | int i; |
| 490 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 491 | callbacks++; |
| 492 | if (quiet) |
| 493 | return; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 494 | for (i = 0;(i<len) && (i < 30);i++) |
| 495 | output[i] = ch[i]; |
| 496 | output[i] = 0; |
| 497 | |
| 498 | fprintf(stdout, "SAX.characters(%s, %d)\n", output, len); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /** |
| 502 | * referenceDebug: |
| 503 | * @ctxt: An XML parser context |
| 504 | * @name: The entity name |
| 505 | * |
| 506 | * called when an entity reference is detected. |
| 507 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 508 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 509 | referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 510 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 511 | callbacks++; |
| 512 | if (quiet) |
| 513 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 514 | fprintf(stdout, "SAX.reference(%s)\n", name); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /** |
| 518 | * ignorableWhitespaceDebug: |
| 519 | * @ctxt: An XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 520 | * @ch: a xmlChar string |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 521 | * @start: the first char in the string |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 522 | * @len: the number of xmlChar |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 523 | * |
| 524 | * receiving some ignorable whitespaces from the parser. |
| 525 | * Question: how much at a time ??? |
| 526 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 527 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 528 | ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 529 | { |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 530 | char output[40]; |
| 531 | int i; |
| 532 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 533 | callbacks++; |
| 534 | if (quiet) |
| 535 | return; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 536 | for (i = 0;(i<len) && (i < 30);i++) |
| 537 | output[i] = ch[i]; |
| 538 | output[i] = 0; |
| 539 | fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /** |
| 543 | * processingInstructionDebug: |
| 544 | * @ctxt: An XML parser context |
| 545 | * @target: the target name |
| 546 | * @data: the PI data's |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 547 | * @len: the number of xmlChar |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 548 | * |
| 549 | * A processing instruction has been parsed. |
| 550 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 551 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 552 | processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 553 | const xmlChar *data) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 554 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 555 | callbacks++; |
| 556 | if (quiet) |
| 557 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 558 | fprintf(stdout, "SAX.processingInstruction(%s, %s)\n", |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 559 | (char *) target, (char *) data); |
| 560 | } |
| 561 | |
| 562 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 563 | * cdataBlockDebug: |
| 564 | * @ctx: the user data (XML parser context) |
| 565 | * @value: The pcdata content |
| 566 | * @len: the block length |
| 567 | * |
| 568 | * called when a pcdata block has been parsed |
| 569 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 570 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 571 | cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 572 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 573 | callbacks++; |
| 574 | if (quiet) |
| 575 | return; |
Daniel Veillard | 3991562 | 2000-10-15 10:06:55 +0000 | [diff] [blame] | 576 | fprintf(stdout, "SAX.pcdata(%.20s, %d)\n", |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 577 | (char *) value, len); |
| 578 | } |
| 579 | |
| 580 | /** |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 581 | * commentDebug: |
| 582 | * @ctxt: An XML parser context |
| 583 | * @value: the comment content |
| 584 | * |
| 585 | * A comment has been parsed. |
| 586 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 587 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 588 | commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 589 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 590 | callbacks++; |
| 591 | if (quiet) |
| 592 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 593 | fprintf(stdout, "SAX.comment(%s)\n", value); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /** |
| 597 | * warningDebug: |
| 598 | * @ctxt: An XML parser context |
| 599 | * @msg: the message to display/transmit |
| 600 | * @...: extra parameters for the message display |
| 601 | * |
| 602 | * Display and format a warning messages, gives file, line, position and |
| 603 | * extra parameters. |
| 604 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 605 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 606 | warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 607 | { |
| 608 | va_list args; |
| 609 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 610 | callbacks++; |
| 611 | if (quiet) |
| 612 | return; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 613 | va_start(args, msg); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 614 | fprintf(stdout, "SAX.warning: "); |
| 615 | vfprintf(stdout, msg, args); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 616 | va_end(args); |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * errorDebug: |
| 621 | * @ctxt: An XML parser context |
| 622 | * @msg: the message to display/transmit |
| 623 | * @...: extra parameters for the message display |
| 624 | * |
| 625 | * Display and format a error messages, gives file, line, position and |
| 626 | * extra parameters. |
| 627 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 628 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 629 | errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 630 | { |
| 631 | va_list args; |
| 632 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 633 | callbacks++; |
| 634 | if (quiet) |
| 635 | return; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 636 | va_start(args, msg); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 637 | fprintf(stdout, "SAX.error: "); |
| 638 | vfprintf(stdout, msg, args); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 639 | va_end(args); |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * fatalErrorDebug: |
| 644 | * @ctxt: An XML parser context |
| 645 | * @msg: the message to display/transmit |
| 646 | * @...: extra parameters for the message display |
| 647 | * |
| 648 | * Display and format a fatalError messages, gives file, line, position and |
| 649 | * extra parameters. |
| 650 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 651 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 652 | fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 653 | { |
| 654 | va_list args; |
| 655 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 656 | callbacks++; |
| 657 | if (quiet) |
| 658 | return; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 659 | va_start(args, msg); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 660 | fprintf(stdout, "SAX.fatalError: "); |
| 661 | vfprintf(stdout, msg, args); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 662 | va_end(args); |
| 663 | } |
| 664 | |
| 665 | xmlSAXHandler debugSAXHandlerStruct = { |
| 666 | internalSubsetDebug, |
| 667 | isStandaloneDebug, |
| 668 | hasInternalSubsetDebug, |
| 669 | hasExternalSubsetDebug, |
| 670 | resolveEntityDebug, |
| 671 | getEntityDebug, |
| 672 | entityDeclDebug, |
| 673 | notationDeclDebug, |
| 674 | attributeDeclDebug, |
| 675 | elementDeclDebug, |
| 676 | unparsedEntityDeclDebug, |
| 677 | setDocumentLocatorDebug, |
| 678 | startDocumentDebug, |
| 679 | endDocumentDebug, |
| 680 | startElementDebug, |
| 681 | endElementDebug, |
| 682 | referenceDebug, |
| 683 | charactersDebug, |
| 684 | ignorableWhitespaceDebug, |
| 685 | processingInstructionDebug, |
| 686 | commentDebug, |
| 687 | warningDebug, |
| 688 | errorDebug, |
| 689 | fatalErrorDebug, |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 690 | getParameterEntityDebug, |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 691 | cdataBlockDebug, |
Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 692 | externalSubsetDebug, |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 693 | 1, |
| 694 | NULL, |
| 695 | NULL, |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 696 | NULL |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 697 | }; |
| 698 | |
| 699 | xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct; |
| 700 | |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 701 | /* |
| 702 | * SAX2 specific callbacks |
| 703 | */ |
| 704 | /** |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 705 | * startElementNsDebug: |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 706 | * @ctxt: An XML parser context |
| 707 | * @name: The element name |
| 708 | * |
| 709 | * called when an opening tag has been processed. |
| 710 | */ |
| 711 | static void |
| 712 | startElementNsDebug(void *ctx ATTRIBUTE_UNUSED, |
| 713 | const xmlChar *localname, |
| 714 | const xmlChar *prefix, |
| 715 | const xmlChar *URI, |
| 716 | int nb_namespaces, |
| 717 | const xmlChar **namespaces, |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 718 | int nb_attributes, |
| 719 | int nb_defaulted, |
| 720 | const xmlChar **attributes) |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 721 | { |
| 722 | int i; |
| 723 | |
| 724 | callbacks++; |
| 725 | if (quiet) |
| 726 | return; |
| 727 | fprintf(stdout, "SAX.startElementNs(%s", (char *) localname); |
| 728 | if (prefix == NULL) |
| 729 | fprintf(stdout, ", NULL"); |
| 730 | else |
| 731 | fprintf(stdout, ", %s", (char *) prefix); |
| 732 | if (URI == NULL) |
| 733 | fprintf(stdout, ", NULL"); |
| 734 | else |
| 735 | fprintf(stdout, ", '%s'", (char *) URI); |
| 736 | fprintf(stdout, ", %d", nb_namespaces); |
| 737 | |
| 738 | if (namespaces != NULL) { |
| 739 | for (i = 0;i < nb_namespaces * 2;i++) { |
| 740 | fprintf(stdout, ", xmlns"); |
| 741 | if (namespaces[i] != NULL) |
| 742 | fprintf(stdout, ":%s", namespaces[i]); |
| 743 | i++; |
| 744 | fprintf(stdout, "='%s'", namespaces[i]); |
| 745 | } |
| 746 | } |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 747 | fprintf(stdout, ", %d, %d", nb_attributes, nb_defaulted); |
| 748 | if (attributes != NULL) { |
| 749 | for (i = 0;i < nb_attributes;i += 5) { |
| 750 | if (attributes[i + 1] != NULL) |
| 751 | fprintf(stdout, ", %s:%s='", attributes[i + 1], attributes[i]); |
| 752 | else |
| 753 | fprintf(stdout, ", %s='", attributes[i]); |
| 754 | fprintf(stdout, "%.4s...', %d", attributes[i + 3], |
| 755 | attributes[i + 4] - attributes[i + 3]); |
| 756 | } |
| 757 | } |
| 758 | fprintf(stdout, ")\n"); |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | /** |
| 762 | * endElementDebug: |
| 763 | * @ctxt: An XML parser context |
| 764 | * @name: The element name |
| 765 | * |
| 766 | * called when the end of an element has been detected. |
| 767 | */ |
| 768 | static void |
| 769 | endElementNsDebug(void *ctx ATTRIBUTE_UNUSED, |
| 770 | const xmlChar *localname, |
| 771 | const xmlChar *prefix, |
| 772 | const xmlChar *URI) |
| 773 | { |
| 774 | callbacks++; |
| 775 | if (quiet) |
| 776 | return; |
| 777 | fprintf(stdout, "SAX.endElementNs(%s", (char *) localname); |
| 778 | if (prefix == NULL) |
| 779 | fprintf(stdout, ", NULL"); |
| 780 | else |
| 781 | fprintf(stdout, ", %s", (char *) prefix); |
| 782 | if (URI == NULL) |
| 783 | fprintf(stdout, ", NULL)\n"); |
| 784 | else |
| 785 | fprintf(stdout, ", '%s')\n", (char *) URI); |
| 786 | } |
| 787 | |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 788 | xmlSAXHandler debugSAX2HandlerStruct = { |
| 789 | internalSubsetDebug, |
| 790 | isStandaloneDebug, |
| 791 | hasInternalSubsetDebug, |
| 792 | hasExternalSubsetDebug, |
| 793 | resolveEntityDebug, |
| 794 | getEntityDebug, |
| 795 | entityDeclDebug, |
| 796 | notationDeclDebug, |
| 797 | attributeDeclDebug, |
| 798 | elementDeclDebug, |
| 799 | unparsedEntityDeclDebug, |
| 800 | setDocumentLocatorDebug, |
| 801 | startDocumentDebug, |
| 802 | endDocumentDebug, |
| 803 | NULL, |
| 804 | NULL, |
| 805 | referenceDebug, |
| 806 | charactersDebug, |
| 807 | ignorableWhitespaceDebug, |
| 808 | processingInstructionDebug, |
| 809 | commentDebug, |
| 810 | warningDebug, |
| 811 | errorDebug, |
| 812 | fatalErrorDebug, |
| 813 | getParameterEntityDebug, |
| 814 | cdataBlockDebug, |
| 815 | externalSubsetDebug, |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 816 | XML_SAX2_MAGIC, |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 817 | NULL, |
| 818 | startElementNsDebug, |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 819 | endElementNsDebug |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 820 | }; |
| 821 | |
| 822 | xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct; |
| 823 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 824 | /************************************************************************ |
| 825 | * * |
| 826 | * Debug * |
| 827 | * * |
| 828 | ************************************************************************/ |
| 829 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 830 | static void |
| 831 | parseAndPrintFile(char *filename) { |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 832 | int res; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 833 | |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 834 | if (push) { |
| 835 | FILE *f; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 836 | |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 837 | if ((!quiet) && (!nonull)) { |
| 838 | /* |
| 839 | * Empty callbacks for checking |
| 840 | */ |
| 841 | f = fopen(filename, "r"); |
| 842 | if (f != NULL) { |
| 843 | int ret; |
| 844 | char chars[10]; |
| 845 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 846 | |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 847 | ret = fread(chars, 1, 4, f); |
| 848 | if (ret > 0) { |
| 849 | ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL, |
| 850 | chars, ret, filename); |
| 851 | while ((ret = fread(chars, 1, 3, f)) > 0) { |
| 852 | xmlParseChunk(ctxt, chars, ret, 0); |
| 853 | } |
| 854 | xmlParseChunk(ctxt, chars, 0, 1); |
| 855 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 856 | } |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 857 | fclose(f); |
| 858 | } else { |
| 859 | xmlGenericError(xmlGenericErrorContext, |
| 860 | "Cannot read file %s\n", filename); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 861 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 862 | } |
| 863 | /* |
| 864 | * Debug callback |
| 865 | */ |
| 866 | f = fopen(filename, "r"); |
| 867 | if (f != NULL) { |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 868 | int ret; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 869 | char chars[10]; |
| 870 | xmlParserCtxtPtr ctxt; |
| 871 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 872 | ret = fread(chars, 1, 4, f); |
| 873 | if (ret > 0) { |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 874 | if (sax2) |
| 875 | ctxt = xmlCreatePushParserCtxt(debugSAX2Handler, NULL, |
| 876 | chars, ret, filename); |
| 877 | else |
| 878 | ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL, |
| 879 | chars, ret, filename); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 880 | while ((ret = fread(chars, 1, 3, f)) > 0) { |
| 881 | xmlParseChunk(ctxt, chars, ret, 0); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 882 | } |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 883 | ret = xmlParseChunk(ctxt, chars, 0, 1); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 884 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 885 | if (ret != 0) { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 886 | fprintf(stdout, |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 887 | "xmlSAXUserParseFile returned error %d\n", ret); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | fclose(f); |
| 891 | } |
| 892 | } else { |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 893 | if (!speed) { |
| 894 | /* |
| 895 | * Empty callbacks for checking |
| 896 | */ |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 897 | if ((!quiet) && (!nonull)) { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 898 | res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename); |
| 899 | if (res != 0) { |
| 900 | fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); |
| 901 | } |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 902 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 903 | |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 904 | /* |
| 905 | * Debug callback |
| 906 | */ |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 907 | callbacks = 0; |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 908 | if (sax2) |
| 909 | res = xmlSAXUserParseFile(debugSAX2Handler, NULL, filename); |
| 910 | else |
| 911 | res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename); |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 912 | if (res != 0) { |
| 913 | fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); |
| 914 | } |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 915 | if (quiet) |
| 916 | fprintf(stdout, "%d callbacks generated\n", callbacks); |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 917 | } else { |
| 918 | /* |
| 919 | * test 100x the SAX parse |
| 920 | */ |
| 921 | int i; |
| 922 | |
| 923 | for (i = 0; i<100;i++) |
| 924 | res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename); |
| 925 | if (res != 0) { |
| 926 | fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); |
| 927 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 928 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 932 | |
| 933 | int main(int argc, char **argv) { |
| 934 | int i; |
| 935 | int files = 0; |
| 936 | |
| 937 | for (i = 1; i < argc ; i++) { |
| 938 | if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) |
| 939 | debug++; |
| 940 | else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) |
| 941 | copy++; |
| 942 | else if ((!strcmp(argv[i], "-recover")) || |
| 943 | (!strcmp(argv[i], "--recover"))) |
| 944 | recovery++; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 945 | else if ((!strcmp(argv[i], "-push")) || |
| 946 | (!strcmp(argv[i], "--push"))) |
| 947 | push++; |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 948 | else if ((!strcmp(argv[i], "-speed")) || |
| 949 | (!strcmp(argv[i], "--speed"))) |
| 950 | speed++; |
Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 951 | else if ((!strcmp(argv[i], "-noent")) || |
| 952 | (!strcmp(argv[i], "--noent"))) |
| 953 | noent++; |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 954 | else if ((!strcmp(argv[i], "-quiet")) || |
| 955 | (!strcmp(argv[i], "--quiet"))) |
| 956 | quiet++; |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame] | 957 | else if ((!strcmp(argv[i], "-sax2")) || |
| 958 | (!strcmp(argv[i], "--sax2"))) |
| 959 | sax2++; |
| 960 | else if ((!strcmp(argv[i], "-nonull")) || |
| 961 | (!strcmp(argv[i], "--nonull"))) |
| 962 | nonull++; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 963 | } |
Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 964 | if (noent != 0) xmlSubstituteEntitiesDefault(1); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 965 | for (i = 1; i < argc ; i++) { |
| 966 | if (argv[i][0] != '-') { |
| 967 | parseAndPrintFile(argv[i]); |
| 968 | files ++; |
| 969 | } |
| 970 | } |
Daniel Veillard | f5c2c87 | 1999-12-01 09:51:45 +0000 | [diff] [blame] | 971 | xmlCleanupParser(); |
| 972 | xmlMemoryDump(); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 973 | |
| 974 | return(0); |
| 975 | } |