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