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