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