blob: 8822fa3f187202ebdeac26f549ff196dbbf1cb82 [file] [log] [blame]
Daniel Veillardeae522a2001-04-23 13:41:34 +00001/*
2 * testDocbook.c : a small tester program for SGML Docbook input.
3 *
4 * See Copyright for the status of this software.
5 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00006 * daniel@veillard.com
Daniel Veillardeae522a2001-04-23 13:41:34 +00007 */
8
9#include "libxml.h"
10
11#ifdef LIBXML_DOCB_ENABLED
12
13#include <stdio.h>
14#include <string.h>
15#include <stdarg.h>
16
17
18#ifdef HAVE_SYS_TYPES_H
19#include <sys/types.h>
20#endif
21#ifdef HAVE_SYS_STAT_H
22#include <sys/stat.h>
23#endif
24#ifdef HAVE_FCNTL_H
25#include <fcntl.h>
26#endif
27#ifdef HAVE_UNISTD_H
28#include <unistd.h>
29#endif
30#ifdef HAVE_STDLIB_H
31#include <stdlib.h>
32#endif
33
34#include <libxml/xmlmemory.h>
35#include <libxml/DOCBparser.h>
36#include <libxml/tree.h>
37#include <libxml/debugXML.h>
38
39#ifdef LIBXML_DEBUG_ENABLED
40static int debug = 0;
41#endif
42static int copy = 0;
43static int sax = 0;
44static int repeat = 0;
45static int noout = 0;
Daniel Veillard61b33d52001-04-24 13:55:12 +000046static int noent = 0;
Daniel Veillardeae522a2001-04-23 13:41:34 +000047static int push = 0;
48static char *encoding = NULL;
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 */
75 NULL, /* getParameterEntity */
76 NULL, /* cdataBlock */
Daniel Veillardd0463562001-10-13 09:15:48 +000077 NULL, /* externalSubset */
78 1
Daniel Veillardeae522a2001-04-23 13:41:34 +000079};
80
81xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
82extern xmlSAXHandlerPtr debugSAXHandler;
83
84/************************************************************************
85 * *
86 * Debug Handlers *
87 * *
88 ************************************************************************/
89
90/**
91 * isStandaloneDebug:
92 * @ctxt: An XML parser context
93 *
94 * Is this document tagged standalone ?
95 *
96 * Returns 1 if true
97 */
98static int
99isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED)
100{
101 fprintf(stdout, "SAX.isStandalone()\n");
102 return(0);
103}
104
105/**
106 * hasInternalSubsetDebug:
107 * @ctxt: An XML parser context
108 *
109 * Does this document has an internal subset
110 *
111 * Returns 1 if true
112 */
113static int
114hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
115{
116 fprintf(stdout, "SAX.hasInternalSubset()\n");
117 return(0);
118}
119
120/**
121 * hasExternalSubsetDebug:
122 * @ctxt: An XML parser context
123 *
124 * Does this document has an external subset
125 *
126 * Returns 1 if true
127 */
128static int
129hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
130{
131 fprintf(stdout, "SAX.hasExternalSubset()\n");
132 return(0);
133}
134
135/**
136 * hasInternalSubsetDebug:
137 * @ctxt: An XML parser context
138 *
139 * Does this document has an internal subset
140 */
141static void
142internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
143 const xmlChar *ExternalID, const xmlChar *SystemID)
144{
145 fprintf(stdout, "SAX.internalSubset(%s,", name);
146 if (ExternalID == NULL)
147 fprintf(stdout, " ,");
148 else
149 fprintf(stdout, " %s,", ExternalID);
150 if (SystemID == NULL)
151 fprintf(stdout, " )\n");
152 else
153 fprintf(stdout, " %s)\n", SystemID);
154}
155
156/**
157 * resolveEntityDebug:
158 * @ctxt: An XML parser context
159 * @publicId: The public ID of the entity
160 * @systemId: The system ID of the entity
161 *
162 * Special entity resolver, better left to the parser, it has
163 * more context than the application layer.
164 * The default behaviour is to NOT resolve the entities, in that case
165 * the ENTITY_REF nodes are built in the structure (and the parameter
166 * values).
167 *
168 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
169 */
170static xmlParserInputPtr
171resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId)
172{
173 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
174
175
176 fprintf(stdout, "SAX.resolveEntity(");
177 if (publicId != NULL)
178 fprintf(stdout, "%s", (char *)publicId);
179 else
180 fprintf(stdout, " ");
181 if (systemId != NULL)
182 fprintf(stdout, ", %s)\n", (char *)systemId);
183 else
184 fprintf(stdout, ", )\n");
185/*********
186 if (systemId != NULL) {
187 return(xmlNewInputFromFile(ctxt, (char *) systemId));
188 }
189 *********/
190 return(NULL);
191}
192
193/**
194 * getEntityDebug:
195 * @ctxt: An XML parser context
196 * @name: The entity name
197 *
198 * Get an entity by name
199 *
200 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
201 */
202static xmlEntityPtr
203getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
204{
205 fprintf(stdout, "SAX.getEntity(%s)\n", name);
206 return(NULL);
207}
208
209/**
210 * getParameterEntityDebug:
211 * @ctxt: An XML parser context
212 * @name: The entity name
213 *
214 * Get a parameter entity by name
215 *
216 * Returns the xmlParserInputPtr
217 */
218static xmlEntityPtr
219getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
220{
221 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
222 return(NULL);
223}
224
225
226/**
227 * entityDeclDebug:
228 * @ctxt: An XML parser context
229 * @name: the entity name
230 * @type: the entity type
231 * @publicId: The public ID of the entity
232 * @systemId: The system ID of the entity
233 * @content: the entity value (without processing).
234 *
235 * An entity definition has been parsed
236 */
237static void
238entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
239 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
240{
241 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
242 name, type, publicId, systemId, content);
243}
244
245/**
246 * attributeDeclDebug:
247 * @ctxt: An XML parser context
248 * @name: the attribute name
249 * @type: the attribute type
250 *
251 * An attribute definition has been parsed
252 */
253static void
254attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *elem,
255 const xmlChar *name, int type, int def,
256 const xmlChar *defaultValue,
257 xmlEnumerationPtr tree ATTRIBUTE_UNUSED)
258{
259 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
260 elem, name, type, def, defaultValue);
261}
262
263/**
264 * elementDeclDebug:
265 * @ctxt: An XML parser context
266 * @name: the element name
267 * @type: the element type
268 * @content: the element value (without processing).
269 *
270 * An element definition has been parsed
271 */
272static void
273elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
274 xmlElementContentPtr content ATTRIBUTE_UNUSED)
275{
276 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
277 name, type);
278}
279
280/**
281 * notationDeclDebug:
282 * @ctxt: An XML parser context
283 * @name: The name of the notation
284 * @publicId: The public ID of the entity
285 * @systemId: The system ID of the entity
286 *
287 * What to do when a notation declaration has been parsed.
288 */
289static void
290notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
291 const xmlChar *publicId, const xmlChar *systemId)
292{
293 fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
294 (char *) name, (char *) publicId, (char *) systemId);
295}
296
297/**
298 * unparsedEntityDeclDebug:
299 * @ctxt: An XML parser context
300 * @name: The name of the entity
301 * @publicId: The public ID of the entity
302 * @systemId: The system ID of the entity
303 * @notationName: the name of the notation
304 *
305 * What to do when an unparsed entity declaration is parsed
306 */
307static void
308unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
309 const xmlChar *publicId, const xmlChar *systemId,
310 const xmlChar *notationName)
311{
312 fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
313 (char *) name, (char *) publicId, (char *) systemId,
314 (char *) notationName);
315}
316
317/**
318 * setDocumentLocatorDebug:
319 * @ctxt: An XML parser context
320 * @loc: A SAX Locator
321 *
322 * Receive the document locator at startup, actually xmlDefaultSAXLocator
323 * Everything is available on the context, so this is useless in our case.
324 */
325static void
326setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED,
327 xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
328{
329 fprintf(stdout, "SAX.setDocumentLocator()\n");
330}
331
332/**
333 * startDocumentDebug:
334 * @ctxt: An XML parser context
335 *
336 * called when the document start being processed.
337 */
338static void
339startDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
340{
341 fprintf(stdout, "SAX.startDocument()\n");
342}
343
344/**
345 * endDocumentDebug:
346 * @ctxt: An XML parser context
347 *
348 * called when the document end has been detected.
349 */
350static void
351endDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
352{
353 fprintf(stdout, "SAX.endDocument()\n");
354}
355
356/**
357 * startElementDebug:
358 * @ctxt: An XML parser context
359 * @name: The element name
360 *
361 * called when an opening tag has been processed.
362 */
363static void
364startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts)
365{
366 int i;
367
368 fprintf(stdout, "SAX.startElement(%s", (char *) name);
369 if (atts != NULL) {
370 for (i = 0;(atts[i] != NULL);i++) {
371 fprintf(stdout, ", %s", atts[i++]);
372 if (atts[i] != NULL) {
373 unsigned char output[40];
374 const unsigned char *att = atts[i];
375 int outlen, attlen;
376 fprintf(stdout, "='");
377 while ((attlen = strlen((char*)att)) > 0) {
378 outlen = sizeof output - 1;
379 docbEncodeEntities(output, &outlen, att, &attlen, '\'');
380 fprintf(stdout, "%.*s", outlen, output);
381 att += attlen;
382 }
383 fprintf(stdout, "'");
384 }
385 }
386 }
387 fprintf(stdout, ")\n");
388}
389
390/**
391 * endElementDebug:
392 * @ctxt: An XML parser context
393 * @name: The element name
394 *
395 * called when the end of an element has been detected.
396 */
397static void
398endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
399{
400 fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
401}
402
403/**
404 * charactersDebug:
405 * @ctxt: An XML parser context
406 * @ch: a xmlChar string
407 * @len: the number of xmlChar
408 *
409 * receiving some chars from the parser.
410 * Question: how much at a time ???
411 */
412static void
413charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
414{
415 unsigned char output[40];
416 int inlen = len, outlen = 30;
417
418 docbEncodeEntities(output, &outlen, ch, &inlen, 0);
419 output[outlen] = 0;
420
421 fprintf(stdout, "SAX.characters(%s, %d)\n", output, len);
422}
423
424/**
425 * referenceDebug:
426 * @ctxt: An XML parser context
427 * @name: The entity name
428 *
429 * called when an entity reference is detected.
430 */
431static void
432referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
433{
434 fprintf(stdout, "SAX.reference(%s)\n", name);
435}
436
437/**
438 * ignorableWhitespaceDebug:
439 * @ctxt: An XML parser context
440 * @ch: a xmlChar string
441 * @start: the first char in the string
442 * @len: the number of xmlChar
443 *
444 * receiving some ignorable whitespaces from the parser.
445 * Question: how much at a time ???
446 */
447static void
448ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
449{
450 char output[40];
451 int i;
452
453 for (i = 0;(i<len) && (i < 30);i++)
454 output[i] = ch[i];
455 output[i] = 0;
456
457 fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len);
458}
459
460/**
461 * processingInstructionDebug:
462 * @ctxt: An XML parser context
463 * @target: the target name
464 * @data: the PI data's
465 * @len: the number of xmlChar
466 *
467 * A processing instruction has been parsed.
468 */
469static void
470processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target,
471 const xmlChar *data)
472{
473 fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
474 (char *) target, (char *) data);
475}
476
477/**
478 * commentDebug:
479 * @ctxt: An XML parser context
480 * @value: the comment content
481 *
482 * A comment has been parsed.
483 */
484static void
485commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value)
486{
487 fprintf(stdout, "SAX.comment(%s)\n", value);
488}
489
490/**
491 * cdataBlockDebug:
492 * @ctx: the user data (XML parser context)
493 * @value: The pcdata content
494 * @len: the block length
495 *
496 * called when a pcdata block has been parsed
497 */
498static void
499cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len)
500{
501 fprintf(stdout, "SAX.pcdata(%.20s, %d)\n",
502 (char *) value, len);
503}
504
505/**
506 * externalSubsetDebug:
507 * @ctxt: An XML parser context
508 *
509 * Does this document has an external subset
510 */
511static void
512externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
513 const xmlChar *ExternalID, const xmlChar *SystemID)
514{
515 fprintf(stdout, "SAX.externalSubset(%s,", name);
516 if (ExternalID == NULL)
517 fprintf(stdout, " ,");
518 else
519 fprintf(stdout, " %s,", ExternalID);
520 if (SystemID == NULL)
521 fprintf(stdout, " )\n");
522 else
523 fprintf(stdout, " %s)\n", SystemID);
524}
525
526/**
527 * warningDebug:
528 * @ctxt: An XML parser context
529 * @msg: the message to display/transmit
530 * @...: extra parameters for the message display
531 *
532 * Display and format a warning messages, gives file, line, position and
533 * extra parameters.
534 */
535static void
536warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
537{
538 va_list args;
539
540 va_start(args, msg);
541 fprintf(stdout, "SAX.warning: ");
542 vfprintf(stdout, msg, args);
543 va_end(args);
544}
545
546/**
547 * errorDebug:
548 * @ctxt: An XML parser context
549 * @msg: the message to display/transmit
550 * @...: extra parameters for the message display
551 *
552 * Display and format a error messages, gives file, line, position and
553 * extra parameters.
554 */
555static void
556errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
557{
558 va_list args;
559
560 va_start(args, msg);
561 fprintf(stdout, "SAX.error: ");
562 vfprintf(stdout, msg, args);
563 va_end(args);
564}
565
566/**
567 * fatalErrorDebug:
568 * @ctxt: An XML parser context
569 * @msg: the message to display/transmit
570 * @...: extra parameters for the message display
571 *
572 * Display and format a fatalError messages, gives file, line, position and
573 * extra parameters.
574 */
575static void
576fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
577{
578 va_list args;
579
580 va_start(args, msg);
581 fprintf(stdout, "SAX.fatalError: ");
582 vfprintf(stdout, msg, args);
583 va_end(args);
584}
585
586xmlSAXHandler debugSAXHandlerStruct = {
587 internalSubsetDebug,
588 isStandaloneDebug,
589 hasInternalSubsetDebug,
590 hasExternalSubsetDebug,
591 resolveEntityDebug,
592 getEntityDebug,
593 entityDeclDebug,
594 notationDeclDebug,
595 attributeDeclDebug,
596 elementDeclDebug,
597 unparsedEntityDeclDebug,
598 setDocumentLocatorDebug,
599 startDocumentDebug,
600 endDocumentDebug,
601 startElementDebug,
602 endElementDebug,
603 referenceDebug,
604 charactersDebug,
605 ignorableWhitespaceDebug,
606 processingInstructionDebug,
607 commentDebug,
608 warningDebug,
609 errorDebug,
610 fatalErrorDebug,
611 getParameterEntityDebug,
612 cdataBlockDebug,
Daniel Veillardd0463562001-10-13 09:15:48 +0000613 externalSubsetDebug,
614 1
Daniel Veillardeae522a2001-04-23 13:41:34 +0000615};
616
617xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
618/************************************************************************
619 * *
620 * Debug *
621 * *
622 ************************************************************************/
623
624static void
625parseSAXFile(char *filename) {
626 docbDocPtr doc = NULL;
627
628 /*
629 * Empty callbacks for checking
630 */
631 if (push) {
632 FILE *f;
633
634 f = fopen(filename, "r");
635 if (f != NULL) {
636 int res, size = 3;
637 char chars[4096];
638 docbParserCtxtPtr ctxt;
639
640 /* if (repeat) */
641 size = 4096;
642 res = fread(chars, 1, 4, f);
643 if (res > 0) {
644 ctxt = docbCreatePushParserCtxt(emptySAXHandler, NULL,
645 chars, res, filename, 0);
646 while ((res = fread(chars, 1, size, f)) > 0) {
647 docbParseChunk(ctxt, chars, res, 0);
648 }
649 docbParseChunk(ctxt, chars, 0, 1);
650 doc = ctxt->myDoc;
651 docbFreeParserCtxt(ctxt);
652 }
653 if (doc != NULL) {
654 fprintf(stdout, "sgmlSAXParseFile returned non-NULL\n");
655 xmlFreeDoc(doc);
656 }
657 fclose(f);
658 }
659 if (!noout) {
660 f = fopen(filename, "r");
661 if (f != NULL) {
662 int res, size = 3;
663 char chars[4096];
664 docbParserCtxtPtr ctxt;
665
666 /* if (repeat) */
667 size = 4096;
668 res = fread(chars, 1, 4, f);
669 if (res > 0) {
670 ctxt = docbCreatePushParserCtxt(debugSAXHandler, NULL,
671 chars, res, filename, 0);
672 while ((res = fread(chars, 1, size, f)) > 0) {
673 docbParseChunk(ctxt, chars, res, 0);
674 }
675 docbParseChunk(ctxt, chars, 0, 1);
676 doc = ctxt->myDoc;
677 docbFreeParserCtxt(ctxt);
678 }
679 if (doc != NULL) {
680 fprintf(stdout, "sgmlSAXParseFile returned non-NULL\n");
681 xmlFreeDoc(doc);
682 }
683 fclose(f);
684 }
685 }
686 } else {
687 doc = docbSAXParseFile(filename, NULL, emptySAXHandler, NULL);
688 if (doc != NULL) {
689 fprintf(stdout, "sgmlSAXParseFile returned non-NULL\n");
690 xmlFreeDoc(doc);
691 }
692
693 if (!noout) {
694 /*
695 * Debug callback
696 */
697 doc = docbSAXParseFile(filename, NULL, debugSAXHandler, NULL);
698 if (doc != NULL) {
699 fprintf(stdout, "sgmlSAXParseFile returned non-NULL\n");
700 xmlFreeDoc(doc);
701 }
702 }
703 }
704}
705
706static void
707parseAndPrintFile(char *filename) {
708 docbDocPtr doc = NULL, tmp;
709
710 /*
711 * build an SGML tree from a string;
712 */
713 if (push) {
714 FILE *f;
715
716 f = fopen(filename, "r");
717 if (f != NULL) {
718 int res, size = 3;
719 char chars[4096];
720 docbParserCtxtPtr ctxt;
721
722 /* if (repeat) */
723 size = 4096;
724 res = fread(chars, 1, 4, f);
725 if (res > 0) {
726 ctxt = docbCreatePushParserCtxt(NULL, NULL,
727 chars, res, filename, 0);
728 while ((res = fread(chars, 1, size, f)) > 0) {
729 docbParseChunk(ctxt, chars, res, 0);
730 }
731 docbParseChunk(ctxt, chars, 0, 1);
732 doc = ctxt->myDoc;
733 docbFreeParserCtxt(ctxt);
734 }
735 fclose(f);
736 }
737 } else {
738 doc = docbParseFile(filename, NULL);
739 }
740 if (doc == NULL) {
741 fprintf(stderr, "Could not parse %s\n", filename);
742 }
743
744 /*
745 * test intermediate copy if needed.
746 */
747 if (copy) {
748 tmp = doc;
749 doc = xmlCopyDoc(doc, 1);
750 xmlFreeDoc(tmp);
751 }
752
753 /*
754 * print it.
755 */
756 if (!noout) {
757#ifdef LIBXML_DEBUG_ENABLED
758 if (!debug) {
759 if (encoding)
760 xmlSaveFileEnc("-", doc, encoding);
761 else
762 xmlDocDump(stdout, doc);
763 } else
764 xmlDebugDumpDocument(stdout, doc);
765#else
766 if (encoding)
767 xmlSaveFileEnc("-", doc, encoding);
768 else
769 xmlDocDump(stdout, doc);
770#endif
771 }
772
773 /*
774 * free it.
775 */
776 xmlFreeDoc(doc);
777}
778
779int main(int argc, char **argv) {
780 int i, count;
781 int files = 0;
782
783 for (i = 1; i < argc ; i++) {
784#ifdef LIBXML_DEBUG_ENABLED
785 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
786 debug++;
787 else
788#endif
789 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
790 copy++;
791 else if ((!strcmp(argv[i], "-push")) || (!strcmp(argv[i], "--push")))
792 push++;
793 else if ((!strcmp(argv[i], "-sax")) || (!strcmp(argv[i], "--sax")))
794 sax++;
Daniel Veillard61b33d52001-04-24 13:55:12 +0000795 else if ((!strcmp(argv[i], "-noent")) || (!strcmp(argv[i], "--noent")))
796 noent++;
Daniel Veillardeae522a2001-04-23 13:41:34 +0000797 else if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout")))
798 noout++;
799 else if ((!strcmp(argv[i], "-repeat")) ||
800 (!strcmp(argv[i], "--repeat")))
801 repeat++;
802 else if ((!strcmp(argv[i], "-encode")) ||
803 (!strcmp(argv[i], "--encode"))) {
804 i++;
805 encoding = argv[i];
806 }
807 }
Daniel Veillard61b33d52001-04-24 13:55:12 +0000808 if (noent != 0) xmlSubstituteEntitiesDefault(1);
Daniel Veillardeae522a2001-04-23 13:41:34 +0000809 for (i = 1; i < argc ; i++) {
810 if ((!strcmp(argv[i], "-encode")) ||
811 (!strcmp(argv[i], "--encode"))) {
812 i++;
813 continue;
814 }
815 if (argv[i][0] != '-') {
816 if (repeat) {
817 for (count = 0;count < 100 * repeat;count++) {
818 if (sax)
819 parseSAXFile(argv[i]);
820 else
821 parseAndPrintFile(argv[i]);
822 }
823 } else {
824 if (sax)
825 parseSAXFile(argv[i]);
826 else
827 parseAndPrintFile(argv[i]);
828 }
829 files ++;
830 }
831 }
832 if (files == 0) {
833 printf("Usage : %s [--debug] [--copy] [--copy] SGMLfiles ...\n",
834 argv[0]);
835 printf("\tParse the Docbook files and output the result of the parsing\n");
836#ifdef LIBXML_DEBUG_ENABLED
837 printf("\t--debug : dump a debug tree of the in-memory document\n");
838#endif
839 printf("\t--copy : used to test the internal copy implementation\n");
840 printf("\t--sax : debug the sequence of SAX callbacks\n");
841 printf("\t--repeat : parse the file 100 times, for timing\n");
842 printf("\t--noout : do not print the result\n");
843 printf("\t--push : use the push mode parser\n");
844 printf("\t--encode encoding : output in the given encoding\n");
845 }
846 xmlCleanupParser();
847 xmlMemoryDump();
848
849 return(0);
850}
851#else /* !LIBXML_DOCB_ENABLED */
852#include <stdio.h>
853int main(int argc, char **argv) {
854 printf("%s : SGML support not compiled in\n", argv[0]);
855 return(0);
856}
857#endif