blob: bfa60109085df729163def75922098a84847da77 [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) {
Daniel Veillarde715dd22000-08-29 18:29:38 +0000385 int ret;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000386 int res, size = 3;
387 char chars[1024];
388 xmlParserCtxtPtr ctxt;
389
390 if (repeat)
391 size = 1024;
392 res = fread(chars, 1, 4, f);
393 if (res > 0) {
394 ctxt = xmlCreatePushParserCtxt(NULL, NULL,
395 chars, res, filename);
396 while ((res = fread(chars, 1, size, f)) > 0) {
397 xmlParseChunk(ctxt, chars, res, 0);
398 }
399 xmlParseChunk(ctxt, chars, 0, 1);
400 doc = ctxt->myDoc;
Daniel Veillarde715dd22000-08-29 18:29:38 +0000401 ret = ctxt->wellFormed;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000402 xmlFreeParserCtxt(ctxt);
Daniel Veillarde715dd22000-08-29 18:29:38 +0000403 if (!ret) {
404 xmlFreeDoc(doc);
405 doc = NULL;
406 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000407 }
408 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000409 } else if (testIO) {
410 int ret;
411 FILE *f;
412
413 f = fopen(filename, "r");
414 if (f != NULL) {
415 xmlParserCtxtPtr ctxt;
416
417 ctxt = xmlCreateIOParserCtxt(NULL, NULL,
418 (xmlInputReadCallback) myRead,
419 (xmlInputCloseCallback) myClose,
420 f, XML_CHAR_ENCODING_NONE);
421 xmlParseDocument(ctxt);
422
423 ret = ctxt->wellFormed;
424 doc = ctxt->myDoc;
425 xmlFreeParserCtxt(ctxt);
426 if (!ret) {
427 xmlFreeDoc(doc);
428 doc = NULL;
429 }
430 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000431 } else if (recovery) {
432 doc = xmlRecoverFile(filename);
433 } else if (htmlout) {
434 int ret;
435 xmlParserCtxtPtr ctxt;
436 xmlSAXHandler silent, *old;
437
438 ctxt = xmlCreateFileParserCtxt(filename);
Daniel Veillard88a172f2000-08-04 18:23:10 +0000439
440 if (ctxt == NULL) {
441 /* If xmlCreateFileParseCtxt() return NULL something
442 strange happened so we don't want to do anything. Do
443 we want to print an error message here?
444 <sven@zen.org> */
Daniel Veillard7ebb1ee2000-08-04 18:24:45 +0000445 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000446 } else {
447 memcpy(&silent, ctxt->sax, sizeof(silent));
448 old = ctxt->sax;
449 silent.error = xmlHTMLError;
450 if (xmlGetWarningsDefaultValue)
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000451 silent.warning = xmlHTMLWarning;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000452 else
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000453 silent.warning = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000454 silent.fatalError = xmlHTMLError;
455 ctxt->sax = &silent;
456 ctxt->vctxt.error = xmlHTMLValidityError;
457 if (xmlGetWarningsDefaultValue)
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000458 ctxt->vctxt.warning = xmlHTMLValidityWarning;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000459 else
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000460 ctxt->vctxt.warning = NULL;
461
Daniel Veillard88a172f2000-08-04 18:23:10 +0000462 xmlParseDocument(ctxt);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000463
Daniel Veillard88a172f2000-08-04 18:23:10 +0000464 ret = ctxt->wellFormed;
465 doc = ctxt->myDoc;
466 ctxt->sax = old;
467 xmlFreeParserCtxt(ctxt);
468 if (!ret) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000469 xmlFreeDoc(doc);
470 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000471 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000472 }
Daniel Veillard46e370e2000-07-21 20:32:03 +0000473#ifdef HAVE_SYS_MMAN_H
474 } else if (memory) {
475 int fd;
476 struct stat info;
477 const char *base;
478 if (stat(filename, &info) < 0)
479 return;
480 if ((fd = open(filename, O_RDONLY)) < 0)
481 return;
482 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
Daniel Veillard29579362000-08-14 17:57:48 +0000483 if (base == (void *) MAP_FAILED)
Daniel Veillard46e370e2000-07-21 20:32:03 +0000484 return;
485
486 doc = xmlParseMemory((char *) base, info.st_size);
487 munmap((char *) base, info.st_size);
488#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000489 } else
490 doc = xmlParseFile(filename);
491#ifdef LIBXML_HTML_ENABLED
492 }
493#endif
494
Daniel Veillard88a172f2000-08-04 18:23:10 +0000495 /*
496 * If we don't have a document we might as well give up. Do we
497 * want an error message here? <sven@zen.org> */
498 if (doc == NULL)
499 {
500 return;
501 }
502
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000503#ifdef LIBXML_DEBUG_ENABLED
504 /*
505 * shell interraction
506 */
507 if (shell)
508 xmlShell(doc, filename, xmlShellReadline, stdout);
509#endif
510
511 /*
512 * test intermediate copy if needed.
513 */
514 if (copy) {
515 tmp = doc;
516 doc = xmlCopyDoc(doc, 1);
517 xmlFreeDoc(tmp);
518 }
519
520 if ((insert) && (!html)) {
521 const xmlChar* list[256];
522 int nb, i;
523 xmlNodePtr node;
524
525 if (doc->children != NULL) {
526 node = doc->children;
527 while ((node != NULL) && (node->last == NULL)) node = node->next;
528 if (node != NULL) {
529 nb = xmlValidGetValidElements(node->last, NULL, list, 256);
530 if (nb < 0) {
531 printf("could not get valid list of elements\n");
532 } else if (nb == 0) {
533 printf("No element can be indersted under root\n");
534 } else {
535 printf("%d element types can be indersted under root:\n",
536 nb);
537 for (i = 0;i < nb;i++) {
538 printf("%s\n", list[i]);
539 }
540 }
541 }
542 }
543 }else if (noout == 0) {
544 /*
545 * print it.
546 */
547#ifdef LIBXML_DEBUG_ENABLED
548 if (!debug) {
549#endif
550 if (compress)
551 xmlSaveFile("-", doc);
Daniel Veillardbe803962000-06-28 23:40:59 +0000552 else if (encoding != NULL)
553 xmlSaveFileEnc("-", doc, encoding);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000554 else
555 xmlDocDump(stdout, doc);
556#ifdef LIBXML_DEBUG_ENABLED
557 } else
558 xmlDebugDumpDocument(stdout, doc);
559#endif
560 }
561
562 /*
563 * A posteriori validation test
564 */
565 if (postvalid) {
566 xmlValidCtxt cvp;
567 cvp.userData = (void *) stderr; cvp.error = (xmlValidityErrorFunc) fprintf; cvp.warning = (xmlValidityWarningFunc) fprintf;
568 xmlValidateDocument(&cvp, doc);
569 }
570
571#ifdef LIBXML_DEBUG_ENABLED
572 if ((debugent) && (!html))
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +0000573 xmlDebugDumpEntities(stderr, doc);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000574#endif
575
576 /*
577 * free it.
578 */
579 xmlFreeDoc(doc);
580}
581
582int main(int argc, char **argv) {
583 int i, count;
584 int files = 0;
585
Daniel Veillardbe803962000-06-28 23:40:59 +0000586 LIBXML_TEST_VERSION
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000587 for (i = 1; i < argc ; i++) {
588#ifdef LIBXML_DEBUG_ENABLED
589 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
590 debug++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000591 else if ((!strcmp(argv[i], "-shell")) ||
592 (!strcmp(argv[i], "--shell"))) {
593 shell++;
594 noout = 1;
595 } else
596#endif
597 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
598 copy++;
599 else if ((!strcmp(argv[i], "-recover")) ||
600 (!strcmp(argv[i], "--recover")))
601 recovery++;
602 else if ((!strcmp(argv[i], "-noent")) ||
603 (!strcmp(argv[i], "--noent")))
604 noent++;
605 else if ((!strcmp(argv[i], "-noout")) ||
606 (!strcmp(argv[i], "--noout")))
607 noout++;
608 else if ((!strcmp(argv[i], "-htmlout")) ||
609 (!strcmp(argv[i], "--htmlout")))
610 htmlout++;
611#ifdef LIBXML_HTML_ENABLED
612 else if ((!strcmp(argv[i], "-html")) ||
613 (!strcmp(argv[i], "--html"))) {
614 html++;
615 }
616#endif /* LIBXML_HTML_ENABLED */
617 else if ((!strcmp(argv[i], "-nowrap")) ||
618 (!strcmp(argv[i], "--nowrap")))
619 nowrap++;
620 else if ((!strcmp(argv[i], "-valid")) ||
621 (!strcmp(argv[i], "--valid")))
622 valid++;
623 else if ((!strcmp(argv[i], "-postvalid")) ||
624 (!strcmp(argv[i], "--postvalid")))
625 postvalid++;
626 else if ((!strcmp(argv[i], "-insert")) ||
627 (!strcmp(argv[i], "--insert")))
628 insert++;
629 else if ((!strcmp(argv[i], "-repeat")) ||
630 (!strcmp(argv[i], "--repeat")))
631 repeat++;
632 else if ((!strcmp(argv[i], "-push")) ||
633 (!strcmp(argv[i], "--push")))
634 push++;
Daniel Veillard46e370e2000-07-21 20:32:03 +0000635#ifdef HAVE_SYS_MMAN_H
636 else if ((!strcmp(argv[i], "-memory")) ||
637 (!strcmp(argv[i], "--memory")))
638 memory++;
639#endif
Daniel Veillard5e873c42000-04-12 13:27:38 +0000640 else if ((!strcmp(argv[i], "-testIO")) ||
641 (!strcmp(argv[i], "--testIO")))
642 testIO++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000643 else if ((!strcmp(argv[i], "-compress")) ||
644 (!strcmp(argv[i], "--compress"))) {
645 compress++;
646 xmlSetCompressMode(9);
647 }
648 else if ((!strcmp(argv[i], "-nowarning")) ||
649 (!strcmp(argv[i], "--nowarning"))) {
650 xmlGetWarningsDefaultValue = 0;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +0000651 xmlPedanticParserDefault(0);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000652 }
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +0000653 else if ((!strcmp(argv[i], "-pedantic")) ||
654 (!strcmp(argv[i], "--pedantic"))) {
655 xmlGetWarningsDefaultValue = 1;
656 xmlPedanticParserDefault(1);
657 }
658 else if ((!strcmp(argv[i], "-debugent")) ||
659 (!strcmp(argv[i], "--debugent"))) {
660 debugent++;
661 xmlParserDebugEntities = 1;
662 }
Daniel Veillardbe803962000-06-28 23:40:59 +0000663 else if ((!strcmp(argv[i], "-encode")) ||
664 (!strcmp(argv[i], "--encode"))) {
665 i++;
666 encoding = argv[i];
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +0000667 /*
668 * OK it's for testing purposes
669 */
670 xmlAddEncodingAlias("UTF-8", "DVEnc");
Daniel Veillardbe803962000-06-28 23:40:59 +0000671 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000672 else if ((!strcmp(argv[i], "-noblanks")) ||
673 (!strcmp(argv[i], "--noblanks"))) {
674 noblanks++;
675 xmlKeepBlanksDefault(0);
676 }
677 }
678 if (noent != 0) xmlSubstituteEntitiesDefault(1);
679 if (valid != 0) xmlDoValidityCheckingDefaultValue = 1;
680 if ((htmlout) && (!nowrap)) {
681 fprintf(stderr,
682 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
683 fprintf(stderr, "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
684 fprintf(stderr,
685 "<html><head><title>%s output</title></head>\n",
686 argv[0]);
687 fprintf(stderr,
688 "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
689 argv[0]);
690 }
691 for (i = 1; i < argc ; i++) {
Daniel Veillardbe803962000-06-28 23:40:59 +0000692 if ((!strcmp(argv[i], "-encode")) ||
693 (!strcmp(argv[i], "--encode"))) {
694 i++;
695 continue;
696 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000697 if (argv[i][0] != '-') {
698 if (repeat) {
699 for (count = 0;count < 100 * repeat;count++)
700 parseAndPrintFile(argv[i]);
701 } else
702 parseAndPrintFile(argv[i]);
703 files ++;
704 }
705 }
706 if ((htmlout) && (!nowrap)) {
707 fprintf(stderr, "</body></html>\n");
708 }
709 if (files == 0) {
710 printf("Usage : %s [--debug] [--debugent] [--copy] [--recover] [--noent] [--noout] [--valid] [--repeat] XMLfiles ...\n",
711 argv[0]);
712 printf("\tParse the XML files and output the result of the parsing\n");
713#ifdef LIBXML_DEBUG_ENABLED
714 printf("\t--debug : dump a debug tree of the in-memory document\n");
715 printf("\t--shell : run a navigating shell\n");
716 printf("\t--debugent : debug the entities defined in the document\n");
717#endif
718 printf("\t--copy : used to test the internal copy implementation\n");
719 printf("\t--recover : output what was parsable on broken XML documents\n");
720 printf("\t--noent : substitute entity references by their value\n");
721 printf("\t--noout : don't output the result tree\n");
722 printf("\t--htmlout : output results as HTML\n");
723 printf("\t--nowarp : do not put HTML doc wrapper\n");
724 printf("\t--valid : validate the document in addition to std well-formed check\n");
725 printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
726 printf("\t--repeat : repeat 100 times, for timing or profiling\n");
727 printf("\t--insert : ad-hoc test for valid insertions\n");
728 printf("\t--compress : turn on gzip compression of output\n");
729#ifdef LIBXML_HTML_ENABLED
730 printf("\t--html : use the HTML parser\n");
731#endif
732 printf("\t--push : use the push mode of the parser\n");
Daniel Veillard46e370e2000-07-21 20:32:03 +0000733#ifdef HAVE_SYS_MMAN_H
734 printf("\t--memory : parse from memory\n");
735#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000736 printf("\t--nowarning : do not emit warnings from parser/validator\n");
737 printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
Daniel Veillard5e873c42000-04-12 13:27:38 +0000738 printf("\t--testIO : test user I/O support\n");
Daniel Veillard32bc74e2000-07-14 14:49:25 +0000739 printf("\t--encode encoding : output in the given encoding\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000740 }
741 xmlCleanupParser();
742 xmlMemoryDump();
743
744 return(0);
745}
Daniel Veillard88a172f2000-08-04 18:23:10 +0000746