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