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