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 | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 14 | #include <assert.h> |
| 15 | |
Daniel Veillard | 3c5ed91 | 2002-01-08 10:36:16 +0000 | [diff] [blame] | 16 | #if defined (_WIN32) && !defined(__CYGWIN__) |
Daniel Veillard | 2d90de4 | 2001-04-16 17:46:18 +0000 | [diff] [blame] | 17 | #ifdef _MSC_VER |
| 18 | #include <winsock2.h> |
| 19 | #pragma comment(lib, "ws2_32.lib") |
| 20 | #define gettimeofday(p1,p2) |
Daniel Veillard | f216d46 | 2002-02-08 13:44:24 +0000 | [diff] [blame] | 21 | #include <time.h> |
Daniel Veillard | 28ae636 | 2001-07-14 16:44:32 +0000 | [diff] [blame] | 22 | #else /* _MSC_VER */ |
| 23 | #include <sys/time.h> |
Daniel Veillard | 2d90de4 | 2001-04-16 17:46:18 +0000 | [diff] [blame] | 24 | #endif /* _MSC_VER */ |
| 25 | #else /* _WIN32 */ |
Daniel Veillard | ed472f3 | 2001-12-13 08:48:14 +0000 | [diff] [blame] | 26 | #ifdef HAVE_SYS_TIME_H |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 27 | #include <sys/time.h> |
Daniel Veillard | ed472f3 | 2001-12-13 08:48:14 +0000 | [diff] [blame] | 28 | #endif |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 29 | #ifdef HAVE_TIME_H |
| 30 | #include <time.h> |
| 31 | #endif |
Daniel Veillard | 2d90de4 | 2001-04-16 17:46:18 +0000 | [diff] [blame] | 32 | #endif /* _WIN32 */ |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 33 | |
Daniel Veillard | 90bc371 | 2002-03-07 15:12:58 +0000 | [diff] [blame] | 34 | #ifdef HAVE_SYS_TIMEB_H |
| 35 | #include <sys/timeb.h> |
| 36 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 37 | |
| 38 | #ifdef HAVE_SYS_TYPES_H |
| 39 | #include <sys/types.h> |
| 40 | #endif |
| 41 | #ifdef HAVE_SYS_STAT_H |
| 42 | #include <sys/stat.h> |
| 43 | #endif |
| 44 | #ifdef HAVE_FCNTL_H |
| 45 | #include <fcntl.h> |
| 46 | #endif |
| 47 | #ifdef HAVE_UNISTD_H |
| 48 | #include <unistd.h> |
| 49 | #endif |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 50 | #ifdef HAVE_SYS_MMAN_H |
| 51 | #include <sys/mman.h> |
Daniel Veillard | 87b9539 | 2000-08-12 21:12:04 +0000 | [diff] [blame] | 52 | /* seems needed for Solaris */ |
| 53 | #ifndef MAP_FAILED |
| 54 | #define MAP_FAILED ((void *) -1) |
| 55 | #endif |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 56 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 57 | #ifdef HAVE_STDLIB_H |
| 58 | #include <stdlib.h> |
| 59 | #endif |
| 60 | #ifdef HAVE_LIBREADLINE |
| 61 | #include <readline/readline.h> |
| 62 | #ifdef HAVE_LIBHISTORY |
| 63 | #include <readline/history.h> |
| 64 | #endif |
| 65 | #endif |
| 66 | |
| 67 | #include <libxml/xmlmemory.h> |
| 68 | #include <libxml/parser.h> |
| 69 | #include <libxml/parserInternals.h> |
| 70 | #include <libxml/HTMLparser.h> |
| 71 | #include <libxml/HTMLtree.h> |
| 72 | #include <libxml/tree.h> |
| 73 | #include <libxml/xpath.h> |
| 74 | #include <libxml/debugXML.h> |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 75 | #include <libxml/xmlerror.h> |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 76 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 77 | #include <libxml/xinclude.h> |
| 78 | #endif |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 79 | #ifdef LIBXML_CATALOG_ENABLED |
| 80 | #include <libxml/catalog.h> |
| 81 | #endif |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 82 | #ifdef LIBXML_DOCB_ENABLED |
| 83 | #include <libxml/DOCBparser.h> |
| 84 | #endif |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 85 | #include <libxml/globals.h> |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 86 | #include <libxml/xmlreader.h> |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 87 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 88 | #include <libxml/relaxng.h> |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 89 | #include <libxml/xmlschemas.h> |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 90 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 91 | |
Daniel Veillard | 3be2751 | 2003-01-26 19:49:04 +0000 | [diff] [blame] | 92 | #ifndef XML_XML_DEFAULT_CATALOG |
| 93 | #define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog" |
| 94 | #endif |
| 95 | |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 96 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 97 | static int shell = 0; |
| 98 | static int debugent = 0; |
| 99 | #endif |
Daniel Veillard | 8326e73 | 2003-01-07 00:19:07 +0000 | [diff] [blame] | 100 | static int debug = 0; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 101 | static int copy = 0; |
| 102 | static int recovery = 0; |
| 103 | static int noent = 0; |
| 104 | static int noout = 0; |
| 105 | static int nowrap = 0; |
| 106 | static int valid = 0; |
| 107 | static int postvalid = 0; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 108 | static char * dtdvalid = NULL; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 109 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 110 | static char * relaxng = NULL; |
| 111 | static xmlRelaxNGPtr relaxngschemas = NULL; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 112 | static char * schema = NULL; |
| 113 | static xmlSchemaPtr wxschemas = NULL; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 114 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 115 | static int repeat = 0; |
| 116 | static int insert = 0; |
| 117 | static int compress = 0; |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 118 | #ifdef LIBXML_DOCB_ENABLED |
| 119 | static int sgml = 0; |
| 120 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 121 | static int html = 0; |
| 122 | static int htmlout = 0; |
| 123 | static int push = 0; |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 124 | #ifdef HAVE_SYS_MMAN_H |
| 125 | static int memory = 0; |
| 126 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 127 | static int noblanks = 0; |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 128 | static int format = 0; |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 129 | static int testIO = 0; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 130 | static char *encoding = NULL; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 131 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 132 | static int xinclude = 0; |
| 133 | #endif |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 134 | static int dtdattrs = 0; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 135 | static int loaddtd = 0; |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 136 | static int progresult = 0; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 137 | static int timing = 0; |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 138 | static int generate = 0; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 139 | static int dropdtd = 0; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 140 | #ifdef LIBXML_CATALOG_ENABLED |
| 141 | static int catalogs = 0; |
| 142 | static int nocatalogs = 0; |
| 143 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 144 | static int stream = 0; |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 145 | static int chkregister = 0; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 146 | static const char *output = NULL; |
| 147 | |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 148 | |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 149 | /* |
| 150 | * Internal timing routines to remove the necessity to have unix-specific |
| 151 | * function calls |
| 152 | */ |
| 153 | |
Daniel Veillard | 8c1ae60 | 2002-03-07 11:21:00 +0000 | [diff] [blame] | 154 | #ifndef HAVE_GETTIMEOFDAY |
| 155 | #ifdef HAVE_SYS_TIMEB_H |
| 156 | #ifdef HAVE_SYS_TIME_H |
| 157 | #ifdef HAVE_FTIME |
| 158 | |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 159 | static int |
Daniel Veillard | 8c1ae60 | 2002-03-07 11:21:00 +0000 | [diff] [blame] | 160 | my_gettimeofday(struct timeval *tvp, void *tzp) |
| 161 | { |
| 162 | struct timeb timebuffer; |
| 163 | |
| 164 | ftime(&timebuffer); |
| 165 | if (tvp) { |
| 166 | tvp->tv_sec = timebuffer.time; |
| 167 | tvp->tv_usec = timebuffer.millitm * 1000L; |
| 168 | } |
| 169 | return (0); |
| 170 | } |
| 171 | #define HAVE_GETTIMEOFDAY 1 |
| 172 | #define gettimeofday my_gettimeofday |
| 173 | |
| 174 | #endif /* HAVE_FTIME */ |
| 175 | #endif /* HAVE_SYS_TIME_H */ |
| 176 | #endif /* HAVE_SYS_TIMEB_H */ |
| 177 | #endif /* !HAVE_GETTIMEOFDAY */ |
| 178 | |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 179 | #if defined(HAVE_GETTIMEOFDAY) |
| 180 | static struct timeval begin, end; |
| 181 | |
| 182 | /* |
| 183 | * startTimer: call where you want to start timing |
| 184 | */ |
| 185 | static void |
| 186 | startTimer(void) |
| 187 | { |
| 188 | gettimeofday(&begin, NULL); |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | * endTimer: call where you want to stop timing and to print out a |
| 193 | * message about the timing performed; format is a printf |
| 194 | * type argument |
| 195 | */ |
| 196 | static void |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 197 | endTimer(const char *fmt, ...) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 198 | { |
| 199 | long msec; |
| 200 | va_list ap; |
| 201 | |
| 202 | gettimeofday(&end, NULL); |
| 203 | msec = end.tv_sec - begin.tv_sec; |
| 204 | msec *= 1000; |
| 205 | msec += (end.tv_usec - begin.tv_usec) / 1000; |
| 206 | |
| 207 | #ifndef HAVE_STDARG_H |
| 208 | #error "endTimer required stdarg functions" |
| 209 | #endif |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 210 | va_start(ap, fmt); |
| 211 | vfprintf(stderr, fmt, ap); |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 212 | va_end(ap); |
| 213 | |
| 214 | fprintf(stderr, " took %ld ms\n", msec); |
| 215 | } |
| 216 | #elif defined(HAVE_TIME_H) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 217 | /* |
| 218 | * No gettimeofday function, so we have to make do with calling clock. |
| 219 | * This is obviously less accurate, but there's little we can do about |
| 220 | * that. |
| 221 | */ |
Daniel Veillard | 90bc371 | 2002-03-07 15:12:58 +0000 | [diff] [blame] | 222 | #ifndef CLOCKS_PER_SEC |
| 223 | #define CLOCKS_PER_SEC 100 |
| 224 | #endif |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 225 | |
| 226 | static clock_t begin, end; |
| 227 | static void |
| 228 | startTimer(void) |
| 229 | { |
| 230 | begin = clock(); |
| 231 | } |
| 232 | static void |
| 233 | endTimer(const char *fmt, ...) |
| 234 | { |
| 235 | long msec; |
| 236 | va_list ap; |
| 237 | |
| 238 | end = clock(); |
| 239 | msec = ((end - begin) * 1000) / CLOCKS_PER_SEC; |
| 240 | |
| 241 | #ifndef HAVE_STDARG_H |
| 242 | #error "endTimer required stdarg functions" |
| 243 | #endif |
| 244 | va_start(ap, fmt); |
| 245 | vfprintf(stderr, fmt, ap); |
| 246 | va_end(ap); |
| 247 | fprintf(stderr, " took %ld ms\n", msec); |
| 248 | } |
| 249 | #else |
| 250 | |
| 251 | /* |
| 252 | * We don't have a gettimeofday or time.h, so we just don't do timing |
| 253 | */ |
| 254 | static void |
| 255 | startTimer(void) |
| 256 | { |
| 257 | /* |
| 258 | * Do nothing |
| 259 | */ |
| 260 | } |
| 261 | static void |
| 262 | endTimer(char *format, ...) |
| 263 | { |
| 264 | /* |
| 265 | * We cannot do anything because we don't have a timing function |
| 266 | */ |
| 267 | #ifdef HAVE_STDARG_H |
| 268 | va_start(ap, format); |
| 269 | vfprintf(stderr, format, ap); |
| 270 | va_end(ap); |
| 271 | fprintf(stderr, " was not timed\n", msec); |
| 272 | #else |
| 273 | /* We don't have gettimeofday, time or stdarg.h, what crazy world is |
| 274 | * this ?! |
| 275 | */ |
| 276 | #endif |
| 277 | } |
| 278 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 279 | /************************************************************************ |
| 280 | * * |
| 281 | * HTML ouput * |
| 282 | * * |
| 283 | ************************************************************************/ |
| 284 | char buffer[50000]; |
| 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 | xmlHTMLEncodeSend(void) { |
| 288 | char *result; |
| 289 | |
| 290 | result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer); |
| 291 | if (result) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 292 | xmlGenericError(xmlGenericErrorContext, "%s", result); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 293 | xmlFree(result); |
| 294 | } |
| 295 | buffer[0] = 0; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * xmlHTMLPrintFileInfo: |
| 300 | * @input: an xmlParserInputPtr input |
| 301 | * |
| 302 | * Displays the associated file and line informations for the current input |
| 303 | */ |
| 304 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 305 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 306 | xmlHTMLPrintFileInfo(xmlParserInputPtr input) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 307 | int len; |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 308 | xmlGenericError(xmlGenericErrorContext, "<p>"); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 309 | |
| 310 | len = strlen(buffer); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 311 | if (input != NULL) { |
| 312 | if (input->filename) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 313 | snprintf(&buffer[len], sizeof(buffer) - len, "%s:%d: ", input->filename, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 314 | input->line); |
| 315 | } else { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 316 | snprintf(&buffer[len], sizeof(buffer) - len, "Entity: line %d: ", input->line); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | xmlHTMLEncodeSend(); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * xmlHTMLPrintFileContext: |
| 324 | * @input: an xmlParserInputPtr input |
| 325 | * |
| 326 | * Displays current context within the input content for error tracking |
| 327 | */ |
| 328 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 329 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 330 | xmlHTMLPrintFileContext(xmlParserInputPtr input) { |
| 331 | const xmlChar *cur, *base; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 332 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 333 | int n; |
| 334 | |
| 335 | if (input == NULL) return; |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 336 | xmlGenericError(xmlGenericErrorContext, "<pre>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 337 | cur = input->cur; |
| 338 | base = input->base; |
| 339 | while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { |
| 340 | cur--; |
| 341 | } |
| 342 | n = 0; |
| 343 | while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) |
| 344 | cur--; |
| 345 | if ((*cur == '\n') || (*cur == '\r')) cur++; |
| 346 | base = cur; |
| 347 | n = 0; |
| 348 | while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 349 | len = strlen(buffer); |
| 350 | snprintf(&buffer[len], sizeof(buffer) - len, "%c", |
| 351 | (unsigned char) *cur++); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 352 | n++; |
| 353 | } |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 354 | len = strlen(buffer); |
| 355 | snprintf(&buffer[len], sizeof(buffer) - len, "\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 356 | cur = input->cur; |
| 357 | while ((*cur == '\n') || (*cur == '\r')) |
| 358 | cur--; |
| 359 | n = 0; |
| 360 | while ((cur != base) && (n++ < 80)) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 361 | len = strlen(buffer); |
| 362 | snprintf(&buffer[len], sizeof(buffer) - len, " "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 363 | base++; |
| 364 | } |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 365 | len = strlen(buffer); |
| 366 | snprintf(&buffer[len], sizeof(buffer) - len, "^\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 367 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 368 | xmlGenericError(xmlGenericErrorContext, "</pre>"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /** |
| 372 | * xmlHTMLError: |
| 373 | * @ctx: an XML parser context |
| 374 | * @msg: the message to display/transmit |
| 375 | * @...: extra parameters for the message display |
| 376 | * |
| 377 | * Display and format an error messages, gives file, line, position and |
| 378 | * extra parameters. |
| 379 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 380 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 381 | xmlHTMLError(void *ctx, const char *msg, ...) |
| 382 | { |
| 383 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 384 | xmlParserInputPtr input; |
| 385 | xmlParserInputPtr cur = NULL; |
| 386 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 387 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 388 | |
| 389 | buffer[0] = 0; |
| 390 | input = ctxt->input; |
| 391 | if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { |
| 392 | cur = input; |
| 393 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 394 | } |
| 395 | |
| 396 | xmlHTMLPrintFileInfo(input); |
| 397 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 398 | xmlGenericError(xmlGenericErrorContext, "<b>error</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 399 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 400 | len = strlen(buffer); |
| 401 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 402 | va_end(args); |
| 403 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 404 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 405 | |
| 406 | xmlHTMLPrintFileContext(input); |
| 407 | xmlHTMLEncodeSend(); |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * xmlHTMLWarning: |
| 412 | * @ctx: an XML parser context |
| 413 | * @msg: the message to display/transmit |
| 414 | * @...: extra parameters for the message display |
| 415 | * |
| 416 | * Display and format a warning messages, gives file, line, position and |
| 417 | * extra parameters. |
| 418 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 419 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 420 | xmlHTMLWarning(void *ctx, const char *msg, ...) |
| 421 | { |
| 422 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 423 | xmlParserInputPtr input; |
| 424 | xmlParserInputPtr cur = NULL; |
| 425 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 426 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 427 | |
| 428 | buffer[0] = 0; |
| 429 | input = ctxt->input; |
| 430 | if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { |
| 431 | cur = input; |
| 432 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 433 | } |
| 434 | |
| 435 | |
| 436 | xmlHTMLPrintFileInfo(input); |
| 437 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 438 | xmlGenericError(xmlGenericErrorContext, "<b>warning</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 439 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 440 | len = strlen(buffer); |
| 441 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 442 | va_end(args); |
| 443 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 444 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 445 | |
| 446 | xmlHTMLPrintFileContext(input); |
| 447 | xmlHTMLEncodeSend(); |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * xmlHTMLValidityError: |
| 452 | * @ctx: an XML parser context |
| 453 | * @msg: the message to display/transmit |
| 454 | * @...: extra parameters for the message display |
| 455 | * |
| 456 | * Display and format an validity error messages, gives file, |
| 457 | * line, position and extra parameters. |
| 458 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 459 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 460 | xmlHTMLValidityError(void *ctx, const char *msg, ...) |
| 461 | { |
| 462 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 463 | xmlParserInputPtr input; |
| 464 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 465 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 466 | |
| 467 | buffer[0] = 0; |
| 468 | input = ctxt->input; |
| 469 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 470 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 471 | |
| 472 | xmlHTMLPrintFileInfo(input); |
| 473 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 474 | xmlGenericError(xmlGenericErrorContext, "<b>validity error</b>: "); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 475 | len = strlen(buffer); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 476 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 477 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 478 | va_end(args); |
| 479 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 480 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 481 | |
| 482 | xmlHTMLPrintFileContext(input); |
| 483 | xmlHTMLEncodeSend(); |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * xmlHTMLValidityWarning: |
| 488 | * @ctx: an XML parser context |
| 489 | * @msg: the message to display/transmit |
| 490 | * @...: extra parameters for the message display |
| 491 | * |
| 492 | * Display and format a validity warning messages, gives file, line, |
| 493 | * position and extra parameters. |
| 494 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 495 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 496 | xmlHTMLValidityWarning(void *ctx, const char *msg, ...) |
| 497 | { |
| 498 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 499 | xmlParserInputPtr input; |
| 500 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 501 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 502 | |
| 503 | buffer[0] = 0; |
| 504 | input = ctxt->input; |
| 505 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 506 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 507 | |
| 508 | xmlHTMLPrintFileInfo(input); |
| 509 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 510 | xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 511 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 512 | len = strlen(buffer); |
| 513 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 514 | va_end(args); |
| 515 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 516 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 517 | |
| 518 | xmlHTMLPrintFileContext(input); |
| 519 | xmlHTMLEncodeSend(); |
| 520 | } |
| 521 | |
| 522 | /************************************************************************ |
| 523 | * * |
| 524 | * Shell Interface * |
| 525 | * * |
| 526 | ************************************************************************/ |
Daniel Veillard | 56ada1d | 2003-01-07 11:17:25 +0000 | [diff] [blame] | 527 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 528 | /** |
| 529 | * xmlShellReadline: |
| 530 | * @prompt: the prompt value |
| 531 | * |
| 532 | * Read a string |
| 533 | * |
| 534 | * Returns a pointer to it or NULL on EOF the caller is expected to |
| 535 | * free the returned string. |
| 536 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 537 | static char * |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 538 | xmlShellReadline(char *prompt) { |
| 539 | #ifdef HAVE_LIBREADLINE |
| 540 | char *line_read; |
| 541 | |
| 542 | /* Get a line from the user. */ |
| 543 | line_read = readline (prompt); |
| 544 | |
| 545 | /* If the line has any text in it, save it on the history. */ |
| 546 | if (line_read && *line_read) |
| 547 | add_history (line_read); |
| 548 | |
| 549 | return (line_read); |
| 550 | #else |
| 551 | char line_read[501]; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 552 | char *ret; |
| 553 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 554 | |
| 555 | if (prompt != NULL) |
| 556 | fprintf(stdout, "%s", prompt); |
| 557 | if (!fgets(line_read, 500, stdin)) |
| 558 | return(NULL); |
| 559 | line_read[500] = 0; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 560 | len = strlen(line_read); |
| 561 | ret = (char *) malloc(len + 1); |
| 562 | if (ret != NULL) { |
| 563 | memcpy (ret, line_read, len + 1); |
| 564 | } |
| 565 | return(ret); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 566 | #endif |
| 567 | } |
Daniel Veillard | 56ada1d | 2003-01-07 11:17:25 +0000 | [diff] [blame] | 568 | #endif /* LIBXML_DEBUG_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 569 | |
| 570 | /************************************************************************ |
| 571 | * * |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 572 | * I/O Interfaces * |
| 573 | * * |
| 574 | ************************************************************************/ |
| 575 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 576 | static int myRead(FILE *f, char * buf, int len) { |
| 577 | return(fread(buf, 1, len, f)); |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 578 | } |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 579 | static void myClose(FILE *f) { |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 580 | if (f != stdin) { |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 581 | fclose(f); |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 582 | } |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /************************************************************************ |
| 586 | * * |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 587 | * Stream Test processing * |
| 588 | * * |
| 589 | ************************************************************************/ |
| 590 | static int count = 0; |
| 591 | static int elem, attrs; |
| 592 | |
| 593 | static void processNode(xmlTextReaderPtr reader) { |
Daniel Veillard | e59494f | 2003-01-04 16:35:29 +0000 | [diff] [blame] | 594 | xmlChar *name, *value; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 595 | |
Daniel Veillard | e59494f | 2003-01-04 16:35:29 +0000 | [diff] [blame] | 596 | name = xmlTextReaderName(reader); |
| 597 | if (name == NULL) |
| 598 | name = xmlStrdup(BAD_CAST "--"); |
Daniel Veillard | 99737f5 | 2003-03-22 14:55:50 +0000 | [diff] [blame] | 599 | |
Daniel Veillard | e59494f | 2003-01-04 16:35:29 +0000 | [diff] [blame] | 600 | value = xmlTextReaderValue(reader); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 601 | |
Daniel Veillard | 99737f5 | 2003-03-22 14:55:50 +0000 | [diff] [blame] | 602 | printf("%d %d %s %d %d", |
Daniel Veillard | e59494f | 2003-01-04 16:35:29 +0000 | [diff] [blame] | 603 | xmlTextReaderDepth(reader), |
| 604 | xmlTextReaderNodeType(reader), |
| 605 | name, |
Daniel Veillard | 99737f5 | 2003-03-22 14:55:50 +0000 | [diff] [blame] | 606 | xmlTextReaderIsEmptyElement(reader), |
| 607 | xmlTextReaderHasValue(reader)); |
Daniel Veillard | e59494f | 2003-01-04 16:35:29 +0000 | [diff] [blame] | 608 | xmlFree(name); |
| 609 | if (value == NULL) |
| 610 | printf("\n"); |
| 611 | else { |
| 612 | printf(" %s\n", value); |
| 613 | xmlFree(value); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
| 617 | static void streamFile(char *filename) { |
| 618 | xmlTextReaderPtr reader; |
| 619 | int ret; |
| 620 | |
| 621 | if (count) { |
| 622 | elem = 0; |
| 623 | attrs = 0; |
| 624 | } |
| 625 | |
| 626 | reader = xmlNewTextReaderFilename(filename); |
| 627 | if (reader != NULL) { |
| 628 | if (valid) |
| 629 | xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1); |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 630 | else |
| 631 | xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1); |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 632 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 633 | if (relaxng != NULL) { |
| 634 | if (timing) { |
| 635 | startTimer(); |
| 636 | } |
| 637 | ret = xmlTextReaderRelaxNGValidate(reader, relaxng); |
| 638 | if (ret < 0) { |
| 639 | xmlGenericError(xmlGenericErrorContext, |
| 640 | "Relax-NG schema %s failed to compile\n", relaxng); |
| 641 | relaxng = NULL; |
| 642 | } |
| 643 | if (timing) { |
| 644 | endTimer("Compiling the schemas"); |
| 645 | } |
| 646 | } |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 647 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 648 | |
| 649 | /* |
| 650 | * Process all nodes in sequence |
| 651 | */ |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 652 | if (timing) { |
| 653 | startTimer(); |
| 654 | } |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 655 | ret = xmlTextReaderRead(reader); |
| 656 | while (ret == 1) { |
| 657 | if (debug) |
| 658 | processNode(reader); |
| 659 | ret = xmlTextReaderRead(reader); |
| 660 | } |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 661 | if (timing) { |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 662 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 663 | if ((valid) || (relaxng != NULL)) |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 664 | #else |
| 665 | if (valid) |
| 666 | #endif |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 667 | endTimer("Parsing and validating"); |
| 668 | else |
| 669 | endTimer("Parsing"); |
| 670 | } |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 671 | |
Daniel Veillard | f6bad79 | 2003-04-11 19:38:54 +0000 | [diff] [blame] | 672 | if (valid) { |
| 673 | if (xmlTextReaderIsValid(reader) != 1) { |
| 674 | xmlGenericError(xmlGenericErrorContext, |
| 675 | "Document %s does not validate\n", filename); |
| 676 | progresult = 3; |
| 677 | } |
| 678 | } |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 679 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 680 | if (relaxng != NULL) { |
| 681 | if (xmlTextReaderIsValid(reader) != 1) { |
| 682 | printf("%s fails to validate\n", filename); |
| 683 | progresult = 3; |
| 684 | } else { |
| 685 | printf("%s validates\n", filename); |
| 686 | } |
| 687 | } |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 688 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 689 | /* |
| 690 | * Done, cleanup and status |
| 691 | */ |
| 692 | xmlFreeTextReader(reader); |
| 693 | if (ret != 0) { |
| 694 | printf("%s : failed to parse\n", filename); |
Daniel Veillard | f6bad79 | 2003-04-11 19:38:54 +0000 | [diff] [blame] | 695 | progresult = 1; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 696 | } |
| 697 | } else { |
| 698 | fprintf(stderr, "Unable to open %s\n", filename); |
Daniel Veillard | f6bad79 | 2003-04-11 19:38:54 +0000 | [diff] [blame] | 699 | progresult = 1; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
| 703 | /************************************************************************ |
| 704 | * * |
| 705 | * Tree Test processing * |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 706 | * * |
| 707 | ************************************************************************/ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 708 | static void parseAndPrintFile(char *filename) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 709 | xmlDocPtr doc = NULL, tmp; |
| 710 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 711 | if ((timing) && (!repeat)) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 712 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 713 | |
| 714 | |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 715 | if (filename == NULL) { |
| 716 | if (generate) { |
| 717 | xmlNodePtr n; |
| 718 | |
| 719 | doc = xmlNewDoc(BAD_CAST "1.0"); |
| 720 | n = xmlNewNode(NULL, BAD_CAST "info"); |
| 721 | xmlNodeSetContent(n, BAD_CAST "abc"); |
| 722 | xmlDocSetRootElement(doc, n); |
| 723 | } |
| 724 | } |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 725 | #ifdef LIBXML_DOCB_ENABLED |
| 726 | /* |
| 727 | * build an SGML tree from a string; |
| 728 | */ |
| 729 | else if ((sgml) && (push)) { |
| 730 | FILE *f; |
| 731 | |
| 732 | f = fopen(filename, "r"); |
| 733 | if (f != NULL) { |
| 734 | int res, size = 3; |
| 735 | char chars[4096]; |
| 736 | docbParserCtxtPtr ctxt; |
| 737 | |
| 738 | /* if (repeat) */ |
| 739 | size = 4096; |
| 740 | res = fread(chars, 1, 4, f); |
| 741 | if (res > 0) { |
| 742 | ctxt = docbCreatePushParserCtxt(NULL, NULL, |
| 743 | chars, res, filename, 0); |
| 744 | while ((res = fread(chars, 1, size, f)) > 0) { |
| 745 | docbParseChunk(ctxt, chars, res, 0); |
| 746 | } |
| 747 | docbParseChunk(ctxt, chars, 0, 1); |
| 748 | doc = ctxt->myDoc; |
| 749 | docbFreeParserCtxt(ctxt); |
| 750 | } |
| 751 | fclose(f); |
| 752 | } |
| 753 | } else if (sgml) { |
| 754 | doc = docbParseFile(filename, NULL); |
| 755 | } |
| 756 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 757 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 758 | else if (html) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 759 | doc = htmlParseFile(filename, NULL); |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 760 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 761 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 762 | else { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 763 | /* |
| 764 | * build an XML tree from a string; |
| 765 | */ |
| 766 | if (push) { |
| 767 | FILE *f; |
| 768 | |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 769 | /* '-' Usually means stdin -<sven@zen.org> */ |
| 770 | if ((filename[0] == '-') && (filename[1] == 0)) { |
| 771 | f = stdin; |
| 772 | } else { |
| 773 | f = fopen(filename, "r"); |
| 774 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 775 | if (f != NULL) { |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 776 | int ret; |
Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 777 | int res, size = 1024; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 778 | char chars[1024]; |
| 779 | xmlParserCtxtPtr ctxt; |
| 780 | |
Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 781 | /* if (repeat) size = 1024; */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 782 | res = fread(chars, 1, 4, f); |
| 783 | if (res > 0) { |
| 784 | ctxt = xmlCreatePushParserCtxt(NULL, NULL, |
| 785 | chars, res, filename); |
| 786 | while ((res = fread(chars, 1, size, f)) > 0) { |
| 787 | xmlParseChunk(ctxt, chars, res, 0); |
| 788 | } |
| 789 | xmlParseChunk(ctxt, chars, 0, 1); |
| 790 | doc = ctxt->myDoc; |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 791 | ret = ctxt->wellFormed; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 792 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 793 | if (!ret) { |
| 794 | xmlFreeDoc(doc); |
| 795 | doc = NULL; |
| 796 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 797 | } |
| 798 | } |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 799 | } else if (testIO) { |
| 800 | int ret; |
| 801 | FILE *f; |
| 802 | |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 803 | /* '-' Usually means stdin -<sven@zen.org> */ |
| 804 | if ((filename[0] == '-') && (filename[1] == 0)) { |
| 805 | f = stdin; |
| 806 | } else { |
| 807 | f = fopen(filename, "r"); |
| 808 | } |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 809 | if (f != NULL) { |
| 810 | xmlParserCtxtPtr ctxt; |
| 811 | |
| 812 | ctxt = xmlCreateIOParserCtxt(NULL, NULL, |
| 813 | (xmlInputReadCallback) myRead, |
| 814 | (xmlInputCloseCallback) myClose, |
| 815 | f, XML_CHAR_ENCODING_NONE); |
| 816 | xmlParseDocument(ctxt); |
| 817 | |
| 818 | ret = ctxt->wellFormed; |
| 819 | doc = ctxt->myDoc; |
| 820 | xmlFreeParserCtxt(ctxt); |
| 821 | if (!ret) { |
| 822 | xmlFreeDoc(doc); |
| 823 | doc = NULL; |
| 824 | } |
| 825 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 826 | } else if (recovery) { |
| 827 | doc = xmlRecoverFile(filename); |
| 828 | } else if (htmlout) { |
| 829 | int ret; |
| 830 | xmlParserCtxtPtr ctxt; |
| 831 | xmlSAXHandler silent, *old; |
| 832 | |
| 833 | ctxt = xmlCreateFileParserCtxt(filename); |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 834 | |
| 835 | if (ctxt == NULL) { |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 836 | /* If xmlCreateFileParserCtxt() return NULL something |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 837 | strange happened so we don't want to do anything. Do |
| 838 | we want to print an error message here? |
| 839 | <sven@zen.org> */ |
Daniel Veillard | 7ebb1ee | 2000-08-04 18:24:45 +0000 | [diff] [blame] | 840 | doc = NULL; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 841 | } else { |
| 842 | memcpy(&silent, ctxt->sax, sizeof(silent)); |
| 843 | old = ctxt->sax; |
| 844 | silent.error = xmlHTMLError; |
| 845 | if (xmlGetWarningsDefaultValue) |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 846 | silent.warning = xmlHTMLWarning; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 847 | else |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 848 | silent.warning = NULL; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 849 | silent.fatalError = xmlHTMLError; |
| 850 | ctxt->sax = &silent; |
| 851 | ctxt->vctxt.error = xmlHTMLValidityError; |
| 852 | if (xmlGetWarningsDefaultValue) |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 853 | ctxt->vctxt.warning = xmlHTMLValidityWarning; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 854 | else |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 855 | ctxt->vctxt.warning = NULL; |
| 856 | |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 857 | xmlParseDocument(ctxt); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 858 | |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 859 | ret = ctxt->wellFormed; |
| 860 | doc = ctxt->myDoc; |
| 861 | ctxt->sax = old; |
| 862 | xmlFreeParserCtxt(ctxt); |
| 863 | if (!ret) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 864 | xmlFreeDoc(doc); |
| 865 | doc = NULL; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 866 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 867 | } |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 868 | #ifdef HAVE_SYS_MMAN_H |
| 869 | } else if (memory) { |
| 870 | int fd; |
| 871 | struct stat info; |
| 872 | const char *base; |
| 873 | if (stat(filename, &info) < 0) |
| 874 | return; |
| 875 | if ((fd = open(filename, O_RDONLY)) < 0) |
| 876 | return; |
| 877 | base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; |
Daniel Veillard | 2957936 | 2000-08-14 17:57:48 +0000 | [diff] [blame] | 878 | if (base == (void *) MAP_FAILED) |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 879 | return; |
| 880 | |
| 881 | doc = xmlParseMemory((char *) base, info.st_size); |
| 882 | munmap((char *) base, info.st_size); |
| 883 | #endif |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 884 | } else if (valid) { |
| 885 | int ret; |
| 886 | xmlParserCtxtPtr ctxt; |
| 887 | |
| 888 | ctxt = xmlCreateFileParserCtxt(filename); |
| 889 | |
| 890 | if (ctxt == NULL) { |
| 891 | doc = NULL; |
| 892 | } else { |
| 893 | xmlParseDocument(ctxt); |
| 894 | if (ctxt->valid == 0) |
| 895 | progresult = 4; |
| 896 | ret = ctxt->wellFormed; |
| 897 | doc = ctxt->myDoc; |
| 898 | xmlFreeParserCtxt(ctxt); |
| 899 | if (!ret) { |
| 900 | xmlFreeDoc(doc); |
| 901 | doc = NULL; |
| 902 | } |
| 903 | } |
| 904 | } else { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 905 | doc = xmlParseFile(filename); |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 906 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 907 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 908 | |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 909 | /* |
| 910 | * If we don't have a document we might as well give up. Do we |
| 911 | * want an error message here? <sven@zen.org> */ |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 912 | if (doc == NULL) { |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 913 | progresult = 1; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 914 | return; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 917 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 918 | endTimer("Parsing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 921 | /* |
| 922 | * Remove DOCTYPE nodes |
| 923 | */ |
| 924 | if (dropdtd) { |
| 925 | xmlDtdPtr dtd; |
| 926 | |
| 927 | dtd = xmlGetIntSubset(doc); |
| 928 | if (dtd != NULL) { |
| 929 | xmlUnlinkNode((xmlNodePtr)dtd); |
| 930 | xmlFreeDtd(dtd); |
| 931 | } |
| 932 | } |
| 933 | |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 934 | #ifdef LIBXML_XINCLUDE_ENABLED |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 935 | if (xinclude) { |
| 936 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 937 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 938 | } |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 939 | xmlXIncludeProcess(doc); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 940 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 941 | endTimer("Xinclude processing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 942 | } |
| 943 | } |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 944 | #endif |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 945 | |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 946 | #ifdef LIBXML_DEBUG_ENABLED |
| 947 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 948 | * shell interaction |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 949 | */ |
| 950 | if (shell) |
| 951 | xmlShell(doc, filename, xmlShellReadline, stdout); |
| 952 | #endif |
| 953 | |
| 954 | /* |
| 955 | * test intermediate copy if needed. |
| 956 | */ |
| 957 | if (copy) { |
| 958 | tmp = doc; |
| 959 | doc = xmlCopyDoc(doc, 1); |
| 960 | xmlFreeDoc(tmp); |
| 961 | } |
| 962 | |
| 963 | if ((insert) && (!html)) { |
| 964 | const xmlChar* list[256]; |
| 965 | int nb, i; |
| 966 | xmlNodePtr node; |
| 967 | |
| 968 | if (doc->children != NULL) { |
| 969 | node = doc->children; |
| 970 | while ((node != NULL) && (node->last == NULL)) node = node->next; |
| 971 | if (node != NULL) { |
| 972 | nb = xmlValidGetValidElements(node->last, NULL, list, 256); |
| 973 | if (nb < 0) { |
| 974 | printf("could not get valid list of elements\n"); |
| 975 | } else if (nb == 0) { |
MDT 2001 John Fleck | bbb9e43 | 2001-09-24 03:08:43 +0000 | [diff] [blame] | 976 | printf("No element can be inserted under root\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 977 | } else { |
MDT 2001 John Fleck | bbb9e43 | 2001-09-24 03:08:43 +0000 | [diff] [blame] | 978 | printf("%d element types can be inserted under root:\n", |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 979 | nb); |
| 980 | for (i = 0;i < nb;i++) { |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 981 | printf("%s\n", (char *) list[i]); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | }else if (noout == 0) { |
| 987 | /* |
| 988 | * print it. |
| 989 | */ |
| 990 | #ifdef LIBXML_DEBUG_ENABLED |
| 991 | if (!debug) { |
| 992 | #endif |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 993 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 994 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 995 | } |
Daniel Veillard | 3b2c261 | 2001-04-04 00:09:00 +0000 | [diff] [blame] | 996 | #ifdef HAVE_SYS_MMAN_H |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 997 | if (memory) { |
| 998 | xmlChar *result; |
| 999 | int len; |
| 1000 | |
| 1001 | if (encoding != NULL) { |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 1002 | if ( format ) { |
| 1003 | xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1); |
| 1004 | } else { |
| 1005 | xmlDocDumpMemoryEnc(doc, &result, &len, encoding); |
| 1006 | } |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 1007 | } else { |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 1008 | if (format) |
| 1009 | xmlDocDumpFormatMemory(doc, &result, &len, 1); |
| 1010 | else |
| 1011 | xmlDocDumpMemory(doc, &result, &len); |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 1012 | } |
| 1013 | if (result == NULL) { |
| 1014 | fprintf(stderr, "Failed to save\n"); |
| 1015 | } else { |
| 1016 | write(1, result, len); |
| 1017 | xmlFree(result); |
| 1018 | } |
Daniel Veillard | 3b2c261 | 2001-04-04 00:09:00 +0000 | [diff] [blame] | 1019 | } else |
| 1020 | #endif /* HAVE_SYS_MMAN_H */ |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1021 | if (compress) { |
| 1022 | xmlSaveFile(output ? output : "-", doc); |
| 1023 | } |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 1024 | else if (encoding != NULL) { |
| 1025 | if ( format ) { |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1026 | xmlSaveFormatFileEnc(output ? output : "-", doc, encoding, 1); |
| 1027 | } |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 1028 | else { |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1029 | xmlSaveFileEnc(output ? output : "-", doc, encoding); |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 1030 | } |
| 1031 | } |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1032 | else if (format) { |
| 1033 | xmlSaveFormatFile(output ? output : "-", doc, 1); |
| 1034 | } |
| 1035 | else { |
| 1036 | FILE *out; |
| 1037 | if (output == NULL) |
| 1038 | out = stdout; |
| 1039 | else { |
| 1040 | out = fopen(output,"wb"); |
| 1041 | } |
| 1042 | xmlDocDump(out, doc); |
| 1043 | |
| 1044 | if (output) |
| 1045 | fclose(out); |
| 1046 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1047 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1048 | endTimer("Saving"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1049 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1050 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 1051 | } else { |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1052 | FILE *out; |
| 1053 | if (output == NULL) |
| 1054 | out = stdout; |
| 1055 | else { |
| 1056 | out = fopen(output,"wb"); |
| 1057 | } |
| 1058 | xmlDebugDumpDocument(out, doc); |
| 1059 | |
| 1060 | if (output) |
| 1061 | fclose(out); |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 1062 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1063 | #endif |
| 1064 | } |
| 1065 | |
| 1066 | /* |
| 1067 | * A posteriori validation test |
| 1068 | */ |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1069 | if (dtdvalid != NULL) { |
| 1070 | xmlDtdPtr dtd; |
| 1071 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1072 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1073 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1074 | } |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1075 | dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1076 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1077 | endTimer("Parsing DTD"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1078 | } |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1079 | if (dtd == NULL) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1080 | xmlGenericError(xmlGenericErrorContext, |
| 1081 | "Could not parse DTD %s\n", dtdvalid); |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 1082 | progresult = 2; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1083 | } else { |
| 1084 | xmlValidCtxt cvp; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1085 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1086 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1087 | } |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1088 | cvp.userData = (void *) stderr; |
| 1089 | cvp.error = (xmlValidityErrorFunc) fprintf; |
| 1090 | cvp.warning = (xmlValidityWarningFunc) fprintf; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1091 | if (!xmlValidateDtd(&cvp, doc, dtd)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1092 | xmlGenericError(xmlGenericErrorContext, |
| 1093 | "Document %s does not validate against %s\n", |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1094 | filename, dtdvalid); |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 1095 | progresult = 3; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1096 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1097 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1098 | endTimer("Validating against DTD"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1099 | } |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1100 | xmlFreeDtd(dtd); |
| 1101 | } |
| 1102 | } else if (postvalid) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1103 | xmlValidCtxt cvp; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1104 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1105 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1106 | } |
Daniel Veillard | b7664f4 | 2001-08-19 13:00:43 +0000 | [diff] [blame] | 1107 | cvp.userData = (void *) stderr; |
| 1108 | cvp.error = (xmlValidityErrorFunc) fprintf; |
| 1109 | cvp.warning = (xmlValidityWarningFunc) fprintf; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1110 | if (!xmlValidateDocument(&cvp, doc)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1111 | xmlGenericError(xmlGenericErrorContext, |
| 1112 | "Document %s does not validate\n", filename); |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 1113 | progresult = 3; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1114 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1115 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1116 | endTimer("Validating"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1117 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1118 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 1119 | } else if (relaxngschemas != NULL) { |
| 1120 | xmlRelaxNGValidCtxtPtr ctxt; |
| 1121 | int ret; |
| 1122 | |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 1123 | if ((timing) && (!repeat)) { |
| 1124 | startTimer(); |
| 1125 | } |
| 1126 | |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1127 | ctxt = xmlRelaxNGNewValidCtxt(relaxngschemas); |
| 1128 | xmlRelaxNGSetValidErrors(ctxt, |
| 1129 | (xmlRelaxNGValidityErrorFunc) fprintf, |
| 1130 | (xmlRelaxNGValidityWarningFunc) fprintf, |
| 1131 | stderr); |
| 1132 | ret = xmlRelaxNGValidateDoc(ctxt, doc); |
| 1133 | if (ret == 0) { |
| 1134 | printf("%s validates\n", filename); |
| 1135 | } else if (ret > 0) { |
| 1136 | printf("%s fails to validate\n", filename); |
| 1137 | } else { |
| 1138 | printf("%s validation generated an internal error\n", |
| 1139 | filename); |
| 1140 | } |
| 1141 | xmlRelaxNGFreeValidCtxt(ctxt); |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 1142 | if ((timing) && (!repeat)) { |
| 1143 | endTimer("Validating"); |
| 1144 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1145 | } else if (wxschemas != NULL) { |
| 1146 | xmlSchemaValidCtxtPtr ctxt; |
| 1147 | int ret; |
| 1148 | |
| 1149 | if ((timing) && (!repeat)) { |
| 1150 | startTimer(); |
| 1151 | } |
| 1152 | |
| 1153 | ctxt = xmlSchemaNewValidCtxt(wxschemas); |
| 1154 | xmlSchemaSetValidErrors(ctxt, |
| 1155 | (xmlSchemaValidityErrorFunc) fprintf, |
| 1156 | (xmlSchemaValidityWarningFunc) fprintf, |
| 1157 | stderr); |
| 1158 | ret = xmlSchemaValidateDoc(ctxt, doc); |
| 1159 | if (ret == 0) { |
| 1160 | printf("%s validates\n", filename); |
| 1161 | } else if (ret > 0) { |
| 1162 | printf("%s fails to validate\n", filename); |
| 1163 | } else { |
| 1164 | printf("%s validation generated an internal error\n", |
| 1165 | filename); |
| 1166 | } |
| 1167 | xmlSchemaFreeValidCtxt(ctxt); |
| 1168 | if ((timing) && (!repeat)) { |
| 1169 | endTimer("Validating"); |
| 1170 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1171 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | #ifdef LIBXML_DEBUG_ENABLED |
| 1175 | if ((debugent) && (!html)) |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1176 | xmlDebugDumpEntities(stderr, doc); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1177 | #endif |
| 1178 | |
| 1179 | /* |
| 1180 | * free it. |
| 1181 | */ |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1182 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1183 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1184 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1185 | xmlFreeDoc(doc); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1186 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1187 | endTimer("Freeing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1188 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1191 | /************************************************************************ |
| 1192 | * * |
| 1193 | * Usage and Main * |
| 1194 | * * |
| 1195 | ************************************************************************/ |
| 1196 | |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 1197 | static void showVersion(const char *name) { |
| 1198 | fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion); |
| 1199 | fprintf(stderr, " compiled with: "); |
| 1200 | #ifdef LIBXML_FTP_ENABLED |
| 1201 | fprintf(stderr, "FTP "); |
| 1202 | #endif |
| 1203 | #ifdef LIBXML_HTTP_ENABLED |
| 1204 | fprintf(stderr, "HTTP "); |
| 1205 | #endif |
| 1206 | #ifdef LIBXML_HTML_ENABLED |
| 1207 | fprintf(stderr, "HTML "); |
| 1208 | #endif |
| 1209 | #ifdef LIBXML_C14N_ENABLED |
| 1210 | fprintf(stderr, "C14N "); |
| 1211 | #endif |
| 1212 | #ifdef LIBXML_CATALOG_ENABLED |
| 1213 | fprintf(stderr, "Catalog "); |
| 1214 | #endif |
| 1215 | #ifdef LIBXML_DOCB_ENABLED |
| 1216 | fprintf(stderr, "DocBook "); |
| 1217 | #endif |
| 1218 | #ifdef LIBXML_XPATH_ENABLED |
| 1219 | fprintf(stderr, "XPath "); |
| 1220 | #endif |
| 1221 | #ifdef LIBXML_XPTR_ENABLED |
| 1222 | fprintf(stderr, "XPointer "); |
| 1223 | #endif |
| 1224 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 1225 | fprintf(stderr, "XInclude "); |
| 1226 | #endif |
| 1227 | #ifdef LIBXML_ICONV_ENABLED |
| 1228 | fprintf(stderr, "Iconv "); |
| 1229 | #endif |
| 1230 | #ifdef DEBUG_MEMORY_LOCATION |
| 1231 | fprintf(stderr, "MemDebug "); |
| 1232 | #endif |
| 1233 | #ifdef LIBXML_UNICODE_ENABLED |
| 1234 | fprintf(stderr, "Unicode "); |
| 1235 | #endif |
| 1236 | #ifdef LIBXML_REGEXP_ENABLED |
| 1237 | fprintf(stderr, "Regexps "); |
| 1238 | #endif |
| 1239 | #ifdef LIBXML_AUTOMATA_ENABLED |
| 1240 | fprintf(stderr, "Automata "); |
| 1241 | #endif |
| 1242 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 1243 | fprintf(stderr, "Schemas "); |
| 1244 | #endif |
| 1245 | fprintf(stderr, "\n"); |
| 1246 | } |
| 1247 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1248 | static void usage(const char *name) { |
| 1249 | printf("Usage : %s [options] XMLfiles ...\n", name); |
| 1250 | printf("\tParse the XML files and output the result of the parsing\n"); |
| 1251 | printf("\t--version : display the version of the XML library used\n"); |
| 1252 | #ifdef LIBXML_DEBUG_ENABLED |
| 1253 | printf("\t--debug : dump a debug tree of the in-memory document\n"); |
| 1254 | printf("\t--shell : run a navigating shell\n"); |
| 1255 | printf("\t--debugent : debug the entities defined in the document\n"); |
Daniel Veillard | 8326e73 | 2003-01-07 00:19:07 +0000 | [diff] [blame] | 1256 | #else |
| 1257 | printf("\t--debug : dump the nodes content when using --stream\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1258 | #endif |
| 1259 | printf("\t--copy : used to test the internal copy implementation\n"); |
| 1260 | printf("\t--recover : output what was parsable on broken XML documents\n"); |
| 1261 | printf("\t--noent : substitute entity references by their value\n"); |
| 1262 | printf("\t--noout : don't output the result tree\n"); |
Daniel Veillard | e8b09e4 | 2003-05-13 22:14:13 +0000 | [diff] [blame] | 1263 | printf("\t--nonet : refuse to fetch DTDs or entities over network\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1264 | printf("\t--htmlout : output results as HTML\n"); |
Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 1265 | printf("\t--nowrap : do not put HTML doc wrapper\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1266 | printf("\t--valid : validate the document in addition to std well-formed check\n"); |
| 1267 | printf("\t--postvalid : do a posteriori validation, i.e after parsing\n"); |
| 1268 | printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n"); |
| 1269 | printf("\t--timing : print some timings\n"); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1270 | printf("\t--output file or -o file: save to a given file\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1271 | printf("\t--repeat : repeat 100 times, for timing or profiling\n"); |
| 1272 | printf("\t--insert : ad-hoc test for valid insertions\n"); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1273 | #ifdef HAVE_ZLIB_H |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1274 | printf("\t--compress : turn on gzip compression of output\n"); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1275 | #endif |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 1276 | #ifdef LIBXML_DOCB_ENABLED |
| 1277 | printf("\t--sgml : use the DocBook SGML parser\n"); |
| 1278 | #endif |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1279 | #ifdef LIBXML_HTML_ENABLED |
| 1280 | printf("\t--html : use the HTML parser\n"); |
| 1281 | #endif |
| 1282 | printf("\t--push : use the push mode of the parser\n"); |
| 1283 | #ifdef HAVE_SYS_MMAN_H |
| 1284 | printf("\t--memory : parse from memory\n"); |
| 1285 | #endif |
| 1286 | printf("\t--nowarning : do not emit warnings from parser/validator\n"); |
| 1287 | printf("\t--noblanks : drop (ignorable?) blanks spaces\n"); |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 1288 | printf("\t--format : reformat/reindent the input\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1289 | printf("\t--testIO : test user I/O support\n"); |
| 1290 | printf("\t--encode encoding : output in the given encoding\n"); |
| 1291 | #ifdef LIBXML_CATALOG_ENABLED |
Daniel Veillard | bd9b0e8 | 2001-11-26 10:32:08 +0000 | [diff] [blame] | 1292 | printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n"); |
| 1293 | printf("\t otherwise XML Catalogs starting from \n"); |
Daniel Veillard | 3be2751 | 2003-01-26 19:49:04 +0000 | [diff] [blame] | 1294 | printf("\t " XML_XML_DEFAULT_CATALOG " are activated by default\n"); |
Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 1295 | printf("\t--nocatalogs: deactivate all catalogs\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1296 | #endif |
| 1297 | printf("\t--auto : generate a small doc on the fly\n"); |
| 1298 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 1299 | printf("\t--xinclude : do XInclude processing\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1300 | #endif |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1301 | printf("\t--loaddtd : fetch external DTD\n"); |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 1302 | printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n"); |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 1303 | printf("\t--dropdtd : remove the DOCTYPE of the input docs\n"); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1304 | printf("\t--stream : use the streaming interface to process very large files\n"); |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1305 | printf("\t--chkregister : verify the node registration code\n"); |
Daniel Veillard | ef4d3bc | 2003-02-07 12:38:22 +0000 | [diff] [blame] | 1306 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1307 | printf("\t--relaxng schema : do RelaxNG validation against the schema\n"); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1308 | printf("\t--schema schema : do validation against the WXS schema\n"); |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1309 | #endif |
Daniel Veillard | a42f25f | 2002-01-25 14:15:40 +0000 | [diff] [blame] | 1310 | printf("\nLibxml project home page: http://xmlsoft.org/\n"); |
| 1311 | printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1312 | } |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1313 | |
| 1314 | static void registerNode(xmlNodePtr node) |
| 1315 | { |
| 1316 | node->_private = malloc(sizeof(long)); |
| 1317 | *(long*)node->_private = (long) 0x81726354; |
| 1318 | } |
| 1319 | |
| 1320 | static void deregisterNode(xmlNodePtr node) |
| 1321 | { |
| 1322 | assert(node->_private != NULL); |
| 1323 | assert(*(long*)node->_private == (long) 0x81726354); |
| 1324 | free(node->_private); |
| 1325 | } |
| 1326 | |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 1327 | int |
| 1328 | main(int argc, char **argv) { |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1329 | int i, acount; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1330 | int files = 0; |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 1331 | int version = 0; |
Aleksey Sanin | 693c9bc | 2003-03-09 22:36:52 +0000 | [diff] [blame] | 1332 | const char* indent; |
| 1333 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1334 | if (argc <= 1) { |
| 1335 | usage(argv[0]); |
| 1336 | return(1); |
| 1337 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1338 | LIBXML_TEST_VERSION |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1339 | for (i = 1; i < argc ; i++) { |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1340 | if (!strcmp(argv[i], "-")) |
| 1341 | break; |
| 1342 | |
| 1343 | if (argv[i][0] != '-') |
| 1344 | continue; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1345 | if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) |
| 1346 | debug++; |
Daniel Veillard | 56ada1d | 2003-01-07 11:17:25 +0000 | [diff] [blame] | 1347 | else |
| 1348 | #ifdef LIBXML_DEBUG_ENABLED |
| 1349 | if ((!strcmp(argv[i], "-shell")) || |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1350 | (!strcmp(argv[i], "--shell"))) { |
| 1351 | shell++; |
| 1352 | noout = 1; |
| 1353 | } else |
| 1354 | #endif |
| 1355 | if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) |
| 1356 | copy++; |
| 1357 | else if ((!strcmp(argv[i], "-recover")) || |
| 1358 | (!strcmp(argv[i], "--recover"))) |
| 1359 | recovery++; |
| 1360 | else if ((!strcmp(argv[i], "-noent")) || |
| 1361 | (!strcmp(argv[i], "--noent"))) |
| 1362 | noent++; |
Daniel Veillard | 4ec885a | 2001-06-17 10:31:07 +0000 | [diff] [blame] | 1363 | else if ((!strcmp(argv[i], "-version")) || |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 1364 | (!strcmp(argv[i], "--version"))) { |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 1365 | showVersion(argv[0]); |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 1366 | version = 1; |
| 1367 | } else if ((!strcmp(argv[i], "-noout")) || |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1368 | (!strcmp(argv[i], "--noout"))) |
| 1369 | noout++; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1370 | else if ((!strcmp(argv[i], "-o")) || |
| 1371 | (!strcmp(argv[i], "-output")) || |
| 1372 | (!strcmp(argv[i], "--output"))) { |
| 1373 | i++; |
Daniel Veillard | 6e4f1c0 | 2002-04-09 09:55:20 +0000 | [diff] [blame] | 1374 | output = argv[i]; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1375 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1376 | else if ((!strcmp(argv[i], "-htmlout")) || |
| 1377 | (!strcmp(argv[i], "--htmlout"))) |
| 1378 | htmlout++; |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 1379 | #ifdef LIBXML_DOCB_ENABLED |
| 1380 | else if ((!strcmp(argv[i], "-sgml")) || |
| 1381 | (!strcmp(argv[i], "--sgml"))) { |
| 1382 | sgml++; |
| 1383 | } |
| 1384 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1385 | #ifdef LIBXML_HTML_ENABLED |
| 1386 | else if ((!strcmp(argv[i], "-html")) || |
| 1387 | (!strcmp(argv[i], "--html"))) { |
| 1388 | html++; |
| 1389 | } |
| 1390 | #endif /* LIBXML_HTML_ENABLED */ |
| 1391 | else if ((!strcmp(argv[i], "-nowrap")) || |
| 1392 | (!strcmp(argv[i], "--nowrap"))) |
| 1393 | nowrap++; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1394 | else if ((!strcmp(argv[i], "-loaddtd")) || |
| 1395 | (!strcmp(argv[i], "--loaddtd"))) |
| 1396 | loaddtd++; |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 1397 | else if ((!strcmp(argv[i], "-dtdattr")) || |
| 1398 | (!strcmp(argv[i], "--dtdattr"))) { |
| 1399 | loaddtd++; |
| 1400 | dtdattrs++; |
| 1401 | } else if ((!strcmp(argv[i], "-valid")) || |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1402 | (!strcmp(argv[i], "--valid"))) |
| 1403 | valid++; |
| 1404 | else if ((!strcmp(argv[i], "-postvalid")) || |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1405 | (!strcmp(argv[i], "--postvalid"))) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1406 | postvalid++; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1407 | loaddtd++; |
| 1408 | } else if ((!strcmp(argv[i], "-dtdvalid")) || |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1409 | (!strcmp(argv[i], "--dtdvalid"))) { |
| 1410 | i++; |
| 1411 | dtdvalid = argv[i]; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1412 | loaddtd++; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1413 | } |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 1414 | else if ((!strcmp(argv[i], "-dropdtd")) || |
| 1415 | (!strcmp(argv[i], "--dropdtd"))) |
| 1416 | dropdtd++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1417 | else if ((!strcmp(argv[i], "-insert")) || |
| 1418 | (!strcmp(argv[i], "--insert"))) |
| 1419 | insert++; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1420 | else if ((!strcmp(argv[i], "-timing")) || |
| 1421 | (!strcmp(argv[i], "--timing"))) |
| 1422 | timing++; |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 1423 | else if ((!strcmp(argv[i], "-auto")) || |
| 1424 | (!strcmp(argv[i], "--auto"))) |
| 1425 | generate++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1426 | else if ((!strcmp(argv[i], "-repeat")) || |
| 1427 | (!strcmp(argv[i], "--repeat"))) |
| 1428 | repeat++; |
| 1429 | else if ((!strcmp(argv[i], "-push")) || |
| 1430 | (!strcmp(argv[i], "--push"))) |
| 1431 | push++; |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 1432 | #ifdef HAVE_SYS_MMAN_H |
| 1433 | else if ((!strcmp(argv[i], "-memory")) || |
| 1434 | (!strcmp(argv[i], "--memory"))) |
| 1435 | memory++; |
| 1436 | #endif |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 1437 | else if ((!strcmp(argv[i], "-testIO")) || |
| 1438 | (!strcmp(argv[i], "--testIO"))) |
| 1439 | testIO++; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 1440 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 1441 | else if ((!strcmp(argv[i], "-xinclude")) || |
| 1442 | (!strcmp(argv[i], "--xinclude"))) |
| 1443 | xinclude++; |
| 1444 | #endif |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1445 | #ifdef HAVE_ZLIB_H |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1446 | else if ((!strcmp(argv[i], "-compress")) || |
| 1447 | (!strcmp(argv[i], "--compress"))) { |
| 1448 | compress++; |
| 1449 | xmlSetCompressMode(9); |
| 1450 | } |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1451 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1452 | else if ((!strcmp(argv[i], "-nowarning")) || |
| 1453 | (!strcmp(argv[i], "--nowarning"))) { |
| 1454 | xmlGetWarningsDefaultValue = 0; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1455 | xmlPedanticParserDefault(0); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1456 | } |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1457 | else if ((!strcmp(argv[i], "-pedantic")) || |
| 1458 | (!strcmp(argv[i], "--pedantic"))) { |
| 1459 | xmlGetWarningsDefaultValue = 1; |
| 1460 | xmlPedanticParserDefault(1); |
| 1461 | } |
Daniel Veillard | 64c20ed | 2000-09-22 16:07:02 +0000 | [diff] [blame] | 1462 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1463 | else if ((!strcmp(argv[i], "-debugent")) || |
| 1464 | (!strcmp(argv[i], "--debugent"))) { |
| 1465 | debugent++; |
| 1466 | xmlParserDebugEntities = 1; |
| 1467 | } |
Daniel Veillard | 64c20ed | 2000-09-22 16:07:02 +0000 | [diff] [blame] | 1468 | #endif |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 1469 | #ifdef LIBXML_CATALOG_ENABLED |
| 1470 | else if ((!strcmp(argv[i], "-catalogs")) || |
| 1471 | (!strcmp(argv[i], "--catalogs"))) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1472 | catalogs++; |
| 1473 | } else if ((!strcmp(argv[i], "-nocatalogs")) || |
| 1474 | (!strcmp(argv[i], "--nocatalogs"))) { |
| 1475 | nocatalogs++; |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 1476 | } |
| 1477 | #endif |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1478 | else if ((!strcmp(argv[i], "-encode")) || |
| 1479 | (!strcmp(argv[i], "--encode"))) { |
| 1480 | i++; |
| 1481 | encoding = argv[i]; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1482 | /* |
| 1483 | * OK it's for testing purposes |
| 1484 | */ |
| 1485 | xmlAddEncodingAlias("UTF-8", "DVEnc"); |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1486 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1487 | else if ((!strcmp(argv[i], "-noblanks")) || |
| 1488 | (!strcmp(argv[i], "--noblanks"))) { |
| 1489 | noblanks++; |
| 1490 | xmlKeepBlanksDefault(0); |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 1491 | } |
| 1492 | else if ((!strcmp(argv[i], "-format")) || |
| 1493 | (!strcmp(argv[i], "--format"))) { |
| 1494 | noblanks++; |
| 1495 | format++; |
| 1496 | xmlKeepBlanksDefault(0); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1497 | } |
| 1498 | else if ((!strcmp(argv[i], "-stream")) || |
| 1499 | (!strcmp(argv[i], "--stream"))) { |
| 1500 | stream++; |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1501 | } |
| 1502 | else if ((!strcmp(argv[i], "-chkregister")) || |
| 1503 | (!strcmp(argv[i], "--chkregister"))) { |
| 1504 | chkregister++; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1505 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 1506 | } else if ((!strcmp(argv[i], "-relaxng")) || |
| 1507 | (!strcmp(argv[i], "--relaxng"))) { |
| 1508 | i++; |
| 1509 | relaxng = argv[i]; |
| 1510 | noent++; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1511 | } else if ((!strcmp(argv[i], "-schema")) || |
| 1512 | (!strcmp(argv[i], "--schema"))) { |
| 1513 | i++; |
| 1514 | schema = argv[i]; |
| 1515 | noent++; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1516 | #endif |
Daniel Veillard | e8b09e4 | 2003-05-13 22:14:13 +0000 | [diff] [blame] | 1517 | } else if ((!strcmp(argv[i], "-nonet")) || |
| 1518 | (!strcmp(argv[i], "--nonet"))) { |
| 1519 | xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1520 | } else { |
| 1521 | fprintf(stderr, "Unknown option %s\n", argv[i]); |
| 1522 | usage(argv[0]); |
| 1523 | return(1); |
| 1524 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1525 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1526 | |
| 1527 | #ifdef LIBXML_CATALOG_ENABLED |
| 1528 | if (nocatalogs == 0) { |
| 1529 | if (catalogs) { |
| 1530 | const char *catal; |
| 1531 | |
| 1532 | catal = getenv("SGML_CATALOG_FILES"); |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 1533 | if (catal != NULL) { |
| 1534 | xmlLoadCatalogs(catal); |
| 1535 | } else { |
| 1536 | fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n"); |
| 1537 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1538 | } |
| 1539 | } |
| 1540 | #endif |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1541 | |
| 1542 | if (chkregister) { |
| 1543 | xmlRegisterNodeDefault(registerNode); |
| 1544 | xmlDeregisterNodeDefault(deregisterNode); |
| 1545 | } |
Aleksey Sanin | 693c9bc | 2003-03-09 22:36:52 +0000 | [diff] [blame] | 1546 | |
| 1547 | indent = getenv("XMLLINT_INDENT"); |
| 1548 | if(indent != NULL) { |
| 1549 | xmlTreeIndentString = indent; |
| 1550 | } |
| 1551 | |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1552 | |
Daniel Veillard | d9bad13 | 2001-07-23 19:39:43 +0000 | [diff] [blame] | 1553 | xmlLineNumbersDefault(1); |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 1554 | if (loaddtd != 0) |
| 1555 | xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS; |
| 1556 | if (dtdattrs) |
| 1557 | xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1558 | if (noent != 0) xmlSubstituteEntitiesDefault(1); |
| 1559 | if (valid != 0) xmlDoValidityCheckingDefaultValue = 1; |
| 1560 | if ((htmlout) && (!nowrap)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1561 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1562 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n"); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1563 | xmlGenericError(xmlGenericErrorContext, |
| 1564 | "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"); |
| 1565 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1566 | "<html><head><title>%s output</title></head>\n", |
| 1567 | argv[0]); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1568 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1569 | "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n", |
| 1570 | argv[0]); |
| 1571 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1572 | |
| 1573 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1574 | if ((relaxng != NULL) && (stream == 0)) { |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1575 | xmlRelaxNGParserCtxtPtr ctxt; |
| 1576 | |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1577 | /* forces loading the DTDs */ |
| 1578 | xmlLoadExtDtdDefaultValue |= 1; |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 1579 | if (timing) { |
| 1580 | startTimer(); |
| 1581 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1582 | ctxt = xmlRelaxNGNewParserCtxt(relaxng); |
| 1583 | xmlRelaxNGSetParserErrors(ctxt, |
| 1584 | (xmlRelaxNGValidityErrorFunc) fprintf, |
| 1585 | (xmlRelaxNGValidityWarningFunc) fprintf, |
| 1586 | stderr); |
| 1587 | relaxngschemas = xmlRelaxNGParse(ctxt); |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1588 | if (relaxngschemas == NULL) { |
| 1589 | xmlGenericError(xmlGenericErrorContext, |
| 1590 | "Relax-NG schema %s failed to compile\n", relaxng); |
| 1591 | relaxng = NULL; |
| 1592 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1593 | xmlRelaxNGFreeParserCtxt(ctxt); |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 1594 | if (timing) { |
| 1595 | endTimer("Compiling the schemas"); |
| 1596 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1597 | } else if ((schema != NULL) && (stream == 0)) { |
| 1598 | xmlSchemaParserCtxtPtr ctxt; |
| 1599 | |
| 1600 | if (timing) { |
| 1601 | startTimer(); |
| 1602 | } |
| 1603 | ctxt = xmlSchemaNewParserCtxt(schema); |
| 1604 | xmlSchemaSetParserErrors(ctxt, |
| 1605 | (xmlSchemaValidityErrorFunc) fprintf, |
| 1606 | (xmlSchemaValidityWarningFunc) fprintf, |
| 1607 | stderr); |
| 1608 | wxschemas = xmlSchemaParse(ctxt); |
| 1609 | if (wxschemas == NULL) { |
| 1610 | xmlGenericError(xmlGenericErrorContext, |
| 1611 | "WXS schema %s failed to compile\n", schema); |
| 1612 | schema = NULL; |
| 1613 | } |
| 1614 | xmlSchemaFreeParserCtxt(ctxt); |
| 1615 | if (timing) { |
| 1616 | endTimer("Compiling the schemas"); |
| 1617 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1618 | } |
| 1619 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1620 | for (i = 1; i < argc ; i++) { |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1621 | if ((!strcmp(argv[i], "-encode")) || |
| 1622 | (!strcmp(argv[i], "--encode"))) { |
| 1623 | i++; |
| 1624 | continue; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1625 | } else if ((!strcmp(argv[i], "-o")) || |
| 1626 | (!strcmp(argv[i], "-output")) || |
| 1627 | (!strcmp(argv[i], "--output"))) { |
| 1628 | i++; |
| 1629 | continue; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1630 | } |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1631 | if ((!strcmp(argv[i], "-dtdvalid")) || |
| 1632 | (!strcmp(argv[i], "--dtdvalid"))) { |
| 1633 | i++; |
| 1634 | continue; |
| 1635 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1636 | if ((!strcmp(argv[i], "-relaxng")) || |
| 1637 | (!strcmp(argv[i], "--relaxng"))) { |
| 1638 | i++; |
| 1639 | continue; |
| 1640 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1641 | if ((!strcmp(argv[i], "-schema")) || |
| 1642 | (!strcmp(argv[i], "--schema"))) { |
| 1643 | i++; |
| 1644 | continue; |
| 1645 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1646 | if ((timing) && (repeat)) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1647 | startTimer(); |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1648 | /* Remember file names. "-" means stdin. <sven@zen.org> */ |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 1649 | if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1650 | if (repeat) { |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1651 | for (acount = 0;acount < 100 * repeat;acount++) |
| 1652 | if (stream != 0) |
| 1653 | streamFile(argv[i]); |
| 1654 | else |
| 1655 | parseAndPrintFile(argv[i]); |
| 1656 | } else { |
| 1657 | if (stream != 0) |
| 1658 | streamFile(argv[i]); |
| 1659 | else |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1660 | parseAndPrintFile(argv[i]); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1661 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1662 | files ++; |
Daniel Veillard | a786693 | 2001-12-04 13:14:44 +0000 | [diff] [blame] | 1663 | if ((timing) && (repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1664 | endTimer("100 iterations"); |
Daniel Veillard | a786693 | 2001-12-04 13:14:44 +0000 | [diff] [blame] | 1665 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1666 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1667 | } |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 1668 | if (generate) |
| 1669 | parseAndPrintFile(NULL); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1670 | if ((htmlout) && (!nowrap)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1671 | xmlGenericError(xmlGenericErrorContext, "</body></html>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1672 | } |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 1673 | if ((files == 0) && (!generate) && (version == 0)) { |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1674 | usage(argv[0]); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1675 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1676 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 1677 | if (relaxngschemas != NULL) |
| 1678 | xmlRelaxNGFree(relaxngschemas); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1679 | if (wxschemas != NULL) |
| 1680 | xmlSchemaFree(wxschemas); |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1681 | xmlRelaxNGCleanupTypes(); |
| 1682 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1683 | xmlCleanupParser(); |
| 1684 | xmlMemoryDump(); |
| 1685 | |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 1686 | return(progresult); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1687 | } |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 1688 | |