Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 1 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2 | * testSAX.c : a small tester program for parsing using the SAX API. |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
Daniel Veillard | c5d6434 | 2001-06-24 12:13:24 +0000 | [diff] [blame] | 6 | * daniel@veillard.com |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 9 | #include "libxml.h" |
| 10 | |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 11 | #include <string.h> |
| 12 | #include <stdarg.h> |
| 13 | |
| 14 | #ifdef HAVE_SYS_TYPES_H |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 15 | #include <sys/types.h> |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 16 | #endif |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 17 | #ifdef HAVE_SYS_STAT_H |
| 18 | #include <sys/stat.h> |
| 19 | #endif |
| 20 | #ifdef HAVE_FCNTL_H |
| 21 | #include <fcntl.h> |
| 22 | #endif |
| 23 | #ifdef HAVE_UNISTD_H |
| 24 | #include <unistd.h> |
| 25 | #endif |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 26 | #ifdef HAVE_STDLIB_H |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 27 | #include <stdlib.h> |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 28 | #endif |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 29 | #ifdef HAVE_STRING_H |
| 30 | #include <string.h> |
| 31 | #endif |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 32 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 33 | |
Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 34 | #include <libxml/globals.h> |
Daniel Veillard | b71379b | 2000-10-09 12:30:39 +0000 | [diff] [blame] | 35 | #include <libxml/xmlerror.h> |
Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame] | 36 | #include <libxml/parser.h> |
| 37 | #include <libxml/parserInternals.h> /* only for xmlNewInputFromFile() */ |
| 38 | #include <libxml/tree.h> |
| 39 | #include <libxml/debugXML.h> |
| 40 | #include <libxml/xmlmemory.h> |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 41 | |
| 42 | static int debug = 0; |
| 43 | static int copy = 0; |
| 44 | static int recovery = 0; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 45 | static int push = 0; |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 46 | static int speed = 0; |
Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 47 | static int noent = 0; |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 48 | static int quiet = 0; |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame^] | 49 | static int nonull = 0; |
| 50 | static int sax2 = 0; |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 51 | static int callbacks = 0; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 52 | |
| 53 | xmlSAXHandler emptySAXHandlerStruct = { |
| 54 | NULL, /* internalSubset */ |
| 55 | NULL, /* isStandalone */ |
| 56 | NULL, /* hasInternalSubset */ |
| 57 | NULL, /* hasExternalSubset */ |
| 58 | NULL, /* resolveEntity */ |
| 59 | NULL, /* getEntity */ |
| 60 | NULL, /* entityDecl */ |
| 61 | NULL, /* notationDecl */ |
| 62 | NULL, /* attributeDecl */ |
| 63 | NULL, /* elementDecl */ |
| 64 | NULL, /* unparsedEntityDecl */ |
| 65 | NULL, /* setDocumentLocator */ |
| 66 | NULL, /* startDocument */ |
| 67 | NULL, /* endDocument */ |
| 68 | NULL, /* startElement */ |
| 69 | NULL, /* endElement */ |
| 70 | NULL, /* reference */ |
| 71 | NULL, /* characters */ |
| 72 | NULL, /* ignorableWhitespace */ |
| 73 | NULL, /* processingInstruction */ |
| 74 | NULL, /* comment */ |
| 75 | NULL, /* xmlParserWarning */ |
| 76 | NULL, /* xmlParserError */ |
| 77 | NULL, /* xmlParserError */ |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 78 | NULL, /* getParameterEntity */ |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 79 | NULL, /* cdataBlock; */ |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame^] | 80 | NULL, /* externalSubset; */ |
| 81 | 1, |
| 82 | NULL, |
| 83 | NULL, /* startElementNs */ |
| 84 | NULL, /* endElementNs */ |
| 85 | NULL /* attributeNs */ |
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 | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 309 | attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *elem, const xmlChar *name, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 310 | int type, int def, const xmlChar *defaultValue, |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 311 | xmlEnumerationPtr tree ATTRIBUTE_UNUSED) |
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) |
| 315 | return; |
Daniel Veillard | 7e99c63 | 2000-10-06 12:59:53 +0000 | [diff] [blame] | 316 | if (defaultValue == NULL) |
| 317 | fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n", |
| 318 | elem, name, type, def); |
| 319 | else |
| 320 | fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 321 | elem, name, type, def, defaultValue); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * elementDeclDebug: |
| 326 | * @ctxt: An XML parser context |
| 327 | * @name: the element name |
| 328 | * @type: the element type |
| 329 | * @content: the element value (without processing). |
| 330 | * |
| 331 | * An element definition has been parsed |
| 332 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 333 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 334 | elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, |
| 335 | xmlElementContentPtr content ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 336 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 337 | callbacks++; |
| 338 | if (quiet) |
| 339 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 340 | fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n", |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 341 | name, type); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * notationDeclDebug: |
| 346 | * @ctxt: An XML parser context |
| 347 | * @name: The name of the notation |
| 348 | * @publicId: The public ID of the entity |
| 349 | * @systemId: The system ID of the entity |
| 350 | * |
| 351 | * What to do when a notation declaration has been parsed. |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 352 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 353 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 354 | notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 355 | const xmlChar *publicId, const xmlChar *systemId) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 356 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 357 | callbacks++; |
| 358 | if (quiet) |
| 359 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 360 | fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n", |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 361 | (char *) name, (char *) publicId, (char *) systemId); |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * unparsedEntityDeclDebug: |
| 366 | * @ctxt: An XML parser context |
| 367 | * @name: The name of the entity |
| 368 | * @publicId: The public ID of the entity |
| 369 | * @systemId: The system ID of the entity |
| 370 | * @notationName: the name of the notation |
| 371 | * |
| 372 | * What to do when an unparsed entity declaration is parsed |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 373 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 374 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 375 | unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 376 | const xmlChar *publicId, const xmlChar *systemId, |
| 377 | const xmlChar *notationName) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 378 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 379 | callbacks++; |
| 380 | if (quiet) |
| 381 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 382 | fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n", |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 383 | (char *) name, (char *) publicId, (char *) systemId, |
| 384 | (char *) notationName); |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * setDocumentLocatorDebug: |
| 389 | * @ctxt: An XML parser context |
| 390 | * @loc: A SAX Locator |
| 391 | * |
| 392 | * Receive the document locator at startup, actually xmlDefaultSAXLocator |
| 393 | * Everything is available on the context, so this is useless in our case. |
| 394 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 395 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 396 | setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 397 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 398 | callbacks++; |
| 399 | if (quiet) |
| 400 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 401 | fprintf(stdout, "SAX.setDocumentLocator()\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /** |
| 405 | * startDocumentDebug: |
| 406 | * @ctxt: An XML parser context |
| 407 | * |
| 408 | * called when the document start being processed. |
| 409 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 410 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 411 | startDocumentDebug(void *ctx ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 412 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 413 | callbacks++; |
| 414 | if (quiet) |
| 415 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 416 | fprintf(stdout, "SAX.startDocument()\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /** |
| 420 | * endDocumentDebug: |
| 421 | * @ctxt: An XML parser context |
| 422 | * |
| 423 | * called when the document end has been detected. |
| 424 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 425 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 426 | endDocumentDebug(void *ctx ATTRIBUTE_UNUSED) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 427 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 428 | callbacks++; |
| 429 | if (quiet) |
| 430 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 431 | fprintf(stdout, "SAX.endDocument()\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /** |
| 435 | * startElementDebug: |
| 436 | * @ctxt: An XML parser context |
| 437 | * @name: The element name |
| 438 | * |
| 439 | * called when an opening tag has been processed. |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 440 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 441 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 442 | startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 443 | { |
| 444 | int i; |
| 445 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 446 | callbacks++; |
| 447 | if (quiet) |
| 448 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 449 | fprintf(stdout, "SAX.startElement(%s", (char *) name); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 450 | if (atts != NULL) { |
| 451 | for (i = 0;(atts[i] != NULL);i++) { |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 452 | fprintf(stdout, ", %s='", atts[i++]); |
Daniel Veillard | 808a3f1 | 2000-08-17 13:50:51 +0000 | [diff] [blame] | 453 | if (atts[i] != NULL) |
| 454 | fprintf(stdout, "%s'", atts[i]); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 455 | } |
| 456 | } |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 457 | fprintf(stdout, ")\n"); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /** |
| 461 | * endElementDebug: |
| 462 | * @ctxt: An XML parser context |
| 463 | * @name: The element name |
| 464 | * |
| 465 | * called when the end of an element has been detected. |
| 466 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 467 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 468 | endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 469 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 470 | callbacks++; |
| 471 | if (quiet) |
| 472 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 473 | fprintf(stdout, "SAX.endElement(%s)\n", (char *) name); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | /** |
| 477 | * charactersDebug: |
| 478 | * @ctxt: An XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 479 | * @ch: a xmlChar string |
| 480 | * @len: the number of xmlChar |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 481 | * |
| 482 | * receiving some chars from the parser. |
| 483 | * Question: how much at a time ??? |
| 484 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 485 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 486 | charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 487 | { |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 488 | char output[40]; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 489 | int i; |
| 490 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 491 | callbacks++; |
| 492 | if (quiet) |
| 493 | return; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 494 | for (i = 0;(i<len) && (i < 30);i++) |
| 495 | output[i] = ch[i]; |
| 496 | output[i] = 0; |
| 497 | |
| 498 | fprintf(stdout, "SAX.characters(%s, %d)\n", output, len); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /** |
| 502 | * referenceDebug: |
| 503 | * @ctxt: An XML parser context |
| 504 | * @name: The entity name |
| 505 | * |
| 506 | * called when an entity reference is detected. |
| 507 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 508 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 509 | referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 510 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 511 | callbacks++; |
| 512 | if (quiet) |
| 513 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 514 | fprintf(stdout, "SAX.reference(%s)\n", name); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /** |
| 518 | * ignorableWhitespaceDebug: |
| 519 | * @ctxt: An XML parser context |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 520 | * @ch: a xmlChar string |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 521 | * @start: the first char in the string |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 522 | * @len: the number of xmlChar |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 523 | * |
| 524 | * receiving some ignorable whitespaces from the parser. |
| 525 | * Question: how much at a time ??? |
| 526 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 527 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 528 | ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 529 | { |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 530 | char output[40]; |
| 531 | int i; |
| 532 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 533 | callbacks++; |
| 534 | if (quiet) |
| 535 | return; |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 536 | for (i = 0;(i<len) && (i < 30);i++) |
| 537 | output[i] = ch[i]; |
| 538 | output[i] = 0; |
| 539 | fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /** |
| 543 | * processingInstructionDebug: |
| 544 | * @ctxt: An XML parser context |
| 545 | * @target: the target name |
| 546 | * @data: the PI data's |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 547 | * @len: the number of xmlChar |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 548 | * |
| 549 | * A processing instruction has been parsed. |
| 550 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 551 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 552 | processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target, |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 553 | const xmlChar *data) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 554 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 555 | callbacks++; |
| 556 | if (quiet) |
| 557 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 558 | fprintf(stdout, "SAX.processingInstruction(%s, %s)\n", |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 559 | (char *) target, (char *) data); |
| 560 | } |
| 561 | |
| 562 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 563 | * cdataBlockDebug: |
| 564 | * @ctx: the user data (XML parser context) |
| 565 | * @value: The pcdata content |
| 566 | * @len: the block length |
| 567 | * |
| 568 | * called when a pcdata block has been parsed |
| 569 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 570 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 571 | cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len) |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 572 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 573 | callbacks++; |
| 574 | if (quiet) |
| 575 | return; |
Daniel Veillard | 3991562 | 2000-10-15 10:06:55 +0000 | [diff] [blame] | 576 | fprintf(stdout, "SAX.pcdata(%.20s, %d)\n", |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 577 | (char *) value, len); |
| 578 | } |
| 579 | |
| 580 | /** |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 581 | * commentDebug: |
| 582 | * @ctxt: An XML parser context |
| 583 | * @value: the comment content |
| 584 | * |
| 585 | * A comment has been parsed. |
| 586 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 587 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 588 | commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 589 | { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 590 | callbacks++; |
| 591 | if (quiet) |
| 592 | return; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 593 | fprintf(stdout, "SAX.comment(%s)\n", value); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /** |
| 597 | * warningDebug: |
| 598 | * @ctxt: An XML parser context |
| 599 | * @msg: the message to display/transmit |
| 600 | * @...: extra parameters for the message display |
| 601 | * |
| 602 | * Display and format a warning messages, gives file, line, position and |
| 603 | * extra parameters. |
| 604 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 605 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 606 | warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 607 | { |
| 608 | va_list args; |
| 609 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 610 | callbacks++; |
| 611 | if (quiet) |
| 612 | return; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 613 | va_start(args, msg); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 614 | fprintf(stdout, "SAX.warning: "); |
| 615 | vfprintf(stdout, msg, args); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 616 | va_end(args); |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * errorDebug: |
| 621 | * @ctxt: An XML parser context |
| 622 | * @msg: the message to display/transmit |
| 623 | * @...: extra parameters for the message display |
| 624 | * |
| 625 | * Display and format a error messages, gives file, line, position and |
| 626 | * extra parameters. |
| 627 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 628 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 629 | errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 630 | { |
| 631 | va_list args; |
| 632 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 633 | callbacks++; |
| 634 | if (quiet) |
| 635 | return; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 636 | va_start(args, msg); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 637 | fprintf(stdout, "SAX.error: "); |
| 638 | vfprintf(stdout, msg, args); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 639 | va_end(args); |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * fatalErrorDebug: |
| 644 | * @ctxt: An XML parser context |
| 645 | * @msg: the message to display/transmit |
| 646 | * @...: extra parameters for the message display |
| 647 | * |
| 648 | * Display and format a fatalError messages, gives file, line, position and |
| 649 | * extra parameters. |
| 650 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 651 | static void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 652 | fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 653 | { |
| 654 | va_list args; |
| 655 | |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 656 | callbacks++; |
| 657 | if (quiet) |
| 658 | return; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 659 | va_start(args, msg); |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 660 | fprintf(stdout, "SAX.fatalError: "); |
| 661 | vfprintf(stdout, msg, args); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 662 | va_end(args); |
| 663 | } |
| 664 | |
| 665 | xmlSAXHandler debugSAXHandlerStruct = { |
| 666 | internalSubsetDebug, |
| 667 | isStandaloneDebug, |
| 668 | hasInternalSubsetDebug, |
| 669 | hasExternalSubsetDebug, |
| 670 | resolveEntityDebug, |
| 671 | getEntityDebug, |
| 672 | entityDeclDebug, |
| 673 | notationDeclDebug, |
| 674 | attributeDeclDebug, |
| 675 | elementDeclDebug, |
| 676 | unparsedEntityDeclDebug, |
| 677 | setDocumentLocatorDebug, |
| 678 | startDocumentDebug, |
| 679 | endDocumentDebug, |
| 680 | startElementDebug, |
| 681 | endElementDebug, |
| 682 | referenceDebug, |
| 683 | charactersDebug, |
| 684 | ignorableWhitespaceDebug, |
| 685 | processingInstructionDebug, |
| 686 | commentDebug, |
| 687 | warningDebug, |
| 688 | errorDebug, |
| 689 | fatalErrorDebug, |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 690 | getParameterEntityDebug, |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 691 | cdataBlockDebug, |
Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 692 | externalSubsetDebug, |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame^] | 693 | 1, |
| 694 | NULL, |
| 695 | NULL, |
| 696 | NULL, |
| 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 | /** |
| 706 | * startElementDebug: |
| 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, |
| 719 | int nb_attributes) |
| 720 | { |
| 721 | int i; |
| 722 | |
| 723 | callbacks++; |
| 724 | if (quiet) |
| 725 | return; |
| 726 | fprintf(stdout, "SAX.startElementNs(%s", (char *) localname); |
| 727 | if (prefix == NULL) |
| 728 | fprintf(stdout, ", NULL"); |
| 729 | else |
| 730 | fprintf(stdout, ", %s", (char *) prefix); |
| 731 | if (URI == NULL) |
| 732 | fprintf(stdout, ", NULL"); |
| 733 | else |
| 734 | fprintf(stdout, ", '%s'", (char *) URI); |
| 735 | fprintf(stdout, ", %d", nb_namespaces); |
| 736 | |
| 737 | if (namespaces != NULL) { |
| 738 | for (i = 0;i < nb_namespaces * 2;i++) { |
| 739 | fprintf(stdout, ", xmlns"); |
| 740 | if (namespaces[i] != NULL) |
| 741 | fprintf(stdout, ":%s", namespaces[i]); |
| 742 | i++; |
| 743 | fprintf(stdout, "='%s'", namespaces[i]); |
| 744 | } |
| 745 | } |
| 746 | fprintf(stdout, ", %d)\n", nb_attributes); |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * endElementDebug: |
| 751 | * @ctxt: An XML parser context |
| 752 | * @name: The element name |
| 753 | * |
| 754 | * called when the end of an element has been detected. |
| 755 | */ |
| 756 | static void |
| 757 | endElementNsDebug(void *ctx ATTRIBUTE_UNUSED, |
| 758 | const xmlChar *localname, |
| 759 | const xmlChar *prefix, |
| 760 | const xmlChar *URI) |
| 761 | { |
| 762 | callbacks++; |
| 763 | if (quiet) |
| 764 | return; |
| 765 | fprintf(stdout, "SAX.endElementNs(%s", (char *) localname); |
| 766 | if (prefix == NULL) |
| 767 | fprintf(stdout, ", NULL"); |
| 768 | else |
| 769 | fprintf(stdout, ", %s", (char *) prefix); |
| 770 | if (URI == NULL) |
| 771 | fprintf(stdout, ", NULL)\n"); |
| 772 | else |
| 773 | fprintf(stdout, ", '%s')\n", (char *) URI); |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * attributeNsDebug: |
| 778 | * @ctxt: An XML parser context |
| 779 | * @name: The element name |
| 780 | * |
| 781 | * called when the end of an element has been detected. |
| 782 | */ |
| 783 | static void |
| 784 | attributeNsDebug(void *ctx ATTRIBUTE_UNUSED, |
| 785 | const xmlChar *localname, |
| 786 | const xmlChar *prefix, |
| 787 | const xmlChar *URI, |
| 788 | const xmlChar *value, |
| 789 | int valuelen) |
| 790 | { |
| 791 | callbacks++; |
| 792 | if (quiet) |
| 793 | return; |
| 794 | fprintf(stdout, "SAX.attributeNs(%s", (char *) localname); |
| 795 | if (prefix == NULL) |
| 796 | fprintf(stdout, ", NULL"); |
| 797 | else |
| 798 | fprintf(stdout, ", %s", (char *) prefix); |
| 799 | if (URI == NULL) |
| 800 | fprintf(stdout, ", NULL"); |
| 801 | else |
| 802 | fprintf(stdout, ", '%s'", (char *) URI); |
| 803 | if (valuelen > 13) |
| 804 | fprintf(stdout, ", %10s..., %d)\n", value, valuelen); |
| 805 | else |
| 806 | fprintf(stdout, ", %s, %d)\n", value, valuelen); |
| 807 | } |
| 808 | |
| 809 | xmlSAXHandler debugSAX2HandlerStruct = { |
| 810 | internalSubsetDebug, |
| 811 | isStandaloneDebug, |
| 812 | hasInternalSubsetDebug, |
| 813 | hasExternalSubsetDebug, |
| 814 | resolveEntityDebug, |
| 815 | getEntityDebug, |
| 816 | entityDeclDebug, |
| 817 | notationDeclDebug, |
| 818 | attributeDeclDebug, |
| 819 | elementDeclDebug, |
| 820 | unparsedEntityDeclDebug, |
| 821 | setDocumentLocatorDebug, |
| 822 | startDocumentDebug, |
| 823 | endDocumentDebug, |
| 824 | NULL, |
| 825 | NULL, |
| 826 | referenceDebug, |
| 827 | charactersDebug, |
| 828 | ignorableWhitespaceDebug, |
| 829 | processingInstructionDebug, |
| 830 | commentDebug, |
| 831 | warningDebug, |
| 832 | errorDebug, |
| 833 | fatalErrorDebug, |
| 834 | getParameterEntityDebug, |
| 835 | cdataBlockDebug, |
| 836 | externalSubsetDebug, |
| 837 | 1, |
| 838 | NULL, |
| 839 | startElementNsDebug, |
| 840 | endElementNsDebug, |
| 841 | attributeNsDebug |
| 842 | }; |
| 843 | |
| 844 | xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct; |
| 845 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 846 | /************************************************************************ |
| 847 | * * |
| 848 | * Debug * |
| 849 | * * |
| 850 | ************************************************************************/ |
| 851 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 852 | static void |
| 853 | parseAndPrintFile(char *filename) { |
Daniel Veillard | 7a66ee6 | 1999-09-26 11:31:02 +0000 | [diff] [blame] | 854 | int res; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 855 | |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 856 | if (push) { |
| 857 | FILE *f; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 858 | |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame^] | 859 | if ((!quiet) && (!nonull)) { |
| 860 | /* |
| 861 | * Empty callbacks for checking |
| 862 | */ |
| 863 | f = fopen(filename, "r"); |
| 864 | if (f != NULL) { |
| 865 | int ret; |
| 866 | char chars[10]; |
| 867 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 868 | |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame^] | 869 | ret = fread(chars, 1, 4, f); |
| 870 | if (ret > 0) { |
| 871 | ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL, |
| 872 | chars, ret, filename); |
| 873 | while ((ret = fread(chars, 1, 3, f)) > 0) { |
| 874 | xmlParseChunk(ctxt, chars, ret, 0); |
| 875 | } |
| 876 | xmlParseChunk(ctxt, chars, 0, 1); |
| 877 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 878 | } |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame^] | 879 | fclose(f); |
| 880 | } else { |
| 881 | xmlGenericError(xmlGenericErrorContext, |
| 882 | "Cannot read file %s\n", filename); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 883 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 884 | } |
| 885 | /* |
| 886 | * Debug callback |
| 887 | */ |
| 888 | f = fopen(filename, "r"); |
| 889 | if (f != NULL) { |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 890 | int ret; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 891 | char chars[10]; |
| 892 | xmlParserCtxtPtr ctxt; |
| 893 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 894 | ret = fread(chars, 1, 4, f); |
| 895 | if (ret > 0) { |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame^] | 896 | if (sax2) |
| 897 | ctxt = xmlCreatePushParserCtxt(debugSAX2Handler, NULL, |
| 898 | chars, ret, filename); |
| 899 | else |
| 900 | ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL, |
| 901 | chars, ret, filename); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 902 | while ((ret = fread(chars, 1, 3, f)) > 0) { |
| 903 | xmlParseChunk(ctxt, chars, ret, 0); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 904 | } |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 905 | ret = xmlParseChunk(ctxt, chars, 0, 1); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 906 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 907 | if (ret != 0) { |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 908 | fprintf(stdout, |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 909 | "xmlSAXUserParseFile returned error %d\n", ret); |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | fclose(f); |
| 913 | } |
| 914 | } else { |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 915 | if (!speed) { |
| 916 | /* |
| 917 | * Empty callbacks for checking |
| 918 | */ |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame^] | 919 | if ((!quiet) && (!nonull)) { |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 920 | res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename); |
| 921 | if (res != 0) { |
| 922 | fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); |
| 923 | } |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 924 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 925 | |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 926 | /* |
| 927 | * Debug callback |
| 928 | */ |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 929 | callbacks = 0; |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame^] | 930 | if (sax2) |
| 931 | res = xmlSAXUserParseFile(debugSAX2Handler, NULL, filename); |
| 932 | else |
| 933 | res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename); |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 934 | if (res != 0) { |
| 935 | fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); |
| 936 | } |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 937 | if (quiet) |
| 938 | fprintf(stdout, "%d callbacks generated\n", callbacks); |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 939 | } else { |
| 940 | /* |
| 941 | * test 100x the SAX parse |
| 942 | */ |
| 943 | int i; |
| 944 | |
| 945 | for (i = 0; i<100;i++) |
| 946 | res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename); |
| 947 | if (res != 0) { |
| 948 | fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res); |
| 949 | } |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 950 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 954 | |
| 955 | int main(int argc, char **argv) { |
| 956 | int i; |
| 957 | int files = 0; |
| 958 | |
| 959 | for (i = 1; i < argc ; i++) { |
| 960 | if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) |
| 961 | debug++; |
| 962 | else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) |
| 963 | copy++; |
| 964 | else if ((!strcmp(argv[i], "-recover")) || |
| 965 | (!strcmp(argv[i], "--recover"))) |
| 966 | recovery++; |
Daniel Veillard | dbfd641 | 1999-12-28 16:35:14 +0000 | [diff] [blame] | 967 | else if ((!strcmp(argv[i], "-push")) || |
| 968 | (!strcmp(argv[i], "--push"))) |
| 969 | push++; |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 970 | else if ((!strcmp(argv[i], "-speed")) || |
| 971 | (!strcmp(argv[i], "--speed"))) |
| 972 | speed++; |
Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 973 | else if ((!strcmp(argv[i], "-noent")) || |
| 974 | (!strcmp(argv[i], "--noent"))) |
| 975 | noent++; |
Daniel Veillard | e50f3b5 | 2002-03-20 19:24:21 +0000 | [diff] [blame] | 976 | else if ((!strcmp(argv[i], "-quiet")) || |
| 977 | (!strcmp(argv[i], "--quiet"))) |
| 978 | quiet++; |
Daniel Veillard | 0fb1893 | 2003-09-07 09:14:37 +0000 | [diff] [blame^] | 979 | else if ((!strcmp(argv[i], "-sax2")) || |
| 980 | (!strcmp(argv[i], "--sax2"))) |
| 981 | sax2++; |
| 982 | else if ((!strcmp(argv[i], "-nonull")) || |
| 983 | (!strcmp(argv[i], "--nonull"))) |
| 984 | nonull++; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 985 | } |
Daniel Veillard | 5997aca | 2002-03-18 18:36:20 +0000 | [diff] [blame] | 986 | if (noent != 0) xmlSubstituteEntitiesDefault(1); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 987 | for (i = 1; i < argc ; i++) { |
| 988 | if (argv[i][0] != '-') { |
| 989 | parseAndPrintFile(argv[i]); |
| 990 | files ++; |
| 991 | } |
| 992 | } |
Daniel Veillard | f5c2c87 | 1999-12-01 09:51:45 +0000 | [diff] [blame] | 993 | xmlCleanupParser(); |
| 994 | xmlMemoryDump(); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 995 | |
| 996 | return(0); |
| 997 | } |