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