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