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