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