blob: b92b5330bdd228ba4f7613ba6d097177b8079ae2 [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;
176#endif
Daniel Veillard81273902003-09-30 00:43:48 +0000177#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +0000178static int stream = 0;
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000179static int walker = 0;
Daniel Veillard81273902003-09-30 00:43:48 +0000180#endif /* LIBXML_READER_ENABLED */
Daniel Veillard8a1b1852003-01-05 22:37:17 +0000181static int chkregister = 0;
Daniel Veillarda2d51fc2004-04-30 22:25:59 +0000182static int nbregister = 0;
Daniel Veillard81273902003-09-30 00:43:48 +0000183#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +0000184static int sax1 = 0;
Daniel Veillard81273902003-09-30 00:43:48 +0000185#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000186#ifdef LIBXML_PATTERN_ENABLED
187static const char *pattern = NULL;
188static xmlPatternPtr patternc = NULL;
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000189static xmlStreamCtxtPtr patstream = NULL;
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000190#endif
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000191static int options = 0;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000192
Daniel Veillard87076042004-05-03 22:54:49 +0000193/************************************************************************
Daniel Veillard0bff36d2004-08-31 09:37:03 +0000194 * *
195 * Entity loading control and customization. *
196 * *
197 ************************************************************************/
198#define MAX_PATHS 64
199static xmlChar *paths[MAX_PATHS + 1];
200static int nbpaths = 0;
201static int load_trace = 0;
202
203static
204void parsePath(const xmlChar *path) {
205 const xmlChar *cur;
206
207 if (path == NULL)
208 return;
209 while (*path != 0) {
210 if (nbpaths >= MAX_PATHS) {
211 fprintf(stderr, "MAX_PATHS reached: too many paths\n");
212 return;
213 }
214 cur = path;
215 while ((*cur == ' ') || (*cur == ':'))
216 cur++;
217 path = cur;
218 while ((*cur != 0) && (*cur != ' ') && (*cur != ':'))
219 cur++;
220 if (cur != path) {
221 paths[nbpaths] = xmlStrndup(path, cur - path);
222 if (paths[nbpaths] != NULL)
223 nbpaths++;
224 path = cur;
225 }
226 }
227}
228
229xmlExternalEntityLoader defaultEntityLoader = NULL;
230
231static xmlParserInputPtr
232xmllintExternalEntityLoader(const char *URL, const char *ID,
233 xmlParserCtxtPtr ctxt) {
234 xmlParserInputPtr ret;
235 warningSAXFunc warning = NULL;
236
237 int i;
238 const char *lastsegment = URL;
239 const char *iter = URL;
240
241 if (nbpaths > 0) {
242 while (*iter != 0) {
243 if (*iter == '/')
244 lastsegment = iter + 1;
245 iter++;
246 }
247 }
248
249 if ((ctxt != NULL) && (ctxt->sax != NULL)) {
250 warning = ctxt->sax->warning;
251 ctxt->sax->warning = NULL;
252 }
253
254 if (defaultEntityLoader != NULL) {
255 ret = defaultEntityLoader(URL, ID, ctxt);
256 if (ret != NULL) {
257 if (warning != NULL)
258 ctxt->sax->warning = warning;
259 if (load_trace) {
260 fprintf \
261 (stderr,
262 "Loaded URL=\"%s\" ID=\"%s\"\n",
263 URL ? URL : "(null)",
264 ID ? ID : "(null)");
265 }
266 return(ret);
267 }
268 }
269 for (i = 0;i < nbpaths;i++) {
270 xmlChar *newURL;
271
272 newURL = xmlStrdup((const xmlChar *) paths[i]);
273 newURL = xmlStrcat(newURL, (const xmlChar *) "/");
274 newURL = xmlStrcat(newURL, (const xmlChar *) lastsegment);
275 if (newURL != NULL) {
276 ret = defaultEntityLoader((const char *)newURL, ID, ctxt);
277 if (ret != NULL) {
278 if (warning != NULL)
279 ctxt->sax->warning = warning;
280 if (load_trace) {
281 fprintf \
282 (stderr,
283 "Loaded URL=\"%s\" ID=\"%s\"\n",
284 newURL,
285 ID ? ID : "(null)");
286 }
287 xmlFree(newURL);
288 return(ret);
289 }
290 xmlFree(newURL);
291 }
292 }
293 if (warning != NULL) {
294 ctxt->sax->warning = warning;
295 if (URL != NULL)
296 warning(ctxt, "failed to load external entity \"%s\"\n", URL);
297 else if (ID != NULL)
298 warning(ctxt, "failed to load external entity \"%s\"\n", ID);
299 }
300 return(NULL);
301}
302/************************************************************************
Daniel Veillard87076042004-05-03 22:54:49 +0000303 * *
304 * Memory allocation consumption debugging *
305 * *
306 ************************************************************************/
307
Daniel Veillard3af3b592004-05-05 19:22:30 +0000308static void
309OOM(void)
310{
Daniel Veillard87076042004-05-03 22:54:49 +0000311 fprintf(stderr, "Ran out of memory needs > %d bytes\n", maxmem);
William M. Brack8304d872004-06-08 13:29:32 +0000312 progresult = XMLLINT_ERR_MEM;
Daniel Veillard87076042004-05-03 22:54:49 +0000313}
314
Daniel Veillard3af3b592004-05-05 19:22:30 +0000315static void
316myFreeFunc(void *mem)
317{
Daniel Veillard87076042004-05-03 22:54:49 +0000318 xmlMemFree(mem);
319}
Daniel Veillard3af3b592004-05-05 19:22:30 +0000320static void *
321myMallocFunc(size_t size)
322{
Daniel Veillard87076042004-05-03 22:54:49 +0000323 void *ret;
324
325 ret = xmlMemMalloc(size);
326 if (ret != NULL) {
327 if (xmlMemUsed() > maxmem) {
Daniel Veillard3af3b592004-05-05 19:22:30 +0000328 OOM();
329 xmlMemFree(ret);
330 return (NULL);
331 }
Daniel Veillard87076042004-05-03 22:54:49 +0000332 }
Daniel Veillard3af3b592004-05-05 19:22:30 +0000333 return (ret);
Daniel Veillard87076042004-05-03 22:54:49 +0000334}
Daniel Veillard3af3b592004-05-05 19:22:30 +0000335static void *
336myReallocFunc(void *mem, size_t size)
337{
Daniel Veillard87076042004-05-03 22:54:49 +0000338 void *ret;
339
340 ret = xmlMemRealloc(mem, size);
341 if (ret != NULL) {
342 if (xmlMemUsed() > maxmem) {
Daniel Veillard3af3b592004-05-05 19:22:30 +0000343 OOM();
344 xmlMemFree(ret);
345 return (NULL);
346 }
Daniel Veillard87076042004-05-03 22:54:49 +0000347 }
Daniel Veillard3af3b592004-05-05 19:22:30 +0000348 return (ret);
Daniel Veillard87076042004-05-03 22:54:49 +0000349}
Daniel Veillard3af3b592004-05-05 19:22:30 +0000350static char *
351myStrdupFunc(const char *str)
352{
Daniel Veillard87076042004-05-03 22:54:49 +0000353 char *ret;
354
355 ret = xmlMemoryStrdup(str);
356 if (ret != NULL) {
357 if (xmlMemUsed() > maxmem) {
Daniel Veillard3af3b592004-05-05 19:22:30 +0000358 OOM();
359 xmlFree(ret);
360 return (NULL);
361 }
Daniel Veillard87076042004-05-03 22:54:49 +0000362 }
Daniel Veillard3af3b592004-05-05 19:22:30 +0000363 return (ret);
Daniel Veillard87076042004-05-03 22:54:49 +0000364}
Daniel Veillard87076042004-05-03 22:54:49 +0000365/************************************************************************
366 * *
367 * Internal timing routines to remove the necessity to have *
368 * unix-specific function calls. *
369 * *
370 ************************************************************************/
Daniel Veillard01db67c2001-12-18 07:09:59 +0000371
Daniel Veillard8c1ae602002-03-07 11:21:00 +0000372#ifndef HAVE_GETTIMEOFDAY
373#ifdef HAVE_SYS_TIMEB_H
374#ifdef HAVE_SYS_TIME_H
375#ifdef HAVE_FTIME
376
Daniel Veillard01c13b52002-12-10 15:19:08 +0000377static int
Daniel Veillard8c1ae602002-03-07 11:21:00 +0000378my_gettimeofday(struct timeval *tvp, void *tzp)
379{
380 struct timeb timebuffer;
381
382 ftime(&timebuffer);
383 if (tvp) {
384 tvp->tv_sec = timebuffer.time;
385 tvp->tv_usec = timebuffer.millitm * 1000L;
386 }
387 return (0);
388}
389#define HAVE_GETTIMEOFDAY 1
390#define gettimeofday my_gettimeofday
391
392#endif /* HAVE_FTIME */
393#endif /* HAVE_SYS_TIME_H */
394#endif /* HAVE_SYS_TIMEB_H */
395#endif /* !HAVE_GETTIMEOFDAY */
396
Daniel Veillard01db67c2001-12-18 07:09:59 +0000397#if defined(HAVE_GETTIMEOFDAY)
398static struct timeval begin, end;
399
400/*
401 * startTimer: call where you want to start timing
402 */
403static void
404startTimer(void)
405{
406 gettimeofday(&begin, NULL);
407}
408
409/*
410 * endTimer: call where you want to stop timing and to print out a
411 * message about the timing performed; format is a printf
412 * type argument
413 */
414static void
Daniel Veillard118aed72002-09-24 14:13:13 +0000415endTimer(const char *fmt, ...)
Daniel Veillard01db67c2001-12-18 07:09:59 +0000416{
417 long msec;
418 va_list ap;
419
420 gettimeofday(&end, NULL);
421 msec = end.tv_sec - begin.tv_sec;
422 msec *= 1000;
423 msec += (end.tv_usec - begin.tv_usec) / 1000;
424
425#ifndef HAVE_STDARG_H
426#error "endTimer required stdarg functions"
427#endif
Daniel Veillard118aed72002-09-24 14:13:13 +0000428 va_start(ap, fmt);
429 vfprintf(stderr, fmt, ap);
Daniel Veillard01db67c2001-12-18 07:09:59 +0000430 va_end(ap);
431
432 fprintf(stderr, " took %ld ms\n", msec);
433}
434#elif defined(HAVE_TIME_H)
Daniel Veillard01db67c2001-12-18 07:09:59 +0000435/*
436 * No gettimeofday function, so we have to make do with calling clock.
437 * This is obviously less accurate, but there's little we can do about
438 * that.
439 */
Daniel Veillard90bc3712002-03-07 15:12:58 +0000440#ifndef CLOCKS_PER_SEC
441#define CLOCKS_PER_SEC 100
442#endif
Daniel Veillard01db67c2001-12-18 07:09:59 +0000443
444static clock_t begin, end;
445static void
446startTimer(void)
447{
448 begin = clock();
449}
450static void
451endTimer(const char *fmt, ...)
452{
453 long msec;
454 va_list ap;
455
456 end = clock();
457 msec = ((end - begin) * 1000) / CLOCKS_PER_SEC;
458
459#ifndef HAVE_STDARG_H
460#error "endTimer required stdarg functions"
461#endif
462 va_start(ap, fmt);
463 vfprintf(stderr, fmt, ap);
464 va_end(ap);
465 fprintf(stderr, " took %ld ms\n", msec);
466}
467#else
468
469/*
470 * We don't have a gettimeofday or time.h, so we just don't do timing
471 */
472static void
473startTimer(void)
474{
475 /*
476 * Do nothing
477 */
478}
479static void
480endTimer(char *format, ...)
481{
482 /*
483 * We cannot do anything because we don't have a timing function
484 */
485#ifdef HAVE_STDARG_H
486 va_start(ap, format);
487 vfprintf(stderr, format, ap);
488 va_end(ap);
489 fprintf(stderr, " was not timed\n", msec);
490#else
491 /* We don't have gettimeofday, time or stdarg.h, what crazy world is
492 * this ?!
493 */
494#endif
495}
496#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000497/************************************************************************
498 * *
499 * HTML ouput *
500 * *
501 ************************************************************************/
502char buffer[50000];
503
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000504static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000505xmlHTMLEncodeSend(void) {
506 char *result;
507
508 result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
509 if (result) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000510 xmlGenericError(xmlGenericErrorContext, "%s", result);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000511 xmlFree(result);
512 }
513 buffer[0] = 0;
514}
515
516/**
517 * xmlHTMLPrintFileInfo:
518 * @input: an xmlParserInputPtr input
519 *
520 * Displays the associated file and line informations for the current input
521 */
522
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000523static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000524xmlHTMLPrintFileInfo(xmlParserInputPtr input) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000525 int len;
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000526 xmlGenericError(xmlGenericErrorContext, "<p>");
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000527
528 len = strlen(buffer);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000529 if (input != NULL) {
530 if (input->filename) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000531 snprintf(&buffer[len], sizeof(buffer) - len, "%s:%d: ", input->filename,
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000532 input->line);
533 } else {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000534 snprintf(&buffer[len], sizeof(buffer) - len, "Entity: line %d: ", input->line);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000535 }
536 }
537 xmlHTMLEncodeSend();
538}
539
540/**
541 * xmlHTMLPrintFileContext:
542 * @input: an xmlParserInputPtr input
543 *
544 * Displays current context within the input content for error tracking
545 */
546
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000547static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000548xmlHTMLPrintFileContext(xmlParserInputPtr input) {
549 const xmlChar *cur, *base;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000550 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000551 int n;
552
553 if (input == NULL) return;
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000554 xmlGenericError(xmlGenericErrorContext, "<pre>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000555 cur = input->cur;
556 base = input->base;
557 while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
558 cur--;
559 }
560 n = 0;
561 while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
562 cur--;
563 if ((*cur == '\n') || (*cur == '\r')) cur++;
564 base = cur;
565 n = 0;
566 while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000567 len = strlen(buffer);
568 snprintf(&buffer[len], sizeof(buffer) - len, "%c",
569 (unsigned char) *cur++);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000570 n++;
571 }
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000572 len = strlen(buffer);
573 snprintf(&buffer[len], sizeof(buffer) - len, "\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000574 cur = input->cur;
575 while ((*cur == '\n') || (*cur == '\r'))
576 cur--;
577 n = 0;
578 while ((cur != base) && (n++ < 80)) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000579 len = strlen(buffer);
580 snprintf(&buffer[len], sizeof(buffer) - len, " ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000581 base++;
582 }
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000583 len = strlen(buffer);
584 snprintf(&buffer[len], sizeof(buffer) - len, "^\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000585 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000586 xmlGenericError(xmlGenericErrorContext, "</pre>");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000587}
588
589/**
590 * xmlHTMLError:
591 * @ctx: an XML parser context
592 * @msg: the message to display/transmit
593 * @...: extra parameters for the message display
594 *
595 * Display and format an error messages, gives file, line, position and
596 * extra parameters.
597 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000598static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000599xmlHTMLError(void *ctx, const char *msg, ...)
600{
601 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
602 xmlParserInputPtr input;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000603 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000604 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000605
606 buffer[0] = 0;
607 input = ctxt->input;
608 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000609 input = ctxt->inputTab[ctxt->inputNr - 2];
610 }
611
612 xmlHTMLPrintFileInfo(input);
613
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000614 xmlGenericError(xmlGenericErrorContext, "<b>error</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000615 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000616 len = strlen(buffer);
617 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000618 va_end(args);
619 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000620 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000621
622 xmlHTMLPrintFileContext(input);
623 xmlHTMLEncodeSend();
624}
625
626/**
627 * xmlHTMLWarning:
628 * @ctx: an XML parser context
629 * @msg: the message to display/transmit
630 * @...: extra parameters for the message display
631 *
632 * Display and format a warning messages, gives file, line, position and
633 * extra parameters.
634 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000635static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000636xmlHTMLWarning(void *ctx, const char *msg, ...)
637{
638 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
639 xmlParserInputPtr input;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000640 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000641 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000642
643 buffer[0] = 0;
644 input = ctxt->input;
645 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000646 input = ctxt->inputTab[ctxt->inputNr - 2];
647 }
648
649
650 xmlHTMLPrintFileInfo(input);
651
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000652 xmlGenericError(xmlGenericErrorContext, "<b>warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000653 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000654 len = strlen(buffer);
655 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000656 va_end(args);
657 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000658 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000659
660 xmlHTMLPrintFileContext(input);
661 xmlHTMLEncodeSend();
662}
663
664/**
665 * xmlHTMLValidityError:
666 * @ctx: an XML parser context
667 * @msg: the message to display/transmit
668 * @...: extra parameters for the message display
669 *
670 * Display and format an validity error messages, gives file,
671 * line, position and extra parameters.
672 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000673static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000674xmlHTMLValidityError(void *ctx, const char *msg, ...)
675{
676 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
677 xmlParserInputPtr input;
678 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000679 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000680
681 buffer[0] = 0;
682 input = ctxt->input;
683 if ((input->filename == NULL) && (ctxt->inputNr > 1))
684 input = ctxt->inputTab[ctxt->inputNr - 2];
685
686 xmlHTMLPrintFileInfo(input);
687
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000688 xmlGenericError(xmlGenericErrorContext, "<b>validity error</b>: ");
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000689 len = strlen(buffer);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000690 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000691 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000692 va_end(args);
693 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000694 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000695
696 xmlHTMLPrintFileContext(input);
697 xmlHTMLEncodeSend();
Daniel Veillard9fcb4912005-03-16 12:57:31 +0000698 progresult = XMLLINT_ERR_VALID;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000699}
700
701/**
702 * xmlHTMLValidityWarning:
703 * @ctx: an XML parser context
704 * @msg: the message to display/transmit
705 * @...: extra parameters for the message display
706 *
707 * Display and format a validity warning messages, gives file, line,
708 * position and extra parameters.
709 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000710static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000711xmlHTMLValidityWarning(void *ctx, const char *msg, ...)
712{
713 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
714 xmlParserInputPtr input;
715 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000716 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000717
718 buffer[0] = 0;
719 input = ctxt->input;
720 if ((input->filename == NULL) && (ctxt->inputNr > 1))
721 input = ctxt->inputTab[ctxt->inputNr - 2];
722
723 xmlHTMLPrintFileInfo(input);
724
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000725 xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000726 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000727 len = strlen(buffer);
728 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000729 va_end(args);
730 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000731 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000732
733 xmlHTMLPrintFileContext(input);
734 xmlHTMLEncodeSend();
735}
736
737/************************************************************************
738 * *
739 * Shell Interface *
740 * *
741 ************************************************************************/
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000742#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardd0cf7f62004-11-09 16:17:02 +0000743#ifdef LIBXML_XPATH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000744/**
745 * xmlShellReadline:
746 * @prompt: the prompt value
747 *
748 * Read a string
749 *
750 * Returns a pointer to it or NULL on EOF the caller is expected to
751 * free the returned string.
752 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000753static char *
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000754xmlShellReadline(char *prompt) {
755#ifdef HAVE_LIBREADLINE
756 char *line_read;
757
758 /* Get a line from the user. */
759 line_read = readline (prompt);
760
761 /* If the line has any text in it, save it on the history. */
762 if (line_read && *line_read)
763 add_history (line_read);
764
765 return (line_read);
766#else
767 char line_read[501];
Daniel Veillard29e43992001-12-13 22:21:58 +0000768 char *ret;
769 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000770
771 if (prompt != NULL)
772 fprintf(stdout, "%s", prompt);
773 if (!fgets(line_read, 500, stdin))
774 return(NULL);
775 line_read[500] = 0;
Daniel Veillard29e43992001-12-13 22:21:58 +0000776 len = strlen(line_read);
777 ret = (char *) malloc(len + 1);
778 if (ret != NULL) {
779 memcpy (ret, line_read, len + 1);
780 }
781 return(ret);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000782#endif
783}
Daniel Veillardd0cf7f62004-11-09 16:17:02 +0000784#endif /* LIBXML_XPATH_ENABLED */
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000785#endif /* LIBXML_DEBUG_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000786
787/************************************************************************
788 * *
Daniel Veillard5e873c42000-04-12 13:27:38 +0000789 * I/O Interfaces *
790 * *
791 ************************************************************************/
792
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000793static int myRead(FILE *f, char * buf, int len) {
794 return(fread(buf, 1, len, f));
Daniel Veillard5e873c42000-04-12 13:27:38 +0000795}
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000796static void myClose(FILE *f) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000797 if (f != stdin) {
Daniel Veillard5e873c42000-04-12 13:27:38 +0000798 fclose(f);
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000799 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000800}
801
Daniel Veillard81273902003-09-30 00:43:48 +0000802#ifdef LIBXML_READER_ENABLED
Daniel Veillard5e873c42000-04-12 13:27:38 +0000803/************************************************************************
804 * *
Daniel Veillard7704fb12003-01-03 16:19:51 +0000805 * Stream Test processing *
806 * *
807 ************************************************************************/
Daniel Veillard7704fb12003-01-03 16:19:51 +0000808static void processNode(xmlTextReaderPtr reader) {
Daniel Veillard198c1bf2003-10-20 17:07:41 +0000809 const xmlChar *name, *value;
Daniel Veillard16ef8002005-01-31 00:27:50 +0000810 int type, empty;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000811
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000812 type = xmlTextReaderNodeType(reader);
Daniel Veillard16ef8002005-01-31 00:27:50 +0000813 empty = xmlTextReaderIsEmptyElement(reader);
Daniel Veillard99737f52003-03-22 14:55:50 +0000814
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000815 if (debug) {
816 name = xmlTextReaderConstName(reader);
817 if (name == NULL)
818 name = BAD_CAST "--";
Daniel Veillard7704fb12003-01-03 16:19:51 +0000819
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000820 value = xmlTextReaderConstValue(reader);
821
822
823 printf("%d %d %s %d %d",
824 xmlTextReaderDepth(reader),
825 type,
826 name,
Daniel Veillard16ef8002005-01-31 00:27:50 +0000827 empty,
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000828 xmlTextReaderHasValue(reader));
829 if (value == NULL)
830 printf("\n");
831 else {
832 printf(" %s\n", value);
833 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000834 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000835#ifdef LIBXML_PATTERN_ENABLED
836 if (patternc) {
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000837 xmlChar *path = NULL;
838 int match = -1;
839
840 if (type == XML_READER_TYPE_ELEMENT) {
841 /* do the check only on element start */
842 match = xmlPatternMatch(patternc, xmlTextReaderCurrentNode(reader));
843
844 if (match) {
845 path = xmlGetNodePath(xmlTextReaderCurrentNode(reader));
846 printf("Node %s matches pattern %s\n", path, pattern);
847 }
848 }
849 if (patstream != NULL) {
850 int ret;
851
852 if (type == XML_READER_TYPE_ELEMENT) {
853 ret = xmlStreamPush(patstream,
854 xmlTextReaderConstLocalName(reader),
855 xmlTextReaderConstNamespaceUri(reader));
856 if (ret < 0) {
857 fprintf(stderr, "xmlStreamPush() failure\n");
858 xmlFreeStreamCtxt(patstream);
859 patstream = NULL;
860 } else if (ret != match) {
861 if (path == NULL) {
862 path = xmlGetNodePath(
863 xmlTextReaderCurrentNode(reader));
864 }
865 fprintf(stderr,
866 "xmlPatternMatch and xmlStreamPush disagree\n");
867 fprintf(stderr,
868 " pattern %s node %s\n",
869 pattern, path);
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000870 }
871
872
Daniel Veillard16ef8002005-01-31 00:27:50 +0000873 }
874 if ((type == XML_READER_TYPE_END_ELEMENT) ||
875 ((type == XML_READER_TYPE_ELEMENT) && (empty))) {
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000876 ret = xmlStreamPop(patstream);
877 if (ret < 0) {
878 fprintf(stderr, "xmlStreamPop() failure\n");
879 xmlFreeStreamCtxt(patstream);
880 patstream = NULL;
881 }
882 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000883 }
Daniel Veillardf9d16912005-01-30 22:36:30 +0000884 if (path != NULL)
885 xmlFree(path);
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000886 }
887#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000888}
889
890static void streamFile(char *filename) {
891 xmlTextReaderPtr reader;
892 int ret;
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000893#ifdef HAVE_SYS_MMAN_H
894 int fd = -1;
895 struct stat info;
896 const char *base = NULL;
897 xmlParserInputBufferPtr input = NULL;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000898
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000899 if (memory) {
900 if (stat(filename, &info) < 0)
901 return;
902 if ((fd = open(filename, O_RDONLY)) < 0)
903 return;
904 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
905 if (base == (void *) MAP_FAILED)
906 return;
907
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000908 reader = xmlReaderForMemory(base, info.st_size, filename,
909 NULL, options);
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000910 } else
911#endif
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000912 reader = xmlReaderForFile(filename, NULL, options);
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000913#ifdef LIBXML_PATTERN_ENABLED
Daniel Veillardd4301ab2005-02-03 22:24:10 +0000914 if (pattern != NULL) {
915 patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL);
916 if (patternc == NULL) {
917 xmlGenericError(xmlGenericErrorContext,
918 "Pattern %s failed to compile\n", pattern);
919 progresult = XMLLINT_ERR_SCHEMAPAT;
920 pattern = NULL;
921 }
922 }
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000923 if (patternc != NULL) {
924 patstream = xmlPatternGetStreamCtxt(patternc);
925 if (patstream != NULL) {
926 ret = xmlStreamPush(patstream, NULL, NULL);
927 if (ret < 0) {
928 fprintf(stderr, "xmlStreamPush() failure\n");
929 xmlFreeStreamCtxt(patstream);
930 patstream = NULL;
931 }
932 }
933 }
934#endif
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000935
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000936
Daniel Veillard7704fb12003-01-03 16:19:51 +0000937 if (reader != NULL) {
Daniel Veillard4432df22003-09-28 18:58:27 +0000938#ifdef LIBXML_VALID_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +0000939 if (valid)
940 xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);
Daniel Veillardce192eb2003-04-16 15:58:05 +0000941 else
Daniel Veillard4432df22003-09-28 18:58:27 +0000942#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardce192eb2003-04-16 15:58:05 +0000943 xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1);
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000944#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardce192eb2003-04-16 15:58:05 +0000945 if (relaxng != NULL) {
Daniel Veillard81514ba2003-09-16 23:17:26 +0000946 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000947 startTimer();
948 }
949 ret = xmlTextReaderRelaxNGValidate(reader, relaxng);
950 if (ret < 0) {
951 xmlGenericError(xmlGenericErrorContext,
952 "Relax-NG schema %s failed to compile\n", relaxng);
William M. Brack8304d872004-06-08 13:29:32 +0000953 progresult = XMLLINT_ERR_SCHEMACOMP;
Daniel Veillardce192eb2003-04-16 15:58:05 +0000954 relaxng = NULL;
955 }
Daniel Veillard81514ba2003-09-16 23:17:26 +0000956 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000957 endTimer("Compiling the schemas");
958 }
959 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000960#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000961
962 /*
963 * Process all nodes in sequence
964 */
Daniel Veillard81514ba2003-09-16 23:17:26 +0000965 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000966 startTimer();
967 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000968 ret = xmlTextReaderRead(reader);
969 while (ret == 1) {
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000970 if ((debug)
971#ifdef LIBXML_PATTERN_ENABLED
972 || (patternc)
973#endif
974 )
Daniel Veillard7704fb12003-01-03 16:19:51 +0000975 processNode(reader);
976 ret = xmlTextReaderRead(reader);
977 }
Daniel Veillard81514ba2003-09-16 23:17:26 +0000978 if ((timing) && (!repeat)) {
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000979#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardf54cd532004-02-25 11:52:31 +0000980 if (relaxng != NULL)
Daniel Veillard49138f12004-02-19 12:58:36 +0000981 endTimer("Parsing and validating");
982 else
Daniel Veillardf54cd532004-02-25 11:52:31 +0000983#endif
Daniel Veillard4432df22003-09-28 18:58:27 +0000984#ifdef LIBXML_VALID_ENABLED
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000985 if (valid)
Daniel Veillardce192eb2003-04-16 15:58:05 +0000986 endTimer("Parsing and validating");
987 else
Daniel Veillard4432df22003-09-28 18:58:27 +0000988#endif
Daniel Veillardf54cd532004-02-25 11:52:31 +0000989 endTimer("Parsing");
Daniel Veillardce192eb2003-04-16 15:58:05 +0000990 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000991
Daniel Veillard4432df22003-09-28 18:58:27 +0000992#ifdef LIBXML_VALID_ENABLED
Daniel Veillardf6bad792003-04-11 19:38:54 +0000993 if (valid) {
994 if (xmlTextReaderIsValid(reader) != 1) {
995 xmlGenericError(xmlGenericErrorContext,
996 "Document %s does not validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +0000997 progresult = XMLLINT_ERR_VALID;
Daniel Veillardf6bad792003-04-11 19:38:54 +0000998 }
999 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001000#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard37fc84d2003-05-09 19:38:15 +00001001#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardf4e55762003-04-15 23:32:22 +00001002 if (relaxng != NULL) {
1003 if (xmlTextReaderIsValid(reader) != 1) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001004 fprintf(stderr, "%s fails to validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001005 progresult = XMLLINT_ERR_VALID;
Daniel Veillardf4e55762003-04-15 23:32:22 +00001006 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001007 fprintf(stderr, "%s validates\n", filename);
Daniel Veillardf4e55762003-04-15 23:32:22 +00001008 }
1009 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +00001010#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +00001011 /*
1012 * Done, cleanup and status
1013 */
1014 xmlFreeTextReader(reader);
1015 if (ret != 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001016 fprintf(stderr, "%s : failed to parse\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001017 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7704fb12003-01-03 16:19:51 +00001018 }
1019 } else {
1020 fprintf(stderr, "Unable to open %s\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001021 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7704fb12003-01-03 16:19:51 +00001022 }
Daniel Veillard2fc6df92005-01-30 18:42:55 +00001023#ifdef LIBXML_PATTERN_ENABLED
1024 if (patstream != NULL) {
1025 xmlFreeStreamCtxt(patstream);
1026 patstream = NULL;
1027 }
1028#endif
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00001029#ifdef HAVE_SYS_MMAN_H
1030 if (memory) {
1031 xmlFreeParserInputBuffer(input);
1032 munmap((char *) base, info.st_size);
1033 close(fd);
1034 }
1035#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +00001036}
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001037
1038static void walkDoc(xmlDocPtr doc) {
1039 xmlTextReaderPtr reader;
1040 int ret;
1041
Daniel Veillardd4301ab2005-02-03 22:24:10 +00001042#ifdef LIBXML_PATTERN_ENABLED
1043 xmlNodePtr root;
1044 const xmlChar *namespaces[22];
1045 int i;
1046 xmlNsPtr ns;
1047
1048 root = xmlDocGetRootElement(doc);
1049 for (ns = root->nsDef, i = 0;ns != NULL && i < 20;ns=ns->next) {
1050 namespaces[i++] = ns->href;
1051 namespaces[i++] = ns->prefix;
1052 }
1053 namespaces[i++] = NULL;
1054 namespaces[i++] = NULL;
1055
1056 if (pattern != NULL) {
1057 patternc = xmlPatterncompile((const xmlChar *) pattern, doc->dict,
1058 0, &namespaces[0]);
1059 if (patternc == NULL) {
1060 xmlGenericError(xmlGenericErrorContext,
1061 "Pattern %s failed to compile\n", pattern);
1062 progresult = XMLLINT_ERR_SCHEMAPAT;
1063 pattern = NULL;
1064 }
1065 }
Daniel Veillard2b2e02d2005-02-05 23:20:22 +00001066 if (patternc != NULL) {
1067 patstream = xmlPatternGetStreamCtxt(patternc);
1068 if (patstream != NULL) {
1069 ret = xmlStreamPush(patstream, NULL, NULL);
1070 if (ret < 0) {
1071 fprintf(stderr, "xmlStreamPush() failure\n");
1072 xmlFreeStreamCtxt(patstream);
1073 patstream = NULL;
1074 }
1075 }
1076 }
Daniel Veillardd4301ab2005-02-03 22:24:10 +00001077#endif /* LIBXML_PATTERN_ENABLED */
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001078 reader = xmlReaderWalker(doc);
1079 if (reader != NULL) {
1080 if ((timing) && (!repeat)) {
1081 startTimer();
1082 }
1083 ret = xmlTextReaderRead(reader);
1084 while (ret == 1) {
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001085 if ((debug)
1086#ifdef LIBXML_PATTERN_ENABLED
1087 || (patternc)
1088#endif
1089 )
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001090 processNode(reader);
1091 ret = xmlTextReaderRead(reader);
1092 }
1093 if ((timing) && (!repeat)) {
1094 endTimer("walking through the doc");
1095 }
1096 xmlFreeTextReader(reader);
1097 if (ret != 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001098 fprintf(stderr, "failed to walk through the doc\n");
William M. Brack8304d872004-06-08 13:29:32 +00001099 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001100 }
1101 } else {
1102 fprintf(stderr, "Failed to crate a reader from the document\n");
William M. Brack8304d872004-06-08 13:29:32 +00001103 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001104 }
Daniel Veillard2b2e02d2005-02-05 23:20:22 +00001105#ifdef LIBXML_PATTERN_ENABLED
1106 if (patstream != NULL) {
1107 xmlFreeStreamCtxt(patstream);
1108 patstream = NULL;
1109 }
1110#endif
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001111}
Daniel Veillard81273902003-09-30 00:43:48 +00001112#endif /* LIBXML_READER_ENABLED */
Daniel Veillard7704fb12003-01-03 16:19:51 +00001113
1114/************************************************************************
1115 * *
1116 * Tree Test processing *
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001117 * *
1118 ************************************************************************/
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001119static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
Daniel Veillard652327a2003-09-29 18:02:38 +00001120 xmlDocPtr doc = NULL;
1121#ifdef LIBXML_TREE_ENABLED
1122 xmlDocPtr tmp;
1123#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001124
Daniel Veillard48b2f892001-02-25 16:11:03 +00001125 if ((timing) && (!repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +00001126 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001127
1128
Daniel Veillard652327a2003-09-29 18:02:38 +00001129#ifdef LIBXML_TREE_ENABLED
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001130 if (filename == NULL) {
1131 if (generate) {
1132 xmlNodePtr n;
1133
1134 doc = xmlNewDoc(BAD_CAST "1.0");
Daniel Veillard95ddcd32004-10-26 21:53:55 +00001135 n = xmlNewDocNode(doc, NULL, BAD_CAST "info", NULL);
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001136 xmlNodeSetContent(n, BAD_CAST "abc");
1137 xmlDocSetRootElement(doc, n);
1138 }
1139 }
Daniel Veillard652327a2003-09-29 18:02:38 +00001140#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001141#ifdef LIBXML_HTML_ENABLED
Daniel Veillard73b013f2003-09-30 12:36:01 +00001142#ifdef LIBXML_PUSH_ENABLED
William M. Brack78637da2003-07-31 14:47:38 +00001143 else if ((html) && (push)) {
1144 FILE *f;
1145
William M. Brack3403add2004-06-27 02:07:51 +00001146#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
1147 f = fopen(filename, "rb");
1148#else
1149 f = fopen(filename, "r");
1150#endif
William M. Brack78637da2003-07-31 14:47:38 +00001151 if (f != NULL) {
1152 int res, size = 3;
1153 char chars[4096];
1154 htmlParserCtxtPtr ctxt;
1155
1156 /* if (repeat) */
1157 size = 4096;
1158 res = fread(chars, 1, 4, f);
1159 if (res > 0) {
1160 ctxt = htmlCreatePushParserCtxt(NULL, NULL,
William M. Brack1d75c8a2003-10-27 13:48:16 +00001161 chars, res, filename, XML_CHAR_ENCODING_NONE);
William M. Brack78637da2003-07-31 14:47:38 +00001162 while ((res = fread(chars, 1, size, f)) > 0) {
1163 htmlParseChunk(ctxt, chars, res, 0);
1164 }
1165 htmlParseChunk(ctxt, chars, 0, 1);
1166 doc = ctxt->myDoc;
1167 htmlFreeParserCtxt(ctxt);
1168 }
1169 fclose(f);
1170 }
1171 }
Daniel Veillard73b013f2003-09-30 12:36:01 +00001172#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001173 else if (html) {
Daniel Veillard9475a352003-09-26 12:47:50 +00001174 doc = htmlReadFile(filename, NULL, options);
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001175 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001176#endif /* LIBXML_HTML_ENABLED */
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001177 else {
Daniel Veillard73b013f2003-09-30 12:36:01 +00001178#ifdef LIBXML_PUSH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001179 /*
1180 * build an XML tree from a string;
1181 */
1182 if (push) {
1183 FILE *f;
1184
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001185 /* '-' Usually means stdin -<sven@zen.org> */
1186 if ((filename[0] == '-') && (filename[1] == 0)) {
1187 f = stdin;
1188 } else {
William M. Brack3403add2004-06-27 02:07:51 +00001189#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
1190 f = fopen(filename, "rb");
1191#else
1192 f = fopen(filename, "r");
1193#endif
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001194 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001195 if (f != NULL) {
Daniel Veillarde715dd22000-08-29 18:29:38 +00001196 int ret;
Daniel Veillarda880b122003-04-21 21:36:41 +00001197 int res, size = 1024;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001198 char chars[1024];
1199 xmlParserCtxtPtr ctxt;
1200
Daniel Veillarda880b122003-04-21 21:36:41 +00001201 /* if (repeat) size = 1024; */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001202 res = fread(chars, 1, 4, f);
1203 if (res > 0) {
1204 ctxt = xmlCreatePushParserCtxt(NULL, NULL,
1205 chars, res, filename);
Daniel Veillard500a1de2004-03-22 15:22:58 +00001206 xmlCtxtUseOptions(ctxt, options);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001207 while ((res = fread(chars, 1, size, f)) > 0) {
1208 xmlParseChunk(ctxt, chars, res, 0);
1209 }
1210 xmlParseChunk(ctxt, chars, 0, 1);
1211 doc = ctxt->myDoc;
Daniel Veillarde715dd22000-08-29 18:29:38 +00001212 ret = ctxt->wellFormed;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001213 xmlFreeParserCtxt(ctxt);
Daniel Veillarde715dd22000-08-29 18:29:38 +00001214 if (!ret) {
1215 xmlFreeDoc(doc);
1216 doc = NULL;
1217 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001218 }
1219 }
Daniel Veillard73b013f2003-09-30 12:36:01 +00001220 } else
1221#endif /* LIBXML_PUSH_ENABLED */
1222 if (testIO) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001223 if ((filename[0] == '-') && (filename[1] == 0)) {
Daniel Veillard60942de2003-09-25 21:05:58 +00001224 doc = xmlReadFd(0, NULL, NULL, options);
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001225 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001226 FILE *f;
Daniel Veillard5e873c42000-04-12 13:27:38 +00001227
William M. Brack3403add2004-06-27 02:07:51 +00001228#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
1229 f = fopen(filename, "rb");
1230#else
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001231 f = fopen(filename, "r");
William M. Brack3403add2004-06-27 02:07:51 +00001232#endif
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001233 if (f != NULL) {
1234 if (rectxt == NULL)
1235 doc = xmlReadIO((xmlInputReadCallback) myRead,
1236 (xmlInputCloseCallback) myClose, f,
Daniel Veillard60942de2003-09-25 21:05:58 +00001237 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001238 else
1239 doc = xmlCtxtReadIO(rectxt,
1240 (xmlInputReadCallback) myRead,
1241 (xmlInputCloseCallback) myClose, f,
Daniel Veillard60942de2003-09-25 21:05:58 +00001242 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001243 } else
Daniel Veillard5e873c42000-04-12 13:27:38 +00001244 doc = NULL;
Daniel Veillard5e873c42000-04-12 13:27:38 +00001245 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001246 } else if (htmlout) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001247 xmlParserCtxtPtr ctxt;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001248
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001249 if (rectxt == NULL)
1250 ctxt = xmlNewParserCtxt();
1251 else
1252 ctxt = rectxt;
Daniel Veillard88a172f2000-08-04 18:23:10 +00001253 if (ctxt == NULL) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001254 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +00001255 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001256 ctxt->sax->error = xmlHTMLError;
1257 ctxt->sax->warning = xmlHTMLWarning;
1258 ctxt->vctxt.error = xmlHTMLValidityError;
1259 ctxt->vctxt.warning = xmlHTMLValidityWarning;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001260
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001261 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001262
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001263 if (rectxt == NULL)
1264 xmlFreeParserCtxt(ctxt);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001265 }
Daniel Veillard46e370e2000-07-21 20:32:03 +00001266#ifdef HAVE_SYS_MMAN_H
1267 } else if (memory) {
1268 int fd;
1269 struct stat info;
1270 const char *base;
1271 if (stat(filename, &info) < 0)
1272 return;
1273 if ((fd = open(filename, O_RDONLY)) < 0)
1274 return;
1275 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
Daniel Veillard29579362000-08-14 17:57:48 +00001276 if (base == (void *) MAP_FAILED)
Daniel Veillard46e370e2000-07-21 20:32:03 +00001277 return;
1278
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001279 if (rectxt == NULL)
Daniel Veillard60942de2003-09-25 21:05:58 +00001280 doc = xmlReadMemory((char *) base, info.st_size,
1281 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001282 else
Daniel Veillard60942de2003-09-25 21:05:58 +00001283 doc = xmlCtxtReadMemory(rectxt, (char *) base, info.st_size,
1284 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001285
Daniel Veillard46e370e2000-07-21 20:32:03 +00001286 munmap((char *) base, info.st_size);
1287#endif
Daniel Veillard4432df22003-09-28 18:58:27 +00001288#ifdef LIBXML_VALID_ENABLED
Daniel Veillardea7751d2002-12-20 00:16:24 +00001289 } else if (valid) {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001290 xmlParserCtxtPtr ctxt = NULL;
Daniel Veillardea7751d2002-12-20 00:16:24 +00001291
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001292 if (rectxt == NULL)
1293 ctxt = xmlNewParserCtxt();
1294 else
1295 ctxt = rectxt;
Daniel Veillardea7751d2002-12-20 00:16:24 +00001296 if (ctxt == NULL) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001297 doc = NULL;
Daniel Veillardea7751d2002-12-20 00:16:24 +00001298 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001299 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
1300
1301 if (ctxt->valid == 0)
William M. Brack8304d872004-06-08 13:29:32 +00001302 progresult = XMLLINT_ERR_RDFILE;
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001303 if (rectxt == NULL)
1304 xmlFreeParserCtxt(ctxt);
Daniel Veillardea7751d2002-12-20 00:16:24 +00001305 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001306#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardea7751d2002-12-20 00:16:24 +00001307 } else {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001308 if (rectxt != NULL)
1309 doc = xmlCtxtReadFile(rectxt, filename, NULL, options);
1310 else
1311 doc = xmlReadFile(filename, NULL, options);
Daniel Veillardea7751d2002-12-20 00:16:24 +00001312 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001313 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001314
Daniel Veillard88a172f2000-08-04 18:23:10 +00001315 /*
1316 * If we don't have a document we might as well give up. Do we
1317 * want an error message here? <sven@zen.org> */
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001318 if (doc == NULL) {
William M. Brack8304d872004-06-08 13:29:32 +00001319 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard88a172f2000-08-04 18:23:10 +00001320 return;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001321 }
1322
Daniel Veillard48b2f892001-02-25 16:11:03 +00001323 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001324 endTimer("Parsing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001325 }
1326
Daniel Veillard29e43992001-12-13 22:21:58 +00001327 /*
1328 * Remove DOCTYPE nodes
1329 */
1330 if (dropdtd) {
1331 xmlDtdPtr dtd;
1332
1333 dtd = xmlGetIntSubset(doc);
1334 if (dtd != NULL) {
1335 xmlUnlinkNode((xmlNodePtr)dtd);
1336 xmlFreeDtd(dtd);
1337 }
1338 }
1339
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001340#ifdef LIBXML_XINCLUDE_ENABLED
Daniel Veillard48b2f892001-02-25 16:11:03 +00001341 if (xinclude) {
1342 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001343 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001344 }
William M. Brack4e1c2db2005-02-11 10:58:55 +00001345 if (xmlXIncludeProcessFlags(doc, options) < 0)
1346 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard48b2f892001-02-25 16:11:03 +00001347 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001348 endTimer("Xinclude processing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001349 }
1350 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001351#endif
Daniel Veillard88a172f2000-08-04 18:23:10 +00001352
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001353#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardd0cf7f62004-11-09 16:17:02 +00001354#ifdef LIBXML_XPATH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001355 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001356 * shell interaction
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001357 */
1358 if (shell)
1359 xmlShell(doc, filename, xmlShellReadline, stdout);
1360#endif
Daniel Veillardd0cf7f62004-11-09 16:17:02 +00001361#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001362
Daniel Veillard652327a2003-09-29 18:02:38 +00001363#ifdef LIBXML_TREE_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001364 /*
1365 * test intermediate copy if needed.
1366 */
1367 if (copy) {
1368 tmp = doc;
Daniel Veillard4edd3ed2004-09-20 20:03:01 +00001369 if (timing) {
1370 startTimer();
1371 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001372 doc = xmlCopyDoc(doc, 1);
Daniel Veillard4edd3ed2004-09-20 20:03:01 +00001373 if (timing) {
1374 endTimer("Copying");
1375 }
1376 if (timing) {
1377 startTimer();
1378 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001379 xmlFreeDoc(tmp);
Daniel Veillard4edd3ed2004-09-20 20:03:01 +00001380 if (timing) {
1381 endTimer("Freeing original");
1382 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001383 }
Daniel Veillard652327a2003-09-29 18:02:38 +00001384#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001385
Daniel Veillard4432df22003-09-28 18:58:27 +00001386#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001387 if ((insert) && (!html)) {
1388 const xmlChar* list[256];
1389 int nb, i;
1390 xmlNodePtr node;
1391
1392 if (doc->children != NULL) {
1393 node = doc->children;
1394 while ((node != NULL) && (node->last == NULL)) node = node->next;
1395 if (node != NULL) {
1396 nb = xmlValidGetValidElements(node->last, NULL, list, 256);
1397 if (nb < 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001398 fprintf(stderr, "could not get valid list of elements\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001399 } else if (nb == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001400 fprintf(stderr, "No element can be inserted under root\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001401 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001402 fprintf(stderr, "%d element types can be inserted under root:\n",
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001403 nb);
1404 for (i = 0;i < nb;i++) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001405 fprintf(stderr, "%s\n", (char *) list[i]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001406 }
1407 }
1408 }
1409 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001410 }else
1411#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001412#ifdef LIBXML_READER_ENABLED
1413 if (walker) {
1414 walkDoc(doc);
1415 }
1416#endif /* LIBXML_READER_ENABLED */
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001417#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard4432df22003-09-28 18:58:27 +00001418 if (noout == 0) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001419 int ret;
1420
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001421 /*
1422 * print it.
1423 */
1424#ifdef LIBXML_DEBUG_ENABLED
1425 if (!debug) {
1426#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +00001427 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001428 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001429 }
Daniel Veillard656ce942004-04-30 23:11:45 +00001430#ifdef LIBXML_HTML_ENABLED
Daniel Veillard42fd4122003-11-04 08:47:48 +00001431 if ((html) && (!xmlout)) {
1432 if (compress) {
1433 htmlSaveFile(output ? output : "-", doc);
1434 }
1435 else if (encoding != NULL) {
1436 if ( format ) {
1437 htmlSaveFileFormat(output ? output : "-", doc, encoding, 1);
1438 }
1439 else {
1440 htmlSaveFileFormat(output ? output : "-", doc, encoding, 0);
1441 }
1442 }
1443 else if (format) {
1444 htmlSaveFileFormat(output ? output : "-", doc, NULL, 1);
1445 }
1446 else {
1447 FILE *out;
1448 if (output == NULL)
1449 out = stdout;
1450 else {
1451 out = fopen(output,"wb");
1452 }
1453 if (out != NULL) {
1454 if (htmlDocDump(out, doc) < 0)
William M. Brack8304d872004-06-08 13:29:32 +00001455 progresult = XMLLINT_ERR_OUT;
Daniel Veillard42fd4122003-11-04 08:47:48 +00001456
1457 if (output != NULL)
1458 fclose(out);
1459 } else {
1460 fprintf(stderr, "failed to open %s\n", output);
William M. Brack8304d872004-06-08 13:29:32 +00001461 progresult = XMLLINT_ERR_OUT;
Daniel Veillard42fd4122003-11-04 08:47:48 +00001462 }
1463 }
1464 if ((timing) && (!repeat)) {
1465 endTimer("Saving");
1466 }
1467 } else
1468#endif
Daniel Veillard25048d82004-08-14 22:37:54 +00001469#ifdef LIBXML_C14N_ENABLED
1470 if (canonical) {
1471 xmlChar *result = NULL;
1472 int size;
1473
1474 size = xmlC14NDocDumpMemory(doc, NULL, 0, NULL, 1, &result);
1475 if (size >= 0) {
1476 write(1, result, size);
1477 xmlFree(result);
1478 } else {
1479 fprintf(stderr, "Failed to canonicalize\n");
1480 progresult = XMLLINT_ERR_OUT;
1481 }
1482 } else
1483#endif
Daniel Veillard3b2c2612001-04-04 00:09:00 +00001484#ifdef HAVE_SYS_MMAN_H
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001485 if (memory) {
1486 xmlChar *result;
1487 int len;
1488
1489 if (encoding != NULL) {
Daniel Veillardd536f702001-11-08 17:32:47 +00001490 if ( format ) {
1491 xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1);
1492 } else {
1493 xmlDocDumpMemoryEnc(doc, &result, &len, encoding);
1494 }
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001495 } else {
Daniel Veillard90493a92001-08-14 14:12:47 +00001496 if (format)
1497 xmlDocDumpFormatMemory(doc, &result, &len, 1);
1498 else
1499 xmlDocDumpMemory(doc, &result, &len);
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001500 }
1501 if (result == NULL) {
1502 fprintf(stderr, "Failed to save\n");
Daniel Veillard25048d82004-08-14 22:37:54 +00001503 progresult = XMLLINT_ERR_OUT;
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001504 } else {
1505 write(1, result, len);
1506 xmlFree(result);
1507 }
Daniel Veillard3b2c2612001-04-04 00:09:00 +00001508 } else
1509#endif /* HAVE_SYS_MMAN_H */
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001510 if (compress) {
1511 xmlSaveFile(output ? output : "-", doc);
1512 }
Daniel Veillardd536f702001-11-08 17:32:47 +00001513 else if (encoding != NULL) {
1514 if ( format ) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001515 ret = xmlSaveFormatFileEnc(output ? output : "-", doc,
1516 encoding, 1);
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001517 }
Daniel Veillardd536f702001-11-08 17:32:47 +00001518 else {
Daniel Veillard3df01182003-12-10 10:17:51 +00001519 ret = xmlSaveFileEnc(output ? output : "-", doc, encoding);
1520 }
1521 if (ret < 0) {
1522 fprintf(stderr, "failed save to %s\n",
1523 output ? output : "-");
William M. Brack8304d872004-06-08 13:29:32 +00001524 progresult = XMLLINT_ERR_OUT;
Daniel Veillardd536f702001-11-08 17:32:47 +00001525 }
1526 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001527 else if (format) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001528 ret = xmlSaveFormatFile(output ? output : "-", doc, 1);
1529 if (ret < 0) {
1530 fprintf(stderr, "failed save to %s\n",
1531 output ? output : "-");
William M. Brack8304d872004-06-08 13:29:32 +00001532 progresult = XMLLINT_ERR_OUT;
Daniel Veillard3df01182003-12-10 10:17:51 +00001533 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001534 }
1535 else {
1536 FILE *out;
1537 if (output == NULL)
1538 out = stdout;
1539 else {
1540 out = fopen(output,"wb");
1541 }
Daniel Veillard05d987b2003-10-08 11:54:57 +00001542 if (out != NULL) {
Daniel Veillard828ce832003-10-08 19:19:10 +00001543 if (xmlDocDump(out, doc) < 0)
William M. Brack8304d872004-06-08 13:29:32 +00001544 progresult = XMLLINT_ERR_OUT;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001545
Daniel Veillard05d987b2003-10-08 11:54:57 +00001546 if (output != NULL)
1547 fclose(out);
1548 } else {
1549 fprintf(stderr, "failed to open %s\n", output);
William M. Brack8304d872004-06-08 13:29:32 +00001550 progresult = XMLLINT_ERR_OUT;
Daniel Veillard05d987b2003-10-08 11:54:57 +00001551 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001552 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001553 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001554 endTimer("Saving");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001555 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001556#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001557 } else {
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001558 FILE *out;
1559 if (output == NULL)
1560 out = stdout;
1561 else {
1562 out = fopen(output,"wb");
1563 }
Daniel Veillard05d987b2003-10-08 11:54:57 +00001564 if (out != NULL) {
1565 xmlDebugDumpDocument(out, doc);
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001566
Daniel Veillard05d987b2003-10-08 11:54:57 +00001567 if (output != NULL)
1568 fclose(out);
1569 } else {
1570 fprintf(stderr, "failed to open %s\n", output);
William M. Brack8304d872004-06-08 13:29:32 +00001571 progresult = XMLLINT_ERR_OUT;
Daniel Veillard05d987b2003-10-08 11:54:57 +00001572 }
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001573 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001574#endif
1575 }
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001576#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001577
Daniel Veillard4432df22003-09-28 18:58:27 +00001578#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001579 /*
1580 * A posteriori validation test
1581 */
Daniel Veillard66f68e72003-08-18 16:39:51 +00001582 if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) {
Daniel Veillardcd429612000-10-11 15:57:05 +00001583 xmlDtdPtr dtd;
1584
Daniel Veillard48b2f892001-02-25 16:11:03 +00001585 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001586 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001587 }
Daniel Veillard66f68e72003-08-18 16:39:51 +00001588 if (dtdvalid != NULL)
1589 dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid);
1590 else
1591 dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001592 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001593 endTimer("Parsing DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001594 }
Daniel Veillardcd429612000-10-11 15:57:05 +00001595 if (dtd == NULL) {
Daniel Veillard66f68e72003-08-18 16:39:51 +00001596 if (dtdvalid != NULL)
1597 xmlGenericError(xmlGenericErrorContext,
1598 "Could not parse DTD %s\n", dtdvalid);
1599 else
1600 xmlGenericError(xmlGenericErrorContext,
1601 "Could not parse DTD %s\n", dtdvalidfpi);
William M. Brack8304d872004-06-08 13:29:32 +00001602 progresult = XMLLINT_ERR_DTD;
Daniel Veillardcd429612000-10-11 15:57:05 +00001603 } else {
Daniel Veillarda37aab82003-06-09 09:10:36 +00001604 xmlValidCtxtPtr cvp;
1605
1606 if ((cvp = xmlNewValidCtxt()) == NULL) {
1607 xmlGenericError(xmlGenericErrorContext,
1608 "Couldn't allocate validation context\n");
1609 exit(-1);
1610 }
1611 cvp->userData = (void *) stderr;
1612 cvp->error = (xmlValidityErrorFunc) fprintf;
1613 cvp->warning = (xmlValidityWarningFunc) fprintf;
1614
Daniel Veillard48b2f892001-02-25 16:11:03 +00001615 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001616 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001617 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001618 if (!xmlValidateDtd(cvp, doc, dtd)) {
Daniel Veillard66f68e72003-08-18 16:39:51 +00001619 if (dtdvalid != NULL)
1620 xmlGenericError(xmlGenericErrorContext,
1621 "Document %s does not validate against %s\n",
1622 filename, dtdvalid);
1623 else
1624 xmlGenericError(xmlGenericErrorContext,
1625 "Document %s does not validate against %s\n",
1626 filename, dtdvalidfpi);
William M. Brack8304d872004-06-08 13:29:32 +00001627 progresult = XMLLINT_ERR_VALID;
Daniel Veillardcd429612000-10-11 15:57:05 +00001628 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001629 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001630 endTimer("Validating against DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001631 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001632 xmlFreeValidCtxt(cvp);
Daniel Veillardcd429612000-10-11 15:57:05 +00001633 xmlFreeDtd(dtd);
1634 }
1635 } else if (postvalid) {
Daniel Veillarda37aab82003-06-09 09:10:36 +00001636 xmlValidCtxtPtr cvp;
1637
1638 if ((cvp = xmlNewValidCtxt()) == NULL) {
1639 xmlGenericError(xmlGenericErrorContext,
1640 "Couldn't allocate validation context\n");
1641 exit(-1);
1642 }
1643
Daniel Veillard48b2f892001-02-25 16:11:03 +00001644 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001645 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001646 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001647 cvp->userData = (void *) stderr;
1648 cvp->error = (xmlValidityErrorFunc) fprintf;
1649 cvp->warning = (xmlValidityWarningFunc) fprintf;
1650 if (!xmlValidateDocument(cvp, doc)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001651 xmlGenericError(xmlGenericErrorContext,
1652 "Document %s does not validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001653 progresult = XMLLINT_ERR_VALID;
Daniel Veillardcd429612000-10-11 15:57:05 +00001654 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001655 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001656 endTimer("Validating");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001657 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001658 xmlFreeValidCtxt(cvp);
Daniel Veillard4432df22003-09-28 18:58:27 +00001659 }
1660#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard71531f32003-02-05 13:19:53 +00001661#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard4432df22003-09-28 18:58:27 +00001662 if (relaxngschemas != NULL) {
Daniel Veillard71531f32003-02-05 13:19:53 +00001663 xmlRelaxNGValidCtxtPtr ctxt;
1664 int ret;
1665
Daniel Veillard42f12e92003-03-07 18:32:59 +00001666 if ((timing) && (!repeat)) {
1667 startTimer();
1668 }
1669
Daniel Veillard71531f32003-02-05 13:19:53 +00001670 ctxt = xmlRelaxNGNewValidCtxt(relaxngschemas);
1671 xmlRelaxNGSetValidErrors(ctxt,
1672 (xmlRelaxNGValidityErrorFunc) fprintf,
1673 (xmlRelaxNGValidityWarningFunc) fprintf,
1674 stderr);
1675 ret = xmlRelaxNGValidateDoc(ctxt, doc);
1676 if (ret == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001677 fprintf(stderr, "%s validates\n", filename);
Daniel Veillard71531f32003-02-05 13:19:53 +00001678 } else if (ret > 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001679 fprintf(stderr, "%s fails to validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001680 progresult = XMLLINT_ERR_VALID;
Daniel Veillard71531f32003-02-05 13:19:53 +00001681 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001682 fprintf(stderr, "%s validation generated an internal error\n",
Daniel Veillard71531f32003-02-05 13:19:53 +00001683 filename);
William M. Brack8304d872004-06-08 13:29:32 +00001684 progresult = XMLLINT_ERR_VALID;
Daniel Veillard71531f32003-02-05 13:19:53 +00001685 }
1686 xmlRelaxNGFreeValidCtxt(ctxt);
Daniel Veillard42f12e92003-03-07 18:32:59 +00001687 if ((timing) && (!repeat)) {
1688 endTimer("Validating");
1689 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001690 } else if (wxschemas != NULL) {
1691 xmlSchemaValidCtxtPtr ctxt;
1692 int ret;
1693
1694 if ((timing) && (!repeat)) {
1695 startTimer();
1696 }
1697
1698 ctxt = xmlSchemaNewValidCtxt(wxschemas);
1699 xmlSchemaSetValidErrors(ctxt,
1700 (xmlSchemaValidityErrorFunc) fprintf,
1701 (xmlSchemaValidityWarningFunc) fprintf,
1702 stderr);
1703 ret = xmlSchemaValidateDoc(ctxt, doc);
1704 if (ret == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001705 fprintf(stderr, "%s validates\n", filename);
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001706 } else if (ret > 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001707 fprintf(stderr, "%s fails to validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001708 progresult = XMLLINT_ERR_VALID;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001709 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001710 fprintf(stderr, "%s validation generated an internal error\n",
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001711 filename);
William M. Brack8304d872004-06-08 13:29:32 +00001712 progresult = XMLLINT_ERR_VALID;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001713 }
1714 xmlSchemaFreeValidCtxt(ctxt);
1715 if ((timing) && (!repeat)) {
1716 endTimer("Validating");
1717 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001718 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001719#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001720
1721#ifdef LIBXML_DEBUG_ENABLED
1722 if ((debugent) && (!html))
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001723 xmlDebugDumpEntities(stderr, doc);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001724#endif
1725
1726 /*
1727 * free it.
1728 */
Daniel Veillard48b2f892001-02-25 16:11:03 +00001729 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001730 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001731 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001732 xmlFreeDoc(doc);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001733 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001734 endTimer("Freeing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001735 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001736}
1737
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001738/************************************************************************
1739 * *
1740 * Usage and Main *
1741 * *
1742 ************************************************************************/
1743
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001744static void showVersion(const char *name) {
1745 fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion);
1746 fprintf(stderr, " compiled with: ");
Daniel Veillard4432df22003-09-28 18:58:27 +00001747#ifdef LIBXML_VALID_ENABLED
1748 fprintf(stderr, "DTDValid ");
1749#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001750#ifdef LIBXML_FTP_ENABLED
1751 fprintf(stderr, "FTP ");
1752#endif
1753#ifdef LIBXML_HTTP_ENABLED
1754 fprintf(stderr, "HTTP ");
1755#endif
1756#ifdef LIBXML_HTML_ENABLED
1757 fprintf(stderr, "HTML ");
1758#endif
1759#ifdef LIBXML_C14N_ENABLED
1760 fprintf(stderr, "C14N ");
1761#endif
1762#ifdef LIBXML_CATALOG_ENABLED
1763 fprintf(stderr, "Catalog ");
1764#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001765#ifdef LIBXML_XPATH_ENABLED
1766 fprintf(stderr, "XPath ");
1767#endif
1768#ifdef LIBXML_XPTR_ENABLED
1769 fprintf(stderr, "XPointer ");
1770#endif
1771#ifdef LIBXML_XINCLUDE_ENABLED
1772 fprintf(stderr, "XInclude ");
1773#endif
1774#ifdef LIBXML_ICONV_ENABLED
1775 fprintf(stderr, "Iconv ");
1776#endif
1777#ifdef DEBUG_MEMORY_LOCATION
1778 fprintf(stderr, "MemDebug ");
1779#endif
1780#ifdef LIBXML_UNICODE_ENABLED
1781 fprintf(stderr, "Unicode ");
1782#endif
1783#ifdef LIBXML_REGEXP_ENABLED
1784 fprintf(stderr, "Regexps ");
1785#endif
1786#ifdef LIBXML_AUTOMATA_ENABLED
1787 fprintf(stderr, "Automata ");
1788#endif
1789#ifdef LIBXML_SCHEMAS_ENABLED
1790 fprintf(stderr, "Schemas ");
1791#endif
Daniel Veillardce1648b2005-01-04 15:10:22 +00001792#ifdef LIBXML_MODULES_ENABLED
1793 fprintf(stderr, "Modules ");
1794#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001795 fprintf(stderr, "\n");
1796}
1797
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001798static void usage(const char *name) {
1799 printf("Usage : %s [options] XMLfiles ...\n", name);
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001800#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001801 printf("\tParse the XML files and output the result of the parsing\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001802#else
1803 printf("\tParse the XML files\n");
1804#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001805 printf("\t--version : display the version of the XML library used\n");
1806#ifdef LIBXML_DEBUG_ENABLED
1807 printf("\t--debug : dump a debug tree of the in-memory document\n");
1808 printf("\t--shell : run a navigating shell\n");
1809 printf("\t--debugent : debug the entities defined in the document\n");
Daniel Veillard8326e732003-01-07 00:19:07 +00001810#else
Daniel Veillard81273902003-09-30 00:43:48 +00001811#ifdef LIBXML_READER_ENABLED
Daniel Veillard8326e732003-01-07 00:19:07 +00001812 printf("\t--debug : dump the nodes content when using --stream\n");
Daniel Veillard81273902003-09-30 00:43:48 +00001813#endif /* LIBXML_READER_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001814#endif
Daniel Veillard652327a2003-09-29 18:02:38 +00001815#ifdef LIBXML_TREE_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001816 printf("\t--copy : used to test the internal copy implementation\n");
Daniel Veillard652327a2003-09-29 18:02:38 +00001817#endif /* LIBXML_TREE_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001818 printf("\t--recover : output what was parsable on broken XML documents\n");
1819 printf("\t--noent : substitute entity references by their value\n");
1820 printf("\t--noout : don't output the result tree\n");
Daniel Veillard0bff36d2004-08-31 09:37:03 +00001821 printf("\t--path 'paths': provide a set of paths for resources\n");
1822 printf("\t--load-trace : print trace of all external entites loaded\n");
Daniel Veillarde8b09e42003-05-13 22:14:13 +00001823 printf("\t--nonet : refuse to fetch DTDs or entities over network\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001824 printf("\t--htmlout : output results as HTML\n");
Daniel Veillard05c13a22001-09-09 08:38:09 +00001825 printf("\t--nowrap : do not put HTML doc wrapper\n");
Daniel Veillard4432df22003-09-28 18:58:27 +00001826#ifdef LIBXML_VALID_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001827 printf("\t--valid : validate the document in addition to std well-formed check\n");
1828 printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
1829 printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
Daniel Veillard66f68e72003-08-18 16:39:51 +00001830 printf("\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
Daniel Veillard4432df22003-09-28 18:58:27 +00001831#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001832 printf("\t--timing : print some timings\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001833 printf("\t--output file or -o file: save to a given file\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001834 printf("\t--repeat : repeat 100 times, for timing or profiling\n");
1835 printf("\t--insert : ad-hoc test for valid insertions\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001836#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001837#ifdef HAVE_ZLIB_H
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001838 printf("\t--compress : turn on gzip compression of output\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001839#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001840#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001841#ifdef LIBXML_HTML_ENABLED
1842 printf("\t--html : use the HTML parser\n");
Daniel Veillard42fd4122003-11-04 08:47:48 +00001843 printf("\t--xmlout : force to use the XML serializer when using --html\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001844#endif
Daniel Veillard73b013f2003-09-30 12:36:01 +00001845#ifdef LIBXML_PUSH_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001846 printf("\t--push : use the push mode of the parser\n");
Daniel Veillard73b013f2003-09-30 12:36:01 +00001847#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001848#ifdef HAVE_SYS_MMAN_H
1849 printf("\t--memory : parse from memory\n");
1850#endif
Daniel Veillard87076042004-05-03 22:54:49 +00001851 printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001852 printf("\t--nowarning : do not emit warnings from parser/validator\n");
1853 printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
Daniel Veillarddca8cc72003-09-26 13:53:14 +00001854 printf("\t--nocdata : replace cdata section with text nodes\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001855#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard90493a92001-08-14 14:12:47 +00001856 printf("\t--format : reformat/reindent the input\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001857 printf("\t--encode encoding : output in the given encoding\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001858 printf("\t--dropdtd : remove the DOCTYPE of the input docs\n");
1859#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard25048d82004-08-14 22:37:54 +00001860 printf("\t--c14n: save in W3C canonical format (with comments)\n");
1861#ifdef LIBXML_C14N_ENABLED
1862#endif /* LIBXML_C14N_ENABLED */
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001863 printf("\t--nsclean : remove redundant namespace declarations\n");
1864 printf("\t--testIO : test user I/O support\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001865#ifdef LIBXML_CATALOG_ENABLED
Daniel Veillardbd9b0e82001-11-26 10:32:08 +00001866 printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");
1867 printf("\t otherwise XML Catalogs starting from \n");
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001868 printf("\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG);
Daniel Veillard05c13a22001-09-09 08:38:09 +00001869 printf("\t--nocatalogs: deactivate all catalogs\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001870#endif
1871 printf("\t--auto : generate a small doc on the fly\n");
1872#ifdef LIBXML_XINCLUDE_ENABLED
1873 printf("\t--xinclude : do XInclude processing\n");
Daniel Veillardc14c3892004-08-16 12:34:50 +00001874 printf("\t--noxincludenode : same but do not generate XInclude nodes\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001875#endif
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001876 printf("\t--loaddtd : fetch external DTD\n");
Daniel Veillard48da9102001-08-07 01:10:10 +00001877 printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
Daniel Veillard81273902003-09-30 00:43:48 +00001878#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00001879 printf("\t--stream : use the streaming interface to process very large files\n");
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001880 printf("\t--walker : create a reader and walk though the resulting doc\n");
Daniel Veillard81273902003-09-30 00:43:48 +00001881#endif /* LIBXML_READER_ENABLED */
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001882#ifdef LIBXML_PATTERN_ENABLED
1883 printf("\t--pattern pattern_value : test the pattern support\n");
1884#endif
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001885 printf("\t--chkregister : verify the node registration code\n");
Daniel Veillardef4d3bc2003-02-07 12:38:22 +00001886#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard71531f32003-02-05 13:19:53 +00001887 printf("\t--relaxng schema : do RelaxNG validation against the schema\n");
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001888 printf("\t--schema schema : do validation against the WXS schema\n");
Daniel Veillard71531f32003-02-05 13:19:53 +00001889#endif
Daniel Veillarda42f25f2002-01-25 14:15:40 +00001890 printf("\nLibxml project home page: http://xmlsoft.org/\n");
1891 printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001892}
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001893
1894static void registerNode(xmlNodePtr node)
1895{
1896 node->_private = malloc(sizeof(long));
1897 *(long*)node->_private = (long) 0x81726354;
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00001898 nbregister++;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001899}
1900
1901static void deregisterNode(xmlNodePtr node)
1902{
1903 assert(node->_private != NULL);
1904 assert(*(long*)node->_private == (long) 0x81726354);
1905 free(node->_private);
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00001906 nbregister--;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001907}
1908
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001909int
1910main(int argc, char **argv) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00001911 int i, acount;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001912 int files = 0;
Daniel Veillard845cce42002-01-09 11:51:37 +00001913 int version = 0;
Aleksey Sanin693c9bc2003-03-09 22:36:52 +00001914 const char* indent;
1915
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001916 if (argc <= 1) {
1917 usage(argv[0]);
1918 return(1);
1919 }
Daniel Veillardbe803962000-06-28 23:40:59 +00001920 LIBXML_TEST_VERSION
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001921 for (i = 1; i < argc ; i++) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001922 if (!strcmp(argv[i], "-"))
1923 break;
1924
1925 if (argv[i][0] != '-')
1926 continue;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001927 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
1928 debug++;
Daniel Veillard56ada1d2003-01-07 11:17:25 +00001929 else
1930#ifdef LIBXML_DEBUG_ENABLED
1931 if ((!strcmp(argv[i], "-shell")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001932 (!strcmp(argv[i], "--shell"))) {
1933 shell++;
1934 noout = 1;
1935 } else
1936#endif
Daniel Veillard652327a2003-09-29 18:02:38 +00001937#ifdef LIBXML_TREE_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001938 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
1939 copy++;
Daniel Veillard652327a2003-09-29 18:02:38 +00001940 else
1941#endif /* LIBXML_TREE_ENABLED */
1942 if ((!strcmp(argv[i], "-recover")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001943 (!strcmp(argv[i], "--recover"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001944 recovery++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001945 options |= XML_PARSE_RECOVER;
1946 } else if ((!strcmp(argv[i], "-noent")) ||
1947 (!strcmp(argv[i], "--noent"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001948 noent++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001949 options |= XML_PARSE_NOENT;
Daniel Veillarddca8cc72003-09-26 13:53:14 +00001950 } else if ((!strcmp(argv[i], "-nsclean")) ||
1951 (!strcmp(argv[i], "--nsclean"))) {
1952 options |= XML_PARSE_NSCLEAN;
1953 } else if ((!strcmp(argv[i], "-nocdata")) ||
1954 (!strcmp(argv[i], "--nocdata"))) {
1955 options |= XML_PARSE_NOCDATA;
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001956 } else if ((!strcmp(argv[i], "-nodict")) ||
1957 (!strcmp(argv[i], "--nodict"))) {
1958 options |= XML_PARSE_NODICT;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001959 } else if ((!strcmp(argv[i], "-version")) ||
Daniel Veillard845cce42002-01-09 11:51:37 +00001960 (!strcmp(argv[i], "--version"))) {
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001961 showVersion(argv[0]);
Daniel Veillard845cce42002-01-09 11:51:37 +00001962 version = 1;
1963 } else if ((!strcmp(argv[i], "-noout")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001964 (!strcmp(argv[i], "--noout")))
1965 noout++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001966#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001967 else if ((!strcmp(argv[i], "-o")) ||
1968 (!strcmp(argv[i], "-output")) ||
1969 (!strcmp(argv[i], "--output"))) {
1970 i++;
Daniel Veillard6e4f1c02002-04-09 09:55:20 +00001971 output = argv[i];
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001972 }
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001973#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001974 else if ((!strcmp(argv[i], "-htmlout")) ||
1975 (!strcmp(argv[i], "--htmlout")))
1976 htmlout++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001977 else if ((!strcmp(argv[i], "-nowrap")) ||
1978 (!strcmp(argv[i], "--nowrap")))
1979 nowrap++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001980#ifdef LIBXML_HTML_ENABLED
1981 else if ((!strcmp(argv[i], "-html")) ||
1982 (!strcmp(argv[i], "--html"))) {
1983 html++;
1984 }
Daniel Veillard42fd4122003-11-04 08:47:48 +00001985 else if ((!strcmp(argv[i], "-xmlout")) ||
1986 (!strcmp(argv[i], "--xmlout"))) {
1987 xmlout++;
1988 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001989#endif /* LIBXML_HTML_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001990 else if ((!strcmp(argv[i], "-loaddtd")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001991 (!strcmp(argv[i], "--loaddtd"))) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001992 loaddtd++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001993 options |= XML_PARSE_DTDLOAD;
1994 } else if ((!strcmp(argv[i], "-dtdattr")) ||
Daniel Veillard48da9102001-08-07 01:10:10 +00001995 (!strcmp(argv[i], "--dtdattr"))) {
1996 loaddtd++;
1997 dtdattrs++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001998 options |= XML_PARSE_DTDATTR;
Daniel Veillard4432df22003-09-28 18:58:27 +00001999 }
2000#ifdef LIBXML_VALID_ENABLED
2001 else if ((!strcmp(argv[i], "-valid")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002002 (!strcmp(argv[i], "--valid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002003 valid++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002004 options |= XML_PARSE_DTDVALID;
2005 } else if ((!strcmp(argv[i], "-postvalid")) ||
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002006 (!strcmp(argv[i], "--postvalid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002007 postvalid++;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002008 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00002009 options |= XML_PARSE_DTDLOAD;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002010 } else if ((!strcmp(argv[i], "-dtdvalid")) ||
Daniel Veillardcd429612000-10-11 15:57:05 +00002011 (!strcmp(argv[i], "--dtdvalid"))) {
2012 i++;
2013 dtdvalid = argv[i];
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002014 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00002015 options |= XML_PARSE_DTDLOAD;
Daniel Veillard66f68e72003-08-18 16:39:51 +00002016 } else if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
2017 (!strcmp(argv[i], "--dtdvalidfpi"))) {
2018 i++;
2019 dtdvalidfpi = argv[i];
2020 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00002021 options |= XML_PARSE_DTDLOAD;
Daniel Veillardcd429612000-10-11 15:57:05 +00002022 }
Daniel Veillard4432df22003-09-28 18:58:27 +00002023#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard29e43992001-12-13 22:21:58 +00002024 else if ((!strcmp(argv[i], "-dropdtd")) ||
2025 (!strcmp(argv[i], "--dropdtd")))
2026 dropdtd++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002027 else if ((!strcmp(argv[i], "-insert")) ||
2028 (!strcmp(argv[i], "--insert")))
2029 insert++;
Daniel Veillard48b2f892001-02-25 16:11:03 +00002030 else if ((!strcmp(argv[i], "-timing")) ||
2031 (!strcmp(argv[i], "--timing")))
2032 timing++;
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00002033 else if ((!strcmp(argv[i], "-auto")) ||
2034 (!strcmp(argv[i], "--auto")))
2035 generate++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002036 else if ((!strcmp(argv[i], "-repeat")) ||
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00002037 (!strcmp(argv[i], "--repeat"))) {
2038 if (repeat)
2039 repeat *= 10;
2040 else
2041 repeat = 100;
Daniel Veillard73b013f2003-09-30 12:36:01 +00002042 }
2043#ifdef LIBXML_PUSH_ENABLED
2044 else if ((!strcmp(argv[i], "-push")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002045 (!strcmp(argv[i], "--push")))
2046 push++;
Daniel Veillard73b013f2003-09-30 12:36:01 +00002047#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillard46e370e2000-07-21 20:32:03 +00002048#ifdef HAVE_SYS_MMAN_H
2049 else if ((!strcmp(argv[i], "-memory")) ||
2050 (!strcmp(argv[i], "--memory")))
2051 memory++;
2052#endif
Daniel Veillard5e873c42000-04-12 13:27:38 +00002053 else if ((!strcmp(argv[i], "-testIO")) ||
2054 (!strcmp(argv[i], "--testIO")))
2055 testIO++;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00002056#ifdef LIBXML_XINCLUDE_ENABLED
2057 else if ((!strcmp(argv[i], "-xinclude")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002058 (!strcmp(argv[i], "--xinclude"))) {
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00002059 xinclude++;
Daniel Veillard7899c5c2003-11-03 12:31:38 +00002060 options |= XML_PARSE_XINCLUDE;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002061 }
Daniel Veillardc14c3892004-08-16 12:34:50 +00002062 else if ((!strcmp(argv[i], "-noxincludenode")) ||
2063 (!strcmp(argv[i], "--noxincludenode"))) {
2064 xinclude++;
2065 options |= XML_PARSE_XINCLUDE;
2066 options |= XML_PARSE_NOXINCNODE;
2067 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00002068#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002069#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00002070#ifdef HAVE_ZLIB_H
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002071 else if ((!strcmp(argv[i], "-compress")) ||
2072 (!strcmp(argv[i], "--compress"))) {
2073 compress++;
2074 xmlSetCompressMode(9);
2075 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00002076#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002077#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002078 else if ((!strcmp(argv[i], "-nowarning")) ||
2079 (!strcmp(argv[i], "--nowarning"))) {
2080 xmlGetWarningsDefaultValue = 0;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002081 xmlPedanticParserDefault(0);
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002082 options |= XML_PARSE_NOWARNING;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002083 }
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002084 else if ((!strcmp(argv[i], "-pedantic")) ||
2085 (!strcmp(argv[i], "--pedantic"))) {
2086 xmlGetWarningsDefaultValue = 1;
2087 xmlPedanticParserDefault(1);
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002088 options |= XML_PARSE_PEDANTIC;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002089 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00002090#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002091 else if ((!strcmp(argv[i], "-debugent")) ||
2092 (!strcmp(argv[i], "--debugent"))) {
2093 debugent++;
2094 xmlParserDebugEntities = 1;
2095 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00002096#endif
Daniel Veillard25048d82004-08-14 22:37:54 +00002097#ifdef LIBXML_C14N_ENABLED
2098 else if ((!strcmp(argv[i], "-c14n")) ||
2099 (!strcmp(argv[i], "--c14n"))) {
2100 canonical++;
2101 options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD;
2102 }
2103#endif
Daniel Veillard81418e32001-05-22 15:08:55 +00002104#ifdef LIBXML_CATALOG_ENABLED
2105 else if ((!strcmp(argv[i], "-catalogs")) ||
2106 (!strcmp(argv[i], "--catalogs"))) {
Daniel Veillarde2940dd2001-08-22 00:06:49 +00002107 catalogs++;
2108 } else if ((!strcmp(argv[i], "-nocatalogs")) ||
2109 (!strcmp(argv[i], "--nocatalogs"))) {
2110 nocatalogs++;
Daniel Veillard81418e32001-05-22 15:08:55 +00002111 }
2112#endif
Daniel Veillardbe803962000-06-28 23:40:59 +00002113 else if ((!strcmp(argv[i], "-encode")) ||
2114 (!strcmp(argv[i], "--encode"))) {
2115 i++;
2116 encoding = argv[i];
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002117 /*
2118 * OK it's for testing purposes
2119 */
2120 xmlAddEncodingAlias("UTF-8", "DVEnc");
Daniel Veillardbe803962000-06-28 23:40:59 +00002121 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002122 else if ((!strcmp(argv[i], "-noblanks")) ||
2123 (!strcmp(argv[i], "--noblanks"))) {
2124 noblanks++;
2125 xmlKeepBlanksDefault(0);
Daniel Veillard90493a92001-08-14 14:12:47 +00002126 }
Daniel Veillard87076042004-05-03 22:54:49 +00002127 else if ((!strcmp(argv[i], "-maxmem")) ||
2128 (!strcmp(argv[i], "--maxmem"))) {
2129 i++;
2130 if (sscanf(argv[i], "%d", &maxmem) == 1) {
2131 xmlMemSetup(myFreeFunc, myMallocFunc, myReallocFunc,
2132 myStrdupFunc);
2133 } else {
2134 maxmem = 0;
2135 }
2136 }
Daniel Veillard90493a92001-08-14 14:12:47 +00002137 else if ((!strcmp(argv[i], "-format")) ||
2138 (!strcmp(argv[i], "--format"))) {
2139 noblanks++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002140#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard90493a92001-08-14 14:12:47 +00002141 format++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002142#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard90493a92001-08-14 14:12:47 +00002143 xmlKeepBlanksDefault(0);
Daniel Veillard7704fb12003-01-03 16:19:51 +00002144 }
Daniel Veillard81273902003-09-30 00:43:48 +00002145#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00002146 else if ((!strcmp(argv[i], "-stream")) ||
2147 (!strcmp(argv[i], "--stream"))) {
2148 stream++;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002149 }
Daniel Veillard7899c5c2003-11-03 12:31:38 +00002150 else if ((!strcmp(argv[i], "-walker")) ||
2151 (!strcmp(argv[i], "--walker"))) {
2152 walker++;
2153 noout++;
2154 }
Daniel Veillard81273902003-09-30 00:43:48 +00002155#endif /* LIBXML_READER_ENABLED */
2156#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +00002157 else if ((!strcmp(argv[i], "-sax1")) ||
2158 (!strcmp(argv[i], "--sax1"))) {
2159 sax1++;
2160 }
Daniel Veillard81273902003-09-30 00:43:48 +00002161#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002162 else if ((!strcmp(argv[i], "-chkregister")) ||
2163 (!strcmp(argv[i], "--chkregister"))) {
2164 chkregister++;
Daniel Veillard71531f32003-02-05 13:19:53 +00002165#ifdef LIBXML_SCHEMAS_ENABLED
2166 } else if ((!strcmp(argv[i], "-relaxng")) ||
2167 (!strcmp(argv[i], "--relaxng"))) {
2168 i++;
2169 relaxng = argv[i];
2170 noent++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002171 options |= XML_PARSE_NOENT;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002172 } else if ((!strcmp(argv[i], "-schema")) ||
2173 (!strcmp(argv[i], "--schema"))) {
2174 i++;
2175 schema = argv[i];
2176 noent++;
Daniel Veillard71531f32003-02-05 13:19:53 +00002177#endif
Daniel Veillarde8b09e42003-05-13 22:14:13 +00002178 } else if ((!strcmp(argv[i], "-nonet")) ||
2179 (!strcmp(argv[i], "--nonet"))) {
Daniel Veillard61b93382003-11-03 14:28:31 +00002180 options |= XML_PARSE_NONET;
Daniel Veillard0bff36d2004-08-31 09:37:03 +00002181 } else if ((!strcmp(argv[i], "-load-trace")) ||
2182 (!strcmp(argv[i], "--load-trace"))) {
2183 load_trace++;
2184 } else if ((!strcmp(argv[i], "-path")) ||
2185 (!strcmp(argv[i], "--path"))) {
2186 i++;
2187 parsePath(BAD_CAST argv[i]);
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002188#ifdef LIBXML_PATTERN_ENABLED
2189 } else if ((!strcmp(argv[i], "-pattern")) ||
2190 (!strcmp(argv[i], "--pattern"))) {
2191 i++;
2192 pattern = argv[i];
2193#endif
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002194 } else {
2195 fprintf(stderr, "Unknown option %s\n", argv[i]);
2196 usage(argv[0]);
2197 return(1);
2198 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002199 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00002200
2201#ifdef LIBXML_CATALOG_ENABLED
2202 if (nocatalogs == 0) {
2203 if (catalogs) {
2204 const char *catal;
2205
2206 catal = getenv("SGML_CATALOG_FILES");
Daniel Veillard6c5f9d12001-08-25 13:33:14 +00002207 if (catal != NULL) {
2208 xmlLoadCatalogs(catal);
2209 } else {
2210 fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n");
2211 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00002212 }
2213 }
2214#endif
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002215
Daniel Veillard81273902003-09-30 00:43:48 +00002216#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +00002217 if (sax1)
2218 xmlSAXDefaultVersion(1);
2219 else
2220 xmlSAXDefaultVersion(2);
Daniel Veillard81273902003-09-30 00:43:48 +00002221#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillard07cb8222003-09-10 10:51:05 +00002222
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002223 if (chkregister) {
2224 xmlRegisterNodeDefault(registerNode);
2225 xmlDeregisterNodeDefault(deregisterNode);
2226 }
Aleksey Sanin693c9bc2003-03-09 22:36:52 +00002227
2228 indent = getenv("XMLLINT_INDENT");
2229 if(indent != NULL) {
2230 xmlTreeIndentString = indent;
2231 }
2232
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002233
Daniel Veillard0bff36d2004-08-31 09:37:03 +00002234 defaultEntityLoader = xmlGetExternalEntityLoader();
2235 xmlSetExternalEntityLoader(xmllintExternalEntityLoader);
2236
Daniel Veillardd9bad132001-07-23 19:39:43 +00002237 xmlLineNumbersDefault(1);
Daniel Veillard48da9102001-08-07 01:10:10 +00002238 if (loaddtd != 0)
2239 xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
2240 if (dtdattrs)
2241 xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002242 if (noent != 0) xmlSubstituteEntitiesDefault(1);
Daniel Veillard4432df22003-09-28 18:58:27 +00002243#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002244 if (valid != 0) xmlDoValidityCheckingDefaultValue = 1;
Daniel Veillard4432df22003-09-28 18:58:27 +00002245#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002246 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002247 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002248 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002249 xmlGenericError(xmlGenericErrorContext,
2250 "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
2251 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002252 "<html><head><title>%s output</title></head>\n",
2253 argv[0]);
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002254 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002255 "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
2256 argv[0]);
2257 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002258
2259#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard81273902003-09-30 00:43:48 +00002260 if ((relaxng != NULL)
2261#ifdef LIBXML_READER_ENABLED
2262 && (stream == 0)
2263#endif /* LIBXML_READER_ENABLED */
2264 ) {
Daniel Veillard71531f32003-02-05 13:19:53 +00002265 xmlRelaxNGParserCtxtPtr ctxt;
2266
Daniel Veillardce192eb2003-04-16 15:58:05 +00002267 /* forces loading the DTDs */
2268 xmlLoadExtDtdDefaultValue |= 1;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002269 options |= XML_PARSE_DTDLOAD;
Daniel Veillard42f12e92003-03-07 18:32:59 +00002270 if (timing) {
2271 startTimer();
2272 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002273 ctxt = xmlRelaxNGNewParserCtxt(relaxng);
2274 xmlRelaxNGSetParserErrors(ctxt,
2275 (xmlRelaxNGValidityErrorFunc) fprintf,
2276 (xmlRelaxNGValidityWarningFunc) fprintf,
2277 stderr);
2278 relaxngschemas = xmlRelaxNGParse(ctxt);
Daniel Veillardce192eb2003-04-16 15:58:05 +00002279 if (relaxngschemas == NULL) {
2280 xmlGenericError(xmlGenericErrorContext,
2281 "Relax-NG schema %s failed to compile\n", relaxng);
William M. Brack8304d872004-06-08 13:29:32 +00002282 progresult = XMLLINT_ERR_SCHEMACOMP;
Daniel Veillardce192eb2003-04-16 15:58:05 +00002283 relaxng = NULL;
2284 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002285 xmlRelaxNGFreeParserCtxt(ctxt);
Daniel Veillard42f12e92003-03-07 18:32:59 +00002286 if (timing) {
2287 endTimer("Compiling the schemas");
2288 }
Daniel Veillardebe25d42004-03-25 09:35:49 +00002289 } else if ((schema != NULL)
2290#ifdef LIBXML_READER_ENABLED
2291 && (stream == 0)
2292#endif
2293 ) {
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002294 xmlSchemaParserCtxtPtr ctxt;
2295
2296 if (timing) {
2297 startTimer();
2298 }
2299 ctxt = xmlSchemaNewParserCtxt(schema);
2300 xmlSchemaSetParserErrors(ctxt,
2301 (xmlSchemaValidityErrorFunc) fprintf,
2302 (xmlSchemaValidityWarningFunc) fprintf,
2303 stderr);
2304 wxschemas = xmlSchemaParse(ctxt);
2305 if (wxschemas == NULL) {
2306 xmlGenericError(xmlGenericErrorContext,
2307 "WXS schema %s failed to compile\n", schema);
William M. Brack8304d872004-06-08 13:29:32 +00002308 progresult = XMLLINT_ERR_SCHEMACOMP;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002309 schema = NULL;
2310 }
2311 xmlSchemaFreeParserCtxt(ctxt);
2312 if (timing) {
2313 endTimer("Compiling the schemas");
2314 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002315 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002316#endif /* LIBXML_SCHEMAS_ENABLED */
2317#ifdef LIBXML_PATTERN_ENABLED
Daniel Veillardd4301ab2005-02-03 22:24:10 +00002318 if ((pattern != NULL) && (walker == 0)) {
Daniel Veillardffa7b7e2003-12-05 16:10:21 +00002319 patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL);
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002320 if (patternc == NULL) {
2321 xmlGenericError(xmlGenericErrorContext,
2322 "Pattern %s failed to compile\n", pattern);
William M. Brack8304d872004-06-08 13:29:32 +00002323 progresult = XMLLINT_ERR_SCHEMAPAT;
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002324 pattern = NULL;
2325 }
2326 }
2327#endif /* LIBXML_PATTERN_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002328 for (i = 1; i < argc ; i++) {
Daniel Veillardbe803962000-06-28 23:40:59 +00002329 if ((!strcmp(argv[i], "-encode")) ||
2330 (!strcmp(argv[i], "--encode"))) {
2331 i++;
2332 continue;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00002333 } else if ((!strcmp(argv[i], "-o")) ||
2334 (!strcmp(argv[i], "-output")) ||
2335 (!strcmp(argv[i], "--output"))) {
2336 i++;
2337 continue;
Daniel Veillardbe803962000-06-28 23:40:59 +00002338 }
Daniel Veillard4432df22003-09-28 18:58:27 +00002339#ifdef LIBXML_VALID_ENABLED
Daniel Veillardcd429612000-10-11 15:57:05 +00002340 if ((!strcmp(argv[i], "-dtdvalid")) ||
2341 (!strcmp(argv[i], "--dtdvalid"))) {
2342 i++;
2343 continue;
Daniel Veillard0bff36d2004-08-31 09:37:03 +00002344 }
2345 if ((!strcmp(argv[i], "-path")) ||
2346 (!strcmp(argv[i], "--path"))) {
2347 i++;
2348 continue;
Daniel Veillardcd429612000-10-11 15:57:05 +00002349 }
Daniel Veillard66f68e72003-08-18 16:39:51 +00002350 if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
2351 (!strcmp(argv[i], "--dtdvalidfpi"))) {
2352 i++;
2353 continue;
2354 }
Daniel Veillard4432df22003-09-28 18:58:27 +00002355#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard71531f32003-02-05 13:19:53 +00002356 if ((!strcmp(argv[i], "-relaxng")) ||
2357 (!strcmp(argv[i], "--relaxng"))) {
2358 i++;
2359 continue;
2360 }
Daniel Veillard87076042004-05-03 22:54:49 +00002361 if ((!strcmp(argv[i], "-maxmem")) ||
2362 (!strcmp(argv[i], "--maxmem"))) {
2363 i++;
2364 continue;
2365 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002366 if ((!strcmp(argv[i], "-schema")) ||
2367 (!strcmp(argv[i], "--schema"))) {
2368 i++;
2369 continue;
2370 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002371#ifdef LIBXML_PATTERN_ENABLED
2372 if ((!strcmp(argv[i], "-pattern")) ||
2373 (!strcmp(argv[i], "--pattern"))) {
2374 i++;
2375 continue;
2376 }
2377#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +00002378 if ((timing) && (repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +00002379 startTimer();
Daniel Veillardcbaf3992001-12-31 16:16:02 +00002380 /* Remember file names. "-" means stdin. <sven@zen.org> */
Daniel Veillard4a6845d2001-01-03 13:32:39 +00002381 if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002382 if (repeat) {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002383 xmlParserCtxtPtr ctxt = NULL;
2384
2385 for (acount = 0;acount < repeat;acount++) {
Daniel Veillard81273902003-09-30 00:43:48 +00002386#ifdef LIBXML_READER_ENABLED
Daniel Veillard198c1bf2003-10-20 17:07:41 +00002387 if (stream != 0) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00002388 streamFile(argv[i]);
Daniel Veillard198c1bf2003-10-20 17:07:41 +00002389 } else {
Daniel Veillard81273902003-09-30 00:43:48 +00002390#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002391 if (ctxt == NULL)
2392 ctxt = xmlNewParserCtxt();
2393 parseAndPrintFile(argv[i], ctxt);
Daniel Veillard81273902003-09-30 00:43:48 +00002394#ifdef LIBXML_READER_ENABLED
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002395 }
Daniel Veillard81273902003-09-30 00:43:48 +00002396#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002397 }
2398 if (ctxt != NULL)
2399 xmlFreeParserCtxt(ctxt);
Daniel Veillard7704fb12003-01-03 16:19:51 +00002400 } else {
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00002401 nbregister = 0;
2402
Daniel Veillard81273902003-09-30 00:43:48 +00002403#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00002404 if (stream != 0)
2405 streamFile(argv[i]);
2406 else
Daniel Veillard81273902003-09-30 00:43:48 +00002407#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002408 parseAndPrintFile(argv[i], NULL);
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00002409
2410 if ((chkregister) && (nbregister != 0)) {
2411 fprintf(stderr, "Registration count off: %d\n", nbregister);
William M. Brack8304d872004-06-08 13:29:32 +00002412 progresult = XMLLINT_ERR_RDREGIS;
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00002413 }
Daniel Veillard7704fb12003-01-03 16:19:51 +00002414 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002415 files ++;
Daniel Veillarda7866932001-12-04 13:14:44 +00002416 if ((timing) && (repeat)) {
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00002417 endTimer("%d iterations", repeat);
Daniel Veillarda7866932001-12-04 13:14:44 +00002418 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00002419 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002420 }
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00002421 if (generate)
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002422 parseAndPrintFile(NULL, NULL);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002423 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002424 xmlGenericError(xmlGenericErrorContext, "</body></html>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002425 }
Daniel Veillard845cce42002-01-09 11:51:37 +00002426 if ((files == 0) && (!generate) && (version == 0)) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002427 usage(argv[0]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002428 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002429#ifdef LIBXML_SCHEMAS_ENABLED
2430 if (relaxngschemas != NULL)
2431 xmlRelaxNGFree(relaxngschemas);
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002432 if (wxschemas != NULL)
2433 xmlSchemaFree(wxschemas);
Daniel Veillard71531f32003-02-05 13:19:53 +00002434 xmlRelaxNGCleanupTypes();
2435#endif
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002436#ifdef LIBXML_PATTERN_ENABLED
2437 if (patternc != NULL)
2438 xmlFreePattern(patternc);
2439#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002440 xmlCleanupParser();
2441 xmlMemoryDump();
2442
Daniel Veillardf7cd4812001-02-23 18:44:52 +00002443 return(progresult);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002444}
Daniel Veillard88a172f2000-08-04 18:23:10 +00002445