blob: 8311ffbd368261686ee316270a4ba30bc11a2da7 [file] [log] [blame]
Daniel Veillard5099ae81999-04-21 20:12:07 +00001/*
2 * tester.c : a small tester program for parsing using the SAX API.
3 *
4 * See Copyright for the status of this software.
5 *
6 * Daniel.Veillard@w3.org
7 */
8
9#ifdef WIN32
10#define HAVE_FCNTL_H
11#include <io.h>
12#else
Daniel Veillard7f7d1111999-09-22 09:46:25 +000013#include "config.h"
Daniel Veillard5099ae81999-04-21 20:12:07 +000014#endif
Daniel Veillard7f7d1111999-09-22 09:46:25 +000015
16#include <stdio.h>
17#include <string.h>
18#include <stdarg.h>
19
20#ifdef HAVE_SYS_TYPES_H
Daniel Veillard5099ae81999-04-21 20:12:07 +000021#include <sys/types.h>
Daniel Veillard7f7d1111999-09-22 09:46:25 +000022#endif
Daniel Veillard5099ae81999-04-21 20:12:07 +000023#ifdef HAVE_SYS_STAT_H
24#include <sys/stat.h>
25#endif
26#ifdef HAVE_FCNTL_H
27#include <fcntl.h>
28#endif
29#ifdef HAVE_UNISTD_H
30#include <unistd.h>
31#endif
Daniel Veillard7f7d1111999-09-22 09:46:25 +000032#ifdef HAVE_STDLIB_H
Daniel Veillard5099ae81999-04-21 20:12:07 +000033#include <stdlib.h>
Daniel Veillard7f7d1111999-09-22 09:46:25 +000034#endif
Daniel Veillard7a66ee61999-09-26 11:31:02 +000035#ifdef HAVE_STRING_H
36#include <string.h>
37#endif
Daniel Veillard7f7d1111999-09-22 09:46:25 +000038
Daniel Veillard5099ae81999-04-21 20:12:07 +000039
40#include "parser.h"
Daniel Veillard011b63c1999-06-02 17:44:04 +000041#include "parserInternals.h" /* only for xmlNewInputFromFile() */
Daniel Veillard5099ae81999-04-21 20:12:07 +000042#include "tree.h"
43#include "debugXML.h"
44
45static int debug = 0;
46static int copy = 0;
47static int recovery = 0;
48
49xmlSAXHandler emptySAXHandlerStruct = {
50 NULL, /* internalSubset */
51 NULL, /* isStandalone */
52 NULL, /* hasInternalSubset */
53 NULL, /* hasExternalSubset */
54 NULL, /* resolveEntity */
55 NULL, /* getEntity */
56 NULL, /* entityDecl */
57 NULL, /* notationDecl */
58 NULL, /* attributeDecl */
59 NULL, /* elementDecl */
60 NULL, /* unparsedEntityDecl */
61 NULL, /* setDocumentLocator */
62 NULL, /* startDocument */
63 NULL, /* endDocument */
64 NULL, /* startElement */
65 NULL, /* endElement */
66 NULL, /* reference */
67 NULL, /* characters */
68 NULL, /* ignorableWhitespace */
69 NULL, /* processingInstruction */
70 NULL, /* comment */
71 NULL, /* xmlParserWarning */
72 NULL, /* xmlParserError */
73 NULL, /* xmlParserError */
Daniel Veillardb05deb71999-08-10 19:04:08 +000074 NULL, /* getParameterEntity */
Daniel Veillard5099ae81999-04-21 20:12:07 +000075};
76
77xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
Daniel Veillard011b63c1999-06-02 17:44:04 +000078extern xmlSAXHandlerPtr debugSAXHandler;
Daniel Veillard5099ae81999-04-21 20:12:07 +000079
80/*
81 * Note: there is a couple of errors introduced on purpose.
82 */
Daniel Veillard7a66ee61999-09-26 11:31:02 +000083static char buffer[] =
Daniel Veillard5099ae81999-04-21 20:12:07 +000084"<?xml version=\"1.0\"?>\n\
85<?xml:namespace ns = \"http://www.ietf.org/standards/dav/\" prefix = \"D\"?>\n\
86<?xml:namespace ns = \"http://www.w3.com/standards/z39.50/\" prefix = \"Z\"?>\n\
87<D:propertyupdate>\n\
88<D:set a=\"'toto'\" b>\n\
89 <D:prop>\n\
90 <Z:authors>\n\
91 <Z:Author>Jim Whitehead</Z:Author>\n\
92 <Z:Author>Roy Fielding</Z:Author>\n\
93 </Z:authors>\n\
94 </D:prop>\n\
95 </D:set>\n\
96 <D:remove>\n\
97 <D:prop><Z:Copyright-Owner/></D:prop>\n\
98 </D:remove>\n\
99</D:propertyupdate>\n\
100\n\
101";
102
103/************************************************************************
104 * *
105 * Debug Handlers *
106 * *
107 ************************************************************************/
108
109/**
110 * isStandaloneDebug:
111 * @ctxt: An XML parser context
112 *
113 * Is this document tagged standalone ?
114 *
115 * Returns 1 if true
116 */
117int
Daniel Veillardb96e6431999-08-29 21:02:19 +0000118isStandaloneDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000119{
Daniel Veillard27d88741999-05-29 11:51:49 +0000120 fprintf(stdout, "SAX.isStandalone()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000121 return(0);
122}
123
124/**
125 * hasInternalSubsetDebug:
126 * @ctxt: An XML parser context
127 *
128 * Does this document has an internal subset
129 *
130 * Returns 1 if true
131 */
132int
Daniel Veillardb96e6431999-08-29 21:02:19 +0000133hasInternalSubsetDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000134{
Daniel Veillard27d88741999-05-29 11:51:49 +0000135 fprintf(stdout, "SAX.hasInternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000136 return(0);
137}
138
139/**
140 * hasExternalSubsetDebug:
141 * @ctxt: An XML parser context
142 *
143 * Does this document has an external subset
144 *
145 * Returns 1 if true
146 */
147int
Daniel Veillardb96e6431999-08-29 21:02:19 +0000148hasExternalSubsetDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000149{
Daniel Veillard27d88741999-05-29 11:51:49 +0000150 fprintf(stdout, "SAX.hasExternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000151 return(0);
152}
153
154/**
155 * hasInternalSubsetDebug:
156 * @ctxt: An XML parser context
157 *
158 * Does this document has an internal subset
159 */
160void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000161internalSubsetDebug(void *ctx, const xmlChar *name,
162 const xmlChar *ExternalID, const xmlChar *SystemID)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000163{
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000164 /* xmlDtdPtr externalSubset; */
Daniel Veillard011b63c1999-06-02 17:44:04 +0000165
Daniel Veillard27d88741999-05-29 11:51:49 +0000166 fprintf(stdout, "SAX.internalSubset(%s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000167 name, ExternalID, SystemID);
Daniel Veillard011b63c1999-06-02 17:44:04 +0000168
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000169/***********
Daniel Veillard011b63c1999-06-02 17:44:04 +0000170 if ((ExternalID != NULL) || (SystemID != NULL)) {
Daniel Veillardb05deb71999-08-10 19:04:08 +0000171 externalSubset = xmlParseDTD(ExternalID, SystemID);
172 if (externalSubset != NULL) {
173 xmlFreeDtd(externalSubset);
174 }
Daniel Veillard011b63c1999-06-02 17:44:04 +0000175 }
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000176 ***********/
Daniel Veillard5099ae81999-04-21 20:12:07 +0000177}
178
179/**
180 * resolveEntityDebug:
181 * @ctxt: An XML parser context
182 * @publicId: The public ID of the entity
183 * @systemId: The system ID of the entity
184 *
185 * Special entity resolver, better left to the parser, it has
186 * more context than the application layer.
187 * The default behaviour is to NOT resolve the entities, in that case
188 * the ENTITY_REF nodes are built in the structure (and the parameter
189 * values).
190 *
191 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
192 */
193xmlParserInputPtr
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000194resolveEntityDebug(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000195{
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000196 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000197
Daniel Veillard14fff061999-06-22 21:49:07 +0000198
199 fprintf(stdout, "SAX.resolveEntity(");
200 if (publicId != NULL)
201 fprintf(stdout, "%s", (char *)publicId);
202 else
203 fprintf(stdout, " ");
204 if (systemId != NULL)
205 fprintf(stdout, ", %s)\n", (char *)systemId);
206 else
207 fprintf(stdout, ", )\n");
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000208/*********
Daniel Veillard011b63c1999-06-02 17:44:04 +0000209 if (systemId != NULL) {
Daniel Veillardb96e6431999-08-29 21:02:19 +0000210 return(xmlNewInputFromFile(ctxt, (char *) systemId));
Daniel Veillard011b63c1999-06-02 17:44:04 +0000211 }
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000212 *********/
Daniel Veillard5099ae81999-04-21 20:12:07 +0000213 return(NULL);
214}
215
216/**
217 * getEntityDebug:
218 * @ctxt: An XML parser context
219 * @name: The entity name
220 *
221 * Get an entity by name
222 *
223 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
224 */
225xmlEntityPtr
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000226getEntityDebug(void *ctx, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000227{
Daniel Veillard27d88741999-05-29 11:51:49 +0000228 fprintf(stdout, "SAX.getEntity(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000229 return(NULL);
230}
231
Daniel Veillardb05deb71999-08-10 19:04:08 +0000232/**
233 * getParameterEntityDebug:
234 * @ctxt: An XML parser context
235 * @name: The entity name
236 *
237 * Get a parameter entity by name
238 *
239 * Returns the xmlParserInputPtr
240 */
241xmlEntityPtr
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000242getParameterEntityDebug(void *ctx, const xmlChar *name)
Daniel Veillardb05deb71999-08-10 19:04:08 +0000243{
244 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
245 return(NULL);
246}
247
Daniel Veillard5099ae81999-04-21 20:12:07 +0000248
249/**
250 * entityDeclDebug:
251 * @ctxt: An XML parser context
252 * @name: the entity name
253 * @type: the entity type
254 * @publicId: The public ID of the entity
255 * @systemId: The system ID of the entity
256 * @content: the entity value (without processing).
257 *
258 * An entity definition has been parsed
259 */
260void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000261entityDeclDebug(void *ctx, const xmlChar *name, int type,
262 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000263{
Daniel Veillard27d88741999-05-29 11:51:49 +0000264 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000265 name, type, publicId, systemId, content);
266}
267
268/**
269 * attributeDeclDebug:
270 * @ctxt: An XML parser context
271 * @name: the attribute name
272 * @type: the attribute type
273 *
274 * An attribute definition has been parsed
275 */
276void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000277attributeDeclDebug(void *ctx, const xmlChar *elem, const xmlChar *name,
278 int type, int def, const xmlChar *defaultValue,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000279 xmlEnumerationPtr tree)
280{
Daniel Veillard27d88741999-05-29 11:51:49 +0000281 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000282 elem, name, type, def, defaultValue);
283}
284
285/**
286 * elementDeclDebug:
287 * @ctxt: An XML parser context
288 * @name: the element name
289 * @type: the element type
290 * @content: the element value (without processing).
291 *
292 * An element definition has been parsed
293 */
294void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000295elementDeclDebug(void *ctx, const xmlChar *name, int type,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000296 xmlElementContentPtr content)
297{
Daniel Veillard27d88741999-05-29 11:51:49 +0000298 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000299 name, type);
300}
301
302/**
303 * notationDeclDebug:
304 * @ctxt: An XML parser context
305 * @name: The name of the notation
306 * @publicId: The public ID of the entity
307 * @systemId: The system ID of the entity
308 *
309 * What to do when a notation declaration has been parsed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000310 */
311void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000312notationDeclDebug(void *ctx, const xmlChar *name,
313 const xmlChar *publicId, const xmlChar *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000314{
Daniel Veillard27d88741999-05-29 11:51:49 +0000315 fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000316 (char *) name, (char *) publicId, (char *) systemId);
317}
318
319/**
320 * unparsedEntityDeclDebug:
321 * @ctxt: An XML parser context
322 * @name: The name of the entity
323 * @publicId: The public ID of the entity
324 * @systemId: The system ID of the entity
325 * @notationName: the name of the notation
326 *
327 * What to do when an unparsed entity declaration is parsed
Daniel Veillard5099ae81999-04-21 20:12:07 +0000328 */
329void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000330unparsedEntityDeclDebug(void *ctx, const xmlChar *name,
331 const xmlChar *publicId, const xmlChar *systemId,
332 const xmlChar *notationName)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000333{
Daniel Veillard27d88741999-05-29 11:51:49 +0000334 fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000335 (char *) name, (char *) publicId, (char *) systemId,
336 (char *) notationName);
337}
338
339/**
340 * setDocumentLocatorDebug:
341 * @ctxt: An XML parser context
342 * @loc: A SAX Locator
343 *
344 * Receive the document locator at startup, actually xmlDefaultSAXLocator
345 * Everything is available on the context, so this is useless in our case.
346 */
347void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000348setDocumentLocatorDebug(void *ctx, xmlSAXLocatorPtr loc)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000349{
Daniel Veillard27d88741999-05-29 11:51:49 +0000350 fprintf(stdout, "SAX.setDocumentLocator()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000351}
352
353/**
354 * startDocumentDebug:
355 * @ctxt: An XML parser context
356 *
357 * called when the document start being processed.
358 */
359void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000360startDocumentDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000361{
Daniel Veillard27d88741999-05-29 11:51:49 +0000362 fprintf(stdout, "SAX.startDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000363}
364
365/**
366 * endDocumentDebug:
367 * @ctxt: An XML parser context
368 *
369 * called when the document end has been detected.
370 */
371void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000372endDocumentDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000373{
Daniel Veillard27d88741999-05-29 11:51:49 +0000374 fprintf(stdout, "SAX.endDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000375}
376
377/**
378 * startElementDebug:
379 * @ctxt: An XML parser context
380 * @name: The element name
381 *
382 * called when an opening tag has been processed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000383 */
384void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000385startElementDebug(void *ctx, const xmlChar *name, const xmlChar **atts)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000386{
387 int i;
388
Daniel Veillard27d88741999-05-29 11:51:49 +0000389 fprintf(stdout, "SAX.startElement(%s", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000390 if (atts != NULL) {
391 for (i = 0;(atts[i] != NULL);i++) {
Daniel Veillard27d88741999-05-29 11:51:49 +0000392 fprintf(stdout, ", %s='", atts[i++]);
393 fprintf(stdout, "%s'", atts[i]);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000394 }
395 }
Daniel Veillard27d88741999-05-29 11:51:49 +0000396 fprintf(stdout, ")\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000397}
398
399/**
400 * endElementDebug:
401 * @ctxt: An XML parser context
402 * @name: The element name
403 *
404 * called when the end of an element has been detected.
405 */
406void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000407endElementDebug(void *ctx, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000408{
Daniel Veillard27d88741999-05-29 11:51:49 +0000409 fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000410}
411
412/**
413 * charactersDebug:
414 * @ctxt: An XML parser context
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000415 * @ch: a xmlChar string
416 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000417 *
418 * receiving some chars from the parser.
419 * Question: how much at a time ???
420 */
421void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000422charactersDebug(void *ctx, const xmlChar *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000423{
Daniel Veillarde2d034d1999-07-27 19:52:06 +0000424 int i;
425
426 fprintf(stdout, "SAX.characters(");
427 for (i = 0;(i < len) && (i < 30);i++)
428 fprintf(stdout, "%c", ch[i]);
429 fprintf(stdout, ", %d)\n", len);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000430}
431
432/**
433 * referenceDebug:
434 * @ctxt: An XML parser context
435 * @name: The entity name
436 *
437 * called when an entity reference is detected.
438 */
439void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000440referenceDebug(void *ctx, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000441{
Daniel Veillard27d88741999-05-29 11:51:49 +0000442 fprintf(stdout, "SAX.reference(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000443}
444
445/**
446 * ignorableWhitespaceDebug:
447 * @ctxt: An XML parser context
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000448 * @ch: a xmlChar string
Daniel Veillard5099ae81999-04-21 20:12:07 +0000449 * @start: the first char in the string
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000450 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000451 *
452 * receiving some ignorable whitespaces from the parser.
453 * Question: how much at a time ???
454 */
455void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000456ignorableWhitespaceDebug(void *ctx, const xmlChar *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000457{
Daniel Veillard27d88741999-05-29 11:51:49 +0000458 fprintf(stdout, "SAX.ignorableWhitespace(%.30s, %d)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000459 (char *) ch, len);
460}
461
462/**
463 * processingInstructionDebug:
464 * @ctxt: An XML parser context
465 * @target: the target name
466 * @data: the PI data's
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000467 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000468 *
469 * A processing instruction has been parsed.
470 */
471void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000472processingInstructionDebug(void *ctx, const xmlChar *target,
473 const xmlChar *data)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000474{
Daniel Veillard27d88741999-05-29 11:51:49 +0000475 fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000476 (char *) target, (char *) data);
477}
478
479/**
480 * commentDebug:
481 * @ctxt: An XML parser context
482 * @value: the comment content
483 *
484 * A comment has been parsed.
485 */
486void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000487commentDebug(void *ctx, const xmlChar *value)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000488{
Daniel Veillard27d88741999-05-29 11:51:49 +0000489 fprintf(stdout, "SAX.comment(%s)\n", value);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000490}
491
492/**
493 * warningDebug:
494 * @ctxt: An XML parser context
495 * @msg: the message to display/transmit
496 * @...: extra parameters for the message display
497 *
498 * Display and format a warning messages, gives file, line, position and
499 * extra parameters.
500 */
501void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000502warningDebug(void *ctx, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000503{
504 va_list args;
505
506 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000507 fprintf(stdout, "SAX.warning: ");
508 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000509 va_end(args);
510}
511
512/**
513 * errorDebug:
514 * @ctxt: An XML parser context
515 * @msg: the message to display/transmit
516 * @...: extra parameters for the message display
517 *
518 * Display and format a error messages, gives file, line, position and
519 * extra parameters.
520 */
521void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000522errorDebug(void *ctx, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000523{
524 va_list args;
525
526 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000527 fprintf(stdout, "SAX.error: ");
528 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000529 va_end(args);
530}
531
532/**
533 * fatalErrorDebug:
534 * @ctxt: An XML parser context
535 * @msg: the message to display/transmit
536 * @...: extra parameters for the message display
537 *
538 * Display and format a fatalError messages, gives file, line, position and
539 * extra parameters.
540 */
541void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000542fatalErrorDebug(void *ctx, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000543{
544 va_list args;
545
546 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000547 fprintf(stdout, "SAX.fatalError: ");
548 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000549 va_end(args);
550}
551
552xmlSAXHandler debugSAXHandlerStruct = {
553 internalSubsetDebug,
554 isStandaloneDebug,
555 hasInternalSubsetDebug,
556 hasExternalSubsetDebug,
557 resolveEntityDebug,
558 getEntityDebug,
559 entityDeclDebug,
560 notationDeclDebug,
561 attributeDeclDebug,
562 elementDeclDebug,
563 unparsedEntityDeclDebug,
564 setDocumentLocatorDebug,
565 startDocumentDebug,
566 endDocumentDebug,
567 startElementDebug,
568 endElementDebug,
569 referenceDebug,
570 charactersDebug,
571 ignorableWhitespaceDebug,
572 processingInstructionDebug,
573 commentDebug,
574 warningDebug,
575 errorDebug,
576 fatalErrorDebug,
Daniel Veillardb05deb71999-08-10 19:04:08 +0000577 getParameterEntityDebug,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000578};
579
580xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
581
582/************************************************************************
583 * *
584 * Debug *
585 * *
586 ************************************************************************/
587
588void parseAndPrintFile(char *filename) {
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000589 int res;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000590
591 /*
592 * Empty callbacks for checking
593 */
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000594 res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
595 if (res != 0) {
596 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000597 }
598
599 /*
600 * Debug callback
601 */
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000602 res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
603 if (res != 0) {
604 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000605 }
606}
607
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000608void parseAndPrintBuffer(char *buf) {
609 int res;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000610
611 /*
612 * Empty callbacks for checking
613 */
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000614 res = xmlSAXUserParseMemory(emptySAXHandler, NULL, buf, strlen(buf));
615 if (res != 0) {
616 fprintf(stdout, "xmlSAXUserParseMemory returned error %d\n", res);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000617 }
618
619 /*
620 * Debug callback
621 */
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000622 res = xmlSAXUserParseMemory(debugSAXHandler, NULL, buf, strlen(buf));
623 if (res != 0) {
624 fprintf(stdout, "xmlSAXUserParseMemory returned error %d\n", res);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000625 }
626}
627
628int main(int argc, char **argv) {
629 int i;
630 int files = 0;
631
632 for (i = 1; i < argc ; i++) {
633 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
634 debug++;
635 else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
636 copy++;
637 else if ((!strcmp(argv[i], "-recover")) ||
638 (!strcmp(argv[i], "--recover")))
639 recovery++;
640 }
641 for (i = 1; i < argc ; i++) {
642 if (argv[i][0] != '-') {
643 parseAndPrintFile(argv[i]);
644 files ++;
645 }
646 }
647 if (files == 0) {
648 printf("\nFirst test for the parser, with errors\n");
649 parseAndPrintBuffer(buffer);
650 }
651
652 return(0);
653}