blob: 85e2e82dea068bcc82ada97604b755c81aa4018b [file] [log] [blame]
Daniel Veillardbe70ff71999-07-05 16:50:46 +00001/*
2 * testHTML.c : a small tester program for HTML input.
3 *
4 * See Copyright for the status of this software.
5 *
6 * Daniel.Veillard@w3.org
7 */
8
9#ifdef WIN32
Daniel Veillard3c558c31999-12-22 11:30:41 +000010#include "win32config.h"
Daniel Veillardbe70ff71999-07-05 16:50:46 +000011#else
Daniel Veillard7f7d1111999-09-22 09:46:25 +000012#include "config.h"
Daniel Veillardbe70ff71999-07-05 16:50:46 +000013#endif
Daniel Veillard7f7d1111999-09-22 09:46:25 +000014
Daniel Veillard361d8452000-04-03 19:48:13 +000015#include "xmlversion.h"
16#ifdef LIBXML_HTML_ENABLED
17
Daniel Veillard7f7d1111999-09-22 09:46:25 +000018#include <stdio.h>
19#include <string.h>
Daniel Veillard7c1206f1999-10-14 09:10:25 +000020#include <stdarg.h>
21
Daniel Veillard7f7d1111999-09-22 09:46:25 +000022
23#ifdef HAVE_SYS_TYPES_H
Daniel Veillardbe70ff71999-07-05 16:50:46 +000024#include <sys/types.h>
Daniel Veillard7f7d1111999-09-22 09:46:25 +000025#endif
Daniel Veillardbe70ff71999-07-05 16:50:46 +000026#ifdef HAVE_SYS_STAT_H
27#include <sys/stat.h>
28#endif
29#ifdef HAVE_FCNTL_H
30#include <fcntl.h>
31#endif
32#ifdef HAVE_UNISTD_H
33#include <unistd.h>
34#endif
Daniel Veillard7f7d1111999-09-22 09:46:25 +000035#ifdef HAVE_STDLIB_H
Daniel Veillardbe70ff71999-07-05 16:50:46 +000036#include <stdlib.h>
Daniel Veillard7f7d1111999-09-22 09:46:25 +000037#endif
Daniel Veillardbe70ff71999-07-05 16:50:46 +000038
Daniel Veillard361d8452000-04-03 19:48:13 +000039#include <libxml/xmlmemory.h>
40#include <libxml/HTMLparser.h>
41#include <libxml/HTMLtree.h>
42#include <libxml/debugXML.h>
Daniel Veillardbe70ff71999-07-05 16:50:46 +000043
Daniel Veillard361d8452000-04-03 19:48:13 +000044#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardbe70ff71999-07-05 16:50:46 +000045static int debug = 0;
Daniel Veillard361d8452000-04-03 19:48:13 +000046#endif
Daniel Veillardbe70ff71999-07-05 16:50:46 +000047static int copy = 0;
Daniel Veillard7c1206f1999-10-14 09:10:25 +000048static int sax = 0;
49static int repeat = 0;
50static int noout = 0;
Daniel Veillard5e5c6231999-12-29 12:49:06 +000051static int push = 0;
Daniel Veillard32bc74e2000-07-14 14:49:25 +000052static char *encoding = NULL;
Daniel Veillardbe70ff71999-07-05 16:50:46 +000053
Daniel Veillard7c1206f1999-10-14 09:10:25 +000054xmlSAXHandler emptySAXHandlerStruct = {
55 NULL, /* internalSubset */
56 NULL, /* isStandalone */
57 NULL, /* hasInternalSubset */
58 NULL, /* hasExternalSubset */
59 NULL, /* resolveEntity */
60 NULL, /* getEntity */
61 NULL, /* entityDecl */
62 NULL, /* notationDecl */
63 NULL, /* attributeDecl */
64 NULL, /* elementDecl */
65 NULL, /* unparsedEntityDecl */
66 NULL, /* setDocumentLocator */
67 NULL, /* startDocument */
68 NULL, /* endDocument */
69 NULL, /* startElement */
70 NULL, /* endElement */
71 NULL, /* reference */
72 NULL, /* characters */
73 NULL, /* ignorableWhitespace */
74 NULL, /* processingInstruction */
75 NULL, /* comment */
76 NULL, /* xmlParserWarning */
77 NULL, /* xmlParserError */
78 NULL, /* xmlParserError */
79 NULL, /* getParameterEntity */
80};
81
82xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
83extern xmlSAXHandlerPtr debugSAXHandler;
84
85/************************************************************************
86 * *
87 * Debug Handlers *
88 * *
89 ************************************************************************/
90
91/**
92 * isStandaloneDebug:
93 * @ctxt: An XML parser context
94 *
95 * Is this document tagged standalone ?
96 *
97 * Returns 1 if true
98 */
99int
100isStandaloneDebug(void *ctx)
101{
102 fprintf(stdout, "SAX.isStandalone()\n");
103 return(0);
104}
105
106/**
107 * hasInternalSubsetDebug:
108 * @ctxt: An XML parser context
109 *
110 * Does this document has an internal subset
111 *
112 * Returns 1 if true
113 */
114int
115hasInternalSubsetDebug(void *ctx)
116{
117 fprintf(stdout, "SAX.hasInternalSubset()\n");
118 return(0);
119}
120
121/**
122 * hasExternalSubsetDebug:
123 * @ctxt: An XML parser context
124 *
125 * Does this document has an external subset
126 *
127 * Returns 1 if true
128 */
129int
130hasExternalSubsetDebug(void *ctx)
131{
132 fprintf(stdout, "SAX.hasExternalSubset()\n");
133 return(0);
134}
135
136/**
137 * hasInternalSubsetDebug:
138 * @ctxt: An XML parser context
139 *
140 * Does this document has an internal subset
141 */
142void
143internalSubsetDebug(void *ctx, const xmlChar *name,
144 const xmlChar *ExternalID, const xmlChar *SystemID)
145{
146 /* xmlDtdPtr externalSubset; */
147
148 fprintf(stdout, "SAX.internalSubset(%s, %s, %s)\n",
149 name, ExternalID, SystemID);
150
151/***********
152 if ((ExternalID != NULL) || (SystemID != NULL)) {
153 externalSubset = xmlParseDTD(ExternalID, SystemID);
154 if (externalSubset != NULL) {
155 xmlFreeDtd(externalSubset);
156 }
157 }
158 ***********/
159}
160
161/**
162 * resolveEntityDebug:
163 * @ctxt: An XML parser context
164 * @publicId: The public ID of the entity
165 * @systemId: The system ID of the entity
166 *
167 * Special entity resolver, better left to the parser, it has
168 * more context than the application layer.
169 * The default behaviour is to NOT resolve the entities, in that case
170 * the ENTITY_REF nodes are built in the structure (and the parameter
171 * values).
172 *
173 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
174 */
175xmlParserInputPtr
176resolveEntityDebug(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
177{
178 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
179
180
181 fprintf(stdout, "SAX.resolveEntity(");
182 if (publicId != NULL)
183 fprintf(stdout, "%s", (char *)publicId);
184 else
185 fprintf(stdout, " ");
186 if (systemId != NULL)
187 fprintf(stdout, ", %s)\n", (char *)systemId);
188 else
189 fprintf(stdout, ", )\n");
190/*********
191 if (systemId != NULL) {
192 return(xmlNewInputFromFile(ctxt, (char *) systemId));
193 }
194 *********/
195 return(NULL);
196}
197
198/**
199 * getEntityDebug:
200 * @ctxt: An XML parser context
201 * @name: The entity name
202 *
203 * Get an entity by name
204 *
205 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
206 */
207xmlEntityPtr
208getEntityDebug(void *ctx, const xmlChar *name)
209{
210 fprintf(stdout, "SAX.getEntity(%s)\n", name);
211 return(NULL);
212}
213
214/**
215 * getParameterEntityDebug:
216 * @ctxt: An XML parser context
217 * @name: The entity name
218 *
219 * Get a parameter entity by name
220 *
221 * Returns the xmlParserInputPtr
222 */
223xmlEntityPtr
224getParameterEntityDebug(void *ctx, const xmlChar *name)
225{
226 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
227 return(NULL);
228}
229
230
231/**
232 * entityDeclDebug:
233 * @ctxt: An XML parser context
234 * @name: the entity name
235 * @type: the entity type
236 * @publicId: The public ID of the entity
237 * @systemId: The system ID of the entity
238 * @content: the entity value (without processing).
239 *
240 * An entity definition has been parsed
241 */
242void
243entityDeclDebug(void *ctx, const xmlChar *name, int type,
244 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
245{
246 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
247 name, type, publicId, systemId, content);
248}
249
250/**
251 * attributeDeclDebug:
252 * @ctxt: An XML parser context
253 * @name: the attribute name
254 * @type: the attribute type
255 *
256 * An attribute definition has been parsed
257 */
258void
259attributeDeclDebug(void *ctx, const xmlChar *elem, const xmlChar *name,
260 int type, int def, const xmlChar *defaultValue,
261 xmlEnumerationPtr tree)
262{
263 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
264 elem, name, type, def, defaultValue);
265}
266
267/**
268 * elementDeclDebug:
269 * @ctxt: An XML parser context
270 * @name: the element name
271 * @type: the element type
272 * @content: the element value (without processing).
273 *
274 * An element definition has been parsed
275 */
276void
277elementDeclDebug(void *ctx, const xmlChar *name, int type,
278 xmlElementContentPtr content)
279{
280 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
281 name, type);
282}
283
284/**
285 * notationDeclDebug:
286 * @ctxt: An XML parser context
287 * @name: The name of the notation
288 * @publicId: The public ID of the entity
289 * @systemId: The system ID of the entity
290 *
291 * What to do when a notation declaration has been parsed.
292 */
293void
294notationDeclDebug(void *ctx, const xmlChar *name,
295 const xmlChar *publicId, const xmlChar *systemId)
296{
297 fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
298 (char *) name, (char *) publicId, (char *) systemId);
299}
300
301/**
302 * unparsedEntityDeclDebug:
303 * @ctxt: An XML parser context
304 * @name: The name of the entity
305 * @publicId: The public ID of the entity
306 * @systemId: The system ID of the entity
307 * @notationName: the name of the notation
308 *
309 * What to do when an unparsed entity declaration is parsed
310 */
311void
312unparsedEntityDeclDebug(void *ctx, const xmlChar *name,
313 const xmlChar *publicId, const xmlChar *systemId,
314 const xmlChar *notationName)
315{
316 fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
317 (char *) name, (char *) publicId, (char *) systemId,
318 (char *) notationName);
319}
320
321/**
322 * setDocumentLocatorDebug:
323 * @ctxt: An XML parser context
324 * @loc: A SAX Locator
325 *
326 * Receive the document locator at startup, actually xmlDefaultSAXLocator
327 * Everything is available on the context, so this is useless in our case.
328 */
329void
330setDocumentLocatorDebug(void *ctx, xmlSAXLocatorPtr loc)
331{
332 fprintf(stdout, "SAX.setDocumentLocator()\n");
333}
334
335/**
336 * startDocumentDebug:
337 * @ctxt: An XML parser context
338 *
339 * called when the document start being processed.
340 */
341void
342startDocumentDebug(void *ctx)
343{
344 fprintf(stdout, "SAX.startDocument()\n");
345}
346
347/**
348 * endDocumentDebug:
349 * @ctxt: An XML parser context
350 *
351 * called when the document end has been detected.
352 */
353void
354endDocumentDebug(void *ctx)
355{
356 fprintf(stdout, "SAX.endDocument()\n");
357}
358
359/**
360 * startElementDebug:
361 * @ctxt: An XML parser context
362 * @name: The element name
363 *
364 * called when an opening tag has been processed.
365 */
366void
367startElementDebug(void *ctx, const xmlChar *name, const xmlChar **atts)
368{
369 int i;
370
371 fprintf(stdout, "SAX.startElement(%s", (char *) name);
372 if (atts != NULL) {
373 for (i = 0;(atts[i] != NULL);i++) {
374 fprintf(stdout, ", %s='", atts[i++]);
375 fprintf(stdout, "%s'", atts[i]);
376 }
377 }
378 fprintf(stdout, ")\n");
379}
380
381/**
382 * endElementDebug:
383 * @ctxt: An XML parser context
384 * @name: The element name
385 *
386 * called when the end of an element has been detected.
387 */
388void
389endElementDebug(void *ctx, const xmlChar *name)
390{
391 fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
392}
393
394/**
395 * charactersDebug:
396 * @ctxt: An XML parser context
397 * @ch: a xmlChar string
398 * @len: the number of xmlChar
399 *
400 * receiving some chars from the parser.
401 * Question: how much at a time ???
402 */
403void
404charactersDebug(void *ctx, const xmlChar *ch, int len)
405{
Daniel Veillard87b95392000-08-12 21:12:04 +0000406 char output[40];
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000407 int i;
408
Daniel Veillard87b95392000-08-12 21:12:04 +0000409 for (i = 0;(i<len) && (i < 30);i++)
410 output[i] = ch[i];
411 output[i] = 0;
412
413 fprintf(stdout, "SAX.characters(%s, %d)\n", output, len);
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000414}
415
416/**
417 * referenceDebug:
418 * @ctxt: An XML parser context
419 * @name: The entity name
420 *
421 * called when an entity reference is detected.
422 */
423void
424referenceDebug(void *ctx, const xmlChar *name)
425{
426 fprintf(stdout, "SAX.reference(%s)\n", name);
427}
428
429/**
430 * ignorableWhitespaceDebug:
431 * @ctxt: An XML parser context
432 * @ch: a xmlChar string
433 * @start: the first char in the string
434 * @len: the number of xmlChar
435 *
436 * receiving some ignorable whitespaces from the parser.
437 * Question: how much at a time ???
438 */
439void
440ignorableWhitespaceDebug(void *ctx, const xmlChar *ch, int len)
441{
Daniel Veillard87b95392000-08-12 21:12:04 +0000442 char output[40];
443 int i;
444
445 for (i = 0;(i<len) && (i < 30);i++)
446 output[i] = ch[i];
447 output[i] = 0;
448
449 fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len);
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000450}
451
452/**
453 * processingInstructionDebug:
454 * @ctxt: An XML parser context
455 * @target: the target name
456 * @data: the PI data's
457 * @len: the number of xmlChar
458 *
459 * A processing instruction has been parsed.
460 */
461void
462processingInstructionDebug(void *ctx, const xmlChar *target,
463 const xmlChar *data)
464{
465 fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
466 (char *) target, (char *) data);
467}
468
469/**
470 * commentDebug:
471 * @ctxt: An XML parser context
472 * @value: the comment content
473 *
474 * A comment has been parsed.
475 */
476void
477commentDebug(void *ctx, const xmlChar *value)
478{
479 fprintf(stdout, "SAX.comment(%s)\n", value);
480}
481
482/**
483 * warningDebug:
484 * @ctxt: An XML parser context
485 * @msg: the message to display/transmit
486 * @...: extra parameters for the message display
487 *
488 * Display and format a warning messages, gives file, line, position and
489 * extra parameters.
490 */
491void
492warningDebug(void *ctx, const char *msg, ...)
493{
494 va_list args;
495
496 va_start(args, msg);
497 fprintf(stdout, "SAX.warning: ");
498 vfprintf(stdout, msg, args);
499 va_end(args);
500}
501
502/**
503 * errorDebug:
504 * @ctxt: An XML parser context
505 * @msg: the message to display/transmit
506 * @...: extra parameters for the message display
507 *
508 * Display and format a error messages, gives file, line, position and
509 * extra parameters.
510 */
511void
512errorDebug(void *ctx, const char *msg, ...)
513{
514 va_list args;
515
516 va_start(args, msg);
517 fprintf(stdout, "SAX.error: ");
518 vfprintf(stdout, msg, args);
519 va_end(args);
520}
521
522/**
523 * fatalErrorDebug:
524 * @ctxt: An XML parser context
525 * @msg: the message to display/transmit
526 * @...: extra parameters for the message display
527 *
528 * Display and format a fatalError messages, gives file, line, position and
529 * extra parameters.
530 */
531void
532fatalErrorDebug(void *ctx, const char *msg, ...)
533{
534 va_list args;
535
536 va_start(args, msg);
537 fprintf(stdout, "SAX.fatalError: ");
538 vfprintf(stdout, msg, args);
539 va_end(args);
540}
541
542xmlSAXHandler debugSAXHandlerStruct = {
543 internalSubsetDebug,
544 isStandaloneDebug,
545 hasInternalSubsetDebug,
546 hasExternalSubsetDebug,
547 resolveEntityDebug,
548 getEntityDebug,
549 entityDeclDebug,
550 notationDeclDebug,
551 attributeDeclDebug,
552 elementDeclDebug,
553 unparsedEntityDeclDebug,
554 setDocumentLocatorDebug,
555 startDocumentDebug,
556 endDocumentDebug,
557 startElementDebug,
558 endElementDebug,
559 referenceDebug,
560 charactersDebug,
561 ignorableWhitespaceDebug,
562 processingInstructionDebug,
563 commentDebug,
564 warningDebug,
565 errorDebug,
566 fatalErrorDebug,
567 getParameterEntityDebug,
568};
569
570xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000571/************************************************************************
572 * *
573 * Debug *
574 * *
575 ************************************************************************/
576
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000577void parseSAXFile(char *filename) {
578 htmlDocPtr doc;
579 /*
580 * Empty callbacks for checking
581 */
Daniel Veillard87b95392000-08-12 21:12:04 +0000582 if (push) {
583 FILE *f;
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000584
Daniel Veillard87b95392000-08-12 21:12:04 +0000585 f = fopen(filename, "r");
586 if (f != NULL) {
587 int res, size = 3;
588 char chars[4096];
589 htmlParserCtxtPtr ctxt;
590
591 /* if (repeat) */
592 size = 4096;
593 res = fread(chars, 1, 4, f);
594 if (res > 0) {
595 ctxt = htmlCreatePushParserCtxt(emptySAXHandler, NULL,
596 chars, res, filename, 0);
597 while ((res = fread(chars, 1, size, f)) > 0) {
598 htmlParseChunk(ctxt, chars, res, 0);
599 }
600 htmlParseChunk(ctxt, chars, 0, 1);
601 doc = ctxt->myDoc;
602 htmlFreeParserCtxt(ctxt);
603 }
604 if (doc != NULL) {
605 fprintf(stdout, "htmlSAXParseFile returned non-NULL\n");
606 xmlFreeDoc(doc);
607 }
608 fclose(f);
609 }
610 if (!noout) {
611 f = fopen(filename, "r");
612 if (f != NULL) {
613 int res, size = 3;
614 char chars[4096];
615 htmlParserCtxtPtr ctxt;
616
617 /* if (repeat) */
618 size = 4096;
619 res = fread(chars, 1, 4, f);
620 if (res > 0) {
621 ctxt = htmlCreatePushParserCtxt(debugSAXHandler, NULL,
622 chars, res, filename, 0);
623 while ((res = fread(chars, 1, size, f)) > 0) {
624 htmlParseChunk(ctxt, chars, res, 0);
625 }
626 htmlParseChunk(ctxt, chars, 0, 1);
627 doc = ctxt->myDoc;
628 htmlFreeParserCtxt(ctxt);
629 }
630 if (doc != NULL) {
631 fprintf(stdout, "htmlSAXParseFile returned non-NULL\n");
632 xmlFreeDoc(doc);
633 }
634 fclose(f);
635 }
636 }
637 } else {
638 doc = htmlSAXParseFile(filename, NULL, emptySAXHandler, NULL);
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000639 if (doc != NULL) {
640 fprintf(stdout, "htmlSAXParseFile returned non-NULL\n");
641 xmlFreeDoc(doc);
642 }
Daniel Veillard87b95392000-08-12 21:12:04 +0000643
644 if (!noout) {
645 /*
646 * Debug callback
647 */
648 doc = htmlSAXParseFile(filename, NULL, debugSAXHandler, NULL);
649 if (doc != NULL) {
650 fprintf(stdout, "htmlSAXParseFile returned non-NULL\n");
651 xmlFreeDoc(doc);
652 }
653 }
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000654 }
655}
656
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000657void parseAndPrintFile(char *filename) {
Daniel Veillard2eac5032000-01-09 21:08:56 +0000658 htmlDocPtr doc = NULL, tmp;
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000659
660 /*
661 * build an HTML tree from a string;
662 */
Daniel Veillard5e5c6231999-12-29 12:49:06 +0000663 if (push) {
664 FILE *f;
665
666 f = fopen(filename, "r");
667 if (f != NULL) {
668 int res, size = 3;
Daniel Veillard87b95392000-08-12 21:12:04 +0000669 char chars[4096];
Daniel Veillard5e5c6231999-12-29 12:49:06 +0000670 htmlParserCtxtPtr ctxt;
671
Daniel Veillard87b95392000-08-12 21:12:04 +0000672 /* if (repeat) */
673 size = 4096;
Daniel Veillard5e5c6231999-12-29 12:49:06 +0000674 res = fread(chars, 1, 4, f);
675 if (res > 0) {
676 ctxt = htmlCreatePushParserCtxt(NULL, NULL,
677 chars, res, filename, 0);
678 while ((res = fread(chars, 1, size, f)) > 0) {
679 htmlParseChunk(ctxt, chars, res, 0);
680 }
681 htmlParseChunk(ctxt, chars, 0, 1);
682 doc = ctxt->myDoc;
683 htmlFreeParserCtxt(ctxt);
684 }
Daniel Veillard87b95392000-08-12 21:12:04 +0000685 fclose(f);
Daniel Veillard5e5c6231999-12-29 12:49:06 +0000686 }
687 } else {
688 doc = htmlParseFile(filename, NULL);
689 }
690 if (doc == NULL) {
691 fprintf(stderr, "Could not parse %s\n", filename);
692 }
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000693
694 /*
695 * test intermediate copy if needed.
696 */
697 if (copy) {
698 tmp = doc;
699 doc = xmlCopyDoc(doc, 1);
700 xmlFreeDoc(tmp);
701 }
702
703 /*
704 * print it.
705 */
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000706 if (!noout) {
Daniel Veillard361d8452000-04-03 19:48:13 +0000707#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillard32bc74e2000-07-14 14:49:25 +0000708 if (!debug) {
709 if (encoding)
710 htmlSaveFileEnc("-", doc, encoding);
711 else
712 htmlDocDump(stdout, doc);
713 } else
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000714 xmlDebugDumpDocument(stdout, doc);
Daniel Veillard361d8452000-04-03 19:48:13 +0000715#else
Daniel Veillard32bc74e2000-07-14 14:49:25 +0000716 if (encoding)
717 htmlSaveFileEnc("-", doc, encoding);
718 else
719 htmlDocDump(stdout, doc);
Daniel Veillard361d8452000-04-03 19:48:13 +0000720#endif
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000721 }
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000722
723 /*
724 * free it.
725 */
726 xmlFreeDoc(doc);
727}
728
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000729int main(int argc, char **argv) {
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000730 int i, count;
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000731 int files = 0;
732
733 for (i = 1; i < argc ; i++) {
Daniel Veillard361d8452000-04-03 19:48:13 +0000734#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000735 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
736 debug++;
Daniel Veillard361d8452000-04-03 19:48:13 +0000737 else
738#endif
739 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000740 copy++;
Daniel Veillard5e5c6231999-12-29 12:49:06 +0000741 else if ((!strcmp(argv[i], "-push")) || (!strcmp(argv[i], "--push")))
742 push++;
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000743 else if ((!strcmp(argv[i], "-sax")) || (!strcmp(argv[i], "--sax")))
744 sax++;
745 else if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout")))
746 noout++;
747 else if ((!strcmp(argv[i], "-repeat")) ||
748 (!strcmp(argv[i], "--repeat")))
749 repeat++;
Daniel Veillard32bc74e2000-07-14 14:49:25 +0000750 else if ((!strcmp(argv[i], "-encode")) ||
751 (!strcmp(argv[i], "--encode"))) {
752 i++;
753 encoding = argv[i];
754 }
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000755 }
756 for (i = 1; i < argc ; i++) {
Daniel Veillard32bc74e2000-07-14 14:49:25 +0000757 if ((!strcmp(argv[i], "-encode")) ||
758 (!strcmp(argv[i], "--encode"))) {
759 i++;
760 continue;
761 }
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000762 if (argv[i][0] != '-') {
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000763 if (repeat) {
764 for (count = 0;count < 100 * repeat;count++) {
765 if (sax)
766 parseSAXFile(argv[i]);
767 else
768 parseAndPrintFile(argv[i]);
769 }
770 } else {
771 if (sax)
772 parseSAXFile(argv[i]);
773 else
774 parseAndPrintFile(argv[i]);
775 }
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000776 files ++;
777 }
778 }
779 if (files == 0) {
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000780 printf("Usage : %s [--debug] [--copy] [--copy] HTMLfiles ...\n",
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000781 argv[0]);
782 printf("\tParse the HTML files and output the result of the parsing\n");
Daniel Veillard361d8452000-04-03 19:48:13 +0000783#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000784 printf("\t--debug : dump a debug tree of the in-memory document\n");
Daniel Veillard361d8452000-04-03 19:48:13 +0000785#endif
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000786 printf("\t--copy : used to test the internal copy implementation\n");
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000787 printf("\t--sax : debug the sequence of SAX callbacks\n");
Daniel Veillard5e5c6231999-12-29 12:49:06 +0000788 printf("\t--repeat : parse the file 100 times, for timing\n");
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000789 printf("\t--noout : do not print the result\n");
Daniel Veillard5e5c6231999-12-29 12:49:06 +0000790 printf("\t--push : use the push mode parser\n");
Daniel Veillard32bc74e2000-07-14 14:49:25 +0000791 printf("\t--encode encoding : output in the given encoding\n");
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000792 }
Daniel Veillardf5c2c871999-12-01 09:51:45 +0000793 xmlCleanupParser();
Daniel Veillard7c1206f1999-10-14 09:10:25 +0000794 xmlMemoryDump();
Daniel Veillardbe70ff71999-07-05 16:50:46 +0000795
796 return(0);
797}
Daniel Veillard361d8452000-04-03 19:48:13 +0000798#else /* !LIBXML_HTML_ENABLED */
799#include <stdio.h>
800int main(int argc, char **argv) {
801 printf("%s : HTML support not compiled in\n", argv[0]);
802 return(0);
803}
804#endif