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