blob: b8db61b2e5dfd5fd8ca032655bd0a737fb9c6f66 [file] [log] [blame]
Daniel Veillard5099ae81999-04-21 20:12:07 +00001/*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00002 * testSAX.c : a small tester program for parsing using the SAX API.
Daniel Veillard5099ae81999-04-21 20:12:07 +00003 *
4 * See Copyright for the status of this software.
5 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00006 * daniel@veillard.com
Daniel Veillard5099ae81999-04-21 20:12:07 +00007 */
8
Bjorn Reese70a9da52001-04-21 16:57:29 +00009#include "libxml.h"
10
Daniel Veillard81273902003-09-30 00:43:48 +000011#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard7f7d1111999-09-22 09:46:25 +000012#include <string.h>
13#include <stdarg.h>
14
15#ifdef HAVE_SYS_TYPES_H
Daniel Veillard5099ae81999-04-21 20:12:07 +000016#include <sys/types.h>
Daniel Veillard7f7d1111999-09-22 09:46:25 +000017#endif
Daniel Veillard5099ae81999-04-21 20:12:07 +000018#ifdef HAVE_SYS_STAT_H
19#include <sys/stat.h>
20#endif
21#ifdef HAVE_FCNTL_H
22#include <fcntl.h>
23#endif
24#ifdef HAVE_UNISTD_H
25#include <unistd.h>
26#endif
Daniel Veillard7f7d1111999-09-22 09:46:25 +000027#ifdef HAVE_STDLIB_H
Daniel Veillard5099ae81999-04-21 20:12:07 +000028#include <stdlib.h>
Daniel Veillard7f7d1111999-09-22 09:46:25 +000029#endif
Daniel Veillard7a66ee61999-09-26 11:31:02 +000030#ifdef HAVE_STRING_H
31#include <string.h>
32#endif
Daniel Veillard7f7d1111999-09-22 09:46:25 +000033
Daniel Veillard5099ae81999-04-21 20:12:07 +000034
Daniel Veillardd0463562001-10-13 09:15:48 +000035#include <libxml/globals.h>
Daniel Veillardb71379b2000-10-09 12:30:39 +000036#include <libxml/xmlerror.h>
Daniel Veillard361d8452000-04-03 19:48:13 +000037#include <libxml/parser.h>
38#include <libxml/parserInternals.h> /* only for xmlNewInputFromFile() */
39#include <libxml/tree.h>
40#include <libxml/debugXML.h>
41#include <libxml/xmlmemory.h>
Daniel Veillard5099ae81999-04-21 20:12:07 +000042
43static int debug = 0;
44static int copy = 0;
45static int recovery = 0;
Daniel Veillarddbfd6411999-12-28 16:35:14 +000046static int push = 0;
Daniel Veillard5e873c42000-04-12 13:27:38 +000047static int speed = 0;
Daniel Veillard5997aca2002-03-18 18:36:20 +000048static int noent = 0;
Daniel Veillarde50f3b52002-03-20 19:24:21 +000049static int quiet = 0;
Daniel Veillard0fb18932003-09-07 09:14:37 +000050static int nonull = 0;
51static int sax2 = 0;
Daniel Veillarde50f3b52002-03-20 19:24:21 +000052static int callbacks = 0;
Daniel Veillard5099ae81999-04-21 20:12:07 +000053
54xmlSAXHandler emptySAXHandlerStruct = {
55 NULL, /* internalSubset */
56 NULL, /* isStandalone */
57 NULL, /* hasInternalSubset */
58 NULL, /* hasExternalSubset */
59 NULL, /* resolveEntity */
60 NULL, /* getEntity */
61 NULL, /* entityDecl */
62 NULL, /* notationDecl */
63 NULL, /* attributeDecl */
64 NULL, /* elementDecl */
65 NULL, /* unparsedEntityDecl */
66 NULL, /* setDocumentLocator */
67 NULL, /* startDocument */
68 NULL, /* endDocument */
69 NULL, /* startElement */
70 NULL, /* endElement */
71 NULL, /* reference */
72 NULL, /* characters */
73 NULL, /* ignorableWhitespace */
74 NULL, /* processingInstruction */
75 NULL, /* comment */
76 NULL, /* xmlParserWarning */
77 NULL, /* xmlParserError */
78 NULL, /* xmlParserError */
Daniel Veillardb05deb71999-08-10 19:04:08 +000079 NULL, /* getParameterEntity */
Daniel Veillardcf461992000-03-14 18:30:20 +000080 NULL, /* cdataBlock; */
Daniel Veillard0fb18932003-09-07 09:14:37 +000081 NULL, /* externalSubset; */
82 1,
83 NULL,
84 NULL, /* startElementNs */
William M. Brack871611b2003-10-18 04:53:14 +000085 NULL, /* endElementNs */
86 NULL /* xmlStructuredErrorFunc */
Daniel Veillard5099ae81999-04-21 20:12:07 +000087};
88
89xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
Daniel Veillard011b63c1999-06-02 17:44:04 +000090extern xmlSAXHandlerPtr debugSAXHandler;
Daniel Veillard5099ae81999-04-21 20:12:07 +000091
Daniel Veillard5099ae81999-04-21 20:12:07 +000092/************************************************************************
93 * *
94 * Debug Handlers *
95 * *
96 ************************************************************************/
97
98/**
99 * isStandaloneDebug:
100 * @ctxt: An XML parser context
101 *
102 * Is this document tagged standalone ?
103 *
104 * Returns 1 if true
105 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000106static int
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000107isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000108{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000109 callbacks++;
110 if (quiet)
111 return(0);
Daniel Veillard27d88741999-05-29 11:51:49 +0000112 fprintf(stdout, "SAX.isStandalone()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000113 return(0);
114}
115
116/**
117 * hasInternalSubsetDebug:
118 * @ctxt: An XML parser context
119 *
120 * Does this document has an internal subset
121 *
122 * Returns 1 if true
123 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000124static int
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000125hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000126{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000127 callbacks++;
128 if (quiet)
129 return(0);
Daniel Veillard27d88741999-05-29 11:51:49 +0000130 fprintf(stdout, "SAX.hasInternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000131 return(0);
132}
133
134/**
135 * hasExternalSubsetDebug:
136 * @ctxt: An XML parser context
137 *
138 * Does this document has an external subset
139 *
140 * Returns 1 if true
141 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000142static int
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000143hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000144{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000145 callbacks++;
146 if (quiet)
147 return(0);
Daniel Veillard27d88741999-05-29 11:51:49 +0000148 fprintf(stdout, "SAX.hasExternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000149 return(0);
150}
151
152/**
Daniel Veillard06047432000-04-24 11:33:38 +0000153 * internalSubsetDebug:
Daniel Veillard5099ae81999-04-21 20:12:07 +0000154 * @ctxt: An XML parser context
155 *
156 * Does this document has an internal subset
157 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000158static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000159internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000160 const xmlChar *ExternalID, const xmlChar *SystemID)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000161{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000162 callbacks++;
163 if (quiet)
164 return;
Daniel Veillard808a3f12000-08-17 13:50:51 +0000165 fprintf(stdout, "SAX.internalSubset(%s,", name);
166 if (ExternalID == NULL)
167 fprintf(stdout, " ,");
168 else
169 fprintf(stdout, " %s,", ExternalID);
170 if (SystemID == NULL)
171 fprintf(stdout, " )\n");
172 else
173 fprintf(stdout, " %s)\n", SystemID);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000174}
175
176/**
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000177 * externalSubsetDebug:
178 * @ctxt: An XML parser context
179 *
180 * Does this document has an external subset
181 */
182static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000183externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000184 const xmlChar *ExternalID, const xmlChar *SystemID)
185{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000186 callbacks++;
187 if (quiet)
188 return;
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000189 fprintf(stdout, "SAX.externalSubset(%s,", name);
190 if (ExternalID == NULL)
191 fprintf(stdout, " ,");
192 else
193 fprintf(stdout, " %s,", ExternalID);
194 if (SystemID == NULL)
195 fprintf(stdout, " )\n");
196 else
197 fprintf(stdout, " %s)\n", SystemID);
198}
199
200/**
Daniel Veillard5099ae81999-04-21 20:12:07 +0000201 * resolveEntityDebug:
202 * @ctxt: An XML parser context
203 * @publicId: The public ID of the entity
204 * @systemId: The system ID of the entity
205 *
206 * Special entity resolver, better left to the parser, it has
207 * more context than the application layer.
208 * The default behaviour is to NOT resolve the entities, in that case
209 * the ENTITY_REF nodes are built in the structure (and the parameter
210 * values).
211 *
212 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
213 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000214static xmlParserInputPtr
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000215resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000216{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000217 callbacks++;
218 if (quiet)
219 return(NULL);
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000220 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000221
Daniel Veillard14fff061999-06-22 21:49:07 +0000222
223 fprintf(stdout, "SAX.resolveEntity(");
224 if (publicId != NULL)
225 fprintf(stdout, "%s", (char *)publicId);
226 else
227 fprintf(stdout, " ");
228 if (systemId != NULL)
229 fprintf(stdout, ", %s)\n", (char *)systemId);
230 else
231 fprintf(stdout, ", )\n");
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000232/*********
Daniel Veillard011b63c1999-06-02 17:44:04 +0000233 if (systemId != NULL) {
Daniel Veillardb96e6431999-08-29 21:02:19 +0000234 return(xmlNewInputFromFile(ctxt, (char *) systemId));
Daniel Veillard011b63c1999-06-02 17:44:04 +0000235 }
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000236 *********/
Daniel Veillard5099ae81999-04-21 20:12:07 +0000237 return(NULL);
238}
239
240/**
241 * getEntityDebug:
242 * @ctxt: An XML parser context
243 * @name: The entity name
244 *
245 * Get an entity by name
246 *
247 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
248 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000249static xmlEntityPtr
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000250getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000251{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000252 callbacks++;
253 if (quiet)
254 return(NULL);
Daniel Veillard27d88741999-05-29 11:51:49 +0000255 fprintf(stdout, "SAX.getEntity(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000256 return(NULL);
257}
258
Daniel Veillardb05deb71999-08-10 19:04:08 +0000259/**
260 * getParameterEntityDebug:
261 * @ctxt: An XML parser context
262 * @name: The entity name
263 *
264 * Get a parameter entity by name
265 *
266 * Returns the xmlParserInputPtr
267 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000268static xmlEntityPtr
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000269getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillardb05deb71999-08-10 19:04:08 +0000270{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000271 callbacks++;
272 if (quiet)
273 return(NULL);
Daniel Veillardb05deb71999-08-10 19:04:08 +0000274 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
275 return(NULL);
276}
277
Daniel Veillard5099ae81999-04-21 20:12:07 +0000278
279/**
280 * entityDeclDebug:
281 * @ctxt: An XML parser context
282 * @name: the entity name
283 * @type: the entity type
284 * @publicId: The public ID of the entity
285 * @systemId: The system ID of the entity
286 * @content: the entity value (without processing).
287 *
288 * An entity definition has been parsed
289 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000290static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000291entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000292 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000293{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000294 callbacks++;
295 if (quiet)
296 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000297 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000298 name, type, publicId, systemId, content);
299}
300
301/**
302 * attributeDeclDebug:
303 * @ctxt: An XML parser context
304 * @name: the attribute name
305 * @type: the attribute type
306 *
307 * An attribute definition has been parsed
308 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000309static void
Daniel Veillard07cb8222003-09-10 10:51:05 +0000310attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar * elem,
311 const xmlChar * name, int type, int def,
312 const xmlChar * defaultValue, xmlEnumerationPtr tree)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000313{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000314 callbacks++;
315 if (quiet)
Daniel Veillard07cb8222003-09-10 10:51:05 +0000316 return;
Daniel Veillard7e99c632000-10-06 12:59:53 +0000317 if (defaultValue == NULL)
Daniel Veillard07cb8222003-09-10 10:51:05 +0000318 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n",
319 elem, name, type, def);
Daniel Veillard7e99c632000-10-06 12:59:53 +0000320 else
Daniel Veillard07cb8222003-09-10 10:51:05 +0000321 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
322 elem, name, type, def, defaultValue);
323 xmlFreeEnumeration(tree);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000324}
325
326/**
327 * elementDeclDebug:
328 * @ctxt: An XML parser context
329 * @name: the element name
330 * @type: the element type
331 * @content: the element value (without processing).
332 *
333 * An element definition has been parsed
334 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000335static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000336elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
337 xmlElementContentPtr content ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000338{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000339 callbacks++;
340 if (quiet)
341 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000342 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000343 name, type);
344}
345
346/**
347 * notationDeclDebug:
348 * @ctxt: An XML parser context
349 * @name: The name of the notation
350 * @publicId: The public ID of the entity
351 * @systemId: The system ID of the entity
352 *
353 * What to do when a notation declaration has been parsed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000354 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000355static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000356notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000357 const xmlChar *publicId, const xmlChar *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000358{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000359 callbacks++;
360 if (quiet)
361 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000362 fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000363 (char *) name, (char *) publicId, (char *) systemId);
364}
365
366/**
367 * unparsedEntityDeclDebug:
368 * @ctxt: An XML parser context
369 * @name: The name of the entity
370 * @publicId: The public ID of the entity
371 * @systemId: The system ID of the entity
372 * @notationName: the name of the notation
373 *
374 * What to do when an unparsed entity declaration is parsed
Daniel Veillard5099ae81999-04-21 20:12:07 +0000375 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000376static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000377unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000378 const xmlChar *publicId, const xmlChar *systemId,
379 const xmlChar *notationName)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000380{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000381 callbacks++;
382 if (quiet)
383 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000384 fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000385 (char *) name, (char *) publicId, (char *) systemId,
386 (char *) notationName);
387}
388
389/**
390 * setDocumentLocatorDebug:
391 * @ctxt: An XML parser context
392 * @loc: A SAX Locator
393 *
394 * Receive the document locator at startup, actually xmlDefaultSAXLocator
395 * Everything is available on the context, so this is useless in our case.
396 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000397static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000398setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000399{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000400 callbacks++;
401 if (quiet)
402 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000403 fprintf(stdout, "SAX.setDocumentLocator()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000404}
405
406/**
407 * startDocumentDebug:
408 * @ctxt: An XML parser context
409 *
410 * called when the document start being processed.
411 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000412static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000413startDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000414{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000415 callbacks++;
416 if (quiet)
417 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000418 fprintf(stdout, "SAX.startDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000419}
420
421/**
422 * endDocumentDebug:
423 * @ctxt: An XML parser context
424 *
425 * called when the document end has been detected.
426 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000427static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000428endDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000429{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000430 callbacks++;
431 if (quiet)
432 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000433 fprintf(stdout, "SAX.endDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000434}
435
436/**
437 * startElementDebug:
438 * @ctxt: An XML parser context
439 * @name: The element name
440 *
441 * called when an opening tag has been processed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000442 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000443static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000444startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000445{
446 int i;
447
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000448 callbacks++;
449 if (quiet)
450 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000451 fprintf(stdout, "SAX.startElement(%s", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000452 if (atts != NULL) {
453 for (i = 0;(atts[i] != NULL);i++) {
Daniel Veillard27d88741999-05-29 11:51:49 +0000454 fprintf(stdout, ", %s='", atts[i++]);
Daniel Veillard808a3f12000-08-17 13:50:51 +0000455 if (atts[i] != NULL)
456 fprintf(stdout, "%s'", atts[i]);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000457 }
458 }
Daniel Veillard27d88741999-05-29 11:51:49 +0000459 fprintf(stdout, ")\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000460}
461
462/**
463 * endElementDebug:
464 * @ctxt: An XML parser context
465 * @name: The element name
466 *
467 * called when the end of an element has been detected.
468 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000469static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000470endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000471{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000472 callbacks++;
473 if (quiet)
474 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000475 fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000476}
477
478/**
479 * charactersDebug:
480 * @ctxt: An XML parser context
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000481 * @ch: a xmlChar string
482 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000483 *
484 * receiving some chars from the parser.
485 * Question: how much at a time ???
486 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000487static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000488charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000489{
Daniel Veillard87b95392000-08-12 21:12:04 +0000490 char output[40];
Daniel Veillarde2d034d1999-07-27 19:52:06 +0000491 int i;
492
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000493 callbacks++;
494 if (quiet)
495 return;
Daniel Veillard87b95392000-08-12 21:12:04 +0000496 for (i = 0;(i<len) && (i < 30);i++)
497 output[i] = ch[i];
498 output[i] = 0;
499
500 fprintf(stdout, "SAX.characters(%s, %d)\n", output, len);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000501}
502
503/**
504 * referenceDebug:
505 * @ctxt: An XML parser context
506 * @name: The entity name
507 *
508 * called when an entity reference is detected.
509 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000510static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000511referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000512{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000513 callbacks++;
514 if (quiet)
515 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000516 fprintf(stdout, "SAX.reference(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000517}
518
519/**
520 * ignorableWhitespaceDebug:
521 * @ctxt: An XML parser context
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000522 * @ch: a xmlChar string
Daniel Veillard5099ae81999-04-21 20:12:07 +0000523 * @start: the first char in the string
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000524 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000525 *
526 * receiving some ignorable whitespaces from the parser.
527 * Question: how much at a time ???
528 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000529static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000530ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000531{
Daniel Veillard87b95392000-08-12 21:12:04 +0000532 char output[40];
533 int i;
534
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000535 callbacks++;
536 if (quiet)
537 return;
Daniel Veillard87b95392000-08-12 21:12:04 +0000538 for (i = 0;(i<len) && (i < 30);i++)
539 output[i] = ch[i];
540 output[i] = 0;
541 fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000542}
543
544/**
545 * processingInstructionDebug:
546 * @ctxt: An XML parser context
547 * @target: the target name
548 * @data: the PI data's
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000549 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000550 *
551 * A processing instruction has been parsed.
552 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000553static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000554processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000555 const xmlChar *data)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000556{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000557 callbacks++;
558 if (quiet)
559 return;
Daniel Veillard4772af62003-10-27 16:23:43 +0000560 if (data != NULL)
561 fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
562 (char *) target, (char *) data);
563 else
564 fprintf(stdout, "SAX.processingInstruction(%s, NULL)\n",
565 (char *) target);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000566}
567
568/**
Daniel Veillardcf461992000-03-14 18:30:20 +0000569 * cdataBlockDebug:
570 * @ctx: the user data (XML parser context)
571 * @value: The pcdata content
572 * @len: the block length
573 *
574 * called when a pcdata block has been parsed
575 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000576static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000577cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len)
Daniel Veillardcf461992000-03-14 18:30:20 +0000578{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000579 callbacks++;
580 if (quiet)
581 return;
Daniel Veillard39915622000-10-15 10:06:55 +0000582 fprintf(stdout, "SAX.pcdata(%.20s, %d)\n",
Daniel Veillardcf461992000-03-14 18:30:20 +0000583 (char *) value, len);
584}
585
586/**
Daniel Veillard5099ae81999-04-21 20:12:07 +0000587 * commentDebug:
588 * @ctxt: An XML parser context
589 * @value: the comment content
590 *
591 * A comment has been parsed.
592 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000593static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000594commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000595{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000596 callbacks++;
597 if (quiet)
598 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000599 fprintf(stdout, "SAX.comment(%s)\n", value);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000600}
601
602/**
603 * warningDebug:
604 * @ctxt: An XML parser context
605 * @msg: the message to display/transmit
606 * @...: extra parameters for the message display
607 *
608 * Display and format a warning messages, gives file, line, position and
609 * extra parameters.
610 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000611static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000612warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000613{
614 va_list args;
615
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000616 callbacks++;
617 if (quiet)
618 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000619 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000620 fprintf(stdout, "SAX.warning: ");
621 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000622 va_end(args);
623}
624
625/**
626 * errorDebug:
627 * @ctxt: An XML parser context
628 * @msg: the message to display/transmit
629 * @...: extra parameters for the message display
630 *
631 * Display and format a error messages, gives file, line, position and
632 * extra parameters.
633 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000634static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000635errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000636{
637 va_list args;
638
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000639 callbacks++;
640 if (quiet)
641 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000642 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000643 fprintf(stdout, "SAX.error: ");
644 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000645 va_end(args);
646}
647
648/**
649 * fatalErrorDebug:
650 * @ctxt: An XML parser context
651 * @msg: the message to display/transmit
652 * @...: extra parameters for the message display
653 *
654 * Display and format a fatalError messages, gives file, line, position and
655 * extra parameters.
656 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000657static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000658fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000659{
660 va_list args;
661
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000662 callbacks++;
663 if (quiet)
664 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000665 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000666 fprintf(stdout, "SAX.fatalError: ");
667 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000668 va_end(args);
669}
670
671xmlSAXHandler debugSAXHandlerStruct = {
672 internalSubsetDebug,
673 isStandaloneDebug,
674 hasInternalSubsetDebug,
675 hasExternalSubsetDebug,
676 resolveEntityDebug,
677 getEntityDebug,
678 entityDeclDebug,
679 notationDeclDebug,
680 attributeDeclDebug,
681 elementDeclDebug,
682 unparsedEntityDeclDebug,
683 setDocumentLocatorDebug,
684 startDocumentDebug,
685 endDocumentDebug,
686 startElementDebug,
687 endElementDebug,
688 referenceDebug,
689 charactersDebug,
690 ignorableWhitespaceDebug,
691 processingInstructionDebug,
692 commentDebug,
693 warningDebug,
694 errorDebug,
695 fatalErrorDebug,
Daniel Veillardb05deb71999-08-10 19:04:08 +0000696 getParameterEntityDebug,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000697 cdataBlockDebug,
Daniel Veillardd0463562001-10-13 09:15:48 +0000698 externalSubsetDebug,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000699 1,
700 NULL,
701 NULL,
William M. Brack871611b2003-10-18 04:53:14 +0000702 NULL,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000703 NULL
Daniel Veillard5099ae81999-04-21 20:12:07 +0000704};
705
706xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
707
Daniel Veillard0fb18932003-09-07 09:14:37 +0000708/*
709 * SAX2 specific callbacks
710 */
711/**
Daniel Veillard07cb8222003-09-10 10:51:05 +0000712 * startElementNsDebug:
Daniel Veillard0fb18932003-09-07 09:14:37 +0000713 * @ctxt: An XML parser context
714 * @name: The element name
715 *
716 * called when an opening tag has been processed.
717 */
718static void
719startElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
720 const xmlChar *localname,
721 const xmlChar *prefix,
722 const xmlChar *URI,
723 int nb_namespaces,
724 const xmlChar **namespaces,
Daniel Veillard07cb8222003-09-10 10:51:05 +0000725 int nb_attributes,
726 int nb_defaulted,
727 const xmlChar **attributes)
Daniel Veillard0fb18932003-09-07 09:14:37 +0000728{
729 int i;
730
731 callbacks++;
732 if (quiet)
733 return;
734 fprintf(stdout, "SAX.startElementNs(%s", (char *) localname);
735 if (prefix == NULL)
736 fprintf(stdout, ", NULL");
737 else
738 fprintf(stdout, ", %s", (char *) prefix);
739 if (URI == NULL)
740 fprintf(stdout, ", NULL");
741 else
742 fprintf(stdout, ", '%s'", (char *) URI);
743 fprintf(stdout, ", %d", nb_namespaces);
744
745 if (namespaces != NULL) {
746 for (i = 0;i < nb_namespaces * 2;i++) {
747 fprintf(stdout, ", xmlns");
748 if (namespaces[i] != NULL)
749 fprintf(stdout, ":%s", namespaces[i]);
750 i++;
751 fprintf(stdout, "='%s'", namespaces[i]);
752 }
753 }
Daniel Veillard07cb8222003-09-10 10:51:05 +0000754 fprintf(stdout, ", %d, %d", nb_attributes, nb_defaulted);
755 if (attributes != NULL) {
756 for (i = 0;i < nb_attributes;i += 5) {
757 if (attributes[i + 1] != NULL)
758 fprintf(stdout, ", %s:%s='", attributes[i + 1], attributes[i]);
759 else
760 fprintf(stdout, ", %s='", attributes[i]);
761 fprintf(stdout, "%.4s...', %d", attributes[i + 3],
William M. Brack76e95df2003-10-18 16:20:14 +0000762 (int)(attributes[i + 4] - attributes[i + 3]));
Daniel Veillard07cb8222003-09-10 10:51:05 +0000763 }
764 }
765 fprintf(stdout, ")\n");
Daniel Veillard0fb18932003-09-07 09:14:37 +0000766}
767
768/**
769 * endElementDebug:
770 * @ctxt: An XML parser context
771 * @name: The element name
772 *
773 * called when the end of an element has been detected.
774 */
775static void
776endElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
777 const xmlChar *localname,
778 const xmlChar *prefix,
779 const xmlChar *URI)
780{
781 callbacks++;
782 if (quiet)
783 return;
784 fprintf(stdout, "SAX.endElementNs(%s", (char *) localname);
785 if (prefix == NULL)
786 fprintf(stdout, ", NULL");
787 else
788 fprintf(stdout, ", %s", (char *) prefix);
789 if (URI == NULL)
790 fprintf(stdout, ", NULL)\n");
791 else
792 fprintf(stdout, ", '%s')\n", (char *) URI);
793}
794
Daniel Veillard0fb18932003-09-07 09:14:37 +0000795xmlSAXHandler debugSAX2HandlerStruct = {
796 internalSubsetDebug,
797 isStandaloneDebug,
798 hasInternalSubsetDebug,
799 hasExternalSubsetDebug,
800 resolveEntityDebug,
801 getEntityDebug,
802 entityDeclDebug,
803 notationDeclDebug,
804 attributeDeclDebug,
805 elementDeclDebug,
806 unparsedEntityDeclDebug,
807 setDocumentLocatorDebug,
808 startDocumentDebug,
809 endDocumentDebug,
810 NULL,
811 NULL,
812 referenceDebug,
813 charactersDebug,
814 ignorableWhitespaceDebug,
815 processingInstructionDebug,
816 commentDebug,
817 warningDebug,
818 errorDebug,
819 fatalErrorDebug,
820 getParameterEntityDebug,
821 cdataBlockDebug,
822 externalSubsetDebug,
Daniel Veillard07cb8222003-09-10 10:51:05 +0000823 XML_SAX2_MAGIC,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000824 NULL,
825 startElementNsDebug,
William M. Brack871611b2003-10-18 04:53:14 +0000826 endElementNsDebug,
827 NULL
Daniel Veillard0fb18932003-09-07 09:14:37 +0000828};
829
830xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
831
Daniel Veillard5099ae81999-04-21 20:12:07 +0000832/************************************************************************
833 * *
834 * Debug *
835 * *
836 ************************************************************************/
837
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000838static void
839parseAndPrintFile(char *filename) {
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000840 int res;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000841
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000842 if (push) {
843 FILE *f;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000844
Daniel Veillard0fb18932003-09-07 09:14:37 +0000845 if ((!quiet) && (!nonull)) {
846 /*
847 * Empty callbacks for checking
848 */
849 f = fopen(filename, "r");
850 if (f != NULL) {
851 int ret;
852 char chars[10];
853 xmlParserCtxtPtr ctxt;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000854
Daniel Veillard0fb18932003-09-07 09:14:37 +0000855 ret = fread(chars, 1, 4, f);
856 if (ret > 0) {
857 ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL,
858 chars, ret, filename);
859 while ((ret = fread(chars, 1, 3, f)) > 0) {
860 xmlParseChunk(ctxt, chars, ret, 0);
861 }
862 xmlParseChunk(ctxt, chars, 0, 1);
863 xmlFreeParserCtxt(ctxt);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000864 }
Daniel Veillard0fb18932003-09-07 09:14:37 +0000865 fclose(f);
866 } else {
867 xmlGenericError(xmlGenericErrorContext,
868 "Cannot read file %s\n", filename);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000869 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000870 }
871 /*
872 * Debug callback
873 */
874 f = fopen(filename, "r");
875 if (f != NULL) {
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000876 int ret;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000877 char chars[10];
878 xmlParserCtxtPtr ctxt;
879
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000880 ret = fread(chars, 1, 4, f);
881 if (ret > 0) {
Daniel Veillard0fb18932003-09-07 09:14:37 +0000882 if (sax2)
883 ctxt = xmlCreatePushParserCtxt(debugSAX2Handler, NULL,
884 chars, ret, filename);
885 else
886 ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL,
887 chars, ret, filename);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000888 while ((ret = fread(chars, 1, 3, f)) > 0) {
889 xmlParseChunk(ctxt, chars, ret, 0);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000890 }
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000891 ret = xmlParseChunk(ctxt, chars, 0, 1);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000892 xmlFreeParserCtxt(ctxt);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000893 if (ret != 0) {
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000894 fprintf(stdout,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000895 "xmlSAXUserParseFile returned error %d\n", ret);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000896 }
897 }
898 fclose(f);
899 }
900 } else {
Daniel Veillard5e873c42000-04-12 13:27:38 +0000901 if (!speed) {
902 /*
903 * Empty callbacks for checking
904 */
Daniel Veillard0fb18932003-09-07 09:14:37 +0000905 if ((!quiet) && (!nonull)) {
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000906 res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
907 if (res != 0) {
908 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
909 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000910 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000911
Daniel Veillard5e873c42000-04-12 13:27:38 +0000912 /*
913 * Debug callback
914 */
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000915 callbacks = 0;
Daniel Veillard0fb18932003-09-07 09:14:37 +0000916 if (sax2)
917 res = xmlSAXUserParseFile(debugSAX2Handler, NULL, filename);
918 else
919 res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
Daniel Veillard5e873c42000-04-12 13:27:38 +0000920 if (res != 0) {
921 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
922 }
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000923 if (quiet)
924 fprintf(stdout, "%d callbacks generated\n", callbacks);
Daniel Veillard5e873c42000-04-12 13:27:38 +0000925 } else {
926 /*
927 * test 100x the SAX parse
928 */
929 int i;
930
931 for (i = 0; i<100;i++)
932 res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
933 if (res != 0) {
934 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
935 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000936 }
Daniel Veillard5099ae81999-04-21 20:12:07 +0000937 }
938}
939
Daniel Veillard5099ae81999-04-21 20:12:07 +0000940
941int main(int argc, char **argv) {
942 int i;
943 int files = 0;
944
945 for (i = 1; i < argc ; i++) {
946 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
947 debug++;
948 else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
949 copy++;
950 else if ((!strcmp(argv[i], "-recover")) ||
951 (!strcmp(argv[i], "--recover")))
952 recovery++;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000953 else if ((!strcmp(argv[i], "-push")) ||
954 (!strcmp(argv[i], "--push")))
955 push++;
Daniel Veillard5e873c42000-04-12 13:27:38 +0000956 else if ((!strcmp(argv[i], "-speed")) ||
957 (!strcmp(argv[i], "--speed")))
958 speed++;
Daniel Veillard5997aca2002-03-18 18:36:20 +0000959 else if ((!strcmp(argv[i], "-noent")) ||
960 (!strcmp(argv[i], "--noent")))
961 noent++;
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000962 else if ((!strcmp(argv[i], "-quiet")) ||
963 (!strcmp(argv[i], "--quiet")))
964 quiet++;
Daniel Veillard0fb18932003-09-07 09:14:37 +0000965 else if ((!strcmp(argv[i], "-sax2")) ||
966 (!strcmp(argv[i], "--sax2")))
967 sax2++;
968 else if ((!strcmp(argv[i], "-nonull")) ||
969 (!strcmp(argv[i], "--nonull")))
970 nonull++;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000971 }
Daniel Veillard5997aca2002-03-18 18:36:20 +0000972 if (noent != 0) xmlSubstituteEntitiesDefault(1);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000973 for (i = 1; i < argc ; i++) {
974 if (argv[i][0] != '-') {
975 parseAndPrintFile(argv[i]);
976 files ++;
977 }
978 }
Daniel Veillardf5c2c871999-12-01 09:51:45 +0000979 xmlCleanupParser();
980 xmlMemoryDump();
Daniel Veillard5099ae81999-04-21 20:12:07 +0000981
982 return(0);
983}
Daniel Veillard81273902003-09-30 00:43:48 +0000984#else
985int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
986 printf("%s : SAX1 parsing support not compiled in\n", argv[0]);
987 return(0);
988}
989#endif /* LIBXML_SAX1_ENABLED */