blob: 7dcdcf4f3faae120ef54f7d4c14f33a6db1d18b6 [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
13#include <config.h>
14#endif
15#include <sys/types.h>
16#ifdef HAVE_SYS_STAT_H
17#include <sys/stat.h>
18#endif
19#ifdef HAVE_FCNTL_H
20#include <fcntl.h>
21#endif
22#ifdef HAVE_UNISTD_H
23#include <unistd.h>
24#endif
25#include <stdio.h>
26#include <string.h>
27#include <stdlib.h>
28#include <stdarg.h>
29
30#include "parser.h"
Daniel Veillard011b63c1999-06-02 17:44:04 +000031#include "parserInternals.h" /* only for xmlNewInputFromFile() */
Daniel Veillard5099ae81999-04-21 20:12:07 +000032#include "tree.h"
33#include "debugXML.h"
34
35static int debug = 0;
36static int copy = 0;
37static int recovery = 0;
38
39xmlSAXHandler emptySAXHandlerStruct = {
40 NULL, /* internalSubset */
41 NULL, /* isStandalone */
42 NULL, /* hasInternalSubset */
43 NULL, /* hasExternalSubset */
44 NULL, /* resolveEntity */
45 NULL, /* getEntity */
46 NULL, /* entityDecl */
47 NULL, /* notationDecl */
48 NULL, /* attributeDecl */
49 NULL, /* elementDecl */
50 NULL, /* unparsedEntityDecl */
51 NULL, /* setDocumentLocator */
52 NULL, /* startDocument */
53 NULL, /* endDocument */
54 NULL, /* startElement */
55 NULL, /* endElement */
56 NULL, /* reference */
57 NULL, /* characters */
58 NULL, /* ignorableWhitespace */
59 NULL, /* processingInstruction */
60 NULL, /* comment */
61 NULL, /* xmlParserWarning */
62 NULL, /* xmlParserError */
63 NULL, /* xmlParserError */
Daniel Veillardb05deb71999-08-10 19:04:08 +000064 NULL, /* getParameterEntity */
Daniel Veillard5099ae81999-04-21 20:12:07 +000065};
66
67xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
Daniel Veillard011b63c1999-06-02 17:44:04 +000068extern xmlSAXHandlerPtr debugSAXHandler;
Daniel Veillard5099ae81999-04-21 20:12:07 +000069
70/*
71 * Note: there is a couple of errors introduced on purpose.
72 */
73static CHAR buffer[] =
74"<?xml version=\"1.0\"?>\n\
75<?xml:namespace ns = \"http://www.ietf.org/standards/dav/\" prefix = \"D\"?>\n\
76<?xml:namespace ns = \"http://www.w3.com/standards/z39.50/\" prefix = \"Z\"?>\n\
77<D:propertyupdate>\n\
78<D:set a=\"'toto'\" b>\n\
79 <D:prop>\n\
80 <Z:authors>\n\
81 <Z:Author>Jim Whitehead</Z:Author>\n\
82 <Z:Author>Roy Fielding</Z:Author>\n\
83 </Z:authors>\n\
84 </D:prop>\n\
85 </D:set>\n\
86 <D:remove>\n\
87 <D:prop><Z:Copyright-Owner/></D:prop>\n\
88 </D:remove>\n\
89</D:propertyupdate>\n\
90\n\
91";
92
93/************************************************************************
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 */
107int
Daniel Veillardb96e6431999-08-29 21:02:19 +0000108isStandaloneDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000109{
Daniel Veillard27d88741999-05-29 11:51:49 +0000110 fprintf(stdout, "SAX.isStandalone()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000111 return(0);
112}
113
114/**
115 * hasInternalSubsetDebug:
116 * @ctxt: An XML parser context
117 *
118 * Does this document has an internal subset
119 *
120 * Returns 1 if true
121 */
122int
Daniel Veillardb96e6431999-08-29 21:02:19 +0000123hasInternalSubsetDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000124{
Daniel Veillard27d88741999-05-29 11:51:49 +0000125 fprintf(stdout, "SAX.hasInternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000126 return(0);
127}
128
129/**
130 * hasExternalSubsetDebug:
131 * @ctxt: An XML parser context
132 *
133 * Does this document has an external subset
134 *
135 * Returns 1 if true
136 */
137int
Daniel Veillardb96e6431999-08-29 21:02:19 +0000138hasExternalSubsetDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000139{
Daniel Veillard27d88741999-05-29 11:51:49 +0000140 fprintf(stdout, "SAX.hasExternalSubset()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000141 return(0);
142}
143
144/**
145 * hasInternalSubsetDebug:
146 * @ctxt: An XML parser context
147 *
148 * Does this document has an internal subset
149 */
150void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000151internalSubsetDebug(void *ctx, const CHAR *name,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000152 const CHAR *ExternalID, const CHAR *SystemID)
153{
Daniel Veillard011b63c1999-06-02 17:44:04 +0000154 xmlDtdPtr externalSubset;
155
Daniel Veillard27d88741999-05-29 11:51:49 +0000156 fprintf(stdout, "SAX.internalSubset(%s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000157 name, ExternalID, SystemID);
Daniel Veillard011b63c1999-06-02 17:44:04 +0000158
159 if ((ExternalID != NULL) || (SystemID != NULL)) {
Daniel Veillardb05deb71999-08-10 19:04:08 +0000160 externalSubset = xmlParseDTD(ExternalID, SystemID);
161 if (externalSubset != NULL) {
162 xmlFreeDtd(externalSubset);
163 }
Daniel Veillard011b63c1999-06-02 17:44:04 +0000164 }
Daniel Veillard5099ae81999-04-21 20:12:07 +0000165}
166
167/**
168 * resolveEntityDebug:
169 * @ctxt: An XML parser context
170 * @publicId: The public ID of the entity
171 * @systemId: The system ID of the entity
172 *
173 * Special entity resolver, better left to the parser, it has
174 * more context than the application layer.
175 * The default behaviour is to NOT resolve the entities, in that case
176 * the ENTITY_REF nodes are built in the structure (and the parameter
177 * values).
178 *
179 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
180 */
181xmlParserInputPtr
Daniel Veillardb96e6431999-08-29 21:02:19 +0000182resolveEntityDebug(void *ctx, const CHAR *publicId, const CHAR *systemId)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000183{
Daniel Veillardb96e6431999-08-29 21:02:19 +0000184 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
185
Daniel Veillard14fff061999-06-22 21:49:07 +0000186
187 fprintf(stdout, "SAX.resolveEntity(");
188 if (publicId != NULL)
189 fprintf(stdout, "%s", (char *)publicId);
190 else
191 fprintf(stdout, " ");
192 if (systemId != NULL)
193 fprintf(stdout, ", %s)\n", (char *)systemId);
194 else
195 fprintf(stdout, ", )\n");
Daniel Veillard011b63c1999-06-02 17:44:04 +0000196 if (systemId != NULL) {
Daniel Veillardb96e6431999-08-29 21:02:19 +0000197 return(xmlNewInputFromFile(ctxt, (char *) systemId));
Daniel Veillard011b63c1999-06-02 17:44:04 +0000198 }
Daniel Veillard5099ae81999-04-21 20:12:07 +0000199 return(NULL);
200}
201
202/**
203 * getEntityDebug:
204 * @ctxt: An XML parser context
205 * @name: The entity name
206 *
207 * Get an entity by name
208 *
209 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
210 */
211xmlEntityPtr
Daniel Veillardb96e6431999-08-29 21:02:19 +0000212getEntityDebug(void *ctx, const CHAR *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000213{
Daniel Veillard27d88741999-05-29 11:51:49 +0000214 fprintf(stdout, "SAX.getEntity(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000215 return(NULL);
216}
217
Daniel Veillardb05deb71999-08-10 19:04:08 +0000218/**
219 * getParameterEntityDebug:
220 * @ctxt: An XML parser context
221 * @name: The entity name
222 *
223 * Get a parameter entity by name
224 *
225 * Returns the xmlParserInputPtr
226 */
227xmlEntityPtr
Daniel Veillardb96e6431999-08-29 21:02:19 +0000228getParameterEntityDebug(void *ctx, const CHAR *name)
Daniel Veillardb05deb71999-08-10 19:04:08 +0000229{
230 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
231 return(NULL);
232}
233
Daniel Veillard5099ae81999-04-21 20:12:07 +0000234
235/**
236 * entityDeclDebug:
237 * @ctxt: An XML parser context
238 * @name: the entity name
239 * @type: the entity type
240 * @publicId: The public ID of the entity
241 * @systemId: The system ID of the entity
242 * @content: the entity value (without processing).
243 *
244 * An entity definition has been parsed
245 */
246void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000247entityDeclDebug(void *ctx, const CHAR *name, int type,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000248 const CHAR *publicId, const CHAR *systemId, CHAR *content)
249{
Daniel Veillard27d88741999-05-29 11:51:49 +0000250 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000251 name, type, publicId, systemId, content);
252}
253
254/**
255 * attributeDeclDebug:
256 * @ctxt: An XML parser context
257 * @name: the attribute name
258 * @type: the attribute type
259 *
260 * An attribute definition has been parsed
261 */
262void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000263attributeDeclDebug(void *ctx, const CHAR *elem, const CHAR *name,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000264 int type, int def, const CHAR *defaultValue,
265 xmlEnumerationPtr tree)
266{
Daniel Veillard27d88741999-05-29 11:51:49 +0000267 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000268 elem, name, type, def, defaultValue);
269}
270
271/**
272 * elementDeclDebug:
273 * @ctxt: An XML parser context
274 * @name: the element name
275 * @type: the element type
276 * @content: the element value (without processing).
277 *
278 * An element definition has been parsed
279 */
280void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000281elementDeclDebug(void *ctx, const CHAR *name, int type,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000282 xmlElementContentPtr content)
283{
Daniel Veillard27d88741999-05-29 11:51:49 +0000284 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000285 name, type);
286}
287
288/**
289 * notationDeclDebug:
290 * @ctxt: An XML parser context
291 * @name: The name of the notation
292 * @publicId: The public ID of the entity
293 * @systemId: The system ID of the entity
294 *
295 * What to do when a notation declaration has been parsed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000296 */
297void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000298notationDeclDebug(void *ctx, const CHAR *name,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000299 const CHAR *publicId, const CHAR *systemId)
300{
Daniel Veillard27d88741999-05-29 11:51:49 +0000301 fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000302 (char *) name, (char *) publicId, (char *) systemId);
303}
304
305/**
306 * unparsedEntityDeclDebug:
307 * @ctxt: An XML parser context
308 * @name: The name of the entity
309 * @publicId: The public ID of the entity
310 * @systemId: The system ID of the entity
311 * @notationName: the name of the notation
312 *
313 * What to do when an unparsed entity declaration is parsed
Daniel Veillard5099ae81999-04-21 20:12:07 +0000314 */
315void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000316unparsedEntityDeclDebug(void *ctx, const CHAR *name,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000317 const CHAR *publicId, const CHAR *systemId,
318 const CHAR *notationName)
319{
Daniel Veillard27d88741999-05-29 11:51:49 +0000320 fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000321 (char *) name, (char *) publicId, (char *) systemId,
322 (char *) notationName);
323}
324
325/**
326 * setDocumentLocatorDebug:
327 * @ctxt: An XML parser context
328 * @loc: A SAX Locator
329 *
330 * Receive the document locator at startup, actually xmlDefaultSAXLocator
331 * Everything is available on the context, so this is useless in our case.
332 */
333void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000334setDocumentLocatorDebug(void *ctx, xmlSAXLocatorPtr loc)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000335{
Daniel Veillard27d88741999-05-29 11:51:49 +0000336 fprintf(stdout, "SAX.setDocumentLocator()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000337}
338
339/**
340 * startDocumentDebug:
341 * @ctxt: An XML parser context
342 *
343 * called when the document start being processed.
344 */
345void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000346startDocumentDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000347{
Daniel Veillard27d88741999-05-29 11:51:49 +0000348 fprintf(stdout, "SAX.startDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000349}
350
351/**
352 * endDocumentDebug:
353 * @ctxt: An XML parser context
354 *
355 * called when the document end has been detected.
356 */
357void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000358endDocumentDebug(void *ctx)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000359{
Daniel Veillard27d88741999-05-29 11:51:49 +0000360 fprintf(stdout, "SAX.endDocument()\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000361}
362
363/**
364 * startElementDebug:
365 * @ctxt: An XML parser context
366 * @name: The element name
367 *
368 * called when an opening tag has been processed.
Daniel Veillard5099ae81999-04-21 20:12:07 +0000369 */
370void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000371startElementDebug(void *ctx, const CHAR *name, const CHAR **atts)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000372{
373 int i;
374
Daniel Veillard27d88741999-05-29 11:51:49 +0000375 fprintf(stdout, "SAX.startElement(%s", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000376 if (atts != NULL) {
377 for (i = 0;(atts[i] != NULL);i++) {
Daniel Veillard27d88741999-05-29 11:51:49 +0000378 fprintf(stdout, ", %s='", atts[i++]);
379 fprintf(stdout, "%s'", atts[i]);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000380 }
381 }
Daniel Veillard27d88741999-05-29 11:51:49 +0000382 fprintf(stdout, ")\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000383}
384
385/**
386 * endElementDebug:
387 * @ctxt: An XML parser context
388 * @name: The element name
389 *
390 * called when the end of an element has been detected.
391 */
392void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000393endElementDebug(void *ctx, const CHAR *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000394{
Daniel Veillard27d88741999-05-29 11:51:49 +0000395 fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000396}
397
398/**
399 * charactersDebug:
400 * @ctxt: An XML parser context
401 * @ch: a CHAR string
402 * @len: the number of CHAR
403 *
404 * receiving some chars from the parser.
405 * Question: how much at a time ???
406 */
407void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000408charactersDebug(void *ctx, const CHAR *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000409{
Daniel Veillarde2d034d1999-07-27 19:52:06 +0000410 int i;
411
412 fprintf(stdout, "SAX.characters(");
413 for (i = 0;(i < len) && (i < 30);i++)
414 fprintf(stdout, "%c", ch[i]);
415 fprintf(stdout, ", %d)\n", len);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000416}
417
418/**
419 * referenceDebug:
420 * @ctxt: An XML parser context
421 * @name: The entity name
422 *
423 * called when an entity reference is detected.
424 */
425void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000426referenceDebug(void *ctx, const CHAR *name)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000427{
Daniel Veillard27d88741999-05-29 11:51:49 +0000428 fprintf(stdout, "SAX.reference(%s)\n", name);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000429}
430
431/**
432 * ignorableWhitespaceDebug:
433 * @ctxt: An XML parser context
434 * @ch: a CHAR string
435 * @start: the first char in the string
436 * @len: the number of CHAR
437 *
438 * receiving some ignorable whitespaces from the parser.
439 * Question: how much at a time ???
440 */
441void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000442ignorableWhitespaceDebug(void *ctx, const CHAR *ch, int len)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000443{
Daniel Veillard27d88741999-05-29 11:51:49 +0000444 fprintf(stdout, "SAX.ignorableWhitespace(%.30s, %d)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000445 (char *) ch, len);
446}
447
448/**
449 * processingInstructionDebug:
450 * @ctxt: An XML parser context
451 * @target: the target name
452 * @data: the PI data's
453 * @len: the number of CHAR
454 *
455 * A processing instruction has been parsed.
456 */
457void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000458processingInstructionDebug(void *ctx, const CHAR *target,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000459 const CHAR *data)
460{
Daniel Veillard27d88741999-05-29 11:51:49 +0000461 fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
Daniel Veillard5099ae81999-04-21 20:12:07 +0000462 (char *) target, (char *) data);
463}
464
465/**
466 * commentDebug:
467 * @ctxt: An XML parser context
468 * @value: the comment content
469 *
470 * A comment has been parsed.
471 */
472void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000473commentDebug(void *ctx, const CHAR *value)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000474{
Daniel Veillard27d88741999-05-29 11:51:49 +0000475 fprintf(stdout, "SAX.comment(%s)\n", value);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000476}
477
478/**
479 * warningDebug:
480 * @ctxt: An XML parser context
481 * @msg: the message to display/transmit
482 * @...: extra parameters for the message display
483 *
484 * Display and format a warning messages, gives file, line, position and
485 * extra parameters.
486 */
487void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000488warningDebug(void *ctx, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000489{
490 va_list args;
491
492 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000493 fprintf(stdout, "SAX.warning: ");
494 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000495 va_end(args);
496}
497
498/**
499 * errorDebug:
500 * @ctxt: An XML parser context
501 * @msg: the message to display/transmit
502 * @...: extra parameters for the message display
503 *
504 * Display and format a error messages, gives file, line, position and
505 * extra parameters.
506 */
507void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000508errorDebug(void *ctx, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000509{
510 va_list args;
511
512 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000513 fprintf(stdout, "SAX.error: ");
514 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000515 va_end(args);
516}
517
518/**
519 * fatalErrorDebug:
520 * @ctxt: An XML parser context
521 * @msg: the message to display/transmit
522 * @...: extra parameters for the message display
523 *
524 * Display and format a fatalError messages, gives file, line, position and
525 * extra parameters.
526 */
527void
Daniel Veillardb96e6431999-08-29 21:02:19 +0000528fatalErrorDebug(void *ctx, const char *msg, ...)
Daniel Veillard5099ae81999-04-21 20:12:07 +0000529{
530 va_list args;
531
532 va_start(args, msg);
Daniel Veillard27d88741999-05-29 11:51:49 +0000533 fprintf(stdout, "SAX.fatalError: ");
534 vfprintf(stdout, msg, args);
Daniel Veillard5099ae81999-04-21 20:12:07 +0000535 va_end(args);
536}
537
538xmlSAXHandler debugSAXHandlerStruct = {
539 internalSubsetDebug,
540 isStandaloneDebug,
541 hasInternalSubsetDebug,
542 hasExternalSubsetDebug,
543 resolveEntityDebug,
544 getEntityDebug,
545 entityDeclDebug,
546 notationDeclDebug,
547 attributeDeclDebug,
548 elementDeclDebug,
549 unparsedEntityDeclDebug,
550 setDocumentLocatorDebug,
551 startDocumentDebug,
552 endDocumentDebug,
553 startElementDebug,
554 endElementDebug,
555 referenceDebug,
556 charactersDebug,
557 ignorableWhitespaceDebug,
558 processingInstructionDebug,
559 commentDebug,
560 warningDebug,
561 errorDebug,
562 fatalErrorDebug,
Daniel Veillardb05deb71999-08-10 19:04:08 +0000563 getParameterEntityDebug,
Daniel Veillard5099ae81999-04-21 20:12:07 +0000564};
565
566xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
567
568/************************************************************************
569 * *
570 * Debug *
571 * *
572 ************************************************************************/
573
574void parseAndPrintFile(char *filename) {
575 xmlDocPtr doc;
576
577 /*
578 * Empty callbacks for checking
579 */
580 doc = xmlSAXParseFile(emptySAXHandler, filename, 0);
581 if (doc != NULL) {
Daniel Veillard27d88741999-05-29 11:51:49 +0000582 fprintf(stdout, "xmlSAXParseFile returned non-NULL\n");
Daniel Veillard5099ae81999-04-21 20:12:07 +0000583 xmlDocDump(stdout, doc);
584 }
585
586 /*
587 * Debug callback
588 */
589 doc = xmlSAXParseFile(debugSAXHandler, filename, 0);
590 if (doc != NULL) {
591 fprintf(stderr, "xmlSAXParseFile returned non-NULL\n");
592 xmlDocDump(stdout, doc);
593 }
594}
595
596void parseAndPrintBuffer(CHAR *buf) {
597 xmlDocPtr doc;
598
599 /*
600 * Empty callbacks for checking
601 */
602 doc = xmlSAXParseDoc(emptySAXHandler, buf, 0);
603 if (doc != NULL) {
604 fprintf(stderr, "xmlSAXParseDoc returned non-NULL\n");
605 xmlDocDump(stdout, doc);
606 }
607
608 /*
609 * Debug callback
610 */
611 doc = xmlSAXParseDoc(debugSAXHandler, buf, 0);
612 if (doc != NULL) {
613 fprintf(stderr, "xmlSAXParseDoc returned non-NULL\n");
614 xmlDocDump(stdout, doc);
615 }
616}
617
618int main(int argc, char **argv) {
619 int i;
620 int files = 0;
621
622 for (i = 1; i < argc ; i++) {
623 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
624 debug++;
625 else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
626 copy++;
627 else if ((!strcmp(argv[i], "-recover")) ||
628 (!strcmp(argv[i], "--recover")))
629 recovery++;
630 }
631 for (i = 1; i < argc ; i++) {
632 if (argv[i][0] != '-') {
633 parseAndPrintFile(argv[i]);
634 files ++;
635 }
636 }
637 if (files == 0) {
638 printf("\nFirst test for the parser, with errors\n");
639 parseAndPrintBuffer(buffer);
640 }
641
642 return(0);
643}