blob: 4f00c53e41ea9252ea70acdb63dcd62e3abeb10c [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 Veillard4773df22004-01-23 13:15:13 +000052static int repeat = 0;
Daniel Veillarde50f3b52002-03-20 19:24:21 +000053static int callbacks = 0;
Daniel Veillard5099ae81999-04-21 20:12:07 +000054
55xmlSAXHandler emptySAXHandlerStruct = {
56 NULL, /* internalSubset */
57 NULL, /* isStandalone */
58 NULL, /* hasInternalSubset */
59 NULL, /* hasExternalSubset */
60 NULL, /* resolveEntity */
61 NULL, /* getEntity */
62 NULL, /* entityDecl */
63 NULL, /* notationDecl */
64 NULL, /* attributeDecl */
65 NULL, /* elementDecl */
66 NULL, /* unparsedEntityDecl */
67 NULL, /* setDocumentLocator */
68 NULL, /* startDocument */
69 NULL, /* endDocument */
70 NULL, /* startElement */
71 NULL, /* endElement */
72 NULL, /* reference */
73 NULL, /* characters */
74 NULL, /* ignorableWhitespace */
75 NULL, /* processingInstruction */
76 NULL, /* comment */
77 NULL, /* xmlParserWarning */
78 NULL, /* xmlParserError */
79 NULL, /* xmlParserError */
Daniel Veillardb05deb71999-08-10 19:04:08 +000080 NULL, /* getParameterEntity */
Daniel Veillardcf461992000-03-14 18:30:20 +000081 NULL, /* cdataBlock; */
Daniel Veillard0fb18932003-09-07 09:14:37 +000082 NULL, /* externalSubset; */
83 1,
84 NULL,
85 NULL, /* startElementNs */
William M. Brack871611b2003-10-18 04:53:14 +000086 NULL, /* endElementNs */
87 NULL /* xmlStructuredErrorFunc */
Daniel Veillard5099ae81999-04-21 20:12:07 +000088};
89
90xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
Daniel Veillard011b63c1999-06-02 17:44:04 +000091extern xmlSAXHandlerPtr debugSAXHandler;
Daniel Veillard5099ae81999-04-21 20:12:07 +000092
Daniel Veillard5099ae81999-04-21 20:12:07 +000093/************************************************************************
94 * *
95 * Debug Handlers *
96 * *
97 ************************************************************************/
98
99/**
100 * isStandaloneDebug:
101 * @ctxt: An XML parser context
102 *
103 * Is this document tagged standalone ?
104 *
105 * Returns 1 if true
106 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000107static int
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000108isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000109{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000110 callbacks++;
111 if (quiet)
112 return(0);
Daniel Veillard27d88741999-05-29 11:51:49 +0000113 fprintf(stdout, "SAX.isStandalone()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000114 return(0);
115}
116
117/**
118 * hasInternalSubsetDebug:
119 * @ctxt: An XML parser context
120 *
121 * Does this document has an internal subset
122 *
123 * Returns 1 if true
124 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000125static int
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000126hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000127{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000128 callbacks++;
129 if (quiet)
130 return(0);
Daniel Veillard27d88741999-05-29 11:51:49 +0000131 fprintf(stdout, "SAX.hasInternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000132 return(0);
133}
134
135/**
136 * hasExternalSubsetDebug:
137 * @ctxt: An XML parser context
138 *
139 * Does this document has an external subset
140 *
141 * Returns 1 if true
142 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000143static int
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000144hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000145{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000146 callbacks++;
147 if (quiet)
148 return(0);
Daniel Veillard27d88741999-05-29 11:51:49 +0000149 fprintf(stdout, "SAX.hasExternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000150 return(0);
151}
152
153/**
Daniel Veillard06047432000-04-24 11:33:38 +0000154 * internalSubsetDebug:
Daniel Veillard5099ae81999-04-21 20:12:07 +0000155 * @ctxt: An XML parser context
156 *
157 * Does this document has an internal subset
158 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000159static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000160internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000161 const xmlChar *ExternalID, const xmlChar *SystemID)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000162{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000163 callbacks++;
164 if (quiet)
165 return;
Daniel Veillard808a3f12000-08-17 13:50:51 +0000166 fprintf(stdout, "SAX.internalSubset(%s,", name);
167 if (ExternalID == NULL)
168 fprintf(stdout, " ,");
169 else
170 fprintf(stdout, " %s,", ExternalID);
171 if (SystemID == NULL)
172 fprintf(stdout, " )\n");
173 else
174 fprintf(stdout, " %s)\n", SystemID);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000175}
176
177/**
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000178 * externalSubsetDebug:
179 * @ctxt: An XML parser context
180 *
181 * Does this document has an external subset
182 */
183static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000184externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000185 const xmlChar *ExternalID, const xmlChar *SystemID)
186{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000187 callbacks++;
188 if (quiet)
189 return;
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000190 fprintf(stdout, "SAX.externalSubset(%s,", name);
191 if (ExternalID == NULL)
192 fprintf(stdout, " ,");
193 else
194 fprintf(stdout, " %s,", ExternalID);
195 if (SystemID == NULL)
196 fprintf(stdout, " )\n");
197 else
198 fprintf(stdout, " %s)\n", SystemID);
199}
200
201/**
Daniel Veillard5099ae81999-04-21 20:12:07 +0000202 * resolveEntityDebug:
203 * @ctxt: An XML parser context
204 * @publicId: The public ID of the entity
205 * @systemId: The system ID of the entity
206 *
207 * Special entity resolver, better left to the parser, it has
208 * more context than the application layer.
209 * The default behaviour is to NOT resolve the entities, in that case
210 * the ENTITY_REF nodes are built in the structure (and the parameter
211 * values).
212 *
213 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
214 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000215static xmlParserInputPtr
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000216resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000217{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000218 callbacks++;
219 if (quiet)
220 return(NULL);
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000221 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000222
Daniel Veillard14fff061999-06-22 21:49:07 +0000223
224 fprintf(stdout, "SAX.resolveEntity(");
225 if (publicId != NULL)
226 fprintf(stdout, "%s", (char *)publicId);
227 else
228 fprintf(stdout, " ");
229 if (systemId != NULL)
230 fprintf(stdout, ", %s)\n", (char *)systemId);
231 else
232 fprintf(stdout, ", )\n");
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000233/*********
Daniel Veillard011b63c1999-06-02 17:44:04 +0000234 if (systemId != NULL) {
Daniel Veillardb96e6431999-08-29 21:02:19 +0000235 return(xmlNewInputFromFile(ctxt, (char *) systemId));
Daniel Veillard011b63c1999-06-02 17:44:04 +0000236 }
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000237 *********/
Daniel Veillard5099ae81999-04-21 20:12:07 +0000238 return(NULL);
239}
240
241/**
242 * getEntityDebug:
243 * @ctxt: An XML parser context
244 * @name: The entity name
245 *
246 * Get an entity by name
247 *
248 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
249 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000250static xmlEntityPtr
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000251getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000252{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000253 callbacks++;
254 if (quiet)
255 return(NULL);
Daniel Veillard27d88741999-05-29 11:51:49 +0000256 fprintf(stdout, "SAX.getEntity(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000257 return(NULL);
258}
259
Daniel Veillardb05deb71999-08-10 19:04:08 +0000260/**
261 * getParameterEntityDebug:
262 * @ctxt: An XML parser context
263 * @name: The entity name
264 *
265 * Get a parameter entity by name
266 *
267 * Returns the xmlParserInputPtr
268 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000269static xmlEntityPtr
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000270getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillardb05deb71999-08-10 19:04:08 +0000271{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000272 callbacks++;
273 if (quiet)
274 return(NULL);
Daniel Veillardb05deb71999-08-10 19:04:08 +0000275 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
276 return(NULL);
277}
278
Daniel Veillard5099ae81999-04-21 20:12:07 +0000279
280/**
281 * entityDeclDebug:
282 * @ctxt: An XML parser context
283 * @name: the entity name
284 * @type: the entity type
285 * @publicId: The public ID of the entity
286 * @systemId: The system ID of the entity
287 * @content: the entity value (without processing).
288 *
289 * An entity definition has been parsed
290 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000291static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000292entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000293 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000294{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000295 callbacks++;
296 if (quiet)
297 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000298 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000299 name, type, publicId, systemId, content);
300}
301
302/**
303 * attributeDeclDebug:
304 * @ctxt: An XML parser context
305 * @name: the attribute name
306 * @type: the attribute type
307 *
308 * An attribute definition has been parsed
309 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000310static void
Daniel Veillard07cb8222003-09-10 10:51:05 +0000311attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar * elem,
312 const xmlChar * name, int type, int def,
313 const xmlChar * defaultValue, xmlEnumerationPtr tree)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000314{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000315 callbacks++;
316 if (quiet)
Daniel Veillard07cb8222003-09-10 10:51:05 +0000317 return;
Daniel Veillard7e99c632000-10-06 12:59:53 +0000318 if (defaultValue == NULL)
Daniel Veillard07cb8222003-09-10 10:51:05 +0000319 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n",
320 elem, name, type, def);
Daniel Veillard7e99c632000-10-06 12:59:53 +0000321 else
Daniel Veillard07cb8222003-09-10 10:51:05 +0000322 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
323 elem, name, type, def, defaultValue);
324 xmlFreeEnumeration(tree);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000325}
326
327/**
328 * elementDeclDebug:
329 * @ctxt: An XML parser context
330 * @name: the element name
331 * @type: the element type
332 * @content: the element value (without processing).
333 *
334 * An element definition has been parsed
335 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000336static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000337elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
338 xmlElementContentPtr content ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000339{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000340 callbacks++;
341 if (quiet)
342 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000343 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000344 name, type);
345}
346
347/**
348 * notationDeclDebug:
349 * @ctxt: An XML parser context
350 * @name: The name of the notation
351 * @publicId: The public ID of the entity
352 * @systemId: The system ID of the entity
353 *
354 * What to do when a notation declaration has been parsed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000355 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000356static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000357notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000358 const xmlChar *publicId, const xmlChar *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000359{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000360 callbacks++;
361 if (quiet)
362 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000363 fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000364 (char *) name, (char *) publicId, (char *) systemId);
365}
366
367/**
368 * unparsedEntityDeclDebug:
369 * @ctxt: An XML parser context
370 * @name: The name of the entity
371 * @publicId: The public ID of the entity
372 * @systemId: The system ID of the entity
373 * @notationName: the name of the notation
374 *
375 * What to do when an unparsed entity declaration is parsed
Daniel Veillard5099ae81999-04-21 20:12:07 +0000376 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000377static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000378unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000379 const xmlChar *publicId, const xmlChar *systemId,
380 const xmlChar *notationName)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000381{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000382 callbacks++;
383 if (quiet)
384 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000385 fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000386 (char *) name, (char *) publicId, (char *) systemId,
387 (char *) notationName);
388}
389
390/**
391 * setDocumentLocatorDebug:
392 * @ctxt: An XML parser context
393 * @loc: A SAX Locator
394 *
395 * Receive the document locator at startup, actually xmlDefaultSAXLocator
396 * Everything is available on the context, so this is useless in our case.
397 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000398static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000399setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000400{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000401 callbacks++;
402 if (quiet)
403 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000404 fprintf(stdout, "SAX.setDocumentLocator()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000405}
406
407/**
408 * startDocumentDebug:
409 * @ctxt: An XML parser context
410 *
411 * called when the document start being processed.
412 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000413static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000414startDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000415{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000416 callbacks++;
417 if (quiet)
418 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000419 fprintf(stdout, "SAX.startDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000420}
421
422/**
423 * endDocumentDebug:
424 * @ctxt: An XML parser context
425 *
426 * called when the document end has been detected.
427 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000428static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000429endDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000430{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000431 callbacks++;
432 if (quiet)
433 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000434 fprintf(stdout, "SAX.endDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000435}
436
437/**
438 * startElementDebug:
439 * @ctxt: An XML parser context
440 * @name: The element name
441 *
442 * called when an opening tag has been processed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000443 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000444static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000445startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000446{
447 int i;
448
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000449 callbacks++;
450 if (quiet)
451 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000452 fprintf(stdout, "SAX.startElement(%s", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000453 if (atts != NULL) {
454 for (i = 0;(atts[i] != NULL);i++) {
Daniel Veillard27d88741999-05-29 11:51:49 +0000455 fprintf(stdout, ", %s='", atts[i++]);
Daniel Veillard808a3f12000-08-17 13:50:51 +0000456 if (atts[i] != NULL)
457 fprintf(stdout, "%s'", atts[i]);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000458 }
459 }
Daniel Veillard27d88741999-05-29 11:51:49 +0000460 fprintf(stdout, ")\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000461}
462
463/**
464 * endElementDebug:
465 * @ctxt: An XML parser context
466 * @name: The element name
467 *
468 * called when the end of an element has been detected.
469 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000470static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000471endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000472{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000473 callbacks++;
474 if (quiet)
475 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000476 fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000477}
478
479/**
480 * charactersDebug:
481 * @ctxt: An XML parser context
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000482 * @ch: a xmlChar string
483 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000484 *
485 * receiving some chars from the parser.
486 * Question: how much at a time ???
487 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000488static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000489charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000490{
Daniel Veillard87b95392000-08-12 21:12:04 +0000491 char output[40];
Daniel Veillarde2d034d1999-07-27 19:52:06 +0000492 int i;
493
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000494 callbacks++;
495 if (quiet)
496 return;
Daniel Veillard87b95392000-08-12 21:12:04 +0000497 for (i = 0;(i<len) && (i < 30);i++)
498 output[i] = ch[i];
499 output[i] = 0;
500
501 fprintf(stdout, "SAX.characters(%s, %d)\n", output, len);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000502}
503
504/**
505 * referenceDebug:
506 * @ctxt: An XML parser context
507 * @name: The entity name
508 *
509 * called when an entity reference is detected.
510 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000511static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000512referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000513{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000514 callbacks++;
515 if (quiet)
516 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000517 fprintf(stdout, "SAX.reference(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000518}
519
520/**
521 * ignorableWhitespaceDebug:
522 * @ctxt: An XML parser context
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000523 * @ch: a xmlChar string
Daniel Veillard5099ae81999-04-21 20:12:07 +0000524 * @start: the first char in the string
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000525 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000526 *
527 * receiving some ignorable whitespaces from the parser.
528 * Question: how much at a time ???
529 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000530static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000531ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000532{
Daniel Veillard87b95392000-08-12 21:12:04 +0000533 char output[40];
534 int i;
535
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000536 callbacks++;
537 if (quiet)
538 return;
Daniel Veillard87b95392000-08-12 21:12:04 +0000539 for (i = 0;(i<len) && (i < 30);i++)
540 output[i] = ch[i];
541 output[i] = 0;
542 fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000543}
544
545/**
546 * processingInstructionDebug:
547 * @ctxt: An XML parser context
548 * @target: the target name
549 * @data: the PI data's
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000550 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000551 *
552 * A processing instruction has been parsed.
553 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000554static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000555processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000556 const xmlChar *data)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000557{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000558 callbacks++;
559 if (quiet)
560 return;
Daniel Veillard4772af62003-10-27 16:23:43 +0000561 if (data != NULL)
562 fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
563 (char *) target, (char *) data);
564 else
565 fprintf(stdout, "SAX.processingInstruction(%s, NULL)\n",
566 (char *) target);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000567}
568
569/**
Daniel Veillardcf461992000-03-14 18:30:20 +0000570 * cdataBlockDebug:
571 * @ctx: the user data (XML parser context)
572 * @value: The pcdata content
573 * @len: the block length
574 *
575 * called when a pcdata block has been parsed
576 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000577static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000578cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len)
Daniel Veillardcf461992000-03-14 18:30:20 +0000579{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000580 callbacks++;
581 if (quiet)
582 return;
Daniel Veillard39915622000-10-15 10:06:55 +0000583 fprintf(stdout, "SAX.pcdata(%.20s, %d)\n",
Daniel Veillardcf461992000-03-14 18:30:20 +0000584 (char *) value, len);
585}
586
587/**
Daniel Veillard5099ae81999-04-21 20:12:07 +0000588 * commentDebug:
589 * @ctxt: An XML parser context
590 * @value: the comment content
591 *
592 * A comment has been parsed.
593 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000594static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000595commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000596{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000597 callbacks++;
598 if (quiet)
599 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000600 fprintf(stdout, "SAX.comment(%s)\n", value);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000601}
602
603/**
604 * warningDebug:
605 * @ctxt: An XML parser context
606 * @msg: the message to display/transmit
607 * @...: extra parameters for the message display
608 *
609 * Display and format a warning messages, gives file, line, position and
610 * extra parameters.
611 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000612static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000613warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000614{
615 va_list args;
616
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000617 callbacks++;
618 if (quiet)
619 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000620 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000621 fprintf(stdout, "SAX.warning: ");
622 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000623 va_end(args);
624}
625
626/**
627 * errorDebug:
628 * @ctxt: An XML parser context
629 * @msg: the message to display/transmit
630 * @...: extra parameters for the message display
631 *
632 * Display and format a error messages, gives file, line, position and
633 * extra parameters.
634 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000635static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000636errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000637{
638 va_list args;
639
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000640 callbacks++;
641 if (quiet)
642 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000643 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000644 fprintf(stdout, "SAX.error: ");
645 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000646 va_end(args);
647}
648
649/**
650 * fatalErrorDebug:
651 * @ctxt: An XML parser context
652 * @msg: the message to display/transmit
653 * @...: extra parameters for the message display
654 *
655 * Display and format a fatalError messages, gives file, line, position and
656 * extra parameters.
657 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000658static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000659fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000660{
661 va_list args;
662
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000663 callbacks++;
664 if (quiet)
665 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000666 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000667 fprintf(stdout, "SAX.fatalError: ");
668 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000669 va_end(args);
670}
671
672xmlSAXHandler debugSAXHandlerStruct = {
673 internalSubsetDebug,
674 isStandaloneDebug,
675 hasInternalSubsetDebug,
676 hasExternalSubsetDebug,
677 resolveEntityDebug,
678 getEntityDebug,
679 entityDeclDebug,
680 notationDeclDebug,
681 attributeDeclDebug,
682 elementDeclDebug,
683 unparsedEntityDeclDebug,
684 setDocumentLocatorDebug,
685 startDocumentDebug,
686 endDocumentDebug,
687 startElementDebug,
688 endElementDebug,
689 referenceDebug,
690 charactersDebug,
691 ignorableWhitespaceDebug,
692 processingInstructionDebug,
693 commentDebug,
694 warningDebug,
695 errorDebug,
696 fatalErrorDebug,
Daniel Veillardb05deb71999-08-10 19:04:08 +0000697 getParameterEntityDebug,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000698 cdataBlockDebug,
Daniel Veillardd0463562001-10-13 09:15:48 +0000699 externalSubsetDebug,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000700 1,
701 NULL,
702 NULL,
William M. Brack871611b2003-10-18 04:53:14 +0000703 NULL,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000704 NULL
Daniel Veillard5099ae81999-04-21 20:12:07 +0000705};
706
707xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
708
Daniel Veillard0fb18932003-09-07 09:14:37 +0000709/*
710 * SAX2 specific callbacks
711 */
712/**
Daniel Veillard07cb8222003-09-10 10:51:05 +0000713 * startElementNsDebug:
Daniel Veillard0fb18932003-09-07 09:14:37 +0000714 * @ctxt: An XML parser context
715 * @name: The element name
716 *
717 * called when an opening tag has been processed.
718 */
719static void
720startElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
721 const xmlChar *localname,
722 const xmlChar *prefix,
723 const xmlChar *URI,
724 int nb_namespaces,
725 const xmlChar **namespaces,
Daniel Veillard07cb8222003-09-10 10:51:05 +0000726 int nb_attributes,
727 int nb_defaulted,
728 const xmlChar **attributes)
Daniel Veillard0fb18932003-09-07 09:14:37 +0000729{
730 int i;
731
732 callbacks++;
733 if (quiet)
734 return;
735 fprintf(stdout, "SAX.startElementNs(%s", (char *) localname);
736 if (prefix == NULL)
737 fprintf(stdout, ", NULL");
738 else
739 fprintf(stdout, ", %s", (char *) prefix);
740 if (URI == NULL)
741 fprintf(stdout, ", NULL");
742 else
743 fprintf(stdout, ", '%s'", (char *) URI);
744 fprintf(stdout, ", %d", nb_namespaces);
745
746 if (namespaces != NULL) {
747 for (i = 0;i < nb_namespaces * 2;i++) {
748 fprintf(stdout, ", xmlns");
749 if (namespaces[i] != NULL)
750 fprintf(stdout, ":%s", namespaces[i]);
751 i++;
752 fprintf(stdout, "='%s'", namespaces[i]);
753 }
754 }
Daniel Veillard07cb8222003-09-10 10:51:05 +0000755 fprintf(stdout, ", %d, %d", nb_attributes, nb_defaulted);
756 if (attributes != NULL) {
757 for (i = 0;i < nb_attributes;i += 5) {
758 if (attributes[i + 1] != NULL)
759 fprintf(stdout, ", %s:%s='", attributes[i + 1], attributes[i]);
760 else
761 fprintf(stdout, ", %s='", attributes[i]);
762 fprintf(stdout, "%.4s...', %d", attributes[i + 3],
William M. Brack76e95df2003-10-18 16:20:14 +0000763 (int)(attributes[i + 4] - attributes[i + 3]));
Daniel Veillard07cb8222003-09-10 10:51:05 +0000764 }
765 }
766 fprintf(stdout, ")\n");
Daniel Veillard0fb18932003-09-07 09:14:37 +0000767}
768
769/**
770 * endElementDebug:
771 * @ctxt: An XML parser context
772 * @name: The element name
773 *
774 * called when the end of an element has been detected.
775 */
776static void
777endElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
778 const xmlChar *localname,
779 const xmlChar *prefix,
780 const xmlChar *URI)
781{
782 callbacks++;
783 if (quiet)
784 return;
785 fprintf(stdout, "SAX.endElementNs(%s", (char *) localname);
786 if (prefix == NULL)
787 fprintf(stdout, ", NULL");
788 else
789 fprintf(stdout, ", %s", (char *) prefix);
790 if (URI == NULL)
791 fprintf(stdout, ", NULL)\n");
792 else
793 fprintf(stdout, ", '%s')\n", (char *) URI);
794}
795
Daniel Veillard0fb18932003-09-07 09:14:37 +0000796xmlSAXHandler debugSAX2HandlerStruct = {
797 internalSubsetDebug,
798 isStandaloneDebug,
799 hasInternalSubsetDebug,
800 hasExternalSubsetDebug,
801 resolveEntityDebug,
802 getEntityDebug,
803 entityDeclDebug,
804 notationDeclDebug,
805 attributeDeclDebug,
806 elementDeclDebug,
807 unparsedEntityDeclDebug,
808 setDocumentLocatorDebug,
809 startDocumentDebug,
810 endDocumentDebug,
811 NULL,
812 NULL,
813 referenceDebug,
814 charactersDebug,
815 ignorableWhitespaceDebug,
816 processingInstructionDebug,
817 commentDebug,
818 warningDebug,
819 errorDebug,
820 fatalErrorDebug,
821 getParameterEntityDebug,
822 cdataBlockDebug,
823 externalSubsetDebug,
Daniel Veillard07cb8222003-09-10 10:51:05 +0000824 XML_SAX2_MAGIC,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000825 NULL,
826 startElementNsDebug,
William M. Brack871611b2003-10-18 04:53:14 +0000827 endElementNsDebug,
828 NULL
Daniel Veillard0fb18932003-09-07 09:14:37 +0000829};
830
831xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
832
Daniel Veillard5099ae81999-04-21 20:12:07 +0000833/************************************************************************
834 * *
835 * Debug *
836 * *
837 ************************************************************************/
838
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000839static void
840parseAndPrintFile(char *filename) {
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000841 int res;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000842
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000843 if (push) {
844 FILE *f;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000845
Daniel Veillard0fb18932003-09-07 09:14:37 +0000846 if ((!quiet) && (!nonull)) {
847 /*
848 * Empty callbacks for checking
849 */
850 f = fopen(filename, "r");
851 if (f != NULL) {
852 int ret;
853 char chars[10];
854 xmlParserCtxtPtr ctxt;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000855
Daniel Veillard0fb18932003-09-07 09:14:37 +0000856 ret = fread(chars, 1, 4, f);
857 if (ret > 0) {
858 ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL,
859 chars, ret, filename);
860 while ((ret = fread(chars, 1, 3, f)) > 0) {
861 xmlParseChunk(ctxt, chars, ret, 0);
862 }
863 xmlParseChunk(ctxt, chars, 0, 1);
864 xmlFreeParserCtxt(ctxt);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000865 }
Daniel Veillard0fb18932003-09-07 09:14:37 +0000866 fclose(f);
867 } else {
868 xmlGenericError(xmlGenericErrorContext,
869 "Cannot read file %s\n", filename);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000870 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000871 }
872 /*
873 * Debug callback
874 */
875 f = fopen(filename, "r");
876 if (f != NULL) {
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000877 int ret;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000878 char chars[10];
879 xmlParserCtxtPtr ctxt;
880
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000881 ret = fread(chars, 1, 4, f);
882 if (ret > 0) {
Daniel Veillard0fb18932003-09-07 09:14:37 +0000883 if (sax2)
884 ctxt = xmlCreatePushParserCtxt(debugSAX2Handler, NULL,
885 chars, ret, filename);
886 else
887 ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL,
888 chars, ret, filename);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000889 while ((ret = fread(chars, 1, 3, f)) > 0) {
890 xmlParseChunk(ctxt, chars, ret, 0);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000891 }
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000892 ret = xmlParseChunk(ctxt, chars, 0, 1);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000893 xmlFreeParserCtxt(ctxt);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000894 if (ret != 0) {
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000895 fprintf(stdout,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000896 "xmlSAXUserParseFile returned error %d\n", ret);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000897 }
898 }
899 fclose(f);
900 }
901 } else {
Daniel Veillard5e873c42000-04-12 13:27:38 +0000902 if (!speed) {
903 /*
904 * Empty callbacks for checking
905 */
Daniel Veillard0fb18932003-09-07 09:14:37 +0000906 if ((!quiet) && (!nonull)) {
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000907 res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
908 if (res != 0) {
909 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
910 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000911 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000912
Daniel Veillard5e873c42000-04-12 13:27:38 +0000913 /*
914 * Debug callback
915 */
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000916 callbacks = 0;
Daniel Veillard4773df22004-01-23 13:15:13 +0000917 if (repeat) {
918 int i;
919 for (i = 0;i < 99;i++) {
920 if (sax2)
921 res = xmlSAXUserParseFile(debugSAX2Handler, NULL,
922 filename);
923 else
924 res = xmlSAXUserParseFile(debugSAXHandler, NULL,
925 filename);
926 }
927 }
Daniel Veillard0fb18932003-09-07 09:14:37 +0000928 if (sax2)
929 res = xmlSAXUserParseFile(debugSAX2Handler, NULL, filename);
930 else
931 res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
Daniel Veillard5e873c42000-04-12 13:27:38 +0000932 if (res != 0) {
933 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
934 }
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000935 if (quiet)
936 fprintf(stdout, "%d callbacks generated\n", callbacks);
Daniel Veillard5e873c42000-04-12 13:27:38 +0000937 } else {
938 /*
939 * test 100x the SAX parse
940 */
941 int i;
942
943 for (i = 0; i<100;i++)
944 res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
945 if (res != 0) {
946 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
947 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000948 }
Daniel Veillard5099ae81999-04-21 20:12:07 +0000949 }
950}
951
Daniel Veillard5099ae81999-04-21 20:12:07 +0000952
953int main(int argc, char **argv) {
954 int i;
955 int files = 0;
956
957 for (i = 1; i < argc ; i++) {
958 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
959 debug++;
960 else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
961 copy++;
962 else if ((!strcmp(argv[i], "-recover")) ||
963 (!strcmp(argv[i], "--recover")))
964 recovery++;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000965 else if ((!strcmp(argv[i], "-push")) ||
966 (!strcmp(argv[i], "--push")))
967 push++;
Daniel Veillard5e873c42000-04-12 13:27:38 +0000968 else if ((!strcmp(argv[i], "-speed")) ||
969 (!strcmp(argv[i], "--speed")))
970 speed++;
Daniel Veillard4773df22004-01-23 13:15:13 +0000971 else if ((!strcmp(argv[i], "-repeat")) ||
972 (!strcmp(argv[i], "--repeat"))) {
973 repeat++;
974 quiet++;
975 } else if ((!strcmp(argv[i], "-noent")) ||
Daniel Veillard5997aca2002-03-18 18:36:20 +0000976 (!strcmp(argv[i], "--noent")))
977 noent++;
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000978 else if ((!strcmp(argv[i], "-quiet")) ||
979 (!strcmp(argv[i], "--quiet")))
980 quiet++;
Daniel Veillard0fb18932003-09-07 09:14:37 +0000981 else if ((!strcmp(argv[i], "-sax2")) ||
982 (!strcmp(argv[i], "--sax2")))
983 sax2++;
984 else if ((!strcmp(argv[i], "-nonull")) ||
985 (!strcmp(argv[i], "--nonull")))
986 nonull++;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000987 }
Daniel Veillard5997aca2002-03-18 18:36:20 +0000988 if (noent != 0) xmlSubstituteEntitiesDefault(1);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000989 for (i = 1; i < argc ; i++) {
990 if (argv[i][0] != '-') {
991 parseAndPrintFile(argv[i]);
992 files ++;
993 }
994 }
Daniel Veillardf5c2c871999-12-01 09:51:45 +0000995 xmlCleanupParser();
996 xmlMemoryDump();
Daniel Veillard5099ae81999-04-21 20:12:07 +0000997
998 return(0);
999}
Daniel Veillard81273902003-09-30 00:43:48 +00001000#else
1001int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
1002 printf("%s : SAX1 parsing support not compiled in\n", argv[0]);
1003 return(0);
1004}
1005#endif /* LIBXML_SAX1_ENABLED */