blob: dbed44f81211580fdaee91a792571da8ef9448a6 [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>
Daniel Veillardc284c642005-03-31 10:24:24 +000034#undef XML_SOCKLEN_T
35#define XML_SOCKLEN_T unsigned int
Daniel Veillard1638a472003-08-14 01:23:25 +000036#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 Veillard6ebf3c42004-08-22 13:11:39 +000095#ifdef LIBXML_C14N_ENABLED
96#include <libxml/c14n.h>
97#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +000098
Daniel Veillard3be27512003-01-26 19:49:04 +000099#ifndef XML_XML_DEFAULT_CATALOG
100#define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog"
101#endif
102
William M. Brack8304d872004-06-08 13:29:32 +0000103typedef enum {
104 XMLLINT_RETURN_OK = 0, /* No error */
105 XMLLINT_ERR_UNCLASS, /* Unclassified */
106 XMLLINT_ERR_DTD, /* Error in DTD */
107 XMLLINT_ERR_VALID, /* Validation error */
108 XMLLINT_ERR_RDFILE, /* CtxtReadFile error */
109 XMLLINT_ERR_SCHEMACOMP, /* Schema compilation */
110 XMLLINT_ERR_OUT, /* Error writing output */
111 XMLLINT_ERR_SCHEMAPAT, /* Error in schema pattern */
112 XMLLINT_ERR_RDREGIS, /* Error in Reader registration */
113 XMLLINT_ERR_MEM /* Out of memory error */
114} xmllintReturnCode;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000115#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000116static int shell = 0;
117static int debugent = 0;
118#endif
Daniel Veillard8326e732003-01-07 00:19:07 +0000119static int debug = 0;
Daniel Veillard87076042004-05-03 22:54:49 +0000120static int maxmem = 0;
Daniel Veillard652327a2003-09-29 18:02:38 +0000121#ifdef LIBXML_TREE_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000122static int copy = 0;
Daniel Veillard652327a2003-09-29 18:02:38 +0000123#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000124static int recovery = 0;
125static int noent = 0;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000126static int noblanks = 0;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000127static int noout = 0;
128static int nowrap = 0;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000129#ifdef LIBXML_OUTPUT_ENABLED
130static int format = 0;
131static const char *output = NULL;
132static int compress = 0;
133#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard4432df22003-09-28 18:58:27 +0000134#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000135static int valid = 0;
136static int postvalid = 0;
Daniel Veillardcd429612000-10-11 15:57:05 +0000137static char * dtdvalid = NULL;
Daniel Veillard66f68e72003-08-18 16:39:51 +0000138static char * dtdvalidfpi = NULL;
Daniel Veillard4432df22003-09-28 18:58:27 +0000139#endif
Daniel Veillard71531f32003-02-05 13:19:53 +0000140#ifdef LIBXML_SCHEMAS_ENABLED
141static char * relaxng = NULL;
142static xmlRelaxNGPtr relaxngschemas = NULL;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +0000143static char * schema = NULL;
144static xmlSchemaPtr wxschemas = NULL;
Daniel Veillard71531f32003-02-05 13:19:53 +0000145#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000146static int repeat = 0;
147static int insert = 0;
Daniel Veillard656ce942004-04-30 23:11:45 +0000148#if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED)
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000149static int html = 0;
Daniel Veillard42fd4122003-11-04 08:47:48 +0000150static int xmlout = 0;
Daniel Veillard4432df22003-09-28 18:58:27 +0000151#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000152static int htmlout = 0;
Daniel Veillard73b013f2003-09-30 12:36:01 +0000153#ifdef LIBXML_PUSH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000154static int push = 0;
Daniel Veillard73b013f2003-09-30 12:36:01 +0000155#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillard46e370e2000-07-21 20:32:03 +0000156#ifdef HAVE_SYS_MMAN_H
157static int memory = 0;
158#endif
Daniel Veillard5e873c42000-04-12 13:27:38 +0000159static int testIO = 0;
Daniel Veillardbe803962000-06-28 23:40:59 +0000160static char *encoding = NULL;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000161#ifdef LIBXML_XINCLUDE_ENABLED
162static int xinclude = 0;
163#endif
Daniel Veillard48da9102001-08-07 01:10:10 +0000164static int dtdattrs = 0;
Daniel Veillard10ea86c2001-06-20 13:55:33 +0000165static int loaddtd = 0;
William M. Brack8304d872004-06-08 13:29:32 +0000166static xmllintReturnCode progresult = XMLLINT_RETURN_OK;
Daniel Veillard48b2f892001-02-25 16:11:03 +0000167static int timing = 0;
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000168static int generate = 0;
Daniel Veillard29e43992001-12-13 22:21:58 +0000169static int dropdtd = 0;
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000170#ifdef LIBXML_CATALOG_ENABLED
171static int catalogs = 0;
172static int nocatalogs = 0;
173#endif
Daniel Veillard25048d82004-08-14 22:37:54 +0000174#ifdef LIBXML_C14N_ENABLED
175static int canonical = 0;
Aleksey Sanin2650df12005-06-06 17:16:50 +0000176static int exc_canonical = 0;
Daniel Veillard25048d82004-08-14 22:37:54 +0000177#endif
Daniel Veillard81273902003-09-30 00:43:48 +0000178#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +0000179static int stream = 0;
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000180static int walker = 0;
Daniel Veillard81273902003-09-30 00:43:48 +0000181#endif /* LIBXML_READER_ENABLED */
Daniel Veillard8a1b1852003-01-05 22:37:17 +0000182static int chkregister = 0;
Daniel Veillarda2d51fc2004-04-30 22:25:59 +0000183static int nbregister = 0;
Daniel Veillard81273902003-09-30 00:43:48 +0000184#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +0000185static int sax1 = 0;
Daniel Veillard81273902003-09-30 00:43:48 +0000186#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000187#ifdef LIBXML_PATTERN_ENABLED
188static const char *pattern = NULL;
189static xmlPatternPtr patternc = NULL;
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000190static xmlStreamCtxtPtr patstream = NULL;
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000191#endif
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000192static int options = 0;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000193
Daniel Veillard87076042004-05-03 22:54:49 +0000194/************************************************************************
Daniel Veillard0bff36d2004-08-31 09:37:03 +0000195 * *
196 * Entity loading control and customization. *
197 * *
198 ************************************************************************/
199#define MAX_PATHS 64
200static xmlChar *paths[MAX_PATHS + 1];
201static int nbpaths = 0;
202static int load_trace = 0;
203
204static
205void parsePath(const xmlChar *path) {
206 const xmlChar *cur;
207
208 if (path == NULL)
209 return;
210 while (*path != 0) {
211 if (nbpaths >= MAX_PATHS) {
212 fprintf(stderr, "MAX_PATHS reached: too many paths\n");
213 return;
214 }
215 cur = path;
216 while ((*cur == ' ') || (*cur == ':'))
217 cur++;
218 path = cur;
219 while ((*cur != 0) && (*cur != ' ') && (*cur != ':'))
220 cur++;
221 if (cur != path) {
222 paths[nbpaths] = xmlStrndup(path, cur - path);
223 if (paths[nbpaths] != NULL)
224 nbpaths++;
225 path = cur;
226 }
227 }
228}
229
230xmlExternalEntityLoader defaultEntityLoader = NULL;
231
232static xmlParserInputPtr
233xmllintExternalEntityLoader(const char *URL, const char *ID,
234 xmlParserCtxtPtr ctxt) {
235 xmlParserInputPtr ret;
236 warningSAXFunc warning = NULL;
237
238 int i;
239 const char *lastsegment = URL;
240 const char *iter = URL;
241
242 if (nbpaths > 0) {
243 while (*iter != 0) {
244 if (*iter == '/')
245 lastsegment = iter + 1;
246 iter++;
247 }
248 }
249
250 if ((ctxt != NULL) && (ctxt->sax != NULL)) {
251 warning = ctxt->sax->warning;
252 ctxt->sax->warning = NULL;
253 }
254
255 if (defaultEntityLoader != NULL) {
256 ret = defaultEntityLoader(URL, ID, ctxt);
257 if (ret != NULL) {
258 if (warning != NULL)
259 ctxt->sax->warning = warning;
260 if (load_trace) {
261 fprintf \
262 (stderr,
263 "Loaded URL=\"%s\" ID=\"%s\"\n",
264 URL ? URL : "(null)",
265 ID ? ID : "(null)");
266 }
267 return(ret);
268 }
269 }
270 for (i = 0;i < nbpaths;i++) {
271 xmlChar *newURL;
272
273 newURL = xmlStrdup((const xmlChar *) paths[i]);
274 newURL = xmlStrcat(newURL, (const xmlChar *) "/");
275 newURL = xmlStrcat(newURL, (const xmlChar *) lastsegment);
276 if (newURL != NULL) {
277 ret = defaultEntityLoader((const char *)newURL, ID, ctxt);
278 if (ret != NULL) {
279 if (warning != NULL)
280 ctxt->sax->warning = warning;
281 if (load_trace) {
282 fprintf \
283 (stderr,
284 "Loaded URL=\"%s\" ID=\"%s\"\n",
285 newURL,
286 ID ? ID : "(null)");
287 }
288 xmlFree(newURL);
289 return(ret);
290 }
291 xmlFree(newURL);
292 }
293 }
294 if (warning != NULL) {
295 ctxt->sax->warning = warning;
296 if (URL != NULL)
297 warning(ctxt, "failed to load external entity \"%s\"\n", URL);
298 else if (ID != NULL)
299 warning(ctxt, "failed to load external entity \"%s\"\n", ID);
300 }
301 return(NULL);
302}
303/************************************************************************
Daniel Veillard87076042004-05-03 22:54:49 +0000304 * *
305 * Memory allocation consumption debugging *
306 * *
307 ************************************************************************/
308
Daniel Veillard3af3b592004-05-05 19:22:30 +0000309static void
310OOM(void)
311{
Daniel Veillard87076042004-05-03 22:54:49 +0000312 fprintf(stderr, "Ran out of memory needs > %d bytes\n", maxmem);
William M. Brack8304d872004-06-08 13:29:32 +0000313 progresult = XMLLINT_ERR_MEM;
Daniel Veillard87076042004-05-03 22:54:49 +0000314}
315
Daniel Veillard3af3b592004-05-05 19:22:30 +0000316static void
317myFreeFunc(void *mem)
318{
Daniel Veillard87076042004-05-03 22:54:49 +0000319 xmlMemFree(mem);
320}
Daniel Veillard3af3b592004-05-05 19:22:30 +0000321static void *
322myMallocFunc(size_t size)
323{
Daniel Veillard87076042004-05-03 22:54:49 +0000324 void *ret;
325
326 ret = xmlMemMalloc(size);
327 if (ret != NULL) {
328 if (xmlMemUsed() > maxmem) {
Daniel Veillard3af3b592004-05-05 19:22:30 +0000329 OOM();
330 xmlMemFree(ret);
331 return (NULL);
332 }
Daniel Veillard87076042004-05-03 22:54:49 +0000333 }
Daniel Veillard3af3b592004-05-05 19:22:30 +0000334 return (ret);
Daniel Veillard87076042004-05-03 22:54:49 +0000335}
Daniel Veillard3af3b592004-05-05 19:22:30 +0000336static void *
337myReallocFunc(void *mem, size_t size)
338{
Daniel Veillard87076042004-05-03 22:54:49 +0000339 void *ret;
340
341 ret = xmlMemRealloc(mem, size);
342 if (ret != NULL) {
343 if (xmlMemUsed() > maxmem) {
Daniel Veillard3af3b592004-05-05 19:22:30 +0000344 OOM();
345 xmlMemFree(ret);
346 return (NULL);
347 }
Daniel Veillard87076042004-05-03 22:54:49 +0000348 }
Daniel Veillard3af3b592004-05-05 19:22:30 +0000349 return (ret);
Daniel Veillard87076042004-05-03 22:54:49 +0000350}
Daniel Veillard3af3b592004-05-05 19:22:30 +0000351static char *
352myStrdupFunc(const char *str)
353{
Daniel Veillard87076042004-05-03 22:54:49 +0000354 char *ret;
355
356 ret = xmlMemoryStrdup(str);
357 if (ret != NULL) {
358 if (xmlMemUsed() > maxmem) {
Daniel Veillard3af3b592004-05-05 19:22:30 +0000359 OOM();
360 xmlFree(ret);
361 return (NULL);
362 }
Daniel Veillard87076042004-05-03 22:54:49 +0000363 }
Daniel Veillard3af3b592004-05-05 19:22:30 +0000364 return (ret);
Daniel Veillard87076042004-05-03 22:54:49 +0000365}
Daniel Veillard87076042004-05-03 22:54:49 +0000366/************************************************************************
367 * *
368 * Internal timing routines to remove the necessity to have *
369 * unix-specific function calls. *
370 * *
371 ************************************************************************/
Daniel Veillard01db67c2001-12-18 07:09:59 +0000372
Daniel Veillard8c1ae602002-03-07 11:21:00 +0000373#ifndef HAVE_GETTIMEOFDAY
374#ifdef HAVE_SYS_TIMEB_H
375#ifdef HAVE_SYS_TIME_H
376#ifdef HAVE_FTIME
377
Daniel Veillard01c13b52002-12-10 15:19:08 +0000378static int
Daniel Veillard8c1ae602002-03-07 11:21:00 +0000379my_gettimeofday(struct timeval *tvp, void *tzp)
380{
381 struct timeb timebuffer;
382
383 ftime(&timebuffer);
384 if (tvp) {
385 tvp->tv_sec = timebuffer.time;
386 tvp->tv_usec = timebuffer.millitm * 1000L;
387 }
388 return (0);
389}
390#define HAVE_GETTIMEOFDAY 1
391#define gettimeofday my_gettimeofday
392
393#endif /* HAVE_FTIME */
394#endif /* HAVE_SYS_TIME_H */
395#endif /* HAVE_SYS_TIMEB_H */
396#endif /* !HAVE_GETTIMEOFDAY */
397
Daniel Veillard01db67c2001-12-18 07:09:59 +0000398#if defined(HAVE_GETTIMEOFDAY)
399static struct timeval begin, end;
400
401/*
402 * startTimer: call where you want to start timing
403 */
404static void
405startTimer(void)
406{
407 gettimeofday(&begin, NULL);
408}
409
410/*
411 * endTimer: call where you want to stop timing and to print out a
412 * message about the timing performed; format is a printf
413 * type argument
414 */
415static void
Daniel Veillard118aed72002-09-24 14:13:13 +0000416endTimer(const char *fmt, ...)
Daniel Veillard01db67c2001-12-18 07:09:59 +0000417{
418 long msec;
419 va_list ap;
420
421 gettimeofday(&end, NULL);
422 msec = end.tv_sec - begin.tv_sec;
423 msec *= 1000;
424 msec += (end.tv_usec - begin.tv_usec) / 1000;
425
426#ifndef HAVE_STDARG_H
427#error "endTimer required stdarg functions"
428#endif
Daniel Veillard118aed72002-09-24 14:13:13 +0000429 va_start(ap, fmt);
430 vfprintf(stderr, fmt, ap);
Daniel Veillard01db67c2001-12-18 07:09:59 +0000431 va_end(ap);
432
433 fprintf(stderr, " took %ld ms\n", msec);
434}
435#elif defined(HAVE_TIME_H)
Daniel Veillard01db67c2001-12-18 07:09:59 +0000436/*
437 * No gettimeofday function, so we have to make do with calling clock.
438 * This is obviously less accurate, but there's little we can do about
439 * that.
440 */
Daniel Veillard90bc3712002-03-07 15:12:58 +0000441#ifndef CLOCKS_PER_SEC
442#define CLOCKS_PER_SEC 100
443#endif
Daniel Veillard01db67c2001-12-18 07:09:59 +0000444
445static clock_t begin, end;
446static void
447startTimer(void)
448{
449 begin = clock();
450}
451static void
452endTimer(const char *fmt, ...)
453{
454 long msec;
455 va_list ap;
456
457 end = clock();
458 msec = ((end - begin) * 1000) / CLOCKS_PER_SEC;
459
460#ifndef HAVE_STDARG_H
461#error "endTimer required stdarg functions"
462#endif
463 va_start(ap, fmt);
464 vfprintf(stderr, fmt, ap);
465 va_end(ap);
466 fprintf(stderr, " took %ld ms\n", msec);
467}
468#else
469
470/*
471 * We don't have a gettimeofday or time.h, so we just don't do timing
472 */
473static void
474startTimer(void)
475{
476 /*
477 * Do nothing
478 */
479}
480static void
481endTimer(char *format, ...)
482{
483 /*
484 * We cannot do anything because we don't have a timing function
485 */
486#ifdef HAVE_STDARG_H
487 va_start(ap, format);
488 vfprintf(stderr, format, ap);
489 va_end(ap);
490 fprintf(stderr, " was not timed\n", msec);
491#else
492 /* We don't have gettimeofday, time or stdarg.h, what crazy world is
493 * this ?!
494 */
495#endif
496}
497#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000498/************************************************************************
499 * *
500 * HTML ouput *
501 * *
502 ************************************************************************/
503char buffer[50000];
504
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000505static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000506xmlHTMLEncodeSend(void) {
507 char *result;
508
509 result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
510 if (result) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000511 xmlGenericError(xmlGenericErrorContext, "%s", result);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000512 xmlFree(result);
513 }
514 buffer[0] = 0;
515}
516
517/**
518 * xmlHTMLPrintFileInfo:
519 * @input: an xmlParserInputPtr input
520 *
521 * Displays the associated file and line informations for the current input
522 */
523
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000524static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000525xmlHTMLPrintFileInfo(xmlParserInputPtr input) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000526 int len;
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000527 xmlGenericError(xmlGenericErrorContext, "<p>");
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000528
529 len = strlen(buffer);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000530 if (input != NULL) {
531 if (input->filename) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000532 snprintf(&buffer[len], sizeof(buffer) - len, "%s:%d: ", input->filename,
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000533 input->line);
534 } else {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000535 snprintf(&buffer[len], sizeof(buffer) - len, "Entity: line %d: ", input->line);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000536 }
537 }
538 xmlHTMLEncodeSend();
539}
540
541/**
542 * xmlHTMLPrintFileContext:
543 * @input: an xmlParserInputPtr input
544 *
545 * Displays current context within the input content for error tracking
546 */
547
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000548static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000549xmlHTMLPrintFileContext(xmlParserInputPtr input) {
550 const xmlChar *cur, *base;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000551 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000552 int n;
553
554 if (input == NULL) return;
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000555 xmlGenericError(xmlGenericErrorContext, "<pre>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000556 cur = input->cur;
557 base = input->base;
558 while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
559 cur--;
560 }
561 n = 0;
562 while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
563 cur--;
564 if ((*cur == '\n') || (*cur == '\r')) cur++;
565 base = cur;
566 n = 0;
567 while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000568 len = strlen(buffer);
569 snprintf(&buffer[len], sizeof(buffer) - len, "%c",
570 (unsigned char) *cur++);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000571 n++;
572 }
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000573 len = strlen(buffer);
574 snprintf(&buffer[len], sizeof(buffer) - len, "\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000575 cur = input->cur;
576 while ((*cur == '\n') || (*cur == '\r'))
577 cur--;
578 n = 0;
579 while ((cur != base) && (n++ < 80)) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000580 len = strlen(buffer);
581 snprintf(&buffer[len], sizeof(buffer) - len, " ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000582 base++;
583 }
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000584 len = strlen(buffer);
585 snprintf(&buffer[len], sizeof(buffer) - len, "^\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000586 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000587 xmlGenericError(xmlGenericErrorContext, "</pre>");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000588}
589
590/**
591 * xmlHTMLError:
592 * @ctx: an XML parser context
593 * @msg: the message to display/transmit
594 * @...: extra parameters for the message display
595 *
596 * Display and format an error messages, gives file, line, position and
597 * extra parameters.
598 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000599static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000600xmlHTMLError(void *ctx, const char *msg, ...)
601{
602 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
603 xmlParserInputPtr input;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000604 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000605 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000606
607 buffer[0] = 0;
608 input = ctxt->input;
609 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000610 input = ctxt->inputTab[ctxt->inputNr - 2];
611 }
612
613 xmlHTMLPrintFileInfo(input);
614
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000615 xmlGenericError(xmlGenericErrorContext, "<b>error</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000616 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000617 len = strlen(buffer);
618 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000619 va_end(args);
620 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000621 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000622
623 xmlHTMLPrintFileContext(input);
624 xmlHTMLEncodeSend();
625}
626
627/**
628 * xmlHTMLWarning:
629 * @ctx: an XML parser context
630 * @msg: the message to display/transmit
631 * @...: extra parameters for the message display
632 *
633 * Display and format a warning messages, gives file, line, position and
634 * extra parameters.
635 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000636static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000637xmlHTMLWarning(void *ctx, const char *msg, ...)
638{
639 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
640 xmlParserInputPtr input;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000641 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000642 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000643
644 buffer[0] = 0;
645 input = ctxt->input;
646 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000647 input = ctxt->inputTab[ctxt->inputNr - 2];
648 }
649
650
651 xmlHTMLPrintFileInfo(input);
652
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000653 xmlGenericError(xmlGenericErrorContext, "<b>warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000654 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000655 len = strlen(buffer);
656 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000657 va_end(args);
658 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000659 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000660
661 xmlHTMLPrintFileContext(input);
662 xmlHTMLEncodeSend();
663}
664
665/**
666 * xmlHTMLValidityError:
667 * @ctx: an XML parser context
668 * @msg: the message to display/transmit
669 * @...: extra parameters for the message display
670 *
671 * Display and format an validity error messages, gives file,
672 * line, position and extra parameters.
673 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000674static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000675xmlHTMLValidityError(void *ctx, const char *msg, ...)
676{
677 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
678 xmlParserInputPtr input;
679 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000680 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000681
682 buffer[0] = 0;
683 input = ctxt->input;
684 if ((input->filename == NULL) && (ctxt->inputNr > 1))
685 input = ctxt->inputTab[ctxt->inputNr - 2];
686
687 xmlHTMLPrintFileInfo(input);
688
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000689 xmlGenericError(xmlGenericErrorContext, "<b>validity error</b>: ");
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000690 len = strlen(buffer);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000691 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000692 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000693 va_end(args);
694 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000695 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000696
697 xmlHTMLPrintFileContext(input);
698 xmlHTMLEncodeSend();
Daniel Veillard9fcb4912005-03-16 12:57:31 +0000699 progresult = XMLLINT_ERR_VALID;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000700}
701
702/**
703 * xmlHTMLValidityWarning:
704 * @ctx: an XML parser context
705 * @msg: the message to display/transmit
706 * @...: extra parameters for the message display
707 *
708 * Display and format a validity warning messages, gives file, line,
709 * position and extra parameters.
710 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000711static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000712xmlHTMLValidityWarning(void *ctx, const char *msg, ...)
713{
714 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
715 xmlParserInputPtr input;
716 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000717 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000718
719 buffer[0] = 0;
720 input = ctxt->input;
721 if ((input->filename == NULL) && (ctxt->inputNr > 1))
722 input = ctxt->inputTab[ctxt->inputNr - 2];
723
724 xmlHTMLPrintFileInfo(input);
725
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000726 xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000727 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000728 len = strlen(buffer);
729 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000730 va_end(args);
731 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000732 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000733
734 xmlHTMLPrintFileContext(input);
735 xmlHTMLEncodeSend();
736}
737
738/************************************************************************
739 * *
740 * Shell Interface *
741 * *
742 ************************************************************************/
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000743#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardd0cf7f62004-11-09 16:17:02 +0000744#ifdef LIBXML_XPATH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000745/**
746 * xmlShellReadline:
747 * @prompt: the prompt value
748 *
749 * Read a string
750 *
751 * Returns a pointer to it or NULL on EOF the caller is expected to
752 * free the returned string.
753 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000754static char *
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000755xmlShellReadline(char *prompt) {
756#ifdef HAVE_LIBREADLINE
757 char *line_read;
758
759 /* Get a line from the user. */
760 line_read = readline (prompt);
761
762 /* If the line has any text in it, save it on the history. */
763 if (line_read && *line_read)
764 add_history (line_read);
765
766 return (line_read);
767#else
768 char line_read[501];
Daniel Veillard29e43992001-12-13 22:21:58 +0000769 char *ret;
770 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000771
772 if (prompt != NULL)
773 fprintf(stdout, "%s", prompt);
774 if (!fgets(line_read, 500, stdin))
775 return(NULL);
776 line_read[500] = 0;
Daniel Veillard29e43992001-12-13 22:21:58 +0000777 len = strlen(line_read);
778 ret = (char *) malloc(len + 1);
779 if (ret != NULL) {
780 memcpy (ret, line_read, len + 1);
781 }
782 return(ret);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000783#endif
784}
Daniel Veillardd0cf7f62004-11-09 16:17:02 +0000785#endif /* LIBXML_XPATH_ENABLED */
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000786#endif /* LIBXML_DEBUG_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000787
788/************************************************************************
789 * *
Daniel Veillard5e873c42000-04-12 13:27:38 +0000790 * I/O Interfaces *
791 * *
792 ************************************************************************/
793
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000794static int myRead(FILE *f, char * buf, int len) {
795 return(fread(buf, 1, len, f));
Daniel Veillard5e873c42000-04-12 13:27:38 +0000796}
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000797static void myClose(FILE *f) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000798 if (f != stdin) {
Daniel Veillard5e873c42000-04-12 13:27:38 +0000799 fclose(f);
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000800 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000801}
802
Daniel Veillard81273902003-09-30 00:43:48 +0000803#ifdef LIBXML_READER_ENABLED
Daniel Veillard5e873c42000-04-12 13:27:38 +0000804/************************************************************************
805 * *
Daniel Veillard7704fb12003-01-03 16:19:51 +0000806 * Stream Test processing *
807 * *
808 ************************************************************************/
Daniel Veillard7704fb12003-01-03 16:19:51 +0000809static void processNode(xmlTextReaderPtr reader) {
Daniel Veillard198c1bf2003-10-20 17:07:41 +0000810 const xmlChar *name, *value;
Daniel Veillard16ef8002005-01-31 00:27:50 +0000811 int type, empty;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000812
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000813 type = xmlTextReaderNodeType(reader);
Daniel Veillard16ef8002005-01-31 00:27:50 +0000814 empty = xmlTextReaderIsEmptyElement(reader);
Daniel Veillard99737f52003-03-22 14:55:50 +0000815
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000816 if (debug) {
817 name = xmlTextReaderConstName(reader);
818 if (name == NULL)
819 name = BAD_CAST "--";
Daniel Veillard7704fb12003-01-03 16:19:51 +0000820
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000821 value = xmlTextReaderConstValue(reader);
822
823
824 printf("%d %d %s %d %d",
825 xmlTextReaderDepth(reader),
826 type,
827 name,
Daniel Veillard16ef8002005-01-31 00:27:50 +0000828 empty,
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000829 xmlTextReaderHasValue(reader));
830 if (value == NULL)
831 printf("\n");
832 else {
833 printf(" %s\n", value);
834 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000835 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000836#ifdef LIBXML_PATTERN_ENABLED
837 if (patternc) {
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000838 xmlChar *path = NULL;
839 int match = -1;
840
841 if (type == XML_READER_TYPE_ELEMENT) {
842 /* do the check only on element start */
843 match = xmlPatternMatch(patternc, xmlTextReaderCurrentNode(reader));
844
845 if (match) {
846 path = xmlGetNodePath(xmlTextReaderCurrentNode(reader));
847 printf("Node %s matches pattern %s\n", path, pattern);
848 }
849 }
850 if (patstream != NULL) {
851 int ret;
852
853 if (type == XML_READER_TYPE_ELEMENT) {
854 ret = xmlStreamPush(patstream,
855 xmlTextReaderConstLocalName(reader),
856 xmlTextReaderConstNamespaceUri(reader));
857 if (ret < 0) {
858 fprintf(stderr, "xmlStreamPush() failure\n");
859 xmlFreeStreamCtxt(patstream);
860 patstream = NULL;
861 } else if (ret != match) {
862 if (path == NULL) {
863 path = xmlGetNodePath(
864 xmlTextReaderCurrentNode(reader));
865 }
866 fprintf(stderr,
867 "xmlPatternMatch and xmlStreamPush disagree\n");
868 fprintf(stderr,
869 " pattern %s node %s\n",
870 pattern, path);
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000871 }
872
873
Daniel Veillard16ef8002005-01-31 00:27:50 +0000874 }
875 if ((type == XML_READER_TYPE_END_ELEMENT) ||
876 ((type == XML_READER_TYPE_ELEMENT) && (empty))) {
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000877 ret = xmlStreamPop(patstream);
878 if (ret < 0) {
879 fprintf(stderr, "xmlStreamPop() failure\n");
880 xmlFreeStreamCtxt(patstream);
881 patstream = NULL;
882 }
883 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000884 }
Daniel Veillardf9d16912005-01-30 22:36:30 +0000885 if (path != NULL)
886 xmlFree(path);
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000887 }
888#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000889}
890
891static void streamFile(char *filename) {
892 xmlTextReaderPtr reader;
893 int ret;
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000894#ifdef HAVE_SYS_MMAN_H
895 int fd = -1;
896 struct stat info;
897 const char *base = NULL;
898 xmlParserInputBufferPtr input = NULL;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000899
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000900 if (memory) {
901 if (stat(filename, &info) < 0)
902 return;
903 if ((fd = open(filename, O_RDONLY)) < 0)
904 return;
905 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
906 if (base == (void *) MAP_FAILED)
907 return;
908
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000909 reader = xmlReaderForMemory(base, info.st_size, filename,
910 NULL, options);
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000911 } else
912#endif
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000913 reader = xmlReaderForFile(filename, NULL, options);
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000914#ifdef LIBXML_PATTERN_ENABLED
Daniel Veillardd4301ab2005-02-03 22:24:10 +0000915 if (pattern != NULL) {
916 patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL);
917 if (patternc == NULL) {
918 xmlGenericError(xmlGenericErrorContext,
919 "Pattern %s failed to compile\n", pattern);
920 progresult = XMLLINT_ERR_SCHEMAPAT;
921 pattern = NULL;
922 }
923 }
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000924 if (patternc != NULL) {
925 patstream = xmlPatternGetStreamCtxt(patternc);
926 if (patstream != NULL) {
927 ret = xmlStreamPush(patstream, NULL, NULL);
928 if (ret < 0) {
929 fprintf(stderr, "xmlStreamPush() failure\n");
930 xmlFreeStreamCtxt(patstream);
931 patstream = NULL;
932 }
933 }
934 }
935#endif
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000936
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000937
Daniel Veillard7704fb12003-01-03 16:19:51 +0000938 if (reader != NULL) {
Daniel Veillard4432df22003-09-28 18:58:27 +0000939#ifdef LIBXML_VALID_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +0000940 if (valid)
941 xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);
Daniel Veillardce192eb2003-04-16 15:58:05 +0000942 else
Daniel Veillard4432df22003-09-28 18:58:27 +0000943#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardce192eb2003-04-16 15:58:05 +0000944 xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1);
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000945#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardce192eb2003-04-16 15:58:05 +0000946 if (relaxng != NULL) {
Daniel Veillard81514ba2003-09-16 23:17:26 +0000947 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000948 startTimer();
949 }
950 ret = xmlTextReaderRelaxNGValidate(reader, relaxng);
951 if (ret < 0) {
952 xmlGenericError(xmlGenericErrorContext,
953 "Relax-NG schema %s failed to compile\n", relaxng);
William M. Brack8304d872004-06-08 13:29:32 +0000954 progresult = XMLLINT_ERR_SCHEMACOMP;
Daniel Veillardce192eb2003-04-16 15:58:05 +0000955 relaxng = NULL;
956 }
Daniel Veillard81514ba2003-09-16 23:17:26 +0000957 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000958 endTimer("Compiling the schemas");
959 }
960 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000961#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000962
963 /*
964 * Process all nodes in sequence
965 */
Daniel Veillard81514ba2003-09-16 23:17:26 +0000966 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000967 startTimer();
968 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000969 ret = xmlTextReaderRead(reader);
970 while (ret == 1) {
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000971 if ((debug)
972#ifdef LIBXML_PATTERN_ENABLED
973 || (patternc)
974#endif
975 )
Daniel Veillard7704fb12003-01-03 16:19:51 +0000976 processNode(reader);
977 ret = xmlTextReaderRead(reader);
978 }
Daniel Veillard81514ba2003-09-16 23:17:26 +0000979 if ((timing) && (!repeat)) {
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000980#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardf54cd532004-02-25 11:52:31 +0000981 if (relaxng != NULL)
Daniel Veillard49138f12004-02-19 12:58:36 +0000982 endTimer("Parsing and validating");
983 else
Daniel Veillardf54cd532004-02-25 11:52:31 +0000984#endif
Daniel Veillard4432df22003-09-28 18:58:27 +0000985#ifdef LIBXML_VALID_ENABLED
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000986 if (valid)
Daniel Veillardce192eb2003-04-16 15:58:05 +0000987 endTimer("Parsing and validating");
988 else
Daniel Veillard4432df22003-09-28 18:58:27 +0000989#endif
Daniel Veillardf54cd532004-02-25 11:52:31 +0000990 endTimer("Parsing");
Daniel Veillardce192eb2003-04-16 15:58:05 +0000991 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000992
Daniel Veillard4432df22003-09-28 18:58:27 +0000993#ifdef LIBXML_VALID_ENABLED
Daniel Veillardf6bad792003-04-11 19:38:54 +0000994 if (valid) {
995 if (xmlTextReaderIsValid(reader) != 1) {
996 xmlGenericError(xmlGenericErrorContext,
997 "Document %s does not validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +0000998 progresult = XMLLINT_ERR_VALID;
Daniel Veillardf6bad792003-04-11 19:38:54 +0000999 }
1000 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001001#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard37fc84d2003-05-09 19:38:15 +00001002#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardf4e55762003-04-15 23:32:22 +00001003 if (relaxng != NULL) {
1004 if (xmlTextReaderIsValid(reader) != 1) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001005 fprintf(stderr, "%s fails to validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001006 progresult = XMLLINT_ERR_VALID;
Daniel Veillardf4e55762003-04-15 23:32:22 +00001007 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001008 fprintf(stderr, "%s validates\n", filename);
Daniel Veillardf4e55762003-04-15 23:32:22 +00001009 }
1010 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +00001011#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +00001012 /*
1013 * Done, cleanup and status
1014 */
1015 xmlFreeTextReader(reader);
1016 if (ret != 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001017 fprintf(stderr, "%s : failed to parse\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001018 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7704fb12003-01-03 16:19:51 +00001019 }
1020 } else {
1021 fprintf(stderr, "Unable to open %s\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001022 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7704fb12003-01-03 16:19:51 +00001023 }
Daniel Veillard2fc6df92005-01-30 18:42:55 +00001024#ifdef LIBXML_PATTERN_ENABLED
1025 if (patstream != NULL) {
1026 xmlFreeStreamCtxt(patstream);
1027 patstream = NULL;
1028 }
1029#endif
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00001030#ifdef HAVE_SYS_MMAN_H
1031 if (memory) {
1032 xmlFreeParserInputBuffer(input);
1033 munmap((char *) base, info.st_size);
1034 close(fd);
1035 }
1036#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +00001037}
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001038
1039static void walkDoc(xmlDocPtr doc) {
1040 xmlTextReaderPtr reader;
1041 int ret;
1042
Daniel Veillardd4301ab2005-02-03 22:24:10 +00001043#ifdef LIBXML_PATTERN_ENABLED
1044 xmlNodePtr root;
1045 const xmlChar *namespaces[22];
1046 int i;
1047 xmlNsPtr ns;
1048
1049 root = xmlDocGetRootElement(doc);
1050 for (ns = root->nsDef, i = 0;ns != NULL && i < 20;ns=ns->next) {
1051 namespaces[i++] = ns->href;
1052 namespaces[i++] = ns->prefix;
1053 }
1054 namespaces[i++] = NULL;
1055 namespaces[i++] = NULL;
1056
1057 if (pattern != NULL) {
1058 patternc = xmlPatterncompile((const xmlChar *) pattern, doc->dict,
1059 0, &namespaces[0]);
1060 if (patternc == NULL) {
1061 xmlGenericError(xmlGenericErrorContext,
1062 "Pattern %s failed to compile\n", pattern);
1063 progresult = XMLLINT_ERR_SCHEMAPAT;
1064 pattern = NULL;
1065 }
1066 }
Daniel Veillard2b2e02d2005-02-05 23:20:22 +00001067 if (patternc != NULL) {
1068 patstream = xmlPatternGetStreamCtxt(patternc);
1069 if (patstream != NULL) {
1070 ret = xmlStreamPush(patstream, NULL, NULL);
1071 if (ret < 0) {
1072 fprintf(stderr, "xmlStreamPush() failure\n");
1073 xmlFreeStreamCtxt(patstream);
1074 patstream = NULL;
1075 }
1076 }
1077 }
Daniel Veillardd4301ab2005-02-03 22:24:10 +00001078#endif /* LIBXML_PATTERN_ENABLED */
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001079 reader = xmlReaderWalker(doc);
1080 if (reader != NULL) {
1081 if ((timing) && (!repeat)) {
1082 startTimer();
1083 }
1084 ret = xmlTextReaderRead(reader);
1085 while (ret == 1) {
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001086 if ((debug)
1087#ifdef LIBXML_PATTERN_ENABLED
1088 || (patternc)
1089#endif
1090 )
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001091 processNode(reader);
1092 ret = xmlTextReaderRead(reader);
1093 }
1094 if ((timing) && (!repeat)) {
1095 endTimer("walking through the doc");
1096 }
1097 xmlFreeTextReader(reader);
1098 if (ret != 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001099 fprintf(stderr, "failed to walk through the doc\n");
William M. Brack8304d872004-06-08 13:29:32 +00001100 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001101 }
1102 } else {
1103 fprintf(stderr, "Failed to crate a reader from the document\n");
William M. Brack8304d872004-06-08 13:29:32 +00001104 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001105 }
Daniel Veillard2b2e02d2005-02-05 23:20:22 +00001106#ifdef LIBXML_PATTERN_ENABLED
1107 if (patstream != NULL) {
1108 xmlFreeStreamCtxt(patstream);
1109 patstream = NULL;
1110 }
1111#endif
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001112}
Daniel Veillard81273902003-09-30 00:43:48 +00001113#endif /* LIBXML_READER_ENABLED */
Daniel Veillard7704fb12003-01-03 16:19:51 +00001114
1115/************************************************************************
1116 * *
1117 * Tree Test processing *
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001118 * *
1119 ************************************************************************/
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001120static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
Daniel Veillard652327a2003-09-29 18:02:38 +00001121 xmlDocPtr doc = NULL;
1122#ifdef LIBXML_TREE_ENABLED
1123 xmlDocPtr tmp;
1124#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001125
Daniel Veillard48b2f892001-02-25 16:11:03 +00001126 if ((timing) && (!repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +00001127 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001128
1129
Daniel Veillard652327a2003-09-29 18:02:38 +00001130#ifdef LIBXML_TREE_ENABLED
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001131 if (filename == NULL) {
1132 if (generate) {
1133 xmlNodePtr n;
1134
1135 doc = xmlNewDoc(BAD_CAST "1.0");
Daniel Veillard95ddcd32004-10-26 21:53:55 +00001136 n = xmlNewDocNode(doc, NULL, BAD_CAST "info", NULL);
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001137 xmlNodeSetContent(n, BAD_CAST "abc");
1138 xmlDocSetRootElement(doc, n);
1139 }
1140 }
Daniel Veillard652327a2003-09-29 18:02:38 +00001141#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001142#ifdef LIBXML_HTML_ENABLED
Daniel Veillard73b013f2003-09-30 12:36:01 +00001143#ifdef LIBXML_PUSH_ENABLED
William M. Brack78637da2003-07-31 14:47:38 +00001144 else if ((html) && (push)) {
1145 FILE *f;
1146
William M. Brack3403add2004-06-27 02:07:51 +00001147#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
1148 f = fopen(filename, "rb");
1149#else
1150 f = fopen(filename, "r");
1151#endif
William M. Brack78637da2003-07-31 14:47:38 +00001152 if (f != NULL) {
1153 int res, size = 3;
1154 char chars[4096];
1155 htmlParserCtxtPtr ctxt;
1156
1157 /* if (repeat) */
1158 size = 4096;
1159 res = fread(chars, 1, 4, f);
1160 if (res > 0) {
1161 ctxt = htmlCreatePushParserCtxt(NULL, NULL,
William M. Brack1d75c8a2003-10-27 13:48:16 +00001162 chars, res, filename, XML_CHAR_ENCODING_NONE);
William M. Brack78637da2003-07-31 14:47:38 +00001163 while ((res = fread(chars, 1, size, f)) > 0) {
1164 htmlParseChunk(ctxt, chars, res, 0);
1165 }
1166 htmlParseChunk(ctxt, chars, 0, 1);
1167 doc = ctxt->myDoc;
1168 htmlFreeParserCtxt(ctxt);
1169 }
1170 fclose(f);
1171 }
1172 }
Daniel Veillard73b013f2003-09-30 12:36:01 +00001173#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001174 else if (html) {
Daniel Veillard9475a352003-09-26 12:47:50 +00001175 doc = htmlReadFile(filename, NULL, options);
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001176 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001177#endif /* LIBXML_HTML_ENABLED */
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001178 else {
Daniel Veillard73b013f2003-09-30 12:36:01 +00001179#ifdef LIBXML_PUSH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001180 /*
1181 * build an XML tree from a string;
1182 */
1183 if (push) {
1184 FILE *f;
1185
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001186 /* '-' Usually means stdin -<sven@zen.org> */
1187 if ((filename[0] == '-') && (filename[1] == 0)) {
1188 f = stdin;
1189 } else {
William M. Brack3403add2004-06-27 02:07:51 +00001190#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
1191 f = fopen(filename, "rb");
1192#else
1193 f = fopen(filename, "r");
1194#endif
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001195 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001196 if (f != NULL) {
Daniel Veillarde715dd22000-08-29 18:29:38 +00001197 int ret;
Daniel Veillarda880b122003-04-21 21:36:41 +00001198 int res, size = 1024;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001199 char chars[1024];
1200 xmlParserCtxtPtr ctxt;
1201
Daniel Veillarda880b122003-04-21 21:36:41 +00001202 /* if (repeat) size = 1024; */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001203 res = fread(chars, 1, 4, f);
1204 if (res > 0) {
1205 ctxt = xmlCreatePushParserCtxt(NULL, NULL,
1206 chars, res, filename);
Daniel Veillard500a1de2004-03-22 15:22:58 +00001207 xmlCtxtUseOptions(ctxt, options);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001208 while ((res = fread(chars, 1, size, f)) > 0) {
1209 xmlParseChunk(ctxt, chars, res, 0);
1210 }
1211 xmlParseChunk(ctxt, chars, 0, 1);
1212 doc = ctxt->myDoc;
Daniel Veillarde715dd22000-08-29 18:29:38 +00001213 ret = ctxt->wellFormed;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001214 xmlFreeParserCtxt(ctxt);
Daniel Veillarde715dd22000-08-29 18:29:38 +00001215 if (!ret) {
1216 xmlFreeDoc(doc);
1217 doc = NULL;
1218 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001219 }
1220 }
Daniel Veillard73b013f2003-09-30 12:36:01 +00001221 } else
1222#endif /* LIBXML_PUSH_ENABLED */
1223 if (testIO) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001224 if ((filename[0] == '-') && (filename[1] == 0)) {
Daniel Veillard60942de2003-09-25 21:05:58 +00001225 doc = xmlReadFd(0, NULL, NULL, options);
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001226 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001227 FILE *f;
Daniel Veillard5e873c42000-04-12 13:27:38 +00001228
William M. Brack3403add2004-06-27 02:07:51 +00001229#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
1230 f = fopen(filename, "rb");
1231#else
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001232 f = fopen(filename, "r");
William M. Brack3403add2004-06-27 02:07:51 +00001233#endif
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001234 if (f != NULL) {
1235 if (rectxt == NULL)
1236 doc = xmlReadIO((xmlInputReadCallback) myRead,
1237 (xmlInputCloseCallback) myClose, f,
Daniel Veillard60942de2003-09-25 21:05:58 +00001238 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001239 else
1240 doc = xmlCtxtReadIO(rectxt,
1241 (xmlInputReadCallback) myRead,
1242 (xmlInputCloseCallback) myClose, f,
Daniel Veillard60942de2003-09-25 21:05:58 +00001243 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001244 } else
Daniel Veillard5e873c42000-04-12 13:27:38 +00001245 doc = NULL;
Daniel Veillard5e873c42000-04-12 13:27:38 +00001246 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001247 } else if (htmlout) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001248 xmlParserCtxtPtr ctxt;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001249
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001250 if (rectxt == NULL)
1251 ctxt = xmlNewParserCtxt();
1252 else
1253 ctxt = rectxt;
Daniel Veillard88a172f2000-08-04 18:23:10 +00001254 if (ctxt == NULL) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001255 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +00001256 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001257 ctxt->sax->error = xmlHTMLError;
1258 ctxt->sax->warning = xmlHTMLWarning;
1259 ctxt->vctxt.error = xmlHTMLValidityError;
1260 ctxt->vctxt.warning = xmlHTMLValidityWarning;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001261
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001262 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001263
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001264 if (rectxt == NULL)
1265 xmlFreeParserCtxt(ctxt);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001266 }
Daniel Veillard46e370e2000-07-21 20:32:03 +00001267#ifdef HAVE_SYS_MMAN_H
1268 } else if (memory) {
1269 int fd;
1270 struct stat info;
1271 const char *base;
1272 if (stat(filename, &info) < 0)
1273 return;
1274 if ((fd = open(filename, O_RDONLY)) < 0)
1275 return;
1276 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
Daniel Veillard29579362000-08-14 17:57:48 +00001277 if (base == (void *) MAP_FAILED)
Daniel Veillard46e370e2000-07-21 20:32:03 +00001278 return;
1279
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001280 if (rectxt == NULL)
Daniel Veillard60942de2003-09-25 21:05:58 +00001281 doc = xmlReadMemory((char *) base, info.st_size,
1282 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001283 else
Daniel Veillard60942de2003-09-25 21:05:58 +00001284 doc = xmlCtxtReadMemory(rectxt, (char *) base, info.st_size,
1285 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001286
Daniel Veillard46e370e2000-07-21 20:32:03 +00001287 munmap((char *) base, info.st_size);
1288#endif
Daniel Veillard4432df22003-09-28 18:58:27 +00001289#ifdef LIBXML_VALID_ENABLED
Daniel Veillardea7751d2002-12-20 00:16:24 +00001290 } else if (valid) {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001291 xmlParserCtxtPtr ctxt = NULL;
Daniel Veillardea7751d2002-12-20 00:16:24 +00001292
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001293 if (rectxt == NULL)
1294 ctxt = xmlNewParserCtxt();
1295 else
1296 ctxt = rectxt;
Daniel Veillardea7751d2002-12-20 00:16:24 +00001297 if (ctxt == NULL) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001298 doc = NULL;
Daniel Veillardea7751d2002-12-20 00:16:24 +00001299 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001300 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
1301
1302 if (ctxt->valid == 0)
William M. Brack8304d872004-06-08 13:29:32 +00001303 progresult = XMLLINT_ERR_RDFILE;
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001304 if (rectxt == NULL)
1305 xmlFreeParserCtxt(ctxt);
Daniel Veillardea7751d2002-12-20 00:16:24 +00001306 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001307#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardea7751d2002-12-20 00:16:24 +00001308 } else {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001309 if (rectxt != NULL)
1310 doc = xmlCtxtReadFile(rectxt, filename, NULL, options);
Daniel Veillard81562d22005-06-15 13:27:56 +00001311 else {
1312#ifdef LIBXML_SAX1_ENABLED
1313 if (sax1)
1314 doc = xmlParseFile(filename);
1315 else
1316#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001317 doc = xmlReadFile(filename, NULL, options);
Daniel Veillard81562d22005-06-15 13:27:56 +00001318 }
Daniel Veillardea7751d2002-12-20 00:16:24 +00001319 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001320 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001321
Daniel Veillard88a172f2000-08-04 18:23:10 +00001322 /*
1323 * If we don't have a document we might as well give up. Do we
1324 * want an error message here? <sven@zen.org> */
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001325 if (doc == NULL) {
William M. Brack8304d872004-06-08 13:29:32 +00001326 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard88a172f2000-08-04 18:23:10 +00001327 return;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001328 }
1329
Daniel Veillard48b2f892001-02-25 16:11:03 +00001330 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001331 endTimer("Parsing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001332 }
1333
Daniel Veillard29e43992001-12-13 22:21:58 +00001334 /*
1335 * Remove DOCTYPE nodes
1336 */
1337 if (dropdtd) {
1338 xmlDtdPtr dtd;
1339
1340 dtd = xmlGetIntSubset(doc);
1341 if (dtd != NULL) {
1342 xmlUnlinkNode((xmlNodePtr)dtd);
1343 xmlFreeDtd(dtd);
1344 }
1345 }
1346
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001347#ifdef LIBXML_XINCLUDE_ENABLED
Daniel Veillard48b2f892001-02-25 16:11:03 +00001348 if (xinclude) {
1349 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001350 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001351 }
William M. Brack4e1c2db2005-02-11 10:58:55 +00001352 if (xmlXIncludeProcessFlags(doc, options) < 0)
1353 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard48b2f892001-02-25 16:11:03 +00001354 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001355 endTimer("Xinclude processing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001356 }
1357 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001358#endif
Daniel Veillard88a172f2000-08-04 18:23:10 +00001359
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001360#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardd0cf7f62004-11-09 16:17:02 +00001361#ifdef LIBXML_XPATH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001362 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001363 * shell interaction
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001364 */
1365 if (shell)
1366 xmlShell(doc, filename, xmlShellReadline, stdout);
1367#endif
Daniel Veillardd0cf7f62004-11-09 16:17:02 +00001368#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001369
Daniel Veillard652327a2003-09-29 18:02:38 +00001370#ifdef LIBXML_TREE_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001371 /*
1372 * test intermediate copy if needed.
1373 */
1374 if (copy) {
1375 tmp = doc;
Daniel Veillard4edd3ed2004-09-20 20:03:01 +00001376 if (timing) {
1377 startTimer();
1378 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001379 doc = xmlCopyDoc(doc, 1);
Daniel Veillard4edd3ed2004-09-20 20:03:01 +00001380 if (timing) {
1381 endTimer("Copying");
1382 }
1383 if (timing) {
1384 startTimer();
1385 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001386 xmlFreeDoc(tmp);
Daniel Veillard4edd3ed2004-09-20 20:03:01 +00001387 if (timing) {
1388 endTimer("Freeing original");
1389 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001390 }
Daniel Veillard652327a2003-09-29 18:02:38 +00001391#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001392
Daniel Veillard4432df22003-09-28 18:58:27 +00001393#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001394 if ((insert) && (!html)) {
1395 const xmlChar* list[256];
1396 int nb, i;
1397 xmlNodePtr node;
1398
1399 if (doc->children != NULL) {
1400 node = doc->children;
1401 while ((node != NULL) && (node->last == NULL)) node = node->next;
1402 if (node != NULL) {
1403 nb = xmlValidGetValidElements(node->last, NULL, list, 256);
1404 if (nb < 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001405 fprintf(stderr, "could not get valid list of elements\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001406 } else if (nb == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001407 fprintf(stderr, "No element can be inserted under root\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001408 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001409 fprintf(stderr, "%d element types can be inserted under root:\n",
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001410 nb);
1411 for (i = 0;i < nb;i++) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001412 fprintf(stderr, "%s\n", (char *) list[i]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001413 }
1414 }
1415 }
1416 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001417 }else
1418#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001419#ifdef LIBXML_READER_ENABLED
1420 if (walker) {
1421 walkDoc(doc);
1422 }
1423#endif /* LIBXML_READER_ENABLED */
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001424#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard4432df22003-09-28 18:58:27 +00001425 if (noout == 0) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001426 int ret;
1427
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001428 /*
1429 * print it.
1430 */
1431#ifdef LIBXML_DEBUG_ENABLED
1432 if (!debug) {
1433#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +00001434 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001435 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001436 }
Daniel Veillard656ce942004-04-30 23:11:45 +00001437#ifdef LIBXML_HTML_ENABLED
Daniel Veillard42fd4122003-11-04 08:47:48 +00001438 if ((html) && (!xmlout)) {
1439 if (compress) {
1440 htmlSaveFile(output ? output : "-", doc);
1441 }
1442 else if (encoding != NULL) {
1443 if ( format ) {
1444 htmlSaveFileFormat(output ? output : "-", doc, encoding, 1);
1445 }
1446 else {
1447 htmlSaveFileFormat(output ? output : "-", doc, encoding, 0);
1448 }
1449 }
1450 else if (format) {
1451 htmlSaveFileFormat(output ? output : "-", doc, NULL, 1);
1452 }
1453 else {
1454 FILE *out;
1455 if (output == NULL)
1456 out = stdout;
1457 else {
1458 out = fopen(output,"wb");
1459 }
1460 if (out != NULL) {
1461 if (htmlDocDump(out, doc) < 0)
William M. Brack8304d872004-06-08 13:29:32 +00001462 progresult = XMLLINT_ERR_OUT;
Daniel Veillard42fd4122003-11-04 08:47:48 +00001463
1464 if (output != NULL)
1465 fclose(out);
1466 } else {
1467 fprintf(stderr, "failed to open %s\n", output);
William M. Brack8304d872004-06-08 13:29:32 +00001468 progresult = XMLLINT_ERR_OUT;
Daniel Veillard42fd4122003-11-04 08:47:48 +00001469 }
1470 }
1471 if ((timing) && (!repeat)) {
1472 endTimer("Saving");
1473 }
1474 } else
1475#endif
Daniel Veillard25048d82004-08-14 22:37:54 +00001476#ifdef LIBXML_C14N_ENABLED
1477 if (canonical) {
1478 xmlChar *result = NULL;
1479 int size;
1480
1481 size = xmlC14NDocDumpMemory(doc, NULL, 0, NULL, 1, &result);
1482 if (size >= 0) {
1483 write(1, result, size);
1484 xmlFree(result);
1485 } else {
1486 fprintf(stderr, "Failed to canonicalize\n");
1487 progresult = XMLLINT_ERR_OUT;
1488 }
1489 } else
Aleksey Sanin2650df12005-06-06 17:16:50 +00001490 if (exc_canonical) {
1491 xmlChar *result = NULL;
1492 int size;
1493
1494 size = xmlC14NDocDumpMemory(doc, NULL, 1, NULL, 1, &result);
1495 if (size >= 0) {
1496 write(1, result, size);
1497 xmlFree(result);
1498 } else {
1499 fprintf(stderr, "Failed to canonicalize\n");
1500 progresult = XMLLINT_ERR_OUT;
1501 }
1502 } else
Daniel Veillard25048d82004-08-14 22:37:54 +00001503#endif
Daniel Veillard3b2c2612001-04-04 00:09:00 +00001504#ifdef HAVE_SYS_MMAN_H
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001505 if (memory) {
1506 xmlChar *result;
1507 int len;
1508
1509 if (encoding != NULL) {
Daniel Veillardd536f702001-11-08 17:32:47 +00001510 if ( format ) {
1511 xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1);
1512 } else {
1513 xmlDocDumpMemoryEnc(doc, &result, &len, encoding);
1514 }
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001515 } else {
Daniel Veillard90493a92001-08-14 14:12:47 +00001516 if (format)
1517 xmlDocDumpFormatMemory(doc, &result, &len, 1);
1518 else
1519 xmlDocDumpMemory(doc, &result, &len);
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001520 }
1521 if (result == NULL) {
1522 fprintf(stderr, "Failed to save\n");
Daniel Veillard25048d82004-08-14 22:37:54 +00001523 progresult = XMLLINT_ERR_OUT;
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001524 } else {
1525 write(1, result, len);
1526 xmlFree(result);
1527 }
Daniel Veillard3b2c2612001-04-04 00:09:00 +00001528 } else
1529#endif /* HAVE_SYS_MMAN_H */
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001530 if (compress) {
1531 xmlSaveFile(output ? output : "-", doc);
1532 }
Daniel Veillardd536f702001-11-08 17:32:47 +00001533 else if (encoding != NULL) {
1534 if ( format ) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001535 ret = xmlSaveFormatFileEnc(output ? output : "-", doc,
1536 encoding, 1);
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001537 }
Daniel Veillardd536f702001-11-08 17:32:47 +00001538 else {
Daniel Veillard3df01182003-12-10 10:17:51 +00001539 ret = xmlSaveFileEnc(output ? output : "-", doc, encoding);
1540 }
1541 if (ret < 0) {
1542 fprintf(stderr, "failed save to %s\n",
1543 output ? output : "-");
William M. Brack8304d872004-06-08 13:29:32 +00001544 progresult = XMLLINT_ERR_OUT;
Daniel Veillardd536f702001-11-08 17:32:47 +00001545 }
1546 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001547 else if (format) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001548 ret = xmlSaveFormatFile(output ? output : "-", doc, 1);
1549 if (ret < 0) {
1550 fprintf(stderr, "failed save to %s\n",
1551 output ? output : "-");
William M. Brack8304d872004-06-08 13:29:32 +00001552 progresult = XMLLINT_ERR_OUT;
Daniel Veillard3df01182003-12-10 10:17:51 +00001553 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001554 }
1555 else {
1556 FILE *out;
1557 if (output == NULL)
1558 out = stdout;
1559 else {
1560 out = fopen(output,"wb");
1561 }
Daniel Veillard05d987b2003-10-08 11:54:57 +00001562 if (out != NULL) {
Daniel Veillard828ce832003-10-08 19:19:10 +00001563 if (xmlDocDump(out, doc) < 0)
William M. Brack8304d872004-06-08 13:29:32 +00001564 progresult = XMLLINT_ERR_OUT;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001565
Daniel Veillard05d987b2003-10-08 11:54:57 +00001566 if (output != NULL)
1567 fclose(out);
1568 } else {
1569 fprintf(stderr, "failed to open %s\n", output);
William M. Brack8304d872004-06-08 13:29:32 +00001570 progresult = XMLLINT_ERR_OUT;
Daniel Veillard05d987b2003-10-08 11:54:57 +00001571 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001572 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001573 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001574 endTimer("Saving");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001575 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001576#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001577 } else {
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001578 FILE *out;
1579 if (output == NULL)
1580 out = stdout;
1581 else {
1582 out = fopen(output,"wb");
1583 }
Daniel Veillard05d987b2003-10-08 11:54:57 +00001584 if (out != NULL) {
1585 xmlDebugDumpDocument(out, doc);
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001586
Daniel Veillard05d987b2003-10-08 11:54:57 +00001587 if (output != NULL)
1588 fclose(out);
1589 } else {
1590 fprintf(stderr, "failed to open %s\n", output);
William M. Brack8304d872004-06-08 13:29:32 +00001591 progresult = XMLLINT_ERR_OUT;
Daniel Veillard05d987b2003-10-08 11:54:57 +00001592 }
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001593 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001594#endif
1595 }
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001596#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001597
Daniel Veillard4432df22003-09-28 18:58:27 +00001598#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001599 /*
1600 * A posteriori validation test
1601 */
Daniel Veillard66f68e72003-08-18 16:39:51 +00001602 if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) {
Daniel Veillardcd429612000-10-11 15:57:05 +00001603 xmlDtdPtr dtd;
1604
Daniel Veillard48b2f892001-02-25 16:11:03 +00001605 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001606 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001607 }
Daniel Veillard66f68e72003-08-18 16:39:51 +00001608 if (dtdvalid != NULL)
1609 dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid);
1610 else
1611 dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001612 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001613 endTimer("Parsing DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001614 }
Daniel Veillardcd429612000-10-11 15:57:05 +00001615 if (dtd == NULL) {
Daniel Veillard66f68e72003-08-18 16:39:51 +00001616 if (dtdvalid != NULL)
1617 xmlGenericError(xmlGenericErrorContext,
1618 "Could not parse DTD %s\n", dtdvalid);
1619 else
1620 xmlGenericError(xmlGenericErrorContext,
1621 "Could not parse DTD %s\n", dtdvalidfpi);
William M. Brack8304d872004-06-08 13:29:32 +00001622 progresult = XMLLINT_ERR_DTD;
Daniel Veillardcd429612000-10-11 15:57:05 +00001623 } else {
Daniel Veillarda37aab82003-06-09 09:10:36 +00001624 xmlValidCtxtPtr cvp;
1625
1626 if ((cvp = xmlNewValidCtxt()) == NULL) {
1627 xmlGenericError(xmlGenericErrorContext,
1628 "Couldn't allocate validation context\n");
1629 exit(-1);
1630 }
1631 cvp->userData = (void *) stderr;
1632 cvp->error = (xmlValidityErrorFunc) fprintf;
1633 cvp->warning = (xmlValidityWarningFunc) fprintf;
1634
Daniel Veillard48b2f892001-02-25 16:11:03 +00001635 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001636 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001637 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001638 if (!xmlValidateDtd(cvp, doc, dtd)) {
Daniel Veillard66f68e72003-08-18 16:39:51 +00001639 if (dtdvalid != NULL)
1640 xmlGenericError(xmlGenericErrorContext,
1641 "Document %s does not validate against %s\n",
1642 filename, dtdvalid);
1643 else
1644 xmlGenericError(xmlGenericErrorContext,
1645 "Document %s does not validate against %s\n",
1646 filename, dtdvalidfpi);
William M. Brack8304d872004-06-08 13:29:32 +00001647 progresult = XMLLINT_ERR_VALID;
Daniel Veillardcd429612000-10-11 15:57:05 +00001648 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001649 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001650 endTimer("Validating against DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001651 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001652 xmlFreeValidCtxt(cvp);
Daniel Veillardcd429612000-10-11 15:57:05 +00001653 xmlFreeDtd(dtd);
1654 }
1655 } else if (postvalid) {
Daniel Veillarda37aab82003-06-09 09:10:36 +00001656 xmlValidCtxtPtr cvp;
1657
1658 if ((cvp = xmlNewValidCtxt()) == NULL) {
1659 xmlGenericError(xmlGenericErrorContext,
1660 "Couldn't allocate validation context\n");
1661 exit(-1);
1662 }
1663
Daniel Veillard48b2f892001-02-25 16:11:03 +00001664 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001665 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001666 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001667 cvp->userData = (void *) stderr;
1668 cvp->error = (xmlValidityErrorFunc) fprintf;
1669 cvp->warning = (xmlValidityWarningFunc) fprintf;
1670 if (!xmlValidateDocument(cvp, doc)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001671 xmlGenericError(xmlGenericErrorContext,
1672 "Document %s does not validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001673 progresult = XMLLINT_ERR_VALID;
Daniel Veillardcd429612000-10-11 15:57:05 +00001674 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001675 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001676 endTimer("Validating");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001677 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001678 xmlFreeValidCtxt(cvp);
Daniel Veillard4432df22003-09-28 18:58:27 +00001679 }
1680#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard71531f32003-02-05 13:19:53 +00001681#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard4432df22003-09-28 18:58:27 +00001682 if (relaxngschemas != NULL) {
Daniel Veillard71531f32003-02-05 13:19:53 +00001683 xmlRelaxNGValidCtxtPtr ctxt;
1684 int ret;
1685
Daniel Veillard42f12e92003-03-07 18:32:59 +00001686 if ((timing) && (!repeat)) {
1687 startTimer();
1688 }
1689
Daniel Veillard71531f32003-02-05 13:19:53 +00001690 ctxt = xmlRelaxNGNewValidCtxt(relaxngschemas);
1691 xmlRelaxNGSetValidErrors(ctxt,
1692 (xmlRelaxNGValidityErrorFunc) fprintf,
1693 (xmlRelaxNGValidityWarningFunc) fprintf,
1694 stderr);
1695 ret = xmlRelaxNGValidateDoc(ctxt, doc);
1696 if (ret == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001697 fprintf(stderr, "%s validates\n", filename);
Daniel Veillard71531f32003-02-05 13:19:53 +00001698 } else if (ret > 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001699 fprintf(stderr, "%s fails to validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001700 progresult = XMLLINT_ERR_VALID;
Daniel Veillard71531f32003-02-05 13:19:53 +00001701 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001702 fprintf(stderr, "%s validation generated an internal error\n",
Daniel Veillard71531f32003-02-05 13:19:53 +00001703 filename);
William M. Brack8304d872004-06-08 13:29:32 +00001704 progresult = XMLLINT_ERR_VALID;
Daniel Veillard71531f32003-02-05 13:19:53 +00001705 }
1706 xmlRelaxNGFreeValidCtxt(ctxt);
Daniel Veillard42f12e92003-03-07 18:32:59 +00001707 if ((timing) && (!repeat)) {
1708 endTimer("Validating");
1709 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001710 } else if (wxschemas != NULL) {
1711 xmlSchemaValidCtxtPtr ctxt;
1712 int ret;
1713
1714 if ((timing) && (!repeat)) {
1715 startTimer();
1716 }
1717
1718 ctxt = xmlSchemaNewValidCtxt(wxschemas);
1719 xmlSchemaSetValidErrors(ctxt,
1720 (xmlSchemaValidityErrorFunc) fprintf,
1721 (xmlSchemaValidityWarningFunc) fprintf,
1722 stderr);
1723 ret = xmlSchemaValidateDoc(ctxt, doc);
1724 if (ret == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001725 fprintf(stderr, "%s validates\n", filename);
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001726 } else if (ret > 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001727 fprintf(stderr, "%s fails to validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001728 progresult = XMLLINT_ERR_VALID;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001729 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001730 fprintf(stderr, "%s validation generated an internal error\n",
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001731 filename);
William M. Brack8304d872004-06-08 13:29:32 +00001732 progresult = XMLLINT_ERR_VALID;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001733 }
1734 xmlSchemaFreeValidCtxt(ctxt);
1735 if ((timing) && (!repeat)) {
1736 endTimer("Validating");
1737 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001738 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001739#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001740
1741#ifdef LIBXML_DEBUG_ENABLED
1742 if ((debugent) && (!html))
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001743 xmlDebugDumpEntities(stderr, doc);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001744#endif
1745
1746 /*
1747 * free it.
1748 */
Daniel Veillard48b2f892001-02-25 16:11:03 +00001749 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001750 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001751 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001752 xmlFreeDoc(doc);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001753 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001754 endTimer("Freeing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001755 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001756}
1757
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001758/************************************************************************
1759 * *
1760 * Usage and Main *
1761 * *
1762 ************************************************************************/
1763
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001764static void showVersion(const char *name) {
1765 fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion);
1766 fprintf(stderr, " compiled with: ");
Daniel Veillard4432df22003-09-28 18:58:27 +00001767#ifdef LIBXML_VALID_ENABLED
1768 fprintf(stderr, "DTDValid ");
1769#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001770#ifdef LIBXML_FTP_ENABLED
1771 fprintf(stderr, "FTP ");
1772#endif
1773#ifdef LIBXML_HTTP_ENABLED
1774 fprintf(stderr, "HTTP ");
1775#endif
1776#ifdef LIBXML_HTML_ENABLED
1777 fprintf(stderr, "HTML ");
1778#endif
1779#ifdef LIBXML_C14N_ENABLED
1780 fprintf(stderr, "C14N ");
1781#endif
1782#ifdef LIBXML_CATALOG_ENABLED
1783 fprintf(stderr, "Catalog ");
1784#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001785#ifdef LIBXML_XPATH_ENABLED
1786 fprintf(stderr, "XPath ");
1787#endif
1788#ifdef LIBXML_XPTR_ENABLED
1789 fprintf(stderr, "XPointer ");
1790#endif
1791#ifdef LIBXML_XINCLUDE_ENABLED
1792 fprintf(stderr, "XInclude ");
1793#endif
1794#ifdef LIBXML_ICONV_ENABLED
1795 fprintf(stderr, "Iconv ");
1796#endif
1797#ifdef DEBUG_MEMORY_LOCATION
1798 fprintf(stderr, "MemDebug ");
1799#endif
1800#ifdef LIBXML_UNICODE_ENABLED
1801 fprintf(stderr, "Unicode ");
1802#endif
1803#ifdef LIBXML_REGEXP_ENABLED
1804 fprintf(stderr, "Regexps ");
1805#endif
1806#ifdef LIBXML_AUTOMATA_ENABLED
1807 fprintf(stderr, "Automata ");
1808#endif
1809#ifdef LIBXML_SCHEMAS_ENABLED
1810 fprintf(stderr, "Schemas ");
1811#endif
Daniel Veillardce1648b2005-01-04 15:10:22 +00001812#ifdef LIBXML_MODULES_ENABLED
1813 fprintf(stderr, "Modules ");
1814#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001815 fprintf(stderr, "\n");
1816}
1817
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001818static void usage(const char *name) {
1819 printf("Usage : %s [options] XMLfiles ...\n", name);
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001820#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001821 printf("\tParse the XML files and output the result of the parsing\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001822#else
1823 printf("\tParse the XML files\n");
1824#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001825 printf("\t--version : display the version of the XML library used\n");
1826#ifdef LIBXML_DEBUG_ENABLED
1827 printf("\t--debug : dump a debug tree of the in-memory document\n");
1828 printf("\t--shell : run a navigating shell\n");
1829 printf("\t--debugent : debug the entities defined in the document\n");
Daniel Veillard8326e732003-01-07 00:19:07 +00001830#else
Daniel Veillard81273902003-09-30 00:43:48 +00001831#ifdef LIBXML_READER_ENABLED
Daniel Veillard8326e732003-01-07 00:19:07 +00001832 printf("\t--debug : dump the nodes content when using --stream\n");
Daniel Veillard81273902003-09-30 00:43:48 +00001833#endif /* LIBXML_READER_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001834#endif
Daniel Veillard652327a2003-09-29 18:02:38 +00001835#ifdef LIBXML_TREE_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001836 printf("\t--copy : used to test the internal copy implementation\n");
Daniel Veillard652327a2003-09-29 18:02:38 +00001837#endif /* LIBXML_TREE_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001838 printf("\t--recover : output what was parsable on broken XML documents\n");
1839 printf("\t--noent : substitute entity references by their value\n");
1840 printf("\t--noout : don't output the result tree\n");
Daniel Veillard0bff36d2004-08-31 09:37:03 +00001841 printf("\t--path 'paths': provide a set of paths for resources\n");
1842 printf("\t--load-trace : print trace of all external entites loaded\n");
Daniel Veillarde8b09e42003-05-13 22:14:13 +00001843 printf("\t--nonet : refuse to fetch DTDs or entities over network\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001844 printf("\t--htmlout : output results as HTML\n");
Daniel Veillard05c13a22001-09-09 08:38:09 +00001845 printf("\t--nowrap : do not put HTML doc wrapper\n");
Daniel Veillard4432df22003-09-28 18:58:27 +00001846#ifdef LIBXML_VALID_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001847 printf("\t--valid : validate the document in addition to std well-formed check\n");
1848 printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
1849 printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
Daniel Veillard66f68e72003-08-18 16:39:51 +00001850 printf("\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
Daniel Veillard4432df22003-09-28 18:58:27 +00001851#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001852 printf("\t--timing : print some timings\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001853 printf("\t--output file or -o file: save to a given file\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001854 printf("\t--repeat : repeat 100 times, for timing or profiling\n");
1855 printf("\t--insert : ad-hoc test for valid insertions\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001856#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001857#ifdef HAVE_ZLIB_H
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001858 printf("\t--compress : turn on gzip compression of output\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001859#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001860#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001861#ifdef LIBXML_HTML_ENABLED
1862 printf("\t--html : use the HTML parser\n");
Daniel Veillard42fd4122003-11-04 08:47:48 +00001863 printf("\t--xmlout : force to use the XML serializer when using --html\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001864#endif
Daniel Veillard73b013f2003-09-30 12:36:01 +00001865#ifdef LIBXML_PUSH_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001866 printf("\t--push : use the push mode of the parser\n");
Daniel Veillard73b013f2003-09-30 12:36:01 +00001867#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001868#ifdef HAVE_SYS_MMAN_H
1869 printf("\t--memory : parse from memory\n");
1870#endif
Daniel Veillard87076042004-05-03 22:54:49 +00001871 printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001872 printf("\t--nowarning : do not emit warnings from parser/validator\n");
1873 printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
Daniel Veillarddca8cc72003-09-26 13:53:14 +00001874 printf("\t--nocdata : replace cdata section with text nodes\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001875#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard90493a92001-08-14 14:12:47 +00001876 printf("\t--format : reformat/reindent the input\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001877 printf("\t--encode encoding : output in the given encoding\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001878 printf("\t--dropdtd : remove the DOCTYPE of the input docs\n");
1879#endif /* LIBXML_OUTPUT_ENABLED */
Aleksey Sanin2650df12005-06-06 17:16:50 +00001880 printf("\t--c14n : save in W3C canonical format (with comments)\n");
1881 printf("\t--exc-c14n : save in W3C exclusive canonical format (with comments)\n");
Daniel Veillard25048d82004-08-14 22:37:54 +00001882#ifdef LIBXML_C14N_ENABLED
1883#endif /* LIBXML_C14N_ENABLED */
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001884 printf("\t--nsclean : remove redundant namespace declarations\n");
1885 printf("\t--testIO : test user I/O support\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001886#ifdef LIBXML_CATALOG_ENABLED
Daniel Veillardbd9b0e82001-11-26 10:32:08 +00001887 printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");
1888 printf("\t otherwise XML Catalogs starting from \n");
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001889 printf("\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG);
Daniel Veillard05c13a22001-09-09 08:38:09 +00001890 printf("\t--nocatalogs: deactivate all catalogs\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001891#endif
1892 printf("\t--auto : generate a small doc on the fly\n");
1893#ifdef LIBXML_XINCLUDE_ENABLED
1894 printf("\t--xinclude : do XInclude processing\n");
Daniel Veillardc14c3892004-08-16 12:34:50 +00001895 printf("\t--noxincludenode : same but do not generate XInclude nodes\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001896#endif
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001897 printf("\t--loaddtd : fetch external DTD\n");
Daniel Veillard48da9102001-08-07 01:10:10 +00001898 printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
Daniel Veillard81273902003-09-30 00:43:48 +00001899#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00001900 printf("\t--stream : use the streaming interface to process very large files\n");
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001901 printf("\t--walker : create a reader and walk though the resulting doc\n");
Daniel Veillard81273902003-09-30 00:43:48 +00001902#endif /* LIBXML_READER_ENABLED */
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001903#ifdef LIBXML_PATTERN_ENABLED
1904 printf("\t--pattern pattern_value : test the pattern support\n");
1905#endif
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001906 printf("\t--chkregister : verify the node registration code\n");
Daniel Veillardef4d3bc2003-02-07 12:38:22 +00001907#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard71531f32003-02-05 13:19:53 +00001908 printf("\t--relaxng schema : do RelaxNG validation against the schema\n");
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001909 printf("\t--schema schema : do validation against the WXS schema\n");
Daniel Veillard71531f32003-02-05 13:19:53 +00001910#endif
Daniel Veillarda42f25f2002-01-25 14:15:40 +00001911 printf("\nLibxml project home page: http://xmlsoft.org/\n");
1912 printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001913}
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001914
1915static void registerNode(xmlNodePtr node)
1916{
1917 node->_private = malloc(sizeof(long));
1918 *(long*)node->_private = (long) 0x81726354;
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00001919 nbregister++;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001920}
1921
1922static void deregisterNode(xmlNodePtr node)
1923{
1924 assert(node->_private != NULL);
1925 assert(*(long*)node->_private == (long) 0x81726354);
1926 free(node->_private);
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00001927 nbregister--;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001928}
1929
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001930int
1931main(int argc, char **argv) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00001932 int i, acount;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001933 int files = 0;
Daniel Veillard845cce42002-01-09 11:51:37 +00001934 int version = 0;
Aleksey Sanin693c9bc2003-03-09 22:36:52 +00001935 const char* indent;
1936
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001937 if (argc <= 1) {
1938 usage(argv[0]);
1939 return(1);
1940 }
Daniel Veillardbe803962000-06-28 23:40:59 +00001941 LIBXML_TEST_VERSION
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001942 for (i = 1; i < argc ; i++) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001943 if (!strcmp(argv[i], "-"))
1944 break;
1945
1946 if (argv[i][0] != '-')
1947 continue;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001948 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
1949 debug++;
Daniel Veillard56ada1d2003-01-07 11:17:25 +00001950 else
1951#ifdef LIBXML_DEBUG_ENABLED
1952 if ((!strcmp(argv[i], "-shell")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001953 (!strcmp(argv[i], "--shell"))) {
1954 shell++;
1955 noout = 1;
1956 } else
1957#endif
Daniel Veillard652327a2003-09-29 18:02:38 +00001958#ifdef LIBXML_TREE_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001959 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
1960 copy++;
Daniel Veillard652327a2003-09-29 18:02:38 +00001961 else
1962#endif /* LIBXML_TREE_ENABLED */
1963 if ((!strcmp(argv[i], "-recover")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001964 (!strcmp(argv[i], "--recover"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001965 recovery++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001966 options |= XML_PARSE_RECOVER;
1967 } else if ((!strcmp(argv[i], "-noent")) ||
1968 (!strcmp(argv[i], "--noent"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001969 noent++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001970 options |= XML_PARSE_NOENT;
Daniel Veillarddca8cc72003-09-26 13:53:14 +00001971 } else if ((!strcmp(argv[i], "-nsclean")) ||
1972 (!strcmp(argv[i], "--nsclean"))) {
1973 options |= XML_PARSE_NSCLEAN;
1974 } else if ((!strcmp(argv[i], "-nocdata")) ||
1975 (!strcmp(argv[i], "--nocdata"))) {
1976 options |= XML_PARSE_NOCDATA;
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001977 } else if ((!strcmp(argv[i], "-nodict")) ||
1978 (!strcmp(argv[i], "--nodict"))) {
1979 options |= XML_PARSE_NODICT;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001980 } else if ((!strcmp(argv[i], "-version")) ||
Daniel Veillard845cce42002-01-09 11:51:37 +00001981 (!strcmp(argv[i], "--version"))) {
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001982 showVersion(argv[0]);
Daniel Veillard845cce42002-01-09 11:51:37 +00001983 version = 1;
1984 } else if ((!strcmp(argv[i], "-noout")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001985 (!strcmp(argv[i], "--noout")))
1986 noout++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001987#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001988 else if ((!strcmp(argv[i], "-o")) ||
1989 (!strcmp(argv[i], "-output")) ||
1990 (!strcmp(argv[i], "--output"))) {
1991 i++;
Daniel Veillard6e4f1c02002-04-09 09:55:20 +00001992 output = argv[i];
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001993 }
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001994#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001995 else if ((!strcmp(argv[i], "-htmlout")) ||
1996 (!strcmp(argv[i], "--htmlout")))
1997 htmlout++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001998 else if ((!strcmp(argv[i], "-nowrap")) ||
1999 (!strcmp(argv[i], "--nowrap")))
2000 nowrap++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002001#ifdef LIBXML_HTML_ENABLED
2002 else if ((!strcmp(argv[i], "-html")) ||
2003 (!strcmp(argv[i], "--html"))) {
2004 html++;
2005 }
Daniel Veillard42fd4122003-11-04 08:47:48 +00002006 else if ((!strcmp(argv[i], "-xmlout")) ||
2007 (!strcmp(argv[i], "--xmlout"))) {
2008 xmlout++;
2009 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002010#endif /* LIBXML_HTML_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002011 else if ((!strcmp(argv[i], "-loaddtd")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002012 (!strcmp(argv[i], "--loaddtd"))) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002013 loaddtd++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002014 options |= XML_PARSE_DTDLOAD;
2015 } else if ((!strcmp(argv[i], "-dtdattr")) ||
Daniel Veillard48da9102001-08-07 01:10:10 +00002016 (!strcmp(argv[i], "--dtdattr"))) {
2017 loaddtd++;
2018 dtdattrs++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002019 options |= XML_PARSE_DTDATTR;
Daniel Veillard4432df22003-09-28 18:58:27 +00002020 }
2021#ifdef LIBXML_VALID_ENABLED
2022 else if ((!strcmp(argv[i], "-valid")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002023 (!strcmp(argv[i], "--valid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002024 valid++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002025 options |= XML_PARSE_DTDVALID;
2026 } else if ((!strcmp(argv[i], "-postvalid")) ||
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002027 (!strcmp(argv[i], "--postvalid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002028 postvalid++;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002029 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00002030 options |= XML_PARSE_DTDLOAD;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002031 } else if ((!strcmp(argv[i], "-dtdvalid")) ||
Daniel Veillardcd429612000-10-11 15:57:05 +00002032 (!strcmp(argv[i], "--dtdvalid"))) {
2033 i++;
2034 dtdvalid = argv[i];
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002035 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00002036 options |= XML_PARSE_DTDLOAD;
Daniel Veillard66f68e72003-08-18 16:39:51 +00002037 } else if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
2038 (!strcmp(argv[i], "--dtdvalidfpi"))) {
2039 i++;
2040 dtdvalidfpi = argv[i];
2041 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00002042 options |= XML_PARSE_DTDLOAD;
Daniel Veillardcd429612000-10-11 15:57:05 +00002043 }
Daniel Veillard4432df22003-09-28 18:58:27 +00002044#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard29e43992001-12-13 22:21:58 +00002045 else if ((!strcmp(argv[i], "-dropdtd")) ||
2046 (!strcmp(argv[i], "--dropdtd")))
2047 dropdtd++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002048 else if ((!strcmp(argv[i], "-insert")) ||
2049 (!strcmp(argv[i], "--insert")))
2050 insert++;
Daniel Veillard48b2f892001-02-25 16:11:03 +00002051 else if ((!strcmp(argv[i], "-timing")) ||
2052 (!strcmp(argv[i], "--timing")))
2053 timing++;
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00002054 else if ((!strcmp(argv[i], "-auto")) ||
2055 (!strcmp(argv[i], "--auto")))
2056 generate++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002057 else if ((!strcmp(argv[i], "-repeat")) ||
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00002058 (!strcmp(argv[i], "--repeat"))) {
2059 if (repeat)
2060 repeat *= 10;
2061 else
2062 repeat = 100;
Daniel Veillard73b013f2003-09-30 12:36:01 +00002063 }
2064#ifdef LIBXML_PUSH_ENABLED
2065 else if ((!strcmp(argv[i], "-push")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002066 (!strcmp(argv[i], "--push")))
2067 push++;
Daniel Veillard73b013f2003-09-30 12:36:01 +00002068#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillard46e370e2000-07-21 20:32:03 +00002069#ifdef HAVE_SYS_MMAN_H
2070 else if ((!strcmp(argv[i], "-memory")) ||
2071 (!strcmp(argv[i], "--memory")))
2072 memory++;
2073#endif
Daniel Veillard5e873c42000-04-12 13:27:38 +00002074 else if ((!strcmp(argv[i], "-testIO")) ||
2075 (!strcmp(argv[i], "--testIO")))
2076 testIO++;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00002077#ifdef LIBXML_XINCLUDE_ENABLED
2078 else if ((!strcmp(argv[i], "-xinclude")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002079 (!strcmp(argv[i], "--xinclude"))) {
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00002080 xinclude++;
Daniel Veillard7899c5c2003-11-03 12:31:38 +00002081 options |= XML_PARSE_XINCLUDE;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002082 }
Daniel Veillardc14c3892004-08-16 12:34:50 +00002083 else if ((!strcmp(argv[i], "-noxincludenode")) ||
2084 (!strcmp(argv[i], "--noxincludenode"))) {
2085 xinclude++;
2086 options |= XML_PARSE_XINCLUDE;
2087 options |= XML_PARSE_NOXINCNODE;
2088 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00002089#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002090#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00002091#ifdef HAVE_ZLIB_H
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002092 else if ((!strcmp(argv[i], "-compress")) ||
2093 (!strcmp(argv[i], "--compress"))) {
2094 compress++;
2095 xmlSetCompressMode(9);
2096 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00002097#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002098#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002099 else if ((!strcmp(argv[i], "-nowarning")) ||
2100 (!strcmp(argv[i], "--nowarning"))) {
2101 xmlGetWarningsDefaultValue = 0;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002102 xmlPedanticParserDefault(0);
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002103 options |= XML_PARSE_NOWARNING;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002104 }
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002105 else if ((!strcmp(argv[i], "-pedantic")) ||
2106 (!strcmp(argv[i], "--pedantic"))) {
2107 xmlGetWarningsDefaultValue = 1;
2108 xmlPedanticParserDefault(1);
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002109 options |= XML_PARSE_PEDANTIC;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002110 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00002111#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002112 else if ((!strcmp(argv[i], "-debugent")) ||
2113 (!strcmp(argv[i], "--debugent"))) {
2114 debugent++;
2115 xmlParserDebugEntities = 1;
2116 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00002117#endif
Daniel Veillard25048d82004-08-14 22:37:54 +00002118#ifdef LIBXML_C14N_ENABLED
2119 else if ((!strcmp(argv[i], "-c14n")) ||
2120 (!strcmp(argv[i], "--c14n"))) {
2121 canonical++;
2122 options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD;
2123 }
Aleksey Sanin2650df12005-06-06 17:16:50 +00002124 else if ((!strcmp(argv[i], "-exc-c14n")) ||
2125 (!strcmp(argv[i], "--exc-c14n"))) {
2126 exc_canonical++;
2127 options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD;
2128 }
Daniel Veillard25048d82004-08-14 22:37:54 +00002129#endif
Daniel Veillard81418e32001-05-22 15:08:55 +00002130#ifdef LIBXML_CATALOG_ENABLED
2131 else if ((!strcmp(argv[i], "-catalogs")) ||
2132 (!strcmp(argv[i], "--catalogs"))) {
Daniel Veillarde2940dd2001-08-22 00:06:49 +00002133 catalogs++;
2134 } else if ((!strcmp(argv[i], "-nocatalogs")) ||
2135 (!strcmp(argv[i], "--nocatalogs"))) {
2136 nocatalogs++;
Daniel Veillard81418e32001-05-22 15:08:55 +00002137 }
2138#endif
Daniel Veillardbe803962000-06-28 23:40:59 +00002139 else if ((!strcmp(argv[i], "-encode")) ||
2140 (!strcmp(argv[i], "--encode"))) {
2141 i++;
2142 encoding = argv[i];
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002143 /*
2144 * OK it's for testing purposes
2145 */
2146 xmlAddEncodingAlias("UTF-8", "DVEnc");
Daniel Veillardbe803962000-06-28 23:40:59 +00002147 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002148 else if ((!strcmp(argv[i], "-noblanks")) ||
2149 (!strcmp(argv[i], "--noblanks"))) {
2150 noblanks++;
2151 xmlKeepBlanksDefault(0);
Daniel Veillard90493a92001-08-14 14:12:47 +00002152 }
Daniel Veillard87076042004-05-03 22:54:49 +00002153 else if ((!strcmp(argv[i], "-maxmem")) ||
2154 (!strcmp(argv[i], "--maxmem"))) {
2155 i++;
2156 if (sscanf(argv[i], "%d", &maxmem) == 1) {
2157 xmlMemSetup(myFreeFunc, myMallocFunc, myReallocFunc,
2158 myStrdupFunc);
2159 } else {
2160 maxmem = 0;
2161 }
2162 }
Daniel Veillard90493a92001-08-14 14:12:47 +00002163 else if ((!strcmp(argv[i], "-format")) ||
2164 (!strcmp(argv[i], "--format"))) {
2165 noblanks++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002166#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard90493a92001-08-14 14:12:47 +00002167 format++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002168#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard90493a92001-08-14 14:12:47 +00002169 xmlKeepBlanksDefault(0);
Daniel Veillard7704fb12003-01-03 16:19:51 +00002170 }
Daniel Veillard81273902003-09-30 00:43:48 +00002171#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00002172 else if ((!strcmp(argv[i], "-stream")) ||
2173 (!strcmp(argv[i], "--stream"))) {
2174 stream++;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002175 }
Daniel Veillard7899c5c2003-11-03 12:31:38 +00002176 else if ((!strcmp(argv[i], "-walker")) ||
2177 (!strcmp(argv[i], "--walker"))) {
2178 walker++;
2179 noout++;
2180 }
Daniel Veillard81273902003-09-30 00:43:48 +00002181#endif /* LIBXML_READER_ENABLED */
2182#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +00002183 else if ((!strcmp(argv[i], "-sax1")) ||
2184 (!strcmp(argv[i], "--sax1"))) {
2185 sax1++;
2186 }
Daniel Veillard81273902003-09-30 00:43:48 +00002187#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002188 else if ((!strcmp(argv[i], "-chkregister")) ||
2189 (!strcmp(argv[i], "--chkregister"))) {
2190 chkregister++;
Daniel Veillard71531f32003-02-05 13:19:53 +00002191#ifdef LIBXML_SCHEMAS_ENABLED
2192 } else if ((!strcmp(argv[i], "-relaxng")) ||
2193 (!strcmp(argv[i], "--relaxng"))) {
2194 i++;
2195 relaxng = argv[i];
2196 noent++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002197 options |= XML_PARSE_NOENT;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002198 } else if ((!strcmp(argv[i], "-schema")) ||
2199 (!strcmp(argv[i], "--schema"))) {
2200 i++;
2201 schema = argv[i];
2202 noent++;
Daniel Veillard71531f32003-02-05 13:19:53 +00002203#endif
Daniel Veillarde8b09e42003-05-13 22:14:13 +00002204 } else if ((!strcmp(argv[i], "-nonet")) ||
2205 (!strcmp(argv[i], "--nonet"))) {
Daniel Veillard61b93382003-11-03 14:28:31 +00002206 options |= XML_PARSE_NONET;
Daniel Veillard0bff36d2004-08-31 09:37:03 +00002207 } else if ((!strcmp(argv[i], "-load-trace")) ||
2208 (!strcmp(argv[i], "--load-trace"))) {
2209 load_trace++;
2210 } else if ((!strcmp(argv[i], "-path")) ||
2211 (!strcmp(argv[i], "--path"))) {
2212 i++;
2213 parsePath(BAD_CAST argv[i]);
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002214#ifdef LIBXML_PATTERN_ENABLED
2215 } else if ((!strcmp(argv[i], "-pattern")) ||
2216 (!strcmp(argv[i], "--pattern"))) {
2217 i++;
2218 pattern = argv[i];
2219#endif
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002220 } else {
2221 fprintf(stderr, "Unknown option %s\n", argv[i]);
2222 usage(argv[0]);
2223 return(1);
2224 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002225 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00002226
2227#ifdef LIBXML_CATALOG_ENABLED
2228 if (nocatalogs == 0) {
2229 if (catalogs) {
2230 const char *catal;
2231
2232 catal = getenv("SGML_CATALOG_FILES");
Daniel Veillard6c5f9d12001-08-25 13:33:14 +00002233 if (catal != NULL) {
2234 xmlLoadCatalogs(catal);
2235 } else {
2236 fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n");
2237 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00002238 }
2239 }
2240#endif
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002241
Daniel Veillard81273902003-09-30 00:43:48 +00002242#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +00002243 if (sax1)
2244 xmlSAXDefaultVersion(1);
2245 else
2246 xmlSAXDefaultVersion(2);
Daniel Veillard81273902003-09-30 00:43:48 +00002247#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillard07cb8222003-09-10 10:51:05 +00002248
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002249 if (chkregister) {
2250 xmlRegisterNodeDefault(registerNode);
2251 xmlDeregisterNodeDefault(deregisterNode);
2252 }
Aleksey Sanin693c9bc2003-03-09 22:36:52 +00002253
2254 indent = getenv("XMLLINT_INDENT");
2255 if(indent != NULL) {
2256 xmlTreeIndentString = indent;
2257 }
2258
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002259
Daniel Veillard0bff36d2004-08-31 09:37:03 +00002260 defaultEntityLoader = xmlGetExternalEntityLoader();
2261 xmlSetExternalEntityLoader(xmllintExternalEntityLoader);
2262
Daniel Veillardd9bad132001-07-23 19:39:43 +00002263 xmlLineNumbersDefault(1);
Daniel Veillard48da9102001-08-07 01:10:10 +00002264 if (loaddtd != 0)
2265 xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
2266 if (dtdattrs)
2267 xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002268 if (noent != 0) xmlSubstituteEntitiesDefault(1);
Daniel Veillard4432df22003-09-28 18:58:27 +00002269#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002270 if (valid != 0) xmlDoValidityCheckingDefaultValue = 1;
Daniel Veillard4432df22003-09-28 18:58:27 +00002271#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002272 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002273 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002274 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002275 xmlGenericError(xmlGenericErrorContext,
2276 "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
2277 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002278 "<html><head><title>%s output</title></head>\n",
2279 argv[0]);
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002280 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002281 "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
2282 argv[0]);
2283 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002284
2285#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard81273902003-09-30 00:43:48 +00002286 if ((relaxng != NULL)
2287#ifdef LIBXML_READER_ENABLED
2288 && (stream == 0)
2289#endif /* LIBXML_READER_ENABLED */
2290 ) {
Daniel Veillard71531f32003-02-05 13:19:53 +00002291 xmlRelaxNGParserCtxtPtr ctxt;
2292
Daniel Veillardce192eb2003-04-16 15:58:05 +00002293 /* forces loading the DTDs */
2294 xmlLoadExtDtdDefaultValue |= 1;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002295 options |= XML_PARSE_DTDLOAD;
Daniel Veillard42f12e92003-03-07 18:32:59 +00002296 if (timing) {
2297 startTimer();
2298 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002299 ctxt = xmlRelaxNGNewParserCtxt(relaxng);
2300 xmlRelaxNGSetParserErrors(ctxt,
2301 (xmlRelaxNGValidityErrorFunc) fprintf,
2302 (xmlRelaxNGValidityWarningFunc) fprintf,
2303 stderr);
2304 relaxngschemas = xmlRelaxNGParse(ctxt);
Daniel Veillardce192eb2003-04-16 15:58:05 +00002305 if (relaxngschemas == NULL) {
2306 xmlGenericError(xmlGenericErrorContext,
2307 "Relax-NG schema %s failed to compile\n", relaxng);
William M. Brack8304d872004-06-08 13:29:32 +00002308 progresult = XMLLINT_ERR_SCHEMACOMP;
Daniel Veillardce192eb2003-04-16 15:58:05 +00002309 relaxng = NULL;
2310 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002311 xmlRelaxNGFreeParserCtxt(ctxt);
Daniel Veillard42f12e92003-03-07 18:32:59 +00002312 if (timing) {
2313 endTimer("Compiling the schemas");
2314 }
Daniel Veillardebe25d42004-03-25 09:35:49 +00002315 } else if ((schema != NULL)
2316#ifdef LIBXML_READER_ENABLED
2317 && (stream == 0)
2318#endif
2319 ) {
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002320 xmlSchemaParserCtxtPtr ctxt;
2321
2322 if (timing) {
2323 startTimer();
2324 }
2325 ctxt = xmlSchemaNewParserCtxt(schema);
2326 xmlSchemaSetParserErrors(ctxt,
2327 (xmlSchemaValidityErrorFunc) fprintf,
2328 (xmlSchemaValidityWarningFunc) fprintf,
2329 stderr);
2330 wxschemas = xmlSchemaParse(ctxt);
2331 if (wxschemas == NULL) {
2332 xmlGenericError(xmlGenericErrorContext,
2333 "WXS schema %s failed to compile\n", schema);
William M. Brack8304d872004-06-08 13:29:32 +00002334 progresult = XMLLINT_ERR_SCHEMACOMP;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002335 schema = NULL;
2336 }
2337 xmlSchemaFreeParserCtxt(ctxt);
2338 if (timing) {
2339 endTimer("Compiling the schemas");
2340 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002341 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002342#endif /* LIBXML_SCHEMAS_ENABLED */
2343#ifdef LIBXML_PATTERN_ENABLED
Daniel Veillard39e5c892005-07-03 22:48:50 +00002344 if ((pattern != NULL)
Daniel Veillardc9352532005-07-04 14:25:34 +00002345#ifdef LIBXML_READER_ENABLED
Daniel Veillard39e5c892005-07-03 22:48:50 +00002346 && (walker == 0)
2347#endif
2348 ) {
Daniel Veillardffa7b7e2003-12-05 16:10:21 +00002349 patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL);
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002350 if (patternc == NULL) {
2351 xmlGenericError(xmlGenericErrorContext,
2352 "Pattern %s failed to compile\n", pattern);
William M. Brack8304d872004-06-08 13:29:32 +00002353 progresult = XMLLINT_ERR_SCHEMAPAT;
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002354 pattern = NULL;
2355 }
2356 }
2357#endif /* LIBXML_PATTERN_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002358 for (i = 1; i < argc ; i++) {
Daniel Veillardbe803962000-06-28 23:40:59 +00002359 if ((!strcmp(argv[i], "-encode")) ||
2360 (!strcmp(argv[i], "--encode"))) {
2361 i++;
2362 continue;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00002363 } else if ((!strcmp(argv[i], "-o")) ||
2364 (!strcmp(argv[i], "-output")) ||
2365 (!strcmp(argv[i], "--output"))) {
2366 i++;
2367 continue;
Daniel Veillardbe803962000-06-28 23:40:59 +00002368 }
Daniel Veillard4432df22003-09-28 18:58:27 +00002369#ifdef LIBXML_VALID_ENABLED
Daniel Veillardcd429612000-10-11 15:57:05 +00002370 if ((!strcmp(argv[i], "-dtdvalid")) ||
2371 (!strcmp(argv[i], "--dtdvalid"))) {
2372 i++;
2373 continue;
Daniel Veillard0bff36d2004-08-31 09:37:03 +00002374 }
2375 if ((!strcmp(argv[i], "-path")) ||
2376 (!strcmp(argv[i], "--path"))) {
2377 i++;
2378 continue;
Daniel Veillardcd429612000-10-11 15:57:05 +00002379 }
Daniel Veillard66f68e72003-08-18 16:39:51 +00002380 if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
2381 (!strcmp(argv[i], "--dtdvalidfpi"))) {
2382 i++;
2383 continue;
2384 }
Daniel Veillard4432df22003-09-28 18:58:27 +00002385#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard71531f32003-02-05 13:19:53 +00002386 if ((!strcmp(argv[i], "-relaxng")) ||
2387 (!strcmp(argv[i], "--relaxng"))) {
2388 i++;
2389 continue;
2390 }
Daniel Veillard87076042004-05-03 22:54:49 +00002391 if ((!strcmp(argv[i], "-maxmem")) ||
2392 (!strcmp(argv[i], "--maxmem"))) {
2393 i++;
2394 continue;
2395 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002396 if ((!strcmp(argv[i], "-schema")) ||
2397 (!strcmp(argv[i], "--schema"))) {
2398 i++;
2399 continue;
2400 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002401#ifdef LIBXML_PATTERN_ENABLED
2402 if ((!strcmp(argv[i], "-pattern")) ||
2403 (!strcmp(argv[i], "--pattern"))) {
2404 i++;
2405 continue;
2406 }
2407#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +00002408 if ((timing) && (repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +00002409 startTimer();
Daniel Veillardcbaf3992001-12-31 16:16:02 +00002410 /* Remember file names. "-" means stdin. <sven@zen.org> */
Daniel Veillard4a6845d2001-01-03 13:32:39 +00002411 if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002412 if (repeat) {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002413 xmlParserCtxtPtr ctxt = NULL;
2414
2415 for (acount = 0;acount < repeat;acount++) {
Daniel Veillard81273902003-09-30 00:43:48 +00002416#ifdef LIBXML_READER_ENABLED
Daniel Veillard198c1bf2003-10-20 17:07:41 +00002417 if (stream != 0) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00002418 streamFile(argv[i]);
Daniel Veillard198c1bf2003-10-20 17:07:41 +00002419 } else {
Daniel Veillard81273902003-09-30 00:43:48 +00002420#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002421 if (ctxt == NULL)
2422 ctxt = xmlNewParserCtxt();
2423 parseAndPrintFile(argv[i], ctxt);
Daniel Veillard81273902003-09-30 00:43:48 +00002424#ifdef LIBXML_READER_ENABLED
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002425 }
Daniel Veillard81273902003-09-30 00:43:48 +00002426#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002427 }
2428 if (ctxt != NULL)
2429 xmlFreeParserCtxt(ctxt);
Daniel Veillard7704fb12003-01-03 16:19:51 +00002430 } else {
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00002431 nbregister = 0;
2432
Daniel Veillard81273902003-09-30 00:43:48 +00002433#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00002434 if (stream != 0)
2435 streamFile(argv[i]);
2436 else
Daniel Veillard81273902003-09-30 00:43:48 +00002437#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002438 parseAndPrintFile(argv[i], NULL);
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00002439
2440 if ((chkregister) && (nbregister != 0)) {
2441 fprintf(stderr, "Registration count off: %d\n", nbregister);
William M. Brack8304d872004-06-08 13:29:32 +00002442 progresult = XMLLINT_ERR_RDREGIS;
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00002443 }
Daniel Veillard7704fb12003-01-03 16:19:51 +00002444 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002445 files ++;
Daniel Veillarda7866932001-12-04 13:14:44 +00002446 if ((timing) && (repeat)) {
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00002447 endTimer("%d iterations", repeat);
Daniel Veillarda7866932001-12-04 13:14:44 +00002448 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00002449 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002450 }
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00002451 if (generate)
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002452 parseAndPrintFile(NULL, NULL);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002453 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002454 xmlGenericError(xmlGenericErrorContext, "</body></html>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002455 }
Daniel Veillard845cce42002-01-09 11:51:37 +00002456 if ((files == 0) && (!generate) && (version == 0)) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002457 usage(argv[0]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002458 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002459#ifdef LIBXML_SCHEMAS_ENABLED
2460 if (relaxngschemas != NULL)
2461 xmlRelaxNGFree(relaxngschemas);
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002462 if (wxschemas != NULL)
2463 xmlSchemaFree(wxschemas);
Daniel Veillard71531f32003-02-05 13:19:53 +00002464 xmlRelaxNGCleanupTypes();
2465#endif
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002466#ifdef LIBXML_PATTERN_ENABLED
2467 if (patternc != NULL)
2468 xmlFreePattern(patternc);
2469#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002470 xmlCleanupParser();
2471 xmlMemoryDump();
2472
Daniel Veillardf7cd4812001-02-23 18:44:52 +00002473 return(progresult);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002474}
Daniel Veillard88a172f2000-08-04 18:23:10 +00002475