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