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