blob: ba606e699d0aec4a11d363666518faac9b3f058f [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 Veillard28ae6362001-07-14 16:44:32 +000013
Daniel Veillard8a1b1852003-01-05 22:37:17 +000014#include <assert.h>
15
Daniel Veillard3c5ed912002-01-08 10:36:16 +000016#if defined (_WIN32) && !defined(__CYGWIN__)
Daniel Veillard2d90de42001-04-16 17:46:18 +000017#ifdef _MSC_VER
18#include <winsock2.h>
19#pragma comment(lib, "ws2_32.lib")
20#define gettimeofday(p1,p2)
Daniel Veillardf216d462002-02-08 13:44:24 +000021#include <time.h>
Daniel Veillard28ae6362001-07-14 16:44:32 +000022#else /* _MSC_VER */
23#include <sys/time.h>
Daniel Veillard2d90de42001-04-16 17:46:18 +000024#endif /* _MSC_VER */
25#else /* _WIN32 */
Daniel Veillarded472f32001-12-13 08:48:14 +000026#ifdef HAVE_SYS_TIME_H
Daniel Veillard48b2f892001-02-25 16:11:03 +000027#include <sys/time.h>
Daniel Veillarded472f32001-12-13 08:48:14 +000028#endif
Daniel Veillard01db67c2001-12-18 07:09:59 +000029#ifdef HAVE_TIME_H
30#include <time.h>
31#endif
Daniel Veillard2d90de42001-04-16 17:46:18 +000032#endif /* _WIN32 */
Daniel Veillard48b2f892001-02-25 16:11:03 +000033
Daniel Veillard90bc3712002-03-07 15:12:58 +000034#ifdef HAVE_SYS_TIMEB_H
35#include <sys/timeb.h>
36#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +000037
38#ifdef HAVE_SYS_TYPES_H
39#include <sys/types.h>
40#endif
41#ifdef HAVE_SYS_STAT_H
42#include <sys/stat.h>
43#endif
44#ifdef HAVE_FCNTL_H
45#include <fcntl.h>
46#endif
47#ifdef HAVE_UNISTD_H
48#include <unistd.h>
49#endif
Daniel Veillard46e370e2000-07-21 20:32:03 +000050#ifdef HAVE_SYS_MMAN_H
51#include <sys/mman.h>
Daniel Veillard87b95392000-08-12 21:12:04 +000052/* seems needed for Solaris */
53#ifndef MAP_FAILED
54#define MAP_FAILED ((void *) -1)
55#endif
Daniel Veillard46e370e2000-07-21 20:32:03 +000056#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +000057#ifdef HAVE_STDLIB_H
58#include <stdlib.h>
59#endif
60#ifdef HAVE_LIBREADLINE
61#include <readline/readline.h>
62#ifdef HAVE_LIBHISTORY
63#include <readline/history.h>
64#endif
65#endif
66
67#include <libxml/xmlmemory.h>
68#include <libxml/parser.h>
69#include <libxml/parserInternals.h>
70#include <libxml/HTMLparser.h>
71#include <libxml/HTMLtree.h>
72#include <libxml/tree.h>
73#include <libxml/xpath.h>
74#include <libxml/debugXML.h>
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +000075#include <libxml/xmlerror.h>
Daniel Veillard9e8bfae2000-11-06 16:43:11 +000076#ifdef LIBXML_XINCLUDE_ENABLED
77#include <libxml/xinclude.h>
78#endif
Daniel Veillard81418e32001-05-22 15:08:55 +000079#ifdef LIBXML_CATALOG_ENABLED
80#include <libxml/catalog.h>
81#endif
Daniel Veillard89cad532001-10-22 09:46:13 +000082#ifdef LIBXML_DOCB_ENABLED
83#include <libxml/DOCBparser.h>
84#endif
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000085#include <libxml/globals.h>
Daniel Veillard7704fb12003-01-03 16:19:51 +000086#include <libxml/xmlreader.h>
Daniel Veillardce8b83b2000-04-05 18:38:42 +000087
Daniel Veillard3be27512003-01-26 19:49:04 +000088#ifndef XML_XML_DEFAULT_CATALOG
89#define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog"
90#endif
91
Daniel Veillardce8b83b2000-04-05 18:38:42 +000092#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +000093static int shell = 0;
94static int debugent = 0;
95#endif
Daniel Veillard8326e732003-01-07 00:19:07 +000096static int debug = 0;
Daniel Veillardce8b83b2000-04-05 18:38:42 +000097static int copy = 0;
98static int recovery = 0;
99static int noent = 0;
100static int noout = 0;
101static int nowrap = 0;
102static int valid = 0;
103static int postvalid = 0;
Daniel Veillardcd429612000-10-11 15:57:05 +0000104static char * dtdvalid = NULL;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000105static int repeat = 0;
106static int insert = 0;
107static int compress = 0;
Daniel Veillard89cad532001-10-22 09:46:13 +0000108#ifdef LIBXML_DOCB_ENABLED
109static int sgml = 0;
110#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000111static int html = 0;
112static int htmlout = 0;
113static int push = 0;
Daniel Veillard46e370e2000-07-21 20:32:03 +0000114#ifdef HAVE_SYS_MMAN_H
115static int memory = 0;
116#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000117static int noblanks = 0;
Daniel Veillard90493a92001-08-14 14:12:47 +0000118static int format = 0;
Daniel Veillard5e873c42000-04-12 13:27:38 +0000119static int testIO = 0;
Daniel Veillardbe803962000-06-28 23:40:59 +0000120static char *encoding = NULL;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000121#ifdef LIBXML_XINCLUDE_ENABLED
122static int xinclude = 0;
123#endif
Daniel Veillard48da9102001-08-07 01:10:10 +0000124static int dtdattrs = 0;
Daniel Veillard10ea86c2001-06-20 13:55:33 +0000125static int loaddtd = 0;
Daniel Veillardf7cd4812001-02-23 18:44:52 +0000126static int progresult = 0;
Daniel Veillard48b2f892001-02-25 16:11:03 +0000127static int timing = 0;
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000128static int generate = 0;
Daniel Veillard29e43992001-12-13 22:21:58 +0000129static int dropdtd = 0;
Daniel Veillarde2940dd2001-08-22 00:06:49 +0000130#ifdef LIBXML_CATALOG_ENABLED
131static int catalogs = 0;
132static int nocatalogs = 0;
133#endif
Daniel Veillard7704fb12003-01-03 16:19:51 +0000134static int stream = 0;
Daniel Veillard8a1b1852003-01-05 22:37:17 +0000135static int chkregister = 0;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000136static const char *output = NULL;
137
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000138
Daniel Veillard01db67c2001-12-18 07:09:59 +0000139/*
140 * Internal timing routines to remove the necessity to have unix-specific
141 * function calls
142 */
143
Daniel Veillard8c1ae602002-03-07 11:21:00 +0000144#ifndef HAVE_GETTIMEOFDAY
145#ifdef HAVE_SYS_TIMEB_H
146#ifdef HAVE_SYS_TIME_H
147#ifdef HAVE_FTIME
148
Daniel Veillard01c13b52002-12-10 15:19:08 +0000149static int
Daniel Veillard8c1ae602002-03-07 11:21:00 +0000150my_gettimeofday(struct timeval *tvp, void *tzp)
151{
152 struct timeb timebuffer;
153
154 ftime(&timebuffer);
155 if (tvp) {
156 tvp->tv_sec = timebuffer.time;
157 tvp->tv_usec = timebuffer.millitm * 1000L;
158 }
159 return (0);
160}
161#define HAVE_GETTIMEOFDAY 1
162#define gettimeofday my_gettimeofday
163
164#endif /* HAVE_FTIME */
165#endif /* HAVE_SYS_TIME_H */
166#endif /* HAVE_SYS_TIMEB_H */
167#endif /* !HAVE_GETTIMEOFDAY */
168
Daniel Veillard01db67c2001-12-18 07:09:59 +0000169#if defined(HAVE_GETTIMEOFDAY)
170static struct timeval begin, end;
171
172/*
173 * startTimer: call where you want to start timing
174 */
175static void
176startTimer(void)
177{
178 gettimeofday(&begin, NULL);
179}
180
181/*
182 * endTimer: call where you want to stop timing and to print out a
183 * message about the timing performed; format is a printf
184 * type argument
185 */
186static void
Daniel Veillard118aed72002-09-24 14:13:13 +0000187endTimer(const char *fmt, ...)
Daniel Veillard01db67c2001-12-18 07:09:59 +0000188{
189 long msec;
190 va_list ap;
191
192 gettimeofday(&end, NULL);
193 msec = end.tv_sec - begin.tv_sec;
194 msec *= 1000;
195 msec += (end.tv_usec - begin.tv_usec) / 1000;
196
197#ifndef HAVE_STDARG_H
198#error "endTimer required stdarg functions"
199#endif
Daniel Veillard118aed72002-09-24 14:13:13 +0000200 va_start(ap, fmt);
201 vfprintf(stderr, fmt, ap);
Daniel Veillard01db67c2001-12-18 07:09:59 +0000202 va_end(ap);
203
204 fprintf(stderr, " took %ld ms\n", msec);
205}
206#elif defined(HAVE_TIME_H)
Daniel Veillard01db67c2001-12-18 07:09:59 +0000207/*
208 * No gettimeofday function, so we have to make do with calling clock.
209 * This is obviously less accurate, but there's little we can do about
210 * that.
211 */
Daniel Veillard90bc3712002-03-07 15:12:58 +0000212#ifndef CLOCKS_PER_SEC
213#define CLOCKS_PER_SEC 100
214#endif
Daniel Veillard01db67c2001-12-18 07:09:59 +0000215
216static clock_t begin, end;
217static void
218startTimer(void)
219{
220 begin = clock();
221}
222static void
223endTimer(const char *fmt, ...)
224{
225 long msec;
226 va_list ap;
227
228 end = clock();
229 msec = ((end - begin) * 1000) / CLOCKS_PER_SEC;
230
231#ifndef HAVE_STDARG_H
232#error "endTimer required stdarg functions"
233#endif
234 va_start(ap, fmt);
235 vfprintf(stderr, fmt, ap);
236 va_end(ap);
237 fprintf(stderr, " took %ld ms\n", msec);
238}
239#else
240
241/*
242 * We don't have a gettimeofday or time.h, so we just don't do timing
243 */
244static void
245startTimer(void)
246{
247 /*
248 * Do nothing
249 */
250}
251static void
252endTimer(char *format, ...)
253{
254 /*
255 * We cannot do anything because we don't have a timing function
256 */
257#ifdef HAVE_STDARG_H
258 va_start(ap, format);
259 vfprintf(stderr, format, ap);
260 va_end(ap);
261 fprintf(stderr, " was not timed\n", msec);
262#else
263 /* We don't have gettimeofday, time or stdarg.h, what crazy world is
264 * this ?!
265 */
266#endif
267}
268#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000269/************************************************************************
270 * *
271 * HTML ouput *
272 * *
273 ************************************************************************/
274char buffer[50000];
275
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000276static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000277xmlHTMLEncodeSend(void) {
278 char *result;
279
280 result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer);
281 if (result) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000282 xmlGenericError(xmlGenericErrorContext, "%s", result);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000283 xmlFree(result);
284 }
285 buffer[0] = 0;
286}
287
288/**
289 * xmlHTMLPrintFileInfo:
290 * @input: an xmlParserInputPtr input
291 *
292 * Displays the associated file and line informations for the current input
293 */
294
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000295static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000296xmlHTMLPrintFileInfo(xmlParserInputPtr input) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000297 int len;
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000298 xmlGenericError(xmlGenericErrorContext, "<p>");
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000299
300 len = strlen(buffer);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000301 if (input != NULL) {
302 if (input->filename) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000303 snprintf(&buffer[len], sizeof(buffer) - len, "%s:%d: ", input->filename,
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000304 input->line);
305 } else {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000306 snprintf(&buffer[len], sizeof(buffer) - len, "Entity: line %d: ", input->line);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000307 }
308 }
309 xmlHTMLEncodeSend();
310}
311
312/**
313 * xmlHTMLPrintFileContext:
314 * @input: an xmlParserInputPtr input
315 *
316 * Displays current context within the input content for error tracking
317 */
318
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000319static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000320xmlHTMLPrintFileContext(xmlParserInputPtr input) {
321 const xmlChar *cur, *base;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000322 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000323 int n;
324
325 if (input == NULL) return;
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000326 xmlGenericError(xmlGenericErrorContext, "<pre>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000327 cur = input->cur;
328 base = input->base;
329 while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
330 cur--;
331 }
332 n = 0;
333 while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
334 cur--;
335 if ((*cur == '\n') || (*cur == '\r')) cur++;
336 base = cur;
337 n = 0;
338 while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000339 len = strlen(buffer);
340 snprintf(&buffer[len], sizeof(buffer) - len, "%c",
341 (unsigned char) *cur++);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000342 n++;
343 }
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000344 len = strlen(buffer);
345 snprintf(&buffer[len], sizeof(buffer) - len, "\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000346 cur = input->cur;
347 while ((*cur == '\n') || (*cur == '\r'))
348 cur--;
349 n = 0;
350 while ((cur != base) && (n++ < 80)) {
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000351 len = strlen(buffer);
352 snprintf(&buffer[len], sizeof(buffer) - len, " ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000353 base++;
354 }
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000355 len = strlen(buffer);
356 snprintf(&buffer[len], sizeof(buffer) - len, "^\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000357 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000358 xmlGenericError(xmlGenericErrorContext, "</pre>");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000359}
360
361/**
362 * xmlHTMLError:
363 * @ctx: an XML parser context
364 * @msg: the message to display/transmit
365 * @...: extra parameters for the message display
366 *
367 * Display and format an error messages, gives file, line, position and
368 * extra parameters.
369 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000370static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000371xmlHTMLError(void *ctx, const char *msg, ...)
372{
373 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
374 xmlParserInputPtr input;
375 xmlParserInputPtr cur = NULL;
376 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000377 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000378
379 buffer[0] = 0;
380 input = ctxt->input;
381 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
382 cur = input;
383 input = ctxt->inputTab[ctxt->inputNr - 2];
384 }
385
386 xmlHTMLPrintFileInfo(input);
387
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000388 xmlGenericError(xmlGenericErrorContext, "<b>error</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000389 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000390 len = strlen(buffer);
391 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000392 va_end(args);
393 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000394 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000395
396 xmlHTMLPrintFileContext(input);
397 xmlHTMLEncodeSend();
398}
399
400/**
401 * xmlHTMLWarning:
402 * @ctx: an XML parser context
403 * @msg: the message to display/transmit
404 * @...: extra parameters for the message display
405 *
406 * Display and format a warning messages, gives file, line, position and
407 * extra parameters.
408 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000409static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000410xmlHTMLWarning(void *ctx, const char *msg, ...)
411{
412 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
413 xmlParserInputPtr input;
414 xmlParserInputPtr cur = NULL;
415 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000416 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000417
418 buffer[0] = 0;
419 input = ctxt->input;
420 if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) {
421 cur = input;
422 input = ctxt->inputTab[ctxt->inputNr - 2];
423 }
424
425
426 xmlHTMLPrintFileInfo(input);
427
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000428 xmlGenericError(xmlGenericErrorContext, "<b>warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000429 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000430 len = strlen(buffer);
431 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000432 va_end(args);
433 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000434 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000435
436 xmlHTMLPrintFileContext(input);
437 xmlHTMLEncodeSend();
438}
439
440/**
441 * xmlHTMLValidityError:
442 * @ctx: an XML parser context
443 * @msg: the message to display/transmit
444 * @...: extra parameters for the message display
445 *
446 * Display and format an validity error messages, gives file,
447 * line, position and extra parameters.
448 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000449static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000450xmlHTMLValidityError(void *ctx, const char *msg, ...)
451{
452 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
453 xmlParserInputPtr input;
454 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000455 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000456
457 buffer[0] = 0;
458 input = ctxt->input;
459 if ((input->filename == NULL) && (ctxt->inputNr > 1))
460 input = ctxt->inputTab[ctxt->inputNr - 2];
461
462 xmlHTMLPrintFileInfo(input);
463
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000464 xmlGenericError(xmlGenericErrorContext, "<b>validity error</b>: ");
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000465 len = strlen(buffer);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000466 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000467 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000468 va_end(args);
469 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000470 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000471
472 xmlHTMLPrintFileContext(input);
473 xmlHTMLEncodeSend();
474}
475
476/**
477 * xmlHTMLValidityWarning:
478 * @ctx: an XML parser context
479 * @msg: the message to display/transmit
480 * @...: extra parameters for the message display
481 *
482 * Display and format a validity warning messages, gives file, line,
483 * position and extra parameters.
484 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000485static void
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000486xmlHTMLValidityWarning(void *ctx, const char *msg, ...)
487{
488 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
489 xmlParserInputPtr input;
490 va_list args;
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000491 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000492
493 buffer[0] = 0;
494 input = ctxt->input;
495 if ((input->filename == NULL) && (ctxt->inputNr > 1))
496 input = ctxt->inputTab[ctxt->inputNr - 2];
497
498 xmlHTMLPrintFileInfo(input);
499
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000500 xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: ");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000501 va_start(args, msg);
Aleksey Sanin49cc9752002-06-14 17:07:10 +0000502 len = strlen(buffer);
503 vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000504 va_end(args);
505 xmlHTMLEncodeSend();
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +0000506 xmlGenericError(xmlGenericErrorContext, "</p>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000507
508 xmlHTMLPrintFileContext(input);
509 xmlHTMLEncodeSend();
510}
511
512/************************************************************************
513 * *
514 * Shell Interface *
515 * *
516 ************************************************************************/
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000517#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000518/**
519 * xmlShellReadline:
520 * @prompt: the prompt value
521 *
522 * Read a string
523 *
524 * Returns a pointer to it or NULL on EOF the caller is expected to
525 * free the returned string.
526 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000527static char *
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000528xmlShellReadline(char *prompt) {
529#ifdef HAVE_LIBREADLINE
530 char *line_read;
531
532 /* Get a line from the user. */
533 line_read = readline (prompt);
534
535 /* If the line has any text in it, save it on the history. */
536 if (line_read && *line_read)
537 add_history (line_read);
538
539 return (line_read);
540#else
541 char line_read[501];
Daniel Veillard29e43992001-12-13 22:21:58 +0000542 char *ret;
543 int len;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000544
545 if (prompt != NULL)
546 fprintf(stdout, "%s", prompt);
547 if (!fgets(line_read, 500, stdin))
548 return(NULL);
549 line_read[500] = 0;
Daniel Veillard29e43992001-12-13 22:21:58 +0000550 len = strlen(line_read);
551 ret = (char *) malloc(len + 1);
552 if (ret != NULL) {
553 memcpy (ret, line_read, len + 1);
554 }
555 return(ret);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000556#endif
557}
Daniel Veillard56ada1d2003-01-07 11:17:25 +0000558#endif /* LIBXML_DEBUG_ENABLED */
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000559
560/************************************************************************
561 * *
Daniel Veillard5e873c42000-04-12 13:27:38 +0000562 * I/O Interfaces *
563 * *
564 ************************************************************************/
565
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000566static int myRead(FILE *f, char * buf, int len) {
567 return(fread(buf, 1, len, f));
Daniel Veillard5e873c42000-04-12 13:27:38 +0000568}
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000569static void myClose(FILE *f) {
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000570 if (f != stdin) {
Daniel Veillard5e873c42000-04-12 13:27:38 +0000571 fclose(f);
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000572 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000573}
574
575/************************************************************************
576 * *
Daniel Veillard7704fb12003-01-03 16:19:51 +0000577 * Stream Test processing *
578 * *
579 ************************************************************************/
580static int count = 0;
581static int elem, attrs;
582
583static void processNode(xmlTextReaderPtr reader) {
Daniel Veillarde59494f2003-01-04 16:35:29 +0000584 xmlChar *name, *value;
Daniel Veillard7704fb12003-01-03 16:19:51 +0000585
Daniel Veillarde59494f2003-01-04 16:35:29 +0000586 name = xmlTextReaderName(reader);
587 if (name == NULL)
588 name = xmlStrdup(BAD_CAST "--");
589 value = xmlTextReaderValue(reader);
Daniel Veillard7704fb12003-01-03 16:19:51 +0000590
Daniel Veillarde59494f2003-01-04 16:35:29 +0000591 printf("%d %d %s %d",
592 xmlTextReaderDepth(reader),
593 xmlTextReaderNodeType(reader),
594 name,
595 xmlTextReaderIsEmptyElement(reader));
596 xmlFree(name);
597 if (value == NULL)
598 printf("\n");
599 else {
600 printf(" %s\n", value);
601 xmlFree(value);
Daniel Veillard7704fb12003-01-03 16:19:51 +0000602 }
603}
604
605static void streamFile(char *filename) {
606 xmlTextReaderPtr reader;
607 int ret;
608
609 if (count) {
610 elem = 0;
611 attrs = 0;
612 }
613
614 reader = xmlNewTextReaderFilename(filename);
615 if (reader != NULL) {
616 if (valid)
617 xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);
618
619 /*
620 * Process all nodes in sequence
621 */
622 ret = xmlTextReaderRead(reader);
623 while (ret == 1) {
624 if (debug)
625 processNode(reader);
626 ret = xmlTextReaderRead(reader);
627 }
628
629 /*
630 * Done, cleanup and status
631 */
632 xmlFreeTextReader(reader);
633 if (ret != 0) {
634 printf("%s : failed to parse\n", filename);
635 }
636 } else {
637 fprintf(stderr, "Unable to open %s\n", filename);
638 }
639}
640
641/************************************************************************
642 * *
643 * Tree Test processing *
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000644 * *
645 ************************************************************************/
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000646static void parseAndPrintFile(char *filename) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000647 xmlDocPtr doc = NULL, tmp;
648
Daniel Veillard48b2f892001-02-25 16:11:03 +0000649 if ((timing) && (!repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +0000650 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +0000651
652
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000653 if (filename == NULL) {
654 if (generate) {
655 xmlNodePtr n;
656
657 doc = xmlNewDoc(BAD_CAST "1.0");
658 n = xmlNewNode(NULL, BAD_CAST "info");
659 xmlNodeSetContent(n, BAD_CAST "abc");
660 xmlDocSetRootElement(doc, n);
661 }
662 }
Daniel Veillard89cad532001-10-22 09:46:13 +0000663#ifdef LIBXML_DOCB_ENABLED
664 /*
665 * build an SGML tree from a string;
666 */
667 else if ((sgml) && (push)) {
668 FILE *f;
669
670 f = fopen(filename, "r");
671 if (f != NULL) {
672 int res, size = 3;
673 char chars[4096];
674 docbParserCtxtPtr ctxt;
675
676 /* if (repeat) */
677 size = 4096;
678 res = fread(chars, 1, 4, f);
679 if (res > 0) {
680 ctxt = docbCreatePushParserCtxt(NULL, NULL,
681 chars, res, filename, 0);
682 while ((res = fread(chars, 1, size, f)) > 0) {
683 docbParseChunk(ctxt, chars, res, 0);
684 }
685 docbParseChunk(ctxt, chars, 0, 1);
686 doc = ctxt->myDoc;
687 docbFreeParserCtxt(ctxt);
688 }
689 fclose(f);
690 }
691 } else if (sgml) {
692 doc = docbParseFile(filename, NULL);
693 }
694#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000695#ifdef LIBXML_HTML_ENABLED
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000696 else if (html) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000697 doc = htmlParseFile(filename, NULL);
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000698 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000699#endif /* LIBXML_HTML_ENABLED */
Daniel Veillardd2f3ec72001-04-11 07:50:02 +0000700 else {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000701 /*
702 * build an XML tree from a string;
703 */
704 if (push) {
705 FILE *f;
706
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000707 /* '-' Usually means stdin -<sven@zen.org> */
708 if ((filename[0] == '-') && (filename[1] == 0)) {
709 f = stdin;
710 } else {
711 f = fopen(filename, "r");
712 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000713 if (f != NULL) {
Daniel Veillarde715dd22000-08-29 18:29:38 +0000714 int ret;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000715 int res, size = 3;
716 char chars[1024];
717 xmlParserCtxtPtr ctxt;
718
719 if (repeat)
720 size = 1024;
721 res = fread(chars, 1, 4, f);
722 if (res > 0) {
723 ctxt = xmlCreatePushParserCtxt(NULL, NULL,
724 chars, res, filename);
725 while ((res = fread(chars, 1, size, f)) > 0) {
726 xmlParseChunk(ctxt, chars, res, 0);
727 }
728 xmlParseChunk(ctxt, chars, 0, 1);
729 doc = ctxt->myDoc;
Daniel Veillarde715dd22000-08-29 18:29:38 +0000730 ret = ctxt->wellFormed;
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000731 xmlFreeParserCtxt(ctxt);
Daniel Veillarde715dd22000-08-29 18:29:38 +0000732 if (!ret) {
733 xmlFreeDoc(doc);
734 doc = NULL;
735 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000736 }
737 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000738 } else if (testIO) {
739 int ret;
740 FILE *f;
741
Daniel Veillard4a6845d2001-01-03 13:32:39 +0000742 /* '-' Usually means stdin -<sven@zen.org> */
743 if ((filename[0] == '-') && (filename[1] == 0)) {
744 f = stdin;
745 } else {
746 f = fopen(filename, "r");
747 }
Daniel Veillard5e873c42000-04-12 13:27:38 +0000748 if (f != NULL) {
749 xmlParserCtxtPtr ctxt;
750
751 ctxt = xmlCreateIOParserCtxt(NULL, NULL,
752 (xmlInputReadCallback) myRead,
753 (xmlInputCloseCallback) myClose,
754 f, XML_CHAR_ENCODING_NONE);
755 xmlParseDocument(ctxt);
756
757 ret = ctxt->wellFormed;
758 doc = ctxt->myDoc;
759 xmlFreeParserCtxt(ctxt);
760 if (!ret) {
761 xmlFreeDoc(doc);
762 doc = NULL;
763 }
764 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000765 } else if (recovery) {
766 doc = xmlRecoverFile(filename);
767 } else if (htmlout) {
768 int ret;
769 xmlParserCtxtPtr ctxt;
770 xmlSAXHandler silent, *old;
771
772 ctxt = xmlCreateFileParserCtxt(filename);
Daniel Veillard88a172f2000-08-04 18:23:10 +0000773
774 if (ctxt == NULL) {
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000775 /* If xmlCreateFileParserCtxt() return NULL something
Daniel Veillard88a172f2000-08-04 18:23:10 +0000776 strange happened so we don't want to do anything. Do
777 we want to print an error message here?
778 <sven@zen.org> */
Daniel Veillard7ebb1ee2000-08-04 18:24:45 +0000779 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000780 } else {
781 memcpy(&silent, ctxt->sax, sizeof(silent));
782 old = ctxt->sax;
783 silent.error = xmlHTMLError;
784 if (xmlGetWarningsDefaultValue)
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000785 silent.warning = xmlHTMLWarning;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000786 else
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000787 silent.warning = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000788 silent.fatalError = xmlHTMLError;
789 ctxt->sax = &silent;
790 ctxt->vctxt.error = xmlHTMLValidityError;
791 if (xmlGetWarningsDefaultValue)
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000792 ctxt->vctxt.warning = xmlHTMLValidityWarning;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000793 else
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000794 ctxt->vctxt.warning = NULL;
795
Daniel Veillard88a172f2000-08-04 18:23:10 +0000796 xmlParseDocument(ctxt);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000797
Daniel Veillard88a172f2000-08-04 18:23:10 +0000798 ret = ctxt->wellFormed;
799 doc = ctxt->myDoc;
800 ctxt->sax = old;
801 xmlFreeParserCtxt(ctxt);
802 if (!ret) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000803 xmlFreeDoc(doc);
804 doc = NULL;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000805 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000806 }
Daniel Veillard46e370e2000-07-21 20:32:03 +0000807#ifdef HAVE_SYS_MMAN_H
808 } else if (memory) {
809 int fd;
810 struct stat info;
811 const char *base;
812 if (stat(filename, &info) < 0)
813 return;
814 if ((fd = open(filename, O_RDONLY)) < 0)
815 return;
816 base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
Daniel Veillard29579362000-08-14 17:57:48 +0000817 if (base == (void *) MAP_FAILED)
Daniel Veillard46e370e2000-07-21 20:32:03 +0000818 return;
819
820 doc = xmlParseMemory((char *) base, info.st_size);
821 munmap((char *) base, info.st_size);
822#endif
Daniel Veillardea7751d2002-12-20 00:16:24 +0000823 } else if (valid) {
824 int ret;
825 xmlParserCtxtPtr ctxt;
826
827 ctxt = xmlCreateFileParserCtxt(filename);
828
829 if (ctxt == NULL) {
830 doc = NULL;
831 } else {
832 xmlParseDocument(ctxt);
833 if (ctxt->valid == 0)
834 progresult = 4;
835 ret = ctxt->wellFormed;
836 doc = ctxt->myDoc;
837 xmlFreeParserCtxt(ctxt);
838 if (!ret) {
839 xmlFreeDoc(doc);
840 doc = NULL;
841 }
842 }
843 } else {
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000844 doc = xmlParseFile(filename);
Daniel Veillardea7751d2002-12-20 00:16:24 +0000845 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000846 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000847
Daniel Veillard88a172f2000-08-04 18:23:10 +0000848 /*
849 * If we don't have a document we might as well give up. Do we
850 * want an error message here? <sven@zen.org> */
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000851 if (doc == NULL) {
Daniel Veillardf7cd4812001-02-23 18:44:52 +0000852 progresult = 1;
Daniel Veillard88a172f2000-08-04 18:23:10 +0000853 return;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000854 }
855
Daniel Veillard48b2f892001-02-25 16:11:03 +0000856 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +0000857 endTimer("Parsing");
Daniel Veillard48b2f892001-02-25 16:11:03 +0000858 }
859
Daniel Veillard29e43992001-12-13 22:21:58 +0000860 /*
861 * Remove DOCTYPE nodes
862 */
863 if (dropdtd) {
864 xmlDtdPtr dtd;
865
866 dtd = xmlGetIntSubset(doc);
867 if (dtd != NULL) {
868 xmlUnlinkNode((xmlNodePtr)dtd);
869 xmlFreeDtd(dtd);
870 }
871 }
872
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000873#ifdef LIBXML_XINCLUDE_ENABLED
Daniel Veillard48b2f892001-02-25 16:11:03 +0000874 if (xinclude) {
875 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +0000876 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +0000877 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000878 xmlXIncludeProcess(doc);
Daniel Veillard48b2f892001-02-25 16:11:03 +0000879 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +0000880 endTimer("Xinclude processing");
Daniel Veillard48b2f892001-02-25 16:11:03 +0000881 }
882 }
Daniel Veillard9e8bfae2000-11-06 16:43:11 +0000883#endif
Daniel Veillard88a172f2000-08-04 18:23:10 +0000884
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000885#ifdef LIBXML_DEBUG_ENABLED
886 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +0000887 * shell interaction
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000888 */
889 if (shell)
890 xmlShell(doc, filename, xmlShellReadline, stdout);
891#endif
892
893 /*
894 * test intermediate copy if needed.
895 */
896 if (copy) {
897 tmp = doc;
898 doc = xmlCopyDoc(doc, 1);
899 xmlFreeDoc(tmp);
900 }
901
902 if ((insert) && (!html)) {
903 const xmlChar* list[256];
904 int nb, i;
905 xmlNodePtr node;
906
907 if (doc->children != NULL) {
908 node = doc->children;
909 while ((node != NULL) && (node->last == NULL)) node = node->next;
910 if (node != NULL) {
911 nb = xmlValidGetValidElements(node->last, NULL, list, 256);
912 if (nb < 0) {
913 printf("could not get valid list of elements\n");
914 } else if (nb == 0) {
MDT 2001 John Fleckbbb9e432001-09-24 03:08:43 +0000915 printf("No element can be inserted under root\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000916 } else {
MDT 2001 John Fleckbbb9e432001-09-24 03:08:43 +0000917 printf("%d element types can be inserted under root:\n",
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000918 nb);
919 for (i = 0;i < nb;i++) {
Daniel Veillard8a1b1852003-01-05 22:37:17 +0000920 printf("%s\n", (char *) list[i]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000921 }
922 }
923 }
924 }
925 }else if (noout == 0) {
926 /*
927 * print it.
928 */
929#ifdef LIBXML_DEBUG_ENABLED
930 if (!debug) {
931#endif
Daniel Veillard48b2f892001-02-25 16:11:03 +0000932 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +0000933 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +0000934 }
Daniel Veillard3b2c2612001-04-04 00:09:00 +0000935#ifdef HAVE_SYS_MMAN_H
Daniel Veillarda6d8eb62000-12-27 10:46:47 +0000936 if (memory) {
937 xmlChar *result;
938 int len;
939
940 if (encoding != NULL) {
Daniel Veillardd536f702001-11-08 17:32:47 +0000941 if ( format ) {
942 xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1);
943 } else {
944 xmlDocDumpMemoryEnc(doc, &result, &len, encoding);
945 }
Daniel Veillarda6d8eb62000-12-27 10:46:47 +0000946 } else {
Daniel Veillard90493a92001-08-14 14:12:47 +0000947 if (format)
948 xmlDocDumpFormatMemory(doc, &result, &len, 1);
949 else
950 xmlDocDumpMemory(doc, &result, &len);
Daniel Veillarda6d8eb62000-12-27 10:46:47 +0000951 }
952 if (result == NULL) {
953 fprintf(stderr, "Failed to save\n");
954 } else {
955 write(1, result, len);
956 xmlFree(result);
957 }
Daniel Veillard3b2c2612001-04-04 00:09:00 +0000958 } else
959#endif /* HAVE_SYS_MMAN_H */
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000960 if (compress) {
961 xmlSaveFile(output ? output : "-", doc);
962 }
Daniel Veillardd536f702001-11-08 17:32:47 +0000963 else if (encoding != NULL) {
964 if ( format ) {
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000965 xmlSaveFormatFileEnc(output ? output : "-", doc, encoding, 1);
966 }
Daniel Veillardd536f702001-11-08 17:32:47 +0000967 else {
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000968 xmlSaveFileEnc(output ? output : "-", doc, encoding);
Daniel Veillardd536f702001-11-08 17:32:47 +0000969 }
970 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000971 else if (format) {
972 xmlSaveFormatFile(output ? output : "-", doc, 1);
973 }
974 else {
975 FILE *out;
976 if (output == NULL)
977 out = stdout;
978 else {
979 out = fopen(output,"wb");
980 }
981 xmlDocDump(out, doc);
982
983 if (output)
984 fclose(out);
985 }
Daniel Veillard48b2f892001-02-25 16:11:03 +0000986 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +0000987 endTimer("Saving");
Daniel Veillard48b2f892001-02-25 16:11:03 +0000988 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +0000989#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillarda6d8eb62000-12-27 10:46:47 +0000990 } else {
Daniel Veillard1df3dfc2001-12-18 11:14:16 +0000991 FILE *out;
992 if (output == NULL)
993 out = stdout;
994 else {
995 out = fopen(output,"wb");
996 }
997 xmlDebugDumpDocument(out, doc);
998
999 if (output)
1000 fclose(out);
Daniel Veillarda6d8eb62000-12-27 10:46:47 +00001001 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001002#endif
1003 }
1004
1005 /*
1006 * A posteriori validation test
1007 */
Daniel Veillardcd429612000-10-11 15:57:05 +00001008 if (dtdvalid != NULL) {
1009 xmlDtdPtr dtd;
1010
Daniel Veillard48b2f892001-02-25 16:11:03 +00001011 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001012 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001013 }
Daniel Veillardcd429612000-10-11 15:57:05 +00001014 dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001015 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001016 endTimer("Parsing DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001017 }
Daniel Veillardcd429612000-10-11 15:57:05 +00001018 if (dtd == NULL) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001019 xmlGenericError(xmlGenericErrorContext,
1020 "Could not parse DTD %s\n", dtdvalid);
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001021 progresult = 2;
Daniel Veillardcd429612000-10-11 15:57:05 +00001022 } else {
1023 xmlValidCtxt cvp;
Daniel Veillard48b2f892001-02-25 16:11:03 +00001024 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001025 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001026 }
Daniel Veillard01db67c2001-12-18 07:09:59 +00001027 cvp.userData = (void *) stderr;
1028 cvp.error = (xmlValidityErrorFunc) fprintf;
1029 cvp.warning = (xmlValidityWarningFunc) fprintf;
Daniel Veillardcd429612000-10-11 15:57:05 +00001030 if (!xmlValidateDtd(&cvp, doc, dtd)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001031 xmlGenericError(xmlGenericErrorContext,
1032 "Document %s does not validate against %s\n",
Daniel Veillardcd429612000-10-11 15:57:05 +00001033 filename, dtdvalid);
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001034 progresult = 3;
Daniel Veillardcd429612000-10-11 15:57:05 +00001035 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001036 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001037 endTimer("Validating against DTD");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001038 }
Daniel Veillardcd429612000-10-11 15:57:05 +00001039 xmlFreeDtd(dtd);
1040 }
1041 } else if (postvalid) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001042 xmlValidCtxt cvp;
Daniel Veillard48b2f892001-02-25 16:11:03 +00001043 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001044 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001045 }
Daniel Veillardb7664f42001-08-19 13:00:43 +00001046 cvp.userData = (void *) stderr;
1047 cvp.error = (xmlValidityErrorFunc) fprintf;
1048 cvp.warning = (xmlValidityWarningFunc) fprintf;
Daniel Veillardcd429612000-10-11 15:57:05 +00001049 if (!xmlValidateDocument(&cvp, doc)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001050 xmlGenericError(xmlGenericErrorContext,
1051 "Document %s does not validate\n", filename);
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001052 progresult = 3;
Daniel Veillardcd429612000-10-11 15:57:05 +00001053 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001054 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001055 endTimer("Validating");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001056 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001057 }
1058
1059#ifdef LIBXML_DEBUG_ENABLED
1060 if ((debugent) && (!html))
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001061 xmlDebugDumpEntities(stderr, doc);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001062#endif
1063
1064 /*
1065 * free it.
1066 */
Daniel Veillard48b2f892001-02-25 16:11:03 +00001067 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001068 startTimer();
Daniel Veillard48b2f892001-02-25 16:11:03 +00001069 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001070 xmlFreeDoc(doc);
Daniel Veillard48b2f892001-02-25 16:11:03 +00001071 if ((timing) && (!repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001072 endTimer("Freeing");
Daniel Veillard48b2f892001-02-25 16:11:03 +00001073 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001074}
1075
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001076/************************************************************************
1077 * *
1078 * Usage and Main *
1079 * *
1080 ************************************************************************/
1081
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001082static void showVersion(const char *name) {
1083 fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion);
1084 fprintf(stderr, " compiled with: ");
1085#ifdef LIBXML_FTP_ENABLED
1086 fprintf(stderr, "FTP ");
1087#endif
1088#ifdef LIBXML_HTTP_ENABLED
1089 fprintf(stderr, "HTTP ");
1090#endif
1091#ifdef LIBXML_HTML_ENABLED
1092 fprintf(stderr, "HTML ");
1093#endif
1094#ifdef LIBXML_C14N_ENABLED
1095 fprintf(stderr, "C14N ");
1096#endif
1097#ifdef LIBXML_CATALOG_ENABLED
1098 fprintf(stderr, "Catalog ");
1099#endif
1100#ifdef LIBXML_DOCB_ENABLED
1101 fprintf(stderr, "DocBook ");
1102#endif
1103#ifdef LIBXML_XPATH_ENABLED
1104 fprintf(stderr, "XPath ");
1105#endif
1106#ifdef LIBXML_XPTR_ENABLED
1107 fprintf(stderr, "XPointer ");
1108#endif
1109#ifdef LIBXML_XINCLUDE_ENABLED
1110 fprintf(stderr, "XInclude ");
1111#endif
1112#ifdef LIBXML_ICONV_ENABLED
1113 fprintf(stderr, "Iconv ");
1114#endif
1115#ifdef DEBUG_MEMORY_LOCATION
1116 fprintf(stderr, "MemDebug ");
1117#endif
1118#ifdef LIBXML_UNICODE_ENABLED
1119 fprintf(stderr, "Unicode ");
1120#endif
1121#ifdef LIBXML_REGEXP_ENABLED
1122 fprintf(stderr, "Regexps ");
1123#endif
1124#ifdef LIBXML_AUTOMATA_ENABLED
1125 fprintf(stderr, "Automata ");
1126#endif
1127#ifdef LIBXML_SCHEMAS_ENABLED
1128 fprintf(stderr, "Schemas ");
1129#endif
1130 fprintf(stderr, "\n");
1131}
1132
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001133static void usage(const char *name) {
1134 printf("Usage : %s [options] XMLfiles ...\n", name);
1135 printf("\tParse the XML files and output the result of the parsing\n");
1136 printf("\t--version : display the version of the XML library used\n");
1137#ifdef LIBXML_DEBUG_ENABLED
1138 printf("\t--debug : dump a debug tree of the in-memory document\n");
1139 printf("\t--shell : run a navigating shell\n");
1140 printf("\t--debugent : debug the entities defined in the document\n");
Daniel Veillard8326e732003-01-07 00:19:07 +00001141#else
1142 printf("\t--debug : dump the nodes content when using --stream\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001143#endif
1144 printf("\t--copy : used to test the internal copy implementation\n");
1145 printf("\t--recover : output what was parsable on broken XML documents\n");
1146 printf("\t--noent : substitute entity references by their value\n");
1147 printf("\t--noout : don't output the result tree\n");
1148 printf("\t--htmlout : output results as HTML\n");
Daniel Veillard05c13a22001-09-09 08:38:09 +00001149 printf("\t--nowrap : do not put HTML doc wrapper\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001150 printf("\t--valid : validate the document in addition to std well-formed check\n");
1151 printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
1152 printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
1153 printf("\t--timing : print some timings\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001154 printf("\t--output file or -o file: save to a given file\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001155 printf("\t--repeat : repeat 100 times, for timing or profiling\n");
1156 printf("\t--insert : ad-hoc test for valid insertions\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001157#ifdef HAVE_ZLIB_H
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001158 printf("\t--compress : turn on gzip compression of output\n");
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001159#endif
Daniel Veillard89cad532001-10-22 09:46:13 +00001160#ifdef LIBXML_DOCB_ENABLED
1161 printf("\t--sgml : use the DocBook SGML parser\n");
1162#endif
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001163#ifdef LIBXML_HTML_ENABLED
1164 printf("\t--html : use the HTML parser\n");
1165#endif
1166 printf("\t--push : use the push mode of the parser\n");
1167#ifdef HAVE_SYS_MMAN_H
1168 printf("\t--memory : parse from memory\n");
1169#endif
1170 printf("\t--nowarning : do not emit warnings from parser/validator\n");
1171 printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
Daniel Veillard90493a92001-08-14 14:12:47 +00001172 printf("\t--format : reformat/reindent the input\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001173 printf("\t--testIO : test user I/O support\n");
1174 printf("\t--encode encoding : output in the given encoding\n");
1175#ifdef LIBXML_CATALOG_ENABLED
Daniel Veillardbd9b0e82001-11-26 10:32:08 +00001176 printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");
1177 printf("\t otherwise XML Catalogs starting from \n");
Daniel Veillard3be27512003-01-26 19:49:04 +00001178 printf("\t " XML_XML_DEFAULT_CATALOG " are activated by default\n");
Daniel Veillard05c13a22001-09-09 08:38:09 +00001179 printf("\t--nocatalogs: deactivate all catalogs\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001180#endif
1181 printf("\t--auto : generate a small doc on the fly\n");
1182#ifdef LIBXML_XINCLUDE_ENABLED
1183 printf("\t--xinclude : do XInclude processing\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001184#endif
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001185 printf("\t--loaddtd : fetch external DTD\n");
Daniel Veillard48da9102001-08-07 01:10:10 +00001186 printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
Daniel Veillard29e43992001-12-13 22:21:58 +00001187 printf("\t--dropdtd : remove the DOCTYPE of the input docs\n");
Daniel Veillard7704fb12003-01-03 16:19:51 +00001188 printf("\t--stream : use the streaming interface to process very large files\n");
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001189 printf("\t--chkregister : verify the node registration code\n");
Daniel Veillarda42f25f2002-01-25 14:15:40 +00001190 printf("\nLibxml project home page: http://xmlsoft.org/\n");
1191 printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001192}
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001193
1194static void registerNode(xmlNodePtr node)
1195{
1196 node->_private = malloc(sizeof(long));
1197 *(long*)node->_private = (long) 0x81726354;
1198}
1199
1200static void deregisterNode(xmlNodePtr node)
1201{
1202 assert(node->_private != NULL);
1203 assert(*(long*)node->_private == (long) 0x81726354);
1204 free(node->_private);
1205}
1206
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001207int
1208main(int argc, char **argv) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00001209 int i, acount;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001210 int files = 0;
Daniel Veillard845cce42002-01-09 11:51:37 +00001211 int version = 0;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001212
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001213 if (argc <= 1) {
1214 usage(argv[0]);
1215 return(1);
1216 }
Daniel Veillardbe803962000-06-28 23:40:59 +00001217 LIBXML_TEST_VERSION
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001218 for (i = 1; i < argc ; i++) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001219 if (!strcmp(argv[i], "-"))
1220 break;
1221
1222 if (argv[i][0] != '-')
1223 continue;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001224 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
1225 debug++;
Daniel Veillard56ada1d2003-01-07 11:17:25 +00001226 else
1227#ifdef LIBXML_DEBUG_ENABLED
1228 if ((!strcmp(argv[i], "-shell")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001229 (!strcmp(argv[i], "--shell"))) {
1230 shell++;
1231 noout = 1;
1232 } else
1233#endif
1234 if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
1235 copy++;
1236 else if ((!strcmp(argv[i], "-recover")) ||
1237 (!strcmp(argv[i], "--recover")))
1238 recovery++;
1239 else if ((!strcmp(argv[i], "-noent")) ||
1240 (!strcmp(argv[i], "--noent")))
1241 noent++;
Daniel Veillard4ec885a2001-06-17 10:31:07 +00001242 else if ((!strcmp(argv[i], "-version")) ||
Daniel Veillard845cce42002-01-09 11:51:37 +00001243 (!strcmp(argv[i], "--version"))) {
Daniel Veillard0f04f8e2002-09-17 23:04:40 +00001244 showVersion(argv[0]);
Daniel Veillard845cce42002-01-09 11:51:37 +00001245 version = 1;
1246 } else if ((!strcmp(argv[i], "-noout")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001247 (!strcmp(argv[i], "--noout")))
1248 noout++;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001249 else if ((!strcmp(argv[i], "-o")) ||
1250 (!strcmp(argv[i], "-output")) ||
1251 (!strcmp(argv[i], "--output"))) {
1252 i++;
Daniel Veillard6e4f1c02002-04-09 09:55:20 +00001253 output = argv[i];
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001254 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001255 else if ((!strcmp(argv[i], "-htmlout")) ||
1256 (!strcmp(argv[i], "--htmlout")))
1257 htmlout++;
Daniel Veillard89cad532001-10-22 09:46:13 +00001258#ifdef LIBXML_DOCB_ENABLED
1259 else if ((!strcmp(argv[i], "-sgml")) ||
1260 (!strcmp(argv[i], "--sgml"))) {
1261 sgml++;
1262 }
1263#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001264#ifdef LIBXML_HTML_ENABLED
1265 else if ((!strcmp(argv[i], "-html")) ||
1266 (!strcmp(argv[i], "--html"))) {
1267 html++;
1268 }
1269#endif /* LIBXML_HTML_ENABLED */
1270 else if ((!strcmp(argv[i], "-nowrap")) ||
1271 (!strcmp(argv[i], "--nowrap")))
1272 nowrap++;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001273 else if ((!strcmp(argv[i], "-loaddtd")) ||
1274 (!strcmp(argv[i], "--loaddtd")))
1275 loaddtd++;
Daniel Veillard48da9102001-08-07 01:10:10 +00001276 else if ((!strcmp(argv[i], "-dtdattr")) ||
1277 (!strcmp(argv[i], "--dtdattr"))) {
1278 loaddtd++;
1279 dtdattrs++;
1280 } else if ((!strcmp(argv[i], "-valid")) ||
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001281 (!strcmp(argv[i], "--valid")))
1282 valid++;
1283 else if ((!strcmp(argv[i], "-postvalid")) ||
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001284 (!strcmp(argv[i], "--postvalid"))) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001285 postvalid++;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001286 loaddtd++;
1287 } else if ((!strcmp(argv[i], "-dtdvalid")) ||
Daniel Veillardcd429612000-10-11 15:57:05 +00001288 (!strcmp(argv[i], "--dtdvalid"))) {
1289 i++;
1290 dtdvalid = argv[i];
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001291 loaddtd++;
Daniel Veillardcd429612000-10-11 15:57:05 +00001292 }
Daniel Veillard29e43992001-12-13 22:21:58 +00001293 else if ((!strcmp(argv[i], "-dropdtd")) ||
1294 (!strcmp(argv[i], "--dropdtd")))
1295 dropdtd++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001296 else if ((!strcmp(argv[i], "-insert")) ||
1297 (!strcmp(argv[i], "--insert")))
1298 insert++;
Daniel Veillard48b2f892001-02-25 16:11:03 +00001299 else if ((!strcmp(argv[i], "-timing")) ||
1300 (!strcmp(argv[i], "--timing")))
1301 timing++;
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001302 else if ((!strcmp(argv[i], "-auto")) ||
1303 (!strcmp(argv[i], "--auto")))
1304 generate++;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001305 else if ((!strcmp(argv[i], "-repeat")) ||
1306 (!strcmp(argv[i], "--repeat")))
1307 repeat++;
1308 else if ((!strcmp(argv[i], "-push")) ||
1309 (!strcmp(argv[i], "--push")))
1310 push++;
Daniel Veillard46e370e2000-07-21 20:32:03 +00001311#ifdef HAVE_SYS_MMAN_H
1312 else if ((!strcmp(argv[i], "-memory")) ||
1313 (!strcmp(argv[i], "--memory")))
1314 memory++;
1315#endif
Daniel Veillard5e873c42000-04-12 13:27:38 +00001316 else if ((!strcmp(argv[i], "-testIO")) ||
1317 (!strcmp(argv[i], "--testIO")))
1318 testIO++;
Daniel Veillard9e8bfae2000-11-06 16:43:11 +00001319#ifdef LIBXML_XINCLUDE_ENABLED
1320 else if ((!strcmp(argv[i], "-xinclude")) ||
1321 (!strcmp(argv[i], "--xinclude")))
1322 xinclude++;
1323#endif
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001324#ifdef HAVE_ZLIB_H
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001325 else if ((!strcmp(argv[i], "-compress")) ||
1326 (!strcmp(argv[i], "--compress"))) {
1327 compress++;
1328 xmlSetCompressMode(9);
1329 }
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001330#endif
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001331 else if ((!strcmp(argv[i], "-nowarning")) ||
1332 (!strcmp(argv[i], "--nowarning"))) {
1333 xmlGetWarningsDefaultValue = 0;
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001334 xmlPedanticParserDefault(0);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001335 }
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001336 else if ((!strcmp(argv[i], "-pedantic")) ||
1337 (!strcmp(argv[i], "--pedantic"))) {
1338 xmlGetWarningsDefaultValue = 1;
1339 xmlPedanticParserDefault(1);
1340 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00001341#ifdef LIBXML_DEBUG_ENABLED
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001342 else if ((!strcmp(argv[i], "-debugent")) ||
1343 (!strcmp(argv[i], "--debugent"))) {
1344 debugent++;
1345 xmlParserDebugEntities = 1;
1346 }
Daniel Veillard64c20ed2000-09-22 16:07:02 +00001347#endif
Daniel Veillard81418e32001-05-22 15:08:55 +00001348#ifdef LIBXML_CATALOG_ENABLED
1349 else if ((!strcmp(argv[i], "-catalogs")) ||
1350 (!strcmp(argv[i], "--catalogs"))) {
Daniel Veillarde2940dd2001-08-22 00:06:49 +00001351 catalogs++;
1352 } else if ((!strcmp(argv[i], "-nocatalogs")) ||
1353 (!strcmp(argv[i], "--nocatalogs"))) {
1354 nocatalogs++;
Daniel Veillard81418e32001-05-22 15:08:55 +00001355 }
1356#endif
Daniel Veillardbe803962000-06-28 23:40:59 +00001357 else if ((!strcmp(argv[i], "-encode")) ||
1358 (!strcmp(argv[i], "--encode"))) {
1359 i++;
1360 encoding = argv[i];
Daniel Veillardf0cc7cc2000-08-26 21:40:43 +00001361 /*
1362 * OK it's for testing purposes
1363 */
1364 xmlAddEncodingAlias("UTF-8", "DVEnc");
Daniel Veillardbe803962000-06-28 23:40:59 +00001365 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001366 else if ((!strcmp(argv[i], "-noblanks")) ||
1367 (!strcmp(argv[i], "--noblanks"))) {
1368 noblanks++;
1369 xmlKeepBlanksDefault(0);
Daniel Veillard90493a92001-08-14 14:12:47 +00001370 }
1371 else if ((!strcmp(argv[i], "-format")) ||
1372 (!strcmp(argv[i], "--format"))) {
1373 noblanks++;
1374 format++;
1375 xmlKeepBlanksDefault(0);
Daniel Veillard7704fb12003-01-03 16:19:51 +00001376 }
1377 else if ((!strcmp(argv[i], "-stream")) ||
1378 (!strcmp(argv[i], "--stream"))) {
1379 stream++;
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001380 }
1381 else if ((!strcmp(argv[i], "-chkregister")) ||
1382 (!strcmp(argv[i], "--chkregister"))) {
1383 chkregister++;
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001384 } else {
1385 fprintf(stderr, "Unknown option %s\n", argv[i]);
1386 usage(argv[0]);
1387 return(1);
1388 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001389 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00001390
1391#ifdef LIBXML_CATALOG_ENABLED
1392 if (nocatalogs == 0) {
1393 if (catalogs) {
1394 const char *catal;
1395
1396 catal = getenv("SGML_CATALOG_FILES");
Daniel Veillard6c5f9d12001-08-25 13:33:14 +00001397 if (catal != NULL) {
1398 xmlLoadCatalogs(catal);
1399 } else {
1400 fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n");
1401 }
Daniel Veillarde2940dd2001-08-22 00:06:49 +00001402 }
1403 }
1404#endif
Daniel Veillard8a1b1852003-01-05 22:37:17 +00001405
1406 if (chkregister) {
1407 xmlRegisterNodeDefault(registerNode);
1408 xmlDeregisterNodeDefault(deregisterNode);
1409 }
1410
Daniel Veillardd9bad132001-07-23 19:39:43 +00001411 xmlLineNumbersDefault(1);
Daniel Veillard48da9102001-08-07 01:10:10 +00001412 if (loaddtd != 0)
1413 xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
1414 if (dtdattrs)
1415 xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001416 if (noent != 0) xmlSubstituteEntitiesDefault(1);
1417 if (valid != 0) xmlDoValidityCheckingDefaultValue = 1;
1418 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001419 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001420 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001421 xmlGenericError(xmlGenericErrorContext,
1422 "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
1423 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001424 "<html><head><title>%s output</title></head>\n",
1425 argv[0]);
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001426 xmlGenericError(xmlGenericErrorContext,
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001427 "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
1428 argv[0]);
1429 }
1430 for (i = 1; i < argc ; i++) {
Daniel Veillardbe803962000-06-28 23:40:59 +00001431 if ((!strcmp(argv[i], "-encode")) ||
1432 (!strcmp(argv[i], "--encode"))) {
1433 i++;
1434 continue;
Daniel Veillard1df3dfc2001-12-18 11:14:16 +00001435 } else if ((!strcmp(argv[i], "-o")) ||
1436 (!strcmp(argv[i], "-output")) ||
1437 (!strcmp(argv[i], "--output"))) {
1438 i++;
1439 continue;
Daniel Veillardbe803962000-06-28 23:40:59 +00001440 }
Daniel Veillardcd429612000-10-11 15:57:05 +00001441 if ((!strcmp(argv[i], "-dtdvalid")) ||
1442 (!strcmp(argv[i], "--dtdvalid"))) {
1443 i++;
1444 continue;
1445 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001446 if ((timing) && (repeat))
Daniel Veillard01db67c2001-12-18 07:09:59 +00001447 startTimer();
Daniel Veillardcbaf3992001-12-31 16:16:02 +00001448 /* Remember file names. "-" means stdin. <sven@zen.org> */
Daniel Veillard4a6845d2001-01-03 13:32:39 +00001449 if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001450 if (repeat) {
Daniel Veillard7704fb12003-01-03 16:19:51 +00001451 for (acount = 0;acount < 100 * repeat;acount++)
1452 if (stream != 0)
1453 streamFile(argv[i]);
1454 else
1455 parseAndPrintFile(argv[i]);
1456 } else {
1457 if (stream != 0)
1458 streamFile(argv[i]);
1459 else
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001460 parseAndPrintFile(argv[i]);
Daniel Veillard7704fb12003-01-03 16:19:51 +00001461 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001462 files ++;
Daniel Veillarda7866932001-12-04 13:14:44 +00001463 if ((timing) && (repeat)) {
Daniel Veillard01db67c2001-12-18 07:09:59 +00001464 endTimer("100 iterations");
Daniel Veillarda7866932001-12-04 13:14:44 +00001465 }
Daniel Veillard48b2f892001-02-25 16:11:03 +00001466 }
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001467 }
Daniel Veillardd2f3ec72001-04-11 07:50:02 +00001468 if (generate)
1469 parseAndPrintFile(NULL);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001470 if ((htmlout) && (!nowrap)) {
Daniel Veillardd6d7f7b2000-10-25 19:56:55 +00001471 xmlGenericError(xmlGenericErrorContext, "</body></html>\n");
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001472 }
Daniel Veillard845cce42002-01-09 11:51:37 +00001473 if ((files == 0) && (!generate) && (version == 0)) {
Daniel Veillard10ea86c2001-06-20 13:55:33 +00001474 usage(argv[0]);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001475 }
1476 xmlCleanupParser();
1477 xmlMemoryDump();
1478
Daniel Veillardf7cd4812001-02-23 18:44:52 +00001479 return(progresult);
Daniel Veillardce8b83b2000-04-05 18:38:42 +00001480}
Daniel Veillard88a172f2000-08-04 18:23:10 +00001481