blob: ecd9644a28f6f5ffc143b5cb75df3bb92962d570 [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"
Daniel Veillardf5c2c871999-12-01 09:51:45 +000044#include "xmlmemory.h"
Daniel Veillard5099ae81999-04-21 20:12:07 +000045
46static int debug = 0;
47static int copy = 0;
48static int recovery = 0;
49
50xmlSAXHandler emptySAXHandlerStruct = {
51 NULL, /* internalSubset */
52 NULL, /* isStandalone */
53 NULL, /* hasInternalSubset */
54 NULL, /* hasExternalSubset */
55 NULL, /* resolveEntity */
56 NULL, /* getEntity */
57 NULL, /* entityDecl */
58 NULL, /* notationDecl */
59 NULL, /* attributeDecl */
60 NULL, /* elementDecl */
61 NULL, /* unparsedEntityDecl */
62 NULL, /* setDocumentLocator */
63 NULL, /* startDocument */
64 NULL, /* endDocument */
65 NULL, /* startElement */
66 NULL, /* endElement */
67 NULL, /* reference */
68 NULL, /* characters */
69 NULL, /* ignorableWhitespace */
70 NULL, /* processingInstruction */
71 NULL, /* comment */
72 NULL, /* xmlParserWarning */
73 NULL, /* xmlParserError */
74 NULL, /* xmlParserError */
Daniel Veillardb05deb71999-08-10 19:04:08 +000075 NULL, /* getParameterEntity */
Daniel Veillard5099ae81999-04-21 20:12:07 +000076};
77
78xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
Daniel Veillard011b63c1999-06-02 17:44:04 +000079extern xmlSAXHandlerPtr debugSAXHandler;
Daniel Veillard5099ae81999-04-21 20:12:07 +000080
81/*
82 * Note: there is a couple of errors introduced on purpose.
83 */
Daniel Veillard7a66ee61999-09-26 11:31:02 +000084static char buffer[] =
Daniel Veillard5099ae81999-04-21 20:12:07 +000085"<?xml version=\"1.0\"?>\n\
86<?xml:namespace ns = \"http://www.ietf.org/standards/dav/\" prefix = \"D\"?>\n\
87<?xml:namespace ns = \"http://www.w3.com/standards/z39.50/\" prefix = \"Z\"?>\n\
88<D:propertyupdate>\n\
89<D:set a=\"'toto'\" b>\n\
90 <D:prop>\n\
91 <Z:authors>\n\
92 <Z:Author>Jim Whitehead</Z:Author>\n\
93 <Z:Author>Roy Fielding</Z:Author>\n\
94 </Z:authors>\n\
95 </D:prop>\n\
96 </D:set>\n\
97 <D:remove>\n\
98 <D:prop><Z:Copyright-Owner/></D:prop>\n\
99 </D:remove>\n\
100</D:propertyupdate>\n\
101\n\
102";
103
104/************************************************************************
105 * *
106 * Debug Handlers *
107 * *
108 ************************************************************************/
109
110/**
111 * isStandaloneDebug:
112 * @ctxt: An XML parser context
113 *
114 * Is this document tagged standalone ?
115 *
116 * Returns 1 if true
117 */
118int
Daniel Veillardb96e6431999-08-29 21:02:19 +0000119isStandaloneDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000120{
Daniel Veillard27d88741999-05-29 11:51:49 +0000121 fprintf(stdout, "SAX.isStandalone()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000122 return(0);
123}
124
125/**
126 * hasInternalSubsetDebug:
127 * @ctxt: An XML parser context
128 *
129 * Does this document has an internal subset
130 *
131 * Returns 1 if true
132 */
133int
Daniel Veillardb96e6431999-08-29 21:02:19 +0000134hasInternalSubsetDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000135{
Daniel Veillard27d88741999-05-29 11:51:49 +0000136 fprintf(stdout, "SAX.hasInternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000137 return(0);
138}
139
140/**
141 * hasExternalSubsetDebug:
142 * @ctxt: An XML parser context
143 *
144 * Does this document has an external subset
145 *
146 * Returns 1 if true
147 */
148int
Daniel Veillardb96e6431999-08-29 21:02:19 +0000149hasExternalSubsetDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000150{
Daniel Veillard27d88741999-05-29 11:51:49 +0000151 fprintf(stdout, "SAX.hasExternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000152 return(0);
153}
154
155/**
156 * hasInternalSubsetDebug:
157 * @ctxt: An XML parser context
158 *
159 * Does this document has an internal subset
160 */
161void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000162internalSubsetDebug(void *ctx, const xmlChar *name,
163 const xmlChar *ExternalID, const xmlChar *SystemID)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000164{
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000165 /* xmlDtdPtr externalSubset; */
Daniel Veillard011b63c1999-06-02 17:44:04 +0000166
Daniel Veillard27d88741999-05-29 11:51:49 +0000167 fprintf(stdout, "SAX.internalSubset(%s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000168 name, ExternalID, SystemID);
Daniel Veillard011b63c1999-06-02 17:44:04 +0000169
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000170/***********
Daniel Veillard011b63c1999-06-02 17:44:04 +0000171 if ((ExternalID != NULL) || (SystemID != NULL)) {
Daniel Veillardb05deb71999-08-10 19:04:08 +0000172 externalSubset = xmlParseDTD(ExternalID, SystemID);
173 if (externalSubset != NULL) {
174 xmlFreeDtd(externalSubset);
175 }
Daniel Veillard011b63c1999-06-02 17:44:04 +0000176 }
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000177 ***********/
Daniel Veillard5099ae81999-04-21 20:12:07 +0000178}
179
180/**
181 * resolveEntityDebug:
182 * @ctxt: An XML parser context
183 * @publicId: The public ID of the entity
184 * @systemId: The system ID of the entity
185 *
186 * Special entity resolver, better left to the parser, it has
187 * more context than the application layer.
188 * The default behaviour is to NOT resolve the entities, in that case
189 * the ENTITY_REF nodes are built in the structure (and the parameter
190 * values).
191 *
192 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
193 */
194xmlParserInputPtr
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000195resolveEntityDebug(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000196{
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000197 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
Daniel Veillardb96e6431999-08-29 21:02:19 +0000198
Daniel Veillard14fff061999-06-22 21:49:07 +0000199
200 fprintf(stdout, "SAX.resolveEntity(");
201 if (publicId != NULL)
202 fprintf(stdout, "%s", (char *)publicId);
203 else
204 fprintf(stdout, " ");
205 if (systemId != NULL)
206 fprintf(stdout, ", %s)\n", (char *)systemId);
207 else
208 fprintf(stdout, ", )\n");
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000209/*********
Daniel Veillard011b63c1999-06-02 17:44:04 +0000210 if (systemId != NULL) {
Daniel Veillardb96e6431999-08-29 21:02:19 +0000211 return(xmlNewInputFromFile(ctxt, (char *) systemId));
Daniel Veillard011b63c1999-06-02 17:44:04 +0000212 }
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000213 *********/
Daniel Veillard5099ae81999-04-21 20:12:07 +0000214 return(NULL);
215}
216
217/**
218 * getEntityDebug:
219 * @ctxt: An XML parser context
220 * @name: The entity name
221 *
222 * Get an entity by name
223 *
224 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
225 */
226xmlEntityPtr
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000227getEntityDebug(void *ctx, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000228{
Daniel Veillard27d88741999-05-29 11:51:49 +0000229 fprintf(stdout, "SAX.getEntity(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000230 return(NULL);
231}
232
Daniel Veillardb05deb71999-08-10 19:04:08 +0000233/**
234 * getParameterEntityDebug:
235 * @ctxt: An XML parser context
236 * @name: The entity name
237 *
238 * Get a parameter entity by name
239 *
240 * Returns the xmlParserInputPtr
241 */
242xmlEntityPtr
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000243getParameterEntityDebug(void *ctx, const xmlChar *name)
Daniel Veillardb05deb71999-08-10 19:04:08 +0000244{
245 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
246 return(NULL);
247}
248
Daniel Veillard5099ae81999-04-21 20:12:07 +0000249
250/**
251 * entityDeclDebug:
252 * @ctxt: An XML parser context
253 * @name: the entity name
254 * @type: the entity type
255 * @publicId: The public ID of the entity
256 * @systemId: The system ID of the entity
257 * @content: the entity value (without processing).
258 *
259 * An entity definition has been parsed
260 */
261void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000262entityDeclDebug(void *ctx, const xmlChar *name, int type,
263 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000264{
Daniel Veillard27d88741999-05-29 11:51:49 +0000265 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000266 name, type, publicId, systemId, content);
267}
268
269/**
270 * attributeDeclDebug:
271 * @ctxt: An XML parser context
272 * @name: the attribute name
273 * @type: the attribute type
274 *
275 * An attribute definition has been parsed
276 */
277void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000278attributeDeclDebug(void *ctx, const xmlChar *elem, const xmlChar *name,
279 int type, int def, const xmlChar *defaultValue,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000280 xmlEnumerationPtr tree)
281{
Daniel Veillard27d88741999-05-29 11:51:49 +0000282 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000283 elem, name, type, def, defaultValue);
284}
285
286/**
287 * elementDeclDebug:
288 * @ctxt: An XML parser context
289 * @name: the element name
290 * @type: the element type
291 * @content: the element value (without processing).
292 *
293 * An element definition has been parsed
294 */
295void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000296elementDeclDebug(void *ctx, const xmlChar *name, int type,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000297 xmlElementContentPtr content)
298{
Daniel Veillard27d88741999-05-29 11:51:49 +0000299 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000300 name, type);
301}
302
303/**
304 * notationDeclDebug:
305 * @ctxt: An XML parser context
306 * @name: The name of the notation
307 * @publicId: The public ID of the entity
308 * @systemId: The system ID of the entity
309 *
310 * What to do when a notation declaration has been parsed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000311 */
312void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000313notationDeclDebug(void *ctx, const xmlChar *name,
314 const xmlChar *publicId, const xmlChar *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000315{
Daniel Veillard27d88741999-05-29 11:51:49 +0000316 fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000317 (char *) name, (char *) publicId, (char *) systemId);
318}
319
320/**
321 * unparsedEntityDeclDebug:
322 * @ctxt: An XML parser context
323 * @name: The name of the entity
324 * @publicId: The public ID of the entity
325 * @systemId: The system ID of the entity
326 * @notationName: the name of the notation
327 *
328 * What to do when an unparsed entity declaration is parsed
Daniel Veillard5099ae81999-04-21 20:12:07 +0000329 */
330void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000331unparsedEntityDeclDebug(void *ctx, const xmlChar *name,
332 const xmlChar *publicId, const xmlChar *systemId,
333 const xmlChar *notationName)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000334{
Daniel Veillard27d88741999-05-29 11:51:49 +0000335 fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000336 (char *) name, (char *) publicId, (char *) systemId,
337 (char *) notationName);
338}
339
340/**
341 * setDocumentLocatorDebug:
342 * @ctxt: An XML parser context
343 * @loc: A SAX Locator
344 *
345 * Receive the document locator at startup, actually xmlDefaultSAXLocator
346 * Everything is available on the context, so this is useless in our case.
347 */
348void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000349setDocumentLocatorDebug(void *ctx, xmlSAXLocatorPtr loc)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000350{
Daniel Veillard27d88741999-05-29 11:51:49 +0000351 fprintf(stdout, "SAX.setDocumentLocator()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000352}
353
354/**
355 * startDocumentDebug:
356 * @ctxt: An XML parser context
357 *
358 * called when the document start being processed.
359 */
360void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000361startDocumentDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000362{
Daniel Veillard27d88741999-05-29 11:51:49 +0000363 fprintf(stdout, "SAX.startDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000364}
365
366/**
367 * endDocumentDebug:
368 * @ctxt: An XML parser context
369 *
370 * called when the document end has been detected.
371 */
372void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000373endDocumentDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000374{
Daniel Veillard27d88741999-05-29 11:51:49 +0000375 fprintf(stdout, "SAX.endDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000376}
377
378/**
379 * startElementDebug:
380 * @ctxt: An XML parser context
381 * @name: The element name
382 *
383 * called when an opening tag has been processed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000384 */
385void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000386startElementDebug(void *ctx, const xmlChar *name, const xmlChar **atts)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000387{
388 int i;
389
Daniel Veillard27d88741999-05-29 11:51:49 +0000390 fprintf(stdout, "SAX.startElement(%s", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000391 if (atts != NULL) {
392 for (i = 0;(atts[i] != NULL);i++) {
Daniel Veillard27d88741999-05-29 11:51:49 +0000393 fprintf(stdout, ", %s='", atts[i++]);
394 fprintf(stdout, "%s'", atts[i]);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000395 }
396 }
Daniel Veillard27d88741999-05-29 11:51:49 +0000397 fprintf(stdout, ")\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000398}
399
400/**
401 * endElementDebug:
402 * @ctxt: An XML parser context
403 * @name: The element name
404 *
405 * called when the end of an element has been detected.
406 */
407void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000408endElementDebug(void *ctx, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000409{
Daniel Veillard27d88741999-05-29 11:51:49 +0000410 fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000411}
412
413/**
414 * charactersDebug:
415 * @ctxt: An XML parser context
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000416 * @ch: a xmlChar string
417 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000418 *
419 * receiving some chars from the parser.
420 * Question: how much at a time ???
421 */
422void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000423charactersDebug(void *ctx, const xmlChar *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000424{
Daniel Veillarde2d034d1999-07-27 19:52:06 +0000425 int i;
426
427 fprintf(stdout, "SAX.characters(");
428 for (i = 0;(i < len) && (i < 30);i++)
429 fprintf(stdout, "%c", ch[i]);
430 fprintf(stdout, ", %d)\n", len);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000431}
432
433/**
434 * referenceDebug:
435 * @ctxt: An XML parser context
436 * @name: The entity name
437 *
438 * called when an entity reference is detected.
439 */
440void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000441referenceDebug(void *ctx, const xmlChar *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000442{
Daniel Veillard27d88741999-05-29 11:51:49 +0000443 fprintf(stdout, "SAX.reference(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000444}
445
446/**
447 * ignorableWhitespaceDebug:
448 * @ctxt: An XML parser context
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000449 * @ch: a xmlChar string
Daniel Veillard5099ae81999-04-21 20:12:07 +0000450 * @start: the first char in the string
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000451 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000452 *
453 * receiving some ignorable whitespaces from the parser.
454 * Question: how much at a time ???
455 */
456void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000457ignorableWhitespaceDebug(void *ctx, const xmlChar *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000458{
Daniel Veillard27d88741999-05-29 11:51:49 +0000459 fprintf(stdout, "SAX.ignorableWhitespace(%.30s, %d)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000460 (char *) ch, len);
461}
462
463/**
464 * processingInstructionDebug:
465 * @ctxt: An XML parser context
466 * @target: the target name
467 * @data: the PI data's
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000468 * @len: the number of xmlChar
Daniel Veillard5099ae81999-04-21 20:12:07 +0000469 *
470 * A processing instruction has been parsed.
471 */
472void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000473processingInstructionDebug(void *ctx, const xmlChar *target,
474 const xmlChar *data)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000475{
Daniel Veillard27d88741999-05-29 11:51:49 +0000476 fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000477 (char *) target, (char *) data);
478}
479
480/**
481 * commentDebug:
482 * @ctxt: An XML parser context
483 * @value: the comment content
484 *
485 * A comment has been parsed.
486 */
487void
Daniel Veillarddd6b3671999-09-23 22:19:22 +0000488commentDebug(void *ctx, const xmlChar *value)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000489{
Daniel Veillard27d88741999-05-29 11:51:49 +0000490 fprintf(stdout, "SAX.comment(%s)\n", value);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000491}
492
493/**
494 * warningDebug:
495 * @ctxt: An XML parser context
496 * @msg: the message to display/transmit
497 * @...: extra parameters for the message display
498 *
499 * Display and format a warning messages, gives file, line, position and
500 * extra parameters.
501 */
502void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000503warningDebug(void *ctx, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000504{
505 va_list args;
506
507 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000508 fprintf(stdout, "SAX.warning: ");
509 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000510 va_end(args);
511}
512
513/**
514 * errorDebug:
515 * @ctxt: An XML parser context
516 * @msg: the message to display/transmit
517 * @...: extra parameters for the message display
518 *
519 * Display and format a error messages, gives file, line, position and
520 * extra parameters.
521 */
522void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000523errorDebug(void *ctx, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000524{
525 va_list args;
526
527 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000528 fprintf(stdout, "SAX.error: ");
529 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000530 va_end(args);
531}
532
533/**
534 * fatalErrorDebug:
535 * @ctxt: An XML parser context
536 * @msg: the message to display/transmit
537 * @...: extra parameters for the message display
538 *
539 * Display and format a fatalError messages, gives file, line, position and
540 * extra parameters.
541 */
542void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000543fatalErrorDebug(void *ctx, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000544{
545 va_list args;
546
547 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000548 fprintf(stdout, "SAX.fatalError: ");
549 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000550 va_end(args);
551}
552
553xmlSAXHandler debugSAXHandlerStruct = {
554 internalSubsetDebug,
555 isStandaloneDebug,
556 hasInternalSubsetDebug,
557 hasExternalSubsetDebug,
558 resolveEntityDebug,
559 getEntityDebug,
560 entityDeclDebug,
561 notationDeclDebug,
562 attributeDeclDebug,
563 elementDeclDebug,
564 unparsedEntityDeclDebug,
565 setDocumentLocatorDebug,
566 startDocumentDebug,
567 endDocumentDebug,
568 startElementDebug,
569 endElementDebug,
570 referenceDebug,
571 charactersDebug,
572 ignorableWhitespaceDebug,
573 processingInstructionDebug,
574 commentDebug,
575 warningDebug,
576 errorDebug,
577 fatalErrorDebug,
Daniel Veillardb05deb71999-08-10 19:04:08 +0000578 getParameterEntityDebug,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000579};
580
581xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
582
583/************************************************************************
584 * *
585 * Debug *
586 * *
587 ************************************************************************/
588
589void parseAndPrintFile(char *filename) {
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000590 int res;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000591
592 /*
593 * Empty callbacks for checking
594 */
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000595 res = xmlSAXUserParseFile(emptySAXHandler, NULL, filename);
596 if (res != 0) {
597 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000598 }
599
600 /*
601 * Debug callback
602 */
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000603 res = xmlSAXUserParseFile(debugSAXHandler, NULL, filename);
604 if (res != 0) {
605 fprintf(stdout, "xmlSAXUserParseFile returned error %d\n", res);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000606 }
607}
608
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000609void parseAndPrintBuffer(char *buf) {
610 int res;
Daniel Veillard5099ae81999-04-21 20:12:07 +0000611
612 /*
613 * Empty callbacks for checking
614 */
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000615 res = xmlSAXUserParseMemory(emptySAXHandler, NULL, buf, strlen(buf));
616 if (res != 0) {
617 fprintf(stdout, "xmlSAXUserParseMemory returned error %d\n", res);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000618 }
619
620 /*
621 * Debug callback
622 */
Daniel Veillard7a66ee61999-09-26 11:31:02 +0000623 res = xmlSAXUserParseMemory(debugSAXHandler, NULL, buf, strlen(buf));
624 if (res != 0) {
625 fprintf(stdout, "xmlSAXUserParseMemory returned error %d\n", res);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000626 }
627}
628
629int main(int argc, char **argv) {
630 int i;
631 int files = 0;
632
633 for (i = 1; i < argc ; i++) {
634 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
635 debug++;
636 else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
637 copy++;
638 else if ((!strcmp(argv[i], "-recover")) ||
639 (!strcmp(argv[i], "--recover")))
640 recovery++;
641 }
642 for (i = 1; i < argc ; i++) {
643 if (argv[i][0] != '-') {
644 parseAndPrintFile(argv[i]);
645 files ++;
646 }
647 }
648 if (files == 0) {
649 printf("\nFirst test for the parser, with errors\n");
650 parseAndPrintBuffer(buffer);
651 }
Daniel Veillardf5c2c871999-12-01 09:51:45 +0000652 xmlCleanupParser();
653 xmlMemoryDump();
Daniel Veillard5099ae81999-04-21 20:12:07 +0000654
655 return(0);
656}