Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * xmllint.c : a small tester program for XML input. |
| 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
Daniel Veillard | c5d6434 | 2001-06-24 12:13:24 +0000 | [diff] [blame] | 6 | * daniel@veillard.com |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 9 | #include "libxml.h" |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 10 | |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 11 | #include <string.h> |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 12 | #include <stdarg.h> |
Daniel Veillard | 28ae636 | 2001-07-14 16:44:32 +0000 | [diff] [blame] | 13 | |
Daniel Veillard | 2d90de4 | 2001-04-16 17:46:18 +0000 | [diff] [blame] | 14 | #ifdef _WIN32 |
| 15 | #ifdef _MSC_VER |
| 16 | #include <winsock2.h> |
| 17 | #pragma comment(lib, "ws2_32.lib") |
| 18 | #define gettimeofday(p1,p2) |
Daniel Veillard | 28ae636 | 2001-07-14 16:44:32 +0000 | [diff] [blame] | 19 | #else /* _MSC_VER */ |
| 20 | #include <sys/time.h> |
Daniel Veillard | 2d90de4 | 2001-04-16 17:46:18 +0000 | [diff] [blame] | 21 | #endif /* _MSC_VER */ |
| 22 | #else /* _WIN32 */ |
Daniel Veillard | ed472f3 | 2001-12-13 08:48:14 +0000 | [diff] [blame] | 23 | #ifdef HAVE_SYS_TIME_H |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 24 | #include <sys/time.h> |
Daniel Veillard | ed472f3 | 2001-12-13 08:48:14 +0000 | [diff] [blame] | 25 | #endif |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 26 | #ifdef HAVE_TIME_H |
| 27 | #include <time.h> |
| 28 | #endif |
Daniel Veillard | 2d90de4 | 2001-04-16 17:46:18 +0000 | [diff] [blame] | 29 | #endif /* _WIN32 */ |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 30 | |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 31 | |
| 32 | #ifdef HAVE_SYS_TYPES_H |
| 33 | #include <sys/types.h> |
| 34 | #endif |
| 35 | #ifdef HAVE_SYS_STAT_H |
| 36 | #include <sys/stat.h> |
| 37 | #endif |
| 38 | #ifdef HAVE_FCNTL_H |
| 39 | #include <fcntl.h> |
| 40 | #endif |
| 41 | #ifdef HAVE_UNISTD_H |
| 42 | #include <unistd.h> |
| 43 | #endif |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 44 | #ifdef HAVE_SYS_MMAN_H |
| 45 | #include <sys/mman.h> |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 46 | /* seems needed for Solaris */ |
| 47 | #ifndef MAP_FAILED |
| 48 | #define MAP_FAILED ((void *) -1) |
| 49 | #endif |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 50 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 51 | #ifdef HAVE_STDLIB_H |
| 52 | #include <stdlib.h> |
| 53 | #endif |
| 54 | #ifdef HAVE_LIBREADLINE |
| 55 | #include <readline/readline.h> |
| 56 | #ifdef HAVE_LIBHISTORY |
| 57 | #include <readline/history.h> |
| 58 | #endif |
| 59 | #endif |
| 60 | |
| 61 | #include <libxml/xmlmemory.h> |
| 62 | #include <libxml/parser.h> |
| 63 | #include <libxml/parserInternals.h> |
| 64 | #include <libxml/HTMLparser.h> |
| 65 | #include <libxml/HTMLtree.h> |
| 66 | #include <libxml/tree.h> |
| 67 | #include <libxml/xpath.h> |
| 68 | #include <libxml/debugXML.h> |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 69 | #include <libxml/xmlerror.h> |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 70 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 71 | #include <libxml/xinclude.h> |
| 72 | #endif |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 73 | #ifdef LIBXML_CATALOG_ENABLED |
| 74 | #include <libxml/catalog.h> |
| 75 | #endif |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 76 | #ifdef LIBXML_DOCB_ENABLED |
| 77 | #include <libxml/DOCBparser.h> |
| 78 | #endif |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 79 | #include <libxml/globals.h> |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 80 | |
| 81 | #ifdef LIBXML_DEBUG_ENABLED |
| 82 | static int debug = 0; |
| 83 | static int shell = 0; |
| 84 | static int debugent = 0; |
| 85 | #endif |
| 86 | static int copy = 0; |
| 87 | static int recovery = 0; |
| 88 | static int noent = 0; |
| 89 | static int noout = 0; |
| 90 | static int nowrap = 0; |
| 91 | static int valid = 0; |
| 92 | static int postvalid = 0; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 93 | static char * dtdvalid = NULL; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 94 | static int repeat = 0; |
| 95 | static int insert = 0; |
| 96 | static int compress = 0; |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 97 | #ifdef LIBXML_DOCB_ENABLED |
| 98 | static int sgml = 0; |
| 99 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 100 | static int html = 0; |
| 101 | static int htmlout = 0; |
| 102 | static int push = 0; |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 103 | #ifdef HAVE_SYS_MMAN_H |
| 104 | static int memory = 0; |
| 105 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 106 | static int noblanks = 0; |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 107 | static int format = 0; |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 108 | static int testIO = 0; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 109 | static char *encoding = NULL; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 110 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 111 | static int xinclude = 0; |
| 112 | #endif |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 113 | static int dtdattrs = 0; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 114 | static int loaddtd = 0; |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 115 | static int progresult = 0; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 116 | static int timing = 0; |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 117 | static int generate = 0; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 118 | static int dropdtd = 0; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 119 | #ifdef LIBXML_CATALOG_ENABLED |
| 120 | static int catalogs = 0; |
| 121 | static int nocatalogs = 0; |
| 122 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 123 | |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 124 | /* |
| 125 | * Internal timing routines to remove the necessity to have unix-specific |
| 126 | * function calls |
| 127 | */ |
| 128 | |
| 129 | #if defined(HAVE_GETTIMEOFDAY) |
| 130 | static struct timeval begin, end; |
| 131 | |
| 132 | /* |
| 133 | * startTimer: call where you want to start timing |
| 134 | */ |
| 135 | static void |
| 136 | startTimer(void) |
| 137 | { |
| 138 | gettimeofday(&begin, NULL); |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * endTimer: call where you want to stop timing and to print out a |
| 143 | * message about the timing performed; format is a printf |
| 144 | * type argument |
| 145 | */ |
| 146 | static void |
| 147 | endTimer(const char *format, ...) |
| 148 | { |
| 149 | long msec; |
| 150 | va_list ap; |
| 151 | |
| 152 | gettimeofday(&end, NULL); |
| 153 | msec = end.tv_sec - begin.tv_sec; |
| 154 | msec *= 1000; |
| 155 | msec += (end.tv_usec - begin.tv_usec) / 1000; |
| 156 | |
| 157 | #ifndef HAVE_STDARG_H |
| 158 | #error "endTimer required stdarg functions" |
| 159 | #endif |
| 160 | va_start(ap, format); |
| 161 | vfprintf(stderr, format, ap); |
| 162 | va_end(ap); |
| 163 | |
| 164 | fprintf(stderr, " took %ld ms\n", msec); |
| 165 | } |
| 166 | #elif defined(HAVE_TIME_H) |
| 167 | |
| 168 | /* |
| 169 | * No gettimeofday function, so we have to make do with calling clock. |
| 170 | * This is obviously less accurate, but there's little we can do about |
| 171 | * that. |
| 172 | */ |
| 173 | |
| 174 | static clock_t begin, end; |
| 175 | static void |
| 176 | startTimer(void) |
| 177 | { |
| 178 | begin = clock(); |
| 179 | } |
| 180 | static void |
| 181 | endTimer(const char *fmt, ...) |
| 182 | { |
| 183 | long msec; |
| 184 | va_list ap; |
| 185 | |
| 186 | end = clock(); |
| 187 | msec = ((end - begin) * 1000) / CLOCKS_PER_SEC; |
| 188 | |
| 189 | #ifndef HAVE_STDARG_H |
| 190 | #error "endTimer required stdarg functions" |
| 191 | #endif |
| 192 | va_start(ap, fmt); |
| 193 | vfprintf(stderr, fmt, ap); |
| 194 | va_end(ap); |
| 195 | fprintf(stderr, " took %ld ms\n", msec); |
| 196 | } |
| 197 | #else |
| 198 | |
| 199 | /* |
| 200 | * We don't have a gettimeofday or time.h, so we just don't do timing |
| 201 | */ |
| 202 | static void |
| 203 | startTimer(void) |
| 204 | { |
| 205 | /* |
| 206 | * Do nothing |
| 207 | */ |
| 208 | } |
| 209 | static void |
| 210 | endTimer(char *format, ...) |
| 211 | { |
| 212 | /* |
| 213 | * We cannot do anything because we don't have a timing function |
| 214 | */ |
| 215 | #ifdef HAVE_STDARG_H |
| 216 | va_start(ap, format); |
| 217 | vfprintf(stderr, format, ap); |
| 218 | va_end(ap); |
| 219 | fprintf(stderr, " was not timed\n", msec); |
| 220 | #else |
| 221 | /* We don't have gettimeofday, time or stdarg.h, what crazy world is |
| 222 | * this ?! |
| 223 | */ |
| 224 | #endif |
| 225 | } |
| 226 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 227 | /************************************************************************ |
| 228 | * * |
| 229 | * HTML ouput * |
| 230 | * * |
| 231 | ************************************************************************/ |
| 232 | char buffer[50000]; |
| 233 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 234 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 235 | xmlHTMLEncodeSend(void) { |
| 236 | char *result; |
| 237 | |
| 238 | result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer); |
| 239 | if (result) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 240 | xmlGenericError(xmlGenericErrorContext, "%s", result); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 241 | xmlFree(result); |
| 242 | } |
| 243 | buffer[0] = 0; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * xmlHTMLPrintFileInfo: |
| 248 | * @input: an xmlParserInputPtr input |
| 249 | * |
| 250 | * Displays the associated file and line informations for the current input |
| 251 | */ |
| 252 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 253 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 254 | xmlHTMLPrintFileInfo(xmlParserInputPtr input) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 255 | xmlGenericError(xmlGenericErrorContext, "<p>"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 256 | if (input != NULL) { |
| 257 | if (input->filename) { |
| 258 | sprintf(&buffer[strlen(buffer)], "%s:%d: ", input->filename, |
| 259 | input->line); |
| 260 | } else { |
| 261 | sprintf(&buffer[strlen(buffer)], "Entity: line %d: ", input->line); |
| 262 | } |
| 263 | } |
| 264 | xmlHTMLEncodeSend(); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * xmlHTMLPrintFileContext: |
| 269 | * @input: an xmlParserInputPtr input |
| 270 | * |
| 271 | * Displays current context within the input content for error tracking |
| 272 | */ |
| 273 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 274 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 275 | xmlHTMLPrintFileContext(xmlParserInputPtr input) { |
| 276 | const xmlChar *cur, *base; |
| 277 | int n; |
| 278 | |
| 279 | if (input == NULL) return; |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 280 | xmlGenericError(xmlGenericErrorContext, "<pre>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 281 | cur = input->cur; |
| 282 | base = input->base; |
| 283 | while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { |
| 284 | cur--; |
| 285 | } |
| 286 | n = 0; |
| 287 | while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) |
| 288 | cur--; |
| 289 | if ((*cur == '\n') || (*cur == '\r')) cur++; |
| 290 | base = cur; |
| 291 | n = 0; |
| 292 | while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { |
| 293 | sprintf(&buffer[strlen(buffer)], "%c", (unsigned char) *cur++); |
| 294 | n++; |
| 295 | } |
| 296 | sprintf(&buffer[strlen(buffer)], "\n"); |
| 297 | cur = input->cur; |
| 298 | while ((*cur == '\n') || (*cur == '\r')) |
| 299 | cur--; |
| 300 | n = 0; |
| 301 | while ((cur != base) && (n++ < 80)) { |
| 302 | sprintf(&buffer[strlen(buffer)], " "); |
| 303 | base++; |
| 304 | } |
| 305 | sprintf(&buffer[strlen(buffer)],"^\n"); |
| 306 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 307 | xmlGenericError(xmlGenericErrorContext, "</pre>"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
| 311 | * xmlHTMLError: |
| 312 | * @ctx: an XML parser context |
| 313 | * @msg: the message to display/transmit |
| 314 | * @...: extra parameters for the message display |
| 315 | * |
| 316 | * Display and format an error messages, gives file, line, position and |
| 317 | * extra parameters. |
| 318 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 319 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 320 | xmlHTMLError(void *ctx, const char *msg, ...) |
| 321 | { |
| 322 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 323 | xmlParserInputPtr input; |
| 324 | xmlParserInputPtr cur = NULL; |
| 325 | va_list args; |
| 326 | |
| 327 | buffer[0] = 0; |
| 328 | input = ctxt->input; |
| 329 | if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { |
| 330 | cur = input; |
| 331 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 332 | } |
| 333 | |
| 334 | xmlHTMLPrintFileInfo(input); |
| 335 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 336 | xmlGenericError(xmlGenericErrorContext, "<b>error</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 337 | va_start(args, msg); |
| 338 | vsprintf(&buffer[strlen(buffer)], msg, args); |
| 339 | va_end(args); |
| 340 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 341 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 342 | |
| 343 | xmlHTMLPrintFileContext(input); |
| 344 | xmlHTMLEncodeSend(); |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * xmlHTMLWarning: |
| 349 | * @ctx: an XML parser context |
| 350 | * @msg: the message to display/transmit |
| 351 | * @...: extra parameters for the message display |
| 352 | * |
| 353 | * Display and format a warning messages, gives file, line, position and |
| 354 | * extra parameters. |
| 355 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 356 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 357 | xmlHTMLWarning(void *ctx, const char *msg, ...) |
| 358 | { |
| 359 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 360 | xmlParserInputPtr input; |
| 361 | xmlParserInputPtr cur = NULL; |
| 362 | va_list args; |
| 363 | |
| 364 | buffer[0] = 0; |
| 365 | input = ctxt->input; |
| 366 | if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { |
| 367 | cur = input; |
| 368 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 369 | } |
| 370 | |
| 371 | |
| 372 | xmlHTMLPrintFileInfo(input); |
| 373 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 374 | xmlGenericError(xmlGenericErrorContext, "<b>warning</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 375 | va_start(args, msg); |
| 376 | vsprintf(&buffer[strlen(buffer)], msg, args); |
| 377 | va_end(args); |
| 378 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 379 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 380 | |
| 381 | xmlHTMLPrintFileContext(input); |
| 382 | xmlHTMLEncodeSend(); |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * xmlHTMLValidityError: |
| 387 | * @ctx: an XML parser context |
| 388 | * @msg: the message to display/transmit |
| 389 | * @...: extra parameters for the message display |
| 390 | * |
| 391 | * Display and format an validity error messages, gives file, |
| 392 | * line, position and extra parameters. |
| 393 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 394 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 395 | xmlHTMLValidityError(void *ctx, const char *msg, ...) |
| 396 | { |
| 397 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 398 | xmlParserInputPtr input; |
| 399 | va_list args; |
| 400 | |
| 401 | buffer[0] = 0; |
| 402 | input = ctxt->input; |
| 403 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 404 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 405 | |
| 406 | xmlHTMLPrintFileInfo(input); |
| 407 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 408 | xmlGenericError(xmlGenericErrorContext, "<b>validity error</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 409 | va_start(args, msg); |
| 410 | vsprintf(&buffer[strlen(buffer)], msg, args); |
| 411 | va_end(args); |
| 412 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 413 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 414 | |
| 415 | xmlHTMLPrintFileContext(input); |
| 416 | xmlHTMLEncodeSend(); |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * xmlHTMLValidityWarning: |
| 421 | * @ctx: an XML parser context |
| 422 | * @msg: the message to display/transmit |
| 423 | * @...: extra parameters for the message display |
| 424 | * |
| 425 | * Display and format a validity warning messages, gives file, line, |
| 426 | * position and extra parameters. |
| 427 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 428 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 429 | xmlHTMLValidityWarning(void *ctx, const char *msg, ...) |
| 430 | { |
| 431 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 432 | xmlParserInputPtr input; |
| 433 | va_list args; |
| 434 | |
| 435 | buffer[0] = 0; |
| 436 | input = ctxt->input; |
| 437 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 438 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 439 | |
| 440 | xmlHTMLPrintFileInfo(input); |
| 441 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 442 | xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 443 | va_start(args, msg); |
| 444 | vsprintf(&buffer[strlen(buffer)], msg, args); |
| 445 | va_end(args); |
| 446 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 447 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 448 | |
| 449 | xmlHTMLPrintFileContext(input); |
| 450 | xmlHTMLEncodeSend(); |
| 451 | } |
| 452 | |
| 453 | /************************************************************************ |
| 454 | * * |
| 455 | * Shell Interface * |
| 456 | * * |
| 457 | ************************************************************************/ |
| 458 | /** |
| 459 | * xmlShellReadline: |
| 460 | * @prompt: the prompt value |
| 461 | * |
| 462 | * Read a string |
| 463 | * |
| 464 | * Returns a pointer to it or NULL on EOF the caller is expected to |
| 465 | * free the returned string. |
| 466 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 467 | static char * |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 468 | xmlShellReadline(char *prompt) { |
| 469 | #ifdef HAVE_LIBREADLINE |
| 470 | char *line_read; |
| 471 | |
| 472 | /* Get a line from the user. */ |
| 473 | line_read = readline (prompt); |
| 474 | |
| 475 | /* If the line has any text in it, save it on the history. */ |
| 476 | if (line_read && *line_read) |
| 477 | add_history (line_read); |
| 478 | |
| 479 | return (line_read); |
| 480 | #else |
| 481 | char line_read[501]; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 482 | char *ret; |
| 483 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 484 | |
| 485 | if (prompt != NULL) |
| 486 | fprintf(stdout, "%s", prompt); |
| 487 | if (!fgets(line_read, 500, stdin)) |
| 488 | return(NULL); |
| 489 | line_read[500] = 0; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 490 | len = strlen(line_read); |
| 491 | ret = (char *) malloc(len + 1); |
| 492 | if (ret != NULL) { |
| 493 | memcpy (ret, line_read, len + 1); |
| 494 | } |
| 495 | return(ret); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 496 | #endif |
| 497 | } |
| 498 | |
| 499 | /************************************************************************ |
| 500 | * * |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 501 | * I/O Interfaces * |
| 502 | * * |
| 503 | ************************************************************************/ |
| 504 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 505 | static int myRead(FILE *f, char * buf, int len) { |
| 506 | return(fread(buf, 1, len, f)); |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 507 | } |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 508 | static void myClose(FILE *f) { |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 509 | if (f != stdin) { |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 510 | fclose(f); |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 511 | } |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /************************************************************************ |
| 515 | * * |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 516 | * Test processing * |
| 517 | * * |
| 518 | ************************************************************************/ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 519 | static void parseAndPrintFile(char *filename) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 520 | xmlDocPtr doc = NULL, tmp; |
| 521 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 522 | if ((timing) && (!repeat)) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 523 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 524 | |
| 525 | |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 526 | if (filename == NULL) { |
| 527 | if (generate) { |
| 528 | xmlNodePtr n; |
| 529 | |
| 530 | doc = xmlNewDoc(BAD_CAST "1.0"); |
| 531 | n = xmlNewNode(NULL, BAD_CAST "info"); |
| 532 | xmlNodeSetContent(n, BAD_CAST "abc"); |
| 533 | xmlDocSetRootElement(doc, n); |
| 534 | } |
| 535 | } |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 536 | #ifdef LIBXML_DOCB_ENABLED |
| 537 | /* |
| 538 | * build an SGML tree from a string; |
| 539 | */ |
| 540 | else if ((sgml) && (push)) { |
| 541 | FILE *f; |
| 542 | |
| 543 | f = fopen(filename, "r"); |
| 544 | if (f != NULL) { |
| 545 | int res, size = 3; |
| 546 | char chars[4096]; |
| 547 | docbParserCtxtPtr ctxt; |
| 548 | |
| 549 | /* if (repeat) */ |
| 550 | size = 4096; |
| 551 | res = fread(chars, 1, 4, f); |
| 552 | if (res > 0) { |
| 553 | ctxt = docbCreatePushParserCtxt(NULL, NULL, |
| 554 | chars, res, filename, 0); |
| 555 | while ((res = fread(chars, 1, size, f)) > 0) { |
| 556 | docbParseChunk(ctxt, chars, res, 0); |
| 557 | } |
| 558 | docbParseChunk(ctxt, chars, 0, 1); |
| 559 | doc = ctxt->myDoc; |
| 560 | docbFreeParserCtxt(ctxt); |
| 561 | } |
| 562 | fclose(f); |
| 563 | } |
| 564 | } else if (sgml) { |
| 565 | doc = docbParseFile(filename, NULL); |
| 566 | } |
| 567 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 568 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 569 | else if (html) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 570 | doc = htmlParseFile(filename, NULL); |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 571 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 572 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 573 | else { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 574 | /* |
| 575 | * build an XML tree from a string; |
| 576 | */ |
| 577 | if (push) { |
| 578 | FILE *f; |
| 579 | |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 580 | /* '-' Usually means stdin -<sven@zen.org> */ |
| 581 | if ((filename[0] == '-') && (filename[1] == 0)) { |
| 582 | f = stdin; |
| 583 | } else { |
| 584 | f = fopen(filename, "r"); |
| 585 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 586 | if (f != NULL) { |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 587 | int ret; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 588 | int res, size = 3; |
| 589 | char chars[1024]; |
| 590 | xmlParserCtxtPtr ctxt; |
| 591 | |
| 592 | if (repeat) |
| 593 | size = 1024; |
| 594 | res = fread(chars, 1, 4, f); |
| 595 | if (res > 0) { |
| 596 | ctxt = xmlCreatePushParserCtxt(NULL, NULL, |
| 597 | chars, res, filename); |
| 598 | while ((res = fread(chars, 1, size, f)) > 0) { |
| 599 | xmlParseChunk(ctxt, chars, res, 0); |
| 600 | } |
| 601 | xmlParseChunk(ctxt, chars, 0, 1); |
| 602 | doc = ctxt->myDoc; |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 603 | ret = ctxt->wellFormed; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 604 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 605 | if (!ret) { |
| 606 | xmlFreeDoc(doc); |
| 607 | doc = NULL; |
| 608 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 609 | } |
| 610 | } |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 611 | } else if (testIO) { |
| 612 | int ret; |
| 613 | FILE *f; |
| 614 | |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 615 | /* '-' Usually means stdin -<sven@zen.org> */ |
| 616 | if ((filename[0] == '-') && (filename[1] == 0)) { |
| 617 | f = stdin; |
| 618 | } else { |
| 619 | f = fopen(filename, "r"); |
| 620 | } |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 621 | if (f != NULL) { |
| 622 | xmlParserCtxtPtr ctxt; |
| 623 | |
| 624 | ctxt = xmlCreateIOParserCtxt(NULL, NULL, |
| 625 | (xmlInputReadCallback) myRead, |
| 626 | (xmlInputCloseCallback) myClose, |
| 627 | f, XML_CHAR_ENCODING_NONE); |
| 628 | xmlParseDocument(ctxt); |
| 629 | |
| 630 | ret = ctxt->wellFormed; |
| 631 | doc = ctxt->myDoc; |
| 632 | xmlFreeParserCtxt(ctxt); |
| 633 | if (!ret) { |
| 634 | xmlFreeDoc(doc); |
| 635 | doc = NULL; |
| 636 | } |
| 637 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 638 | } else if (recovery) { |
| 639 | doc = xmlRecoverFile(filename); |
| 640 | } else if (htmlout) { |
| 641 | int ret; |
| 642 | xmlParserCtxtPtr ctxt; |
| 643 | xmlSAXHandler silent, *old; |
| 644 | |
| 645 | ctxt = xmlCreateFileParserCtxt(filename); |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 646 | |
| 647 | if (ctxt == NULL) { |
| 648 | /* If xmlCreateFileParseCtxt() return NULL something |
| 649 | strange happened so we don't want to do anything. Do |
| 650 | we want to print an error message here? |
| 651 | <sven@zen.org> */ |
Daniel Veillard | 7ebb1ee | 2000-08-04 18:24:45 +0000 | [diff] [blame] | 652 | doc = NULL; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 653 | } else { |
| 654 | memcpy(&silent, ctxt->sax, sizeof(silent)); |
| 655 | old = ctxt->sax; |
| 656 | silent.error = xmlHTMLError; |
| 657 | if (xmlGetWarningsDefaultValue) |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 658 | silent.warning = xmlHTMLWarning; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 659 | else |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 660 | silent.warning = NULL; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 661 | silent.fatalError = xmlHTMLError; |
| 662 | ctxt->sax = &silent; |
| 663 | ctxt->vctxt.error = xmlHTMLValidityError; |
| 664 | if (xmlGetWarningsDefaultValue) |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 665 | ctxt->vctxt.warning = xmlHTMLValidityWarning; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 666 | else |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 667 | ctxt->vctxt.warning = NULL; |
| 668 | |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 669 | xmlParseDocument(ctxt); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 670 | |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 671 | ret = ctxt->wellFormed; |
| 672 | doc = ctxt->myDoc; |
| 673 | ctxt->sax = old; |
| 674 | xmlFreeParserCtxt(ctxt); |
| 675 | if (!ret) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 676 | xmlFreeDoc(doc); |
| 677 | doc = NULL; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 678 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 679 | } |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 680 | #ifdef HAVE_SYS_MMAN_H |
| 681 | } else if (memory) { |
| 682 | int fd; |
| 683 | struct stat info; |
| 684 | const char *base; |
| 685 | if (stat(filename, &info) < 0) |
| 686 | return; |
| 687 | if ((fd = open(filename, O_RDONLY)) < 0) |
| 688 | return; |
| 689 | base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; |
Daniel Veillard | 2957936 | 2000-08-14 17:57:48 +0000 | [diff] [blame] | 690 | if (base == (void *) MAP_FAILED) |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 691 | return; |
| 692 | |
| 693 | doc = xmlParseMemory((char *) base, info.st_size); |
| 694 | munmap((char *) base, info.st_size); |
| 695 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 696 | } else |
| 697 | doc = xmlParseFile(filename); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 698 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 699 | |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 700 | /* |
| 701 | * If we don't have a document we might as well give up. Do we |
| 702 | * want an error message here? <sven@zen.org> */ |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 703 | if (doc == NULL) { |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 704 | progresult = 1; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 705 | return; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 708 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 709 | endTimer("Parsing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 712 | /* |
| 713 | * Remove DOCTYPE nodes |
| 714 | */ |
| 715 | if (dropdtd) { |
| 716 | xmlDtdPtr dtd; |
| 717 | |
| 718 | dtd = xmlGetIntSubset(doc); |
| 719 | if (dtd != NULL) { |
| 720 | xmlUnlinkNode((xmlNodePtr)dtd); |
| 721 | xmlFreeDtd(dtd); |
| 722 | } |
| 723 | } |
| 724 | |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 725 | #ifdef LIBXML_XINCLUDE_ENABLED |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 726 | if (xinclude) { |
| 727 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 728 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 729 | } |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 730 | xmlXIncludeProcess(doc); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 731 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 732 | endTimer("Xinclude processing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 733 | } |
| 734 | } |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 735 | #endif |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 736 | |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 737 | #ifdef LIBXML_DEBUG_ENABLED |
| 738 | /* |
| 739 | * shell interraction |
| 740 | */ |
| 741 | if (shell) |
| 742 | xmlShell(doc, filename, xmlShellReadline, stdout); |
| 743 | #endif |
| 744 | |
| 745 | /* |
| 746 | * test intermediate copy if needed. |
| 747 | */ |
| 748 | if (copy) { |
| 749 | tmp = doc; |
| 750 | doc = xmlCopyDoc(doc, 1); |
| 751 | xmlFreeDoc(tmp); |
| 752 | } |
| 753 | |
| 754 | if ((insert) && (!html)) { |
| 755 | const xmlChar* list[256]; |
| 756 | int nb, i; |
| 757 | xmlNodePtr node; |
| 758 | |
| 759 | if (doc->children != NULL) { |
| 760 | node = doc->children; |
| 761 | while ((node != NULL) && (node->last == NULL)) node = node->next; |
| 762 | if (node != NULL) { |
| 763 | nb = xmlValidGetValidElements(node->last, NULL, list, 256); |
| 764 | if (nb < 0) { |
| 765 | printf("could not get valid list of elements\n"); |
| 766 | } else if (nb == 0) { |
MDT 2001 John Fleck | bbb9e43 | 2001-09-24 03:08:43 +0000 | [diff] [blame] | 767 | printf("No element can be inserted under root\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 768 | } else { |
MDT 2001 John Fleck | bbb9e43 | 2001-09-24 03:08:43 +0000 | [diff] [blame] | 769 | printf("%d element types can be inserted under root:\n", |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 770 | nb); |
| 771 | for (i = 0;i < nb;i++) { |
| 772 | printf("%s\n", list[i]); |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | }else if (noout == 0) { |
| 778 | /* |
| 779 | * print it. |
| 780 | */ |
| 781 | #ifdef LIBXML_DEBUG_ENABLED |
| 782 | if (!debug) { |
| 783 | #endif |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 784 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 785 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 786 | } |
Daniel Veillard | 3b2c261 | 2001-04-04 00:09:00 +0000 | [diff] [blame] | 787 | #ifdef HAVE_SYS_MMAN_H |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 788 | if (memory) { |
| 789 | xmlChar *result; |
| 790 | int len; |
| 791 | |
| 792 | if (encoding != NULL) { |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 793 | if ( format ) { |
| 794 | xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1); |
| 795 | } else { |
| 796 | xmlDocDumpMemoryEnc(doc, &result, &len, encoding); |
| 797 | } |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 798 | } else { |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 799 | if (format) |
| 800 | xmlDocDumpFormatMemory(doc, &result, &len, 1); |
| 801 | else |
| 802 | xmlDocDumpMemory(doc, &result, &len); |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 803 | } |
| 804 | if (result == NULL) { |
| 805 | fprintf(stderr, "Failed to save\n"); |
| 806 | } else { |
| 807 | write(1, result, len); |
| 808 | xmlFree(result); |
| 809 | } |
Daniel Veillard | 3b2c261 | 2001-04-04 00:09:00 +0000 | [diff] [blame] | 810 | } else |
| 811 | #endif /* HAVE_SYS_MMAN_H */ |
| 812 | if (compress) |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 813 | xmlSaveFile("-", doc); |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 814 | else if (encoding != NULL) { |
| 815 | if ( format ) { |
| 816 | xmlSaveFormatFileEnc("-", doc, encoding, 1); |
| 817 | } |
| 818 | else { |
| 819 | xmlSaveFileEnc("-", doc, encoding); |
| 820 | } |
| 821 | } |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 822 | else if (format) |
| 823 | xmlSaveFormatFile("-", doc, 1); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 824 | else |
| 825 | xmlDocDump(stdout, doc); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 826 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 827 | endTimer("Saving"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 828 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 829 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 830 | } else { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 831 | xmlDebugDumpDocument(stdout, doc); |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 832 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 833 | #endif |
| 834 | } |
| 835 | |
| 836 | /* |
| 837 | * A posteriori validation test |
| 838 | */ |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 839 | if (dtdvalid != NULL) { |
| 840 | xmlDtdPtr dtd; |
| 841 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 842 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 843 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 844 | } |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 845 | dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 846 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 847 | endTimer("Parsing DTD"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 848 | } |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 849 | if (dtd == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 850 | xmlGenericError(xmlGenericErrorContext, |
| 851 | "Could not parse DTD %s\n", dtdvalid); |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 852 | progresult = 2; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 853 | } else { |
| 854 | xmlValidCtxt cvp; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 855 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 856 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 857 | } |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 858 | cvp.userData = (void *) stderr; |
| 859 | cvp.error = (xmlValidityErrorFunc) fprintf; |
| 860 | cvp.warning = (xmlValidityWarningFunc) fprintf; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 861 | if (!xmlValidateDtd(&cvp, doc, dtd)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 862 | xmlGenericError(xmlGenericErrorContext, |
| 863 | "Document %s does not validate against %s\n", |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 864 | filename, dtdvalid); |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 865 | progresult = 3; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 866 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 867 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 868 | endTimer("Validating against DTD"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 869 | } |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 870 | xmlFreeDtd(dtd); |
| 871 | } |
| 872 | } else if (postvalid) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 873 | xmlValidCtxt cvp; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 874 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 875 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 876 | } |
Daniel Veillard | b7664f4 | 2001-08-19 13:00:43 +0000 | [diff] [blame] | 877 | cvp.userData = (void *) stderr; |
| 878 | cvp.error = (xmlValidityErrorFunc) fprintf; |
| 879 | cvp.warning = (xmlValidityWarningFunc) fprintf; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 880 | if (!xmlValidateDocument(&cvp, doc)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 881 | xmlGenericError(xmlGenericErrorContext, |
| 882 | "Document %s does not validate\n", filename); |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 883 | progresult = 3; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 884 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 885 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 886 | endTimer("Validating"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 887 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | #ifdef LIBXML_DEBUG_ENABLED |
| 891 | if ((debugent) && (!html)) |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 892 | xmlDebugDumpEntities(stderr, doc); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 893 | #endif |
| 894 | |
| 895 | /* |
| 896 | * free it. |
| 897 | */ |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 898 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 899 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 900 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 901 | xmlFreeDoc(doc); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 902 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 903 | endTimer("Freeing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 904 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 907 | /************************************************************************ |
| 908 | * * |
| 909 | * Usage and Main * |
| 910 | * * |
| 911 | ************************************************************************/ |
| 912 | |
| 913 | static void usage(const char *name) { |
| 914 | printf("Usage : %s [options] XMLfiles ...\n", name); |
| 915 | printf("\tParse the XML files and output the result of the parsing\n"); |
| 916 | printf("\t--version : display the version of the XML library used\n"); |
| 917 | #ifdef LIBXML_DEBUG_ENABLED |
| 918 | printf("\t--debug : dump a debug tree of the in-memory document\n"); |
| 919 | printf("\t--shell : run a navigating shell\n"); |
| 920 | printf("\t--debugent : debug the entities defined in the document\n"); |
| 921 | #endif |
| 922 | printf("\t--copy : used to test the internal copy implementation\n"); |
| 923 | printf("\t--recover : output what was parsable on broken XML documents\n"); |
| 924 | printf("\t--noent : substitute entity references by their value\n"); |
| 925 | printf("\t--noout : don't output the result tree\n"); |
| 926 | printf("\t--htmlout : output results as HTML\n"); |
Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 927 | printf("\t--nowrap : do not put HTML doc wrapper\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 928 | printf("\t--valid : validate the document in addition to std well-formed check\n"); |
| 929 | printf("\t--postvalid : do a posteriori validation, i.e after parsing\n"); |
| 930 | printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n"); |
| 931 | printf("\t--timing : print some timings\n"); |
| 932 | printf("\t--repeat : repeat 100 times, for timing or profiling\n"); |
| 933 | printf("\t--insert : ad-hoc test for valid insertions\n"); |
| 934 | printf("\t--compress : turn on gzip compression of output\n"); |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 935 | #ifdef LIBXML_DOCB_ENABLED |
| 936 | printf("\t--sgml : use the DocBook SGML parser\n"); |
| 937 | #endif |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 938 | #ifdef LIBXML_HTML_ENABLED |
| 939 | printf("\t--html : use the HTML parser\n"); |
| 940 | #endif |
| 941 | printf("\t--push : use the push mode of the parser\n"); |
| 942 | #ifdef HAVE_SYS_MMAN_H |
| 943 | printf("\t--memory : parse from memory\n"); |
| 944 | #endif |
| 945 | printf("\t--nowarning : do not emit warnings from parser/validator\n"); |
| 946 | printf("\t--noblanks : drop (ignorable?) blanks spaces\n"); |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 947 | printf("\t--format : reformat/reindent the input\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 948 | printf("\t--testIO : test user I/O support\n"); |
| 949 | printf("\t--encode encoding : output in the given encoding\n"); |
| 950 | #ifdef LIBXML_CATALOG_ENABLED |
Daniel Veillard | bd9b0e8 | 2001-11-26 10:32:08 +0000 | [diff] [blame] | 951 | printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n"); |
| 952 | printf("\t otherwise XML Catalogs starting from \n"); |
| 953 | printf("\t file:///etc/xml/catalog are activated by default\n"); |
Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 954 | printf("\t--nocatalogs: deactivate all catalogs\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 955 | #endif |
| 956 | printf("\t--auto : generate a small doc on the fly\n"); |
| 957 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 958 | printf("\t--xinclude : do XInclude processing\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 959 | #endif |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 960 | printf("\t--loaddtd : fetch external Dtd\n"); |
| 961 | printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n"); |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 962 | printf("\t--dropdtd : remove the DOCTYPE of the input docs\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 963 | } |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 964 | int |
| 965 | main(int argc, char **argv) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 966 | int i, count; |
| 967 | int files = 0; |
| 968 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 969 | if (argc <= 1) { |
| 970 | usage(argv[0]); |
| 971 | return(1); |
| 972 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 973 | LIBXML_TEST_VERSION |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 974 | for (i = 1; i < argc ; i++) { |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 975 | if (!strcmp(argv[i], "-")) |
| 976 | break; |
| 977 | |
| 978 | if (argv[i][0] != '-') |
| 979 | continue; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 980 | #ifdef LIBXML_DEBUG_ENABLED |
| 981 | if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) |
| 982 | debug++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 983 | else if ((!strcmp(argv[i], "-shell")) || |
| 984 | (!strcmp(argv[i], "--shell"))) { |
| 985 | shell++; |
| 986 | noout = 1; |
| 987 | } else |
| 988 | #endif |
| 989 | if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) |
| 990 | copy++; |
| 991 | else if ((!strcmp(argv[i], "-recover")) || |
| 992 | (!strcmp(argv[i], "--recover"))) |
| 993 | recovery++; |
| 994 | else if ((!strcmp(argv[i], "-noent")) || |
| 995 | (!strcmp(argv[i], "--noent"))) |
| 996 | noent++; |
Daniel Veillard | 4ec885a | 2001-06-17 10:31:07 +0000 | [diff] [blame] | 997 | else if ((!strcmp(argv[i], "-version")) || |
| 998 | (!strcmp(argv[i], "--version"))) |
| 999 | fprintf(stderr, "xmllint: using libxml version %s\n", |
| 1000 | xmlParserVersion); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1001 | else if ((!strcmp(argv[i], "-noout")) || |
| 1002 | (!strcmp(argv[i], "--noout"))) |
| 1003 | noout++; |
| 1004 | else if ((!strcmp(argv[i], "-htmlout")) || |
| 1005 | (!strcmp(argv[i], "--htmlout"))) |
| 1006 | htmlout++; |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 1007 | #ifdef LIBXML_DOCB_ENABLED |
| 1008 | else if ((!strcmp(argv[i], "-sgml")) || |
| 1009 | (!strcmp(argv[i], "--sgml"))) { |
| 1010 | sgml++; |
| 1011 | } |
| 1012 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1013 | #ifdef LIBXML_HTML_ENABLED |
| 1014 | else if ((!strcmp(argv[i], "-html")) || |
| 1015 | (!strcmp(argv[i], "--html"))) { |
| 1016 | html++; |
| 1017 | } |
| 1018 | #endif /* LIBXML_HTML_ENABLED */ |
| 1019 | else if ((!strcmp(argv[i], "-nowrap")) || |
| 1020 | (!strcmp(argv[i], "--nowrap"))) |
| 1021 | nowrap++; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1022 | else if ((!strcmp(argv[i], "-loaddtd")) || |
| 1023 | (!strcmp(argv[i], "--loaddtd"))) |
| 1024 | loaddtd++; |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 1025 | else if ((!strcmp(argv[i], "-dtdattr")) || |
| 1026 | (!strcmp(argv[i], "--dtdattr"))) { |
| 1027 | loaddtd++; |
| 1028 | dtdattrs++; |
| 1029 | } else if ((!strcmp(argv[i], "-valid")) || |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1030 | (!strcmp(argv[i], "--valid"))) |
| 1031 | valid++; |
| 1032 | else if ((!strcmp(argv[i], "-postvalid")) || |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1033 | (!strcmp(argv[i], "--postvalid"))) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1034 | postvalid++; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1035 | loaddtd++; |
| 1036 | } else if ((!strcmp(argv[i], "-dtdvalid")) || |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1037 | (!strcmp(argv[i], "--dtdvalid"))) { |
| 1038 | i++; |
| 1039 | dtdvalid = argv[i]; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1040 | loaddtd++; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1041 | } |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 1042 | else if ((!strcmp(argv[i], "-dropdtd")) || |
| 1043 | (!strcmp(argv[i], "--dropdtd"))) |
| 1044 | dropdtd++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1045 | else if ((!strcmp(argv[i], "-insert")) || |
| 1046 | (!strcmp(argv[i], "--insert"))) |
| 1047 | insert++; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1048 | else if ((!strcmp(argv[i], "-timing")) || |
| 1049 | (!strcmp(argv[i], "--timing"))) |
| 1050 | timing++; |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 1051 | else if ((!strcmp(argv[i], "-auto")) || |
| 1052 | (!strcmp(argv[i], "--auto"))) |
| 1053 | generate++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1054 | else if ((!strcmp(argv[i], "-repeat")) || |
| 1055 | (!strcmp(argv[i], "--repeat"))) |
| 1056 | repeat++; |
| 1057 | else if ((!strcmp(argv[i], "-push")) || |
| 1058 | (!strcmp(argv[i], "--push"))) |
| 1059 | push++; |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 1060 | #ifdef HAVE_SYS_MMAN_H |
| 1061 | else if ((!strcmp(argv[i], "-memory")) || |
| 1062 | (!strcmp(argv[i], "--memory"))) |
| 1063 | memory++; |
| 1064 | #endif |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 1065 | else if ((!strcmp(argv[i], "-testIO")) || |
| 1066 | (!strcmp(argv[i], "--testIO"))) |
| 1067 | testIO++; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 1068 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 1069 | else if ((!strcmp(argv[i], "-xinclude")) || |
| 1070 | (!strcmp(argv[i], "--xinclude"))) |
| 1071 | xinclude++; |
| 1072 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1073 | else if ((!strcmp(argv[i], "-compress")) || |
| 1074 | (!strcmp(argv[i], "--compress"))) { |
| 1075 | compress++; |
| 1076 | xmlSetCompressMode(9); |
| 1077 | } |
| 1078 | else if ((!strcmp(argv[i], "-nowarning")) || |
| 1079 | (!strcmp(argv[i], "--nowarning"))) { |
| 1080 | xmlGetWarningsDefaultValue = 0; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1081 | xmlPedanticParserDefault(0); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1082 | } |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1083 | else if ((!strcmp(argv[i], "-pedantic")) || |
| 1084 | (!strcmp(argv[i], "--pedantic"))) { |
| 1085 | xmlGetWarningsDefaultValue = 1; |
| 1086 | xmlPedanticParserDefault(1); |
| 1087 | } |
Daniel Veillard | 64c20ed | 2000-09-22 16:07:02 +0000 | [diff] [blame] | 1088 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1089 | else if ((!strcmp(argv[i], "-debugent")) || |
| 1090 | (!strcmp(argv[i], "--debugent"))) { |
| 1091 | debugent++; |
| 1092 | xmlParserDebugEntities = 1; |
| 1093 | } |
Daniel Veillard | 64c20ed | 2000-09-22 16:07:02 +0000 | [diff] [blame] | 1094 | #endif |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 1095 | #ifdef LIBXML_CATALOG_ENABLED |
| 1096 | else if ((!strcmp(argv[i], "-catalogs")) || |
| 1097 | (!strcmp(argv[i], "--catalogs"))) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1098 | catalogs++; |
| 1099 | } else if ((!strcmp(argv[i], "-nocatalogs")) || |
| 1100 | (!strcmp(argv[i], "--nocatalogs"))) { |
| 1101 | nocatalogs++; |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 1102 | } |
| 1103 | #endif |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1104 | else if ((!strcmp(argv[i], "-encode")) || |
| 1105 | (!strcmp(argv[i], "--encode"))) { |
| 1106 | i++; |
| 1107 | encoding = argv[i]; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1108 | /* |
| 1109 | * OK it's for testing purposes |
| 1110 | */ |
| 1111 | xmlAddEncodingAlias("UTF-8", "DVEnc"); |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1112 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1113 | else if ((!strcmp(argv[i], "-noblanks")) || |
| 1114 | (!strcmp(argv[i], "--noblanks"))) { |
| 1115 | noblanks++; |
| 1116 | xmlKeepBlanksDefault(0); |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 1117 | } |
| 1118 | else if ((!strcmp(argv[i], "-format")) || |
| 1119 | (!strcmp(argv[i], "--format"))) { |
| 1120 | noblanks++; |
| 1121 | format++; |
| 1122 | xmlKeepBlanksDefault(0); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1123 | } else { |
| 1124 | fprintf(stderr, "Unknown option %s\n", argv[i]); |
| 1125 | usage(argv[0]); |
| 1126 | return(1); |
| 1127 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1128 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1129 | |
| 1130 | #ifdef LIBXML_CATALOG_ENABLED |
| 1131 | if (nocatalogs == 0) { |
| 1132 | if (catalogs) { |
| 1133 | const char *catal; |
| 1134 | |
| 1135 | catal = getenv("SGML_CATALOG_FILES"); |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 1136 | if (catal != NULL) { |
| 1137 | xmlLoadCatalogs(catal); |
| 1138 | } else { |
| 1139 | fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n"); |
| 1140 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | #endif |
Daniel Veillard | d9bad13 | 2001-07-23 19:39:43 +0000 | [diff] [blame] | 1144 | xmlLineNumbersDefault(1); |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 1145 | if (loaddtd != 0) |
| 1146 | xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS; |
| 1147 | if (dtdattrs) |
| 1148 | xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1149 | if (noent != 0) xmlSubstituteEntitiesDefault(1); |
| 1150 | if (valid != 0) xmlDoValidityCheckingDefaultValue = 1; |
| 1151 | if ((htmlout) && (!nowrap)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1152 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1153 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n"); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1154 | xmlGenericError(xmlGenericErrorContext, |
| 1155 | "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"); |
| 1156 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1157 | "<html><head><title>%s output</title></head>\n", |
| 1158 | argv[0]); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1159 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1160 | "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n", |
| 1161 | argv[0]); |
| 1162 | } |
| 1163 | for (i = 1; i < argc ; i++) { |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1164 | if ((!strcmp(argv[i], "-encode")) || |
| 1165 | (!strcmp(argv[i], "--encode"))) { |
| 1166 | i++; |
| 1167 | continue; |
| 1168 | } |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1169 | if ((!strcmp(argv[i], "-dtdvalid")) || |
| 1170 | (!strcmp(argv[i], "--dtdvalid"))) { |
| 1171 | i++; |
| 1172 | continue; |
| 1173 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1174 | if ((timing) && (repeat)) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1175 | startTimer(); |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 1176 | /* Remember file names. "-" means stding. <sven@zen.org> */ |
| 1177 | if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1178 | if (repeat) { |
| 1179 | for (count = 0;count < 100 * repeat;count++) |
| 1180 | parseAndPrintFile(argv[i]); |
| 1181 | } else |
| 1182 | parseAndPrintFile(argv[i]); |
| 1183 | files ++; |
Daniel Veillard | a786693 | 2001-12-04 13:14:44 +0000 | [diff] [blame] | 1184 | if ((timing) && (repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1185 | endTimer("100 iterations"); |
Daniel Veillard | a786693 | 2001-12-04 13:14:44 +0000 | [diff] [blame] | 1186 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1187 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1188 | } |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 1189 | if (generate) |
| 1190 | parseAndPrintFile(NULL); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1191 | if ((htmlout) && (!nowrap)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1192 | xmlGenericError(xmlGenericErrorContext, "</body></html>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1193 | } |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 1194 | if ((files == 0) && (!generate)) { |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1195 | usage(argv[0]); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1196 | } |
| 1197 | xmlCleanupParser(); |
| 1198 | xmlMemoryDump(); |
| 1199 | |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 1200 | return(progresult); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1201 | } |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 1202 | |