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