blob: c4d32184828c481810f55989ba32441087a3032f [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 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00006 * daniel@veillard.com
Daniel Veillardce8b83b2000-04-05 18:38:42 +00007 */
8
Bjorn Reese70a9da52001-04-21 16:57:29 +00009#include "libxml.h"
Daniel Veillardce8b83b2000-04-05 18:38:42 +000010
Daniel Veillardce8b83b2000-04-05 18:38:42 +000011#include <string.h>
Daniel Veillardce8b83b2000-04-05 18:38:42 +000012#include <stdarg.h>
Daniel Veillard8a1b1852003-01-05 22:37:17 +000013#include <assert.h>
14
Daniel Veillard3c5ed912002-01-08 10:36:16 +000015#if defined (_WIN32) && !defined(__CYGWIN__)
Daniel Veillard07cb8222003-09-10 10:51:05 +000016#if defined (_MSC_VER) || defined(__BORLANDC__)
Daniel Veillard2d90de42001-04-16 17:46:18 +000017#include <winsock2.h>
18#pragma comment(lib, "ws2_32.lib")
19#define gettimeofday(p1,p2)
20#endif /* _MSC_VER */
Igor Zlatkovic19b87642003-08-28 12:32:04 +000021#endif /* _WIN32 */
22
Daniel Veillarded472f32001-12-13 08:48:14 +000023#ifdef HAVE_SYS_TIME_H
Daniel Veillard48b2f892001-02-25 16:11:03 +000024#include <sys/time.h>
Daniel Veillarded472f32001-12-13 08:48:14 +000025#endif
Daniel Veillard01db67c2001-12-18 07:09:59 +000026#ifdef HAVE_TIME_H
27#include <time.h>
28#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +000029
Daniel Veillard1638a472003-08-14 01:23:25 +000030#ifdef __MINGW32__
31#define _WINSOCKAPI_
32#include <wsockcompat.h>
33#include <winsock2.h>
34#undef SOCKLEN_T
35#define SOCKLEN_T unsigned int
36#endif
37
Daniel Veillard90bc3712002-03-07 15:12:58 +000038#ifdef HAVE_SYS_TIMEB_H
39#include <sys/timeb.h>
40#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +000041
42#ifdef HAVE_SYS_TYPES_H
43#include <sys/types.h>
44#endif
45#ifdef HAVE_SYS_STAT_H
46#include <sys/stat.h>
47#endif
48#ifdef HAVE_FCNTL_H
49#include <fcntl.h>
50#endif
51#ifdef HAVE_UNISTD_H
52#include <unistd.h>
53#endif
Daniel Veillard46e370e2000-07-21 20:32:03 +000054#ifdef HAVE_SYS_MMAN_H
55#include <sys/mman.h>
Daniel Veillard87b95392000-08-12 21:12:04 +000056/* seems needed for Solaris */
57#ifndef MAP_FAILED
58#define MAP_FAILED ((void *) -1)
59#endif
Daniel Veillard46e370e2000-07-21 20:32:03 +000060#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +000061#ifdef HAVE_STDLIB_H
62#include <stdlib.h>
63#endif
64#ifdef HAVE_LIBREADLINE
65#include <readline/readline.h>
66#ifdef HAVE_LIBHISTORY
67#include <readline/history.h>
68#endif
69#endif
70
71#include <libxml/xmlmemory.h>
72#include <libxml/parser.h>
73#include <libxml/parserInternals.h>
74#include <libxml/HTMLparser.h>
75#include <libxml/HTMLtree.h>
76#include <libxml/tree.h>
77#include <libxml/xpath.h>
78#include <libxml/debugXML.h>
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +000079#include <libxml/xmlerror.h>
Daniel Veillard9e8bfae2000-11-06 16:43:11 +000080#ifdef LIBXML_XINCLUDE_ENABLED
81#include <libxml/xinclude.h>
82#endif
Daniel Veillard81418e32001-05-22 15:08:55 +000083#ifdef LIBXML_CATALOG_ENABLED
84#include <libxml/catalog.h>
85#endif
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000086#include <libxml/globals.h>
Daniel Veillard7704fb12003-01-03 16:19:51 +000087#include <libxml/xmlreader.h>
Daniel Veillard71531f32003-02-05 13:19:53 +000088#ifdef LIBXML_SCHEMAS_ENABLED
89#include <libxml/relaxng.h>
Daniel Veillard75bb3bb2003-05-12 15:25:56 +000090#include <libxml/xmlschemas.h>
Daniel Veillard71531f32003-02-05 13:19:53 +000091#endif
Daniel Veillardb3de70c2003-12-02 22:32:15 +000092#ifdef LIBXML_PATTERN_ENABLED
93#include <libxml/pattern.h>
94#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +000095
Daniel Veillard3be27512003-01-26 19:49:04 +000096#ifndef XML_XML_DEFAULT_CATALOG
97#define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog"
98#endif
99
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000100#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000101static int shell = 0;
102static int debugent = 0;
103#endif
Daniel Veillard8326e732003-01-07 00:19:07 +0000104static int debug = 0;
Daniel Veillard652327a2003-09-29 18:02:38 +0000105#ifdef LIBXML_TREE_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000106static int copy = 0;
Daniel Veillard652327a2003-09-29 18:02:38 +0000107#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000108static int recovery = 0;
109static int noent = 0;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000110static int noblanks = 0;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000111static int noout = 0;
112static int nowrap = 0;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000113#ifdef LIBXML_OUTPUT_ENABLED
114static int format = 0;
115static const char *output = NULL;
116static int compress = 0;
117#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard4432df22003-09-28 18:58:27 +0000118#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000119static int valid = 0;
120static int postvalid = 0;
Daniel Veillardcd429612000-10-11 15:57:05 +0000121static char * dtdvalid = NULL;
Daniel Veillard66f68e72003-08-18 16:39:51 +0000122static char * dtdvalidfpi = NULL;
Daniel Veillard4432df22003-09-28 18:58:27 +0000123#endif
Daniel Veillard71531f32003-02-05 13:19:53 +0000124#ifdef LIBXML_SCHEMAS_ENABLED
125static char * relaxng = NULL;
126static xmlRelaxNGPtr relaxngschemas = NULL;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +0000127static char * schema = NULL;
128static xmlSchemaPtr wxschemas = NULL;
Daniel Veillard71531f32003-02-05 13:19:53 +0000129#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000130static int repeat = 0;
131static int insert = 0;
Daniel Veillard656ce942004-04-30 23:11:45 +0000132#if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED)
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000133static int html = 0;
Daniel Veillard42fd4122003-11-04 08:47:48 +0000134static int xmlout = 0;
Daniel Veillard4432df22003-09-28 18:58:27 +0000135#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000136static int htmlout = 0;
Daniel Veillard73b013f2003-09-30 12:36:01 +0000137#ifdef LIBXML_PUSH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000138static int push = 0;
Daniel Veillard73b013f2003-09-30 12:36:01 +0000139#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillard46e370e2000-07-21 20:32:03 +0000140#ifdef HAVE_SYS_MMAN_H
141static int memory = 0;
142#endif
Daniel Veillard5e873c42000-04-12 13:27:38 +0000143static int testIO = 0;
Daniel Veillardbe803962000-06-28 23:40:59 +0000144static char *encoding = NULL;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000145#ifdef LIBXML_XINCLUDE_ENABLED
146static int xinclude = 0;
147#endif
Daniel Veillard48da9102001-08-07 01:10:10 +0000148static int dtdattrs = 0;
Daniel Veillard10ea86c2001-06-20 13:55:33 +0000149static int loaddtd = 0;
Daniel Veillardf7cd4812001-02-23 18:44:52 +0000150static int progresult = 0;
Daniel Veillard48b2f892001-02-25 16:11:03 +0000151static int timing = 0;
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000152static int generate = 0;
Daniel Veillard29e43992001-12-13 22:21:58 +0000153static int dropdtd = 0;
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000154#ifdef LIBXML_CATALOG_ENABLED
155static int catalogs = 0;
156static int nocatalogs = 0;
157#endif
Daniel Veillard81273902003-09-30 00:43:48 +0000158#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +0000159static int stream = 0;
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000160static int walker = 0;
Daniel Veillard81273902003-09-30 00:43:48 +0000161#endif /* LIBXML_READER_ENABLED */
Daniel Veillard8a1b1852003-01-05 22:37:17 +0000162static int chkregister = 0;
Daniel Veillarda2d51fc2004-04-30 22:25:59 +0000163static int nbregister = 0;
Daniel Veillard81273902003-09-30 00:43:48 +0000164#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +0000165static int sax1 = 0;
Daniel Veillard81273902003-09-30 00:43:48 +0000166#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000167#ifdef LIBXML_PATTERN_ENABLED
168static const char *pattern = NULL;
169static xmlPatternPtr patternc = NULL;
170#endif
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000171static int options = 0;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000172
Daniel Veillard01db67c2001-12-18 07:09:59 +0000173/*
174 * Internal timing routines to remove the necessity to have unix-specific
175 * function calls
176 */
177
Daniel Veillard8c1ae602002-03-07 11:21:00 +0000178#ifndef HAVE_GETTIMEOFDAY
179#ifdef HAVE_SYS_TIMEB_H
180#ifdef HAVE_SYS_TIME_H
181#ifdef HAVE_FTIME
182
Daniel Veillard01c13b52002-12-10 15:19:08 +0000183static int
Daniel Veillard8c1ae602002-03-07 11:21:00 +0000184my_gettimeofday(struct timeval *tvp, void *tzp)
185{
186 struct timeb timebuffer;
187
188 ftime(&timebuffer);
189 if (tvp) {
190 tvp->tv_sec = timebuffer.time;
191 tvp->tv_usec = timebuffer.millitm * 1000L;
192 }
193 return (0);
194}
195#define HAVE_GETTIMEOFDAY 1
196#define gettimeofday my_gettimeofday
197
198#endif /* HAVE_FTIME */
199#endif /* HAVE_SYS_TIME_H */
200#endif /* HAVE_SYS_TIMEB_H */
201#endif /* !HAVE_GETTIMEOFDAY */
202
Daniel Veillard01db67c2001-12-18 07:09:59 +0000203#if defined(HAVE_GETTIMEOFDAY)
204static struct timeval begin, end;
205
206/*
207 * startTimer: call where you want to start timing
208 */
209static void
210startTimer(void)
211{
212 gettimeofday(&begin, NULL);
213}
214
215/*
216 * endTimer: call where you want to stop timing and to print out a
217 * message about the timing performed; format is a printf
218 * type argument
219 */
220static void
Daniel Veillard118aed72002-09-24 14:13:13 +0000221endTimer(const char *fmt, ...)
Daniel Veillard01db67c2001-12-18 07:09:59 +0000222{
223 long msec;
224 va_list ap;
225
226 gettimeofday(&end, NULL);
227 msec = end.tv_sec - begin.tv_sec;
228 msec *= 1000;
229 msec += (end.tv_usec - begin.tv_usec) / 1000;
230
231#ifndef HAVE_STDARG_H
232#error "endTimer required stdarg functions"
233#endif
Daniel Veillard118aed72002-09-24 14:13:13 +0000234 va_start(ap, fmt);
235 vfprintf(stderr, fmt, ap);
Daniel Veillard01db67c2001-12-18 07:09:59 +0000236 va_end(ap);
237
238 fprintf(stderr, " took %ld ms\n", msec);
239}
240#elif defined(HAVE_TIME_H)
Daniel Veillard01db67c2001-12-18 07:09:59 +0000241/*
242 * No gettimeofday function, so we have to make do with calling clock.
243 * This is obviously less accurate, but there's little we can do about
244 * that.
245 */
Daniel Veillard90bc3712002-03-07 15:12:58 +0000246#ifndef CLOCKS_PER_SEC
247#define CLOCKS_PER_SEC 100
248#endif
Daniel Veillard01db67c2001-12-18 07:09:59 +0000249
250static clock_t begin, end;
251static void
252startTimer(void)
253{
254 begin = clock();
255}
256static void
257endTimer(const char *fmt, ...)
258{
259 long msec;
260 va_list ap;
261
262 end = clock();
263 msec = ((end - begin) * 1000) / CLOCKS_PER_SEC;
264
265#ifndef HAVE_STDARG_H
266#error "endTimer required stdarg functions"
267#endif
268 va_start(ap, fmt);
269 vfprintf(stderr, fmt, ap);
270 va_end(ap);
271 fprintf(stderr, " took %ld ms\n", msec);
272}
273#else
274
275/*
276 * We don't have a gettimeofday or time.h, so we just don't do timing
277 */
278static void
279startTimer(void)
280{
281 /*
282 * Do nothing
283 */
284}
285static void
286endTimer(char *format, ...)
287{
288 /*
289 * We cannot do anything because we don't have a timing function
290 */
291#ifdef HAVE_STDARG_H
292 va_start(ap, format);
293 vfprintf(stderr, format, ap);
294 va_end(ap);
295 fprintf(stderr, " was not timed\n", msec);
296#else
297 /* We don't have gettimeofday, time or stdarg.h, what crazy world is
298 * this ?!
299 */
300#endif
301}
302#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000303/************************************************************************
304 * *
305 * HTML ouput *
306 * *
307 ************************************************************************/
308char buffer[50000];
309
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000310static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000311xmlHTMLEncodeSend(void) {
312 char *result;
313
314 result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
315 if (result) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000316 xmlGenericError(xmlGenericErrorContext, "%s", result);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000317 xmlFree(result);
318 }
319 buffer[0] = 0;
320}
321
322/**
323 * xmlHTMLPrintFileInfo:
324 * @input: an xmlParserInputPtr input
325 *
326 * Displays the associated file and line informations for the current input
327 */
328
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000329static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000330xmlHTMLPrintFileInfo(xmlParserInputPtr input) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000331 int len;
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000332 xmlGenericError(xmlGenericErrorContext, "<p>");
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000333
334 len = strlen(buffer);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000335 if (input != NULL) {
336 if (input->filename) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000337 snprintf(&buffer[len], sizeof(buffer) - len, "%s:%d: ", input->filename,
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000338 input->line);
339 } else {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000340 snprintf(&buffer[len], sizeof(buffer) - len, "Entity: line %d: ", input->line);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000341 }
342 }
343 xmlHTMLEncodeSend();
344}
345
346/**
347 * xmlHTMLPrintFileContext:
348 * @input: an xmlParserInputPtr input
349 *
350 * Displays current context within the input content for error tracking
351 */
352
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000353static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000354xmlHTMLPrintFileContext(xmlParserInputPtr input) {
355 const xmlChar *cur, *base;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000356 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000357 int n;
358
359 if (input == NULL) return;
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000360 xmlGenericError(xmlGenericErrorContext, "<pre>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000361 cur = input->cur;
362 base = input->base;
363 while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
364 cur--;
365 }
366 n = 0;
367 while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
368 cur--;
369 if ((*cur == '\n') || (*cur == '\r')) cur++;
370 base = cur;
371 n = 0;
372 while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000373 len = strlen(buffer);
374 snprintf(&buffer[len], sizeof(buffer) - len, "%c",
375 (unsigned char) *cur++);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000376 n++;
377 }
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000378 len = strlen(buffer);
379 snprintf(&buffer[len], sizeof(buffer) - len, "\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000380 cur = input->cur;
381 while ((*cur == '\n') || (*cur == '\r'))
382 cur--;
383 n = 0;
384 while ((cur != base) && (n++ < 80)) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000385 len = strlen(buffer);
386 snprintf(&buffer[len], sizeof(buffer) - len, " ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000387 base++;
388 }
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000389 len = strlen(buffer);
390 snprintf(&buffer[len], sizeof(buffer) - len, "^\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000391 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000392 xmlGenericError(xmlGenericErrorContext, "</pre>");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000393}
394
395/**
396 * xmlHTMLError:
397 * @ctx: an XML parser context
398 * @msg: the message to display/transmit
399 * @...: extra parameters for the message display
400 *
401 * Display and format an error messages, gives file, line, position and
402 * extra parameters.
403 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000404static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000405xmlHTMLError(void *ctx, const char *msg, ...)
406{
407 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
408 xmlParserInputPtr input;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000409 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000410 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000411
412 buffer[0] = 0;
413 input = ctxt->input;
414 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000415 input = ctxt->inputTab[ctxt->inputNr - 2];
416 }
417
418 xmlHTMLPrintFileInfo(input);
419
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000420 xmlGenericError(xmlGenericErrorContext, "<b>error</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000421 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000422 len = strlen(buffer);
423 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000424 va_end(args);
425 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000426 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000427
428 xmlHTMLPrintFileContext(input);
429 xmlHTMLEncodeSend();
430}
431
432/**
433 * xmlHTMLWarning:
434 * @ctx: an XML parser context
435 * @msg: the message to display/transmit
436 * @...: extra parameters for the message display
437 *
438 * Display and format a warning messages, gives file, line, position and
439 * extra parameters.
440 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000441static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000442xmlHTMLWarning(void *ctx, const char *msg, ...)
443{
444 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
445 xmlParserInputPtr input;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000446 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000447 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000448
449 buffer[0] = 0;
450 input = ctxt->input;
451 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000452 input = ctxt->inputTab[ctxt->inputNr - 2];
453 }
454
455
456 xmlHTMLPrintFileInfo(input);
457
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000458 xmlGenericError(xmlGenericErrorContext, "<b>warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000459 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000460 len = strlen(buffer);
461 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000462 va_end(args);
463 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000464 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000465
466 xmlHTMLPrintFileContext(input);
467 xmlHTMLEncodeSend();
468}
469
470/**
471 * xmlHTMLValidityError:
472 * @ctx: an XML parser context
473 * @msg: the message to display/transmit
474 * @...: extra parameters for the message display
475 *
476 * Display and format an validity error messages, gives file,
477 * line, position and extra parameters.
478 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000479static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000480xmlHTMLValidityError(void *ctx, const char *msg, ...)
481{
482 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
483 xmlParserInputPtr input;
484 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000485 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000486
487 buffer[0] = 0;
488 input = ctxt->input;
489 if ((input->filename == NULL) && (ctxt->inputNr > 1))
490 input = ctxt->inputTab[ctxt->inputNr - 2];
491
492 xmlHTMLPrintFileInfo(input);
493
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000494 xmlGenericError(xmlGenericErrorContext, "<b>validity error</b>: ");
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000495 len = strlen(buffer);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000496 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000497 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000498 va_end(args);
499 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000500 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000501
502 xmlHTMLPrintFileContext(input);
503 xmlHTMLEncodeSend();
504}
505
506/**
507 * xmlHTMLValidityWarning:
508 * @ctx: an XML parser context
509 * @msg: the message to display/transmit
510 * @...: extra parameters for the message display
511 *
512 * Display and format a validity warning messages, gives file, line,
513 * position and extra parameters.
514 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000515static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000516xmlHTMLValidityWarning(void *ctx, const char *msg, ...)
517{
518 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
519 xmlParserInputPtr input;
520 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000521 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000522
523 buffer[0] = 0;
524 input = ctxt->input;
525 if ((input->filename == NULL) && (ctxt->inputNr > 1))
526 input = ctxt->inputTab[ctxt->inputNr - 2];
527
528 xmlHTMLPrintFileInfo(input);
529
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000530 xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000531 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000532 len = strlen(buffer);
533 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000534 va_end(args);
535 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000536 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000537
538 xmlHTMLPrintFileContext(input);
539 xmlHTMLEncodeSend();
540}
541
542/************************************************************************
543 * *
544 * Shell Interface *
545 * *
546 ************************************************************************/
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000547#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000548/**
549 * xmlShellReadline:
550 * @prompt: the prompt value
551 *
552 * Read a string
553 *
554 * Returns a pointer to it or NULL on EOF the caller is expected to
555 * free the returned string.
556 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000557static char *
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000558xmlShellReadline(char *prompt) {
559#ifdef HAVE_LIBREADLINE
560 char *line_read;
561
562 /* Get a line from the user. */
563 line_read = readline (prompt);
564
565 /* If the line has any text in it, save it on the history. */
566 if (line_read && *line_read)
567 add_history (line_read);
568
569 return (line_read);
570#else
571 char line_read[501];
Daniel Veillard29e43992001-12-13 22:21:58 +0000572 char *ret;
573 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000574
575 if (prompt != NULL)
576 fprintf(stdout, "%s", prompt);
577 if (!fgets(line_read, 500, stdin))
578 return(NULL);
579 line_read[500] = 0;
Daniel Veillard29e43992001-12-13 22:21:58 +0000580 len = strlen(line_read);
581 ret = (char *) malloc(len + 1);
582 if (ret != NULL) {
583 memcpy (ret, line_read, len + 1);
584 }
585 return(ret);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000586#endif
587}
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000588#endif /* LIBXML_DEBUG_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000589
590/************************************************************************
591 * *
Daniel Veillard5e873c42000-04-12 13:27:38 +0000592 * I/O Interfaces *
593 * *
594 ************************************************************************/
595
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000596static int myRead(FILE *f, char * buf, int len) {
597 return(fread(buf, 1, len, f));
Daniel Veillard5e873c42000-04-12 13:27:38 +0000598}
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000599static void myClose(FILE *f) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000600 if (f != stdin) {
Daniel Veillard5e873c42000-04-12 13:27:38 +0000601 fclose(f);
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000602 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000603}
604
Daniel Veillard81273902003-09-30 00:43:48 +0000605#ifdef LIBXML_READER_ENABLED
Daniel Veillard5e873c42000-04-12 13:27:38 +0000606/************************************************************************
607 * *
Daniel Veillard7704fb12003-01-03 16:19:51 +0000608 * Stream Test processing *
609 * *
610 ************************************************************************/
Daniel Veillard7704fb12003-01-03 16:19:51 +0000611static void processNode(xmlTextReaderPtr reader) {
Daniel Veillard198c1bf2003-10-20 17:07:41 +0000612 const xmlChar *name, *value;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000613
Daniel Veillard198c1bf2003-10-20 17:07:41 +0000614 name = xmlTextReaderConstName(reader);
Daniel Veillarde59494f2003-01-04 16:35:29 +0000615 if (name == NULL)
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000616 name = BAD_CAST "--";
Daniel Veillard99737f52003-03-22 14:55:50 +0000617
Daniel Veillard198c1bf2003-10-20 17:07:41 +0000618 value = xmlTextReaderConstValue(reader);
Daniel Veillard7704fb12003-01-03 16:19:51 +0000619
Daniel Veillard99737f52003-03-22 14:55:50 +0000620 printf("%d %d %s %d %d",
Daniel Veillarde59494f2003-01-04 16:35:29 +0000621 xmlTextReaderDepth(reader),
622 xmlTextReaderNodeType(reader),
623 name,
Daniel Veillard99737f52003-03-22 14:55:50 +0000624 xmlTextReaderIsEmptyElement(reader),
625 xmlTextReaderHasValue(reader));
Daniel Veillarde59494f2003-01-04 16:35:29 +0000626 if (value == NULL)
627 printf("\n");
628 else {
629 printf(" %s\n", value);
Daniel Veillard7704fb12003-01-03 16:19:51 +0000630 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000631#ifdef LIBXML_PATTERN_ENABLED
632 if (patternc) {
633 if (xmlPatternMatch(patternc, xmlTextReaderCurrentNode(reader)) == 1) {
634 printf("Node matches pattern %s\n", pattern);
635 }
636 }
637#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000638}
639
640static void streamFile(char *filename) {
641 xmlTextReaderPtr reader;
642 int ret;
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000643#ifdef HAVE_SYS_MMAN_H
644 int fd = -1;
645 struct stat info;
646 const char *base = NULL;
647 xmlParserInputBufferPtr input = NULL;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000648
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000649 if (memory) {
650 if (stat(filename, &info) < 0)
651 return;
652 if ((fd = open(filename, O_RDONLY)) < 0)
653 return;
654 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
655 if (base == (void *) MAP_FAILED)
656 return;
657
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000658 reader = xmlReaderForMemory(base, info.st_size, filename,
659 NULL, options);
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000660 } else
661#endif
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000662 reader = xmlReaderForFile(filename, NULL, options);
663
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000664
Daniel Veillard7704fb12003-01-03 16:19:51 +0000665 if (reader != NULL) {
Daniel Veillard4432df22003-09-28 18:58:27 +0000666#ifdef LIBXML_VALID_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +0000667 if (valid)
668 xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);
Daniel Veillardce192eb2003-04-16 15:58:05 +0000669 else
Daniel Veillard4432df22003-09-28 18:58:27 +0000670#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardce192eb2003-04-16 15:58:05 +0000671 xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1);
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000672#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardce192eb2003-04-16 15:58:05 +0000673 if (relaxng != NULL) {
Daniel Veillard81514ba2003-09-16 23:17:26 +0000674 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000675 startTimer();
676 }
677 ret = xmlTextReaderRelaxNGValidate(reader, relaxng);
678 if (ret < 0) {
679 xmlGenericError(xmlGenericErrorContext,
680 "Relax-NG schema %s failed to compile\n", relaxng);
Daniel Veillard05d987b2003-10-08 11:54:57 +0000681 progresult = 5;
Daniel Veillardce192eb2003-04-16 15:58:05 +0000682 relaxng = NULL;
683 }
Daniel Veillard81514ba2003-09-16 23:17:26 +0000684 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000685 endTimer("Compiling the schemas");
686 }
687 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000688#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000689
690 /*
691 * Process all nodes in sequence
692 */
Daniel Veillard81514ba2003-09-16 23:17:26 +0000693 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000694 startTimer();
695 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000696 ret = xmlTextReaderRead(reader);
697 while (ret == 1) {
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000698 if ((debug)
699#ifdef LIBXML_PATTERN_ENABLED
700 || (patternc)
701#endif
702 )
Daniel Veillard7704fb12003-01-03 16:19:51 +0000703 processNode(reader);
704 ret = xmlTextReaderRead(reader);
705 }
Daniel Veillard81514ba2003-09-16 23:17:26 +0000706 if ((timing) && (!repeat)) {
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000707#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardf54cd532004-02-25 11:52:31 +0000708 if (relaxng != NULL)
Daniel Veillard49138f12004-02-19 12:58:36 +0000709 endTimer("Parsing and validating");
710 else
Daniel Veillardf54cd532004-02-25 11:52:31 +0000711#endif
Daniel Veillard4432df22003-09-28 18:58:27 +0000712#ifdef LIBXML_VALID_ENABLED
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000713 if (valid)
Daniel Veillardce192eb2003-04-16 15:58:05 +0000714 endTimer("Parsing and validating");
715 else
Daniel Veillard4432df22003-09-28 18:58:27 +0000716#endif
Daniel Veillardf54cd532004-02-25 11:52:31 +0000717 endTimer("Parsing");
Daniel Veillardce192eb2003-04-16 15:58:05 +0000718 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000719
Daniel Veillard4432df22003-09-28 18:58:27 +0000720#ifdef LIBXML_VALID_ENABLED
Daniel Veillardf6bad792003-04-11 19:38:54 +0000721 if (valid) {
722 if (xmlTextReaderIsValid(reader) != 1) {
723 xmlGenericError(xmlGenericErrorContext,
724 "Document %s does not validate\n", filename);
725 progresult = 3;
726 }
727 }
Daniel Veillard4432df22003-09-28 18:58:27 +0000728#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000729#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardf4e55762003-04-15 23:32:22 +0000730 if (relaxng != NULL) {
731 if (xmlTextReaderIsValid(reader) != 1) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +0000732 fprintf(stderr, "%s fails to validate\n", filename);
Daniel Veillardf4e55762003-04-15 23:32:22 +0000733 progresult = 3;
734 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +0000735 fprintf(stderr, "%s validates\n", filename);
Daniel Veillardf4e55762003-04-15 23:32:22 +0000736 }
737 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000738#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000739 /*
740 * Done, cleanup and status
741 */
742 xmlFreeTextReader(reader);
743 if (ret != 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +0000744 fprintf(stderr, "%s : failed to parse\n", filename);
Daniel Veillardf6bad792003-04-11 19:38:54 +0000745 progresult = 1;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000746 }
747 } else {
748 fprintf(stderr, "Unable to open %s\n", filename);
Daniel Veillardf6bad792003-04-11 19:38:54 +0000749 progresult = 1;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000750 }
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000751#ifdef HAVE_SYS_MMAN_H
752 if (memory) {
753 xmlFreeParserInputBuffer(input);
754 munmap((char *) base, info.st_size);
755 close(fd);
756 }
757#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000758}
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000759
760static void walkDoc(xmlDocPtr doc) {
761 xmlTextReaderPtr reader;
762 int ret;
763
764 reader = xmlReaderWalker(doc);
765 if (reader != NULL) {
766 if ((timing) && (!repeat)) {
767 startTimer();
768 }
769 ret = xmlTextReaderRead(reader);
770 while (ret == 1) {
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000771 if ((debug)
772#ifdef LIBXML_PATTERN_ENABLED
773 || (patternc)
774#endif
775 )
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000776 processNode(reader);
777 ret = xmlTextReaderRead(reader);
778 }
779 if ((timing) && (!repeat)) {
780 endTimer("walking through the doc");
781 }
782 xmlFreeTextReader(reader);
783 if (ret != 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +0000784 fprintf(stderr, "failed to walk through the doc\n");
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000785 progresult = 1;
786 }
787 } else {
788 fprintf(stderr, "Failed to crate a reader from the document\n");
789 progresult = 1;
790 }
791}
Daniel Veillard81273902003-09-30 00:43:48 +0000792#endif /* LIBXML_READER_ENABLED */
Daniel Veillard7704fb12003-01-03 16:19:51 +0000793
794/************************************************************************
795 * *
796 * Tree Test processing *
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000797 * *
798 ************************************************************************/
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000799static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
Daniel Veillard652327a2003-09-29 18:02:38 +0000800 xmlDocPtr doc = NULL;
801#ifdef LIBXML_TREE_ENABLED
802 xmlDocPtr tmp;
803#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000804
Daniel Veillard48b2f892001-02-25 16:11:03 +0000805 if ((timing) && (!repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +0000806 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +0000807
808
Daniel Veillard652327a2003-09-29 18:02:38 +0000809#ifdef LIBXML_TREE_ENABLED
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000810 if (filename == NULL) {
811 if (generate) {
812 xmlNodePtr n;
813
814 doc = xmlNewDoc(BAD_CAST "1.0");
815 n = xmlNewNode(NULL, BAD_CAST "info");
816 xmlNodeSetContent(n, BAD_CAST "abc");
817 xmlDocSetRootElement(doc, n);
818 }
819 }
Daniel Veillard652327a2003-09-29 18:02:38 +0000820#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000821#ifdef LIBXML_HTML_ENABLED
Daniel Veillard73b013f2003-09-30 12:36:01 +0000822#ifdef LIBXML_PUSH_ENABLED
William M. Brack78637da2003-07-31 14:47:38 +0000823 else if ((html) && (push)) {
824 FILE *f;
825
826 f = fopen(filename, "r");
827 if (f != NULL) {
828 int res, size = 3;
829 char chars[4096];
830 htmlParserCtxtPtr ctxt;
831
832 /* if (repeat) */
833 size = 4096;
834 res = fread(chars, 1, 4, f);
835 if (res > 0) {
836 ctxt = htmlCreatePushParserCtxt(NULL, NULL,
William M. Brack1d75c8a2003-10-27 13:48:16 +0000837 chars, res, filename, XML_CHAR_ENCODING_NONE);
William M. Brack78637da2003-07-31 14:47:38 +0000838 while ((res = fread(chars, 1, size, f)) > 0) {
839 htmlParseChunk(ctxt, chars, res, 0);
840 }
841 htmlParseChunk(ctxt, chars, 0, 1);
842 doc = ctxt->myDoc;
843 htmlFreeParserCtxt(ctxt);
844 }
845 fclose(f);
846 }
847 }
Daniel Veillard73b013f2003-09-30 12:36:01 +0000848#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000849 else if (html) {
Daniel Veillard9475a352003-09-26 12:47:50 +0000850 doc = htmlReadFile(filename, NULL, options);
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000851 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000852#endif /* LIBXML_HTML_ENABLED */
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000853 else {
Daniel Veillard73b013f2003-09-30 12:36:01 +0000854#ifdef LIBXML_PUSH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000855 /*
856 * build an XML tree from a string;
857 */
858 if (push) {
859 FILE *f;
860
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000861 /* '-' Usually means stdin -<sven@zen.org> */
862 if ((filename[0] == '-') && (filename[1] == 0)) {
863 f = stdin;
864 } else {
865 f = fopen(filename, "r");
866 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000867 if (f != NULL) {
Daniel Veillarde715dd22000-08-29 18:29:38 +0000868 int ret;
Daniel Veillarda880b122003-04-21 21:36:41 +0000869 int res, size = 1024;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000870 char chars[1024];
871 xmlParserCtxtPtr ctxt;
872
Daniel Veillarda880b122003-04-21 21:36:41 +0000873 /* if (repeat) size = 1024; */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000874 res = fread(chars, 1, 4, f);
875 if (res > 0) {
876 ctxt = xmlCreatePushParserCtxt(NULL, NULL,
877 chars, res, filename);
Daniel Veillard500a1de2004-03-22 15:22:58 +0000878 xmlCtxtUseOptions(ctxt, options);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000879 while ((res = fread(chars, 1, size, f)) > 0) {
880 xmlParseChunk(ctxt, chars, res, 0);
881 }
882 xmlParseChunk(ctxt, chars, 0, 1);
883 doc = ctxt->myDoc;
Daniel Veillarde715dd22000-08-29 18:29:38 +0000884 ret = ctxt->wellFormed;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000885 xmlFreeParserCtxt(ctxt);
Daniel Veillarde715dd22000-08-29 18:29:38 +0000886 if (!ret) {
887 xmlFreeDoc(doc);
888 doc = NULL;
889 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000890 }
891 }
Daniel Veillard73b013f2003-09-30 12:36:01 +0000892 } else
893#endif /* LIBXML_PUSH_ENABLED */
894 if (testIO) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000895 if ((filename[0] == '-') && (filename[1] == 0)) {
Daniel Veillard60942de2003-09-25 21:05:58 +0000896 doc = xmlReadFd(0, NULL, NULL, options);
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000897 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000898 FILE *f;
Daniel Veillard5e873c42000-04-12 13:27:38 +0000899
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000900 f = fopen(filename, "r");
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000901 if (f != NULL) {
902 if (rectxt == NULL)
903 doc = xmlReadIO((xmlInputReadCallback) myRead,
904 (xmlInputCloseCallback) myClose, f,
Daniel Veillard60942de2003-09-25 21:05:58 +0000905 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000906 else
907 doc = xmlCtxtReadIO(rectxt,
908 (xmlInputReadCallback) myRead,
909 (xmlInputCloseCallback) myClose, f,
Daniel Veillard60942de2003-09-25 21:05:58 +0000910 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000911 } else
Daniel Veillard5e873c42000-04-12 13:27:38 +0000912 doc = NULL;
Daniel Veillard5e873c42000-04-12 13:27:38 +0000913 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000914 } else if (htmlout) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000915 xmlParserCtxtPtr ctxt;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000916
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000917 if (rectxt == NULL)
918 ctxt = xmlNewParserCtxt();
919 else
920 ctxt = rectxt;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000921 if (ctxt == NULL) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000922 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000923 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000924 ctxt->sax->error = xmlHTMLError;
925 ctxt->sax->warning = xmlHTMLWarning;
926 ctxt->vctxt.error = xmlHTMLValidityError;
927 ctxt->vctxt.warning = xmlHTMLValidityWarning;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000928
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000929 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000930
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000931 if (rectxt == NULL)
932 xmlFreeParserCtxt(ctxt);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000933 }
Daniel Veillard46e370e2000-07-21 20:32:03 +0000934#ifdef HAVE_SYS_MMAN_H
935 } else if (memory) {
936 int fd;
937 struct stat info;
938 const char *base;
939 if (stat(filename, &info) < 0)
940 return;
941 if ((fd = open(filename, O_RDONLY)) < 0)
942 return;
943 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
Daniel Veillard29579362000-08-14 17:57:48 +0000944 if (base == (void *) MAP_FAILED)
Daniel Veillard46e370e2000-07-21 20:32:03 +0000945 return;
946
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000947 if (rectxt == NULL)
Daniel Veillard60942de2003-09-25 21:05:58 +0000948 doc = xmlReadMemory((char *) base, info.st_size,
949 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000950 else
Daniel Veillard60942de2003-09-25 21:05:58 +0000951 doc = xmlCtxtReadMemory(rectxt, (char *) base, info.st_size,
952 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000953
Daniel Veillard46e370e2000-07-21 20:32:03 +0000954 munmap((char *) base, info.st_size);
955#endif
Daniel Veillard4432df22003-09-28 18:58:27 +0000956#ifdef LIBXML_VALID_ENABLED
Daniel Veillardea7751d2002-12-20 00:16:24 +0000957 } else if (valid) {
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000958 xmlParserCtxtPtr ctxt = NULL;
Daniel Veillardea7751d2002-12-20 00:16:24 +0000959
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000960 if (rectxt == NULL)
961 ctxt = xmlNewParserCtxt();
962 else
963 ctxt = rectxt;
Daniel Veillardea7751d2002-12-20 00:16:24 +0000964 if (ctxt == NULL) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000965 doc = NULL;
Daniel Veillardea7751d2002-12-20 00:16:24 +0000966 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000967 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
968
969 if (ctxt->valid == 0)
970 progresult = 4;
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000971 if (rectxt == NULL)
972 xmlFreeParserCtxt(ctxt);
Daniel Veillardea7751d2002-12-20 00:16:24 +0000973 }
Daniel Veillard4432df22003-09-28 18:58:27 +0000974#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardea7751d2002-12-20 00:16:24 +0000975 } else {
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000976 if (rectxt != NULL)
977 doc = xmlCtxtReadFile(rectxt, filename, NULL, options);
978 else
979 doc = xmlReadFile(filename, NULL, options);
Daniel Veillardea7751d2002-12-20 00:16:24 +0000980 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000981 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000982
Daniel Veillard88a172f2000-08-04 18:23:10 +0000983 /*
984 * If we don't have a document we might as well give up. Do we
985 * want an error message here? <sven@zen.org> */
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000986 if (doc == NULL) {
Daniel Veillardf7cd4812001-02-23 18:44:52 +0000987 progresult = 1;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000988 return;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000989 }
990
Daniel Veillard48b2f892001-02-25 16:11:03 +0000991 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +0000992 endTimer("Parsing");
Daniel Veillard48b2f892001-02-25 16:11:03 +0000993 }
994
Daniel Veillard29e43992001-12-13 22:21:58 +0000995 /*
996 * Remove DOCTYPE nodes
997 */
998 if (dropdtd) {
999 xmlDtdPtr dtd;
1000
1001 dtd = xmlGetIntSubset(doc);
1002 if (dtd != NULL) {
1003 xmlUnlinkNode((xmlNodePtr)dtd);
1004 xmlFreeDtd(dtd);
1005 }
1006 }
1007
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001008#ifdef LIBXML_XINCLUDE_ENABLED
Daniel Veillard48b2f892001-02-25 16:11:03 +00001009 if (xinclude) {
1010 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001011 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001012 }
Daniel Veillarde74d2e12003-12-09 11:35:37 +00001013 xmlXIncludeProcessFlags(doc, options);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001014 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001015 endTimer("Xinclude processing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001016 }
1017 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001018#endif
Daniel Veillard88a172f2000-08-04 18:23:10 +00001019
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001020#ifdef LIBXML_DEBUG_ENABLED
1021 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001022 * shell interaction
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001023 */
1024 if (shell)
1025 xmlShell(doc, filename, xmlShellReadline, stdout);
1026#endif
1027
Daniel Veillard652327a2003-09-29 18:02:38 +00001028#ifdef LIBXML_TREE_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001029 /*
1030 * test intermediate copy if needed.
1031 */
1032 if (copy) {
1033 tmp = doc;
1034 doc = xmlCopyDoc(doc, 1);
1035 xmlFreeDoc(tmp);
1036 }
Daniel Veillard652327a2003-09-29 18:02:38 +00001037#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001038
Daniel Veillard4432df22003-09-28 18:58:27 +00001039#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001040 if ((insert) && (!html)) {
1041 const xmlChar* list[256];
1042 int nb, i;
1043 xmlNodePtr node;
1044
1045 if (doc->children != NULL) {
1046 node = doc->children;
1047 while ((node != NULL) && (node->last == NULL)) node = node->next;
1048 if (node != NULL) {
1049 nb = xmlValidGetValidElements(node->last, NULL, list, 256);
1050 if (nb < 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001051 fprintf(stderr, "could not get valid list of elements\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001052 } else if (nb == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001053 fprintf(stderr, "No element can be inserted under root\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001054 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001055 fprintf(stderr, "%d element types can be inserted under root:\n",
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001056 nb);
1057 for (i = 0;i < nb;i++) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001058 fprintf(stderr, "%s\n", (char *) list[i]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001059 }
1060 }
1061 }
1062 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001063 }else
1064#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001065#ifdef LIBXML_READER_ENABLED
1066 if (walker) {
1067 walkDoc(doc);
1068 }
1069#endif /* LIBXML_READER_ENABLED */
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001070#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard4432df22003-09-28 18:58:27 +00001071 if (noout == 0) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001072 int ret;
1073
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001074 /*
1075 * print it.
1076 */
1077#ifdef LIBXML_DEBUG_ENABLED
1078 if (!debug) {
1079#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +00001080 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001081 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001082 }
Daniel Veillard656ce942004-04-30 23:11:45 +00001083#ifdef LIBXML_HTML_ENABLED
Daniel Veillard42fd4122003-11-04 08:47:48 +00001084 if ((html) && (!xmlout)) {
1085 if (compress) {
1086 htmlSaveFile(output ? output : "-", doc);
1087 }
1088 else if (encoding != NULL) {
1089 if ( format ) {
1090 htmlSaveFileFormat(output ? output : "-", doc, encoding, 1);
1091 }
1092 else {
1093 htmlSaveFileFormat(output ? output : "-", doc, encoding, 0);
1094 }
1095 }
1096 else if (format) {
1097 htmlSaveFileFormat(output ? output : "-", doc, NULL, 1);
1098 }
1099 else {
1100 FILE *out;
1101 if (output == NULL)
1102 out = stdout;
1103 else {
1104 out = fopen(output,"wb");
1105 }
1106 if (out != NULL) {
1107 if (htmlDocDump(out, doc) < 0)
1108 progresult = 6;
1109
1110 if (output != NULL)
1111 fclose(out);
1112 } else {
1113 fprintf(stderr, "failed to open %s\n", output);
1114 progresult = 6;
1115 }
1116 }
1117 if ((timing) && (!repeat)) {
1118 endTimer("Saving");
1119 }
1120 } else
1121#endif
Daniel Veillard3b2c2612001-04-04 00:09:00 +00001122#ifdef HAVE_SYS_MMAN_H
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001123 if (memory) {
1124 xmlChar *result;
1125 int len;
1126
1127 if (encoding != NULL) {
Daniel Veillardd536f702001-11-08 17:32:47 +00001128 if ( format ) {
1129 xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1);
1130 } else {
1131 xmlDocDumpMemoryEnc(doc, &result, &len, encoding);
1132 }
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001133 } else {
Daniel Veillard90493a92001-08-14 14:12:47 +00001134 if (format)
1135 xmlDocDumpFormatMemory(doc, &result, &len, 1);
1136 else
1137 xmlDocDumpMemory(doc, &result, &len);
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001138 }
1139 if (result == NULL) {
1140 fprintf(stderr, "Failed to save\n");
1141 } else {
1142 write(1, result, len);
1143 xmlFree(result);
1144 }
Daniel Veillard3b2c2612001-04-04 00:09:00 +00001145 } else
1146#endif /* HAVE_SYS_MMAN_H */
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001147 if (compress) {
1148 xmlSaveFile(output ? output : "-", doc);
1149 }
Daniel Veillardd536f702001-11-08 17:32:47 +00001150 else if (encoding != NULL) {
1151 if ( format ) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001152 ret = xmlSaveFormatFileEnc(output ? output : "-", doc,
1153 encoding, 1);
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001154 }
Daniel Veillardd536f702001-11-08 17:32:47 +00001155 else {
Daniel Veillard3df01182003-12-10 10:17:51 +00001156 ret = xmlSaveFileEnc(output ? output : "-", doc, encoding);
1157 }
1158 if (ret < 0) {
1159 fprintf(stderr, "failed save to %s\n",
1160 output ? output : "-");
1161 progresult = 6;
Daniel Veillardd536f702001-11-08 17:32:47 +00001162 }
1163 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001164 else if (format) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001165 ret = xmlSaveFormatFile(output ? output : "-", doc, 1);
1166 if (ret < 0) {
1167 fprintf(stderr, "failed save to %s\n",
1168 output ? output : "-");
1169 progresult = 6;
1170 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001171 }
1172 else {
1173 FILE *out;
1174 if (output == NULL)
1175 out = stdout;
1176 else {
1177 out = fopen(output,"wb");
1178 }
Daniel Veillard05d987b2003-10-08 11:54:57 +00001179 if (out != NULL) {
Daniel Veillard828ce832003-10-08 19:19:10 +00001180 if (xmlDocDump(out, doc) < 0)
1181 progresult = 6;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001182
Daniel Veillard05d987b2003-10-08 11:54:57 +00001183 if (output != NULL)
1184 fclose(out);
1185 } else {
1186 fprintf(stderr, "failed to open %s\n", output);
1187 progresult = 6;
1188 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001189 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001190 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001191 endTimer("Saving");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001192 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001193#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001194 } else {
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001195 FILE *out;
1196 if (output == NULL)
1197 out = stdout;
1198 else {
1199 out = fopen(output,"wb");
1200 }
Daniel Veillard05d987b2003-10-08 11:54:57 +00001201 if (out != NULL) {
1202 xmlDebugDumpDocument(out, doc);
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001203
Daniel Veillard05d987b2003-10-08 11:54:57 +00001204 if (output != NULL)
1205 fclose(out);
1206 } else {
1207 fprintf(stderr, "failed to open %s\n", output);
1208 progresult = 6;
1209 }
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001210 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001211#endif
1212 }
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001213#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001214
Daniel Veillard4432df22003-09-28 18:58:27 +00001215#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001216 /*
1217 * A posteriori validation test
1218 */
Daniel Veillard66f68e72003-08-18 16:39:51 +00001219 if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) {
Daniel Veillardcd429612000-10-11 15:57:05 +00001220 xmlDtdPtr dtd;
1221
Daniel Veillard48b2f892001-02-25 16:11:03 +00001222 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001223 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001224 }
Daniel Veillard66f68e72003-08-18 16:39:51 +00001225 if (dtdvalid != NULL)
1226 dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid);
1227 else
1228 dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001229 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001230 endTimer("Parsing DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001231 }
Daniel Veillardcd429612000-10-11 15:57:05 +00001232 if (dtd == NULL) {
Daniel Veillard66f68e72003-08-18 16:39:51 +00001233 if (dtdvalid != NULL)
1234 xmlGenericError(xmlGenericErrorContext,
1235 "Could not parse DTD %s\n", dtdvalid);
1236 else
1237 xmlGenericError(xmlGenericErrorContext,
1238 "Could not parse DTD %s\n", dtdvalidfpi);
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001239 progresult = 2;
Daniel Veillardcd429612000-10-11 15:57:05 +00001240 } else {
Daniel Veillarda37aab82003-06-09 09:10:36 +00001241 xmlValidCtxtPtr cvp;
1242
1243 if ((cvp = xmlNewValidCtxt()) == NULL) {
1244 xmlGenericError(xmlGenericErrorContext,
1245 "Couldn't allocate validation context\n");
1246 exit(-1);
1247 }
1248 cvp->userData = (void *) stderr;
1249 cvp->error = (xmlValidityErrorFunc) fprintf;
1250 cvp->warning = (xmlValidityWarningFunc) fprintf;
1251
Daniel Veillard48b2f892001-02-25 16:11:03 +00001252 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001253 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001254 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001255 if (!xmlValidateDtd(cvp, doc, dtd)) {
Daniel Veillard66f68e72003-08-18 16:39:51 +00001256 if (dtdvalid != NULL)
1257 xmlGenericError(xmlGenericErrorContext,
1258 "Document %s does not validate against %s\n",
1259 filename, dtdvalid);
1260 else
1261 xmlGenericError(xmlGenericErrorContext,
1262 "Document %s does not validate against %s\n",
1263 filename, dtdvalidfpi);
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001264 progresult = 3;
Daniel Veillardcd429612000-10-11 15:57:05 +00001265 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001266 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001267 endTimer("Validating against DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001268 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001269 xmlFreeValidCtxt(cvp);
Daniel Veillardcd429612000-10-11 15:57:05 +00001270 xmlFreeDtd(dtd);
1271 }
1272 } else if (postvalid) {
Daniel Veillarda37aab82003-06-09 09:10:36 +00001273 xmlValidCtxtPtr cvp;
1274
1275 if ((cvp = xmlNewValidCtxt()) == NULL) {
1276 xmlGenericError(xmlGenericErrorContext,
1277 "Couldn't allocate validation context\n");
1278 exit(-1);
1279 }
1280
Daniel Veillard48b2f892001-02-25 16:11:03 +00001281 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001282 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001283 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001284 cvp->userData = (void *) stderr;
1285 cvp->error = (xmlValidityErrorFunc) fprintf;
1286 cvp->warning = (xmlValidityWarningFunc) fprintf;
1287 if (!xmlValidateDocument(cvp, doc)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001288 xmlGenericError(xmlGenericErrorContext,
1289 "Document %s does not validate\n", filename);
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001290 progresult = 3;
Daniel Veillardcd429612000-10-11 15:57:05 +00001291 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001292 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001293 endTimer("Validating");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001294 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001295 xmlFreeValidCtxt(cvp);
Daniel Veillard4432df22003-09-28 18:58:27 +00001296 }
1297#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard71531f32003-02-05 13:19:53 +00001298#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard4432df22003-09-28 18:58:27 +00001299 if (relaxngschemas != NULL) {
Daniel Veillard71531f32003-02-05 13:19:53 +00001300 xmlRelaxNGValidCtxtPtr ctxt;
1301 int ret;
1302
Daniel Veillard42f12e92003-03-07 18:32:59 +00001303 if ((timing) && (!repeat)) {
1304 startTimer();
1305 }
1306
Daniel Veillard71531f32003-02-05 13:19:53 +00001307 ctxt = xmlRelaxNGNewValidCtxt(relaxngschemas);
1308 xmlRelaxNGSetValidErrors(ctxt,
1309 (xmlRelaxNGValidityErrorFunc) fprintf,
1310 (xmlRelaxNGValidityWarningFunc) fprintf,
1311 stderr);
1312 ret = xmlRelaxNGValidateDoc(ctxt, doc);
1313 if (ret == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001314 fprintf(stderr, "%s validates\n", filename);
Daniel Veillard71531f32003-02-05 13:19:53 +00001315 } else if (ret > 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001316 fprintf(stderr, "%s fails to validate\n", filename);
Daniel Veillard71531f32003-02-05 13:19:53 +00001317 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001318 fprintf(stderr, "%s validation generated an internal error\n",
Daniel Veillard71531f32003-02-05 13:19:53 +00001319 filename);
1320 }
1321 xmlRelaxNGFreeValidCtxt(ctxt);
Daniel Veillard42f12e92003-03-07 18:32:59 +00001322 if ((timing) && (!repeat)) {
1323 endTimer("Validating");
1324 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001325 } else if (wxschemas != NULL) {
1326 xmlSchemaValidCtxtPtr ctxt;
1327 int ret;
1328
1329 if ((timing) && (!repeat)) {
1330 startTimer();
1331 }
1332
1333 ctxt = xmlSchemaNewValidCtxt(wxschemas);
1334 xmlSchemaSetValidErrors(ctxt,
1335 (xmlSchemaValidityErrorFunc) fprintf,
1336 (xmlSchemaValidityWarningFunc) fprintf,
1337 stderr);
1338 ret = xmlSchemaValidateDoc(ctxt, doc);
1339 if (ret == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001340 fprintf(stderr, "%s validates\n", filename);
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001341 } else if (ret > 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001342 fprintf(stderr, "%s fails to validate\n", filename);
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001343 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001344 fprintf(stderr, "%s validation generated an internal error\n",
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001345 filename);
1346 }
1347 xmlSchemaFreeValidCtxt(ctxt);
1348 if ((timing) && (!repeat)) {
1349 endTimer("Validating");
1350 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001351 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001352#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001353
1354#ifdef LIBXML_DEBUG_ENABLED
1355 if ((debugent) && (!html))
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001356 xmlDebugDumpEntities(stderr, doc);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001357#endif
1358
1359 /*
1360 * free it.
1361 */
Daniel Veillard48b2f892001-02-25 16:11:03 +00001362 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001363 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001364 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001365 xmlFreeDoc(doc);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001366 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001367 endTimer("Freeing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001368 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001369}
1370
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001371/************************************************************************
1372 * *
1373 * Usage and Main *
1374 * *
1375 ************************************************************************/
1376
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001377static void showVersion(const char *name) {
1378 fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion);
1379 fprintf(stderr, " compiled with: ");
Daniel Veillard4432df22003-09-28 18:58:27 +00001380#ifdef LIBXML_VALID_ENABLED
1381 fprintf(stderr, "DTDValid ");
1382#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001383#ifdef LIBXML_FTP_ENABLED
1384 fprintf(stderr, "FTP ");
1385#endif
1386#ifdef LIBXML_HTTP_ENABLED
1387 fprintf(stderr, "HTTP ");
1388#endif
1389#ifdef LIBXML_HTML_ENABLED
1390 fprintf(stderr, "HTML ");
1391#endif
1392#ifdef LIBXML_C14N_ENABLED
1393 fprintf(stderr, "C14N ");
1394#endif
1395#ifdef LIBXML_CATALOG_ENABLED
1396 fprintf(stderr, "Catalog ");
1397#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001398#ifdef LIBXML_XPATH_ENABLED
1399 fprintf(stderr, "XPath ");
1400#endif
1401#ifdef LIBXML_XPTR_ENABLED
1402 fprintf(stderr, "XPointer ");
1403#endif
1404#ifdef LIBXML_XINCLUDE_ENABLED
1405 fprintf(stderr, "XInclude ");
1406#endif
1407#ifdef LIBXML_ICONV_ENABLED
1408 fprintf(stderr, "Iconv ");
1409#endif
1410#ifdef DEBUG_MEMORY_LOCATION
1411 fprintf(stderr, "MemDebug ");
1412#endif
1413#ifdef LIBXML_UNICODE_ENABLED
1414 fprintf(stderr, "Unicode ");
1415#endif
1416#ifdef LIBXML_REGEXP_ENABLED
1417 fprintf(stderr, "Regexps ");
1418#endif
1419#ifdef LIBXML_AUTOMATA_ENABLED
1420 fprintf(stderr, "Automata ");
1421#endif
1422#ifdef LIBXML_SCHEMAS_ENABLED
1423 fprintf(stderr, "Schemas ");
1424#endif
1425 fprintf(stderr, "\n");
1426}
1427
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001428static void usage(const char *name) {
1429 printf("Usage : %s [options] XMLfiles ...\n", name);
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001430#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001431 printf("\tParse the XML files and output the result of the parsing\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001432#else
1433 printf("\tParse the XML files\n");
1434#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001435 printf("\t--version : display the version of the XML library used\n");
1436#ifdef LIBXML_DEBUG_ENABLED
1437 printf("\t--debug : dump a debug tree of the in-memory document\n");
1438 printf("\t--shell : run a navigating shell\n");
1439 printf("\t--debugent : debug the entities defined in the document\n");
Daniel Veillard8326e732003-01-07 00:19:07 +00001440#else
Daniel Veillard81273902003-09-30 00:43:48 +00001441#ifdef LIBXML_READER_ENABLED
Daniel Veillard8326e732003-01-07 00:19:07 +00001442 printf("\t--debug : dump the nodes content when using --stream\n");
Daniel Veillard81273902003-09-30 00:43:48 +00001443#endif /* LIBXML_READER_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001444#endif
Daniel Veillard652327a2003-09-29 18:02:38 +00001445#ifdef LIBXML_TREE_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001446 printf("\t--copy : used to test the internal copy implementation\n");
Daniel Veillard652327a2003-09-29 18:02:38 +00001447#endif /* LIBXML_TREE_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001448 printf("\t--recover : output what was parsable on broken XML documents\n");
1449 printf("\t--noent : substitute entity references by their value\n");
1450 printf("\t--noout : don't output the result tree\n");
Daniel Veillarde8b09e42003-05-13 22:14:13 +00001451 printf("\t--nonet : refuse to fetch DTDs or entities over network\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001452 printf("\t--htmlout : output results as HTML\n");
Daniel Veillard05c13a22001-09-09 08:38:09 +00001453 printf("\t--nowrap : do not put HTML doc wrapper\n");
Daniel Veillard4432df22003-09-28 18:58:27 +00001454#ifdef LIBXML_VALID_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001455 printf("\t--valid : validate the document in addition to std well-formed check\n");
1456 printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
1457 printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
Daniel Veillard66f68e72003-08-18 16:39:51 +00001458 printf("\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
Daniel Veillard4432df22003-09-28 18:58:27 +00001459#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001460 printf("\t--timing : print some timings\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001461 printf("\t--output file or -o file: save to a given file\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001462 printf("\t--repeat : repeat 100 times, for timing or profiling\n");
1463 printf("\t--insert : ad-hoc test for valid insertions\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001464#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001465#ifdef HAVE_ZLIB_H
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001466 printf("\t--compress : turn on gzip compression of output\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001467#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001468#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001469#ifdef LIBXML_HTML_ENABLED
1470 printf("\t--html : use the HTML parser\n");
Daniel Veillard42fd4122003-11-04 08:47:48 +00001471 printf("\t--xmlout : force to use the XML serializer when using --html\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001472#endif
Daniel Veillard73b013f2003-09-30 12:36:01 +00001473#ifdef LIBXML_PUSH_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001474 printf("\t--push : use the push mode of the parser\n");
Daniel Veillard73b013f2003-09-30 12:36:01 +00001475#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001476#ifdef HAVE_SYS_MMAN_H
1477 printf("\t--memory : parse from memory\n");
1478#endif
1479 printf("\t--nowarning : do not emit warnings from parser/validator\n");
1480 printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
Daniel Veillarddca8cc72003-09-26 13:53:14 +00001481 printf("\t--nocdata : replace cdata section with text nodes\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001482#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard90493a92001-08-14 14:12:47 +00001483 printf("\t--format : reformat/reindent the input\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001484 printf("\t--encode encoding : output in the given encoding\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001485 printf("\t--dropdtd : remove the DOCTYPE of the input docs\n");
1486#endif /* LIBXML_OUTPUT_ENABLED */
1487 printf("\t--nsclean : remove redundant namespace declarations\n");
1488 printf("\t--testIO : test user I/O support\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001489#ifdef LIBXML_CATALOG_ENABLED
Daniel Veillardbd9b0e82001-11-26 10:32:08 +00001490 printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");
1491 printf("\t otherwise XML Catalogs starting from \n");
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001492 printf("\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG);
Daniel Veillard05c13a22001-09-09 08:38:09 +00001493 printf("\t--nocatalogs: deactivate all catalogs\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001494#endif
1495 printf("\t--auto : generate a small doc on the fly\n");
1496#ifdef LIBXML_XINCLUDE_ENABLED
1497 printf("\t--xinclude : do XInclude processing\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001498#endif
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001499 printf("\t--loaddtd : fetch external DTD\n");
Daniel Veillard48da9102001-08-07 01:10:10 +00001500 printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
Daniel Veillard81273902003-09-30 00:43:48 +00001501#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00001502 printf("\t--stream : use the streaming interface to process very large files\n");
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001503 printf("\t--walker : create a reader and walk though the resulting doc\n");
Daniel Veillard81273902003-09-30 00:43:48 +00001504#endif /* LIBXML_READER_ENABLED */
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001505#ifdef LIBXML_PATTERN_ENABLED
1506 printf("\t--pattern pattern_value : test the pattern support\n");
1507#endif
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001508 printf("\t--chkregister : verify the node registration code\n");
Daniel Veillardef4d3bc2003-02-07 12:38:22 +00001509#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard71531f32003-02-05 13:19:53 +00001510 printf("\t--relaxng schema : do RelaxNG validation against the schema\n");
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001511 printf("\t--schema schema : do validation against the WXS schema\n");
Daniel Veillard71531f32003-02-05 13:19:53 +00001512#endif
Daniel Veillarda42f25f2002-01-25 14:15:40 +00001513 printf("\nLibxml project home page: http://xmlsoft.org/\n");
1514 printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001515}
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001516
1517static void registerNode(xmlNodePtr node)
1518{
1519 node->_private = malloc(sizeof(long));
1520 *(long*)node->_private = (long) 0x81726354;
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00001521 nbregister++;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001522}
1523
1524static void deregisterNode(xmlNodePtr node)
1525{
1526 assert(node->_private != NULL);
1527 assert(*(long*)node->_private == (long) 0x81726354);
1528 free(node->_private);
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00001529 nbregister--;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001530}
1531
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001532int
1533main(int argc, char **argv) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00001534 int i, acount;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001535 int files = 0;
Daniel Veillard845cce42002-01-09 11:51:37 +00001536 int version = 0;
Aleksey Sanin693c9bc2003-03-09 22:36:52 +00001537 const char* indent;
1538
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001539 if (argc <= 1) {
1540 usage(argv[0]);
1541 return(1);
1542 }
Daniel Veillardbe803962000-06-28 23:40:59 +00001543 LIBXML_TEST_VERSION
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001544 for (i = 1; i < argc ; i++) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001545 if (!strcmp(argv[i], "-"))
1546 break;
1547
1548 if (argv[i][0] != '-')
1549 continue;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001550 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
1551 debug++;
Daniel Veillard56ada1d2003-01-07 11:17:25 +00001552 else
1553#ifdef LIBXML_DEBUG_ENABLED
1554 if ((!strcmp(argv[i], "-shell")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001555 (!strcmp(argv[i], "--shell"))) {
1556 shell++;
1557 noout = 1;
1558 } else
1559#endif
Daniel Veillard652327a2003-09-29 18:02:38 +00001560#ifdef LIBXML_TREE_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001561 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
1562 copy++;
Daniel Veillard652327a2003-09-29 18:02:38 +00001563 else
1564#endif /* LIBXML_TREE_ENABLED */
1565 if ((!strcmp(argv[i], "-recover")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001566 (!strcmp(argv[i], "--recover"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001567 recovery++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001568 options |= XML_PARSE_RECOVER;
1569 } else if ((!strcmp(argv[i], "-noent")) ||
1570 (!strcmp(argv[i], "--noent"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001571 noent++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001572 options |= XML_PARSE_NOENT;
Daniel Veillarddca8cc72003-09-26 13:53:14 +00001573 } else if ((!strcmp(argv[i], "-nsclean")) ||
1574 (!strcmp(argv[i], "--nsclean"))) {
1575 options |= XML_PARSE_NSCLEAN;
1576 } else if ((!strcmp(argv[i], "-nocdata")) ||
1577 (!strcmp(argv[i], "--nocdata"))) {
1578 options |= XML_PARSE_NOCDATA;
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001579 } else if ((!strcmp(argv[i], "-nodict")) ||
1580 (!strcmp(argv[i], "--nodict"))) {
1581 options |= XML_PARSE_NODICT;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001582 } else if ((!strcmp(argv[i], "-version")) ||
Daniel Veillard845cce42002-01-09 11:51:37 +00001583 (!strcmp(argv[i], "--version"))) {
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001584 showVersion(argv[0]);
Daniel Veillard845cce42002-01-09 11:51:37 +00001585 version = 1;
1586 } else if ((!strcmp(argv[i], "-noout")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001587 (!strcmp(argv[i], "--noout")))
1588 noout++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001589#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001590 else if ((!strcmp(argv[i], "-o")) ||
1591 (!strcmp(argv[i], "-output")) ||
1592 (!strcmp(argv[i], "--output"))) {
1593 i++;
Daniel Veillard6e4f1c02002-04-09 09:55:20 +00001594 output = argv[i];
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001595 }
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001596#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001597 else if ((!strcmp(argv[i], "-htmlout")) ||
1598 (!strcmp(argv[i], "--htmlout")))
1599 htmlout++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001600 else if ((!strcmp(argv[i], "-nowrap")) ||
1601 (!strcmp(argv[i], "--nowrap")))
1602 nowrap++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001603#ifdef LIBXML_HTML_ENABLED
1604 else if ((!strcmp(argv[i], "-html")) ||
1605 (!strcmp(argv[i], "--html"))) {
1606 html++;
1607 }
Daniel Veillard42fd4122003-11-04 08:47:48 +00001608 else if ((!strcmp(argv[i], "-xmlout")) ||
1609 (!strcmp(argv[i], "--xmlout"))) {
1610 xmlout++;
1611 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001612#endif /* LIBXML_HTML_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001613 else if ((!strcmp(argv[i], "-loaddtd")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001614 (!strcmp(argv[i], "--loaddtd"))) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001615 loaddtd++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001616 options |= XML_PARSE_DTDLOAD;
1617 } else if ((!strcmp(argv[i], "-dtdattr")) ||
Daniel Veillard48da9102001-08-07 01:10:10 +00001618 (!strcmp(argv[i], "--dtdattr"))) {
1619 loaddtd++;
1620 dtdattrs++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001621 options |= XML_PARSE_DTDATTR;
Daniel Veillard4432df22003-09-28 18:58:27 +00001622 }
1623#ifdef LIBXML_VALID_ENABLED
1624 else if ((!strcmp(argv[i], "-valid")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001625 (!strcmp(argv[i], "--valid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001626 valid++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001627 options |= XML_PARSE_DTDVALID;
1628 } else if ((!strcmp(argv[i], "-postvalid")) ||
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001629 (!strcmp(argv[i], "--postvalid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001630 postvalid++;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001631 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00001632 options |= XML_PARSE_DTDLOAD;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001633 } else if ((!strcmp(argv[i], "-dtdvalid")) ||
Daniel Veillardcd429612000-10-11 15:57:05 +00001634 (!strcmp(argv[i], "--dtdvalid"))) {
1635 i++;
1636 dtdvalid = argv[i];
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001637 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00001638 options |= XML_PARSE_DTDLOAD;
Daniel Veillard66f68e72003-08-18 16:39:51 +00001639 } else if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
1640 (!strcmp(argv[i], "--dtdvalidfpi"))) {
1641 i++;
1642 dtdvalidfpi = argv[i];
1643 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00001644 options |= XML_PARSE_DTDLOAD;
Daniel Veillardcd429612000-10-11 15:57:05 +00001645 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001646#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard29e43992001-12-13 22:21:58 +00001647 else if ((!strcmp(argv[i], "-dropdtd")) ||
1648 (!strcmp(argv[i], "--dropdtd")))
1649 dropdtd++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001650 else if ((!strcmp(argv[i], "-insert")) ||
1651 (!strcmp(argv[i], "--insert")))
1652 insert++;
Daniel Veillard48b2f892001-02-25 16:11:03 +00001653 else if ((!strcmp(argv[i], "-timing")) ||
1654 (!strcmp(argv[i], "--timing")))
1655 timing++;
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001656 else if ((!strcmp(argv[i], "-auto")) ||
1657 (!strcmp(argv[i], "--auto")))
1658 generate++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001659 else if ((!strcmp(argv[i], "-repeat")) ||
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00001660 (!strcmp(argv[i], "--repeat"))) {
1661 if (repeat)
1662 repeat *= 10;
1663 else
1664 repeat = 100;
Daniel Veillard73b013f2003-09-30 12:36:01 +00001665 }
1666#ifdef LIBXML_PUSH_ENABLED
1667 else if ((!strcmp(argv[i], "-push")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001668 (!strcmp(argv[i], "--push")))
1669 push++;
Daniel Veillard73b013f2003-09-30 12:36:01 +00001670#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillard46e370e2000-07-21 20:32:03 +00001671#ifdef HAVE_SYS_MMAN_H
1672 else if ((!strcmp(argv[i], "-memory")) ||
1673 (!strcmp(argv[i], "--memory")))
1674 memory++;
1675#endif
Daniel Veillard5e873c42000-04-12 13:27:38 +00001676 else if ((!strcmp(argv[i], "-testIO")) ||
1677 (!strcmp(argv[i], "--testIO")))
1678 testIO++;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001679#ifdef LIBXML_XINCLUDE_ENABLED
1680 else if ((!strcmp(argv[i], "-xinclude")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001681 (!strcmp(argv[i], "--xinclude"))) {
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001682 xinclude++;
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001683 options |= XML_PARSE_XINCLUDE;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001684 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001685#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001686#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001687#ifdef HAVE_ZLIB_H
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001688 else if ((!strcmp(argv[i], "-compress")) ||
1689 (!strcmp(argv[i], "--compress"))) {
1690 compress++;
1691 xmlSetCompressMode(9);
1692 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001693#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001694#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001695 else if ((!strcmp(argv[i], "-nowarning")) ||
1696 (!strcmp(argv[i], "--nowarning"))) {
1697 xmlGetWarningsDefaultValue = 0;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001698 xmlPedanticParserDefault(0);
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001699 options |= XML_PARSE_NOWARNING;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001700 }
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001701 else if ((!strcmp(argv[i], "-pedantic")) ||
1702 (!strcmp(argv[i], "--pedantic"))) {
1703 xmlGetWarningsDefaultValue = 1;
1704 xmlPedanticParserDefault(1);
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001705 options |= XML_PARSE_PEDANTIC;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001706 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00001707#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001708 else if ((!strcmp(argv[i], "-debugent")) ||
1709 (!strcmp(argv[i], "--debugent"))) {
1710 debugent++;
1711 xmlParserDebugEntities = 1;
1712 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00001713#endif
Daniel Veillard81418e32001-05-22 15:08:55 +00001714#ifdef LIBXML_CATALOG_ENABLED
1715 else if ((!strcmp(argv[i], "-catalogs")) ||
1716 (!strcmp(argv[i], "--catalogs"))) {
Daniel Veillarde2940dd2001-08-22 00:06:49 +00001717 catalogs++;
1718 } else if ((!strcmp(argv[i], "-nocatalogs")) ||
1719 (!strcmp(argv[i], "--nocatalogs"))) {
1720 nocatalogs++;
Daniel Veillard81418e32001-05-22 15:08:55 +00001721 }
1722#endif
Daniel Veillardbe803962000-06-28 23:40:59 +00001723 else if ((!strcmp(argv[i], "-encode")) ||
1724 (!strcmp(argv[i], "--encode"))) {
1725 i++;
1726 encoding = argv[i];
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001727 /*
1728 * OK it's for testing purposes
1729 */
1730 xmlAddEncodingAlias("UTF-8", "DVEnc");
Daniel Veillardbe803962000-06-28 23:40:59 +00001731 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001732 else if ((!strcmp(argv[i], "-noblanks")) ||
1733 (!strcmp(argv[i], "--noblanks"))) {
1734 noblanks++;
1735 xmlKeepBlanksDefault(0);
Daniel Veillard90493a92001-08-14 14:12:47 +00001736 }
1737 else if ((!strcmp(argv[i], "-format")) ||
1738 (!strcmp(argv[i], "--format"))) {
1739 noblanks++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001740#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard90493a92001-08-14 14:12:47 +00001741 format++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001742#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard90493a92001-08-14 14:12:47 +00001743 xmlKeepBlanksDefault(0);
Daniel Veillard7704fb12003-01-03 16:19:51 +00001744 }
Daniel Veillard81273902003-09-30 00:43:48 +00001745#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00001746 else if ((!strcmp(argv[i], "-stream")) ||
1747 (!strcmp(argv[i], "--stream"))) {
1748 stream++;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001749 }
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001750 else if ((!strcmp(argv[i], "-walker")) ||
1751 (!strcmp(argv[i], "--walker"))) {
1752 walker++;
1753 noout++;
1754 }
Daniel Veillard81273902003-09-30 00:43:48 +00001755#endif /* LIBXML_READER_ENABLED */
1756#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +00001757 else if ((!strcmp(argv[i], "-sax1")) ||
1758 (!strcmp(argv[i], "--sax1"))) {
1759 sax1++;
1760 }
Daniel Veillard81273902003-09-30 00:43:48 +00001761#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001762 else if ((!strcmp(argv[i], "-chkregister")) ||
1763 (!strcmp(argv[i], "--chkregister"))) {
1764 chkregister++;
Daniel Veillard71531f32003-02-05 13:19:53 +00001765#ifdef LIBXML_SCHEMAS_ENABLED
1766 } else if ((!strcmp(argv[i], "-relaxng")) ||
1767 (!strcmp(argv[i], "--relaxng"))) {
1768 i++;
1769 relaxng = argv[i];
1770 noent++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001771 options |= XML_PARSE_NOENT;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001772 } else if ((!strcmp(argv[i], "-schema")) ||
1773 (!strcmp(argv[i], "--schema"))) {
1774 i++;
1775 schema = argv[i];
1776 noent++;
Daniel Veillard71531f32003-02-05 13:19:53 +00001777#endif
Daniel Veillarde8b09e42003-05-13 22:14:13 +00001778 } else if ((!strcmp(argv[i], "-nonet")) ||
1779 (!strcmp(argv[i], "--nonet"))) {
Daniel Veillard61b93382003-11-03 14:28:31 +00001780 options |= XML_PARSE_NONET;
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001781#ifdef LIBXML_PATTERN_ENABLED
1782 } else if ((!strcmp(argv[i], "-pattern")) ||
1783 (!strcmp(argv[i], "--pattern"))) {
1784 i++;
1785 pattern = argv[i];
1786#endif
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001787 } else {
1788 fprintf(stderr, "Unknown option %s\n", argv[i]);
1789 usage(argv[0]);
1790 return(1);
1791 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001792 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00001793
1794#ifdef LIBXML_CATALOG_ENABLED
1795 if (nocatalogs == 0) {
1796 if (catalogs) {
1797 const char *catal;
1798
1799 catal = getenv("SGML_CATALOG_FILES");
Daniel Veillard6c5f9d12001-08-25 13:33:14 +00001800 if (catal != NULL) {
1801 xmlLoadCatalogs(catal);
1802 } else {
1803 fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n");
1804 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00001805 }
1806 }
1807#endif
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001808
Daniel Veillard81273902003-09-30 00:43:48 +00001809#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +00001810 if (sax1)
1811 xmlSAXDefaultVersion(1);
1812 else
1813 xmlSAXDefaultVersion(2);
Daniel Veillard81273902003-09-30 00:43:48 +00001814#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillard07cb8222003-09-10 10:51:05 +00001815
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001816 if (chkregister) {
1817 xmlRegisterNodeDefault(registerNode);
1818 xmlDeregisterNodeDefault(deregisterNode);
1819 }
Aleksey Sanin693c9bc2003-03-09 22:36:52 +00001820
1821 indent = getenv("XMLLINT_INDENT");
1822 if(indent != NULL) {
1823 xmlTreeIndentString = indent;
1824 }
1825
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001826
Daniel Veillardd9bad132001-07-23 19:39:43 +00001827 xmlLineNumbersDefault(1);
Daniel Veillard48da9102001-08-07 01:10:10 +00001828 if (loaddtd != 0)
1829 xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
1830 if (dtdattrs)
1831 xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001832 if (noent != 0) xmlSubstituteEntitiesDefault(1);
Daniel Veillard4432df22003-09-28 18:58:27 +00001833#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001834 if (valid != 0) xmlDoValidityCheckingDefaultValue = 1;
Daniel Veillard4432df22003-09-28 18:58:27 +00001835#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001836 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001837 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001838 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001839 xmlGenericError(xmlGenericErrorContext,
1840 "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
1841 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001842 "<html><head><title>%s output</title></head>\n",
1843 argv[0]);
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001844 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001845 "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
1846 argv[0]);
1847 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001848
1849#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard81273902003-09-30 00:43:48 +00001850 if ((relaxng != NULL)
1851#ifdef LIBXML_READER_ENABLED
1852 && (stream == 0)
1853#endif /* LIBXML_READER_ENABLED */
1854 ) {
Daniel Veillard71531f32003-02-05 13:19:53 +00001855 xmlRelaxNGParserCtxtPtr ctxt;
1856
Daniel Veillardce192eb2003-04-16 15:58:05 +00001857 /* forces loading the DTDs */
1858 xmlLoadExtDtdDefaultValue |= 1;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001859 options |= XML_PARSE_DTDLOAD;
Daniel Veillard42f12e92003-03-07 18:32:59 +00001860 if (timing) {
1861 startTimer();
1862 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001863 ctxt = xmlRelaxNGNewParserCtxt(relaxng);
1864 xmlRelaxNGSetParserErrors(ctxt,
1865 (xmlRelaxNGValidityErrorFunc) fprintf,
1866 (xmlRelaxNGValidityWarningFunc) fprintf,
1867 stderr);
1868 relaxngschemas = xmlRelaxNGParse(ctxt);
Daniel Veillardce192eb2003-04-16 15:58:05 +00001869 if (relaxngschemas == NULL) {
1870 xmlGenericError(xmlGenericErrorContext,
1871 "Relax-NG schema %s failed to compile\n", relaxng);
Daniel Veillard05d987b2003-10-08 11:54:57 +00001872 progresult = 5;
Daniel Veillardce192eb2003-04-16 15:58:05 +00001873 relaxng = NULL;
1874 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001875 xmlRelaxNGFreeParserCtxt(ctxt);
Daniel Veillard42f12e92003-03-07 18:32:59 +00001876 if (timing) {
1877 endTimer("Compiling the schemas");
1878 }
Daniel Veillardebe25d42004-03-25 09:35:49 +00001879 } else if ((schema != NULL)
1880#ifdef LIBXML_READER_ENABLED
1881 && (stream == 0)
1882#endif
1883 ) {
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001884 xmlSchemaParserCtxtPtr ctxt;
1885
1886 if (timing) {
1887 startTimer();
1888 }
1889 ctxt = xmlSchemaNewParserCtxt(schema);
1890 xmlSchemaSetParserErrors(ctxt,
1891 (xmlSchemaValidityErrorFunc) fprintf,
1892 (xmlSchemaValidityWarningFunc) fprintf,
1893 stderr);
1894 wxschemas = xmlSchemaParse(ctxt);
1895 if (wxschemas == NULL) {
1896 xmlGenericError(xmlGenericErrorContext,
1897 "WXS schema %s failed to compile\n", schema);
Daniel Veillard05d987b2003-10-08 11:54:57 +00001898 progresult = 5;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001899 schema = NULL;
1900 }
1901 xmlSchemaFreeParserCtxt(ctxt);
1902 if (timing) {
1903 endTimer("Compiling the schemas");
1904 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001905 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001906#endif /* LIBXML_SCHEMAS_ENABLED */
1907#ifdef LIBXML_PATTERN_ENABLED
1908 if (pattern != NULL) {
Daniel Veillardffa7b7e2003-12-05 16:10:21 +00001909 patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL);
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001910 if (patternc == NULL) {
1911 xmlGenericError(xmlGenericErrorContext,
1912 "Pattern %s failed to compile\n", pattern);
1913 progresult = 7;
1914 pattern = NULL;
1915 }
1916 }
1917#endif /* LIBXML_PATTERN_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001918 for (i = 1; i < argc ; i++) {
Daniel Veillardbe803962000-06-28 23:40:59 +00001919 if ((!strcmp(argv[i], "-encode")) ||
1920 (!strcmp(argv[i], "--encode"))) {
1921 i++;
1922 continue;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001923 } else if ((!strcmp(argv[i], "-o")) ||
1924 (!strcmp(argv[i], "-output")) ||
1925 (!strcmp(argv[i], "--output"))) {
1926 i++;
1927 continue;
Daniel Veillardbe803962000-06-28 23:40:59 +00001928 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001929#ifdef LIBXML_VALID_ENABLED
Daniel Veillardcd429612000-10-11 15:57:05 +00001930 if ((!strcmp(argv[i], "-dtdvalid")) ||
1931 (!strcmp(argv[i], "--dtdvalid"))) {
1932 i++;
1933 continue;
1934 }
Daniel Veillard66f68e72003-08-18 16:39:51 +00001935 if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
1936 (!strcmp(argv[i], "--dtdvalidfpi"))) {
1937 i++;
1938 continue;
1939 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001940#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard71531f32003-02-05 13:19:53 +00001941 if ((!strcmp(argv[i], "-relaxng")) ||
1942 (!strcmp(argv[i], "--relaxng"))) {
1943 i++;
1944 continue;
1945 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001946 if ((!strcmp(argv[i], "-schema")) ||
1947 (!strcmp(argv[i], "--schema"))) {
1948 i++;
1949 continue;
1950 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001951#ifdef LIBXML_PATTERN_ENABLED
1952 if ((!strcmp(argv[i], "-pattern")) ||
1953 (!strcmp(argv[i], "--pattern"))) {
1954 i++;
1955 continue;
1956 }
1957#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +00001958 if ((timing) && (repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +00001959 startTimer();
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001960 /* Remember file names. "-" means stdin. <sven@zen.org> */
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001961 if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001962 if (repeat) {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001963 xmlParserCtxtPtr ctxt = NULL;
1964
1965 for (acount = 0;acount < repeat;acount++) {
Daniel Veillard81273902003-09-30 00:43:48 +00001966#ifdef LIBXML_READER_ENABLED
Daniel Veillard198c1bf2003-10-20 17:07:41 +00001967 if (stream != 0) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00001968 streamFile(argv[i]);
Daniel Veillard198c1bf2003-10-20 17:07:41 +00001969 } else {
Daniel Veillard81273902003-09-30 00:43:48 +00001970#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001971 if (ctxt == NULL)
1972 ctxt = xmlNewParserCtxt();
1973 parseAndPrintFile(argv[i], ctxt);
Daniel Veillard81273902003-09-30 00:43:48 +00001974#ifdef LIBXML_READER_ENABLED
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001975 }
Daniel Veillard81273902003-09-30 00:43:48 +00001976#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001977 }
1978 if (ctxt != NULL)
1979 xmlFreeParserCtxt(ctxt);
Daniel Veillard7704fb12003-01-03 16:19:51 +00001980 } else {
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00001981 nbregister = 0;
1982
Daniel Veillard81273902003-09-30 00:43:48 +00001983#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00001984 if (stream != 0)
1985 streamFile(argv[i]);
1986 else
Daniel Veillard81273902003-09-30 00:43:48 +00001987#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001988 parseAndPrintFile(argv[i], NULL);
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00001989
1990 if ((chkregister) && (nbregister != 0)) {
1991 fprintf(stderr, "Registration count off: %d\n", nbregister);
1992 progresult = 8;
1993 }
Daniel Veillard7704fb12003-01-03 16:19:51 +00001994 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001995 files ++;
Daniel Veillarda7866932001-12-04 13:14:44 +00001996 if ((timing) && (repeat)) {
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00001997 endTimer("%d iterations", repeat);
Daniel Veillarda7866932001-12-04 13:14:44 +00001998 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001999 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002000 }
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00002001 if (generate)
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002002 parseAndPrintFile(NULL, NULL);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002003 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002004 xmlGenericError(xmlGenericErrorContext, "</body></html>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002005 }
Daniel Veillard845cce42002-01-09 11:51:37 +00002006 if ((files == 0) && (!generate) && (version == 0)) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002007 usage(argv[0]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002008 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002009#ifdef LIBXML_SCHEMAS_ENABLED
2010 if (relaxngschemas != NULL)
2011 xmlRelaxNGFree(relaxngschemas);
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002012 if (wxschemas != NULL)
2013 xmlSchemaFree(wxschemas);
Daniel Veillard71531f32003-02-05 13:19:53 +00002014 xmlRelaxNGCleanupTypes();
2015#endif
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002016#ifdef LIBXML_PATTERN_ENABLED
2017 if (patternc != NULL)
2018 xmlFreePattern(patternc);
2019#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002020 xmlCleanupParser();
2021 xmlMemoryDump();
2022
Daniel Veillardf7cd4812001-02-23 18:44:52 +00002023 return(progresult);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002024}
Daniel Veillard88a172f2000-08-04 18:23:10 +00002025