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