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