blob: 71686ea9772ae2226f647c8ac0a6206f058b4a63 [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 Veillard27d88741999-05-29 11:51:49 +0000560 fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000561 (char *) target, (char *) data);
562}
563
564/**
Daniel Veillardcf461992000-03-14 18:30:20 +0000565 * cdataBlockDebug:
566 * @ctx: the user data (XML parser context)
567 * @value: The pcdata content
568 * @len: the block length
569 *
570 * called when a pcdata block has been parsed
571 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000572static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000573cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len)
Daniel Veillardcf461992000-03-14 18:30:20 +0000574{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000575 callbacks++;
576 if (quiet)
577 return;
Daniel Veillard39915622000-10-15 10:06:55 +0000578 fprintf(stdout, "SAX.pcdata(%.20s, %d)\n",
Daniel Veillardcf461992000-03-14 18:30:20 +0000579 (char *) value, len);
580}
581
582/**
Daniel Veillard5099ae81999-04-21 20:12:07 +0000583 * commentDebug:
584 * @ctxt: An XML parser context
585 * @value: the comment content
586 *
587 * A comment has been parsed.
588 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000589static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000590commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000591{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000592 callbacks++;
593 if (quiet)
594 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000595 fprintf(stdout, "SAX.comment(%s)\n", value);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000596}
597
598/**
599 * warningDebug:
600 * @ctxt: An XML parser context
601 * @msg: the message to display/transmit
602 * @...: extra parameters for the message display
603 *
604 * Display and format a warning messages, gives file, line, position and
605 * extra parameters.
606 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000607static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000608warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000609{
610 va_list args;
611
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000612 callbacks++;
613 if (quiet)
614 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000615 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000616 fprintf(stdout, "SAX.warning: ");
617 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000618 va_end(args);
619}
620
621/**
622 * errorDebug:
623 * @ctxt: An XML parser context
624 * @msg: the message to display/transmit
625 * @...: extra parameters for the message display
626 *
627 * Display and format a error messages, gives file, line, position and
628 * extra parameters.
629 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000630static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000631errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000632{
633 va_list args;
634
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000635 callbacks++;
636 if (quiet)
637 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000638 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000639 fprintf(stdout, "SAX.error: ");
640 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000641 va_end(args);
642}
643
644/**
645 * fatalErrorDebug:
646 * @ctxt: An XML parser context
647 * @msg: the message to display/transmit
648 * @...: extra parameters for the message display
649 *
650 * Display and format a fatalError messages, gives file, line, position and
651 * extra parameters.
652 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000653static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000654fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000655{
656 va_list args;
657
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000658 callbacks++;
659 if (quiet)
660 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000661 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000662 fprintf(stdout, "SAX.fatalError: ");
663 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000664 va_end(args);
665}
666
667xmlSAXHandler debugSAXHandlerStruct = {
668 internalSubsetDebug,
669 isStandaloneDebug,
670 hasInternalSubsetDebug,
671 hasExternalSubsetDebug,
672 resolveEntityDebug,
673 getEntityDebug,
674 entityDeclDebug,
675 notationDeclDebug,
676 attributeDeclDebug,
677 elementDeclDebug,
678 unparsedEntityDeclDebug,
679 setDocumentLocatorDebug,
680 startDocumentDebug,
681 endDocumentDebug,
682 startElementDebug,
683 endElementDebug,
684 referenceDebug,
685 charactersDebug,
686 ignorableWhitespaceDebug,
687 processingInstructionDebug,
688 commentDebug,
689 warningDebug,
690 errorDebug,
691 fatalErrorDebug,
Daniel Veillardb05deb71999-08-10 19:04:08 +0000692 getParameterEntityDebug,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000693 cdataBlockDebug,
Daniel Veillardd0463562001-10-13 09:15:48 +0000694 externalSubsetDebug,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000695 1,
696 NULL,
697 NULL,
William M. Brack871611b2003-10-18 04:53:14 +0000698 NULL,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000699 NULL
Daniel Veillard5099ae81999-04-21 20:12:07 +0000700};
701
702xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
703
Daniel Veillard0fb18932003-09-07 09:14:37 +0000704/*
705 * SAX2 specific callbacks
706 */
707/**
Daniel Veillard07cb8222003-09-10 10:51:05 +0000708 * startElementNsDebug:
Daniel Veillard0fb18932003-09-07 09:14:37 +0000709 * @ctxt: An XML parser context
710 * @name: The element name
711 *
712 * called when an opening tag has been processed.
713 */
714static void
715startElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
716 const xmlChar *localname,
717 const xmlChar *prefix,
718 const xmlChar *URI,
719 int nb_namespaces,
720 const xmlChar **namespaces,
Daniel Veillard07cb8222003-09-10 10:51:05 +0000721 int nb_attributes,
722 int nb_defaulted,
723 const xmlChar **attributes)
Daniel Veillard0fb18932003-09-07 09:14:37 +0000724{
725 int i;
726
727 callbacks++;
728 if (quiet)
729 return;
730 fprintf(stdout, "SAX.startElementNs(%s", (char *) localname);
731 if (prefix == NULL)
732 fprintf(stdout, ", NULL");
733 else
734 fprintf(stdout, ", %s", (char *) prefix);
735 if (URI == NULL)
736 fprintf(stdout, ", NULL");
737 else
738 fprintf(stdout, ", '%s'", (char *) URI);
739 fprintf(stdout, ", %d", nb_namespaces);
740
741 if (namespaces != NULL) {
742 for (i = 0;i < nb_namespaces * 2;i++) {
743 fprintf(stdout, ", xmlns");
744 if (namespaces[i] != NULL)
745 fprintf(stdout, ":%s", namespaces[i]);
746 i++;
747 fprintf(stdout, "='%s'", namespaces[i]);
748 }
749 }
Daniel Veillard07cb8222003-09-10 10:51:05 +0000750 fprintf(stdout, ", %d, %d", nb_attributes, nb_defaulted);
751 if (attributes != NULL) {
752 for (i = 0;i < nb_attributes;i += 5) {
753 if (attributes[i + 1] != NULL)
754 fprintf(stdout, ", %s:%s='", attributes[i + 1], attributes[i]);
755 else
756 fprintf(stdout, ", %s='", attributes[i]);
757 fprintf(stdout, "%.4s...', %d", attributes[i + 3],
William M. Brack76e95df2003-10-18 16:20:14 +0000758 (int)(attributes[i + 4] - attributes[i + 3]));
Daniel Veillard07cb8222003-09-10 10:51:05 +0000759 }
760 }
761 fprintf(stdout, ")\n");
Daniel Veillard0fb18932003-09-07 09:14:37 +0000762}
763
764/**
765 * endElementDebug:
766 * @ctxt: An XML parser context
767 * @name: The element name
768 *
769 * called when the end of an element has been detected.
770 */
771static void
772endElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
773 const xmlChar *localname,
774 const xmlChar *prefix,
775 const xmlChar *URI)
776{
777 callbacks++;
778 if (quiet)
779 return;
780 fprintf(stdout, "SAX.endElementNs(%s", (char *) localname);
781 if (prefix == NULL)
782 fprintf(stdout, ", NULL");
783 else
784 fprintf(stdout, ", %s", (char *) prefix);
785 if (URI == NULL)
786 fprintf(stdout, ", NULL)\n");
787 else
788 fprintf(stdout, ", '%s')\n", (char *) URI);
789}
790
Daniel Veillard0fb18932003-09-07 09:14:37 +0000791xmlSAXHandler debugSAX2HandlerStruct = {
792 internalSubsetDebug,
793 isStandaloneDebug,
794 hasInternalSubsetDebug,
795 hasExternalSubsetDebug,
796 resolveEntityDebug,
797 getEntityDebug,
798 entityDeclDebug,
799 notationDeclDebug,
800 attributeDeclDebug,
801 elementDeclDebug,
802 unparsedEntityDeclDebug,
803 setDocumentLocatorDebug,
804 startDocumentDebug,
805 endDocumentDebug,
806 NULL,
807 NULL,
808 referenceDebug,
809 charactersDebug,
810 ignorableWhitespaceDebug,
811 processingInstructionDebug,
812 commentDebug,
813 warningDebug,
814 errorDebug,
815 fatalErrorDebug,
816 getParameterEntityDebug,
817 cdataBlockDebug,
818 externalSubsetDebug,
Daniel Veillard07cb8222003-09-10 10:51:05 +0000819 XML_SAX2_MAGIC,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000820 NULL,
821 startElementNsDebug,
William M. Brack871611b2003-10-18 04:53:14 +0000822 endElementNsDebug,
823 NULL
Daniel Veillard0fb18932003-09-07 09:14:37 +0000824};
825
826xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
827
Daniel Veillard5099ae81999-04-21 20:12:07 +0000828/************************************************************************
829 * *
830 * Debug *
831 * *
832 ************************************************************************/
833
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000834static void
835parseAndPrintFile(char *filename) {
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000836 int res;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000837
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000838 if (push) {
839 FILE *f;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000840
Daniel Veillard0fb18932003-09-07 09:14:37 +0000841 if ((!quiet) && (!nonull)) {
842 /*
843 * Empty callbacks for checking
844 */
845 f = fopen(filename, "r");
846 if (f != NULL) {
847 int ret;
848 char chars[10];
849 xmlParserCtxtPtr ctxt;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000850
Daniel Veillard0fb18932003-09-07 09:14:37 +0000851 ret = fread(chars, 1, 4, f);
852 if (ret > 0) {
853 ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL,
854 chars, ret, filename);
855 while ((ret = fread(chars, 1, 3, f)) > 0) {
856 xmlParseChunk(ctxt, chars, ret, 0);
857 }
858 xmlParseChunk(ctxt, chars, 0, 1);
859 xmlFreeParserCtxt(ctxt);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000860 }
Daniel Veillard0fb18932003-09-07 09:14:37 +0000861 fclose(f);
862 } else {
863 xmlGenericError(xmlGenericErrorContext,
864 "Cannot read file %s\n", filename);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000865 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000866 }
867 /*
868 * Debug callback
869 */
870 f = fopen(filename, "r");
871 if (f != NULL) {
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000872 int ret;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000873 char chars[10];
874 xmlParserCtxtPtr ctxt;
875
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000876 ret = fread(chars, 1, 4, f);
877 if (ret > 0) {
Daniel Veillard0fb18932003-09-07 09:14:37 +0000878 if (sax2)
879 ctxt = xmlCreatePushParserCtxt(debugSAX2Handler, NULL,
880 chars, ret, filename);
881 else
882 ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL,
883 chars, ret, filename);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000884 while ((ret = fread(chars, 1, 3, f)) > 0) {
885 xmlParseChunk(ctxt, chars, ret, 0);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000886 }
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000887 ret = xmlParseChunk(ctxt, chars, 0, 1);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000888 xmlFreeParserCtxt(ctxt);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000889 if (ret != 0) {
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000890 fprintf(stdout,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000891 "xmlSAXUserParseFile returned error %d\n", ret);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000892 }
893 }
894 fclose(f);
895 }
896 } else {
Daniel Veillard5e873c42000-04-12 13:27:38 +0000897 if (!speed) {
898 /*
899 * Empty callbacks for checking
900 */
Daniel Veillard0fb18932003-09-07 09:14:37 +0000901 if ((!quiet) && (!nonull)) {
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000902 res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
903 if (res != 0) {
904 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
905 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000906 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000907
Daniel Veillard5e873c42000-04-12 13:27:38 +0000908 /*
909 * Debug callback
910 */
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000911 callbacks = 0;
Daniel Veillard0fb18932003-09-07 09:14:37 +0000912 if (sax2)
913 res = xmlSAXUserParseFile(debugSAX2Handler, NULL, filename);
914 else
915 res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
Daniel Veillard5e873c42000-04-12 13:27:38 +0000916 if (res != 0) {
917 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
918 }
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000919 if (quiet)
920 fprintf(stdout, "%d callbacks generated\n", callbacks);
Daniel Veillard5e873c42000-04-12 13:27:38 +0000921 } else {
922 /*
923 * test 100x the SAX parse
924 */
925 int i;
926
927 for (i = 0; i<100;i++)
928 res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
929 if (res != 0) {
930 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
931 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000932 }
Daniel Veillard5099ae81999-04-21 20:12:07 +0000933 }
934}
935
Daniel Veillard5099ae81999-04-21 20:12:07 +0000936
937int main(int argc, char **argv) {
938 int i;
939 int files = 0;
940
941 for (i = 1; i < argc ; i++) {
942 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
943 debug++;
944 else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
945 copy++;
946 else if ((!strcmp(argv[i], "-recover")) ||
947 (!strcmp(argv[i], "--recover")))
948 recovery++;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000949 else if ((!strcmp(argv[i], "-push")) ||
950 (!strcmp(argv[i], "--push")))
951 push++;
Daniel Veillard5e873c42000-04-12 13:27:38 +0000952 else if ((!strcmp(argv[i], "-speed")) ||
953 (!strcmp(argv[i], "--speed")))
954 speed++;
Daniel Veillard5997aca2002-03-18 18:36:20 +0000955 else if ((!strcmp(argv[i], "-noent")) ||
956 (!strcmp(argv[i], "--noent")))
957 noent++;
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000958 else if ((!strcmp(argv[i], "-quiet")) ||
959 (!strcmp(argv[i], "--quiet")))
960 quiet++;
Daniel Veillard0fb18932003-09-07 09:14:37 +0000961 else if ((!strcmp(argv[i], "-sax2")) ||
962 (!strcmp(argv[i], "--sax2")))
963 sax2++;
964 else if ((!strcmp(argv[i], "-nonull")) ||
965 (!strcmp(argv[i], "--nonull")))
966 nonull++;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000967 }
Daniel Veillard5997aca2002-03-18 18:36:20 +0000968 if (noent != 0) xmlSubstituteEntitiesDefault(1);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000969 for (i = 1; i < argc ; i++) {
970 if (argv[i][0] != '-') {
971 parseAndPrintFile(argv[i]);
972 files ++;
973 }
974 }
Daniel Veillardf5c2c871999-12-01 09:51:45 +0000975 xmlCleanupParser();
976 xmlMemoryDump();
Daniel Veillard5099ae81999-04-21 20:12:07 +0000977
978 return(0);
979}
Daniel Veillard81273902003-09-30 00:43:48 +0000980#else
981int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
982 printf("%s : SAX1 parsing support not compiled in\n", argv[0]);
983 return(0);
984}
985#endif /* LIBXML_SAX1_ENABLED */