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