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