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