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