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