blob: bdc198c405e7362e9ae2b2378943179d23e54e75 [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 Veillardce8b83b2000-04-05 18:38:42 +000092
Daniel Veillard3be27512003-01-26 19:49:04 +000093#ifndef XML_XML_DEFAULT_CATALOG
94#define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog"
95#endif
96
Daniel Veillardce8b83b2000-04-05 18:38:42 +000097#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +000098static int shell = 0;
99static int debugent = 0;
100#endif
Daniel Veillard8326e732003-01-07 00:19:07 +0000101static int debug = 0;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000102static int copy = 0;
103static int recovery = 0;
104static int noent = 0;
105static int noout = 0;
106static int nowrap = 0;
107static int valid = 0;
108static int postvalid = 0;
Daniel Veillardcd429612000-10-11 15:57:05 +0000109static char * dtdvalid = NULL;
Daniel Veillard66f68e72003-08-18 16:39:51 +0000110static char * dtdvalidfpi = NULL;
Daniel Veillard71531f32003-02-05 13:19:53 +0000111#ifdef LIBXML_SCHEMAS_ENABLED
112static char * relaxng = NULL;
113static xmlRelaxNGPtr relaxngschemas = NULL;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +0000114static char * schema = NULL;
115static xmlSchemaPtr wxschemas = NULL;
Daniel Veillard71531f32003-02-05 13:19:53 +0000116#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000117static int repeat = 0;
118static int insert = 0;
119static int compress = 0;
120static int html = 0;
121static int htmlout = 0;
122static int push = 0;
Daniel Veillard46e370e2000-07-21 20:32:03 +0000123#ifdef HAVE_SYS_MMAN_H
124static int memory = 0;
125#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000126static int noblanks = 0;
Daniel Veillard90493a92001-08-14 14:12:47 +0000127static int format = 0;
Daniel Veillard5e873c42000-04-12 13:27:38 +0000128static int testIO = 0;
Daniel Veillardbe803962000-06-28 23:40:59 +0000129static char *encoding = NULL;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000130#ifdef LIBXML_XINCLUDE_ENABLED
131static int xinclude = 0;
132#endif
Daniel Veillard48da9102001-08-07 01:10:10 +0000133static int dtdattrs = 0;
Daniel Veillard10ea86c2001-06-20 13:55:33 +0000134static int loaddtd = 0;
Daniel Veillardf7cd4812001-02-23 18:44:52 +0000135static int progresult = 0;
Daniel Veillard48b2f892001-02-25 16:11:03 +0000136static int timing = 0;
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000137static int generate = 0;
Daniel Veillard29e43992001-12-13 22:21:58 +0000138static int dropdtd = 0;
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000139#ifdef LIBXML_CATALOG_ENABLED
140static int catalogs = 0;
141static int nocatalogs = 0;
142#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000143static int stream = 0;
Daniel Veillard8a1b1852003-01-05 22:37:17 +0000144static int chkregister = 0;
Daniel Veillard07cb8222003-09-10 10:51:05 +0000145static int sax1 = 0;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000146static const char *output = NULL;
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000147static int options = 0;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000148
Daniel Veillard01db67c2001-12-18 07:09:59 +0000149/*
150 * Internal timing routines to remove the necessity to have unix-specific
151 * function calls
152 */
153
Daniel Veillard8c1ae602002-03-07 11:21:00 +0000154#ifndef HAVE_GETTIMEOFDAY
155#ifdef HAVE_SYS_TIMEB_H
156#ifdef HAVE_SYS_TIME_H
157#ifdef HAVE_FTIME
158
Daniel Veillard01c13b52002-12-10 15:19:08 +0000159static int
Daniel Veillard8c1ae602002-03-07 11:21:00 +0000160my_gettimeofday(struct timeval *tvp, void *tzp)
161{
162 struct timeb timebuffer;
163
164 ftime(&timebuffer);
165 if (tvp) {
166 tvp->tv_sec = timebuffer.time;
167 tvp->tv_usec = timebuffer.millitm * 1000L;
168 }
169 return (0);
170}
171#define HAVE_GETTIMEOFDAY 1
172#define gettimeofday my_gettimeofday
173
174#endif /* HAVE_FTIME */
175#endif /* HAVE_SYS_TIME_H */
176#endif /* HAVE_SYS_TIMEB_H */
177#endif /* !HAVE_GETTIMEOFDAY */
178
Daniel Veillard01db67c2001-12-18 07:09:59 +0000179#if defined(HAVE_GETTIMEOFDAY)
180static struct timeval begin, end;
181
182/*
183 * startTimer: call where you want to start timing
184 */
185static void
186startTimer(void)
187{
188 gettimeofday(&begin, NULL);
189}
190
191/*
192 * endTimer: call where you want to stop timing and to print out a
193 * message about the timing performed; format is a printf
194 * type argument
195 */
196static void
Daniel Veillard118aed72002-09-24 14:13:13 +0000197endTimer(const char *fmt, ...)
Daniel Veillard01db67c2001-12-18 07:09:59 +0000198{
199 long msec;
200 va_list ap;
201
202 gettimeofday(&end, NULL);
203 msec = end.tv_sec - begin.tv_sec;
204 msec *= 1000;
205 msec += (end.tv_usec - begin.tv_usec) / 1000;
206
207#ifndef HAVE_STDARG_H
208#error "endTimer required stdarg functions"
209#endif
Daniel Veillard118aed72002-09-24 14:13:13 +0000210 va_start(ap, fmt);
211 vfprintf(stderr, fmt, ap);
Daniel Veillard01db67c2001-12-18 07:09:59 +0000212 va_end(ap);
213
214 fprintf(stderr, " took %ld ms\n", msec);
215}
216#elif defined(HAVE_TIME_H)
Daniel Veillard01db67c2001-12-18 07:09:59 +0000217/*
218 * No gettimeofday function, so we have to make do with calling clock.
219 * This is obviously less accurate, but there's little we can do about
220 * that.
221 */
Daniel Veillard90bc3712002-03-07 15:12:58 +0000222#ifndef CLOCKS_PER_SEC
223#define CLOCKS_PER_SEC 100
224#endif
Daniel Veillard01db67c2001-12-18 07:09:59 +0000225
226static clock_t begin, end;
227static void
228startTimer(void)
229{
230 begin = clock();
231}
232static void
233endTimer(const char *fmt, ...)
234{
235 long msec;
236 va_list ap;
237
238 end = clock();
239 msec = ((end - begin) * 1000) / CLOCKS_PER_SEC;
240
241#ifndef HAVE_STDARG_H
242#error "endTimer required stdarg functions"
243#endif
244 va_start(ap, fmt);
245 vfprintf(stderr, fmt, ap);
246 va_end(ap);
247 fprintf(stderr, " took %ld ms\n", msec);
248}
249#else
250
251/*
252 * We don't have a gettimeofday or time.h, so we just don't do timing
253 */
254static void
255startTimer(void)
256{
257 /*
258 * Do nothing
259 */
260}
261static void
262endTimer(char *format, ...)
263{
264 /*
265 * We cannot do anything because we don't have a timing function
266 */
267#ifdef HAVE_STDARG_H
268 va_start(ap, format);
269 vfprintf(stderr, format, ap);
270 va_end(ap);
271 fprintf(stderr, " was not timed\n", msec);
272#else
273 /* We don't have gettimeofday, time or stdarg.h, what crazy world is
274 * this ?!
275 */
276#endif
277}
278#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000279/************************************************************************
280 * *
281 * HTML ouput *
282 * *
283 ************************************************************************/
284char buffer[50000];
285
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000286static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000287xmlHTMLEncodeSend(void) {
288 char *result;
289
290 result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
291 if (result) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000292 xmlGenericError(xmlGenericErrorContext, "%s", result);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000293 xmlFree(result);
294 }
295 buffer[0] = 0;
296}
297
298/**
299 * xmlHTMLPrintFileInfo:
300 * @input: an xmlParserInputPtr input
301 *
302 * Displays the associated file and line informations for the current input
303 */
304
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000305static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000306xmlHTMLPrintFileInfo(xmlParserInputPtr input) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000307 int len;
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000308 xmlGenericError(xmlGenericErrorContext, "<p>");
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000309
310 len = strlen(buffer);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000311 if (input != NULL) {
312 if (input->filename) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000313 snprintf(&buffer[len], sizeof(buffer) - len, "%s:%d: ", input->filename,
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000314 input->line);
315 } else {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000316 snprintf(&buffer[len], sizeof(buffer) - len, "Entity: line %d: ", input->line);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000317 }
318 }
319 xmlHTMLEncodeSend();
320}
321
322/**
323 * xmlHTMLPrintFileContext:
324 * @input: an xmlParserInputPtr input
325 *
326 * Displays current context within the input content for error tracking
327 */
328
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000329static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000330xmlHTMLPrintFileContext(xmlParserInputPtr input) {
331 const xmlChar *cur, *base;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000332 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000333 int n;
334
335 if (input == NULL) return;
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000336 xmlGenericError(xmlGenericErrorContext, "<pre>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000337 cur = input->cur;
338 base = input->base;
339 while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
340 cur--;
341 }
342 n = 0;
343 while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
344 cur--;
345 if ((*cur == '\n') || (*cur == '\r')) cur++;
346 base = cur;
347 n = 0;
348 while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000349 len = strlen(buffer);
350 snprintf(&buffer[len], sizeof(buffer) - len, "%c",
351 (unsigned char) *cur++);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000352 n++;
353 }
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000354 len = strlen(buffer);
355 snprintf(&buffer[len], sizeof(buffer) - len, "\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000356 cur = input->cur;
357 while ((*cur == '\n') || (*cur == '\r'))
358 cur--;
359 n = 0;
360 while ((cur != base) && (n++ < 80)) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000361 len = strlen(buffer);
362 snprintf(&buffer[len], sizeof(buffer) - len, " ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000363 base++;
364 }
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000365 len = strlen(buffer);
366 snprintf(&buffer[len], sizeof(buffer) - len, "^\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000367 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000368 xmlGenericError(xmlGenericErrorContext, "</pre>");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000369}
370
371/**
372 * xmlHTMLError:
373 * @ctx: an XML parser context
374 * @msg: the message to display/transmit
375 * @...: extra parameters for the message display
376 *
377 * Display and format an error messages, gives file, line, position and
378 * extra parameters.
379 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000380static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000381xmlHTMLError(void *ctx, const char *msg, ...)
382{
383 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
384 xmlParserInputPtr input;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000385 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000386 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000387
388 buffer[0] = 0;
389 input = ctxt->input;
390 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000391 input = ctxt->inputTab[ctxt->inputNr - 2];
392 }
393
394 xmlHTMLPrintFileInfo(input);
395
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000396 xmlGenericError(xmlGenericErrorContext, "<b>error</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000397 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000398 len = strlen(buffer);
399 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000400 va_end(args);
401 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000402 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000403
404 xmlHTMLPrintFileContext(input);
405 xmlHTMLEncodeSend();
406}
407
408/**
409 * xmlHTMLWarning:
410 * @ctx: an XML parser context
411 * @msg: the message to display/transmit
412 * @...: extra parameters for the message display
413 *
414 * Display and format a warning messages, gives file, line, position and
415 * extra parameters.
416 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000417static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000418xmlHTMLWarning(void *ctx, const char *msg, ...)
419{
420 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
421 xmlParserInputPtr input;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000422 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000423 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000424
425 buffer[0] = 0;
426 input = ctxt->input;
427 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000428 input = ctxt->inputTab[ctxt->inputNr - 2];
429 }
430
431
432 xmlHTMLPrintFileInfo(input);
433
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000434 xmlGenericError(xmlGenericErrorContext, "<b>warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000435 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000436 len = strlen(buffer);
437 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000438 va_end(args);
439 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000440 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000441
442 xmlHTMLPrintFileContext(input);
443 xmlHTMLEncodeSend();
444}
445
446/**
447 * xmlHTMLValidityError:
448 * @ctx: an XML parser context
449 * @msg: the message to display/transmit
450 * @...: extra parameters for the message display
451 *
452 * Display and format an validity error messages, gives file,
453 * line, position and extra parameters.
454 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000455static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000456xmlHTMLValidityError(void *ctx, const char *msg, ...)
457{
458 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
459 xmlParserInputPtr input;
460 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000461 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000462
463 buffer[0] = 0;
464 input = ctxt->input;
465 if ((input->filename == NULL) && (ctxt->inputNr > 1))
466 input = ctxt->inputTab[ctxt->inputNr - 2];
467
468 xmlHTMLPrintFileInfo(input);
469
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000470 xmlGenericError(xmlGenericErrorContext, "<b>validity error</b>: ");
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000471 len = strlen(buffer);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000472 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000473 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000474 va_end(args);
475 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000476 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000477
478 xmlHTMLPrintFileContext(input);
479 xmlHTMLEncodeSend();
480}
481
482/**
483 * xmlHTMLValidityWarning:
484 * @ctx: an XML parser context
485 * @msg: the message to display/transmit
486 * @...: extra parameters for the message display
487 *
488 * Display and format a validity warning messages, gives file, line,
489 * position and extra parameters.
490 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000491static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000492xmlHTMLValidityWarning(void *ctx, const char *msg, ...)
493{
494 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
495 xmlParserInputPtr input;
496 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000497 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000498
499 buffer[0] = 0;
500 input = ctxt->input;
501 if ((input->filename == NULL) && (ctxt->inputNr > 1))
502 input = ctxt->inputTab[ctxt->inputNr - 2];
503
504 xmlHTMLPrintFileInfo(input);
505
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000506 xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000507 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000508 len = strlen(buffer);
509 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000510 va_end(args);
511 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000512 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000513
514 xmlHTMLPrintFileContext(input);
515 xmlHTMLEncodeSend();
516}
517
518/************************************************************************
519 * *
520 * Shell Interface *
521 * *
522 ************************************************************************/
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000523#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000524/**
525 * xmlShellReadline:
526 * @prompt: the prompt value
527 *
528 * Read a string
529 *
530 * Returns a pointer to it or NULL on EOF the caller is expected to
531 * free the returned string.
532 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000533static char *
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000534xmlShellReadline(char *prompt) {
535#ifdef HAVE_LIBREADLINE
536 char *line_read;
537
538 /* Get a line from the user. */
539 line_read = readline (prompt);
540
541 /* If the line has any text in it, save it on the history. */
542 if (line_read && *line_read)
543 add_history (line_read);
544
545 return (line_read);
546#else
547 char line_read[501];
Daniel Veillard29e43992001-12-13 22:21:58 +0000548 char *ret;
549 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000550
551 if (prompt != NULL)
552 fprintf(stdout, "%s", prompt);
553 if (!fgets(line_read, 500, stdin))
554 return(NULL);
555 line_read[500] = 0;
Daniel Veillard29e43992001-12-13 22:21:58 +0000556 len = strlen(line_read);
557 ret = (char *) malloc(len + 1);
558 if (ret != NULL) {
559 memcpy (ret, line_read, len + 1);
560 }
561 return(ret);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000562#endif
563}
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000564#endif /* LIBXML_DEBUG_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000565
566/************************************************************************
567 * *
Daniel Veillard5e873c42000-04-12 13:27:38 +0000568 * I/O Interfaces *
569 * *
570 ************************************************************************/
571
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000572static int myRead(FILE *f, char * buf, int len) {
573 return(fread(buf, 1, len, f));
Daniel Veillard5e873c42000-04-12 13:27:38 +0000574}
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000575static void myClose(FILE *f) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000576 if (f != stdin) {
Daniel Veillard5e873c42000-04-12 13:27:38 +0000577 fclose(f);
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000578 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000579}
580
581/************************************************************************
582 * *
Daniel Veillard7704fb12003-01-03 16:19:51 +0000583 * Stream Test processing *
584 * *
585 ************************************************************************/
Daniel Veillard7704fb12003-01-03 16:19:51 +0000586static void processNode(xmlTextReaderPtr reader) {
Daniel Veillarde59494f2003-01-04 16:35:29 +0000587 xmlChar *name, *value;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000588
Daniel Veillarde59494f2003-01-04 16:35:29 +0000589 name = xmlTextReaderName(reader);
590 if (name == NULL)
591 name = xmlStrdup(BAD_CAST "--");
Daniel Veillard99737f52003-03-22 14:55:50 +0000592
Daniel Veillarde59494f2003-01-04 16:35:29 +0000593 value = xmlTextReaderValue(reader);
Daniel Veillard7704fb12003-01-03 16:19:51 +0000594
Daniel Veillard99737f52003-03-22 14:55:50 +0000595 printf("%d %d %s %d %d",
Daniel Veillarde59494f2003-01-04 16:35:29 +0000596 xmlTextReaderDepth(reader),
597 xmlTextReaderNodeType(reader),
598 name,
Daniel Veillard99737f52003-03-22 14:55:50 +0000599 xmlTextReaderIsEmptyElement(reader),
600 xmlTextReaderHasValue(reader));
Daniel Veillarde59494f2003-01-04 16:35:29 +0000601 xmlFree(name);
602 if (value == NULL)
603 printf("\n");
604 else {
605 printf(" %s\n", value);
606 xmlFree(value);
Daniel Veillard7704fb12003-01-03 16:19:51 +0000607 }
608}
609
610static void streamFile(char *filename) {
611 xmlTextReaderPtr reader;
612 int ret;
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000613#ifdef HAVE_SYS_MMAN_H
614 int fd = -1;
615 struct stat info;
616 const char *base = NULL;
617 xmlParserInputBufferPtr input = NULL;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000618
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000619 if (memory) {
620 if (stat(filename, &info) < 0)
621 return;
622 if ((fd = open(filename, O_RDONLY)) < 0)
623 return;
624 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
625 if (base == (void *) MAP_FAILED)
626 return;
627
Daniel Veillard53350552003-09-18 13:35:51 +0000628 input = xmlParserInputBufferCreateStatic((char *) base, info.st_size,
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000629 XML_CHAR_ENCODING_NONE);
630 reader = xmlNewTextReader(input, filename);
631 } else
632#endif
633 reader = xmlNewTextReaderFilename(filename);
634
Daniel Veillard7704fb12003-01-03 16:19:51 +0000635 if (reader != NULL) {
636 if (valid)
637 xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);
Daniel Veillardce192eb2003-04-16 15:58:05 +0000638 else
639 xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1);
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000640#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardce192eb2003-04-16 15:58:05 +0000641 if (relaxng != NULL) {
Daniel Veillard81514ba2003-09-16 23:17:26 +0000642 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000643 startTimer();
644 }
645 ret = xmlTextReaderRelaxNGValidate(reader, relaxng);
646 if (ret < 0) {
647 xmlGenericError(xmlGenericErrorContext,
648 "Relax-NG schema %s failed to compile\n", relaxng);
649 relaxng = NULL;
650 }
Daniel Veillard81514ba2003-09-16 23:17:26 +0000651 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000652 endTimer("Compiling the schemas");
653 }
654 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000655#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000656
657 /*
658 * Process all nodes in sequence
659 */
Daniel Veillard81514ba2003-09-16 23:17:26 +0000660 if ((timing) && (!repeat)) {
Daniel Veillardce192eb2003-04-16 15:58:05 +0000661 startTimer();
662 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000663 ret = xmlTextReaderRead(reader);
664 while (ret == 1) {
665 if (debug)
666 processNode(reader);
667 ret = xmlTextReaderRead(reader);
668 }
Daniel Veillard81514ba2003-09-16 23:17:26 +0000669 if ((timing) && (!repeat)) {
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000670#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardce192eb2003-04-16 15:58:05 +0000671 if ((valid) || (relaxng != NULL))
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000672#else
673 if (valid)
674#endif
Daniel Veillardce192eb2003-04-16 15:58:05 +0000675 endTimer("Parsing and validating");
676 else
677 endTimer("Parsing");
678 }
Daniel Veillard7704fb12003-01-03 16:19:51 +0000679
Daniel Veillardf6bad792003-04-11 19:38:54 +0000680 if (valid) {
681 if (xmlTextReaderIsValid(reader) != 1) {
682 xmlGenericError(xmlGenericErrorContext,
683 "Document %s does not validate\n", filename);
684 progresult = 3;
685 }
686 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000687#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardf4e55762003-04-15 23:32:22 +0000688 if (relaxng != NULL) {
689 if (xmlTextReaderIsValid(reader) != 1) {
690 printf("%s fails to validate\n", filename);
691 progresult = 3;
692 } else {
693 printf("%s validates\n", filename);
694 }
695 }
Daniel Veillard37fc84d2003-05-09 19:38:15 +0000696#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000697 /*
698 * Done, cleanup and status
699 */
700 xmlFreeTextReader(reader);
701 if (ret != 0) {
702 printf("%s : failed to parse\n", filename);
Daniel Veillardf6bad792003-04-11 19:38:54 +0000703 progresult = 1;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000704 }
705 } else {
706 fprintf(stderr, "Unable to open %s\n", filename);
Daniel Veillardf6bad792003-04-11 19:38:54 +0000707 progresult = 1;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000708 }
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +0000709#ifdef HAVE_SYS_MMAN_H
710 if (memory) {
711 xmlFreeParserInputBuffer(input);
712 munmap((char *) base, info.st_size);
713 close(fd);
714 }
715#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000716}
717
718/************************************************************************
719 * *
720 * Tree Test processing *
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000721 * *
722 ************************************************************************/
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000723static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000724 xmlDocPtr doc = NULL, tmp;
725
Daniel Veillard48b2f892001-02-25 16:11:03 +0000726 if ((timing) && (!repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +0000727 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +0000728
729
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000730 if (filename == NULL) {
731 if (generate) {
732 xmlNodePtr n;
733
734 doc = xmlNewDoc(BAD_CAST "1.0");
735 n = xmlNewNode(NULL, BAD_CAST "info");
736 xmlNodeSetContent(n, BAD_CAST "abc");
737 xmlDocSetRootElement(doc, n);
738 }
739 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000740#ifdef LIBXML_HTML_ENABLED
William M. Brack78637da2003-07-31 14:47:38 +0000741 else if ((html) && (push)) {
742 FILE *f;
743
744 f = fopen(filename, "r");
745 if (f != NULL) {
746 int res, size = 3;
747 char chars[4096];
748 htmlParserCtxtPtr ctxt;
749
750 /* if (repeat) */
751 size = 4096;
752 res = fread(chars, 1, 4, f);
753 if (res > 0) {
754 ctxt = htmlCreatePushParserCtxt(NULL, NULL,
755 chars, res, filename, 0);
756 while ((res = fread(chars, 1, size, f)) > 0) {
757 htmlParseChunk(ctxt, chars, res, 0);
758 }
759 htmlParseChunk(ctxt, chars, 0, 1);
760 doc = ctxt->myDoc;
761 htmlFreeParserCtxt(ctxt);
762 }
763 fclose(f);
764 }
765 }
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000766 else if (html) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000767 doc = htmlParseFile(filename, NULL);
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000768 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000769#endif /* LIBXML_HTML_ENABLED */
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000770 else {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000771 /*
772 * build an XML tree from a string;
773 */
774 if (push) {
775 FILE *f;
776
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000777 /* '-' Usually means stdin -<sven@zen.org> */
778 if ((filename[0] == '-') && (filename[1] == 0)) {
779 f = stdin;
780 } else {
781 f = fopen(filename, "r");
782 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000783 if (f != NULL) {
Daniel Veillarde715dd22000-08-29 18:29:38 +0000784 int ret;
Daniel Veillarda880b122003-04-21 21:36:41 +0000785 int res, size = 1024;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000786 char chars[1024];
787 xmlParserCtxtPtr ctxt;
788
Daniel Veillarda880b122003-04-21 21:36:41 +0000789 /* if (repeat) size = 1024; */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000790 res = fread(chars, 1, 4, f);
791 if (res > 0) {
792 ctxt = xmlCreatePushParserCtxt(NULL, NULL,
793 chars, res, filename);
794 while ((res = fread(chars, 1, size, f)) > 0) {
795 xmlParseChunk(ctxt, chars, res, 0);
796 }
797 xmlParseChunk(ctxt, chars, 0, 1);
798 doc = ctxt->myDoc;
Daniel Veillarde715dd22000-08-29 18:29:38 +0000799 ret = ctxt->wellFormed;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000800 xmlFreeParserCtxt(ctxt);
Daniel Veillarde715dd22000-08-29 18:29:38 +0000801 if (!ret) {
802 xmlFreeDoc(doc);
803 doc = NULL;
804 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000805 }
806 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000807 } else if (testIO) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000808 if ((filename[0] == '-') && (filename[1] == 0)) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000809 doc = xmlReadFd(0, NULL, options);
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000810 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000811 FILE *f;
Daniel Veillard5e873c42000-04-12 13:27:38 +0000812
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000813 f = fopen(filename, "r");
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000814 if (f != NULL) {
815 if (rectxt == NULL)
816 doc = xmlReadIO((xmlInputReadCallback) myRead,
817 (xmlInputCloseCallback) myClose, f,
818 NULL, options);
819 else
820 doc = xmlCtxtReadIO(rectxt,
821 (xmlInputReadCallback) myRead,
822 (xmlInputCloseCallback) myClose, f,
823 NULL, options);
824 } else
Daniel Veillard5e873c42000-04-12 13:27:38 +0000825 doc = NULL;
Daniel Veillard5e873c42000-04-12 13:27:38 +0000826 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000827 } else if (htmlout) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000828 xmlParserCtxtPtr ctxt;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000829
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000830 if (rectxt == NULL)
831 ctxt = xmlNewParserCtxt();
832 else
833 ctxt = rectxt;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000834 if (ctxt == NULL) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000835 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000836 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000837 ctxt->sax->error = xmlHTMLError;
838 ctxt->sax->warning = xmlHTMLWarning;
839 ctxt->vctxt.error = xmlHTMLValidityError;
840 ctxt->vctxt.warning = xmlHTMLValidityWarning;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000841
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000842 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000843
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000844 if (rectxt == NULL)
845 xmlFreeParserCtxt(ctxt);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000846 }
Daniel Veillard46e370e2000-07-21 20:32:03 +0000847#ifdef HAVE_SYS_MMAN_H
848 } else if (memory) {
849 int fd;
850 struct stat info;
851 const char *base;
852 if (stat(filename, &info) < 0)
853 return;
854 if ((fd = open(filename, O_RDONLY)) < 0)
855 return;
856 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
Daniel Veillard29579362000-08-14 17:57:48 +0000857 if (base == (void *) MAP_FAILED)
Daniel Veillard46e370e2000-07-21 20:32:03 +0000858 return;
859
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000860 if (rectxt == NULL)
861 doc = xmlReadMemory((char *) base, info.st_size, NULL, options);
862 else
863 doc = xmlCtxtReadMemory(rectxt,
864 (char *) base, info.st_size, NULL, options);
865
Daniel Veillard46e370e2000-07-21 20:32:03 +0000866 munmap((char *) base, info.st_size);
867#endif
Daniel Veillardea7751d2002-12-20 00:16:24 +0000868 } else if (valid) {
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000869 xmlParserCtxtPtr ctxt = NULL;
Daniel Veillardea7751d2002-12-20 00:16:24 +0000870
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000871 if (rectxt == NULL)
872 ctxt = xmlNewParserCtxt();
873 else
874 ctxt = rectxt;
Daniel Veillardea7751d2002-12-20 00:16:24 +0000875 if (ctxt == NULL) {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000876 doc = NULL;
Daniel Veillardea7751d2002-12-20 00:16:24 +0000877 } else {
Daniel Veillard16fa96c2003-09-23 21:50:54 +0000878 doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
879
880 if (ctxt->valid == 0)
881 progresult = 4;
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000882 if (rectxt == NULL)
883 xmlFreeParserCtxt(ctxt);
Daniel Veillardea7751d2002-12-20 00:16:24 +0000884 }
885 } else {
Daniel Veillarde96a2a42003-09-24 21:23:56 +0000886 if (rectxt != NULL)
887 doc = xmlCtxtReadFile(rectxt, filename, NULL, options);
888 else
889 doc = xmlReadFile(filename, NULL, options);
Daniel Veillardea7751d2002-12-20 00:16:24 +0000890 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000891 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000892
Daniel Veillard88a172f2000-08-04 18:23:10 +0000893 /*
894 * If we don't have a document we might as well give up. Do we
895 * want an error message here? <sven@zen.org> */
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000896 if (doc == NULL) {
Daniel Veillardf7cd4812001-02-23 18:44:52 +0000897 progresult = 1;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000898 return;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000899 }
900
Daniel Veillard48b2f892001-02-25 16:11:03 +0000901 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +0000902 endTimer("Parsing");
Daniel Veillard48b2f892001-02-25 16:11:03 +0000903 }
904
Daniel Veillard29e43992001-12-13 22:21:58 +0000905 /*
906 * Remove DOCTYPE nodes
907 */
908 if (dropdtd) {
909 xmlDtdPtr dtd;
910
911 dtd = xmlGetIntSubset(doc);
912 if (dtd != NULL) {
913 xmlUnlinkNode((xmlNodePtr)dtd);
914 xmlFreeDtd(dtd);
915 }
916 }
917
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000918#ifdef LIBXML_XINCLUDE_ENABLED
Daniel Veillard48b2f892001-02-25 16:11:03 +0000919 if (xinclude) {
920 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +0000921 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +0000922 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000923 xmlXIncludeProcess(doc);
Daniel Veillard48b2f892001-02-25 16:11:03 +0000924 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +0000925 endTimer("Xinclude processing");
Daniel Veillard48b2f892001-02-25 16:11:03 +0000926 }
927 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000928#endif
Daniel Veillard88a172f2000-08-04 18:23:10 +0000929
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000930#ifdef LIBXML_DEBUG_ENABLED
931 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000932 * shell interaction
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000933 */
934 if (shell)
935 xmlShell(doc, filename, xmlShellReadline, stdout);
936#endif
937
938 /*
939 * test intermediate copy if needed.
940 */
941 if (copy) {
942 tmp = doc;
943 doc = xmlCopyDoc(doc, 1);
944 xmlFreeDoc(tmp);
945 }
946
947 if ((insert) && (!html)) {
948 const xmlChar* list[256];
949 int nb, i;
950 xmlNodePtr node;
951
952 if (doc->children != NULL) {
953 node = doc->children;
954 while ((node != NULL) && (node->last == NULL)) node = node->next;
955 if (node != NULL) {
956 nb = xmlValidGetValidElements(node->last, NULL, list, 256);
957 if (nb < 0) {
958 printf("could not get valid list of elements\n");
959 } else if (nb == 0) {
MDT 2001 John Fleckbbb9e432001-09-24 03:08:43 +0000960 printf("No element can be inserted under root\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000961 } else {
MDT 2001 John Fleckbbb9e432001-09-24 03:08:43 +0000962 printf("%d element types can be inserted under root:\n",
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000963 nb);
964 for (i = 0;i < nb;i++) {
Daniel Veillard8a1b1852003-01-05 22:37:17 +0000965 printf("%s\n", (char *) list[i]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000966 }
967 }
968 }
969 }
970 }else if (noout == 0) {
971 /*
972 * print it.
973 */
974#ifdef LIBXML_DEBUG_ENABLED
975 if (!debug) {
976#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +0000977 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +0000978 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +0000979 }
Daniel Veillard3b2c2612001-04-04 00:09:00 +0000980#ifdef HAVE_SYS_MMAN_H
Daniel Veillarda6d8eb62000-12-27 10:46:47 +0000981 if (memory) {
982 xmlChar *result;
983 int len;
984
985 if (encoding != NULL) {
Daniel Veillardd536f702001-11-08 17:32:47 +0000986 if ( format ) {
987 xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1);
988 } else {
989 xmlDocDumpMemoryEnc(doc, &result, &len, encoding);
990 }
Daniel Veillarda6d8eb62000-12-27 10:46:47 +0000991 } else {
Daniel Veillard90493a92001-08-14 14:12:47 +0000992 if (format)
993 xmlDocDumpFormatMemory(doc, &result, &len, 1);
994 else
995 xmlDocDumpMemory(doc, &result, &len);
Daniel Veillarda6d8eb62000-12-27 10:46:47 +0000996 }
997 if (result == NULL) {
998 fprintf(stderr, "Failed to save\n");
999 } else {
1000 write(1, result, len);
1001 xmlFree(result);
1002 }
Daniel Veillard3b2c2612001-04-04 00:09:00 +00001003 } else
1004#endif /* HAVE_SYS_MMAN_H */
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001005 if (compress) {
1006 xmlSaveFile(output ? output : "-", doc);
1007 }
Daniel Veillardd536f702001-11-08 17:32:47 +00001008 else if (encoding != NULL) {
1009 if ( format ) {
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001010 xmlSaveFormatFileEnc(output ? output : "-", doc, encoding, 1);
1011 }
Daniel Veillardd536f702001-11-08 17:32:47 +00001012 else {
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001013 xmlSaveFileEnc(output ? output : "-", doc, encoding);
Daniel Veillardd536f702001-11-08 17:32:47 +00001014 }
1015 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001016 else if (format) {
1017 xmlSaveFormatFile(output ? output : "-", doc, 1);
1018 }
1019 else {
1020 FILE *out;
1021 if (output == NULL)
1022 out = stdout;
1023 else {
1024 out = fopen(output,"wb");
1025 }
1026 xmlDocDump(out, doc);
1027
1028 if (output)
1029 fclose(out);
1030 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001031 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001032 endTimer("Saving");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001033 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001034#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001035 } else {
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001036 FILE *out;
1037 if (output == NULL)
1038 out = stdout;
1039 else {
1040 out = fopen(output,"wb");
1041 }
1042 xmlDebugDumpDocument(out, doc);
1043
1044 if (output)
1045 fclose(out);
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001046 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001047#endif
1048 }
1049
1050 /*
1051 * A posteriori validation test
1052 */
Daniel Veillard66f68e72003-08-18 16:39:51 +00001053 if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) {
Daniel Veillardcd429612000-10-11 15:57:05 +00001054 xmlDtdPtr dtd;
1055
Daniel Veillard48b2f892001-02-25 16:11:03 +00001056 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001057 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001058 }
Daniel Veillard66f68e72003-08-18 16:39:51 +00001059 if (dtdvalid != NULL)
1060 dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid);
1061 else
1062 dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001063 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001064 endTimer("Parsing DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001065 }
Daniel Veillardcd429612000-10-11 15:57:05 +00001066 if (dtd == NULL) {
Daniel Veillard66f68e72003-08-18 16:39:51 +00001067 if (dtdvalid != NULL)
1068 xmlGenericError(xmlGenericErrorContext,
1069 "Could not parse DTD %s\n", dtdvalid);
1070 else
1071 xmlGenericError(xmlGenericErrorContext,
1072 "Could not parse DTD %s\n", dtdvalidfpi);
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001073 progresult = 2;
Daniel Veillardcd429612000-10-11 15:57:05 +00001074 } else {
Daniel Veillarda37aab82003-06-09 09:10:36 +00001075 xmlValidCtxtPtr cvp;
1076
1077 if ((cvp = xmlNewValidCtxt()) == NULL) {
1078 xmlGenericError(xmlGenericErrorContext,
1079 "Couldn't allocate validation context\n");
1080 exit(-1);
1081 }
1082 cvp->userData = (void *) stderr;
1083 cvp->error = (xmlValidityErrorFunc) fprintf;
1084 cvp->warning = (xmlValidityWarningFunc) fprintf;
1085
Daniel Veillard48b2f892001-02-25 16:11:03 +00001086 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001087 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001088 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001089 if (!xmlValidateDtd(cvp, doc, dtd)) {
Daniel Veillard66f68e72003-08-18 16:39:51 +00001090 if (dtdvalid != NULL)
1091 xmlGenericError(xmlGenericErrorContext,
1092 "Document %s does not validate against %s\n",
1093 filename, dtdvalid);
1094 else
1095 xmlGenericError(xmlGenericErrorContext,
1096 "Document %s does not validate against %s\n",
1097 filename, dtdvalidfpi);
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001098 progresult = 3;
Daniel Veillardcd429612000-10-11 15:57:05 +00001099 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001100 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001101 endTimer("Validating against DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001102 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001103 xmlFreeValidCtxt(cvp);
Daniel Veillardcd429612000-10-11 15:57:05 +00001104 xmlFreeDtd(dtd);
1105 }
1106 } else if (postvalid) {
Daniel Veillarda37aab82003-06-09 09:10:36 +00001107 xmlValidCtxtPtr cvp;
1108
1109 if ((cvp = xmlNewValidCtxt()) == NULL) {
1110 xmlGenericError(xmlGenericErrorContext,
1111 "Couldn't allocate validation context\n");
1112 exit(-1);
1113 }
1114
Daniel Veillard48b2f892001-02-25 16:11:03 +00001115 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001116 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001117 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001118 cvp->userData = (void *) stderr;
1119 cvp->error = (xmlValidityErrorFunc) fprintf;
1120 cvp->warning = (xmlValidityWarningFunc) fprintf;
1121 if (!xmlValidateDocument(cvp, doc)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001122 xmlGenericError(xmlGenericErrorContext,
1123 "Document %s does not validate\n", filename);
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001124 progresult = 3;
Daniel Veillardcd429612000-10-11 15:57:05 +00001125 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001126 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001127 endTimer("Validating");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001128 }
Daniel Veillarda37aab82003-06-09 09:10:36 +00001129 xmlFreeValidCtxt(cvp);
Daniel Veillard71531f32003-02-05 13:19:53 +00001130#ifdef LIBXML_SCHEMAS_ENABLED
1131 } else if (relaxngschemas != NULL) {
1132 xmlRelaxNGValidCtxtPtr ctxt;
1133 int ret;
1134
Daniel Veillard42f12e92003-03-07 18:32:59 +00001135 if ((timing) && (!repeat)) {
1136 startTimer();
1137 }
1138
Daniel Veillard71531f32003-02-05 13:19:53 +00001139 ctxt = xmlRelaxNGNewValidCtxt(relaxngschemas);
1140 xmlRelaxNGSetValidErrors(ctxt,
1141 (xmlRelaxNGValidityErrorFunc) fprintf,
1142 (xmlRelaxNGValidityWarningFunc) fprintf,
1143 stderr);
1144 ret = xmlRelaxNGValidateDoc(ctxt, doc);
1145 if (ret == 0) {
1146 printf("%s validates\n", filename);
1147 } else if (ret > 0) {
1148 printf("%s fails to validate\n", filename);
1149 } else {
1150 printf("%s validation generated an internal error\n",
1151 filename);
1152 }
1153 xmlRelaxNGFreeValidCtxt(ctxt);
Daniel Veillard42f12e92003-03-07 18:32:59 +00001154 if ((timing) && (!repeat)) {
1155 endTimer("Validating");
1156 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001157 } else if (wxschemas != NULL) {
1158 xmlSchemaValidCtxtPtr ctxt;
1159 int ret;
1160
1161 if ((timing) && (!repeat)) {
1162 startTimer();
1163 }
1164
1165 ctxt = xmlSchemaNewValidCtxt(wxschemas);
1166 xmlSchemaSetValidErrors(ctxt,
1167 (xmlSchemaValidityErrorFunc) fprintf,
1168 (xmlSchemaValidityWarningFunc) fprintf,
1169 stderr);
1170 ret = xmlSchemaValidateDoc(ctxt, doc);
1171 if (ret == 0) {
1172 printf("%s validates\n", filename);
1173 } else if (ret > 0) {
1174 printf("%s fails to validate\n", filename);
1175 } else {
1176 printf("%s validation generated an internal error\n",
1177 filename);
1178 }
1179 xmlSchemaFreeValidCtxt(ctxt);
1180 if ((timing) && (!repeat)) {
1181 endTimer("Validating");
1182 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001183#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001184 }
1185
1186#ifdef LIBXML_DEBUG_ENABLED
1187 if ((debugent) && (!html))
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001188 xmlDebugDumpEntities(stderr, doc);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001189#endif
1190
1191 /*
1192 * free it.
1193 */
Daniel Veillard48b2f892001-02-25 16:11:03 +00001194 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001195 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001196 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001197 xmlFreeDoc(doc);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001198 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001199 endTimer("Freeing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001200 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001201}
1202
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001203/************************************************************************
1204 * *
1205 * Usage and Main *
1206 * *
1207 ************************************************************************/
1208
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001209static void showVersion(const char *name) {
1210 fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion);
1211 fprintf(stderr, " compiled with: ");
1212#ifdef LIBXML_FTP_ENABLED
1213 fprintf(stderr, "FTP ");
1214#endif
1215#ifdef LIBXML_HTTP_ENABLED
1216 fprintf(stderr, "HTTP ");
1217#endif
1218#ifdef LIBXML_HTML_ENABLED
1219 fprintf(stderr, "HTML ");
1220#endif
1221#ifdef LIBXML_C14N_ENABLED
1222 fprintf(stderr, "C14N ");
1223#endif
1224#ifdef LIBXML_CATALOG_ENABLED
1225 fprintf(stderr, "Catalog ");
1226#endif
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001227#ifdef LIBXML_XPATH_ENABLED
1228 fprintf(stderr, "XPath ");
1229#endif
1230#ifdef LIBXML_XPTR_ENABLED
1231 fprintf(stderr, "XPointer ");
1232#endif
1233#ifdef LIBXML_XINCLUDE_ENABLED
1234 fprintf(stderr, "XInclude ");
1235#endif
1236#ifdef LIBXML_ICONV_ENABLED
1237 fprintf(stderr, "Iconv ");
1238#endif
1239#ifdef DEBUG_MEMORY_LOCATION
1240 fprintf(stderr, "MemDebug ");
1241#endif
1242#ifdef LIBXML_UNICODE_ENABLED
1243 fprintf(stderr, "Unicode ");
1244#endif
1245#ifdef LIBXML_REGEXP_ENABLED
1246 fprintf(stderr, "Regexps ");
1247#endif
1248#ifdef LIBXML_AUTOMATA_ENABLED
1249 fprintf(stderr, "Automata ");
1250#endif
1251#ifdef LIBXML_SCHEMAS_ENABLED
1252 fprintf(stderr, "Schemas ");
1253#endif
1254 fprintf(stderr, "\n");
1255}
1256
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001257static void usage(const char *name) {
1258 printf("Usage : %s [options] XMLfiles ...\n", name);
1259 printf("\tParse the XML files and output the result of the parsing\n");
1260 printf("\t--version : display the version of the XML library used\n");
1261#ifdef LIBXML_DEBUG_ENABLED
1262 printf("\t--debug : dump a debug tree of the in-memory document\n");
1263 printf("\t--shell : run a navigating shell\n");
1264 printf("\t--debugent : debug the entities defined in the document\n");
Daniel Veillard8326e732003-01-07 00:19:07 +00001265#else
1266 printf("\t--debug : dump the nodes content when using --stream\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001267#endif
1268 printf("\t--copy : used to test the internal copy implementation\n");
1269 printf("\t--recover : output what was parsable on broken XML documents\n");
1270 printf("\t--noent : substitute entity references by their value\n");
1271 printf("\t--noout : don't output the result tree\n");
Daniel Veillarde8b09e42003-05-13 22:14:13 +00001272 printf("\t--nonet : refuse to fetch DTDs or entities over network\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001273 printf("\t--htmlout : output results as HTML\n");
Daniel Veillard05c13a22001-09-09 08:38:09 +00001274 printf("\t--nowrap : do not put HTML doc wrapper\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001275 printf("\t--valid : validate the document in addition to std well-formed check\n");
1276 printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
1277 printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
Daniel Veillard66f68e72003-08-18 16:39:51 +00001278 printf("\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001279 printf("\t--timing : print some timings\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001280 printf("\t--output file or -o file: save to a given file\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001281 printf("\t--repeat : repeat 100 times, for timing or profiling\n");
1282 printf("\t--insert : ad-hoc test for valid insertions\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001283#ifdef HAVE_ZLIB_H
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001284 printf("\t--compress : turn on gzip compression of output\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001285#endif
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001286#ifdef LIBXML_HTML_ENABLED
1287 printf("\t--html : use the HTML parser\n");
1288#endif
1289 printf("\t--push : use the push mode of the parser\n");
1290#ifdef HAVE_SYS_MMAN_H
1291 printf("\t--memory : parse from memory\n");
1292#endif
1293 printf("\t--nowarning : do not emit warnings from parser/validator\n");
1294 printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
Daniel Veillard90493a92001-08-14 14:12:47 +00001295 printf("\t--format : reformat/reindent the input\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001296 printf("\t--testIO : test user I/O support\n");
1297 printf("\t--encode encoding : output in the given encoding\n");
1298#ifdef LIBXML_CATALOG_ENABLED
Daniel Veillardbd9b0e82001-11-26 10:32:08 +00001299 printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");
1300 printf("\t otherwise XML Catalogs starting from \n");
Daniel Veillard3be27512003-01-26 19:49:04 +00001301 printf("\t " XML_XML_DEFAULT_CATALOG " are activated by default\n");
Daniel Veillard05c13a22001-09-09 08:38:09 +00001302 printf("\t--nocatalogs: deactivate all catalogs\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001303#endif
1304 printf("\t--auto : generate a small doc on the fly\n");
1305#ifdef LIBXML_XINCLUDE_ENABLED
1306 printf("\t--xinclude : do XInclude processing\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001307#endif
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001308 printf("\t--loaddtd : fetch external DTD\n");
Daniel Veillard48da9102001-08-07 01:10:10 +00001309 printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
Daniel Veillard29e43992001-12-13 22:21:58 +00001310 printf("\t--dropdtd : remove the DOCTYPE of the input docs\n");
Daniel Veillard7704fb12003-01-03 16:19:51 +00001311 printf("\t--stream : use the streaming interface to process very large files\n");
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001312 printf("\t--chkregister : verify the node registration code\n");
Daniel Veillardef4d3bc2003-02-07 12:38:22 +00001313#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard71531f32003-02-05 13:19:53 +00001314 printf("\t--relaxng schema : do RelaxNG validation against the schema\n");
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001315 printf("\t--schema schema : do validation against the WXS schema\n");
Daniel Veillard71531f32003-02-05 13:19:53 +00001316#endif
Daniel Veillarda42f25f2002-01-25 14:15:40 +00001317 printf("\nLibxml project home page: http://xmlsoft.org/\n");
1318 printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001319}
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001320
1321static void registerNode(xmlNodePtr node)
1322{
1323 node->_private = malloc(sizeof(long));
1324 *(long*)node->_private = (long) 0x81726354;
1325}
1326
1327static void deregisterNode(xmlNodePtr node)
1328{
1329 assert(node->_private != NULL);
1330 assert(*(long*)node->_private == (long) 0x81726354);
1331 free(node->_private);
1332}
1333
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001334int
1335main(int argc, char **argv) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00001336 int i, acount;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001337 int files = 0;
Daniel Veillard845cce42002-01-09 11:51:37 +00001338 int version = 0;
Aleksey Sanin693c9bc2003-03-09 22:36:52 +00001339 const char* indent;
1340
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001341 if (argc <= 1) {
1342 usage(argv[0]);
1343 return(1);
1344 }
Daniel Veillardbe803962000-06-28 23:40:59 +00001345 LIBXML_TEST_VERSION
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001346 for (i = 1; i < argc ; i++) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001347 if (!strcmp(argv[i], "-"))
1348 break;
1349
1350 if (argv[i][0] != '-')
1351 continue;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001352 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
1353 debug++;
Daniel Veillard56ada1d2003-01-07 11:17:25 +00001354 else
1355#ifdef LIBXML_DEBUG_ENABLED
1356 if ((!strcmp(argv[i], "-shell")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001357 (!strcmp(argv[i], "--shell"))) {
1358 shell++;
1359 noout = 1;
1360 } else
1361#endif
1362 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
1363 copy++;
1364 else if ((!strcmp(argv[i], "-recover")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001365 (!strcmp(argv[i], "--recover"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001366 recovery++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001367 options |= XML_PARSE_RECOVER;
1368 } else if ((!strcmp(argv[i], "-noent")) ||
1369 (!strcmp(argv[i], "--noent"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001370 noent++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001371 options |= XML_PARSE_NOENT;
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001372 } else if ((!strcmp(argv[i], "-nodict")) ||
1373 (!strcmp(argv[i], "--nodict"))) {
1374 options |= XML_PARSE_NODICT;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001375 } else if ((!strcmp(argv[i], "-version")) ||
Daniel Veillard845cce42002-01-09 11:51:37 +00001376 (!strcmp(argv[i], "--version"))) {
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001377 showVersion(argv[0]);
Daniel Veillard845cce42002-01-09 11:51:37 +00001378 version = 1;
1379 } else if ((!strcmp(argv[i], "-noout")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001380 (!strcmp(argv[i], "--noout")))
1381 noout++;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001382 else if ((!strcmp(argv[i], "-o")) ||
1383 (!strcmp(argv[i], "-output")) ||
1384 (!strcmp(argv[i], "--output"))) {
1385 i++;
Daniel Veillard6e4f1c02002-04-09 09:55:20 +00001386 output = argv[i];
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001387 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001388 else if ((!strcmp(argv[i], "-htmlout")) ||
1389 (!strcmp(argv[i], "--htmlout")))
1390 htmlout++;
1391#ifdef LIBXML_HTML_ENABLED
1392 else if ((!strcmp(argv[i], "-html")) ||
1393 (!strcmp(argv[i], "--html"))) {
1394 html++;
1395 }
1396#endif /* LIBXML_HTML_ENABLED */
1397 else if ((!strcmp(argv[i], "-nowrap")) ||
1398 (!strcmp(argv[i], "--nowrap")))
1399 nowrap++;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001400 else if ((!strcmp(argv[i], "-loaddtd")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001401 (!strcmp(argv[i], "--loaddtd"))) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001402 loaddtd++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001403 options |= XML_PARSE_DTDLOAD;
1404 } else if ((!strcmp(argv[i], "-dtdattr")) ||
Daniel Veillard48da9102001-08-07 01:10:10 +00001405 (!strcmp(argv[i], "--dtdattr"))) {
1406 loaddtd++;
1407 dtdattrs++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001408 options |= XML_PARSE_DTDATTR;
Daniel Veillard48da9102001-08-07 01:10:10 +00001409 } else if ((!strcmp(argv[i], "-valid")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001410 (!strcmp(argv[i], "--valid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001411 valid++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001412 options |= XML_PARSE_DTDVALID;
1413 } else if ((!strcmp(argv[i], "-postvalid")) ||
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001414 (!strcmp(argv[i], "--postvalid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001415 postvalid++;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001416 loaddtd++;
1417 } else if ((!strcmp(argv[i], "-dtdvalid")) ||
Daniel Veillardcd429612000-10-11 15:57:05 +00001418 (!strcmp(argv[i], "--dtdvalid"))) {
1419 i++;
1420 dtdvalid = argv[i];
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001421 loaddtd++;
Daniel Veillard66f68e72003-08-18 16:39:51 +00001422 } else if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
1423 (!strcmp(argv[i], "--dtdvalidfpi"))) {
1424 i++;
1425 dtdvalidfpi = argv[i];
1426 loaddtd++;
Daniel Veillardcd429612000-10-11 15:57:05 +00001427 }
Daniel Veillard29e43992001-12-13 22:21:58 +00001428 else if ((!strcmp(argv[i], "-dropdtd")) ||
1429 (!strcmp(argv[i], "--dropdtd")))
1430 dropdtd++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001431 else if ((!strcmp(argv[i], "-insert")) ||
1432 (!strcmp(argv[i], "--insert")))
1433 insert++;
Daniel Veillard48b2f892001-02-25 16:11:03 +00001434 else if ((!strcmp(argv[i], "-timing")) ||
1435 (!strcmp(argv[i], "--timing")))
1436 timing++;
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001437 else if ((!strcmp(argv[i], "-auto")) ||
1438 (!strcmp(argv[i], "--auto")))
1439 generate++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001440 else if ((!strcmp(argv[i], "-repeat")) ||
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00001441 (!strcmp(argv[i], "--repeat"))) {
1442 if (repeat)
1443 repeat *= 10;
1444 else
1445 repeat = 100;
1446 } else if ((!strcmp(argv[i], "-push")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001447 (!strcmp(argv[i], "--push")))
1448 push++;
Daniel Veillard46e370e2000-07-21 20:32:03 +00001449#ifdef HAVE_SYS_MMAN_H
1450 else if ((!strcmp(argv[i], "-memory")) ||
1451 (!strcmp(argv[i], "--memory")))
1452 memory++;
1453#endif
Daniel Veillard5e873c42000-04-12 13:27:38 +00001454 else if ((!strcmp(argv[i], "-testIO")) ||
1455 (!strcmp(argv[i], "--testIO")))
1456 testIO++;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001457#ifdef LIBXML_XINCLUDE_ENABLED
1458 else if ((!strcmp(argv[i], "-xinclude")) ||
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001459 (!strcmp(argv[i], "--xinclude"))) {
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001460 xinclude++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001461 /* options |= XML_PARSE_XINCLUDE; */
1462 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001463#endif
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001464#ifdef HAVE_ZLIB_H
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001465 else if ((!strcmp(argv[i], "-compress")) ||
1466 (!strcmp(argv[i], "--compress"))) {
1467 compress++;
1468 xmlSetCompressMode(9);
1469 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001470#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001471 else if ((!strcmp(argv[i], "-nowarning")) ||
1472 (!strcmp(argv[i], "--nowarning"))) {
1473 xmlGetWarningsDefaultValue = 0;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001474 xmlPedanticParserDefault(0);
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001475 options |= XML_PARSE_NOWARNING;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001476 }
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001477 else if ((!strcmp(argv[i], "-pedantic")) ||
1478 (!strcmp(argv[i], "--pedantic"))) {
1479 xmlGetWarningsDefaultValue = 1;
1480 xmlPedanticParserDefault(1);
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001481 options |= XML_PARSE_PEDANTIC;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001482 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00001483#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001484 else if ((!strcmp(argv[i], "-debugent")) ||
1485 (!strcmp(argv[i], "--debugent"))) {
1486 debugent++;
1487 xmlParserDebugEntities = 1;
1488 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00001489#endif
Daniel Veillard81418e32001-05-22 15:08:55 +00001490#ifdef LIBXML_CATALOG_ENABLED
1491 else if ((!strcmp(argv[i], "-catalogs")) ||
1492 (!strcmp(argv[i], "--catalogs"))) {
Daniel Veillarde2940dd2001-08-22 00:06:49 +00001493 catalogs++;
1494 } else if ((!strcmp(argv[i], "-nocatalogs")) ||
1495 (!strcmp(argv[i], "--nocatalogs"))) {
1496 nocatalogs++;
Daniel Veillard81418e32001-05-22 15:08:55 +00001497 }
1498#endif
Daniel Veillardbe803962000-06-28 23:40:59 +00001499 else if ((!strcmp(argv[i], "-encode")) ||
1500 (!strcmp(argv[i], "--encode"))) {
1501 i++;
1502 encoding = argv[i];
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001503 /*
1504 * OK it's for testing purposes
1505 */
1506 xmlAddEncodingAlias("UTF-8", "DVEnc");
Daniel Veillardbe803962000-06-28 23:40:59 +00001507 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001508 else if ((!strcmp(argv[i], "-noblanks")) ||
1509 (!strcmp(argv[i], "--noblanks"))) {
1510 noblanks++;
1511 xmlKeepBlanksDefault(0);
Daniel Veillard90493a92001-08-14 14:12:47 +00001512 }
1513 else if ((!strcmp(argv[i], "-format")) ||
1514 (!strcmp(argv[i], "--format"))) {
1515 noblanks++;
1516 format++;
1517 xmlKeepBlanksDefault(0);
Daniel Veillard7704fb12003-01-03 16:19:51 +00001518 }
1519 else if ((!strcmp(argv[i], "-stream")) ||
1520 (!strcmp(argv[i], "--stream"))) {
1521 stream++;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001522 }
Daniel Veillard07cb8222003-09-10 10:51:05 +00001523 else if ((!strcmp(argv[i], "-sax1")) ||
1524 (!strcmp(argv[i], "--sax1"))) {
1525 sax1++;
1526 }
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001527 else if ((!strcmp(argv[i], "-chkregister")) ||
1528 (!strcmp(argv[i], "--chkregister"))) {
1529 chkregister++;
Daniel Veillard71531f32003-02-05 13:19:53 +00001530#ifdef LIBXML_SCHEMAS_ENABLED
1531 } else if ((!strcmp(argv[i], "-relaxng")) ||
1532 (!strcmp(argv[i], "--relaxng"))) {
1533 i++;
1534 relaxng = argv[i];
1535 noent++;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001536 options |= XML_PARSE_NOENT;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001537 } else if ((!strcmp(argv[i], "-schema")) ||
1538 (!strcmp(argv[i], "--schema"))) {
1539 i++;
1540 schema = argv[i];
1541 noent++;
Daniel Veillard71531f32003-02-05 13:19:53 +00001542#endif
Daniel Veillarde8b09e42003-05-13 22:14:13 +00001543 } else if ((!strcmp(argv[i], "-nonet")) ||
1544 (!strcmp(argv[i], "--nonet"))) {
1545 xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001546 } else {
1547 fprintf(stderr, "Unknown option %s\n", argv[i]);
1548 usage(argv[0]);
1549 return(1);
1550 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001551 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00001552
1553#ifdef LIBXML_CATALOG_ENABLED
1554 if (nocatalogs == 0) {
1555 if (catalogs) {
1556 const char *catal;
1557
1558 catal = getenv("SGML_CATALOG_FILES");
Daniel Veillard6c5f9d12001-08-25 13:33:14 +00001559 if (catal != NULL) {
1560 xmlLoadCatalogs(catal);
1561 } else {
1562 fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n");
1563 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00001564 }
1565 }
1566#endif
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001567
Daniel Veillard07cb8222003-09-10 10:51:05 +00001568 if (sax1)
1569 xmlSAXDefaultVersion(1);
1570 else
1571 xmlSAXDefaultVersion(2);
1572
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001573 if (chkregister) {
1574 xmlRegisterNodeDefault(registerNode);
1575 xmlDeregisterNodeDefault(deregisterNode);
1576 }
Aleksey Sanin693c9bc2003-03-09 22:36:52 +00001577
1578 indent = getenv("XMLLINT_INDENT");
1579 if(indent != NULL) {
1580 xmlTreeIndentString = indent;
1581 }
1582
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001583
Daniel Veillardd9bad132001-07-23 19:39:43 +00001584 xmlLineNumbersDefault(1);
Daniel Veillard48da9102001-08-07 01:10:10 +00001585 if (loaddtd != 0)
1586 xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
1587 if (dtdattrs)
1588 xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001589 if (noent != 0) xmlSubstituteEntitiesDefault(1);
1590 if (valid != 0) xmlDoValidityCheckingDefaultValue = 1;
1591 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001592 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001593 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001594 xmlGenericError(xmlGenericErrorContext,
1595 "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
1596 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001597 "<html><head><title>%s output</title></head>\n",
1598 argv[0]);
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001599 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001600 "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
1601 argv[0]);
1602 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001603
1604#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillardce192eb2003-04-16 15:58:05 +00001605 if ((relaxng != NULL) && (stream == 0)) {
Daniel Veillard71531f32003-02-05 13:19:53 +00001606 xmlRelaxNGParserCtxtPtr ctxt;
1607
Daniel Veillardce192eb2003-04-16 15:58:05 +00001608 /* forces loading the DTDs */
1609 xmlLoadExtDtdDefaultValue |= 1;
Daniel Veillard16fa96c2003-09-23 21:50:54 +00001610 options |= XML_PARSE_DTDLOAD;
Daniel Veillard42f12e92003-03-07 18:32:59 +00001611 if (timing) {
1612 startTimer();
1613 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001614 ctxt = xmlRelaxNGNewParserCtxt(relaxng);
1615 xmlRelaxNGSetParserErrors(ctxt,
1616 (xmlRelaxNGValidityErrorFunc) fprintf,
1617 (xmlRelaxNGValidityWarningFunc) fprintf,
1618 stderr);
1619 relaxngschemas = xmlRelaxNGParse(ctxt);
Daniel Veillardce192eb2003-04-16 15:58:05 +00001620 if (relaxngschemas == NULL) {
1621 xmlGenericError(xmlGenericErrorContext,
1622 "Relax-NG schema %s failed to compile\n", relaxng);
1623 relaxng = NULL;
1624 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001625 xmlRelaxNGFreeParserCtxt(ctxt);
Daniel Veillard42f12e92003-03-07 18:32:59 +00001626 if (timing) {
1627 endTimer("Compiling the schemas");
1628 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001629 } else if ((schema != NULL) && (stream == 0)) {
1630 xmlSchemaParserCtxtPtr ctxt;
1631
1632 if (timing) {
1633 startTimer();
1634 }
1635 ctxt = xmlSchemaNewParserCtxt(schema);
1636 xmlSchemaSetParserErrors(ctxt,
1637 (xmlSchemaValidityErrorFunc) fprintf,
1638 (xmlSchemaValidityWarningFunc) fprintf,
1639 stderr);
1640 wxschemas = xmlSchemaParse(ctxt);
1641 if (wxschemas == NULL) {
1642 xmlGenericError(xmlGenericErrorContext,
1643 "WXS schema %s failed to compile\n", schema);
1644 schema = NULL;
1645 }
1646 xmlSchemaFreeParserCtxt(ctxt);
1647 if (timing) {
1648 endTimer("Compiling the schemas");
1649 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001650 }
1651#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001652 for (i = 1; i < argc ; i++) {
Daniel Veillardbe803962000-06-28 23:40:59 +00001653 if ((!strcmp(argv[i], "-encode")) ||
1654 (!strcmp(argv[i], "--encode"))) {
1655 i++;
1656 continue;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001657 } else if ((!strcmp(argv[i], "-o")) ||
1658 (!strcmp(argv[i], "-output")) ||
1659 (!strcmp(argv[i], "--output"))) {
1660 i++;
1661 continue;
Daniel Veillardbe803962000-06-28 23:40:59 +00001662 }
Daniel Veillardcd429612000-10-11 15:57:05 +00001663 if ((!strcmp(argv[i], "-dtdvalid")) ||
1664 (!strcmp(argv[i], "--dtdvalid"))) {
1665 i++;
1666 continue;
1667 }
Daniel Veillard66f68e72003-08-18 16:39:51 +00001668 if ((!strcmp(argv[i], "-dtdvalidfpi")) ||
1669 (!strcmp(argv[i], "--dtdvalidfpi"))) {
1670 i++;
1671 continue;
1672 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001673 if ((!strcmp(argv[i], "-relaxng")) ||
1674 (!strcmp(argv[i], "--relaxng"))) {
1675 i++;
1676 continue;
1677 }
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001678 if ((!strcmp(argv[i], "-schema")) ||
1679 (!strcmp(argv[i], "--schema"))) {
1680 i++;
1681 continue;
1682 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001683 if ((timing) && (repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +00001684 startTimer();
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001685 /* Remember file names. "-" means stdin. <sven@zen.org> */
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001686 if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001687 if (repeat) {
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001688 xmlParserCtxtPtr ctxt = NULL;
1689
1690 for (acount = 0;acount < repeat;acount++) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00001691 if (stream != 0)
1692 streamFile(argv[i]);
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001693 else {
1694 if (ctxt == NULL)
1695 ctxt = xmlNewParserCtxt();
1696 parseAndPrintFile(argv[i], ctxt);
1697 }
1698 }
1699 if (ctxt != NULL)
1700 xmlFreeParserCtxt(ctxt);
Daniel Veillard7704fb12003-01-03 16:19:51 +00001701 } else {
1702 if (stream != 0)
1703 streamFile(argv[i]);
1704 else
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001705 parseAndPrintFile(argv[i], NULL);
Daniel Veillard7704fb12003-01-03 16:19:51 +00001706 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001707 files ++;
Daniel Veillarda7866932001-12-04 13:14:44 +00001708 if ((timing) && (repeat)) {
Daniel Veillard8d8bf2c2003-09-17 19:36:25 +00001709 endTimer("%d iterations", repeat);
Daniel Veillarda7866932001-12-04 13:14:44 +00001710 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001711 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001712 }
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001713 if (generate)
Daniel Veillarde96a2a42003-09-24 21:23:56 +00001714 parseAndPrintFile(NULL, NULL);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001715 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001716 xmlGenericError(xmlGenericErrorContext, "</body></html>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001717 }
Daniel Veillard845cce42002-01-09 11:51:37 +00001718 if ((files == 0) && (!generate) && (version == 0)) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001719 usage(argv[0]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001720 }
Daniel Veillard71531f32003-02-05 13:19:53 +00001721#ifdef LIBXML_SCHEMAS_ENABLED
1722 if (relaxngschemas != NULL)
1723 xmlRelaxNGFree(relaxngschemas);
Daniel Veillard75bb3bb2003-05-12 15:25:56 +00001724 if (wxschemas != NULL)
1725 xmlSchemaFree(wxschemas);
Daniel Veillard71531f32003-02-05 13:19:53 +00001726 xmlRelaxNGCleanupTypes();
1727#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001728 xmlCleanupParser();
1729 xmlMemoryDump();
1730
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001731 return(progresult);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001732}
Daniel Veillard88a172f2000-08-04 18:23:10 +00001733