blob: edd6d6ae2e33838452730f14468f377afc3139af [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 */
Daniel Veillard07cb8222003-09-10 10:51:05 +000085 NULL /* endElementNs */
Daniel Veillard5099ae81999-04-21 20:12:07 +000086};
87
88xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
Daniel Veillard011b63c1999-06-02 17:44:04 +000089extern xmlSAXHandlerPtr debugSAXHandler;
Daniel Veillard5099ae81999-04-21 20:12:07 +000090
Daniel Veillard5099ae81999-04-21 20:12:07 +000091/************************************************************************
92 * *
93 * Debug Handlers *
94 * *
95 ************************************************************************/
96
97/**
98 * isStandaloneDebug:
99 * @ctxt: An XML parser context
100 *
101 * Is this document tagged standalone ?
102 *
103 * Returns 1 if true
104 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000105static int
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000106isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000107{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000108 callbacks++;
109 if (quiet)
110 return(0);
Daniel Veillard27d88741999-05-29 11:51:49 +0000111 fprintf(stdout, "SAX.isStandalone()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000112 return(0);
113}
114
115/**
116 * hasInternalSubsetDebug:
117 * @ctxt: An XML parser context
118 *
119 * Does this document has an internal subset
120 *
121 * Returns 1 if true
122 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000123static int
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000124hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000125{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000126 callbacks++;
127 if (quiet)
128 return(0);
Daniel Veillard27d88741999-05-29 11:51:49 +0000129 fprintf(stdout, "SAX.hasInternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000130 return(0);
131}
132
133/**
134 * hasExternalSubsetDebug:
135 * @ctxt: An XML parser context
136 *
137 * Does this document has an external subset
138 *
139 * Returns 1 if true
140 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000141static int
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000142hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000143{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000144 callbacks++;
145 if (quiet)
146 return(0);
Daniel Veillard27d88741999-05-29 11:51:49 +0000147 fprintf(stdout, "SAX.hasExternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000148 return(0);
149}
150
151/**
Daniel Veillard06047432000-04-24 11:33:38 +0000152 * internalSubsetDebug:
Daniel Veillard5099ae81999-04-21 20:12:07 +0000153 * @ctxt: An XML parser context
154 *
155 * Does this document has an internal subset
156 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000157static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000158internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000159 const xmlChar *ExternalID, const xmlChar *SystemID)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000160{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000161 callbacks++;
162 if (quiet)
163 return;
Daniel Veillard808a3f12000-08-17 13:50:51 +0000164 fprintf(stdout, "SAX.internalSubset(%s,", name);
165 if (ExternalID == NULL)
166 fprintf(stdout, " ,");
167 else
168 fprintf(stdout, " %s,", ExternalID);
169 if (SystemID == NULL)
170 fprintf(stdout, " )\n");
171 else
172 fprintf(stdout, " %s)\n", SystemID);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000173}
174
175/**
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000176 * externalSubsetDebug:
177 * @ctxt: An XML parser context
178 *
179 * Does this document has an external subset
180 */
181static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000182externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000183 const xmlChar *ExternalID, const xmlChar *SystemID)
184{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000185 callbacks++;
186 if (quiet)
187 return;
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000188 fprintf(stdout, "SAX.externalSubset(%s,", name);
189 if (ExternalID == NULL)
190 fprintf(stdout, " ,");
191 else
192 fprintf(stdout, " %s,", ExternalID);
193 if (SystemID == NULL)
194 fprintf(stdout, " )\n");
195 else
196 fprintf(stdout, " %s)\n", SystemID);
197}
198
199/**
Daniel Veillard5099ae81999-04-21 20:12:07 +0000200 * resolveEntityDebug:
201 * @ctxt: An XML parser context
202 * @publicId: The public ID of the entity
203 * @systemId: The system ID of the entity
204 *
205 * Special entity resolver, better left to the parser, it has
206 * more context than the application layer.
207 * The default behaviour is to NOT resolve the entities, in that case
208 * the ENTITY_REF nodes are built in the structure (and the parameter
209 * values).
210 *
211 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
212 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000213static xmlParserInputPtr
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000214resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000215{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000216 callbacks++;
217 if (quiet)
218 return(NULL);
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000219 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000220
Daniel Veillard14fff061999-06-22 21:49:07 +0000221
222 fprintf(stdout, "SAX.resolveEntity(");
223 if (publicId != NULL)
224 fprintf(stdout, "%s", (char *)publicId);
225 else
226 fprintf(stdout, " ");
227 if (systemId != NULL)
228 fprintf(stdout, ", %s)\n", (char *)systemId);
229 else
230 fprintf(stdout, ", )\n");
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000231/*********
Daniel Veillard011b63c1999-06-02 17:44:04 +0000232 if (systemId != NULL) {
Daniel Veillardb96e6431999-08-29 21:02:19 +0000233 return(xmlNewInputFromFile(ctxt, (char *) systemId));
Daniel Veillard011b63c1999-06-02 17:44:04 +0000234 }
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000235 *********/
Daniel Veillard5099ae81999-04-21 20:12:07 +0000236 return(NULL);
237}
238
239/**
240 * getEntityDebug:
241 * @ctxt: An XML parser context
242 * @name: The entity name
243 *
244 * Get an entity by name
245 *
246 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
247 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000248static xmlEntityPtr
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000249getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000250{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000251 callbacks++;
252 if (quiet)
253 return(NULL);
Daniel Veillard27d88741999-05-29 11:51:49 +0000254 fprintf(stdout, "SAX.getEntity(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000255 return(NULL);
256}
257
Daniel Veillardb05deb71999-08-10 19:04:08 +0000258/**
259 * getParameterEntityDebug:
260 * @ctxt: An XML parser context
261 * @name: The entity name
262 *
263 * Get a parameter entity by name
264 *
265 * Returns the xmlParserInputPtr
266 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000267static xmlEntityPtr
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000268getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillardb05deb71999-08-10 19:04:08 +0000269{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000270 callbacks++;
271 if (quiet)
272 return(NULL);
Daniel Veillardb05deb71999-08-10 19:04:08 +0000273 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
274 return(NULL);
275}
276
Daniel Veillard5099ae81999-04-21 20:12:07 +0000277
278/**
279 * entityDeclDebug:
280 * @ctxt: An XML parser context
281 * @name: the entity name
282 * @type: the entity type
283 * @publicId: The public ID of the entity
284 * @systemId: The system ID of the entity
285 * @content: the entity value (without processing).
286 *
287 * An entity definition has been parsed
288 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000289static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000290entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000291 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000292{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000293 callbacks++;
294 if (quiet)
295 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000296 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000297 name, type, publicId, systemId, content);
298}
299
300/**
301 * attributeDeclDebug:
302 * @ctxt: An XML parser context
303 * @name: the attribute name
304 * @type: the attribute type
305 *
306 * An attribute definition has been parsed
307 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000308static void
Daniel Veillard07cb8222003-09-10 10:51:05 +0000309attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar * elem,
310 const xmlChar * name, int type, int def,
311 const xmlChar * defaultValue, xmlEnumerationPtr tree)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000312{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000313 callbacks++;
314 if (quiet)
Daniel Veillard07cb8222003-09-10 10:51:05 +0000315 return;
Daniel Veillard7e99c632000-10-06 12:59:53 +0000316 if (defaultValue == NULL)
Daniel Veillard07cb8222003-09-10 10:51:05 +0000317 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n",
318 elem, name, type, def);
Daniel Veillard7e99c632000-10-06 12:59:53 +0000319 else
Daniel Veillard07cb8222003-09-10 10:51:05 +0000320 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
321 elem, name, type, def, defaultValue);
322 xmlFreeEnumeration(tree);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000323}
324
325/**
326 * elementDeclDebug:
327 * @ctxt: An XML parser context
328 * @name: the element name
329 * @type: the element type
330 * @content: the element value (without processing).
331 *
332 * An element definition has been parsed
333 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000334static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000335elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
336 xmlElementContentPtr content ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000337{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000338 callbacks++;
339 if (quiet)
340 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000341 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000342 name, type);
343}
344
345/**
346 * notationDeclDebug:
347 * @ctxt: An XML parser context
348 * @name: The name of the notation
349 * @publicId: The public ID of the entity
350 * @systemId: The system ID of the entity
351 *
352 * What to do when a notation declaration has been parsed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000353 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000354static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000355notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000356 const xmlChar *publicId, const xmlChar *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000357{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000358 callbacks++;
359 if (quiet)
360 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000361 fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000362 (char *) name, (char *) publicId, (char *) systemId);
363}
364
365/**
366 * unparsedEntityDeclDebug:
367 * @ctxt: An XML parser context
368 * @name: The name of the entity
369 * @publicId: The public ID of the entity
370 * @systemId: The system ID of the entity
371 * @notationName: the name of the notation
372 *
373 * What to do when an unparsed entity declaration is parsed
Daniel Veillard5099ae81999-04-21 20:12:07 +0000374 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000375static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000376unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000377 const xmlChar *publicId, const xmlChar *systemId,
378 const xmlChar *notationName)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000379{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000380 callbacks++;
381 if (quiet)
382 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000383 fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000384 (char *) name, (char *) publicId, (char *) systemId,
385 (char *) notationName);
386}
387
388/**
389 * setDocumentLocatorDebug:
390 * @ctxt: An XML parser context
391 * @loc: A SAX Locator
392 *
393 * Receive the document locator at startup, actually xmlDefaultSAXLocator
394 * Everything is available on the context, so this is useless in our case.
395 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000396static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000397setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000398{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000399 callbacks++;
400 if (quiet)
401 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000402 fprintf(stdout, "SAX.setDocumentLocator()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000403}
404
405/**
406 * startDocumentDebug:
407 * @ctxt: An XML parser context
408 *
409 * called when the document start being processed.
410 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000411static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000412startDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000413{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000414 callbacks++;
415 if (quiet)
416 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000417 fprintf(stdout, "SAX.startDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000418}
419
420/**
421 * endDocumentDebug:
422 * @ctxt: An XML parser context
423 *
424 * called when the document end has been detected.
425 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000426static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000427endDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000428{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000429 callbacks++;
430 if (quiet)
431 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000432 fprintf(stdout, "SAX.endDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000433}
434
435/**
436 * startElementDebug:
437 * @ctxt: An XML parser context
438 * @name: The element name
439 *
440 * called when an opening tag has been processed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000441 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000442static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000443startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000444{
445 int i;
446
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000447 callbacks++;
448 if (quiet)
449 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000450 fprintf(stdout, "SAX.startElement(%s", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000451 if (atts != NULL) {
452 for (i = 0;(atts[i] != NULL);i++) {
Daniel Veillard27d88741999-05-29 11:51:49 +0000453 fprintf(stdout, ", %s='", atts[i++]);
Daniel Veillard808a3f12000-08-17 13:50:51 +0000454 if (atts[i] != NULL)
455 fprintf(stdout, "%s'", atts[i]);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000456 }
457 }
Daniel Veillard27d88741999-05-29 11:51:49 +0000458 fprintf(stdout, ")\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000459}
460
461/**
462 * endElementDebug:
463 * @ctxt: An XML parser context
464 * @name: The element name
465 *
466 * called when the end of an element has been detected.
467 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000468static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000469endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000470{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000471 callbacks++;
472 if (quiet)
473 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000474 fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000475}
476
477/**
478 * charactersDebug:
479 * @ctxt: An XML parser context
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000480 * @ch: a xmlChar string
481 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000482 *
483 * receiving some chars from the parser.
484 * Question: how much at a time ???
485 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000486static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000487charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000488{
Daniel Veillard87b95392000-08-12 21:12:04 +0000489 char output[40];
Daniel Veillarde2d034d1999-07-27 19:52:06 +0000490 int i;
491
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000492 callbacks++;
493 if (quiet)
494 return;
Daniel Veillard87b95392000-08-12 21:12:04 +0000495 for (i = 0;(i<len) && (i < 30);i++)
496 output[i] = ch[i];
497 output[i] = 0;
498
499 fprintf(stdout, "SAX.characters(%s, %d)\n", output, len);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000500}
501
502/**
503 * referenceDebug:
504 * @ctxt: An XML parser context
505 * @name: The entity name
506 *
507 * called when an entity reference is detected.
508 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000509static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000510referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000511{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000512 callbacks++;
513 if (quiet)
514 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000515 fprintf(stdout, "SAX.reference(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000516}
517
518/**
519 * ignorableWhitespaceDebug:
520 * @ctxt: An XML parser context
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000521 * @ch: a xmlChar string
Daniel Veillard5099ae81999-04-21 20:12:07 +0000522 * @start: the first char in the string
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000523 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000524 *
525 * receiving some ignorable whitespaces from the parser.
526 * Question: how much at a time ???
527 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000528static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000529ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000530{
Daniel Veillard87b95392000-08-12 21:12:04 +0000531 char output[40];
532 int i;
533
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000534 callbacks++;
535 if (quiet)
536 return;
Daniel Veillard87b95392000-08-12 21:12:04 +0000537 for (i = 0;(i<len) && (i < 30);i++)
538 output[i] = ch[i];
539 output[i] = 0;
540 fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000541}
542
543/**
544 * processingInstructionDebug:
545 * @ctxt: An XML parser context
546 * @target: the target name
547 * @data: the PI data's
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000548 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000549 *
550 * A processing instruction has been parsed.
551 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000552static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000553processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target,
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000554 const xmlChar *data)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000555{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000556 callbacks++;
557 if (quiet)
558 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000559 fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000560 (char *) target, (char *) data);
561}
562
563/**
Daniel Veillardcf461992000-03-14 18:30:20 +0000564 * cdataBlockDebug:
565 * @ctx: the user data (XML parser context)
566 * @value: The pcdata content
567 * @len: the block length
568 *
569 * called when a pcdata block has been parsed
570 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000571static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000572cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len)
Daniel Veillardcf461992000-03-14 18:30:20 +0000573{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000574 callbacks++;
575 if (quiet)
576 return;
Daniel Veillard39915622000-10-15 10:06:55 +0000577 fprintf(stdout, "SAX.pcdata(%.20s, %d)\n",
Daniel Veillardcf461992000-03-14 18:30:20 +0000578 (char *) value, len);
579}
580
581/**
Daniel Veillard5099ae81999-04-21 20:12:07 +0000582 * commentDebug:
583 * @ctxt: An XML parser context
584 * @value: the comment content
585 *
586 * A comment has been parsed.
587 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000588static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000589commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000590{
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000591 callbacks++;
592 if (quiet)
593 return;
Daniel Veillard27d88741999-05-29 11:51:49 +0000594 fprintf(stdout, "SAX.comment(%s)\n", value);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000595}
596
597/**
598 * warningDebug:
599 * @ctxt: An XML parser context
600 * @msg: the message to display/transmit
601 * @...: extra parameters for the message display
602 *
603 * Display and format a warning messages, gives file, line, position and
604 * extra parameters.
605 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000606static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000607warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000608{
609 va_list args;
610
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000611 callbacks++;
612 if (quiet)
613 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000614 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000615 fprintf(stdout, "SAX.warning: ");
616 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000617 va_end(args);
618}
619
620/**
621 * errorDebug:
622 * @ctxt: An XML parser context
623 * @msg: the message to display/transmit
624 * @...: extra parameters for the message display
625 *
626 * Display and format a error messages, gives file, line, position and
627 * extra parameters.
628 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000629static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000630errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000631{
632 va_list args;
633
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000634 callbacks++;
635 if (quiet)
636 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000637 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000638 fprintf(stdout, "SAX.error: ");
639 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000640 va_end(args);
641}
642
643/**
644 * fatalErrorDebug:
645 * @ctxt: An XML parser context
646 * @msg: the message to display/transmit
647 * @...: extra parameters for the message display
648 *
649 * Display and format a fatalError messages, gives file, line, position and
650 * extra parameters.
651 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000652static void
Daniel Veillardc86a4fa2001-03-26 16:28:29 +0000653fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000654{
655 va_list args;
656
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000657 callbacks++;
658 if (quiet)
659 return;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000660 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000661 fprintf(stdout, "SAX.fatalError: ");
662 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000663 va_end(args);
664}
665
666xmlSAXHandler debugSAXHandlerStruct = {
667 internalSubsetDebug,
668 isStandaloneDebug,
669 hasInternalSubsetDebug,
670 hasExternalSubsetDebug,
671 resolveEntityDebug,
672 getEntityDebug,
673 entityDeclDebug,
674 notationDeclDebug,
675 attributeDeclDebug,
676 elementDeclDebug,
677 unparsedEntityDeclDebug,
678 setDocumentLocatorDebug,
679 startDocumentDebug,
680 endDocumentDebug,
681 startElementDebug,
682 endElementDebug,
683 referenceDebug,
684 charactersDebug,
685 ignorableWhitespaceDebug,
686 processingInstructionDebug,
687 commentDebug,
688 warningDebug,
689 errorDebug,
690 fatalErrorDebug,
Daniel Veillardb05deb71999-08-10 19:04:08 +0000691 getParameterEntityDebug,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000692 cdataBlockDebug,
Daniel Veillardd0463562001-10-13 09:15:48 +0000693 externalSubsetDebug,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000694 1,
695 NULL,
696 NULL,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000697 NULL
Daniel Veillard5099ae81999-04-21 20:12:07 +0000698};
699
700xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
701
Daniel Veillard0fb18932003-09-07 09:14:37 +0000702/*
703 * SAX2 specific callbacks
704 */
705/**
Daniel Veillard07cb8222003-09-10 10:51:05 +0000706 * startElementNsDebug:
Daniel Veillard0fb18932003-09-07 09:14:37 +0000707 * @ctxt: An XML parser context
708 * @name: The element name
709 *
710 * called when an opening tag has been processed.
711 */
712static void
713startElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
714 const xmlChar *localname,
715 const xmlChar *prefix,
716 const xmlChar *URI,
717 int nb_namespaces,
718 const xmlChar **namespaces,
Daniel Veillard07cb8222003-09-10 10:51:05 +0000719 int nb_attributes,
720 int nb_defaulted,
721 const xmlChar **attributes)
Daniel Veillard0fb18932003-09-07 09:14:37 +0000722{
723 int i;
724
725 callbacks++;
726 if (quiet)
727 return;
728 fprintf(stdout, "SAX.startElementNs(%s", (char *) localname);
729 if (prefix == NULL)
730 fprintf(stdout, ", NULL");
731 else
732 fprintf(stdout, ", %s", (char *) prefix);
733 if (URI == NULL)
734 fprintf(stdout, ", NULL");
735 else
736 fprintf(stdout, ", '%s'", (char *) URI);
737 fprintf(stdout, ", %d", nb_namespaces);
738
739 if (namespaces != NULL) {
740 for (i = 0;i < nb_namespaces * 2;i++) {
741 fprintf(stdout, ", xmlns");
742 if (namespaces[i] != NULL)
743 fprintf(stdout, ":%s", namespaces[i]);
744 i++;
745 fprintf(stdout, "='%s'", namespaces[i]);
746 }
747 }
Daniel Veillard07cb8222003-09-10 10:51:05 +0000748 fprintf(stdout, ", %d, %d", nb_attributes, nb_defaulted);
749 if (attributes != NULL) {
750 for (i = 0;i < nb_attributes;i += 5) {
751 if (attributes[i + 1] != NULL)
752 fprintf(stdout, ", %s:%s='", attributes[i + 1], attributes[i]);
753 else
754 fprintf(stdout, ", %s='", attributes[i]);
755 fprintf(stdout, "%.4s...', %d", attributes[i + 3],
756 attributes[i + 4] - attributes[i + 3]);
757 }
758 }
759 fprintf(stdout, ")\n");
Daniel Veillard0fb18932003-09-07 09:14:37 +0000760}
761
762/**
763 * endElementDebug:
764 * @ctxt: An XML parser context
765 * @name: The element name
766 *
767 * called when the end of an element has been detected.
768 */
769static void
770endElementNsDebug(void *ctx ATTRIBUTE_UNUSED,
771 const xmlChar *localname,
772 const xmlChar *prefix,
773 const xmlChar *URI)
774{
775 callbacks++;
776 if (quiet)
777 return;
778 fprintf(stdout, "SAX.endElementNs(%s", (char *) localname);
779 if (prefix == NULL)
780 fprintf(stdout, ", NULL");
781 else
782 fprintf(stdout, ", %s", (char *) prefix);
783 if (URI == NULL)
784 fprintf(stdout, ", NULL)\n");
785 else
786 fprintf(stdout, ", '%s')\n", (char *) URI);
787}
788
Daniel Veillard0fb18932003-09-07 09:14:37 +0000789xmlSAXHandler debugSAX2HandlerStruct = {
790 internalSubsetDebug,
791 isStandaloneDebug,
792 hasInternalSubsetDebug,
793 hasExternalSubsetDebug,
794 resolveEntityDebug,
795 getEntityDebug,
796 entityDeclDebug,
797 notationDeclDebug,
798 attributeDeclDebug,
799 elementDeclDebug,
800 unparsedEntityDeclDebug,
801 setDocumentLocatorDebug,
802 startDocumentDebug,
803 endDocumentDebug,
804 NULL,
805 NULL,
806 referenceDebug,
807 charactersDebug,
808 ignorableWhitespaceDebug,
809 processingInstructionDebug,
810 commentDebug,
811 warningDebug,
812 errorDebug,
813 fatalErrorDebug,
814 getParameterEntityDebug,
815 cdataBlockDebug,
816 externalSubsetDebug,
Daniel Veillard07cb8222003-09-10 10:51:05 +0000817 XML_SAX2_MAGIC,
Daniel Veillard0fb18932003-09-07 09:14:37 +0000818 NULL,
819 startElementNsDebug,
Daniel Veillard07cb8222003-09-10 10:51:05 +0000820 endElementNsDebug
Daniel Veillard0fb18932003-09-07 09:14:37 +0000821};
822
823xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
824
Daniel Veillard5099ae81999-04-21 20:12:07 +0000825/************************************************************************
826 * *
827 * Debug *
828 * *
829 ************************************************************************/
830
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000831static void
832parseAndPrintFile(char *filename) {
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000833 int res;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000834
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000835 if (push) {
836 FILE *f;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000837
Daniel Veillard0fb18932003-09-07 09:14:37 +0000838 if ((!quiet) && (!nonull)) {
839 /*
840 * Empty callbacks for checking
841 */
842 f = fopen(filename, "r");
843 if (f != NULL) {
844 int ret;
845 char chars[10];
846 xmlParserCtxtPtr ctxt;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000847
Daniel Veillard0fb18932003-09-07 09:14:37 +0000848 ret = fread(chars, 1, 4, f);
849 if (ret > 0) {
850 ctxt = xmlCreatePushParserCtxt(emptySAXHandler, NULL,
851 chars, ret, filename);
852 while ((ret = fread(chars, 1, 3, f)) > 0) {
853 xmlParseChunk(ctxt, chars, ret, 0);
854 }
855 xmlParseChunk(ctxt, chars, 0, 1);
856 xmlFreeParserCtxt(ctxt);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000857 }
Daniel Veillard0fb18932003-09-07 09:14:37 +0000858 fclose(f);
859 } else {
860 xmlGenericError(xmlGenericErrorContext,
861 "Cannot read file %s\n", filename);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000862 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000863 }
864 /*
865 * Debug callback
866 */
867 f = fopen(filename, "r");
868 if (f != NULL) {
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000869 int ret;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000870 char chars[10];
871 xmlParserCtxtPtr ctxt;
872
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000873 ret = fread(chars, 1, 4, f);
874 if (ret > 0) {
Daniel Veillard0fb18932003-09-07 09:14:37 +0000875 if (sax2)
876 ctxt = xmlCreatePushParserCtxt(debugSAX2Handler, NULL,
877 chars, ret, filename);
878 else
879 ctxt = xmlCreatePushParserCtxt(debugSAXHandler, NULL,
880 chars, ret, filename);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000881 while ((ret = fread(chars, 1, 3, f)) > 0) {
882 xmlParseChunk(ctxt, chars, ret, 0);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000883 }
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000884 ret = xmlParseChunk(ctxt, chars, 0, 1);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000885 xmlFreeParserCtxt(ctxt);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000886 if (ret != 0) {
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000887 fprintf(stdout,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000888 "xmlSAXUserParseFile returned error %d\n", ret);
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000889 }
890 }
891 fclose(f);
892 }
893 } else {
Daniel Veillard5e873c42000-04-12 13:27:38 +0000894 if (!speed) {
895 /*
896 * Empty callbacks for checking
897 */
Daniel Veillard0fb18932003-09-07 09:14:37 +0000898 if ((!quiet) && (!nonull)) {
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000899 res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
900 if (res != 0) {
901 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
902 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000903 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000904
Daniel Veillard5e873c42000-04-12 13:27:38 +0000905 /*
906 * Debug callback
907 */
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000908 callbacks = 0;
Daniel Veillard0fb18932003-09-07 09:14:37 +0000909 if (sax2)
910 res = xmlSAXUserParseFile(debugSAX2Handler, NULL, filename);
911 else
912 res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
Daniel Veillard5e873c42000-04-12 13:27:38 +0000913 if (res != 0) {
914 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
915 }
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000916 if (quiet)
917 fprintf(stdout, "%d callbacks generated\n", callbacks);
Daniel Veillard5e873c42000-04-12 13:27:38 +0000918 } else {
919 /*
920 * test 100x the SAX parse
921 */
922 int i;
923
924 for (i = 0; i<100;i++)
925 res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
926 if (res != 0) {
927 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
928 }
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000929 }
Daniel Veillard5099ae81999-04-21 20:12:07 +0000930 }
931}
932
Daniel Veillard5099ae81999-04-21 20:12:07 +0000933
934int main(int argc, char **argv) {
935 int i;
936 int files = 0;
937
938 for (i = 1; i < argc ; i++) {
939 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
940 debug++;
941 else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
942 copy++;
943 else if ((!strcmp(argv[i], "-recover")) ||
944 (!strcmp(argv[i], "--recover")))
945 recovery++;
Daniel Veillarddbfd6411999-12-28 16:35:14 +0000946 else if ((!strcmp(argv[i], "-push")) ||
947 (!strcmp(argv[i], "--push")))
948 push++;
Daniel Veillard5e873c42000-04-12 13:27:38 +0000949 else if ((!strcmp(argv[i], "-speed")) ||
950 (!strcmp(argv[i], "--speed")))
951 speed++;
Daniel Veillard5997aca2002-03-18 18:36:20 +0000952 else if ((!strcmp(argv[i], "-noent")) ||
953 (!strcmp(argv[i], "--noent")))
954 noent++;
Daniel Veillarde50f3b52002-03-20 19:24:21 +0000955 else if ((!strcmp(argv[i], "-quiet")) ||
956 (!strcmp(argv[i], "--quiet")))
957 quiet++;
Daniel Veillard0fb18932003-09-07 09:14:37 +0000958 else if ((!strcmp(argv[i], "-sax2")) ||
959 (!strcmp(argv[i], "--sax2")))
960 sax2++;
961 else if ((!strcmp(argv[i], "-nonull")) ||
962 (!strcmp(argv[i], "--nonull")))
963 nonull++;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000964 }
Daniel Veillard5997aca2002-03-18 18:36:20 +0000965 if (noent != 0) xmlSubstituteEntitiesDefault(1);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000966 for (i = 1; i < argc ; i++) {
967 if (argv[i][0] != '-') {
968 parseAndPrintFile(argv[i]);
969 files ++;
970 }
971 }
Daniel Veillardf5c2c871999-12-01 09:51:45 +0000972 xmlCleanupParser();
973 xmlMemoryDump();
Daniel Veillard5099ae81999-04-21 20:12:07 +0000974
975 return(0);
976}
Daniel Veillard81273902003-09-30 00:43:48 +0000977#else
978int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
979 printf("%s : SAX1 parsing support not compiled in\n", argv[0]);
980 return(0);
981}
982#endif /* LIBXML_SAX1_ENABLED */