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