blob: f691daef47e6b20ba9ea6e9eb6b52658c8c7379f [file] [log] [blame]
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001/*
2 * xmllint.c : a small tester program for XML input.
3 *
4 * See Copyright for the status of this software.
5 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00006 * daniel@veillard.com
Daniel Veillardce8b83b2000-04-05 18:38:42 +00007 */
8
Bjorn Reese70a9da52001-04-21 16:57:29 +00009#include "libxml.h"
Daniel Veillardce8b83b2000-04-05 18:38:42 +000010
Daniel Veillardce8b83b2000-04-05 18:38:42 +000011#include <string.h>
Daniel Veillardce8b83b2000-04-05 18:38:42 +000012#include <stdarg.h>
Daniel Veillard8a1b1852003-01-05 22:37:17 +000013#include <assert.h>
14
Daniel Veillard3c5ed912002-01-08 10:36:16 +000015#if defined (_WIN32) && !defined(__CYGWIN__)
Daniel Veillard07cb8222003-09-10 10:51:05 +000016#if defined (_MSC_VER) || defined(__BORLANDC__)
Daniel Veillard2d90de42001-04-16 17:46:18 +000017#include <winsock2.h>
18#pragma comment(lib, "ws2_32.lib")
19#define gettimeofday(p1,p2)
20#endif /* _MSC_VER */
Igor Zlatkovic19b87642003-08-28 12:32:04 +000021#endif /* _WIN32 */
22
Daniel Veillarded472f32001-12-13 08:48:14 +000023#ifdef HAVE_SYS_TIME_H
Daniel Veillard48b2f892001-02-25 16:11:03 +000024#include <sys/time.h>
Daniel Veillarded472f32001-12-13 08:48:14 +000025#endif
Daniel Veillard01db67c2001-12-18 07:09:59 +000026#ifdef HAVE_TIME_H
27#include <time.h>
28#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +000029
Daniel Veillard1638a472003-08-14 01:23:25 +000030#ifdef __MINGW32__
31#define _WINSOCKAPI_
32#include <wsockcompat.h>
33#include <winsock2.h>
34#undef SOCKLEN_T
35#define SOCKLEN_T unsigned int
36#endif
37
Daniel Veillard90bc3712002-03-07 15:12:58 +000038#ifdef HAVE_SYS_TIMEB_H
39#include <sys/timeb.h>
40#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +000041
42#ifdef HAVE_SYS_TYPES_H
43#include <sys/types.h>
44#endif
45#ifdef HAVE_SYS_STAT_H
46#include <sys/stat.h>
47#endif
48#ifdef HAVE_FCNTL_H
49#include <fcntl.h>
50#endif
51#ifdef HAVE_UNISTD_H
52#include <unistd.h>
53#endif
Daniel Veillard46e370e2000-07-21 20:32:03 +000054#ifdef HAVE_SYS_MMAN_H
55#include <sys/mman.h>
Daniel Veillard87b95392000-08-12 21:12:04 +000056/* seems needed for Solaris */
57#ifndef MAP_FAILED
58#define MAP_FAILED ((void *) -1)
59#endif
Daniel Veillard46e370e2000-07-21 20:32:03 +000060#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +000061#ifdef HAVE_STDLIB_H
62#include <stdlib.h>
63#endif
64#ifdef HAVE_LIBREADLINE
65#include <readline/readline.h>
66#ifdef HAVE_LIBHISTORY
67#include <readline/history.h>
68#endif
69#endif
70
71#include <libxml/xmlmemory.h>
72#include <libxml/parser.h>
73#include <libxml/parserInternals.h>
74#include <libxml/HTMLparser.h>
75#include <libxml/HTMLtree.h>
76#include <libxml/tree.h>
77#include <libxml/xpath.h>
78#include <libxml/debugXML.h>
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +000079#include <libxml/xmlerror.h>
Daniel Veillard9e8bfae2000-11-06 16:43:11 +000080#ifdef LIBXML_XINCLUDE_ENABLED
81#include <libxml/xinclude.h>
82#endif
Daniel Veillard81418e32001-05-22 15:08:55 +000083#ifdef LIBXML_CATALOG_ENABLED
84#include <libxml/catalog.h>
85#endif
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000086#include <libxml/globals.h>
Daniel Veillard7704fb12003-01-03 16:19:51 +000087#include <libxml/xmlreader.h>
Daniel Veillard71531f32003-02-05 13:19:53 +000088#ifdef LIBXML_SCHEMAS_ENABLED
89#include <libxml/relaxng.h>
Daniel Veillard75bb3bb2003-05-12 15:25:56 +000090#include <libxml/xmlschemas.h>
Daniel Veillard71531f32003-02-05 13:19:53 +000091#endif
Daniel Veillardb3de70c2003-12-02 22:32:15 +000092#ifdef LIBXML_PATTERN_ENABLED
93#include <libxml/pattern.h>
94#endif
Daniel 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();
698}
699
700/**
701 * xmlHTMLValidityWarning:
702 * @ctx: an XML parser context
703 * @msg: the message to display/transmit
704 * @...: extra parameters for the message display
705 *
706 * Display and format a validity warning messages, gives file, line,
707 * position and extra parameters.
708 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000709static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000710xmlHTMLValidityWarning(void *ctx, const char *msg, ...)
711{
712 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
713 xmlParserInputPtr input;
714 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000715 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000716
717 buffer[0] = 0;
718 input = ctxt->input;
719 if ((input->filename == NULL) && (ctxt->inputNr > 1))
720 input = ctxt->inputTab[ctxt->inputNr - 2];
721
722 xmlHTMLPrintFileInfo(input);
723
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000724 xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000725 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000726 len = strlen(buffer);
727 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000728 va_end(args);
729 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000730 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000731
732 xmlHTMLPrintFileContext(input);
733 xmlHTMLEncodeSend();
734}
735
736/************************************************************************
737 * *
738 * Shell Interface *
739 * *
740 ************************************************************************/
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000741#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardd0cf7f62004-11-09 16:17:02 +0000742#ifdef LIBXML_XPATH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000743/**
744 * xmlShellReadline:
745 * @prompt: the prompt value
746 *
747 * Read a string
748 *
749 * Returns a pointer to it or NULL on EOF the caller is expected to
750 * free the returned string.
751 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000752static char *
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000753xmlShellReadline(char *prompt) {
754#ifdef HAVE_LIBREADLINE
755 char *line_read;
756
757 /* Get a line from the user. */
758 line_read = readline (prompt);
759
760 /* If the line has any text in it, save it on the history. */
761 if (line_read && *line_read)
762 add_history (line_read);
763
764 return (line_read);
765#else
766 char line_read[501];
Daniel Veillard29e43992001-12-13 22:21:58 +0000767 char *ret;
768 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000769
770 if (prompt != NULL)
771 fprintf(stdout, "%s", prompt);
772 if (!fgets(line_read, 500, stdin))
773 return(NULL);
774 line_read[500] = 0;
Daniel Veillard29e43992001-12-13 22:21:58 +0000775 len = strlen(line_read);
776 ret = (char *) malloc(len + 1);
777 if (ret != NULL) {
778 memcpy (ret, line_read, len + 1);
779 }
780 return(ret);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000781#endif
782}
Daniel Veillardd0cf7f62004-11-09 16:17:02 +0000783#endif /* LIBXML_XPATH_ENABLED */
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000784#endif /* LIBXML_DEBUG_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000785
786/************************************************************************
787 * *
Daniel Veillard5e873c42000-04-12 13:27:38 +0000788 * I/O Interfaces *
789 * *
790 ************************************************************************/
791
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000792static int myRead(FILE *f, char * buf, int len) {
793 return(fread(buf, 1, len, f));
Daniel Veillard5e873c42000-04-12 13:27:38 +0000794}
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000795static void myClose(FILE *f) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000796 if (f != stdin) {
Daniel Veillard5e873c42000-04-12 13:27:38 +0000797 fclose(f);
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000798 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000799}
800
Daniel Veillard81273902003-09-30 00:43:48 +0000801#ifdef LIBXML_READER_ENABLED
Daniel Veillard5e873c42000-04-12 13:27:38 +0000802/************************************************************************
803 * *
Daniel Veillard7704fb12003-01-03 16:19:51 +0000804 * Stream Test processing *
805 * *
806 ************************************************************************/
Daniel Veillard7704fb12003-01-03 16:19:51 +0000807static void processNode(xmlTextReaderPtr reader) {
Daniel Veillard198c1bf2003-10-20 17:07:41 +0000808 const xmlChar *name, *value;
Daniel Veillard16ef8002005-01-31 00:27:50 +0000809 int type, empty;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000810
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000811 type = xmlTextReaderNodeType(reader);
Daniel Veillard16ef8002005-01-31 00:27:50 +0000812 empty = xmlTextReaderIsEmptyElement(reader);
Daniel Veillard99737f52003-03-22 14:55:50 +0000813
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000814 if (debug) {
815 name = xmlTextReaderConstName(reader);
816 if (name == NULL)
817 name = BAD_CAST "--";
Daniel Veillard7704fb12003-01-03 16:19:51 +0000818
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000819 value = xmlTextReaderConstValue(reader);
820
821
822 printf("%d %d %s %d %d",
823 xmlTextReaderDepth(reader),
824 type,
825 name,
Daniel Veillard16ef8002005-01-31 00:27:50 +0000826 empty,
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000827 xmlTextReaderHasValue(reader));
828 if (value == NULL)
829 printf("\n");
830 else {
831 printf(" %s\n", value);
832 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000833 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000834#ifdef LIBXML_PATTERN_ENABLED
835 if (patternc) {
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000836 xmlChar *path = NULL;
837 int match = -1;
838
839 if (type == XML_READER_TYPE_ELEMENT) {
840 /* do the check only on element start */
841 match = xmlPatternMatch(patternc, xmlTextReaderCurrentNode(reader));
842
843 if (match) {
844 path = xmlGetNodePath(xmlTextReaderCurrentNode(reader));
845 printf("Node %s matches pattern %s\n", path, pattern);
846 }
847 }
848 if (patstream != NULL) {
849 int ret;
850
851 if (type == XML_READER_TYPE_ELEMENT) {
852 ret = xmlStreamPush(patstream,
853 xmlTextReaderConstLocalName(reader),
854 xmlTextReaderConstNamespaceUri(reader));
855 if (ret < 0) {
856 fprintf(stderr, "xmlStreamPush() failure\n");
857 xmlFreeStreamCtxt(patstream);
858 patstream = NULL;
859 } else if (ret != match) {
860 if (path == NULL) {
861 path = xmlGetNodePath(
862 xmlTextReaderCurrentNode(reader));
863 }
864 fprintf(stderr,
865 "xmlPatternMatch and xmlStreamPush disagree\n");
866 fprintf(stderr,
867 " pattern %s node %s\n",
868 pattern, path);
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000869 }
870
871
Daniel Veillard16ef8002005-01-31 00:27:50 +0000872 }
873 if ((type == XML_READER_TYPE_END_ELEMENT) ||
874 ((type == XML_READER_TYPE_ELEMENT) && (empty))) {
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000875 ret = xmlStreamPop(patstream);
876 if (ret < 0) {
877 fprintf(stderr, "xmlStreamPop() failure\n");
878 xmlFreeStreamCtxt(patstream);
879 patstream = NULL;
880 }
881 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000882 }
Daniel Veillardf9d16912005-01-30 22:36:30 +0000883 if (path != NULL)
884 xmlFree(path);
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000885 }
886#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000887}
888
889static void streamFile(char *filename) {
890 xmlTextReaderPtr reader;
891 int ret;
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000892#ifdef HAVE_SYS_MMAN_H
893 int fd = -1;
894 struct stat info;
895 const char *base = NULL;
896 xmlParserInputBufferPtr input = NULL;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000897
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000898 if (memory) {
899 if (stat(filename, &info) < 0)
900 return;
901 if ((fd = open(filename, O_RDONLY)) < 0)
902 return;
903 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
904 if (base == (void *) MAP_FAILED)
905 return;
906
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000907 reader = xmlReaderForMemory(base, info.st_size, filename,
908 NULL, options);
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000909 } else
910#endif
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000911 reader = xmlReaderForFile(filename, NULL, options);
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000912#ifdef LIBXML_PATTERN_ENABLED
Daniel Veillardd4301ab2005-02-03 22:24:10 +0000913 if (pattern != NULL) {
914 patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL);
915 if (patternc == NULL) {
916 xmlGenericError(xmlGenericErrorContext,
917 "Pattern %s failed to compile\n", pattern);
918 progresult = XMLLINT_ERR_SCHEMAPAT;
919 pattern = NULL;
920 }
921 }
Daniel Veillard2fc6df92005-01-30 18:42:55 +0000922 if (patternc != NULL) {
923 patstream = xmlPatternGetStreamCtxt(patternc);
924 if (patstream != NULL) {
925 ret = xmlStreamPush(patstream, NULL, NULL);
926 if (ret < 0) {
927 fprintf(stderr, "xmlStreamPush() failure\n");
928 xmlFreeStreamCtxt(patstream);
929 patstream = NULL;
930 }
931 }
932 }
933#endif
Daniel Veillard7899c5c2003-11-03 12:31:38 +0000934
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000935
Daniel Veillard7704fb12003-01-03 16:19:51 +0000936 if (reader != NULL) {
Daniel Veillard4432df22003-09-28 18:58:27 +0000937#ifdef LIBXML_VALID_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +0000938 if (valid)
939 xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);
Daniel Veillardce192eb2003-04-16 15:58:05 +0000940 else
Daniel Veillard4432df22003-09-28 18:58:27 +0000941#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardce192eb2003-04-16 15:58:05 +0000942 xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1);
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000943#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardce192eb2003-04-16 15:58:05 +0000944 if (relaxng != NULL) {
Daniel Veillard81514ba2003-09-16 23:17:26 +0000945 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000946 startTimer();
947 }
948 ret = xmlTextReaderRelaxNGValidate(reader, relaxng);
949 if (ret < 0) {
950 xmlGenericError(xmlGenericErrorContext,
951 "Relax-NG schema %s failed to compile\n", relaxng);
William M. Brack8304d872004-06-08 13:29:32 +0000952 progresult = XMLLINT_ERR_SCHEMACOMP;
Daniel Veillardce192eb2003-04-16 15:58:05 +0000953 relaxng = NULL;
954 }
Daniel Veillard81514ba2003-09-16 23:17:26 +0000955 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000956 endTimer("Compiling the schemas");
957 }
958 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000959#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000960
961 /*
962 * Process all nodes in sequence
963 */
Daniel Veillard81514ba2003-09-16 23:17:26 +0000964 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000965 startTimer();
966 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000967 ret = xmlTextReaderRead(reader);
968 while (ret == 1) {
Daniel Veillardb3de70c2003-12-02 22:32:15 +0000969 if ((debug)
970#ifdef LIBXML_PATTERN_ENABLED
971 || (patternc)
972#endif
973 )
Daniel Veillard7704fb12003-01-03 16:19:51 +0000974 processNode(reader);
975 ret = xmlTextReaderRead(reader);
976 }
Daniel Veillard81514ba2003-09-16 23:17:26 +0000977 if ((timing) && (!repeat)) {
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000978#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardf54cd532004-02-25 11:52:31 +0000979 if (relaxng != NULL)
Daniel Veillard49138f12004-02-19 12:58:36 +0000980 endTimer("Parsing and validating");
981 else
Daniel Veillardf54cd532004-02-25 11:52:31 +0000982#endif
Daniel Veillard4432df22003-09-28 18:58:27 +0000983#ifdef LIBXML_VALID_ENABLED
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000984 if (valid)
Daniel Veillardce192eb2003-04-16 15:58:05 +0000985 endTimer("Parsing and validating");
986 else
Daniel Veillard4432df22003-09-28 18:58:27 +0000987#endif
Daniel Veillardf54cd532004-02-25 11:52:31 +0000988 endTimer("Parsing");
Daniel Veillardce192eb2003-04-16 15:58:05 +0000989 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000990
Daniel Veillard4432df22003-09-28 18:58:27 +0000991#ifdef LIBXML_VALID_ENABLED
Daniel Veillardf6bad792003-04-11 19:38:54 +0000992 if (valid) {
993 if (xmlTextReaderIsValid(reader) != 1) {
994 xmlGenericError(xmlGenericErrorContext,
995 "Document %s does not validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +0000996 progresult = XMLLINT_ERR_VALID;
Daniel Veillardf6bad792003-04-11 19:38:54 +0000997 }
998 }
Daniel Veillard4432df22003-09-28 18:58:27 +0000999#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard37fc84d2003-05-09 19:38:15 +00001000#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardf4e55762003-04-15 23:32:22 +00001001 if (relaxng != NULL) {
1002 if (xmlTextReaderIsValid(reader) != 1) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001003 fprintf(stderr, "%s fails to validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001004 progresult = XMLLINT_ERR_VALID;
Daniel Veillardf4e55762003-04-15 23:32:22 +00001005 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001006 fprintf(stderr, "%s validates\n", filename);
Daniel Veillardf4e55762003-04-15 23:32:22 +00001007 }
1008 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +00001009#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +00001010 /*
1011 * Done, cleanup and status
1012 */
1013 xmlFreeTextReader(reader);
1014 if (ret != 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001015 fprintf(stderr, "%s : failed to parse\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001016 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7704fb12003-01-03 16:19:51 +00001017 }
1018 } else {
1019 fprintf(stderr, "Unable to open %s\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001020 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7704fb12003-01-03 16:19:51 +00001021 }
Daniel Veillard2fc6df92005-01-30 18:42:55 +00001022#ifdef LIBXML_PATTERN_ENABLED
1023 if (patstream != NULL) {
1024 xmlFreeStreamCtxt(patstream);
1025 patstream = NULL;
1026 }
1027#endif
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00001028#ifdef HAVE_SYS_MMAN_H
1029 if (memory) {
1030 xmlFreeParserInputBuffer(input);
1031 munmap((char *) base, info.st_size);
1032 close(fd);
1033 }
1034#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +00001035}
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001036
1037static void walkDoc(xmlDocPtr doc) {
1038 xmlTextReaderPtr reader;
1039 int ret;
1040
Daniel Veillardd4301ab2005-02-03 22:24:10 +00001041#ifdef LIBXML_PATTERN_ENABLED
1042 xmlNodePtr root;
1043 const xmlChar *namespaces[22];
1044 int i;
1045 xmlNsPtr ns;
1046
1047 root = xmlDocGetRootElement(doc);
1048 for (ns = root->nsDef, i = 0;ns != NULL && i < 20;ns=ns->next) {
1049 namespaces[i++] = ns->href;
1050 namespaces[i++] = ns->prefix;
1051 }
1052 namespaces[i++] = NULL;
1053 namespaces[i++] = NULL;
1054
1055 if (pattern != NULL) {
1056 patternc = xmlPatterncompile((const xmlChar *) pattern, doc->dict,
1057 0, &namespaces[0]);
1058 if (patternc == NULL) {
1059 xmlGenericError(xmlGenericErrorContext,
1060 "Pattern %s failed to compile\n", pattern);
1061 progresult = XMLLINT_ERR_SCHEMAPAT;
1062 pattern = NULL;
1063 }
1064 }
Daniel Veillard2b2e02d2005-02-05 23:20:22 +00001065 if (patternc != NULL) {
1066 patstream = xmlPatternGetStreamCtxt(patternc);
1067 if (patstream != NULL) {
1068 ret = xmlStreamPush(patstream, NULL, NULL);
1069 if (ret < 0) {
1070 fprintf(stderr, "xmlStreamPush() failure\n");
1071 xmlFreeStreamCtxt(patstream);
1072 patstream = NULL;
1073 }
1074 }
1075 }
Daniel Veillardd4301ab2005-02-03 22:24:10 +00001076#endif /* LIBXML_PATTERN_ENABLED */
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001077 reader = xmlReaderWalker(doc);
1078 if (reader != NULL) {
1079 if ((timing) && (!repeat)) {
1080 startTimer();
1081 }
1082 ret = xmlTextReaderRead(reader);
1083 while (ret == 1) {
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001084 if ((debug)
1085#ifdef LIBXML_PATTERN_ENABLED
1086 || (patternc)
1087#endif
1088 )
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001089 processNode(reader);
1090 ret = xmlTextReaderRead(reader);
1091 }
1092 if ((timing) && (!repeat)) {
1093 endTimer("walking through the doc");
1094 }
1095 xmlFreeTextReader(reader);
1096 if (ret != 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001097 fprintf(stderr, "failed to walk through the doc\n");
William M. Brack8304d872004-06-08 13:29:32 +00001098 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001099 }
1100 } else {
1101 fprintf(stderr, "Failed to crate a reader from the document\n");
William M. Brack8304d872004-06-08 13:29:32 +00001102 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001103 }
Daniel Veillard2b2e02d2005-02-05 23:20:22 +00001104#ifdef LIBXML_PATTERN_ENABLED
1105 if (patstream != NULL) {
1106 xmlFreeStreamCtxt(patstream);
1107 patstream = NULL;
1108 }
1109#endif
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001110}
Daniel Veillard81273902003-09-30 00:43:48 +00001111#endif /* LIBXML_READER_ENABLED */
Daniel Veillard7704fb12003-01-03 16:19:51 +00001112
1113/************************************************************************
1114 * *
1115 * Tree Test processing *
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001116 * *
1117 ************************************************************************/
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001118static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
Daniel Veillard652327a2003-09-29 18:02:38 +00001119 xmlDocPtr doc = NULL;
1120#ifdef LIBXML_TREE_ENABLED
1121 xmlDocPtr tmp;
1122#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001123
Daniel Veillard48b2f892001-02-25 16:11:03 +00001124 if ((timing) && (!repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +00001125 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001126
1127
Daniel Veillard652327a2003-09-29 18:02:38 +00001128#ifdef LIBXML_TREE_ENABLED
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001129 if (filename == NULL) {
1130 if (generate) {
1131 xmlNodePtr n;
1132
1133 doc = xmlNewDoc(BAD_CAST "1.0");
Daniel Veillard95ddcd32004-10-26 21:53:55 +00001134 n = xmlNewDocNode(doc, NULL, BAD_CAST "info", NULL);
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001135 xmlNodeSetContent(n, BAD_CAST "abc");
1136 xmlDocSetRootElement(doc, n);
1137 }
1138 }
Daniel Veillard652327a2003-09-29 18:02:38 +00001139#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001140#ifdef LIBXML_HTML_ENABLED
Daniel Veillard73b013f2003-09-30 12:36:01 +00001141#ifdef LIBXML_PUSH_ENABLED
William M. Brack78637da2003-07-31 14:47:38 +00001142 else if ((html) && (push)) {
1143 FILE *f;
1144
William M. Brack3403add2004-06-27 02:07:51 +00001145#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
1146 f = fopen(filename, "rb");
1147#else
1148 f = fopen(filename, "r");
1149#endif
William M. Brack78637da2003-07-31 14:47:38 +00001150 if (f != NULL) {
1151 int res, size = 3;
1152 char chars[4096];
1153 htmlParserCtxtPtr ctxt;
1154
1155 /* if (repeat) */
1156 size = 4096;
1157 res = fread(chars, 1, 4, f);
1158 if (res > 0) {
1159 ctxt = htmlCreatePushParserCtxt(NULL, NULL,
William M. Brack1d75c8a2003-10-27 13:48:16 +00001160 chars, res, filename, XML_CHAR_ENCODING_NONE);
William M. Brack78637da2003-07-31 14:47:38 +00001161 while ((res = fread(chars, 1, size, f)) > 0) {
1162 htmlParseChunk(ctxt, chars, res, 0);
1163 }
1164 htmlParseChunk(ctxt, chars, 0, 1);
1165 doc = ctxt->myDoc;
1166 htmlFreeParserCtxt(ctxt);
1167 }
1168 fclose(f);
1169 }
1170 }
Daniel Veillard73b013f2003-09-30 12:36:01 +00001171#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001172 else if (html) {
Daniel Veillard9475a352003-09-26 12:47:50 +00001173 doc = htmlReadFile(filename, NULL, options);
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001174 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001175#endif /* LIBXML_HTML_ENABLED */
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001176 else {
Daniel Veillard73b013f2003-09-30 12:36:01 +00001177#ifdef LIBXML_PUSH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001178 /*
1179 * build an XML tree from a string;
1180 */
1181 if (push) {
1182 FILE *f;
1183
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001184 /* '-' Usually means stdin -<sven@zen.org> */
1185 if ((filename[0] == '-') && (filename[1] == 0)) {
1186 f = stdin;
1187 } else {
William M. Brack3403add2004-06-27 02:07:51 +00001188#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
1189 f = fopen(filename, "rb");
1190#else
1191 f = fopen(filename, "r");
1192#endif
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001193 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001194 if (f != NULL) {
Daniel Veillarde715dd22000-08-29 18:29:38 +00001195 int ret;
Daniel Veillarda880b122003-04-21 21:36:41 +00001196 int res, size = 1024;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001197 char chars[1024];
1198 xmlParserCtxtPtr ctxt;
1199
Daniel Veillarda880b122003-04-21 21:36:41 +00001200 /* if (repeat) size = 1024; */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001201 res = fread(chars, 1, 4, f);
1202 if (res > 0) {
1203 ctxt = xmlCreatePushParserCtxt(NULL, NULL,
1204 chars, res, filename);
Daniel Veillard500a1de2004-03-22 15:22:58 +00001205 xmlCtxtUseOptions(ctxt, options);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001206 while ((res = fread(chars, 1, size, f)) > 0) {
1207 xmlParseChunk(ctxt, chars, res, 0);
1208 }
1209 xmlParseChunk(ctxt, chars, 0, 1);
1210 doc = ctxt->myDoc;
Daniel Veillarde715dd22000-08-29 18:29:38 +00001211 ret = ctxt->wellFormed;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001212 xmlFreeParserCtxt(ctxt);
Daniel Veillarde715dd22000-08-29 18:29:38 +00001213 if (!ret) {
1214 xmlFreeDoc(doc);
1215 doc = NULL;
1216 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001217 }
1218 }
Daniel Veillard73b013f2003-09-30 12:36:01 +00001219 } else
1220#endif /* LIBXML_PUSH_ENABLED */
1221 if (testIO) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001222 if ((filename[0] == '-') && (filename[1] == 0)) {
Daniel Veillard60942de2003-09-25 21:05:58 +00001223 doc = xmlReadFd(0, NULL, NULL, options);
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001224 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001225 FILE *f;
Daniel Veillard5e873c42000-04-12 13:27:38 +00001226
William M. Brack3403add2004-06-27 02:07:51 +00001227#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
1228 f = fopen(filename, "rb");
1229#else
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001230 f = fopen(filename, "r");
William M. Brack3403add2004-06-27 02:07:51 +00001231#endif
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001232 if (f != NULL) {
1233 if (rectxt == NULL)
1234 doc = xmlReadIO((xmlInputReadCallback) myRead,
1235 (xmlInputCloseCallback) myClose, f,
Daniel Veillard60942de2003-09-25 21:05:58 +00001236 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001237 else
1238 doc = xmlCtxtReadIO(rectxt,
1239 (xmlInputReadCallback) myRead,
1240 (xmlInputCloseCallback) myClose, f,
Daniel Veillard60942de2003-09-25 21:05:58 +00001241 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001242 } else
Daniel Veillard5e873c42000-04-12 13:27:38 +00001243 doc = NULL;
Daniel Veillard5e873c42000-04-12 13:27:38 +00001244 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001245 } else if (htmlout) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001246 xmlParserCtxtPtr ctxt;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001247
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001248 if (rectxt == NULL)
1249 ctxt = xmlNewParserCtxt();
1250 else
1251 ctxt = rectxt;
Daniel Veillard88a172f2000-08-04 18:23:10 +00001252 if (ctxt == NULL) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001253 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +00001254 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001255 ctxt->sax->error = xmlHTMLError;
1256 ctxt->sax->warning = xmlHTMLWarning;
1257 ctxt->vctxt.error = xmlHTMLValidityError;
1258 ctxt->vctxt.warning = xmlHTMLValidityWarning;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001259
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001260 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001261
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001262 if (rectxt == NULL)
1263 xmlFreeParserCtxt(ctxt);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001264 }
Daniel Veillard46e370e2000-07-21 20:32:03 +00001265#ifdef HAVE_SYS_MMAN_H
1266 } else if (memory) {
1267 int fd;
1268 struct stat info;
1269 const char *base;
1270 if (stat(filename, &info) < 0)
1271 return;
1272 if ((fd = open(filename, O_RDONLY)) < 0)
1273 return;
1274 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
Daniel Veillard29579362000-08-14 17:57:48 +00001275 if (base == (void *) MAP_FAILED)
Daniel Veillard46e370e2000-07-21 20:32:03 +00001276 return;
1277
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001278 if (rectxt == NULL)
Daniel Veillard60942de2003-09-25 21:05:58 +00001279 doc = xmlReadMemory((char *) base, info.st_size,
1280 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001281 else
Daniel Veillard60942de2003-09-25 21:05:58 +00001282 doc = xmlCtxtReadMemory(rectxt, (char *) base, info.st_size,
1283 filename, NULL, options);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001284
Daniel Veillard46e370e2000-07-21 20:32:03 +00001285 munmap((char *) base, info.st_size);
1286#endif
Daniel Veillard4432df22003-09-28 18:58:27 +00001287#ifdef LIBXML_VALID_ENABLED
Daniel Veillardea7751d2002-12-20 00:16:24 +00001288 } else if (valid) {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001289 xmlParserCtxtPtr ctxt = NULL;
Daniel Veillardea7751d2002-12-20 00:16:24 +00001290
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001291 if (rectxt == NULL)
1292 ctxt = xmlNewParserCtxt();
1293 else
1294 ctxt = rectxt;
Daniel Veillardea7751d2002-12-20 00:16:24 +00001295 if (ctxt == NULL) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001296 doc = NULL;
Daniel Veillardea7751d2002-12-20 00:16:24 +00001297 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001298 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
1299
1300 if (ctxt->valid == 0)
William M. Brack8304d872004-06-08 13:29:32 +00001301 progresult = XMLLINT_ERR_RDFILE;
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001302 if (rectxt == NULL)
1303 xmlFreeParserCtxt(ctxt);
Daniel Veillardea7751d2002-12-20 00:16:24 +00001304 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001305#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardea7751d2002-12-20 00:16:24 +00001306 } else {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001307 if (rectxt != NULL)
1308 doc = xmlCtxtReadFile(rectxt, filename, NULL, options);
1309 else
1310 doc = xmlReadFile(filename, NULL, options);
Daniel Veillardea7751d2002-12-20 00:16:24 +00001311 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001312 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001313
Daniel Veillard88a172f2000-08-04 18:23:10 +00001314 /*
1315 * If we don't have a document we might as well give up. Do we
1316 * want an error message here? <sven@zen.org> */
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001317 if (doc == NULL) {
William M. Brack8304d872004-06-08 13:29:32 +00001318 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard88a172f2000-08-04 18:23:10 +00001319 return;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001320 }
1321
Daniel Veillard48b2f892001-02-25 16:11:03 +00001322 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001323 endTimer("Parsing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001324 }
1325
Daniel Veillard29e43992001-12-13 22:21:58 +00001326 /*
1327 * Remove DOCTYPE nodes
1328 */
1329 if (dropdtd) {
1330 xmlDtdPtr dtd;
1331
1332 dtd = xmlGetIntSubset(doc);
1333 if (dtd != NULL) {
1334 xmlUnlinkNode((xmlNodePtr)dtd);
1335 xmlFreeDtd(dtd);
1336 }
1337 }
1338
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001339#ifdef LIBXML_XINCLUDE_ENABLED
Daniel Veillard48b2f892001-02-25 16:11:03 +00001340 if (xinclude) {
1341 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001342 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001343 }
William M. Brack4e1c2db2005-02-11 10:58:55 +00001344 if (xmlXIncludeProcessFlags(doc, options) < 0)
1345 progresult = XMLLINT_ERR_UNCLASS;
Daniel Veillard48b2f892001-02-25 16:11:03 +00001346 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001347 endTimer("Xinclude processing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001348 }
1349 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001350#endif
Daniel Veillard88a172f2000-08-04 18:23:10 +00001351
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001352#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardd0cf7f62004-11-09 16:17:02 +00001353#ifdef LIBXML_XPATH_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001354 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001355 * shell interaction
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001356 */
1357 if (shell)
1358 xmlShell(doc, filename, xmlShellReadline, stdout);
1359#endif
Daniel Veillardd0cf7f62004-11-09 16:17:02 +00001360#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001361
Daniel Veillard652327a2003-09-29 18:02:38 +00001362#ifdef LIBXML_TREE_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001363 /*
1364 * test intermediate copy if needed.
1365 */
1366 if (copy) {
1367 tmp = doc;
Daniel Veillard4edd3ed2004-09-20 20:03:01 +00001368 if (timing) {
1369 startTimer();
1370 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001371 doc = xmlCopyDoc(doc, 1);
Daniel Veillard4edd3ed2004-09-20 20:03:01 +00001372 if (timing) {
1373 endTimer("Copying");
1374 }
1375 if (timing) {
1376 startTimer();
1377 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001378 xmlFreeDoc(tmp);
Daniel Veillard4edd3ed2004-09-20 20:03:01 +00001379 if (timing) {
1380 endTimer("Freeing original");
1381 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001382 }
Daniel Veillard652327a2003-09-29 18:02:38 +00001383#endif /* LIBXML_TREE_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001384
Daniel Veillard4432df22003-09-28 18:58:27 +00001385#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001386 if ((insert) && (!html)) {
1387 const xmlChar* list[256];
1388 int nb, i;
1389 xmlNodePtr node;
1390
1391 if (doc->children != NULL) {
1392 node = doc->children;
1393 while ((node != NULL) && (node->last == NULL)) node = node->next;
1394 if (node != NULL) {
1395 nb = xmlValidGetValidElements(node->last, NULL, list, 256);
1396 if (nb < 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001397 fprintf(stderr, "could not get valid list of elements\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001398 } else if (nb == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001399 fprintf(stderr, "No element can be inserted under root\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001400 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001401 fprintf(stderr, "%d element types can be inserted under root:\n",
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001402 nb);
1403 for (i = 0;i < nb;i++) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001404 fprintf(stderr, "%s\n", (char *) list[i]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001405 }
1406 }
1407 }
1408 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001409 }else
1410#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001411#ifdef LIBXML_READER_ENABLED
1412 if (walker) {
1413 walkDoc(doc);
1414 }
1415#endif /* LIBXML_READER_ENABLED */
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001416#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard4432df22003-09-28 18:58:27 +00001417 if (noout == 0) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001418 int ret;
1419
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001420 /*
1421 * print it.
1422 */
1423#ifdef LIBXML_DEBUG_ENABLED
1424 if (!debug) {
1425#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +00001426 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001427 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001428 }
Daniel Veillard656ce942004-04-30 23:11:45 +00001429#ifdef LIBXML_HTML_ENABLED
Daniel Veillard42fd4122003-11-04 08:47:48 +00001430 if ((html) && (!xmlout)) {
1431 if (compress) {
1432 htmlSaveFile(output ? output : "-", doc);
1433 }
1434 else if (encoding != NULL) {
1435 if ( format ) {
1436 htmlSaveFileFormat(output ? output : "-", doc, encoding, 1);
1437 }
1438 else {
1439 htmlSaveFileFormat(output ? output : "-", doc, encoding, 0);
1440 }
1441 }
1442 else if (format) {
1443 htmlSaveFileFormat(output ? output : "-", doc, NULL, 1);
1444 }
1445 else {
1446 FILE *out;
1447 if (output == NULL)
1448 out = stdout;
1449 else {
1450 out = fopen(output,"wb");
1451 }
1452 if (out != NULL) {
1453 if (htmlDocDump(out, doc) < 0)
William M. Brack8304d872004-06-08 13:29:32 +00001454 progresult = XMLLINT_ERR_OUT;
Daniel Veillard42fd4122003-11-04 08:47:48 +00001455
1456 if (output != NULL)
1457 fclose(out);
1458 } else {
1459 fprintf(stderr, "failed to open %s\n", output);
William M. Brack8304d872004-06-08 13:29:32 +00001460 progresult = XMLLINT_ERR_OUT;
Daniel Veillard42fd4122003-11-04 08:47:48 +00001461 }
1462 }
1463 if ((timing) && (!repeat)) {
1464 endTimer("Saving");
1465 }
1466 } else
1467#endif
Daniel Veillard25048d82004-08-14 22:37:54 +00001468#ifdef LIBXML_C14N_ENABLED
1469 if (canonical) {
1470 xmlChar *result = NULL;
1471 int size;
1472
1473 size = xmlC14NDocDumpMemory(doc, NULL, 0, NULL, 1, &result);
1474 if (size >= 0) {
1475 write(1, result, size);
1476 xmlFree(result);
1477 } else {
1478 fprintf(stderr, "Failed to canonicalize\n");
1479 progresult = XMLLINT_ERR_OUT;
1480 }
1481 } else
1482#endif
Daniel Veillard3b2c2612001-04-04 00:09:00 +00001483#ifdef HAVE_SYS_MMAN_H
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001484 if (memory) {
1485 xmlChar *result;
1486 int len;
1487
1488 if (encoding != NULL) {
Daniel Veillardd536f702001-11-08 17:32:47 +00001489 if ( format ) {
1490 xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1);
1491 } else {
1492 xmlDocDumpMemoryEnc(doc, &result, &len, encoding);
1493 }
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001494 } else {
Daniel Veillard90493a92001-08-14 14:12:47 +00001495 if (format)
1496 xmlDocDumpFormatMemory(doc, &result, &len, 1);
1497 else
1498 xmlDocDumpMemory(doc, &result, &len);
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001499 }
1500 if (result == NULL) {
1501 fprintf(stderr, "Failed to save\n");
Daniel Veillard25048d82004-08-14 22:37:54 +00001502 progresult = XMLLINT_ERR_OUT;
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001503 } else {
1504 write(1, result, len);
1505 xmlFree(result);
1506 }
Daniel Veillard3b2c2612001-04-04 00:09:00 +00001507 } else
1508#endif /* HAVE_SYS_MMAN_H */
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001509 if (compress) {
1510 xmlSaveFile(output ? output : "-", doc);
1511 }
Daniel Veillardd536f702001-11-08 17:32:47 +00001512 else if (encoding != NULL) {
1513 if ( format ) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001514 ret = xmlSaveFormatFileEnc(output ? output : "-", doc,
1515 encoding, 1);
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001516 }
Daniel Veillardd536f702001-11-08 17:32:47 +00001517 else {
Daniel Veillard3df01182003-12-10 10:17:51 +00001518 ret = xmlSaveFileEnc(output ? output : "-", doc, encoding);
1519 }
1520 if (ret < 0) {
1521 fprintf(stderr, "failed save to %s\n",
1522 output ? output : "-");
William M. Brack8304d872004-06-08 13:29:32 +00001523 progresult = XMLLINT_ERR_OUT;
Daniel Veillardd536f702001-11-08 17:32:47 +00001524 }
1525 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001526 else if (format) {
Daniel Veillard3df01182003-12-10 10:17:51 +00001527 ret = xmlSaveFormatFile(output ? output : "-", doc, 1);
1528 if (ret < 0) {
1529 fprintf(stderr, "failed save to %s\n",
1530 output ? output : "-");
William M. Brack8304d872004-06-08 13:29:32 +00001531 progresult = XMLLINT_ERR_OUT;
Daniel Veillard3df01182003-12-10 10:17:51 +00001532 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001533 }
1534 else {
1535 FILE *out;
1536 if (output == NULL)
1537 out = stdout;
1538 else {
1539 out = fopen(output,"wb");
1540 }
Daniel Veillard05d987b2003-10-08 11:54:57 +00001541 if (out != NULL) {
Daniel Veillard828ce832003-10-08 19:19:10 +00001542 if (xmlDocDump(out, doc) < 0)
William M. Brack8304d872004-06-08 13:29:32 +00001543 progresult = XMLLINT_ERR_OUT;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001544
Daniel Veillard05d987b2003-10-08 11:54:57 +00001545 if (output != NULL)
1546 fclose(out);
1547 } else {
1548 fprintf(stderr, "failed to open %s\n", output);
William M. Brack8304d872004-06-08 13:29:32 +00001549 progresult = XMLLINT_ERR_OUT;
Daniel Veillard05d987b2003-10-08 11:54:57 +00001550 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001551 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001552 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001553 endTimer("Saving");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001554 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001555#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001556 } else {
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001557 FILE *out;
1558 if (output == NULL)
1559 out = stdout;
1560 else {
1561 out = fopen(output,"wb");
1562 }
Daniel Veillard05d987b2003-10-08 11:54:57 +00001563 if (out != NULL) {
1564 xmlDebugDumpDocument(out, doc);
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001565
Daniel Veillard05d987b2003-10-08 11:54:57 +00001566 if (output != NULL)
1567 fclose(out);
1568 } else {
1569 fprintf(stderr, "failed to open %s\n", output);
William M. Brack8304d872004-06-08 13:29:32 +00001570 progresult = XMLLINT_ERR_OUT;
Daniel Veillard05d987b2003-10-08 11:54:57 +00001571 }
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001572 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001573#endif
1574 }
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001575#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001576
Daniel Veillard4432df22003-09-28 18:58:27 +00001577#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001578 /*
1579 * A posteriori validation test
1580 */
Daniel Veillard66f68e72003-08-18 16:39:51 +00001581 if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) {
Daniel Veillardcd429612000-10-11 15:57:05 +00001582 xmlDtdPtr dtd;
1583
Daniel Veillard48b2f892001-02-25 16:11:03 +00001584 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001585 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001586 }
Daniel Veillard66f68e72003-08-18 16:39:51 +00001587 if (dtdvalid != NULL)
1588 dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid);
1589 else
1590 dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001591 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001592 endTimer("Parsing DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001593 }
Daniel Veillardcd429612000-10-11 15:57:05 +00001594 if (dtd == NULL) {
Daniel Veillard66f68e72003-08-18 16:39:51 +00001595 if (dtdvalid != NULL)
1596 xmlGenericError(xmlGenericErrorContext,
1597 "Could not parse DTD %s\n", dtdvalid);
1598 else
1599 xmlGenericError(xmlGenericErrorContext,
1600 "Could not parse DTD %s\n", dtdvalidfpi);
William M. Brack8304d872004-06-08 13:29:32 +00001601 progresult = XMLLINT_ERR_DTD;
Daniel Veillardcd429612000-10-11 15:57:05 +00001602 } else {
Daniel Veillarda37aab82003-06-09 09:10:36 +00001603 xmlValidCtxtPtr cvp;
1604
1605 if ((cvp = xmlNewValidCtxt()) == NULL) {
1606 xmlGenericError(xmlGenericErrorContext,
1607 "Couldn't allocate validation context\n");
1608 exit(-1);
1609 }
1610 cvp->userData = (void *) stderr;
1611 cvp->error = (xmlValidityErrorFunc) fprintf;
1612 cvp->warning = (xmlValidityWarningFunc) fprintf;
1613
Daniel Veillard48b2f892001-02-25 16:11:03 +00001614 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001615 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001616 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001617 if (!xmlValidateDtd(cvp, doc, dtd)) {
Daniel Veillard66f68e72003-08-18 16:39:51 +00001618 if (dtdvalid != NULL)
1619 xmlGenericError(xmlGenericErrorContext,
1620 "Document %s does not validate against %s\n",
1621 filename, dtdvalid);
1622 else
1623 xmlGenericError(xmlGenericErrorContext,
1624 "Document %s does not validate against %s\n",
1625 filename, dtdvalidfpi);
William M. Brack8304d872004-06-08 13:29:32 +00001626 progresult = XMLLINT_ERR_VALID;
Daniel Veillardcd429612000-10-11 15:57:05 +00001627 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001628 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001629 endTimer("Validating against DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001630 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001631 xmlFreeValidCtxt(cvp);
Daniel Veillardcd429612000-10-11 15:57:05 +00001632 xmlFreeDtd(dtd);
1633 }
1634 } else if (postvalid) {
Daniel Veillarda37aab82003-06-09 09:10:36 +00001635 xmlValidCtxtPtr cvp;
1636
1637 if ((cvp = xmlNewValidCtxt()) == NULL) {
1638 xmlGenericError(xmlGenericErrorContext,
1639 "Couldn't allocate validation context\n");
1640 exit(-1);
1641 }
1642
Daniel Veillard48b2f892001-02-25 16:11:03 +00001643 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001644 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001645 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001646 cvp->userData = (void *) stderr;
1647 cvp->error = (xmlValidityErrorFunc) fprintf;
1648 cvp->warning = (xmlValidityWarningFunc) fprintf;
1649 if (!xmlValidateDocument(cvp, doc)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001650 xmlGenericError(xmlGenericErrorContext,
1651 "Document %s does not validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001652 progresult = XMLLINT_ERR_VALID;
Daniel Veillardcd429612000-10-11 15:57:05 +00001653 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001654 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001655 endTimer("Validating");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001656 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001657 xmlFreeValidCtxt(cvp);
Daniel Veillard4432df22003-09-28 18:58:27 +00001658 }
1659#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard71531f32003-02-05 13:19:53 +00001660#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard4432df22003-09-28 18:58:27 +00001661 if (relaxngschemas != NULL) {
Daniel Veillard71531f32003-02-05 13:19:53 +00001662 xmlRelaxNGValidCtxtPtr ctxt;
1663 int ret;
1664
Daniel Veillard42f12e92003-03-07 18:32:59 +00001665 if ((timing) && (!repeat)) {
1666 startTimer();
1667 }
1668
Daniel Veillard71531f32003-02-05 13:19:53 +00001669 ctxt = xmlRelaxNGNewValidCtxt(relaxngschemas);
1670 xmlRelaxNGSetValidErrors(ctxt,
1671 (xmlRelaxNGValidityErrorFunc) fprintf,
1672 (xmlRelaxNGValidityWarningFunc) fprintf,
1673 stderr);
1674 ret = xmlRelaxNGValidateDoc(ctxt, doc);
1675 if (ret == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001676 fprintf(stderr, "%s validates\n", filename);
Daniel Veillard71531f32003-02-05 13:19:53 +00001677 } else if (ret > 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001678 fprintf(stderr, "%s fails to validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001679 progresult = XMLLINT_ERR_VALID;
Daniel Veillard71531f32003-02-05 13:19:53 +00001680 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001681 fprintf(stderr, "%s validation generated an internal error\n",
Daniel Veillard71531f32003-02-05 13:19:53 +00001682 filename);
William M. Brack8304d872004-06-08 13:29:32 +00001683 progresult = XMLLINT_ERR_VALID;
Daniel Veillard71531f32003-02-05 13:19:53 +00001684 }
1685 xmlRelaxNGFreeValidCtxt(ctxt);
Daniel Veillard42f12e92003-03-07 18:32:59 +00001686 if ((timing) && (!repeat)) {
1687 endTimer("Validating");
1688 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001689 } else if (wxschemas != NULL) {
1690 xmlSchemaValidCtxtPtr ctxt;
1691 int ret;
1692
1693 if ((timing) && (!repeat)) {
1694 startTimer();
1695 }
1696
1697 ctxt = xmlSchemaNewValidCtxt(wxschemas);
1698 xmlSchemaSetValidErrors(ctxt,
1699 (xmlSchemaValidityErrorFunc) fprintf,
1700 (xmlSchemaValidityWarningFunc) fprintf,
1701 stderr);
1702 ret = xmlSchemaValidateDoc(ctxt, doc);
1703 if (ret == 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001704 fprintf(stderr, "%s validates\n", filename);
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001705 } else if (ret > 0) {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001706 fprintf(stderr, "%s fails to validate\n", filename);
William M. Brack8304d872004-06-08 13:29:32 +00001707 progresult = XMLLINT_ERR_VALID;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001708 } else {
Daniel Veillardd21f61b2003-12-29 10:31:21 +00001709 fprintf(stderr, "%s validation generated an internal error\n",
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001710 filename);
William M. Brack8304d872004-06-08 13:29:32 +00001711 progresult = XMLLINT_ERR_VALID;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001712 }
1713 xmlSchemaFreeValidCtxt(ctxt);
1714 if ((timing) && (!repeat)) {
1715 endTimer("Validating");
1716 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001717 }
Daniel Veillard4432df22003-09-28 18:58:27 +00001718#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001719
1720#ifdef LIBXML_DEBUG_ENABLED
1721 if ((debugent) && (!html))
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001722 xmlDebugDumpEntities(stderr, doc);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001723#endif
1724
1725 /*
1726 * free it.
1727 */
Daniel Veillard48b2f892001-02-25 16:11:03 +00001728 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001729 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001730 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001731 xmlFreeDoc(doc);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001732 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001733 endTimer("Freeing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001734 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001735}
1736
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001737/************************************************************************
1738 * *
1739 * Usage and Main *
1740 * *
1741 ************************************************************************/
1742
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001743static void showVersion(const char *name) {
1744 fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion);
1745 fprintf(stderr, " compiled with: ");
Daniel Veillard4432df22003-09-28 18:58:27 +00001746#ifdef LIBXML_VALID_ENABLED
1747 fprintf(stderr, "DTDValid ");
1748#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001749#ifdef LIBXML_FTP_ENABLED
1750 fprintf(stderr, "FTP ");
1751#endif
1752#ifdef LIBXML_HTTP_ENABLED
1753 fprintf(stderr, "HTTP ");
1754#endif
1755#ifdef LIBXML_HTML_ENABLED
1756 fprintf(stderr, "HTML ");
1757#endif
1758#ifdef LIBXML_C14N_ENABLED
1759 fprintf(stderr, "C14N ");
1760#endif
1761#ifdef LIBXML_CATALOG_ENABLED
1762 fprintf(stderr, "Catalog ");
1763#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001764#ifdef LIBXML_XPATH_ENABLED
1765 fprintf(stderr, "XPath ");
1766#endif
1767#ifdef LIBXML_XPTR_ENABLED
1768 fprintf(stderr, "XPointer ");
1769#endif
1770#ifdef LIBXML_XINCLUDE_ENABLED
1771 fprintf(stderr, "XInclude ");
1772#endif
1773#ifdef LIBXML_ICONV_ENABLED
1774 fprintf(stderr, "Iconv ");
1775#endif
1776#ifdef DEBUG_MEMORY_LOCATION
1777 fprintf(stderr, "MemDebug ");
1778#endif
1779#ifdef LIBXML_UNICODE_ENABLED
1780 fprintf(stderr, "Unicode ");
1781#endif
1782#ifdef LIBXML_REGEXP_ENABLED
1783 fprintf(stderr, "Regexps ");
1784#endif
1785#ifdef LIBXML_AUTOMATA_ENABLED
1786 fprintf(stderr, "Automata ");
1787#endif
1788#ifdef LIBXML_SCHEMAS_ENABLED
1789 fprintf(stderr, "Schemas ");
1790#endif
Daniel Veillardce1648b2005-01-04 15:10:22 +00001791#ifdef LIBXML_MODULES_ENABLED
1792 fprintf(stderr, "Modules ");
1793#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001794 fprintf(stderr, "\n");
1795}
1796
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001797static void usage(const char *name) {
1798 printf("Usage : %s [options] XMLfiles ...\n", name);
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001799#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001800 printf("\tParse the XML files and output the result of the parsing\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001801#else
1802 printf("\tParse the XML files\n");
1803#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001804 printf("\t--version : display the version of the XML library used\n");
1805#ifdef LIBXML_DEBUG_ENABLED
1806 printf("\t--debug : dump a debug tree of the in-memory document\n");
1807 printf("\t--shell : run a navigating shell\n");
1808 printf("\t--debugent : debug the entities defined in the document\n");
Daniel Veillard8326e732003-01-07 00:19:07 +00001809#else
Daniel Veillard81273902003-09-30 00:43:48 +00001810#ifdef LIBXML_READER_ENABLED
Daniel Veillard8326e732003-01-07 00:19:07 +00001811 printf("\t--debug : dump the nodes content when using --stream\n");
Daniel Veillard81273902003-09-30 00:43:48 +00001812#endif /* LIBXML_READER_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001813#endif
Daniel Veillard652327a2003-09-29 18:02:38 +00001814#ifdef LIBXML_TREE_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001815 printf("\t--copy : used to test the internal copy implementation\n");
Daniel Veillard652327a2003-09-29 18:02:38 +00001816#endif /* LIBXML_TREE_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001817 printf("\t--recover : output what was parsable on broken XML documents\n");
1818 printf("\t--noent : substitute entity references by their value\n");
1819 printf("\t--noout : don't output the result tree\n");
Daniel Veillard0bff36d2004-08-31 09:37:03 +00001820 printf("\t--path 'paths': provide a set of paths for resources\n");
1821 printf("\t--load-trace : print trace of all external entites loaded\n");
Daniel Veillarde8b09e42003-05-13 22:14:13 +00001822 printf("\t--nonet : refuse to fetch DTDs or entities over network\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001823 printf("\t--htmlout : output results as HTML\n");
Daniel Veillard05c13a22001-09-09 08:38:09 +00001824 printf("\t--nowrap : do not put HTML doc wrapper\n");
Daniel Veillard4432df22003-09-28 18:58:27 +00001825#ifdef LIBXML_VALID_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001826 printf("\t--valid : validate the document in addition to std well-formed check\n");
1827 printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
1828 printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
Daniel Veillard66f68e72003-08-18 16:39:51 +00001829 printf("\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
Daniel Veillard4432df22003-09-28 18:58:27 +00001830#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001831 printf("\t--timing : print some timings\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001832 printf("\t--output file or -o file: save to a given file\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001833 printf("\t--repeat : repeat 100 times, for timing or profiling\n");
1834 printf("\t--insert : ad-hoc test for valid insertions\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001835#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001836#ifdef HAVE_ZLIB_H
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001837 printf("\t--compress : turn on gzip compression of output\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001838#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001839#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001840#ifdef LIBXML_HTML_ENABLED
1841 printf("\t--html : use the HTML parser\n");
Daniel Veillard42fd4122003-11-04 08:47:48 +00001842 printf("\t--xmlout : force to use the XML serializer when using --html\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001843#endif
Daniel Veillard73b013f2003-09-30 12:36:01 +00001844#ifdef LIBXML_PUSH_ENABLED
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001845 printf("\t--push : use the push mode of the parser\n");
Daniel Veillard73b013f2003-09-30 12:36:01 +00001846#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001847#ifdef HAVE_SYS_MMAN_H
1848 printf("\t--memory : parse from memory\n");
1849#endif
Daniel Veillard87076042004-05-03 22:54:49 +00001850 printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001851 printf("\t--nowarning : do not emit warnings from parser/validator\n");
1852 printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
Daniel Veillarddca8cc72003-09-26 13:53:14 +00001853 printf("\t--nocdata : replace cdata section with text nodes\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001854#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard90493a92001-08-14 14:12:47 +00001855 printf("\t--format : reformat/reindent the input\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001856 printf("\t--encode encoding : output in the given encoding\n");
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001857 printf("\t--dropdtd : remove the DOCTYPE of the input docs\n");
1858#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard25048d82004-08-14 22:37:54 +00001859 printf("\t--c14n: save in W3C canonical format (with comments)\n");
1860#ifdef LIBXML_C14N_ENABLED
1861#endif /* LIBXML_C14N_ENABLED */
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001862 printf("\t--nsclean : remove redundant namespace declarations\n");
1863 printf("\t--testIO : test user I/O support\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001864#ifdef LIBXML_CATALOG_ENABLED
Daniel Veillardbd9b0e82001-11-26 10:32:08 +00001865 printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");
1866 printf("\t otherwise XML Catalogs starting from \n");
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001867 printf("\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG);
Daniel Veillard05c13a22001-09-09 08:38:09 +00001868 printf("\t--nocatalogs: deactivate all catalogs\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001869#endif
1870 printf("\t--auto : generate a small doc on the fly\n");
1871#ifdef LIBXML_XINCLUDE_ENABLED
1872 printf("\t--xinclude : do XInclude processing\n");
Daniel Veillardc14c3892004-08-16 12:34:50 +00001873 printf("\t--noxincludenode : same but do not generate XInclude nodes\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001874#endif
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001875 printf("\t--loaddtd : fetch external DTD\n");
Daniel Veillard48da9102001-08-07 01:10:10 +00001876 printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
Daniel Veillard81273902003-09-30 00:43:48 +00001877#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00001878 printf("\t--stream : use the streaming interface to process very large files\n");
Daniel Veillard7899c5c2003-11-03 12:31:38 +00001879 printf("\t--walker : create a reader and walk though the resulting doc\n");
Daniel Veillard81273902003-09-30 00:43:48 +00001880#endif /* LIBXML_READER_ENABLED */
Daniel Veillardb3de70c2003-12-02 22:32:15 +00001881#ifdef LIBXML_PATTERN_ENABLED
1882 printf("\t--pattern pattern_value : test the pattern support\n");
1883#endif
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001884 printf("\t--chkregister : verify the node registration code\n");
Daniel Veillardef4d3bc2003-02-07 12:38:22 +00001885#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard71531f32003-02-05 13:19:53 +00001886 printf("\t--relaxng schema : do RelaxNG validation against the schema\n");
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001887 printf("\t--schema schema : do validation against the WXS schema\n");
Daniel Veillard71531f32003-02-05 13:19:53 +00001888#endif
Daniel Veillarda42f25f2002-01-25 14:15:40 +00001889 printf("\nLibxml project home page: http://xmlsoft.org/\n");
1890 printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001891}
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001892
1893static void registerNode(xmlNodePtr node)
1894{
1895 node->_private = malloc(sizeof(long));
1896 *(long*)node->_private = (long) 0x81726354;
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00001897 nbregister++;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001898}
1899
1900static void deregisterNode(xmlNodePtr node)
1901{
1902 assert(node->_private != NULL);
1903 assert(*(long*)node->_private == (long) 0x81726354);
1904 free(node->_private);
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00001905 nbregister--;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001906}
1907
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001908int
1909main(int argc, char **argv) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00001910 int i, acount;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001911 int files = 0;
Daniel Veillard845cce42002-01-09 11:51:37 +00001912 int version = 0;
Aleksey Sanin693c9bc2003-03-09 22:36:52 +00001913 const char* indent;
1914
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001915 if (argc <= 1) {
1916 usage(argv[0]);
1917 return(1);
1918 }
Daniel Veillardbe803962000-06-28 23:40:59 +00001919 LIBXML_TEST_VERSION
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001920 for (i = 1; i < argc ; i++) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001921 if (!strcmp(argv[i], "-"))
1922 break;
1923
1924 if (argv[i][0] != '-')
1925 continue;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001926 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
1927 debug++;
Daniel Veillard56ada1d2003-01-07 11:17:25 +00001928 else
1929#ifdef LIBXML_DEBUG_ENABLED
1930 if ((!strcmp(argv[i], "-shell")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001931 (!strcmp(argv[i], "--shell"))) {
1932 shell++;
1933 noout = 1;
1934 } else
1935#endif
Daniel Veillard652327a2003-09-29 18:02:38 +00001936#ifdef LIBXML_TREE_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001937 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
1938 copy++;
Daniel Veillard652327a2003-09-29 18:02:38 +00001939 else
1940#endif /* LIBXML_TREE_ENABLED */
1941 if ((!strcmp(argv[i], "-recover")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001942 (!strcmp(argv[i], "--recover"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001943 recovery++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001944 options |= XML_PARSE_RECOVER;
1945 } else if ((!strcmp(argv[i], "-noent")) ||
1946 (!strcmp(argv[i], "--noent"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001947 noent++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001948 options |= XML_PARSE_NOENT;
Daniel Veillarddca8cc72003-09-26 13:53:14 +00001949 } else if ((!strcmp(argv[i], "-nsclean")) ||
1950 (!strcmp(argv[i], "--nsclean"))) {
1951 options |= XML_PARSE_NSCLEAN;
1952 } else if ((!strcmp(argv[i], "-nocdata")) ||
1953 (!strcmp(argv[i], "--nocdata"))) {
1954 options |= XML_PARSE_NOCDATA;
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001955 } else if ((!strcmp(argv[i], "-nodict")) ||
1956 (!strcmp(argv[i], "--nodict"))) {
1957 options |= XML_PARSE_NODICT;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001958 } else if ((!strcmp(argv[i], "-version")) ||
Daniel Veillard845cce42002-01-09 11:51:37 +00001959 (!strcmp(argv[i], "--version"))) {
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001960 showVersion(argv[0]);
Daniel Veillard845cce42002-01-09 11:51:37 +00001961 version = 1;
1962 } else if ((!strcmp(argv[i], "-noout")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001963 (!strcmp(argv[i], "--noout")))
1964 noout++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001965#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001966 else if ((!strcmp(argv[i], "-o")) ||
1967 (!strcmp(argv[i], "-output")) ||
1968 (!strcmp(argv[i], "--output"))) {
1969 i++;
Daniel Veillard6e4f1c02002-04-09 09:55:20 +00001970 output = argv[i];
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001971 }
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001972#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001973 else if ((!strcmp(argv[i], "-htmlout")) ||
1974 (!strcmp(argv[i], "--htmlout")))
1975 htmlout++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00001976 else if ((!strcmp(argv[i], "-nowrap")) ||
1977 (!strcmp(argv[i], "--nowrap")))
1978 nowrap++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001979#ifdef LIBXML_HTML_ENABLED
1980 else if ((!strcmp(argv[i], "-html")) ||
1981 (!strcmp(argv[i], "--html"))) {
1982 html++;
1983 }
Daniel Veillard42fd4122003-11-04 08:47:48 +00001984 else if ((!strcmp(argv[i], "-xmlout")) ||
1985 (!strcmp(argv[i], "--xmlout"))) {
1986 xmlout++;
1987 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001988#endif /* LIBXML_HTML_ENABLED */
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001989 else if ((!strcmp(argv[i], "-loaddtd")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001990 (!strcmp(argv[i], "--loaddtd"))) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001991 loaddtd++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001992 options |= XML_PARSE_DTDLOAD;
1993 } else if ((!strcmp(argv[i], "-dtdattr")) ||
Daniel Veillard48da9102001-08-07 01:10:10 +00001994 (!strcmp(argv[i], "--dtdattr"))) {
1995 loaddtd++;
1996 dtdattrs++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001997 options |= XML_PARSE_DTDATTR;
Daniel Veillard4432df22003-09-28 18:58:27 +00001998 }
1999#ifdef LIBXML_VALID_ENABLED
2000 else if ((!strcmp(argv[i], "-valid")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002001 (!strcmp(argv[i], "--valid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002002 valid++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002003 options |= XML_PARSE_DTDVALID;
2004 } else if ((!strcmp(argv[i], "-postvalid")) ||
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002005 (!strcmp(argv[i], "--postvalid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002006 postvalid++;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002007 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00002008 options |= XML_PARSE_DTDLOAD;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002009 } else if ((!strcmp(argv[i], "-dtdvalid")) ||
Daniel Veillardcd429612000-10-11 15:57:05 +00002010 (!strcmp(argv[i], "--dtdvalid"))) {
2011 i++;
2012 dtdvalid = argv[i];
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002013 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00002014 options |= XML_PARSE_DTDLOAD;
Daniel Veillard66f68e72003-08-18 16:39:51 +00002015 } else if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
2016 (!strcmp(argv[i], "--dtdvalidfpi"))) {
2017 i++;
2018 dtdvalidfpi = argv[i];
2019 loaddtd++;
Daniel Veillard5a30b2d2003-12-09 13:54:39 +00002020 options |= XML_PARSE_DTDLOAD;
Daniel Veillardcd429612000-10-11 15:57:05 +00002021 }
Daniel Veillard4432df22003-09-28 18:58:27 +00002022#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard29e43992001-12-13 22:21:58 +00002023 else if ((!strcmp(argv[i], "-dropdtd")) ||
2024 (!strcmp(argv[i], "--dropdtd")))
2025 dropdtd++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002026 else if ((!strcmp(argv[i], "-insert")) ||
2027 (!strcmp(argv[i], "--insert")))
2028 insert++;
Daniel Veillard48b2f892001-02-25 16:11:03 +00002029 else if ((!strcmp(argv[i], "-timing")) ||
2030 (!strcmp(argv[i], "--timing")))
2031 timing++;
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00002032 else if ((!strcmp(argv[i], "-auto")) ||
2033 (!strcmp(argv[i], "--auto")))
2034 generate++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002035 else if ((!strcmp(argv[i], "-repeat")) ||
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00002036 (!strcmp(argv[i], "--repeat"))) {
2037 if (repeat)
2038 repeat *= 10;
2039 else
2040 repeat = 100;
Daniel Veillard73b013f2003-09-30 12:36:01 +00002041 }
2042#ifdef LIBXML_PUSH_ENABLED
2043 else if ((!strcmp(argv[i], "-push")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002044 (!strcmp(argv[i], "--push")))
2045 push++;
Daniel Veillard73b013f2003-09-30 12:36:01 +00002046#endif /* LIBXML_PUSH_ENABLED */
Daniel Veillard46e370e2000-07-21 20:32:03 +00002047#ifdef HAVE_SYS_MMAN_H
2048 else if ((!strcmp(argv[i], "-memory")) ||
2049 (!strcmp(argv[i], "--memory")))
2050 memory++;
2051#endif
Daniel Veillard5e873c42000-04-12 13:27:38 +00002052 else if ((!strcmp(argv[i], "-testIO")) ||
2053 (!strcmp(argv[i], "--testIO")))
2054 testIO++;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00002055#ifdef LIBXML_XINCLUDE_ENABLED
2056 else if ((!strcmp(argv[i], "-xinclude")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002057 (!strcmp(argv[i], "--xinclude"))) {
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00002058 xinclude++;
Daniel Veillard7899c5c2003-11-03 12:31:38 +00002059 options |= XML_PARSE_XINCLUDE;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002060 }
Daniel Veillardc14c3892004-08-16 12:34:50 +00002061 else if ((!strcmp(argv[i], "-noxincludenode")) ||
2062 (!strcmp(argv[i], "--noxincludenode"))) {
2063 xinclude++;
2064 options |= XML_PARSE_XINCLUDE;
2065 options |= XML_PARSE_NOXINCNODE;
2066 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00002067#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002068#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00002069#ifdef HAVE_ZLIB_H
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002070 else if ((!strcmp(argv[i], "-compress")) ||
2071 (!strcmp(argv[i], "--compress"))) {
2072 compress++;
2073 xmlSetCompressMode(9);
2074 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00002075#endif
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002076#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002077 else if ((!strcmp(argv[i], "-nowarning")) ||
2078 (!strcmp(argv[i], "--nowarning"))) {
2079 xmlGetWarningsDefaultValue = 0;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002080 xmlPedanticParserDefault(0);
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002081 options |= XML_PARSE_NOWARNING;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002082 }
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002083 else if ((!strcmp(argv[i], "-pedantic")) ||
2084 (!strcmp(argv[i], "--pedantic"))) {
2085 xmlGetWarningsDefaultValue = 1;
2086 xmlPedanticParserDefault(1);
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002087 options |= XML_PARSE_PEDANTIC;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002088 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00002089#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002090 else if ((!strcmp(argv[i], "-debugent")) ||
2091 (!strcmp(argv[i], "--debugent"))) {
2092 debugent++;
2093 xmlParserDebugEntities = 1;
2094 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00002095#endif
Daniel Veillard25048d82004-08-14 22:37:54 +00002096#ifdef LIBXML_C14N_ENABLED
2097 else if ((!strcmp(argv[i], "-c14n")) ||
2098 (!strcmp(argv[i], "--c14n"))) {
2099 canonical++;
2100 options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD;
2101 }
2102#endif
Daniel Veillard81418e32001-05-22 15:08:55 +00002103#ifdef LIBXML_CATALOG_ENABLED
2104 else if ((!strcmp(argv[i], "-catalogs")) ||
2105 (!strcmp(argv[i], "--catalogs"))) {
Daniel Veillarde2940dd2001-08-22 00:06:49 +00002106 catalogs++;
2107 } else if ((!strcmp(argv[i], "-nocatalogs")) ||
2108 (!strcmp(argv[i], "--nocatalogs"))) {
2109 nocatalogs++;
Daniel Veillard81418e32001-05-22 15:08:55 +00002110 }
2111#endif
Daniel Veillardbe803962000-06-28 23:40:59 +00002112 else if ((!strcmp(argv[i], "-encode")) ||
2113 (!strcmp(argv[i], "--encode"))) {
2114 i++;
2115 encoding = argv[i];
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00002116 /*
2117 * OK it's for testing purposes
2118 */
2119 xmlAddEncodingAlias("UTF-8", "DVEnc");
Daniel Veillardbe803962000-06-28 23:40:59 +00002120 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002121 else if ((!strcmp(argv[i], "-noblanks")) ||
2122 (!strcmp(argv[i], "--noblanks"))) {
2123 noblanks++;
2124 xmlKeepBlanksDefault(0);
Daniel Veillard90493a92001-08-14 14:12:47 +00002125 }
Daniel Veillard87076042004-05-03 22:54:49 +00002126 else if ((!strcmp(argv[i], "-maxmem")) ||
2127 (!strcmp(argv[i], "--maxmem"))) {
2128 i++;
2129 if (sscanf(argv[i], "%d", &maxmem) == 1) {
2130 xmlMemSetup(myFreeFunc, myMallocFunc, myReallocFunc,
2131 myStrdupFunc);
2132 } else {
2133 maxmem = 0;
2134 }
2135 }
Daniel Veillard90493a92001-08-14 14:12:47 +00002136 else if ((!strcmp(argv[i], "-format")) ||
2137 (!strcmp(argv[i], "--format"))) {
2138 noblanks++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002139#ifdef LIBXML_OUTPUT_ENABLED
Daniel Veillard90493a92001-08-14 14:12:47 +00002140 format++;
Daniel Veillarda9cce9c2003-09-29 13:20:24 +00002141#endif /* LIBXML_OUTPUT_ENABLED */
Daniel Veillard90493a92001-08-14 14:12:47 +00002142 xmlKeepBlanksDefault(0);
Daniel Veillard7704fb12003-01-03 16:19:51 +00002143 }
Daniel Veillard81273902003-09-30 00:43:48 +00002144#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00002145 else if ((!strcmp(argv[i], "-stream")) ||
2146 (!strcmp(argv[i], "--stream"))) {
2147 stream++;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002148 }
Daniel Veillard7899c5c2003-11-03 12:31:38 +00002149 else if ((!strcmp(argv[i], "-walker")) ||
2150 (!strcmp(argv[i], "--walker"))) {
2151 walker++;
2152 noout++;
2153 }
Daniel Veillard81273902003-09-30 00:43:48 +00002154#endif /* LIBXML_READER_ENABLED */
2155#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +00002156 else if ((!strcmp(argv[i], "-sax1")) ||
2157 (!strcmp(argv[i], "--sax1"))) {
2158 sax1++;
2159 }
Daniel Veillard81273902003-09-30 00:43:48 +00002160#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002161 else if ((!strcmp(argv[i], "-chkregister")) ||
2162 (!strcmp(argv[i], "--chkregister"))) {
2163 chkregister++;
Daniel Veillard71531f32003-02-05 13:19:53 +00002164#ifdef LIBXML_SCHEMAS_ENABLED
2165 } else if ((!strcmp(argv[i], "-relaxng")) ||
2166 (!strcmp(argv[i], "--relaxng"))) {
2167 i++;
2168 relaxng = argv[i];
2169 noent++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002170 options |= XML_PARSE_NOENT;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002171 } else if ((!strcmp(argv[i], "-schema")) ||
2172 (!strcmp(argv[i], "--schema"))) {
2173 i++;
2174 schema = argv[i];
2175 noent++;
Daniel Veillard71531f32003-02-05 13:19:53 +00002176#endif
Daniel Veillarde8b09e42003-05-13 22:14:13 +00002177 } else if ((!strcmp(argv[i], "-nonet")) ||
2178 (!strcmp(argv[i], "--nonet"))) {
Daniel Veillard61b93382003-11-03 14:28:31 +00002179 options |= XML_PARSE_NONET;
Daniel Veillard0bff36d2004-08-31 09:37:03 +00002180 } else if ((!strcmp(argv[i], "-load-trace")) ||
2181 (!strcmp(argv[i], "--load-trace"))) {
2182 load_trace++;
2183 } else if ((!strcmp(argv[i], "-path")) ||
2184 (!strcmp(argv[i], "--path"))) {
2185 i++;
2186 parsePath(BAD_CAST argv[i]);
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002187#ifdef LIBXML_PATTERN_ENABLED
2188 } else if ((!strcmp(argv[i], "-pattern")) ||
2189 (!strcmp(argv[i], "--pattern"))) {
2190 i++;
2191 pattern = argv[i];
2192#endif
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002193 } else {
2194 fprintf(stderr, "Unknown option %s\n", argv[i]);
2195 usage(argv[0]);
2196 return(1);
2197 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002198 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00002199
2200#ifdef LIBXML_CATALOG_ENABLED
2201 if (nocatalogs == 0) {
2202 if (catalogs) {
2203 const char *catal;
2204
2205 catal = getenv("SGML_CATALOG_FILES");
Daniel Veillard6c5f9d12001-08-25 13:33:14 +00002206 if (catal != NULL) {
2207 xmlLoadCatalogs(catal);
2208 } else {
2209 fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n");
2210 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00002211 }
2212 }
2213#endif
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002214
Daniel Veillard81273902003-09-30 00:43:48 +00002215#ifdef LIBXML_SAX1_ENABLED
Daniel Veillard07cb8222003-09-10 10:51:05 +00002216 if (sax1)
2217 xmlSAXDefaultVersion(1);
2218 else
2219 xmlSAXDefaultVersion(2);
Daniel Veillard81273902003-09-30 00:43:48 +00002220#endif /* LIBXML_SAX1_ENABLED */
Daniel Veillard07cb8222003-09-10 10:51:05 +00002221
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002222 if (chkregister) {
2223 xmlRegisterNodeDefault(registerNode);
2224 xmlDeregisterNodeDefault(deregisterNode);
2225 }
Aleksey Sanin693c9bc2003-03-09 22:36:52 +00002226
2227 indent = getenv("XMLLINT_INDENT");
2228 if(indent != NULL) {
2229 xmlTreeIndentString = indent;
2230 }
2231
Daniel Veillard8a1b1852003-01-05 22:37:17 +00002232
Daniel Veillard0bff36d2004-08-31 09:37:03 +00002233 defaultEntityLoader = xmlGetExternalEntityLoader();
2234 xmlSetExternalEntityLoader(xmllintExternalEntityLoader);
2235
Daniel Veillardd9bad132001-07-23 19:39:43 +00002236 xmlLineNumbersDefault(1);
Daniel Veillard48da9102001-08-07 01:10:10 +00002237 if (loaddtd != 0)
2238 xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
2239 if (dtdattrs)
2240 xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002241 if (noent != 0) xmlSubstituteEntitiesDefault(1);
Daniel Veillard4432df22003-09-28 18:58:27 +00002242#ifdef LIBXML_VALID_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002243 if (valid != 0) xmlDoValidityCheckingDefaultValue = 1;
Daniel Veillard4432df22003-09-28 18:58:27 +00002244#endif /* LIBXML_VALID_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002245 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002246 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002247 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002248 xmlGenericError(xmlGenericErrorContext,
2249 "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
2250 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002251 "<html><head><title>%s output</title></head>\n",
2252 argv[0]);
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002253 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002254 "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
2255 argv[0]);
2256 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002257
2258#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard81273902003-09-30 00:43:48 +00002259 if ((relaxng != NULL)
2260#ifdef LIBXML_READER_ENABLED
2261 && (stream == 0)
2262#endif /* LIBXML_READER_ENABLED */
2263 ) {
Daniel Veillard71531f32003-02-05 13:19:53 +00002264 xmlRelaxNGParserCtxtPtr ctxt;
2265
Daniel Veillardce192eb2003-04-16 15:58:05 +00002266 /* forces loading the DTDs */
2267 xmlLoadExtDtdDefaultValue |= 1;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00002268 options |= XML_PARSE_DTDLOAD;
Daniel Veillard42f12e92003-03-07 18:32:59 +00002269 if (timing) {
2270 startTimer();
2271 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002272 ctxt = xmlRelaxNGNewParserCtxt(relaxng);
2273 xmlRelaxNGSetParserErrors(ctxt,
2274 (xmlRelaxNGValidityErrorFunc) fprintf,
2275 (xmlRelaxNGValidityWarningFunc) fprintf,
2276 stderr);
2277 relaxngschemas = xmlRelaxNGParse(ctxt);
Daniel Veillardce192eb2003-04-16 15:58:05 +00002278 if (relaxngschemas == NULL) {
2279 xmlGenericError(xmlGenericErrorContext,
2280 "Relax-NG schema %s failed to compile\n", relaxng);
William M. Brack8304d872004-06-08 13:29:32 +00002281 progresult = XMLLINT_ERR_SCHEMACOMP;
Daniel Veillardce192eb2003-04-16 15:58:05 +00002282 relaxng = NULL;
2283 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002284 xmlRelaxNGFreeParserCtxt(ctxt);
Daniel Veillard42f12e92003-03-07 18:32:59 +00002285 if (timing) {
2286 endTimer("Compiling the schemas");
2287 }
Daniel Veillardebe25d42004-03-25 09:35:49 +00002288 } else if ((schema != NULL)
2289#ifdef LIBXML_READER_ENABLED
2290 && (stream == 0)
2291#endif
2292 ) {
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002293 xmlSchemaParserCtxtPtr ctxt;
2294
2295 if (timing) {
2296 startTimer();
2297 }
2298 ctxt = xmlSchemaNewParserCtxt(schema);
2299 xmlSchemaSetParserErrors(ctxt,
2300 (xmlSchemaValidityErrorFunc) fprintf,
2301 (xmlSchemaValidityWarningFunc) fprintf,
2302 stderr);
2303 wxschemas = xmlSchemaParse(ctxt);
2304 if (wxschemas == NULL) {
2305 xmlGenericError(xmlGenericErrorContext,
2306 "WXS schema %s failed to compile\n", schema);
William M. Brack8304d872004-06-08 13:29:32 +00002307 progresult = XMLLINT_ERR_SCHEMACOMP;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002308 schema = NULL;
2309 }
2310 xmlSchemaFreeParserCtxt(ctxt);
2311 if (timing) {
2312 endTimer("Compiling the schemas");
2313 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002314 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002315#endif /* LIBXML_SCHEMAS_ENABLED */
2316#ifdef LIBXML_PATTERN_ENABLED
Daniel Veillardd4301ab2005-02-03 22:24:10 +00002317 if ((pattern != NULL) && (walker == 0)) {
Daniel Veillardffa7b7e2003-12-05 16:10:21 +00002318 patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL);
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002319 if (patternc == NULL) {
2320 xmlGenericError(xmlGenericErrorContext,
2321 "Pattern %s failed to compile\n", pattern);
William M. Brack8304d872004-06-08 13:29:32 +00002322 progresult = XMLLINT_ERR_SCHEMAPAT;
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002323 pattern = NULL;
2324 }
2325 }
2326#endif /* LIBXML_PATTERN_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002327 for (i = 1; i < argc ; i++) {
Daniel Veillardbe803962000-06-28 23:40:59 +00002328 if ((!strcmp(argv[i], "-encode")) ||
2329 (!strcmp(argv[i], "--encode"))) {
2330 i++;
2331 continue;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00002332 } else if ((!strcmp(argv[i], "-o")) ||
2333 (!strcmp(argv[i], "-output")) ||
2334 (!strcmp(argv[i], "--output"))) {
2335 i++;
2336 continue;
Daniel Veillardbe803962000-06-28 23:40:59 +00002337 }
Daniel Veillard4432df22003-09-28 18:58:27 +00002338#ifdef LIBXML_VALID_ENABLED
Daniel Veillardcd429612000-10-11 15:57:05 +00002339 if ((!strcmp(argv[i], "-dtdvalid")) ||
2340 (!strcmp(argv[i], "--dtdvalid"))) {
2341 i++;
2342 continue;
Daniel Veillard0bff36d2004-08-31 09:37:03 +00002343 }
2344 if ((!strcmp(argv[i], "-path")) ||
2345 (!strcmp(argv[i], "--path"))) {
2346 i++;
2347 continue;
Daniel Veillardcd429612000-10-11 15:57:05 +00002348 }
Daniel Veillard66f68e72003-08-18 16:39:51 +00002349 if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
2350 (!strcmp(argv[i], "--dtdvalidfpi"))) {
2351 i++;
2352 continue;
2353 }
Daniel Veillard4432df22003-09-28 18:58:27 +00002354#endif /* LIBXML_VALID_ENABLED */
Daniel Veillard71531f32003-02-05 13:19:53 +00002355 if ((!strcmp(argv[i], "-relaxng")) ||
2356 (!strcmp(argv[i], "--relaxng"))) {
2357 i++;
2358 continue;
2359 }
Daniel Veillard87076042004-05-03 22:54:49 +00002360 if ((!strcmp(argv[i], "-maxmem")) ||
2361 (!strcmp(argv[i], "--maxmem"))) {
2362 i++;
2363 continue;
2364 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002365 if ((!strcmp(argv[i], "-schema")) ||
2366 (!strcmp(argv[i], "--schema"))) {
2367 i++;
2368 continue;
2369 }
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002370#ifdef LIBXML_PATTERN_ENABLED
2371 if ((!strcmp(argv[i], "-pattern")) ||
2372 (!strcmp(argv[i], "--pattern"))) {
2373 i++;
2374 continue;
2375 }
2376#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +00002377 if ((timing) && (repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +00002378 startTimer();
Daniel Veillardcbaf3992001-12-31 16:16:02 +00002379 /* Remember file names. "-" means stdin. <sven@zen.org> */
Daniel Veillard4a6845d2001-01-03 13:32:39 +00002380 if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002381 if (repeat) {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002382 xmlParserCtxtPtr ctxt = NULL;
2383
2384 for (acount = 0;acount < repeat;acount++) {
Daniel Veillard81273902003-09-30 00:43:48 +00002385#ifdef LIBXML_READER_ENABLED
Daniel Veillard198c1bf2003-10-20 17:07:41 +00002386 if (stream != 0) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00002387 streamFile(argv[i]);
Daniel Veillard198c1bf2003-10-20 17:07:41 +00002388 } else {
Daniel Veillard81273902003-09-30 00:43:48 +00002389#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002390 if (ctxt == NULL)
2391 ctxt = xmlNewParserCtxt();
2392 parseAndPrintFile(argv[i], ctxt);
Daniel Veillard81273902003-09-30 00:43:48 +00002393#ifdef LIBXML_READER_ENABLED
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002394 }
Daniel Veillard81273902003-09-30 00:43:48 +00002395#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002396 }
2397 if (ctxt != NULL)
2398 xmlFreeParserCtxt(ctxt);
Daniel Veillard7704fb12003-01-03 16:19:51 +00002399 } else {
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00002400 nbregister = 0;
2401
Daniel Veillard81273902003-09-30 00:43:48 +00002402#ifdef LIBXML_READER_ENABLED
Daniel Veillard7704fb12003-01-03 16:19:51 +00002403 if (stream != 0)
2404 streamFile(argv[i]);
2405 else
Daniel Veillard81273902003-09-30 00:43:48 +00002406#endif /* LIBXML_READER_ENABLED */
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002407 parseAndPrintFile(argv[i], NULL);
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00002408
2409 if ((chkregister) && (nbregister != 0)) {
2410 fprintf(stderr, "Registration count off: %d\n", nbregister);
William M. Brack8304d872004-06-08 13:29:32 +00002411 progresult = XMLLINT_ERR_RDREGIS;
Daniel Veillarda2d51fc2004-04-30 22:25:59 +00002412 }
Daniel Veillard7704fb12003-01-03 16:19:51 +00002413 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002414 files ++;
Daniel Veillarda7866932001-12-04 13:14:44 +00002415 if ((timing) && (repeat)) {
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00002416 endTimer("%d iterations", repeat);
Daniel Veillarda7866932001-12-04 13:14:44 +00002417 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00002418 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002419 }
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00002420 if (generate)
Daniel Veillarde96a2a42003-09-24 21:23:56 +00002421 parseAndPrintFile(NULL, NULL);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002422 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00002423 xmlGenericError(xmlGenericErrorContext, "</body></html>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002424 }
Daniel Veillard845cce42002-01-09 11:51:37 +00002425 if ((files == 0) && (!generate) && (version == 0)) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00002426 usage(argv[0]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002427 }
Daniel Veillard71531f32003-02-05 13:19:53 +00002428#ifdef LIBXML_SCHEMAS_ENABLED
2429 if (relaxngschemas != NULL)
2430 xmlRelaxNGFree(relaxngschemas);
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00002431 if (wxschemas != NULL)
2432 xmlSchemaFree(wxschemas);
Daniel Veillard71531f32003-02-05 13:19:53 +00002433 xmlRelaxNGCleanupTypes();
2434#endif
Daniel Veillardb3de70c2003-12-02 22:32:15 +00002435#ifdef LIBXML_PATTERN_ENABLED
2436 if (patternc != NULL)
2437 xmlFreePattern(patternc);
2438#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002439 xmlCleanupParser();
2440 xmlMemoryDump();
2441
Daniel Veillardf7cd4812001-02-23 18:44:52 +00002442 return(progresult);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00002443}
Daniel Veillard88a172f2000-08-04 18:23:10 +00002444