blob: 6027d38455318117eb7ac4e287c9282b7d6fe58e [file] [log] [blame]
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001/*
2 * xmllint.c : a small tester program for XML input.
3 *
4 * See Copyright for the status of this software.
5 *
6 * Daniel.Veillard@w3.org
7 */
8
9#ifdef WIN32
10#include "win32config.h"
11#else
12#include "config.h"
13#endif
14
15#include <stdio.h>
16#include <string.h>
17#include <stdio.h>
18#include <stdarg.h>
19
20#ifdef HAVE_SYS_TYPES_H
21#include <sys/types.h>
22#endif
23#ifdef HAVE_SYS_STAT_H
24#include <sys/stat.h>
25#endif
26#ifdef HAVE_FCNTL_H
27#include <fcntl.h>
28#endif
29#ifdef HAVE_UNISTD_H
30#include <unistd.h>
31#endif
Daniel Veillard46e370e2000-07-21 20:32:03 +000032#ifdef HAVE_SYS_MMAN_H
33#include <sys/mman.h>
Daniel Veillard87b95392000-08-12 21:12:04 +000034/* seems needed for Solaris */
35#ifndef MAP_FAILED
36#define MAP_FAILED ((void *) -1)
37#endif
Daniel Veillard46e370e2000-07-21 20:32:03 +000038#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +000039#ifdef HAVE_STDLIB_H
40#include <stdlib.h>
41#endif
42#ifdef HAVE_LIBREADLINE
43#include <readline/readline.h>
44#ifdef HAVE_LIBHISTORY
45#include <readline/history.h>
46#endif
47#endif
48
49#include <libxml/xmlmemory.h>
50#include <libxml/parser.h>
51#include <libxml/parserInternals.h>
52#include <libxml/HTMLparser.h>
53#include <libxml/HTMLtree.h>
54#include <libxml/tree.h>
55#include <libxml/xpath.h>
56#include <libxml/debugXML.h>
57
58#ifdef LIBXML_DEBUG_ENABLED
59static int debug = 0;
60static int shell = 0;
61static int debugent = 0;
62#endif
63static int copy = 0;
64static int recovery = 0;
65static int noent = 0;
66static int noout = 0;
67static int nowrap = 0;
68static int valid = 0;
69static int postvalid = 0;
70static int repeat = 0;
71static int insert = 0;
72static int compress = 0;
73static int html = 0;
74static int htmlout = 0;
75static int push = 0;
Daniel Veillard46e370e2000-07-21 20:32:03 +000076#ifdef HAVE_SYS_MMAN_H
77static int memory = 0;
78#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +000079static int noblanks = 0;
Daniel Veillard5e873c42000-04-12 13:27:38 +000080static int testIO = 0;
Daniel Veillardbe803962000-06-28 23:40:59 +000081static char *encoding = NULL;
Daniel Veillardce8b83b2000-04-05 18:38:42 +000082
83extern int xmlDoValidityCheckingDefaultValue;
84extern int xmlGetWarningsDefaultValue;
85
86/************************************************************************
87 * *
88 * HTML ouput *
89 * *
90 ************************************************************************/
91char buffer[50000];
92
93void
94xmlHTMLEncodeSend(void) {
95 char *result;
96
97 result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
98 if (result) {
99 fprintf(stderr, "%s", result);
100 xmlFree(result);
101 }
102 buffer[0] = 0;
103}
104
105/**
106 * xmlHTMLPrintFileInfo:
107 * @input: an xmlParserInputPtr input
108 *
109 * Displays the associated file and line informations for the current input
110 */
111
112void
113xmlHTMLPrintFileInfo(xmlParserInputPtr input) {
114 fprintf(stderr, "<p>");
115 if (input != NULL) {
116 if (input->filename) {
117 sprintf(&buffer[strlen(buffer)], "%s:%d: ", input->filename,
118 input->line);
119 } else {
120 sprintf(&buffer[strlen(buffer)], "Entity: line %d: ", input->line);
121 }
122 }
123 xmlHTMLEncodeSend();
124}
125
126/**
127 * xmlHTMLPrintFileContext:
128 * @input: an xmlParserInputPtr input
129 *
130 * Displays current context within the input content for error tracking
131 */
132
133void
134xmlHTMLPrintFileContext(xmlParserInputPtr input) {
135 const xmlChar *cur, *base;
136 int n;
137
138 if (input == NULL) return;
139 fprintf(stderr, "<pre>\n");
140 cur = input->cur;
141 base = input->base;
142 while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
143 cur--;
144 }
145 n = 0;
146 while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
147 cur--;
148 if ((*cur == '\n') || (*cur == '\r')) cur++;
149 base = cur;
150 n = 0;
151 while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
152 sprintf(&buffer[strlen(buffer)], "%c", (unsigned char) *cur++);
153 n++;
154 }
155 sprintf(&buffer[strlen(buffer)], "\n");
156 cur = input->cur;
157 while ((*cur == '\n') || (*cur == '\r'))
158 cur--;
159 n = 0;
160 while ((cur != base) && (n++ < 80)) {
161 sprintf(&buffer[strlen(buffer)], " ");
162 base++;
163 }
164 sprintf(&buffer[strlen(buffer)],"^\n");
165 xmlHTMLEncodeSend();
166 fprintf(stderr, "</pre>");
167}
168
169/**
170 * xmlHTMLError:
171 * @ctx: an XML parser context
172 * @msg: the message to display/transmit
173 * @...: extra parameters for the message display
174 *
175 * Display and format an error messages, gives file, line, position and
176 * extra parameters.
177 */
178void
179xmlHTMLError(void *ctx, const char *msg, ...)
180{
181 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
182 xmlParserInputPtr input;
183 xmlParserInputPtr cur = NULL;
184 va_list args;
185
186 buffer[0] = 0;
187 input = ctxt->input;
188 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
189 cur = input;
190 input = ctxt->inputTab[ctxt->inputNr - 2];
191 }
192
193 xmlHTMLPrintFileInfo(input);
194
195 fprintf(stderr, "<b>error</b>: ");
196 va_start(args, msg);
197 vsprintf(&buffer[strlen(buffer)], msg, args);
198 va_end(args);
199 xmlHTMLEncodeSend();
200 fprintf(stderr, "</p>\n");
201
202 xmlHTMLPrintFileContext(input);
203 xmlHTMLEncodeSend();
204}
205
206/**
207 * xmlHTMLWarning:
208 * @ctx: an XML parser context
209 * @msg: the message to display/transmit
210 * @...: extra parameters for the message display
211 *
212 * Display and format a warning messages, gives file, line, position and
213 * extra parameters.
214 */
215void
216xmlHTMLWarning(void *ctx, const char *msg, ...)
217{
218 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
219 xmlParserInputPtr input;
220 xmlParserInputPtr cur = NULL;
221 va_list args;
222
223 buffer[0] = 0;
224 input = ctxt->input;
225 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
226 cur = input;
227 input = ctxt->inputTab[ctxt->inputNr - 2];
228 }
229
230
231 xmlHTMLPrintFileInfo(input);
232
233 fprintf(stderr, "<b>warning</b>: ");
234 va_start(args, msg);
235 vsprintf(&buffer[strlen(buffer)], msg, args);
236 va_end(args);
237 xmlHTMLEncodeSend();
238 fprintf(stderr, "</p>\n");
239
240 xmlHTMLPrintFileContext(input);
241 xmlHTMLEncodeSend();
242}
243
244/**
245 * xmlHTMLValidityError:
246 * @ctx: an XML parser context
247 * @msg: the message to display/transmit
248 * @...: extra parameters for the message display
249 *
250 * Display and format an validity error messages, gives file,
251 * line, position and extra parameters.
252 */
253void
254xmlHTMLValidityError(void *ctx, const char *msg, ...)
255{
256 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
257 xmlParserInputPtr input;
258 va_list args;
259
260 buffer[0] = 0;
261 input = ctxt->input;
262 if ((input->filename == NULL) && (ctxt->inputNr > 1))
263 input = ctxt->inputTab[ctxt->inputNr - 2];
264
265 xmlHTMLPrintFileInfo(input);
266
267 fprintf(stderr, "<b>validity error</b>: ");
268 va_start(args, msg);
269 vsprintf(&buffer[strlen(buffer)], msg, args);
270 va_end(args);
271 xmlHTMLEncodeSend();
272 fprintf(stderr, "</p>\n");
273
274 xmlHTMLPrintFileContext(input);
275 xmlHTMLEncodeSend();
276}
277
278/**
279 * xmlHTMLValidityWarning:
280 * @ctx: an XML parser context
281 * @msg: the message to display/transmit
282 * @...: extra parameters for the message display
283 *
284 * Display and format a validity warning messages, gives file, line,
285 * position and extra parameters.
286 */
287void
288xmlHTMLValidityWarning(void *ctx, const char *msg, ...)
289{
290 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
291 xmlParserInputPtr input;
292 va_list args;
293
294 buffer[0] = 0;
295 input = ctxt->input;
296 if ((input->filename == NULL) && (ctxt->inputNr > 1))
297 input = ctxt->inputTab[ctxt->inputNr - 2];
298
299 xmlHTMLPrintFileInfo(input);
300
301 fprintf(stderr, "<b>validity warning</b>: ");
302 va_start(args, msg);
303 vsprintf(&buffer[strlen(buffer)], msg, args);
304 va_end(args);
305 xmlHTMLEncodeSend();
306 fprintf(stderr, "</p>\n");
307
308 xmlHTMLPrintFileContext(input);
309 xmlHTMLEncodeSend();
310}
311
312/************************************************************************
313 * *
314 * Shell Interface *
315 * *
316 ************************************************************************/
317/**
318 * xmlShellReadline:
319 * @prompt: the prompt value
320 *
321 * Read a string
322 *
323 * Returns a pointer to it or NULL on EOF the caller is expected to
324 * free the returned string.
325 */
326char *
327xmlShellReadline(char *prompt) {
328#ifdef HAVE_LIBREADLINE
329 char *line_read;
330
331 /* Get a line from the user. */
332 line_read = readline (prompt);
333
334 /* If the line has any text in it, save it on the history. */
335 if (line_read && *line_read)
336 add_history (line_read);
337
338 return (line_read);
339#else
340 char line_read[501];
341
342 if (prompt != NULL)
343 fprintf(stdout, "%s", prompt);
344 if (!fgets(line_read, 500, stdin))
345 return(NULL);
346 line_read[500] = 0;
347 return(strdup(line_read));
348#endif
349}
350
351/************************************************************************
352 * *
Daniel Veillard5e873c42000-04-12 13:27:38 +0000353 * I/O Interfaces *
354 * *
355 ************************************************************************/
356
357int myRead(FILE *f, char * buffer, int len) {
358 return(fread(buffer, 1, len, f));
359}
360void myClose(FILE *f) {
361 fclose(f);
362}
363
364/************************************************************************
365 * *
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000366 * Test processing *
367 * *
368 ************************************************************************/
369void parseAndPrintFile(char *filename) {
370 xmlDocPtr doc = NULL, tmp;
371
372#ifdef LIBXML_HTML_ENABLED
373 if (html) {
374 doc = htmlParseFile(filename, NULL);
375 } else {
376#endif /* LIBXML_HTML_ENABLED */
377 /*
378 * build an XML tree from a string;
379 */
380 if (push) {
381 FILE *f;
382
383 f = fopen(filename, "r");
384 if (f != NULL) {
385 int res, size = 3;
386 char chars[1024];
387 xmlParserCtxtPtr ctxt;
388
389 if (repeat)
390 size = 1024;
391 res = fread(chars, 1, 4, f);
392 if (res > 0) {
393 ctxt = xmlCreatePushParserCtxt(NULL, NULL,
394 chars, res, filename);
395 while ((res = fread(chars, 1, size, f)) > 0) {
396 xmlParseChunk(ctxt, chars, res, 0);
397 }
398 xmlParseChunk(ctxt, chars, 0, 1);
399 doc = ctxt->myDoc;
400 xmlFreeParserCtxt(ctxt);
401 }
402 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000403 } else if (testIO) {
404 int ret;
405 FILE *f;
406
407 f = fopen(filename, "r");
408 if (f != NULL) {
409 xmlParserCtxtPtr ctxt;
410
411 ctxt = xmlCreateIOParserCtxt(NULL, NULL,
412 (xmlInputReadCallback) myRead,
413 (xmlInputCloseCallback) myClose,
414 f, XML_CHAR_ENCODING_NONE);
415 xmlParseDocument(ctxt);
416
417 ret = ctxt->wellFormed;
418 doc = ctxt->myDoc;
419 xmlFreeParserCtxt(ctxt);
420 if (!ret) {
421 xmlFreeDoc(doc);
422 doc = NULL;
423 }
424 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000425 } else if (recovery) {
426 doc = xmlRecoverFile(filename);
427 } else if (htmlout) {
428 int ret;
429 xmlParserCtxtPtr ctxt;
430 xmlSAXHandler silent, *old;
431
432 ctxt = xmlCreateFileParserCtxt(filename);
Daniel Veillard88a172f2000-08-04 18:23:10 +0000433
434 if (ctxt == NULL) {
435 /* If xmlCreateFileParseCtxt() return NULL something
436 strange happened so we don't want to do anything. Do
437 we want to print an error message here?
438 <sven@zen.org> */
Daniel Veillard7ebb1ee2000-08-04 18:24:45 +0000439 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000440 } else {
441 memcpy(&silent, ctxt->sax, sizeof(silent));
442 old = ctxt->sax;
443 silent.error = xmlHTMLError;
444 if (xmlGetWarningsDefaultValue)
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000445 silent.warning = xmlHTMLWarning;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000446 else
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000447 silent.warning = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000448 silent.fatalError = xmlHTMLError;
449 ctxt->sax = &silent;
450 ctxt->vctxt.error = xmlHTMLValidityError;
451 if (xmlGetWarningsDefaultValue)
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000452 ctxt->vctxt.warning = xmlHTMLValidityWarning;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000453 else
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000454 ctxt->vctxt.warning = NULL;
455
Daniel Veillard88a172f2000-08-04 18:23:10 +0000456 xmlParseDocument(ctxt);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000457
Daniel Veillard88a172f2000-08-04 18:23:10 +0000458 ret = ctxt->wellFormed;
459 doc = ctxt->myDoc;
460 ctxt->sax = old;
461 xmlFreeParserCtxt(ctxt);
462 if (!ret) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000463 xmlFreeDoc(doc);
464 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000465 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000466 }
Daniel Veillard46e370e2000-07-21 20:32:03 +0000467#ifdef HAVE_SYS_MMAN_H
468 } else if (memory) {
469 int fd;
470 struct stat info;
471 const char *base;
472 if (stat(filename, &info) < 0)
473 return;
474 if ((fd = open(filename, O_RDONLY)) < 0)
475 return;
476 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
Daniel Veillard29579362000-08-14 17:57:48 +0000477 if (base == (void *) MAP_FAILED)
Daniel Veillard46e370e2000-07-21 20:32:03 +0000478 return;
479
480 doc = xmlParseMemory((char *) base, info.st_size);
481 munmap((char *) base, info.st_size);
482#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000483 } else
484 doc = xmlParseFile(filename);
485#ifdef LIBXML_HTML_ENABLED
486 }
487#endif
488
Daniel Veillard88a172f2000-08-04 18:23:10 +0000489 /*
490 * If we don't have a document we might as well give up. Do we
491 * want an error message here? <sven@zen.org> */
492 if (doc == NULL)
493 {
494 return;
495 }
496
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000497#ifdef LIBXML_DEBUG_ENABLED
498 /*
499 * shell interraction
500 */
501 if (shell)
502 xmlShell(doc, filename, xmlShellReadline, stdout);
503#endif
504
505 /*
506 * test intermediate copy if needed.
507 */
508 if (copy) {
509 tmp = doc;
510 doc = xmlCopyDoc(doc, 1);
511 xmlFreeDoc(tmp);
512 }
513
514 if ((insert) && (!html)) {
515 const xmlChar* list[256];
516 int nb, i;
517 xmlNodePtr node;
518
519 if (doc->children != NULL) {
520 node = doc->children;
521 while ((node != NULL) && (node->last == NULL)) node = node->next;
522 if (node != NULL) {
523 nb = xmlValidGetValidElements(node->last, NULL, list, 256);
524 if (nb < 0) {
525 printf("could not get valid list of elements\n");
526 } else if (nb == 0) {
527 printf("No element can be indersted under root\n");
528 } else {
529 printf("%d element types can be indersted under root:\n",
530 nb);
531 for (i = 0;i < nb;i++) {
532 printf("%s\n", list[i]);
533 }
534 }
535 }
536 }
537 }else if (noout == 0) {
538 /*
539 * print it.
540 */
541#ifdef LIBXML_DEBUG_ENABLED
542 if (!debug) {
543#endif
544 if (compress)
545 xmlSaveFile("-", doc);
Daniel Veillardbe803962000-06-28 23:40:59 +0000546 else if (encoding != NULL)
547 xmlSaveFileEnc("-", doc, encoding);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000548 else
549 xmlDocDump(stdout, doc);
550#ifdef LIBXML_DEBUG_ENABLED
551 } else
552 xmlDebugDumpDocument(stdout, doc);
553#endif
554 }
555
556 /*
557 * A posteriori validation test
558 */
559 if (postvalid) {
560 xmlValidCtxt cvp;
561 cvp.userData = (void *) stderr; cvp.error = (xmlValidityErrorFunc) fprintf; cvp.warning = (xmlValidityWarningFunc) fprintf;
562 xmlValidateDocument(&cvp, doc);
563 }
564
565#ifdef LIBXML_DEBUG_ENABLED
566 if ((debugent) && (!html))
567 xmlDebugDumpEntities(stdout, doc);
568#endif
569
570 /*
571 * free it.
572 */
573 xmlFreeDoc(doc);
574}
575
576int main(int argc, char **argv) {
577 int i, count;
578 int files = 0;
579
Daniel Veillardbe803962000-06-28 23:40:59 +0000580 LIBXML_TEST_VERSION
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000581 for (i = 1; i < argc ; i++) {
582#ifdef LIBXML_DEBUG_ENABLED
583 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
584 debug++;
585 else if ((!strcmp(argv[i], "-debugent")) || (!strcmp(argv[i], "--debugent")))
586 debugent++;
587 else if ((!strcmp(argv[i], "-shell")) ||
588 (!strcmp(argv[i], "--shell"))) {
589 shell++;
590 noout = 1;
591 } else
592#endif
593 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
594 copy++;
595 else if ((!strcmp(argv[i], "-recover")) ||
596 (!strcmp(argv[i], "--recover")))
597 recovery++;
598 else if ((!strcmp(argv[i], "-noent")) ||
599 (!strcmp(argv[i], "--noent")))
600 noent++;
601 else if ((!strcmp(argv[i], "-noout")) ||
602 (!strcmp(argv[i], "--noout")))
603 noout++;
604 else if ((!strcmp(argv[i], "-htmlout")) ||
605 (!strcmp(argv[i], "--htmlout")))
606 htmlout++;
607#ifdef LIBXML_HTML_ENABLED
608 else if ((!strcmp(argv[i], "-html")) ||
609 (!strcmp(argv[i], "--html"))) {
610 html++;
611 }
612#endif /* LIBXML_HTML_ENABLED */
613 else if ((!strcmp(argv[i], "-nowrap")) ||
614 (!strcmp(argv[i], "--nowrap")))
615 nowrap++;
616 else if ((!strcmp(argv[i], "-valid")) ||
617 (!strcmp(argv[i], "--valid")))
618 valid++;
619 else if ((!strcmp(argv[i], "-postvalid")) ||
620 (!strcmp(argv[i], "--postvalid")))
621 postvalid++;
622 else if ((!strcmp(argv[i], "-insert")) ||
623 (!strcmp(argv[i], "--insert")))
624 insert++;
625 else if ((!strcmp(argv[i], "-repeat")) ||
626 (!strcmp(argv[i], "--repeat")))
627 repeat++;
628 else if ((!strcmp(argv[i], "-push")) ||
629 (!strcmp(argv[i], "--push")))
630 push++;
Daniel Veillard46e370e2000-07-21 20:32:03 +0000631#ifdef HAVE_SYS_MMAN_H
632 else if ((!strcmp(argv[i], "-memory")) ||
633 (!strcmp(argv[i], "--memory")))
634 memory++;
635#endif
Daniel Veillard5e873c42000-04-12 13:27:38 +0000636 else if ((!strcmp(argv[i], "-testIO")) ||
637 (!strcmp(argv[i], "--testIO")))
638 testIO++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000639 else if ((!strcmp(argv[i], "-compress")) ||
640 (!strcmp(argv[i], "--compress"))) {
641 compress++;
642 xmlSetCompressMode(9);
643 }
644 else if ((!strcmp(argv[i], "-nowarning")) ||
645 (!strcmp(argv[i], "--nowarning"))) {
646 xmlGetWarningsDefaultValue = 0;
647 }
Daniel Veillardbe803962000-06-28 23:40:59 +0000648 else if ((!strcmp(argv[i], "-encode")) ||
649 (!strcmp(argv[i], "--encode"))) {
650 i++;
651 encoding = argv[i];
652 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000653 else if ((!strcmp(argv[i], "-noblanks")) ||
654 (!strcmp(argv[i], "--noblanks"))) {
655 noblanks++;
656 xmlKeepBlanksDefault(0);
657 }
658 }
659 if (noent != 0) xmlSubstituteEntitiesDefault(1);
660 if (valid != 0) xmlDoValidityCheckingDefaultValue = 1;
661 if ((htmlout) && (!nowrap)) {
662 fprintf(stderr,
663 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
664 fprintf(stderr, "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
665 fprintf(stderr,
666 "<html><head><title>%s output</title></head>\n",
667 argv[0]);
668 fprintf(stderr,
669 "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
670 argv[0]);
671 }
672 for (i = 1; i < argc ; i++) {
Daniel Veillardbe803962000-06-28 23:40:59 +0000673 if ((!strcmp(argv[i], "-encode")) ||
674 (!strcmp(argv[i], "--encode"))) {
675 i++;
676 continue;
677 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000678 if (argv[i][0] != '-') {
679 if (repeat) {
680 for (count = 0;count < 100 * repeat;count++)
681 parseAndPrintFile(argv[i]);
682 } else
683 parseAndPrintFile(argv[i]);
684 files ++;
685 }
686 }
687 if ((htmlout) && (!nowrap)) {
688 fprintf(stderr, "</body></html>\n");
689 }
690 if (files == 0) {
691 printf("Usage : %s [--debug] [--debugent] [--copy] [--recover] [--noent] [--noout] [--valid] [--repeat] XMLfiles ...\n",
692 argv[0]);
693 printf("\tParse the XML files and output the result of the parsing\n");
694#ifdef LIBXML_DEBUG_ENABLED
695 printf("\t--debug : dump a debug tree of the in-memory document\n");
696 printf("\t--shell : run a navigating shell\n");
697 printf("\t--debugent : debug the entities defined in the document\n");
698#endif
699 printf("\t--copy : used to test the internal copy implementation\n");
700 printf("\t--recover : output what was parsable on broken XML documents\n");
701 printf("\t--noent : substitute entity references by their value\n");
702 printf("\t--noout : don't output the result tree\n");
703 printf("\t--htmlout : output results as HTML\n");
704 printf("\t--nowarp : do not put HTML doc wrapper\n");
705 printf("\t--valid : validate the document in addition to std well-formed check\n");
706 printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
707 printf("\t--repeat : repeat 100 times, for timing or profiling\n");
708 printf("\t--insert : ad-hoc test for valid insertions\n");
709 printf("\t--compress : turn on gzip compression of output\n");
710#ifdef LIBXML_HTML_ENABLED
711 printf("\t--html : use the HTML parser\n");
712#endif
713 printf("\t--push : use the push mode of the parser\n");
Daniel Veillard46e370e2000-07-21 20:32:03 +0000714#ifdef HAVE_SYS_MMAN_H
715 printf("\t--memory : parse from memory\n");
716#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000717 printf("\t--nowarning : do not emit warnings from parser/validator\n");
718 printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
Daniel Veillard5e873c42000-04-12 13:27:38 +0000719 printf("\t--testIO : test user I/O support\n");
Daniel Veillard32bc74e2000-07-14 14:49:25 +0000720 printf("\t--encode encoding : output in the given encoding\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000721 }
722 xmlCleanupParser();
723 xmlMemoryDump();
724
725 return(0);
726}
Daniel Veillard88a172f2000-08-04 18:23:10 +0000727