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 | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 193 | static int sax = 0; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 194 | |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 195 | /************************************************************************ |
Daniel Veillard | 0bff36d | 2004-08-31 09:37:03 +0000 | [diff] [blame] | 196 | * * |
| 197 | * Entity loading control and customization. * |
| 198 | * * |
| 199 | ************************************************************************/ |
| 200 | #define MAX_PATHS 64 |
| 201 | static xmlChar *paths[MAX_PATHS + 1]; |
| 202 | static int nbpaths = 0; |
| 203 | static int load_trace = 0; |
| 204 | |
| 205 | static |
| 206 | void parsePath(const xmlChar *path) { |
| 207 | const xmlChar *cur; |
| 208 | |
| 209 | if (path == NULL) |
| 210 | return; |
| 211 | while (*path != 0) { |
| 212 | if (nbpaths >= MAX_PATHS) { |
| 213 | fprintf(stderr, "MAX_PATHS reached: too many paths\n"); |
| 214 | return; |
| 215 | } |
| 216 | cur = path; |
| 217 | while ((*cur == ' ') || (*cur == ':')) |
| 218 | cur++; |
| 219 | path = cur; |
| 220 | while ((*cur != 0) && (*cur != ' ') && (*cur != ':')) |
| 221 | cur++; |
| 222 | if (cur != path) { |
| 223 | paths[nbpaths] = xmlStrndup(path, cur - path); |
| 224 | if (paths[nbpaths] != NULL) |
| 225 | nbpaths++; |
| 226 | path = cur; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | xmlExternalEntityLoader defaultEntityLoader = NULL; |
| 232 | |
| 233 | static xmlParserInputPtr |
| 234 | xmllintExternalEntityLoader(const char *URL, const char *ID, |
| 235 | xmlParserCtxtPtr ctxt) { |
| 236 | xmlParserInputPtr ret; |
| 237 | warningSAXFunc warning = NULL; |
| 238 | |
| 239 | int i; |
| 240 | const char *lastsegment = URL; |
| 241 | const char *iter = URL; |
| 242 | |
| 243 | if (nbpaths > 0) { |
| 244 | while (*iter != 0) { |
| 245 | if (*iter == '/') |
| 246 | lastsegment = iter + 1; |
| 247 | iter++; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | if ((ctxt != NULL) && (ctxt->sax != NULL)) { |
| 252 | warning = ctxt->sax->warning; |
| 253 | ctxt->sax->warning = NULL; |
| 254 | } |
| 255 | |
| 256 | if (defaultEntityLoader != NULL) { |
| 257 | ret = defaultEntityLoader(URL, ID, ctxt); |
| 258 | if (ret != NULL) { |
| 259 | if (warning != NULL) |
| 260 | ctxt->sax->warning = warning; |
| 261 | if (load_trace) { |
| 262 | fprintf \ |
| 263 | (stderr, |
| 264 | "Loaded URL=\"%s\" ID=\"%s\"\n", |
| 265 | URL ? URL : "(null)", |
| 266 | ID ? ID : "(null)"); |
| 267 | } |
| 268 | return(ret); |
| 269 | } |
| 270 | } |
| 271 | for (i = 0;i < nbpaths;i++) { |
| 272 | xmlChar *newURL; |
| 273 | |
| 274 | newURL = xmlStrdup((const xmlChar *) paths[i]); |
| 275 | newURL = xmlStrcat(newURL, (const xmlChar *) "/"); |
| 276 | newURL = xmlStrcat(newURL, (const xmlChar *) lastsegment); |
| 277 | if (newURL != NULL) { |
| 278 | ret = defaultEntityLoader((const char *)newURL, ID, ctxt); |
| 279 | if (ret != NULL) { |
| 280 | if (warning != NULL) |
| 281 | ctxt->sax->warning = warning; |
| 282 | if (load_trace) { |
| 283 | fprintf \ |
| 284 | (stderr, |
| 285 | "Loaded URL=\"%s\" ID=\"%s\"\n", |
| 286 | newURL, |
| 287 | ID ? ID : "(null)"); |
| 288 | } |
| 289 | xmlFree(newURL); |
| 290 | return(ret); |
| 291 | } |
| 292 | xmlFree(newURL); |
| 293 | } |
| 294 | } |
| 295 | if (warning != NULL) { |
| 296 | ctxt->sax->warning = warning; |
| 297 | if (URL != NULL) |
| 298 | warning(ctxt, "failed to load external entity \"%s\"\n", URL); |
| 299 | else if (ID != NULL) |
| 300 | warning(ctxt, "failed to load external entity \"%s\"\n", ID); |
| 301 | } |
| 302 | return(NULL); |
| 303 | } |
| 304 | /************************************************************************ |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 305 | * * |
| 306 | * Memory allocation consumption debugging * |
| 307 | * * |
| 308 | ************************************************************************/ |
| 309 | |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 310 | static void |
| 311 | OOM(void) |
| 312 | { |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 313 | fprintf(stderr, "Ran out of memory needs > %d bytes\n", maxmem); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 314 | progresult = XMLLINT_ERR_MEM; |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 317 | static void |
| 318 | myFreeFunc(void *mem) |
| 319 | { |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 320 | xmlMemFree(mem); |
| 321 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 322 | static void * |
| 323 | myMallocFunc(size_t size) |
| 324 | { |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 325 | void *ret; |
| 326 | |
| 327 | ret = xmlMemMalloc(size); |
| 328 | if (ret != NULL) { |
| 329 | if (xmlMemUsed() > maxmem) { |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 330 | OOM(); |
| 331 | xmlMemFree(ret); |
| 332 | return (NULL); |
| 333 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 334 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 335 | return (ret); |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 336 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 337 | static void * |
| 338 | myReallocFunc(void *mem, size_t size) |
| 339 | { |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 340 | void *ret; |
| 341 | |
| 342 | ret = xmlMemRealloc(mem, size); |
| 343 | if (ret != NULL) { |
| 344 | if (xmlMemUsed() > maxmem) { |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 345 | OOM(); |
| 346 | xmlMemFree(ret); |
| 347 | return (NULL); |
| 348 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 349 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 350 | return (ret); |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 351 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 352 | static char * |
| 353 | myStrdupFunc(const char *str) |
| 354 | { |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 355 | char *ret; |
| 356 | |
| 357 | ret = xmlMemoryStrdup(str); |
| 358 | if (ret != NULL) { |
| 359 | if (xmlMemUsed() > maxmem) { |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 360 | OOM(); |
| 361 | xmlFree(ret); |
| 362 | return (NULL); |
| 363 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 364 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 365 | return (ret); |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 366 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 367 | /************************************************************************ |
| 368 | * * |
| 369 | * Internal timing routines to remove the necessity to have * |
| 370 | * unix-specific function calls. * |
| 371 | * * |
| 372 | ************************************************************************/ |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 373 | |
Daniel Veillard | 8c1ae60 | 2002-03-07 11:21:00 +0000 | [diff] [blame] | 374 | #ifndef HAVE_GETTIMEOFDAY |
| 375 | #ifdef HAVE_SYS_TIMEB_H |
| 376 | #ifdef HAVE_SYS_TIME_H |
| 377 | #ifdef HAVE_FTIME |
| 378 | |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 379 | static int |
Daniel Veillard | 8c1ae60 | 2002-03-07 11:21:00 +0000 | [diff] [blame] | 380 | my_gettimeofday(struct timeval *tvp, void *tzp) |
| 381 | { |
| 382 | struct timeb timebuffer; |
| 383 | |
| 384 | ftime(&timebuffer); |
| 385 | if (tvp) { |
| 386 | tvp->tv_sec = timebuffer.time; |
| 387 | tvp->tv_usec = timebuffer.millitm * 1000L; |
| 388 | } |
| 389 | return (0); |
| 390 | } |
| 391 | #define HAVE_GETTIMEOFDAY 1 |
| 392 | #define gettimeofday my_gettimeofday |
| 393 | |
| 394 | #endif /* HAVE_FTIME */ |
| 395 | #endif /* HAVE_SYS_TIME_H */ |
| 396 | #endif /* HAVE_SYS_TIMEB_H */ |
| 397 | #endif /* !HAVE_GETTIMEOFDAY */ |
| 398 | |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 399 | #if defined(HAVE_GETTIMEOFDAY) |
| 400 | static struct timeval begin, end; |
| 401 | |
| 402 | /* |
| 403 | * startTimer: call where you want to start timing |
| 404 | */ |
| 405 | static void |
| 406 | startTimer(void) |
| 407 | { |
| 408 | gettimeofday(&begin, NULL); |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * endTimer: call where you want to stop timing and to print out a |
| 413 | * message about the timing performed; format is a printf |
| 414 | * type argument |
| 415 | */ |
| 416 | static void |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 417 | endTimer(const char *fmt, ...) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 418 | { |
| 419 | long msec; |
| 420 | va_list ap; |
| 421 | |
| 422 | gettimeofday(&end, NULL); |
| 423 | msec = end.tv_sec - begin.tv_sec; |
| 424 | msec *= 1000; |
| 425 | msec += (end.tv_usec - begin.tv_usec) / 1000; |
| 426 | |
| 427 | #ifndef HAVE_STDARG_H |
| 428 | #error "endTimer required stdarg functions" |
| 429 | #endif |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 430 | va_start(ap, fmt); |
| 431 | vfprintf(stderr, fmt, ap); |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 432 | va_end(ap); |
| 433 | |
| 434 | fprintf(stderr, " took %ld ms\n", msec); |
| 435 | } |
| 436 | #elif defined(HAVE_TIME_H) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 437 | /* |
| 438 | * No gettimeofday function, so we have to make do with calling clock. |
| 439 | * This is obviously less accurate, but there's little we can do about |
| 440 | * that. |
| 441 | */ |
Daniel Veillard | 90bc371 | 2002-03-07 15:12:58 +0000 | [diff] [blame] | 442 | #ifndef CLOCKS_PER_SEC |
| 443 | #define CLOCKS_PER_SEC 100 |
| 444 | #endif |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 445 | |
| 446 | static clock_t begin, end; |
| 447 | static void |
| 448 | startTimer(void) |
| 449 | { |
| 450 | begin = clock(); |
| 451 | } |
| 452 | static void |
| 453 | endTimer(const char *fmt, ...) |
| 454 | { |
| 455 | long msec; |
| 456 | va_list ap; |
| 457 | |
| 458 | end = clock(); |
| 459 | msec = ((end - begin) * 1000) / CLOCKS_PER_SEC; |
| 460 | |
| 461 | #ifndef HAVE_STDARG_H |
| 462 | #error "endTimer required stdarg functions" |
| 463 | #endif |
| 464 | va_start(ap, fmt); |
| 465 | vfprintf(stderr, fmt, ap); |
| 466 | va_end(ap); |
| 467 | fprintf(stderr, " took %ld ms\n", msec); |
| 468 | } |
| 469 | #else |
| 470 | |
| 471 | /* |
| 472 | * We don't have a gettimeofday or time.h, so we just don't do timing |
| 473 | */ |
| 474 | static void |
| 475 | startTimer(void) |
| 476 | { |
| 477 | /* |
| 478 | * Do nothing |
| 479 | */ |
| 480 | } |
| 481 | static void |
| 482 | endTimer(char *format, ...) |
| 483 | { |
| 484 | /* |
| 485 | * We cannot do anything because we don't have a timing function |
| 486 | */ |
| 487 | #ifdef HAVE_STDARG_H |
| 488 | va_start(ap, format); |
| 489 | vfprintf(stderr, format, ap); |
| 490 | va_end(ap); |
| 491 | fprintf(stderr, " was not timed\n", msec); |
| 492 | #else |
| 493 | /* We don't have gettimeofday, time or stdarg.h, what crazy world is |
| 494 | * this ?! |
| 495 | */ |
| 496 | #endif |
| 497 | } |
| 498 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 499 | /************************************************************************ |
| 500 | * * |
| 501 | * HTML ouput * |
| 502 | * * |
| 503 | ************************************************************************/ |
| 504 | char buffer[50000]; |
| 505 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 506 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 507 | xmlHTMLEncodeSend(void) { |
| 508 | char *result; |
| 509 | |
| 510 | result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer); |
| 511 | if (result) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 512 | xmlGenericError(xmlGenericErrorContext, "%s", result); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 513 | xmlFree(result); |
| 514 | } |
| 515 | buffer[0] = 0; |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * xmlHTMLPrintFileInfo: |
| 520 | * @input: an xmlParserInputPtr input |
| 521 | * |
| 522 | * Displays the associated file and line informations for the current input |
| 523 | */ |
| 524 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 525 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 526 | xmlHTMLPrintFileInfo(xmlParserInputPtr input) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 527 | int len; |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 528 | xmlGenericError(xmlGenericErrorContext, "<p>"); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 529 | |
| 530 | len = strlen(buffer); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 531 | if (input != NULL) { |
| 532 | if (input->filename) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 533 | snprintf(&buffer[len], sizeof(buffer) - len, "%s:%d: ", input->filename, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 534 | input->line); |
| 535 | } else { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 536 | snprintf(&buffer[len], sizeof(buffer) - len, "Entity: line %d: ", input->line); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | xmlHTMLEncodeSend(); |
| 540 | } |
| 541 | |
| 542 | /** |
| 543 | * xmlHTMLPrintFileContext: |
| 544 | * @input: an xmlParserInputPtr input |
| 545 | * |
| 546 | * Displays current context within the input content for error tracking |
| 547 | */ |
| 548 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 549 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 550 | xmlHTMLPrintFileContext(xmlParserInputPtr input) { |
| 551 | const xmlChar *cur, *base; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 552 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 553 | int n; |
| 554 | |
| 555 | if (input == NULL) return; |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 556 | xmlGenericError(xmlGenericErrorContext, "<pre>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 557 | cur = input->cur; |
| 558 | base = input->base; |
| 559 | while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { |
| 560 | cur--; |
| 561 | } |
| 562 | n = 0; |
| 563 | while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) |
| 564 | cur--; |
| 565 | if ((*cur == '\n') || (*cur == '\r')) cur++; |
| 566 | base = cur; |
| 567 | n = 0; |
| 568 | while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 569 | len = strlen(buffer); |
| 570 | snprintf(&buffer[len], sizeof(buffer) - len, "%c", |
| 571 | (unsigned char) *cur++); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 572 | n++; |
| 573 | } |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 574 | len = strlen(buffer); |
| 575 | snprintf(&buffer[len], sizeof(buffer) - len, "\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 576 | cur = input->cur; |
| 577 | while ((*cur == '\n') || (*cur == '\r')) |
| 578 | cur--; |
| 579 | n = 0; |
| 580 | while ((cur != base) && (n++ < 80)) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 581 | len = strlen(buffer); |
| 582 | snprintf(&buffer[len], sizeof(buffer) - len, " "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 583 | base++; |
| 584 | } |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 585 | len = strlen(buffer); |
| 586 | snprintf(&buffer[len], sizeof(buffer) - len, "^\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 587 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 588 | xmlGenericError(xmlGenericErrorContext, "</pre>"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | /** |
| 592 | * xmlHTMLError: |
| 593 | * @ctx: an XML parser context |
| 594 | * @msg: the message to display/transmit |
| 595 | * @...: extra parameters for the message display |
| 596 | * |
| 597 | * Display and format an error messages, gives file, line, position and |
| 598 | * extra parameters. |
| 599 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 600 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 601 | xmlHTMLError(void *ctx, const char *msg, ...) |
| 602 | { |
| 603 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 604 | xmlParserInputPtr input; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 605 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 606 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 607 | |
| 608 | buffer[0] = 0; |
| 609 | input = ctxt->input; |
| 610 | if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 611 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 612 | } |
| 613 | |
| 614 | xmlHTMLPrintFileInfo(input); |
| 615 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 616 | xmlGenericError(xmlGenericErrorContext, "<b>error</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 617 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 618 | len = strlen(buffer); |
| 619 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 620 | va_end(args); |
| 621 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 622 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 623 | |
| 624 | xmlHTMLPrintFileContext(input); |
| 625 | xmlHTMLEncodeSend(); |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * xmlHTMLWarning: |
| 630 | * @ctx: an XML parser context |
| 631 | * @msg: the message to display/transmit |
| 632 | * @...: extra parameters for the message display |
| 633 | * |
| 634 | * Display and format a warning messages, gives file, line, position and |
| 635 | * extra parameters. |
| 636 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 637 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 638 | xmlHTMLWarning(void *ctx, const char *msg, ...) |
| 639 | { |
| 640 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 641 | xmlParserInputPtr input; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 642 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 643 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 644 | |
| 645 | buffer[0] = 0; |
| 646 | input = ctxt->input; |
| 647 | if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 648 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 649 | } |
| 650 | |
| 651 | |
| 652 | xmlHTMLPrintFileInfo(input); |
| 653 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 654 | xmlGenericError(xmlGenericErrorContext, "<b>warning</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 655 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 656 | len = strlen(buffer); |
| 657 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 658 | va_end(args); |
| 659 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 660 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 661 | |
| 662 | xmlHTMLPrintFileContext(input); |
| 663 | xmlHTMLEncodeSend(); |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * xmlHTMLValidityError: |
| 668 | * @ctx: an XML parser context |
| 669 | * @msg: the message to display/transmit |
| 670 | * @...: extra parameters for the message display |
| 671 | * |
| 672 | * Display and format an validity error messages, gives file, |
| 673 | * line, position and extra parameters. |
| 674 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 675 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 676 | xmlHTMLValidityError(void *ctx, const char *msg, ...) |
| 677 | { |
| 678 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 679 | xmlParserInputPtr input; |
| 680 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 681 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 682 | |
| 683 | buffer[0] = 0; |
| 684 | input = ctxt->input; |
| 685 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 686 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 687 | |
| 688 | xmlHTMLPrintFileInfo(input); |
| 689 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 690 | xmlGenericError(xmlGenericErrorContext, "<b>validity error</b>: "); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 691 | len = strlen(buffer); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 692 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 693 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 694 | va_end(args); |
| 695 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 696 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 697 | |
| 698 | xmlHTMLPrintFileContext(input); |
| 699 | xmlHTMLEncodeSend(); |
Daniel Veillard | 9fcb491 | 2005-03-16 12:57:31 +0000 | [diff] [blame] | 700 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | /** |
| 704 | * xmlHTMLValidityWarning: |
| 705 | * @ctx: an XML parser context |
| 706 | * @msg: the message to display/transmit |
| 707 | * @...: extra parameters for the message display |
| 708 | * |
| 709 | * Display and format a validity warning messages, gives file, line, |
| 710 | * position and extra parameters. |
| 711 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 712 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 713 | xmlHTMLValidityWarning(void *ctx, const char *msg, ...) |
| 714 | { |
| 715 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 716 | xmlParserInputPtr input; |
| 717 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 718 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 719 | |
| 720 | buffer[0] = 0; |
| 721 | input = ctxt->input; |
| 722 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 723 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 724 | |
| 725 | xmlHTMLPrintFileInfo(input); |
| 726 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 727 | xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 728 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 729 | len = strlen(buffer); |
| 730 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 731 | va_end(args); |
| 732 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 733 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 734 | |
| 735 | xmlHTMLPrintFileContext(input); |
| 736 | xmlHTMLEncodeSend(); |
| 737 | } |
| 738 | |
| 739 | /************************************************************************ |
| 740 | * * |
| 741 | * Shell Interface * |
| 742 | * * |
| 743 | ************************************************************************/ |
Daniel Veillard | 56ada1d | 2003-01-07 11:17:25 +0000 | [diff] [blame] | 744 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 745 | #ifdef LIBXML_XPATH_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 746 | /** |
| 747 | * xmlShellReadline: |
| 748 | * @prompt: the prompt value |
| 749 | * |
| 750 | * Read a string |
| 751 | * |
| 752 | * Returns a pointer to it or NULL on EOF the caller is expected to |
| 753 | * free the returned string. |
| 754 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 755 | static char * |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 756 | xmlShellReadline(char *prompt) { |
| 757 | #ifdef HAVE_LIBREADLINE |
| 758 | char *line_read; |
| 759 | |
| 760 | /* Get a line from the user. */ |
| 761 | line_read = readline (prompt); |
| 762 | |
| 763 | /* If the line has any text in it, save it on the history. */ |
| 764 | if (line_read && *line_read) |
| 765 | add_history (line_read); |
| 766 | |
| 767 | return (line_read); |
| 768 | #else |
| 769 | char line_read[501]; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 770 | char *ret; |
| 771 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 772 | |
| 773 | if (prompt != NULL) |
| 774 | fprintf(stdout, "%s", prompt); |
| 775 | if (!fgets(line_read, 500, stdin)) |
| 776 | return(NULL); |
| 777 | line_read[500] = 0; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 778 | len = strlen(line_read); |
| 779 | ret = (char *) malloc(len + 1); |
| 780 | if (ret != NULL) { |
| 781 | memcpy (ret, line_read, len + 1); |
| 782 | } |
| 783 | return(ret); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 784 | #endif |
| 785 | } |
Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 786 | #endif /* LIBXML_XPATH_ENABLED */ |
Daniel Veillard | 56ada1d | 2003-01-07 11:17:25 +0000 | [diff] [blame] | 787 | #endif /* LIBXML_DEBUG_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 788 | |
| 789 | /************************************************************************ |
| 790 | * * |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 791 | * I/O Interfaces * |
| 792 | * * |
| 793 | ************************************************************************/ |
| 794 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 795 | static int myRead(FILE *f, char * buf, int len) { |
| 796 | return(fread(buf, 1, len, f)); |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 797 | } |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 798 | static void myClose(FILE *f) { |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 799 | if (f != stdin) { |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 800 | fclose(f); |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 801 | } |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 804 | /************************************************************************ |
| 805 | * * |
| 806 | * SAX based tests * |
| 807 | * * |
| 808 | ************************************************************************/ |
| 809 | |
| 810 | /* |
| 811 | * empty SAX block |
| 812 | */ |
| 813 | xmlSAXHandler emptySAXHandlerStruct = { |
| 814 | NULL, /* internalSubset */ |
| 815 | NULL, /* isStandalone */ |
| 816 | NULL, /* hasInternalSubset */ |
| 817 | NULL, /* hasExternalSubset */ |
| 818 | NULL, /* resolveEntity */ |
| 819 | NULL, /* getEntity */ |
| 820 | NULL, /* entityDecl */ |
| 821 | NULL, /* notationDecl */ |
| 822 | NULL, /* attributeDecl */ |
| 823 | NULL, /* elementDecl */ |
| 824 | NULL, /* unparsedEntityDecl */ |
| 825 | NULL, /* setDocumentLocator */ |
| 826 | NULL, /* startDocument */ |
| 827 | NULL, /* endDocument */ |
| 828 | NULL, /* startElement */ |
| 829 | NULL, /* endElement */ |
| 830 | NULL, /* reference */ |
| 831 | NULL, /* characters */ |
| 832 | NULL, /* ignorableWhitespace */ |
| 833 | NULL, /* processingInstruction */ |
| 834 | NULL, /* comment */ |
| 835 | NULL, /* xmlParserWarning */ |
| 836 | NULL, /* xmlParserError */ |
| 837 | NULL, /* xmlParserError */ |
| 838 | NULL, /* getParameterEntity */ |
| 839 | NULL, /* cdataBlock; */ |
| 840 | NULL, /* externalSubset; */ |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 841 | XML_SAX2_MAGIC, |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 842 | NULL, |
| 843 | NULL, /* startElementNs */ |
| 844 | NULL, /* endElementNs */ |
| 845 | NULL /* xmlStructuredErrorFunc */ |
| 846 | }; |
| 847 | |
| 848 | xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct; |
| 849 | extern xmlSAXHandlerPtr debugSAXHandler; |
| 850 | static int callbacks; |
| 851 | |
| 852 | /** |
| 853 | * isStandaloneDebug: |
| 854 | * @ctxt: An XML parser context |
| 855 | * |
| 856 | * Is this document tagged standalone ? |
| 857 | * |
| 858 | * Returns 1 if true |
| 859 | */ |
| 860 | static int |
| 861 | isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED) |
| 862 | { |
| 863 | callbacks++; |
| 864 | if (noout) |
| 865 | return(0); |
| 866 | fprintf(stdout, "SAX.isStandalone()\n"); |
| 867 | return(0); |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * hasInternalSubsetDebug: |
| 872 | * @ctxt: An XML parser context |
| 873 | * |
| 874 | * Does this document has an internal subset |
| 875 | * |
| 876 | * Returns 1 if true |
| 877 | */ |
| 878 | static int |
| 879 | hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED) |
| 880 | { |
| 881 | callbacks++; |
| 882 | if (noout) |
| 883 | return(0); |
| 884 | fprintf(stdout, "SAX.hasInternalSubset()\n"); |
| 885 | return(0); |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * hasExternalSubsetDebug: |
| 890 | * @ctxt: An XML parser context |
| 891 | * |
| 892 | * Does this document has an external subset |
| 893 | * |
| 894 | * Returns 1 if true |
| 895 | */ |
| 896 | static int |
| 897 | hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED) |
| 898 | { |
| 899 | callbacks++; |
| 900 | if (noout) |
| 901 | return(0); |
| 902 | fprintf(stdout, "SAX.hasExternalSubset()\n"); |
| 903 | return(0); |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * internalSubsetDebug: |
| 908 | * @ctxt: An XML parser context |
| 909 | * |
| 910 | * Does this document has an internal subset |
| 911 | */ |
| 912 | static void |
| 913 | internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, |
| 914 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 915 | { |
| 916 | callbacks++; |
| 917 | if (noout) |
| 918 | return; |
| 919 | fprintf(stdout, "SAX.internalSubset(%s,", name); |
| 920 | if (ExternalID == NULL) |
| 921 | fprintf(stdout, " ,"); |
| 922 | else |
| 923 | fprintf(stdout, " %s,", ExternalID); |
| 924 | if (SystemID == NULL) |
| 925 | fprintf(stdout, " )\n"); |
| 926 | else |
| 927 | fprintf(stdout, " %s)\n", SystemID); |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * externalSubsetDebug: |
| 932 | * @ctxt: An XML parser context |
| 933 | * |
| 934 | * Does this document has an external subset |
| 935 | */ |
| 936 | static void |
| 937 | externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, |
| 938 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 939 | { |
| 940 | callbacks++; |
| 941 | if (noout) |
| 942 | return; |
| 943 | fprintf(stdout, "SAX.externalSubset(%s,", name); |
| 944 | if (ExternalID == NULL) |
| 945 | fprintf(stdout, " ,"); |
| 946 | else |
| 947 | fprintf(stdout, " %s,", ExternalID); |
| 948 | if (SystemID == NULL) |
| 949 | fprintf(stdout, " )\n"); |
| 950 | else |
| 951 | fprintf(stdout, " %s)\n", SystemID); |
| 952 | } |
| 953 | |
| 954 | /** |
| 955 | * resolveEntityDebug: |
| 956 | * @ctxt: An XML parser context |
| 957 | * @publicId: The public ID of the entity |
| 958 | * @systemId: The system ID of the entity |
| 959 | * |
| 960 | * Special entity resolver, better left to the parser, it has |
| 961 | * more context than the application layer. |
| 962 | * The default behaviour is to NOT resolve the entities, in that case |
| 963 | * the ENTITY_REF nodes are built in the structure (and the parameter |
| 964 | * values). |
| 965 | * |
| 966 | * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. |
| 967 | */ |
| 968 | static xmlParserInputPtr |
| 969 | resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId) |
| 970 | { |
| 971 | callbacks++; |
| 972 | if (noout) |
| 973 | return(NULL); |
| 974 | /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ |
| 975 | |
| 976 | |
| 977 | fprintf(stdout, "SAX.resolveEntity("); |
| 978 | if (publicId != NULL) |
| 979 | fprintf(stdout, "%s", (char *)publicId); |
| 980 | else |
| 981 | fprintf(stdout, " "); |
| 982 | if (systemId != NULL) |
| 983 | fprintf(stdout, ", %s)\n", (char *)systemId); |
| 984 | else |
| 985 | fprintf(stdout, ", )\n"); |
| 986 | return(NULL); |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * getEntityDebug: |
| 991 | * @ctxt: An XML parser context |
| 992 | * @name: The entity name |
| 993 | * |
| 994 | * Get an entity by name |
| 995 | * |
| 996 | * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. |
| 997 | */ |
| 998 | static xmlEntityPtr |
| 999 | getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
| 1000 | { |
| 1001 | callbacks++; |
| 1002 | if (noout) |
| 1003 | return(NULL); |
| 1004 | fprintf(stdout, "SAX.getEntity(%s)\n", name); |
| 1005 | return(NULL); |
| 1006 | } |
| 1007 | |
| 1008 | /** |
| 1009 | * getParameterEntityDebug: |
| 1010 | * @ctxt: An XML parser context |
| 1011 | * @name: The entity name |
| 1012 | * |
| 1013 | * Get a parameter entity by name |
| 1014 | * |
| 1015 | * Returns the xmlParserInputPtr |
| 1016 | */ |
| 1017 | static xmlEntityPtr |
| 1018 | getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
| 1019 | { |
| 1020 | callbacks++; |
| 1021 | if (noout) |
| 1022 | return(NULL); |
| 1023 | fprintf(stdout, "SAX.getParameterEntity(%s)\n", name); |
| 1024 | return(NULL); |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | /** |
| 1029 | * entityDeclDebug: |
| 1030 | * @ctxt: An XML parser context |
| 1031 | * @name: the entity name |
| 1032 | * @type: the entity type |
| 1033 | * @publicId: The public ID of the entity |
| 1034 | * @systemId: The system ID of the entity |
| 1035 | * @content: the entity value (without processing). |
| 1036 | * |
| 1037 | * An entity definition has been parsed |
| 1038 | */ |
| 1039 | static void |
| 1040 | entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, |
| 1041 | const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) |
| 1042 | { |
| 1043 | const xmlChar *nullstr = BAD_CAST "(null)"; |
| 1044 | /* not all libraries handle printing null pointers nicely */ |
| 1045 | if (publicId == NULL) |
| 1046 | publicId = nullstr; |
| 1047 | if (systemId == NULL) |
| 1048 | systemId = nullstr; |
| 1049 | if (content == NULL) |
| 1050 | content = (xmlChar *)nullstr; |
| 1051 | callbacks++; |
| 1052 | if (noout) |
| 1053 | return; |
| 1054 | fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", |
| 1055 | name, type, publicId, systemId, content); |
| 1056 | } |
| 1057 | |
| 1058 | /** |
| 1059 | * attributeDeclDebug: |
| 1060 | * @ctxt: An XML parser context |
| 1061 | * @name: the attribute name |
| 1062 | * @type: the attribute type |
| 1063 | * |
| 1064 | * An attribute definition has been parsed |
| 1065 | */ |
| 1066 | static void |
| 1067 | attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar * elem, |
| 1068 | const xmlChar * name, int type, int def, |
| 1069 | const xmlChar * defaultValue, xmlEnumerationPtr tree) |
| 1070 | { |
| 1071 | callbacks++; |
| 1072 | if (noout) |
| 1073 | return; |
| 1074 | if (defaultValue == NULL) |
| 1075 | fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n", |
| 1076 | elem, name, type, def); |
| 1077 | else |
| 1078 | fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", |
| 1079 | elem, name, type, def, defaultValue); |
| 1080 | xmlFreeEnumeration(tree); |
| 1081 | } |
| 1082 | |
| 1083 | /** |
| 1084 | * elementDeclDebug: |
| 1085 | * @ctxt: An XML parser context |
| 1086 | * @name: the element name |
| 1087 | * @type: the element type |
| 1088 | * @content: the element value (without processing). |
| 1089 | * |
| 1090 | * An element definition has been parsed |
| 1091 | */ |
| 1092 | static void |
| 1093 | elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, |
| 1094 | xmlElementContentPtr content ATTRIBUTE_UNUSED) |
| 1095 | { |
| 1096 | callbacks++; |
| 1097 | if (noout) |
| 1098 | return; |
| 1099 | fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n", |
| 1100 | name, type); |
| 1101 | } |
| 1102 | |
| 1103 | /** |
| 1104 | * notationDeclDebug: |
| 1105 | * @ctxt: An XML parser context |
| 1106 | * @name: The name of the notation |
| 1107 | * @publicId: The public ID of the entity |
| 1108 | * @systemId: The system ID of the entity |
| 1109 | * |
| 1110 | * What to do when a notation declaration has been parsed. |
| 1111 | */ |
| 1112 | static void |
| 1113 | notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, |
| 1114 | const xmlChar *publicId, const xmlChar *systemId) |
| 1115 | { |
| 1116 | callbacks++; |
| 1117 | if (noout) |
| 1118 | return; |
| 1119 | fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n", |
| 1120 | (char *) name, (char *) publicId, (char *) systemId); |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * unparsedEntityDeclDebug: |
| 1125 | * @ctxt: An XML parser context |
| 1126 | * @name: The name of the entity |
| 1127 | * @publicId: The public ID of the entity |
| 1128 | * @systemId: The system ID of the entity |
| 1129 | * @notationName: the name of the notation |
| 1130 | * |
| 1131 | * What to do when an unparsed entity declaration is parsed |
| 1132 | */ |
| 1133 | static void |
| 1134 | unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, |
| 1135 | const xmlChar *publicId, const xmlChar *systemId, |
| 1136 | const xmlChar *notationName) |
| 1137 | { |
| 1138 | const xmlChar *nullstr = BAD_CAST "(null)"; |
| 1139 | |
| 1140 | if (publicId == NULL) |
| 1141 | publicId = nullstr; |
| 1142 | if (systemId == NULL) |
| 1143 | systemId = nullstr; |
| 1144 | if (notationName == NULL) |
| 1145 | notationName = nullstr; |
| 1146 | callbacks++; |
| 1147 | if (noout) |
| 1148 | return; |
| 1149 | fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n", |
| 1150 | (char *) name, (char *) publicId, (char *) systemId, |
| 1151 | (char *) notationName); |
| 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * setDocumentLocatorDebug: |
| 1156 | * @ctxt: An XML parser context |
| 1157 | * @loc: A SAX Locator |
| 1158 | * |
| 1159 | * Receive the document locator at startup, actually xmlDefaultSAXLocator |
| 1160 | * Everything is available on the context, so this is useless in our case. |
| 1161 | */ |
| 1162 | static void |
| 1163 | setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED) |
| 1164 | { |
| 1165 | callbacks++; |
| 1166 | if (noout) |
| 1167 | return; |
| 1168 | fprintf(stdout, "SAX.setDocumentLocator()\n"); |
| 1169 | } |
| 1170 | |
| 1171 | /** |
| 1172 | * startDocumentDebug: |
| 1173 | * @ctxt: An XML parser context |
| 1174 | * |
| 1175 | * called when the document start being processed. |
| 1176 | */ |
| 1177 | static void |
| 1178 | startDocumentDebug(void *ctx ATTRIBUTE_UNUSED) |
| 1179 | { |
| 1180 | callbacks++; |
| 1181 | if (noout) |
| 1182 | return; |
| 1183 | fprintf(stdout, "SAX.startDocument()\n"); |
| 1184 | } |
| 1185 | |
| 1186 | /** |
| 1187 | * endDocumentDebug: |
| 1188 | * @ctxt: An XML parser context |
| 1189 | * |
| 1190 | * called when the document end has been detected. |
| 1191 | */ |
| 1192 | static void |
| 1193 | endDocumentDebug(void *ctx ATTRIBUTE_UNUSED) |
| 1194 | { |
| 1195 | callbacks++; |
| 1196 | if (noout) |
| 1197 | return; |
| 1198 | fprintf(stdout, "SAX.endDocument()\n"); |
| 1199 | } |
| 1200 | |
| 1201 | /** |
| 1202 | * startElementDebug: |
| 1203 | * @ctxt: An XML parser context |
| 1204 | * @name: The element name |
| 1205 | * |
| 1206 | * called when an opening tag has been processed. |
| 1207 | */ |
| 1208 | static void |
| 1209 | startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts) |
| 1210 | { |
| 1211 | int i; |
| 1212 | |
| 1213 | callbacks++; |
| 1214 | if (noout) |
| 1215 | return; |
| 1216 | fprintf(stdout, "SAX.startElement(%s", (char *) name); |
| 1217 | if (atts != NULL) { |
| 1218 | for (i = 0;(atts[i] != NULL);i++) { |
| 1219 | fprintf(stdout, ", %s='", atts[i++]); |
| 1220 | if (atts[i] != NULL) |
| 1221 | fprintf(stdout, "%s'", atts[i]); |
| 1222 | } |
| 1223 | } |
| 1224 | fprintf(stdout, ")\n"); |
| 1225 | } |
| 1226 | |
| 1227 | /** |
| 1228 | * endElementDebug: |
| 1229 | * @ctxt: An XML parser context |
| 1230 | * @name: The element name |
| 1231 | * |
| 1232 | * called when the end of an element has been detected. |
| 1233 | */ |
| 1234 | static void |
| 1235 | endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
| 1236 | { |
| 1237 | callbacks++; |
| 1238 | if (noout) |
| 1239 | return; |
| 1240 | fprintf(stdout, "SAX.endElement(%s)\n", (char *) name); |
| 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * charactersDebug: |
| 1245 | * @ctxt: An XML parser context |
| 1246 | * @ch: a xmlChar string |
| 1247 | * @len: the number of xmlChar |
| 1248 | * |
| 1249 | * receiving some chars from the parser. |
| 1250 | * Question: how much at a time ??? |
| 1251 | */ |
| 1252 | static void |
| 1253 | charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) |
| 1254 | { |
| 1255 | char out[40]; |
| 1256 | int i; |
| 1257 | |
| 1258 | callbacks++; |
| 1259 | if (noout) |
| 1260 | return; |
| 1261 | for (i = 0;(i<len) && (i < 30);i++) |
| 1262 | out[i] = ch[i]; |
| 1263 | out[i] = 0; |
| 1264 | |
| 1265 | fprintf(stdout, "SAX.characters(%s, %d)\n", out, len); |
| 1266 | } |
| 1267 | |
| 1268 | /** |
| 1269 | * referenceDebug: |
| 1270 | * @ctxt: An XML parser context |
| 1271 | * @name: The entity name |
| 1272 | * |
| 1273 | * called when an entity reference is detected. |
| 1274 | */ |
| 1275 | static void |
| 1276 | referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
| 1277 | { |
| 1278 | callbacks++; |
| 1279 | if (noout) |
| 1280 | return; |
| 1281 | fprintf(stdout, "SAX.reference(%s)\n", name); |
| 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * ignorableWhitespaceDebug: |
| 1286 | * @ctxt: An XML parser context |
| 1287 | * @ch: a xmlChar string |
| 1288 | * @start: the first char in the string |
| 1289 | * @len: the number of xmlChar |
| 1290 | * |
| 1291 | * receiving some ignorable whitespaces from the parser. |
| 1292 | * Question: how much at a time ??? |
| 1293 | */ |
| 1294 | static void |
| 1295 | ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) |
| 1296 | { |
| 1297 | char out[40]; |
| 1298 | int i; |
| 1299 | |
| 1300 | callbacks++; |
| 1301 | if (noout) |
| 1302 | return; |
| 1303 | for (i = 0;(i<len) && (i < 30);i++) |
| 1304 | out[i] = ch[i]; |
| 1305 | out[i] = 0; |
| 1306 | fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", out, len); |
| 1307 | } |
| 1308 | |
| 1309 | /** |
| 1310 | * processingInstructionDebug: |
| 1311 | * @ctxt: An XML parser context |
| 1312 | * @target: the target name |
| 1313 | * @data: the PI data's |
| 1314 | * @len: the number of xmlChar |
| 1315 | * |
| 1316 | * A processing instruction has been parsed. |
| 1317 | */ |
| 1318 | static void |
| 1319 | processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target, |
| 1320 | const xmlChar *data) |
| 1321 | { |
| 1322 | callbacks++; |
| 1323 | if (noout) |
| 1324 | return; |
| 1325 | if (data != NULL) |
| 1326 | fprintf(stdout, "SAX.processingInstruction(%s, %s)\n", |
| 1327 | (char *) target, (char *) data); |
| 1328 | else |
| 1329 | fprintf(stdout, "SAX.processingInstruction(%s, NULL)\n", |
| 1330 | (char *) target); |
| 1331 | } |
| 1332 | |
| 1333 | /** |
| 1334 | * cdataBlockDebug: |
| 1335 | * @ctx: the user data (XML parser context) |
| 1336 | * @value: The pcdata content |
| 1337 | * @len: the block length |
| 1338 | * |
| 1339 | * called when a pcdata block has been parsed |
| 1340 | */ |
| 1341 | static void |
| 1342 | cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len) |
| 1343 | { |
| 1344 | callbacks++; |
| 1345 | if (noout) |
| 1346 | return; |
| 1347 | fprintf(stdout, "SAX.pcdata(%.20s, %d)\n", |
| 1348 | (char *) value, len); |
| 1349 | } |
| 1350 | |
| 1351 | /** |
| 1352 | * commentDebug: |
| 1353 | * @ctxt: An XML parser context |
| 1354 | * @value: the comment content |
| 1355 | * |
| 1356 | * A comment has been parsed. |
| 1357 | */ |
| 1358 | static void |
| 1359 | commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value) |
| 1360 | { |
| 1361 | callbacks++; |
| 1362 | if (noout) |
| 1363 | return; |
| 1364 | fprintf(stdout, "SAX.comment(%s)\n", value); |
| 1365 | } |
| 1366 | |
| 1367 | /** |
| 1368 | * warningDebug: |
| 1369 | * @ctxt: An XML parser context |
| 1370 | * @msg: the message to display/transmit |
| 1371 | * @...: extra parameters for the message display |
| 1372 | * |
| 1373 | * Display and format a warning messages, gives file, line, position and |
| 1374 | * extra parameters. |
| 1375 | */ |
| 1376 | static void |
| 1377 | warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) |
| 1378 | { |
| 1379 | va_list args; |
| 1380 | |
| 1381 | callbacks++; |
| 1382 | if (noout) |
| 1383 | return; |
| 1384 | va_start(args, msg); |
| 1385 | fprintf(stdout, "SAX.warning: "); |
| 1386 | vfprintf(stdout, msg, args); |
| 1387 | va_end(args); |
| 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * errorDebug: |
| 1392 | * @ctxt: An XML parser context |
| 1393 | * @msg: the message to display/transmit |
| 1394 | * @...: extra parameters for the message display |
| 1395 | * |
| 1396 | * Display and format a error messages, gives file, line, position and |
| 1397 | * extra parameters. |
| 1398 | */ |
| 1399 | static void |
| 1400 | errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) |
| 1401 | { |
| 1402 | va_list args; |
| 1403 | |
| 1404 | callbacks++; |
| 1405 | if (noout) |
| 1406 | return; |
| 1407 | va_start(args, msg); |
| 1408 | fprintf(stdout, "SAX.error: "); |
| 1409 | vfprintf(stdout, msg, args); |
| 1410 | va_end(args); |
| 1411 | } |
| 1412 | |
| 1413 | /** |
| 1414 | * fatalErrorDebug: |
| 1415 | * @ctxt: An XML parser context |
| 1416 | * @msg: the message to display/transmit |
| 1417 | * @...: extra parameters for the message display |
| 1418 | * |
| 1419 | * Display and format a fatalError messages, gives file, line, position and |
| 1420 | * extra parameters. |
| 1421 | */ |
| 1422 | static void |
| 1423 | fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) |
| 1424 | { |
| 1425 | va_list args; |
| 1426 | |
| 1427 | callbacks++; |
| 1428 | if (noout) |
| 1429 | return; |
| 1430 | va_start(args, msg); |
| 1431 | fprintf(stdout, "SAX.fatalError: "); |
| 1432 | vfprintf(stdout, msg, args); |
| 1433 | va_end(args); |
| 1434 | } |
| 1435 | |
| 1436 | xmlSAXHandler debugSAXHandlerStruct = { |
| 1437 | internalSubsetDebug, |
| 1438 | isStandaloneDebug, |
| 1439 | hasInternalSubsetDebug, |
| 1440 | hasExternalSubsetDebug, |
| 1441 | resolveEntityDebug, |
| 1442 | getEntityDebug, |
| 1443 | entityDeclDebug, |
| 1444 | notationDeclDebug, |
| 1445 | attributeDeclDebug, |
| 1446 | elementDeclDebug, |
| 1447 | unparsedEntityDeclDebug, |
| 1448 | setDocumentLocatorDebug, |
| 1449 | startDocumentDebug, |
| 1450 | endDocumentDebug, |
| 1451 | startElementDebug, |
| 1452 | endElementDebug, |
| 1453 | referenceDebug, |
| 1454 | charactersDebug, |
| 1455 | ignorableWhitespaceDebug, |
| 1456 | processingInstructionDebug, |
| 1457 | commentDebug, |
| 1458 | warningDebug, |
| 1459 | errorDebug, |
| 1460 | fatalErrorDebug, |
| 1461 | getParameterEntityDebug, |
| 1462 | cdataBlockDebug, |
| 1463 | externalSubsetDebug, |
| 1464 | 1, |
| 1465 | NULL, |
| 1466 | NULL, |
| 1467 | NULL, |
| 1468 | NULL |
| 1469 | }; |
| 1470 | |
| 1471 | xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct; |
| 1472 | |
| 1473 | /* |
| 1474 | * SAX2 specific callbacks |
| 1475 | */ |
| 1476 | /** |
| 1477 | * startElementNsDebug: |
| 1478 | * @ctxt: An XML parser context |
| 1479 | * @name: The element name |
| 1480 | * |
| 1481 | * called when an opening tag has been processed. |
| 1482 | */ |
| 1483 | static void |
| 1484 | startElementNsDebug(void *ctx ATTRIBUTE_UNUSED, |
| 1485 | const xmlChar *localname, |
| 1486 | const xmlChar *prefix, |
| 1487 | const xmlChar *URI, |
| 1488 | int nb_namespaces, |
| 1489 | const xmlChar **namespaces, |
| 1490 | int nb_attributes, |
| 1491 | int nb_defaulted, |
| 1492 | const xmlChar **attributes) |
| 1493 | { |
| 1494 | int i; |
| 1495 | |
| 1496 | callbacks++; |
| 1497 | if (noout) |
| 1498 | return; |
| 1499 | fprintf(stdout, "SAX.startElementNs(%s", (char *) localname); |
| 1500 | if (prefix == NULL) |
| 1501 | fprintf(stdout, ", NULL"); |
| 1502 | else |
| 1503 | fprintf(stdout, ", %s", (char *) prefix); |
| 1504 | if (URI == NULL) |
| 1505 | fprintf(stdout, ", NULL"); |
| 1506 | else |
| 1507 | fprintf(stdout, ", '%s'", (char *) URI); |
| 1508 | fprintf(stdout, ", %d", nb_namespaces); |
| 1509 | |
| 1510 | if (namespaces != NULL) { |
| 1511 | for (i = 0;i < nb_namespaces * 2;i++) { |
| 1512 | fprintf(stdout, ", xmlns"); |
| 1513 | if (namespaces[i] != NULL) |
| 1514 | fprintf(stdout, ":%s", namespaces[i]); |
| 1515 | i++; |
| 1516 | fprintf(stdout, "='%s'", namespaces[i]); |
| 1517 | } |
| 1518 | } |
| 1519 | fprintf(stdout, ", %d, %d", nb_attributes, nb_defaulted); |
| 1520 | if (attributes != NULL) { |
| 1521 | for (i = 0;i < nb_attributes * 5;i += 5) { |
| 1522 | if (attributes[i + 1] != NULL) |
| 1523 | fprintf(stdout, ", %s:%s='", attributes[i + 1], attributes[i]); |
| 1524 | else |
| 1525 | fprintf(stdout, ", %s='", attributes[i]); |
| 1526 | fprintf(stdout, "%.4s...', %d", attributes[i + 3], |
| 1527 | (int)(attributes[i + 4] - attributes[i + 3])); |
| 1528 | } |
| 1529 | } |
| 1530 | fprintf(stdout, ")\n"); |
| 1531 | } |
| 1532 | |
| 1533 | /** |
| 1534 | * endElementDebug: |
| 1535 | * @ctxt: An XML parser context |
| 1536 | * @name: The element name |
| 1537 | * |
| 1538 | * called when the end of an element has been detected. |
| 1539 | */ |
| 1540 | static void |
| 1541 | endElementNsDebug(void *ctx ATTRIBUTE_UNUSED, |
| 1542 | const xmlChar *localname, |
| 1543 | const xmlChar *prefix, |
| 1544 | const xmlChar *URI) |
| 1545 | { |
| 1546 | callbacks++; |
| 1547 | if (noout) |
| 1548 | return; |
| 1549 | fprintf(stdout, "SAX.endElementNs(%s", (char *) localname); |
| 1550 | if (prefix == NULL) |
| 1551 | fprintf(stdout, ", NULL"); |
| 1552 | else |
| 1553 | fprintf(stdout, ", %s", (char *) prefix); |
| 1554 | if (URI == NULL) |
| 1555 | fprintf(stdout, ", NULL)\n"); |
| 1556 | else |
| 1557 | fprintf(stdout, ", '%s')\n", (char *) URI); |
| 1558 | } |
| 1559 | |
| 1560 | xmlSAXHandler debugSAX2HandlerStruct = { |
| 1561 | internalSubsetDebug, |
| 1562 | isStandaloneDebug, |
| 1563 | hasInternalSubsetDebug, |
| 1564 | hasExternalSubsetDebug, |
| 1565 | resolveEntityDebug, |
| 1566 | getEntityDebug, |
| 1567 | entityDeclDebug, |
| 1568 | notationDeclDebug, |
| 1569 | attributeDeclDebug, |
| 1570 | elementDeclDebug, |
| 1571 | unparsedEntityDeclDebug, |
| 1572 | setDocumentLocatorDebug, |
| 1573 | startDocumentDebug, |
| 1574 | endDocumentDebug, |
| 1575 | NULL, |
| 1576 | NULL, |
| 1577 | referenceDebug, |
| 1578 | charactersDebug, |
| 1579 | ignorableWhitespaceDebug, |
| 1580 | processingInstructionDebug, |
| 1581 | commentDebug, |
| 1582 | warningDebug, |
| 1583 | errorDebug, |
| 1584 | fatalErrorDebug, |
| 1585 | getParameterEntityDebug, |
| 1586 | cdataBlockDebug, |
| 1587 | externalSubsetDebug, |
| 1588 | XML_SAX2_MAGIC, |
| 1589 | NULL, |
| 1590 | startElementNsDebug, |
| 1591 | endElementNsDebug, |
| 1592 | NULL |
| 1593 | }; |
| 1594 | |
| 1595 | xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct; |
| 1596 | |
| 1597 | static void |
| 1598 | testSAX(const char *filename) { |
| 1599 | xmlSAXHandlerPtr handler; |
| 1600 | const char *user_data = "user_data"; /* mostly for debugging */ |
| 1601 | xmlParserInputBufferPtr buf = NULL; |
| 1602 | xmlParserInputPtr inputStream; |
| 1603 | xmlParserCtxtPtr ctxt = NULL; |
| 1604 | xmlSAXHandlerPtr old_sax = NULL; |
| 1605 | |
| 1606 | callbacks = 0; |
| 1607 | |
| 1608 | if (noout) { |
| 1609 | handler = emptySAXHandler; |
Daniel Veillard | 78dfc9f | 2005-07-10 22:30:30 +0000 | [diff] [blame] | 1610 | #ifdef LIBXML_SAX1_ENABLED |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 1611 | } else if (sax1) { |
| 1612 | handler = debugSAXHandler; |
Daniel Veillard | 78dfc9f | 2005-07-10 22:30:30 +0000 | [diff] [blame] | 1613 | #endif |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 1614 | } else { |
| 1615 | handler = debugSAX2Handler; |
| 1616 | } |
| 1617 | |
| 1618 | /* |
| 1619 | * it's not the simplest code but the most generic in term of I/O |
| 1620 | */ |
| 1621 | buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); |
| 1622 | if (buf == NULL) { |
| 1623 | goto error; |
| 1624 | } |
| 1625 | |
| 1626 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 1627 | if (wxschemas != NULL) { |
| 1628 | int ret; |
| 1629 | xmlSchemaValidCtxtPtr vctxt; |
| 1630 | |
| 1631 | vctxt = xmlSchemaNewValidCtxt(wxschemas); |
| 1632 | xmlSchemaSetValidErrors(vctxt, |
| 1633 | (xmlSchemaValidityErrorFunc) fprintf, |
| 1634 | (xmlSchemaValidityWarningFunc) fprintf, |
| 1635 | stderr); |
| 1636 | |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 1637 | ret = xmlSchemaValidateStream(vctxt, buf, 0, handler, |
| 1638 | (void *)user_data); |
| 1639 | if (repeat == 0) { |
| 1640 | if (ret == 0) { |
| 1641 | fprintf(stderr, "%s validates\n", filename); |
| 1642 | } else if (ret > 0) { |
| 1643 | fprintf(stderr, "%s fails to validate\n", filename); |
| 1644 | progresult = XMLLINT_ERR_VALID; |
| 1645 | } else { |
| 1646 | fprintf(stderr, "%s validation generated an internal error\n", |
| 1647 | filename); |
| 1648 | progresult = XMLLINT_ERR_VALID; |
| 1649 | } |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 1650 | } |
| 1651 | xmlSchemaFreeValidCtxt(vctxt); |
| 1652 | } else |
| 1653 | #endif |
| 1654 | { |
| 1655 | /* |
| 1656 | * Create the parser context amd hook the input |
| 1657 | */ |
| 1658 | ctxt = xmlNewParserCtxt(); |
| 1659 | if (ctxt == NULL) { |
| 1660 | xmlFreeParserInputBuffer(buf); |
| 1661 | goto error; |
| 1662 | } |
| 1663 | old_sax = ctxt->sax; |
| 1664 | ctxt->sax = handler; |
| 1665 | ctxt->userData = (void *) user_data; |
| 1666 | inputStream = xmlNewIOInputStream(ctxt, buf, XML_CHAR_ENCODING_NONE); |
| 1667 | if (inputStream == NULL) { |
| 1668 | xmlFreeParserInputBuffer(buf); |
| 1669 | goto error; |
| 1670 | } |
| 1671 | inputPush(ctxt, inputStream); |
| 1672 | |
| 1673 | /* do the parsing */ |
| 1674 | xmlParseDocument(ctxt); |
| 1675 | |
| 1676 | if (ctxt->myDoc != NULL) { |
| 1677 | fprintf(stderr, "SAX generated a doc !\n"); |
| 1678 | xmlFreeDoc(ctxt->myDoc); |
| 1679 | ctxt->myDoc = NULL; |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | error: |
| 1684 | if (ctxt != NULL) { |
| 1685 | ctxt->sax = old_sax; |
| 1686 | xmlFreeParserCtxt(ctxt); |
| 1687 | } |
| 1688 | } |
| 1689 | |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 1690 | /************************************************************************ |
| 1691 | * * |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1692 | * Stream Test processing * |
| 1693 | * * |
| 1694 | ************************************************************************/ |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 1695 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1696 | static void processNode(xmlTextReaderPtr reader) { |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1697 | const xmlChar *name, *value; |
Daniel Veillard | 16ef800 | 2005-01-31 00:27:50 +0000 | [diff] [blame] | 1698 | int type, empty; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1699 | |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 1700 | type = xmlTextReaderNodeType(reader); |
Daniel Veillard | 16ef800 | 2005-01-31 00:27:50 +0000 | [diff] [blame] | 1701 | empty = xmlTextReaderIsEmptyElement(reader); |
Daniel Veillard | 99737f5 | 2003-03-22 14:55:50 +0000 | [diff] [blame] | 1702 | |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 1703 | if (debug) { |
| 1704 | name = xmlTextReaderConstName(reader); |
| 1705 | if (name == NULL) |
| 1706 | name = BAD_CAST "--"; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1707 | |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 1708 | value = xmlTextReaderConstValue(reader); |
| 1709 | |
| 1710 | |
| 1711 | printf("%d %d %s %d %d", |
| 1712 | xmlTextReaderDepth(reader), |
| 1713 | type, |
| 1714 | name, |
Daniel Veillard | 16ef800 | 2005-01-31 00:27:50 +0000 | [diff] [blame] | 1715 | empty, |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 1716 | xmlTextReaderHasValue(reader)); |
| 1717 | if (value == NULL) |
| 1718 | printf("\n"); |
| 1719 | else { |
| 1720 | printf(" %s\n", value); |
| 1721 | } |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1722 | } |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 1723 | #ifdef LIBXML_PATTERN_ENABLED |
| 1724 | if (patternc) { |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 1725 | xmlChar *path = NULL; |
| 1726 | int match = -1; |
| 1727 | |
| 1728 | if (type == XML_READER_TYPE_ELEMENT) { |
| 1729 | /* do the check only on element start */ |
| 1730 | match = xmlPatternMatch(patternc, xmlTextReaderCurrentNode(reader)); |
| 1731 | |
| 1732 | if (match) { |
| 1733 | path = xmlGetNodePath(xmlTextReaderCurrentNode(reader)); |
| 1734 | printf("Node %s matches pattern %s\n", path, pattern); |
| 1735 | } |
| 1736 | } |
| 1737 | if (patstream != NULL) { |
| 1738 | int ret; |
| 1739 | |
| 1740 | if (type == XML_READER_TYPE_ELEMENT) { |
| 1741 | ret = xmlStreamPush(patstream, |
| 1742 | xmlTextReaderConstLocalName(reader), |
| 1743 | xmlTextReaderConstNamespaceUri(reader)); |
| 1744 | if (ret < 0) { |
| 1745 | fprintf(stderr, "xmlStreamPush() failure\n"); |
| 1746 | xmlFreeStreamCtxt(patstream); |
| 1747 | patstream = NULL; |
| 1748 | } else if (ret != match) { |
| 1749 | if (path == NULL) { |
| 1750 | path = xmlGetNodePath( |
| 1751 | xmlTextReaderCurrentNode(reader)); |
| 1752 | } |
| 1753 | fprintf(stderr, |
| 1754 | "xmlPatternMatch and xmlStreamPush disagree\n"); |
| 1755 | fprintf(stderr, |
| 1756 | " pattern %s node %s\n", |
| 1757 | pattern, path); |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | |
Daniel Veillard | 16ef800 | 2005-01-31 00:27:50 +0000 | [diff] [blame] | 1761 | } |
| 1762 | if ((type == XML_READER_TYPE_END_ELEMENT) || |
| 1763 | ((type == XML_READER_TYPE_ELEMENT) && (empty))) { |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 1764 | ret = xmlStreamPop(patstream); |
| 1765 | if (ret < 0) { |
| 1766 | fprintf(stderr, "xmlStreamPop() failure\n"); |
| 1767 | xmlFreeStreamCtxt(patstream); |
| 1768 | patstream = NULL; |
| 1769 | } |
| 1770 | } |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 1771 | } |
Daniel Veillard | f9d1691 | 2005-01-30 22:36:30 +0000 | [diff] [blame] | 1772 | if (path != NULL) |
| 1773 | xmlFree(path); |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 1774 | } |
| 1775 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | static void streamFile(char *filename) { |
| 1779 | xmlTextReaderPtr reader; |
| 1780 | int ret; |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 1781 | #ifdef HAVE_SYS_MMAN_H |
| 1782 | int fd = -1; |
| 1783 | struct stat info; |
| 1784 | const char *base = NULL; |
| 1785 | xmlParserInputBufferPtr input = NULL; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1786 | |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 1787 | if (memory) { |
| 1788 | if (stat(filename, &info) < 0) |
| 1789 | return; |
| 1790 | if ((fd = open(filename, O_RDONLY)) < 0) |
| 1791 | return; |
| 1792 | base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; |
| 1793 | if (base == (void *) MAP_FAILED) |
| 1794 | return; |
| 1795 | |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1796 | reader = xmlReaderForMemory(base, info.st_size, filename, |
| 1797 | NULL, options); |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 1798 | } else |
| 1799 | #endif |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1800 | reader = xmlReaderForFile(filename, NULL, options); |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 1801 | #ifdef LIBXML_PATTERN_ENABLED |
Daniel Veillard | d4301ab | 2005-02-03 22:24:10 +0000 | [diff] [blame] | 1802 | if (pattern != NULL) { |
| 1803 | patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL); |
| 1804 | if (patternc == NULL) { |
| 1805 | xmlGenericError(xmlGenericErrorContext, |
| 1806 | "Pattern %s failed to compile\n", pattern); |
| 1807 | progresult = XMLLINT_ERR_SCHEMAPAT; |
| 1808 | pattern = NULL; |
| 1809 | } |
| 1810 | } |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 1811 | if (patternc != NULL) { |
| 1812 | patstream = xmlPatternGetStreamCtxt(patternc); |
| 1813 | if (patstream != NULL) { |
| 1814 | ret = xmlStreamPush(patstream, NULL, NULL); |
| 1815 | if (ret < 0) { |
| 1816 | fprintf(stderr, "xmlStreamPush() failure\n"); |
| 1817 | xmlFreeStreamCtxt(patstream); |
| 1818 | patstream = NULL; |
| 1819 | } |
| 1820 | } |
| 1821 | } |
| 1822 | #endif |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1823 | |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 1824 | |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1825 | if (reader != NULL) { |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1826 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1827 | if (valid) |
| 1828 | xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1); |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1829 | else |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1830 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1831 | xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1); |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 1832 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1833 | if (relaxng != NULL) { |
Daniel Veillard | 81514ba | 2003-09-16 23:17:26 +0000 | [diff] [blame] | 1834 | if ((timing) && (!repeat)) { |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1835 | startTimer(); |
| 1836 | } |
| 1837 | ret = xmlTextReaderRelaxNGValidate(reader, relaxng); |
| 1838 | if (ret < 0) { |
| 1839 | xmlGenericError(xmlGenericErrorContext, |
| 1840 | "Relax-NG schema %s failed to compile\n", relaxng); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1841 | progresult = XMLLINT_ERR_SCHEMACOMP; |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1842 | relaxng = NULL; |
| 1843 | } |
Daniel Veillard | 81514ba | 2003-09-16 23:17:26 +0000 | [diff] [blame] | 1844 | if ((timing) && (!repeat)) { |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1845 | endTimer("Compiling the schemas"); |
| 1846 | } |
| 1847 | } |
Daniel Veillard | f10ae12 | 2005-07-10 19:03:16 +0000 | [diff] [blame] | 1848 | if (schema != NULL) { |
| 1849 | if ((timing) && (!repeat)) { |
| 1850 | startTimer(); |
| 1851 | } |
| 1852 | ret = xmlTextReaderSchemaValidate(reader, schema); |
| 1853 | if (ret < 0) { |
| 1854 | xmlGenericError(xmlGenericErrorContext, |
| 1855 | "XSD schema %s failed to compile\n", schema); |
| 1856 | progresult = XMLLINT_ERR_SCHEMACOMP; |
| 1857 | schema = NULL; |
| 1858 | } |
| 1859 | if ((timing) && (!repeat)) { |
| 1860 | endTimer("Compiling the schemas"); |
| 1861 | } |
| 1862 | } |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 1863 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1864 | |
| 1865 | /* |
| 1866 | * Process all nodes in sequence |
| 1867 | */ |
Daniel Veillard | 81514ba | 2003-09-16 23:17:26 +0000 | [diff] [blame] | 1868 | if ((timing) && (!repeat)) { |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1869 | startTimer(); |
| 1870 | } |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1871 | ret = xmlTextReaderRead(reader); |
| 1872 | while (ret == 1) { |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 1873 | if ((debug) |
| 1874 | #ifdef LIBXML_PATTERN_ENABLED |
| 1875 | || (patternc) |
| 1876 | #endif |
| 1877 | ) |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1878 | processNode(reader); |
| 1879 | ret = xmlTextReaderRead(reader); |
| 1880 | } |
Daniel Veillard | 81514ba | 2003-09-16 23:17:26 +0000 | [diff] [blame] | 1881 | if ((timing) && (!repeat)) { |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 1882 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | f54cd53 | 2004-02-25 11:52:31 +0000 | [diff] [blame] | 1883 | if (relaxng != NULL) |
Daniel Veillard | 49138f1 | 2004-02-19 12:58:36 +0000 | [diff] [blame] | 1884 | endTimer("Parsing and validating"); |
| 1885 | else |
Daniel Veillard | f54cd53 | 2004-02-25 11:52:31 +0000 | [diff] [blame] | 1886 | #endif |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1887 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 1888 | if (valid) |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1889 | endTimer("Parsing and validating"); |
| 1890 | else |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1891 | #endif |
Daniel Veillard | f54cd53 | 2004-02-25 11:52:31 +0000 | [diff] [blame] | 1892 | endTimer("Parsing"); |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 1893 | } |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1894 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1895 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | f6bad79 | 2003-04-11 19:38:54 +0000 | [diff] [blame] | 1896 | if (valid) { |
| 1897 | if (xmlTextReaderIsValid(reader) != 1) { |
| 1898 | xmlGenericError(xmlGenericErrorContext, |
| 1899 | "Document %s does not validate\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1900 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | f6bad79 | 2003-04-11 19:38:54 +0000 | [diff] [blame] | 1901 | } |
| 1902 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1903 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 1904 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | f10ae12 | 2005-07-10 19:03:16 +0000 | [diff] [blame] | 1905 | if ((relaxng != NULL) || (schema != NULL)) { |
Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 1906 | if (xmlTextReaderIsValid(reader) != 1) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1907 | fprintf(stderr, "%s fails to validate\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1908 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 1909 | } else { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1910 | fprintf(stderr, "%s validates\n", filename); |
Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 1911 | } |
| 1912 | } |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 1913 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1914 | /* |
| 1915 | * Done, cleanup and status |
| 1916 | */ |
| 1917 | xmlFreeTextReader(reader); |
| 1918 | if (ret != 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1919 | fprintf(stderr, "%s : failed to parse\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1920 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1921 | } |
| 1922 | } else { |
| 1923 | fprintf(stderr, "Unable to open %s\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1924 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1925 | } |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 1926 | #ifdef LIBXML_PATTERN_ENABLED |
| 1927 | if (patstream != NULL) { |
| 1928 | xmlFreeStreamCtxt(patstream); |
| 1929 | patstream = NULL; |
| 1930 | } |
| 1931 | #endif |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 1932 | #ifdef HAVE_SYS_MMAN_H |
| 1933 | if (memory) { |
| 1934 | xmlFreeParserInputBuffer(input); |
| 1935 | munmap((char *) base, info.st_size); |
| 1936 | close(fd); |
| 1937 | } |
| 1938 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1939 | } |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1940 | |
| 1941 | static void walkDoc(xmlDocPtr doc) { |
| 1942 | xmlTextReaderPtr reader; |
| 1943 | int ret; |
| 1944 | |
Daniel Veillard | d4301ab | 2005-02-03 22:24:10 +0000 | [diff] [blame] | 1945 | #ifdef LIBXML_PATTERN_ENABLED |
| 1946 | xmlNodePtr root; |
| 1947 | const xmlChar *namespaces[22]; |
| 1948 | int i; |
| 1949 | xmlNsPtr ns; |
| 1950 | |
| 1951 | root = xmlDocGetRootElement(doc); |
| 1952 | for (ns = root->nsDef, i = 0;ns != NULL && i < 20;ns=ns->next) { |
| 1953 | namespaces[i++] = ns->href; |
| 1954 | namespaces[i++] = ns->prefix; |
| 1955 | } |
| 1956 | namespaces[i++] = NULL; |
| 1957 | namespaces[i++] = NULL; |
| 1958 | |
| 1959 | if (pattern != NULL) { |
| 1960 | patternc = xmlPatterncompile((const xmlChar *) pattern, doc->dict, |
| 1961 | 0, &namespaces[0]); |
| 1962 | if (patternc == NULL) { |
| 1963 | xmlGenericError(xmlGenericErrorContext, |
| 1964 | "Pattern %s failed to compile\n", pattern); |
| 1965 | progresult = XMLLINT_ERR_SCHEMAPAT; |
| 1966 | pattern = NULL; |
| 1967 | } |
| 1968 | } |
Daniel Veillard | 2b2e02d | 2005-02-05 23:20:22 +0000 | [diff] [blame] | 1969 | if (patternc != NULL) { |
| 1970 | patstream = xmlPatternGetStreamCtxt(patternc); |
| 1971 | if (patstream != NULL) { |
| 1972 | ret = xmlStreamPush(patstream, NULL, NULL); |
| 1973 | if (ret < 0) { |
| 1974 | fprintf(stderr, "xmlStreamPush() failure\n"); |
| 1975 | xmlFreeStreamCtxt(patstream); |
| 1976 | patstream = NULL; |
| 1977 | } |
| 1978 | } |
| 1979 | } |
Daniel Veillard | d4301ab | 2005-02-03 22:24:10 +0000 | [diff] [blame] | 1980 | #endif /* LIBXML_PATTERN_ENABLED */ |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1981 | reader = xmlReaderWalker(doc); |
| 1982 | if (reader != NULL) { |
| 1983 | if ((timing) && (!repeat)) { |
| 1984 | startTimer(); |
| 1985 | } |
| 1986 | ret = xmlTextReaderRead(reader); |
| 1987 | while (ret == 1) { |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 1988 | if ((debug) |
| 1989 | #ifdef LIBXML_PATTERN_ENABLED |
| 1990 | || (patternc) |
| 1991 | #endif |
| 1992 | ) |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1993 | processNode(reader); |
| 1994 | ret = xmlTextReaderRead(reader); |
| 1995 | } |
| 1996 | if ((timing) && (!repeat)) { |
| 1997 | endTimer("walking through the doc"); |
| 1998 | } |
| 1999 | xmlFreeTextReader(reader); |
| 2000 | if (ret != 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2001 | fprintf(stderr, "failed to walk through the doc\n"); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2002 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 2003 | } |
| 2004 | } else { |
| 2005 | fprintf(stderr, "Failed to crate a reader from the document\n"); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2006 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 2007 | } |
Daniel Veillard | 2b2e02d | 2005-02-05 23:20:22 +0000 | [diff] [blame] | 2008 | #ifdef LIBXML_PATTERN_ENABLED |
| 2009 | if (patstream != NULL) { |
| 2010 | xmlFreeStreamCtxt(patstream); |
| 2011 | patstream = NULL; |
| 2012 | } |
| 2013 | #endif |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 2014 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2015 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 2016 | |
| 2017 | /************************************************************************ |
| 2018 | * * |
| 2019 | * Tree Test processing * |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2020 | * * |
| 2021 | ************************************************************************/ |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2022 | static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 2023 | xmlDocPtr doc = NULL; |
| 2024 | #ifdef LIBXML_TREE_ENABLED |
| 2025 | xmlDocPtr tmp; |
| 2026 | #endif /* LIBXML_TREE_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2027 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2028 | if ((timing) && (!repeat)) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2029 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2030 | |
| 2031 | |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 2032 | #ifdef LIBXML_TREE_ENABLED |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 2033 | if (filename == NULL) { |
| 2034 | if (generate) { |
| 2035 | xmlNodePtr n; |
| 2036 | |
| 2037 | doc = xmlNewDoc(BAD_CAST "1.0"); |
Daniel Veillard | 95ddcd3 | 2004-10-26 21:53:55 +0000 | [diff] [blame] | 2038 | n = xmlNewDocNode(doc, NULL, BAD_CAST "info", NULL); |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 2039 | xmlNodeSetContent(n, BAD_CAST "abc"); |
| 2040 | xmlDocSetRootElement(doc, n); |
| 2041 | } |
| 2042 | } |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 2043 | #endif /* LIBXML_TREE_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2044 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 2045 | #ifdef LIBXML_PUSH_ENABLED |
William M. Brack | 78637da | 2003-07-31 14:47:38 +0000 | [diff] [blame] | 2046 | else if ((html) && (push)) { |
| 2047 | FILE *f; |
| 2048 | |
William M. Brack | 3403add | 2004-06-27 02:07:51 +0000 | [diff] [blame] | 2049 | #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 2050 | f = fopen(filename, "rb"); |
| 2051 | #else |
| 2052 | f = fopen(filename, "r"); |
| 2053 | #endif |
William M. Brack | 78637da | 2003-07-31 14:47:38 +0000 | [diff] [blame] | 2054 | if (f != NULL) { |
| 2055 | int res, size = 3; |
| 2056 | char chars[4096]; |
| 2057 | htmlParserCtxtPtr ctxt; |
| 2058 | |
| 2059 | /* if (repeat) */ |
| 2060 | size = 4096; |
| 2061 | res = fread(chars, 1, 4, f); |
| 2062 | if (res > 0) { |
| 2063 | ctxt = htmlCreatePushParserCtxt(NULL, NULL, |
William M. Brack | 1d75c8a | 2003-10-27 13:48:16 +0000 | [diff] [blame] | 2064 | chars, res, filename, XML_CHAR_ENCODING_NONE); |
William M. Brack | 78637da | 2003-07-31 14:47:38 +0000 | [diff] [blame] | 2065 | while ((res = fread(chars, 1, size, f)) > 0) { |
| 2066 | htmlParseChunk(ctxt, chars, res, 0); |
| 2067 | } |
| 2068 | htmlParseChunk(ctxt, chars, 0, 1); |
| 2069 | doc = ctxt->myDoc; |
| 2070 | htmlFreeParserCtxt(ctxt); |
| 2071 | } |
| 2072 | fclose(f); |
| 2073 | } |
| 2074 | } |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 2075 | #endif /* LIBXML_PUSH_ENABLED */ |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 2076 | else if (html) { |
Daniel Veillard | 9475a35 | 2003-09-26 12:47:50 +0000 | [diff] [blame] | 2077 | doc = htmlReadFile(filename, NULL, options); |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 2078 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2079 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 2080 | else { |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 2081 | #ifdef LIBXML_PUSH_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2082 | /* |
| 2083 | * build an XML tree from a string; |
| 2084 | */ |
| 2085 | if (push) { |
| 2086 | FILE *f; |
| 2087 | |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 2088 | /* '-' Usually means stdin -<sven@zen.org> */ |
| 2089 | if ((filename[0] == '-') && (filename[1] == 0)) { |
| 2090 | f = stdin; |
| 2091 | } else { |
William M. Brack | 3403add | 2004-06-27 02:07:51 +0000 | [diff] [blame] | 2092 | #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 2093 | f = fopen(filename, "rb"); |
| 2094 | #else |
| 2095 | f = fopen(filename, "r"); |
| 2096 | #endif |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 2097 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2098 | if (f != NULL) { |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 2099 | int ret; |
Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 2100 | int res, size = 1024; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2101 | char chars[1024]; |
| 2102 | xmlParserCtxtPtr ctxt; |
| 2103 | |
Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 2104 | /* if (repeat) size = 1024; */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2105 | res = fread(chars, 1, 4, f); |
| 2106 | if (res > 0) { |
| 2107 | ctxt = xmlCreatePushParserCtxt(NULL, NULL, |
| 2108 | chars, res, filename); |
Daniel Veillard | 500a1de | 2004-03-22 15:22:58 +0000 | [diff] [blame] | 2109 | xmlCtxtUseOptions(ctxt, options); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2110 | while ((res = fread(chars, 1, size, f)) > 0) { |
| 2111 | xmlParseChunk(ctxt, chars, res, 0); |
| 2112 | } |
| 2113 | xmlParseChunk(ctxt, chars, 0, 1); |
| 2114 | doc = ctxt->myDoc; |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 2115 | ret = ctxt->wellFormed; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2116 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 2117 | if (!ret) { |
| 2118 | xmlFreeDoc(doc); |
| 2119 | doc = NULL; |
| 2120 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2121 | } |
| 2122 | } |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 2123 | } else |
| 2124 | #endif /* LIBXML_PUSH_ENABLED */ |
| 2125 | if (testIO) { |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 2126 | if ((filename[0] == '-') && (filename[1] == 0)) { |
Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 2127 | doc = xmlReadFd(0, NULL, NULL, options); |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 2128 | } else { |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2129 | FILE *f; |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 2130 | |
William M. Brack | 3403add | 2004-06-27 02:07:51 +0000 | [diff] [blame] | 2131 | #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 2132 | f = fopen(filename, "rb"); |
| 2133 | #else |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2134 | f = fopen(filename, "r"); |
William M. Brack | 3403add | 2004-06-27 02:07:51 +0000 | [diff] [blame] | 2135 | #endif |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2136 | if (f != NULL) { |
| 2137 | if (rectxt == NULL) |
| 2138 | doc = xmlReadIO((xmlInputReadCallback) myRead, |
| 2139 | (xmlInputCloseCallback) myClose, f, |
Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 2140 | filename, NULL, options); |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2141 | else |
| 2142 | doc = xmlCtxtReadIO(rectxt, |
| 2143 | (xmlInputReadCallback) myRead, |
| 2144 | (xmlInputCloseCallback) myClose, f, |
Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 2145 | filename, NULL, options); |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2146 | } else |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 2147 | doc = NULL; |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 2148 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2149 | } else if (htmlout) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2150 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2151 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2152 | if (rectxt == NULL) |
| 2153 | ctxt = xmlNewParserCtxt(); |
| 2154 | else |
| 2155 | ctxt = rectxt; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 2156 | if (ctxt == NULL) { |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2157 | doc = NULL; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 2158 | } else { |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2159 | ctxt->sax->error = xmlHTMLError; |
| 2160 | ctxt->sax->warning = xmlHTMLWarning; |
| 2161 | ctxt->vctxt.error = xmlHTMLValidityError; |
| 2162 | ctxt->vctxt.warning = xmlHTMLValidityWarning; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2163 | |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2164 | doc = xmlCtxtReadFile(ctxt, filename, NULL, options); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2165 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2166 | if (rectxt == NULL) |
| 2167 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2168 | } |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 2169 | #ifdef HAVE_SYS_MMAN_H |
| 2170 | } else if (memory) { |
| 2171 | int fd; |
| 2172 | struct stat info; |
| 2173 | const char *base; |
| 2174 | if (stat(filename, &info) < 0) |
| 2175 | return; |
| 2176 | if ((fd = open(filename, O_RDONLY)) < 0) |
| 2177 | return; |
| 2178 | base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; |
Daniel Veillard | 2957936 | 2000-08-14 17:57:48 +0000 | [diff] [blame] | 2179 | if (base == (void *) MAP_FAILED) |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 2180 | return; |
| 2181 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2182 | if (rectxt == NULL) |
Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 2183 | doc = xmlReadMemory((char *) base, info.st_size, |
| 2184 | filename, NULL, options); |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2185 | else |
Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 2186 | doc = xmlCtxtReadMemory(rectxt, (char *) base, info.st_size, |
| 2187 | filename, NULL, options); |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2188 | |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 2189 | munmap((char *) base, info.st_size); |
| 2190 | #endif |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2191 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 2192 | } else if (valid) { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2193 | xmlParserCtxtPtr ctxt = NULL; |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 2194 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2195 | if (rectxt == NULL) |
| 2196 | ctxt = xmlNewParserCtxt(); |
| 2197 | else |
| 2198 | ctxt = rectxt; |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 2199 | if (ctxt == NULL) { |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2200 | doc = NULL; |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 2201 | } else { |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2202 | doc = xmlCtxtReadFile(ctxt, filename, NULL, options); |
| 2203 | |
| 2204 | if (ctxt->valid == 0) |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2205 | progresult = XMLLINT_ERR_RDFILE; |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2206 | if (rectxt == NULL) |
| 2207 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 2208 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2209 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 2210 | } else { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2211 | if (rectxt != NULL) |
| 2212 | doc = xmlCtxtReadFile(rectxt, filename, NULL, options); |
Daniel Veillard | 81562d2 | 2005-06-15 13:27:56 +0000 | [diff] [blame] | 2213 | else { |
| 2214 | #ifdef LIBXML_SAX1_ENABLED |
| 2215 | if (sax1) |
| 2216 | doc = xmlParseFile(filename); |
| 2217 | else |
| 2218 | #endif /* LIBXML_SAX1_ENABLED */ |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2219 | doc = xmlReadFile(filename, NULL, options); |
Daniel Veillard | 81562d2 | 2005-06-15 13:27:56 +0000 | [diff] [blame] | 2220 | } |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 2221 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2222 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2223 | |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 2224 | /* |
| 2225 | * If we don't have a document we might as well give up. Do we |
| 2226 | * want an error message here? <sven@zen.org> */ |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 2227 | if (doc == NULL) { |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2228 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 2229 | return; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2232 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2233 | endTimer("Parsing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 2236 | /* |
| 2237 | * Remove DOCTYPE nodes |
| 2238 | */ |
| 2239 | if (dropdtd) { |
| 2240 | xmlDtdPtr dtd; |
| 2241 | |
| 2242 | dtd = xmlGetIntSubset(doc); |
| 2243 | if (dtd != NULL) { |
| 2244 | xmlUnlinkNode((xmlNodePtr)dtd); |
| 2245 | xmlFreeDtd(dtd); |
| 2246 | } |
| 2247 | } |
| 2248 | |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 2249 | #ifdef LIBXML_XINCLUDE_ENABLED |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2250 | if (xinclude) { |
| 2251 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2252 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2253 | } |
William M. Brack | 4e1c2db | 2005-02-11 10:58:55 +0000 | [diff] [blame] | 2254 | if (xmlXIncludeProcessFlags(doc, options) < 0) |
| 2255 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2256 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2257 | endTimer("Xinclude processing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2258 | } |
| 2259 | } |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 2260 | #endif |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 2261 | |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2262 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 2263 | #ifdef LIBXML_XPATH_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2264 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2265 | * shell interaction |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2266 | */ |
| 2267 | if (shell) |
| 2268 | xmlShell(doc, filename, xmlShellReadline, stdout); |
| 2269 | #endif |
Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 2270 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2271 | |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 2272 | #ifdef LIBXML_TREE_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2273 | /* |
| 2274 | * test intermediate copy if needed. |
| 2275 | */ |
| 2276 | if (copy) { |
| 2277 | tmp = doc; |
Daniel Veillard | 4edd3ed | 2004-09-20 20:03:01 +0000 | [diff] [blame] | 2278 | if (timing) { |
| 2279 | startTimer(); |
| 2280 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2281 | doc = xmlCopyDoc(doc, 1); |
Daniel Veillard | 4edd3ed | 2004-09-20 20:03:01 +0000 | [diff] [blame] | 2282 | if (timing) { |
| 2283 | endTimer("Copying"); |
| 2284 | } |
| 2285 | if (timing) { |
| 2286 | startTimer(); |
| 2287 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2288 | xmlFreeDoc(tmp); |
Daniel Veillard | 4edd3ed | 2004-09-20 20:03:01 +0000 | [diff] [blame] | 2289 | if (timing) { |
| 2290 | endTimer("Freeing original"); |
| 2291 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2292 | } |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 2293 | #endif /* LIBXML_TREE_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2294 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2295 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2296 | if ((insert) && (!html)) { |
| 2297 | const xmlChar* list[256]; |
| 2298 | int nb, i; |
| 2299 | xmlNodePtr node; |
| 2300 | |
| 2301 | if (doc->children != NULL) { |
| 2302 | node = doc->children; |
| 2303 | while ((node != NULL) && (node->last == NULL)) node = node->next; |
| 2304 | if (node != NULL) { |
| 2305 | nb = xmlValidGetValidElements(node->last, NULL, list, 256); |
| 2306 | if (nb < 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2307 | fprintf(stderr, "could not get valid list of elements\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2308 | } else if (nb == 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2309 | fprintf(stderr, "No element can be inserted under root\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2310 | } else { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2311 | fprintf(stderr, "%d element types can be inserted under root:\n", |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2312 | nb); |
| 2313 | for (i = 0;i < nb;i++) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2314 | fprintf(stderr, "%s\n", (char *) list[i]); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2315 | } |
| 2316 | } |
| 2317 | } |
| 2318 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2319 | }else |
| 2320 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 2321 | #ifdef LIBXML_READER_ENABLED |
| 2322 | if (walker) { |
| 2323 | walkDoc(doc); |
| 2324 | } |
| 2325 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2326 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2327 | if (noout == 0) { |
Daniel Veillard | 3df0118 | 2003-12-10 10:17:51 +0000 | [diff] [blame] | 2328 | int ret; |
| 2329 | |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2330 | /* |
| 2331 | * print it. |
| 2332 | */ |
| 2333 | #ifdef LIBXML_DEBUG_ENABLED |
| 2334 | if (!debug) { |
| 2335 | #endif |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2336 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2337 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2338 | } |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 2339 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 2340 | if ((html) && (!xmlout)) { |
| 2341 | if (compress) { |
| 2342 | htmlSaveFile(output ? output : "-", doc); |
| 2343 | } |
| 2344 | else if (encoding != NULL) { |
| 2345 | if ( format ) { |
| 2346 | htmlSaveFileFormat(output ? output : "-", doc, encoding, 1); |
| 2347 | } |
| 2348 | else { |
| 2349 | htmlSaveFileFormat(output ? output : "-", doc, encoding, 0); |
| 2350 | } |
| 2351 | } |
| 2352 | else if (format) { |
| 2353 | htmlSaveFileFormat(output ? output : "-", doc, NULL, 1); |
| 2354 | } |
| 2355 | else { |
| 2356 | FILE *out; |
| 2357 | if (output == NULL) |
| 2358 | out = stdout; |
| 2359 | else { |
| 2360 | out = fopen(output,"wb"); |
| 2361 | } |
| 2362 | if (out != NULL) { |
| 2363 | if (htmlDocDump(out, doc) < 0) |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2364 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 2365 | |
| 2366 | if (output != NULL) |
| 2367 | fclose(out); |
| 2368 | } else { |
| 2369 | fprintf(stderr, "failed to open %s\n", output); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2370 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 2371 | } |
| 2372 | } |
| 2373 | if ((timing) && (!repeat)) { |
| 2374 | endTimer("Saving"); |
| 2375 | } |
| 2376 | } else |
| 2377 | #endif |
Daniel Veillard | 25048d8 | 2004-08-14 22:37:54 +0000 | [diff] [blame] | 2378 | #ifdef LIBXML_C14N_ENABLED |
| 2379 | if (canonical) { |
| 2380 | xmlChar *result = NULL; |
| 2381 | int size; |
| 2382 | |
| 2383 | size = xmlC14NDocDumpMemory(doc, NULL, 0, NULL, 1, &result); |
| 2384 | if (size >= 0) { |
| 2385 | write(1, result, size); |
| 2386 | xmlFree(result); |
| 2387 | } else { |
| 2388 | fprintf(stderr, "Failed to canonicalize\n"); |
| 2389 | progresult = XMLLINT_ERR_OUT; |
| 2390 | } |
| 2391 | } else |
Aleksey Sanin | 2650df1 | 2005-06-06 17:16:50 +0000 | [diff] [blame] | 2392 | if (exc_canonical) { |
| 2393 | xmlChar *result = NULL; |
| 2394 | int size; |
| 2395 | |
| 2396 | size = xmlC14NDocDumpMemory(doc, NULL, 1, NULL, 1, &result); |
| 2397 | if (size >= 0) { |
| 2398 | write(1, result, size); |
| 2399 | xmlFree(result); |
| 2400 | } else { |
| 2401 | fprintf(stderr, "Failed to canonicalize\n"); |
| 2402 | progresult = XMLLINT_ERR_OUT; |
| 2403 | } |
| 2404 | } else |
Daniel Veillard | 25048d8 | 2004-08-14 22:37:54 +0000 | [diff] [blame] | 2405 | #endif |
Daniel Veillard | 3b2c261 | 2001-04-04 00:09:00 +0000 | [diff] [blame] | 2406 | #ifdef HAVE_SYS_MMAN_H |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 2407 | if (memory) { |
| 2408 | xmlChar *result; |
| 2409 | int len; |
| 2410 | |
| 2411 | if (encoding != NULL) { |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 2412 | if ( format ) { |
| 2413 | xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1); |
| 2414 | } else { |
| 2415 | xmlDocDumpMemoryEnc(doc, &result, &len, encoding); |
| 2416 | } |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 2417 | } else { |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 2418 | if (format) |
| 2419 | xmlDocDumpFormatMemory(doc, &result, &len, 1); |
| 2420 | else |
| 2421 | xmlDocDumpMemory(doc, &result, &len); |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 2422 | } |
| 2423 | if (result == NULL) { |
| 2424 | fprintf(stderr, "Failed to save\n"); |
Daniel Veillard | 25048d8 | 2004-08-14 22:37:54 +0000 | [diff] [blame] | 2425 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 2426 | } else { |
| 2427 | write(1, result, len); |
| 2428 | xmlFree(result); |
| 2429 | } |
Daniel Veillard | 3b2c261 | 2001-04-04 00:09:00 +0000 | [diff] [blame] | 2430 | } else |
| 2431 | #endif /* HAVE_SYS_MMAN_H */ |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2432 | if (compress) { |
| 2433 | xmlSaveFile(output ? output : "-", doc); |
| 2434 | } |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 2435 | else if (encoding != NULL) { |
| 2436 | if ( format ) { |
Daniel Veillard | 3df0118 | 2003-12-10 10:17:51 +0000 | [diff] [blame] | 2437 | ret = xmlSaveFormatFileEnc(output ? output : "-", doc, |
| 2438 | encoding, 1); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2439 | } |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 2440 | else { |
Daniel Veillard | 3df0118 | 2003-12-10 10:17:51 +0000 | [diff] [blame] | 2441 | ret = xmlSaveFileEnc(output ? output : "-", doc, encoding); |
| 2442 | } |
| 2443 | if (ret < 0) { |
| 2444 | fprintf(stderr, "failed save to %s\n", |
| 2445 | output ? output : "-"); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2446 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 2447 | } |
| 2448 | } |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2449 | else if (format) { |
Daniel Veillard | 3df0118 | 2003-12-10 10:17:51 +0000 | [diff] [blame] | 2450 | ret = xmlSaveFormatFile(output ? output : "-", doc, 1); |
| 2451 | if (ret < 0) { |
| 2452 | fprintf(stderr, "failed save to %s\n", |
| 2453 | output ? output : "-"); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2454 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 3df0118 | 2003-12-10 10:17:51 +0000 | [diff] [blame] | 2455 | } |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2456 | } |
| 2457 | else { |
| 2458 | FILE *out; |
| 2459 | if (output == NULL) |
| 2460 | out = stdout; |
| 2461 | else { |
| 2462 | out = fopen(output,"wb"); |
| 2463 | } |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 2464 | if (out != NULL) { |
Daniel Veillard | 828ce83 | 2003-10-08 19:19:10 +0000 | [diff] [blame] | 2465 | if (xmlDocDump(out, doc) < 0) |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2466 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2467 | |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 2468 | if (output != NULL) |
| 2469 | fclose(out); |
| 2470 | } else { |
| 2471 | fprintf(stderr, "failed to open %s\n", output); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2472 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 2473 | } |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2474 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2475 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2476 | endTimer("Saving"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2477 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2478 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 2479 | } else { |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2480 | FILE *out; |
| 2481 | if (output == NULL) |
| 2482 | out = stdout; |
| 2483 | else { |
| 2484 | out = fopen(output,"wb"); |
| 2485 | } |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 2486 | if (out != NULL) { |
| 2487 | xmlDebugDumpDocument(out, doc); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2488 | |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 2489 | if (output != NULL) |
| 2490 | fclose(out); |
| 2491 | } else { |
| 2492 | fprintf(stderr, "failed to open %s\n", output); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2493 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 2494 | } |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 2495 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2496 | #endif |
| 2497 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2498 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2499 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2500 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2501 | /* |
| 2502 | * A posteriori validation test |
| 2503 | */ |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 2504 | if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) { |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 2505 | xmlDtdPtr dtd; |
| 2506 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2507 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2508 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2509 | } |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 2510 | if (dtdvalid != NULL) |
| 2511 | dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid); |
| 2512 | else |
| 2513 | dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2514 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2515 | endTimer("Parsing DTD"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2516 | } |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 2517 | if (dtd == NULL) { |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 2518 | if (dtdvalid != NULL) |
| 2519 | xmlGenericError(xmlGenericErrorContext, |
| 2520 | "Could not parse DTD %s\n", dtdvalid); |
| 2521 | else |
| 2522 | xmlGenericError(xmlGenericErrorContext, |
| 2523 | "Could not parse DTD %s\n", dtdvalidfpi); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2524 | progresult = XMLLINT_ERR_DTD; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 2525 | } else { |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 2526 | xmlValidCtxtPtr cvp; |
| 2527 | |
| 2528 | if ((cvp = xmlNewValidCtxt()) == NULL) { |
| 2529 | xmlGenericError(xmlGenericErrorContext, |
| 2530 | "Couldn't allocate validation context\n"); |
| 2531 | exit(-1); |
| 2532 | } |
| 2533 | cvp->userData = (void *) stderr; |
| 2534 | cvp->error = (xmlValidityErrorFunc) fprintf; |
| 2535 | cvp->warning = (xmlValidityWarningFunc) fprintf; |
| 2536 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2537 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2538 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2539 | } |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 2540 | if (!xmlValidateDtd(cvp, doc, dtd)) { |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 2541 | if (dtdvalid != NULL) |
| 2542 | xmlGenericError(xmlGenericErrorContext, |
| 2543 | "Document %s does not validate against %s\n", |
| 2544 | filename, dtdvalid); |
| 2545 | else |
| 2546 | xmlGenericError(xmlGenericErrorContext, |
| 2547 | "Document %s does not validate against %s\n", |
| 2548 | filename, dtdvalidfpi); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2549 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 2550 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2551 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2552 | endTimer("Validating against DTD"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2553 | } |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 2554 | xmlFreeValidCtxt(cvp); |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 2555 | xmlFreeDtd(dtd); |
| 2556 | } |
| 2557 | } else if (postvalid) { |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 2558 | xmlValidCtxtPtr cvp; |
| 2559 | |
| 2560 | if ((cvp = xmlNewValidCtxt()) == NULL) { |
| 2561 | xmlGenericError(xmlGenericErrorContext, |
| 2562 | "Couldn't allocate validation context\n"); |
| 2563 | exit(-1); |
| 2564 | } |
| 2565 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2566 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2567 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2568 | } |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 2569 | cvp->userData = (void *) stderr; |
| 2570 | cvp->error = (xmlValidityErrorFunc) fprintf; |
| 2571 | cvp->warning = (xmlValidityWarningFunc) fprintf; |
| 2572 | if (!xmlValidateDocument(cvp, doc)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 2573 | xmlGenericError(xmlGenericErrorContext, |
| 2574 | "Document %s does not validate\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2575 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 2576 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2577 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2578 | endTimer("Validating"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2579 | } |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 2580 | xmlFreeValidCtxt(cvp); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2581 | } |
| 2582 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2583 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2584 | if (relaxngschemas != NULL) { |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2585 | xmlRelaxNGValidCtxtPtr ctxt; |
| 2586 | int ret; |
| 2587 | |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 2588 | if ((timing) && (!repeat)) { |
| 2589 | startTimer(); |
| 2590 | } |
| 2591 | |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2592 | ctxt = xmlRelaxNGNewValidCtxt(relaxngschemas); |
| 2593 | xmlRelaxNGSetValidErrors(ctxt, |
| 2594 | (xmlRelaxNGValidityErrorFunc) fprintf, |
| 2595 | (xmlRelaxNGValidityWarningFunc) fprintf, |
| 2596 | stderr); |
| 2597 | ret = xmlRelaxNGValidateDoc(ctxt, doc); |
| 2598 | if (ret == 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2599 | fprintf(stderr, "%s validates\n", filename); |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2600 | } else if (ret > 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2601 | fprintf(stderr, "%s fails to validate\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2602 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2603 | } else { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2604 | fprintf(stderr, "%s validation generated an internal error\n", |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2605 | filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2606 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2607 | } |
| 2608 | xmlRelaxNGFreeValidCtxt(ctxt); |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 2609 | if ((timing) && (!repeat)) { |
| 2610 | endTimer("Validating"); |
| 2611 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 2612 | } else if (wxschemas != NULL) { |
| 2613 | xmlSchemaValidCtxtPtr ctxt; |
| 2614 | int ret; |
| 2615 | |
| 2616 | if ((timing) && (!repeat)) { |
| 2617 | startTimer(); |
| 2618 | } |
| 2619 | |
| 2620 | ctxt = xmlSchemaNewValidCtxt(wxschemas); |
| 2621 | xmlSchemaSetValidErrors(ctxt, |
| 2622 | (xmlSchemaValidityErrorFunc) fprintf, |
| 2623 | (xmlSchemaValidityWarningFunc) fprintf, |
| 2624 | stderr); |
| 2625 | ret = xmlSchemaValidateDoc(ctxt, doc); |
| 2626 | if (ret == 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2627 | fprintf(stderr, "%s validates\n", filename); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 2628 | } else if (ret > 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2629 | fprintf(stderr, "%s fails to validate\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2630 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 2631 | } else { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 2632 | fprintf(stderr, "%s validation generated an internal error\n", |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 2633 | filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2634 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 2635 | } |
| 2636 | xmlSchemaFreeValidCtxt(ctxt); |
| 2637 | if ((timing) && (!repeat)) { |
| 2638 | endTimer("Validating"); |
| 2639 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2640 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2641 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2642 | |
| 2643 | #ifdef LIBXML_DEBUG_ENABLED |
| 2644 | if ((debugent) && (!html)) |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 2645 | xmlDebugDumpEntities(stderr, doc); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2646 | #endif |
| 2647 | |
| 2648 | /* |
| 2649 | * free it. |
| 2650 | */ |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2651 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2652 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2653 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2654 | xmlFreeDoc(doc); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2655 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2656 | endTimer("Freeing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2657 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2660 | /************************************************************************ |
| 2661 | * * |
| 2662 | * Usage and Main * |
| 2663 | * * |
| 2664 | ************************************************************************/ |
| 2665 | |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 2666 | static void showVersion(const char *name) { |
| 2667 | fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion); |
| 2668 | fprintf(stderr, " compiled with: "); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2669 | #ifdef LIBXML_VALID_ENABLED |
| 2670 | fprintf(stderr, "DTDValid "); |
| 2671 | #endif |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 2672 | #ifdef LIBXML_FTP_ENABLED |
| 2673 | fprintf(stderr, "FTP "); |
| 2674 | #endif |
| 2675 | #ifdef LIBXML_HTTP_ENABLED |
| 2676 | fprintf(stderr, "HTTP "); |
| 2677 | #endif |
| 2678 | #ifdef LIBXML_HTML_ENABLED |
| 2679 | fprintf(stderr, "HTML "); |
| 2680 | #endif |
| 2681 | #ifdef LIBXML_C14N_ENABLED |
| 2682 | fprintf(stderr, "C14N "); |
| 2683 | #endif |
| 2684 | #ifdef LIBXML_CATALOG_ENABLED |
| 2685 | fprintf(stderr, "Catalog "); |
| 2686 | #endif |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 2687 | #ifdef LIBXML_XPATH_ENABLED |
| 2688 | fprintf(stderr, "XPath "); |
| 2689 | #endif |
| 2690 | #ifdef LIBXML_XPTR_ENABLED |
| 2691 | fprintf(stderr, "XPointer "); |
| 2692 | #endif |
| 2693 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 2694 | fprintf(stderr, "XInclude "); |
| 2695 | #endif |
| 2696 | #ifdef LIBXML_ICONV_ENABLED |
| 2697 | fprintf(stderr, "Iconv "); |
| 2698 | #endif |
| 2699 | #ifdef DEBUG_MEMORY_LOCATION |
| 2700 | fprintf(stderr, "MemDebug "); |
| 2701 | #endif |
| 2702 | #ifdef LIBXML_UNICODE_ENABLED |
| 2703 | fprintf(stderr, "Unicode "); |
| 2704 | #endif |
| 2705 | #ifdef LIBXML_REGEXP_ENABLED |
| 2706 | fprintf(stderr, "Regexps "); |
| 2707 | #endif |
| 2708 | #ifdef LIBXML_AUTOMATA_ENABLED |
| 2709 | fprintf(stderr, "Automata "); |
| 2710 | #endif |
| 2711 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 2712 | fprintf(stderr, "Schemas "); |
| 2713 | #endif |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 2714 | #ifdef LIBXML_MODULES_ENABLED |
| 2715 | fprintf(stderr, "Modules "); |
| 2716 | #endif |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 2717 | fprintf(stderr, "\n"); |
| 2718 | } |
| 2719 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2720 | static void usage(const char *name) { |
| 2721 | printf("Usage : %s [options] XMLfiles ...\n", name); |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2722 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2723 | 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] | 2724 | #else |
| 2725 | printf("\tParse the XML files\n"); |
| 2726 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2727 | printf("\t--version : display the version of the XML library used\n"); |
| 2728 | #ifdef LIBXML_DEBUG_ENABLED |
| 2729 | printf("\t--debug : dump a debug tree of the in-memory document\n"); |
| 2730 | printf("\t--shell : run a navigating shell\n"); |
| 2731 | printf("\t--debugent : debug the entities defined in the document\n"); |
Daniel Veillard | 8326e73 | 2003-01-07 00:19:07 +0000 | [diff] [blame] | 2732 | #else |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2733 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 8326e73 | 2003-01-07 00:19:07 +0000 | [diff] [blame] | 2734 | printf("\t--debug : dump the nodes content when using --stream\n"); |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2735 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2736 | #endif |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 2737 | #ifdef LIBXML_TREE_ENABLED |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2738 | printf("\t--copy : used to test the internal copy implementation\n"); |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 2739 | #endif /* LIBXML_TREE_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2740 | printf("\t--recover : output what was parsable on broken XML documents\n"); |
| 2741 | printf("\t--noent : substitute entity references by their value\n"); |
| 2742 | printf("\t--noout : don't output the result tree\n"); |
Daniel Veillard | 0bff36d | 2004-08-31 09:37:03 +0000 | [diff] [blame] | 2743 | printf("\t--path 'paths': provide a set of paths for resources\n"); |
| 2744 | printf("\t--load-trace : print trace of all external entites loaded\n"); |
Daniel Veillard | e8b09e4 | 2003-05-13 22:14:13 +0000 | [diff] [blame] | 2745 | printf("\t--nonet : refuse to fetch DTDs or entities over network\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2746 | printf("\t--htmlout : output results as HTML\n"); |
Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 2747 | printf("\t--nowrap : do not put HTML doc wrapper\n"); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2748 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2749 | printf("\t--valid : validate the document in addition to std well-formed check\n"); |
| 2750 | printf("\t--postvalid : do a posteriori validation, i.e after parsing\n"); |
| 2751 | 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] | 2752 | 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] | 2753 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2754 | printf("\t--timing : print some timings\n"); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2755 | 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] | 2756 | printf("\t--repeat : repeat 100 times, for timing or profiling\n"); |
| 2757 | printf("\t--insert : ad-hoc test for valid insertions\n"); |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2758 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2759 | #ifdef HAVE_ZLIB_H |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2760 | printf("\t--compress : turn on gzip compression of output\n"); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2761 | #endif |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2762 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2763 | #ifdef LIBXML_HTML_ENABLED |
| 2764 | printf("\t--html : use the HTML parser\n"); |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 2765 | 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] | 2766 | #endif |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 2767 | #ifdef LIBXML_PUSH_ENABLED |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2768 | printf("\t--push : use the push mode of the parser\n"); |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 2769 | #endif /* LIBXML_PUSH_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2770 | #ifdef HAVE_SYS_MMAN_H |
| 2771 | printf("\t--memory : parse from memory\n"); |
| 2772 | #endif |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 2773 | printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2774 | printf("\t--nowarning : do not emit warnings from parser/validator\n"); |
| 2775 | printf("\t--noblanks : drop (ignorable?) blanks spaces\n"); |
Daniel Veillard | dca8cc7 | 2003-09-26 13:53:14 +0000 | [diff] [blame] | 2776 | printf("\t--nocdata : replace cdata section with text nodes\n"); |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2777 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 2778 | printf("\t--format : reformat/reindent the input\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2779 | printf("\t--encode encoding : output in the given encoding\n"); |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2780 | printf("\t--dropdtd : remove the DOCTYPE of the input docs\n"); |
| 2781 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Aleksey Sanin | 2650df1 | 2005-06-06 17:16:50 +0000 | [diff] [blame] | 2782 | printf("\t--c14n : save in W3C canonical format (with comments)\n"); |
| 2783 | 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] | 2784 | #ifdef LIBXML_C14N_ENABLED |
| 2785 | #endif /* LIBXML_C14N_ENABLED */ |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2786 | printf("\t--nsclean : remove redundant namespace declarations\n"); |
| 2787 | printf("\t--testIO : test user I/O support\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2788 | #ifdef LIBXML_CATALOG_ENABLED |
Daniel Veillard | bd9b0e8 | 2001-11-26 10:32:08 +0000 | [diff] [blame] | 2789 | printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n"); |
| 2790 | printf("\t otherwise XML Catalogs starting from \n"); |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 2791 | printf("\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG); |
Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 2792 | printf("\t--nocatalogs: deactivate all catalogs\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2793 | #endif |
| 2794 | printf("\t--auto : generate a small doc on the fly\n"); |
| 2795 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 2796 | printf("\t--xinclude : do XInclude processing\n"); |
Daniel Veillard | c14c389 | 2004-08-16 12:34:50 +0000 | [diff] [blame] | 2797 | printf("\t--noxincludenode : same but do not generate XInclude nodes\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2798 | #endif |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2799 | printf("\t--loaddtd : fetch external DTD\n"); |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 2800 | printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n"); |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2801 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 2802 | 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] | 2803 | 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] | 2804 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 2805 | #ifdef LIBXML_PATTERN_ENABLED |
| 2806 | printf("\t--pattern pattern_value : test the pattern support\n"); |
| 2807 | #endif |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 2808 | printf("\t--chkregister : verify the node registration code\n"); |
Daniel Veillard | ef4d3bc | 2003-02-07 12:38:22 +0000 | [diff] [blame] | 2809 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2810 | printf("\t--relaxng schema : do RelaxNG validation against the schema\n"); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 2811 | printf("\t--schema schema : do validation against the WXS schema\n"); |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2812 | #endif |
Daniel Veillard | 971771e | 2005-07-09 17:32:57 +0000 | [diff] [blame] | 2813 | #ifdef LIBXML_SAX1_ENABLED |
| 2814 | printf("\t--sax1: use the old SAX1 interfaces for processing\n"); |
| 2815 | #endif |
| 2816 | printf("\t--sax: do not build a tree but work just at the SAX level\n"); |
| 2817 | |
Daniel Veillard | a42f25f | 2002-01-25 14:15:40 +0000 | [diff] [blame] | 2818 | printf("\nLibxml project home page: http://xmlsoft.org/\n"); |
| 2819 | 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] | 2820 | } |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 2821 | |
| 2822 | static void registerNode(xmlNodePtr node) |
| 2823 | { |
| 2824 | node->_private = malloc(sizeof(long)); |
| 2825 | *(long*)node->_private = (long) 0x81726354; |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 2826 | nbregister++; |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | static void deregisterNode(xmlNodePtr node) |
| 2830 | { |
| 2831 | assert(node->_private != NULL); |
| 2832 | assert(*(long*)node->_private == (long) 0x81726354); |
| 2833 | free(node->_private); |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 2834 | nbregister--; |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 2835 | } |
| 2836 | |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 2837 | int |
| 2838 | main(int argc, char **argv) { |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 2839 | int i, acount; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2840 | int files = 0; |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 2841 | int version = 0; |
Aleksey Sanin | 693c9bc | 2003-03-09 22:36:52 +0000 | [diff] [blame] | 2842 | const char* indent; |
| 2843 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2844 | if (argc <= 1) { |
| 2845 | usage(argv[0]); |
| 2846 | return(1); |
| 2847 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2848 | LIBXML_TEST_VERSION |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2849 | for (i = 1; i < argc ; i++) { |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2850 | if (!strcmp(argv[i], "-")) |
| 2851 | break; |
| 2852 | |
| 2853 | if (argv[i][0] != '-') |
| 2854 | continue; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2855 | if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) |
| 2856 | debug++; |
Daniel Veillard | 56ada1d | 2003-01-07 11:17:25 +0000 | [diff] [blame] | 2857 | else |
| 2858 | #ifdef LIBXML_DEBUG_ENABLED |
| 2859 | if ((!strcmp(argv[i], "-shell")) || |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2860 | (!strcmp(argv[i], "--shell"))) { |
| 2861 | shell++; |
| 2862 | noout = 1; |
| 2863 | } else |
| 2864 | #endif |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 2865 | #ifdef LIBXML_TREE_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2866 | if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) |
| 2867 | copy++; |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 2868 | else |
| 2869 | #endif /* LIBXML_TREE_ENABLED */ |
| 2870 | if ((!strcmp(argv[i], "-recover")) || |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2871 | (!strcmp(argv[i], "--recover"))) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2872 | recovery++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2873 | options |= XML_PARSE_RECOVER; |
| 2874 | } else if ((!strcmp(argv[i], "-noent")) || |
| 2875 | (!strcmp(argv[i], "--noent"))) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2876 | noent++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2877 | options |= XML_PARSE_NOENT; |
Daniel Veillard | dca8cc7 | 2003-09-26 13:53:14 +0000 | [diff] [blame] | 2878 | } else if ((!strcmp(argv[i], "-nsclean")) || |
| 2879 | (!strcmp(argv[i], "--nsclean"))) { |
| 2880 | options |= XML_PARSE_NSCLEAN; |
| 2881 | } else if ((!strcmp(argv[i], "-nocdata")) || |
| 2882 | (!strcmp(argv[i], "--nocdata"))) { |
| 2883 | options |= XML_PARSE_NOCDATA; |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2884 | } else if ((!strcmp(argv[i], "-nodict")) || |
| 2885 | (!strcmp(argv[i], "--nodict"))) { |
| 2886 | options |= XML_PARSE_NODICT; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2887 | } else if ((!strcmp(argv[i], "-version")) || |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 2888 | (!strcmp(argv[i], "--version"))) { |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 2889 | showVersion(argv[0]); |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 2890 | version = 1; |
| 2891 | } else if ((!strcmp(argv[i], "-noout")) || |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2892 | (!strcmp(argv[i], "--noout"))) |
| 2893 | noout++; |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2894 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2895 | else if ((!strcmp(argv[i], "-o")) || |
| 2896 | (!strcmp(argv[i], "-output")) || |
| 2897 | (!strcmp(argv[i], "--output"))) { |
| 2898 | i++; |
Daniel Veillard | 6e4f1c0 | 2002-04-09 09:55:20 +0000 | [diff] [blame] | 2899 | output = argv[i]; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2900 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2901 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2902 | else if ((!strcmp(argv[i], "-htmlout")) || |
| 2903 | (!strcmp(argv[i], "--htmlout"))) |
| 2904 | htmlout++; |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2905 | else if ((!strcmp(argv[i], "-nowrap")) || |
| 2906 | (!strcmp(argv[i], "--nowrap"))) |
| 2907 | nowrap++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2908 | #ifdef LIBXML_HTML_ENABLED |
| 2909 | else if ((!strcmp(argv[i], "-html")) || |
| 2910 | (!strcmp(argv[i], "--html"))) { |
| 2911 | html++; |
| 2912 | } |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 2913 | else if ((!strcmp(argv[i], "-xmlout")) || |
| 2914 | (!strcmp(argv[i], "--xmlout"))) { |
| 2915 | xmlout++; |
| 2916 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2917 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2918 | else if ((!strcmp(argv[i], "-loaddtd")) || |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2919 | (!strcmp(argv[i], "--loaddtd"))) { |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2920 | loaddtd++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2921 | options |= XML_PARSE_DTDLOAD; |
| 2922 | } else if ((!strcmp(argv[i], "-dtdattr")) || |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 2923 | (!strcmp(argv[i], "--dtdattr"))) { |
| 2924 | loaddtd++; |
| 2925 | dtdattrs++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2926 | options |= XML_PARSE_DTDATTR; |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2927 | } |
| 2928 | #ifdef LIBXML_VALID_ENABLED |
| 2929 | else if ((!strcmp(argv[i], "-valid")) || |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2930 | (!strcmp(argv[i], "--valid"))) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2931 | valid++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2932 | options |= XML_PARSE_DTDVALID; |
| 2933 | } else if ((!strcmp(argv[i], "-postvalid")) || |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2934 | (!strcmp(argv[i], "--postvalid"))) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2935 | postvalid++; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2936 | loaddtd++; |
Daniel Veillard | 5a30b2d | 2003-12-09 13:54:39 +0000 | [diff] [blame] | 2937 | options |= XML_PARSE_DTDLOAD; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2938 | } else if ((!strcmp(argv[i], "-dtdvalid")) || |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 2939 | (!strcmp(argv[i], "--dtdvalid"))) { |
| 2940 | i++; |
| 2941 | dtdvalid = argv[i]; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2942 | loaddtd++; |
Daniel Veillard | 5a30b2d | 2003-12-09 13:54:39 +0000 | [diff] [blame] | 2943 | options |= XML_PARSE_DTDLOAD; |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 2944 | } else if ((!strcmp(argv[i], "-dtdvalidfpi")) || |
| 2945 | (!strcmp(argv[i], "--dtdvalidfpi"))) { |
| 2946 | i++; |
| 2947 | dtdvalidfpi = argv[i]; |
| 2948 | loaddtd++; |
Daniel Veillard | 5a30b2d | 2003-12-09 13:54:39 +0000 | [diff] [blame] | 2949 | options |= XML_PARSE_DTDLOAD; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 2950 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2951 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 2952 | else if ((!strcmp(argv[i], "-dropdtd")) || |
| 2953 | (!strcmp(argv[i], "--dropdtd"))) |
| 2954 | dropdtd++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2955 | else if ((!strcmp(argv[i], "-insert")) || |
| 2956 | (!strcmp(argv[i], "--insert"))) |
| 2957 | insert++; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2958 | else if ((!strcmp(argv[i], "-timing")) || |
| 2959 | (!strcmp(argv[i], "--timing"))) |
| 2960 | timing++; |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 2961 | else if ((!strcmp(argv[i], "-auto")) || |
| 2962 | (!strcmp(argv[i], "--auto"))) |
| 2963 | generate++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2964 | else if ((!strcmp(argv[i], "-repeat")) || |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 2965 | (!strcmp(argv[i], "--repeat"))) { |
| 2966 | if (repeat) |
| 2967 | repeat *= 10; |
| 2968 | else |
| 2969 | repeat = 100; |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 2970 | } |
| 2971 | #ifdef LIBXML_PUSH_ENABLED |
| 2972 | else if ((!strcmp(argv[i], "-push")) || |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2973 | (!strcmp(argv[i], "--push"))) |
| 2974 | push++; |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 2975 | #endif /* LIBXML_PUSH_ENABLED */ |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 2976 | #ifdef HAVE_SYS_MMAN_H |
| 2977 | else if ((!strcmp(argv[i], "-memory")) || |
| 2978 | (!strcmp(argv[i], "--memory"))) |
| 2979 | memory++; |
| 2980 | #endif |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 2981 | else if ((!strcmp(argv[i], "-testIO")) || |
| 2982 | (!strcmp(argv[i], "--testIO"))) |
| 2983 | testIO++; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 2984 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 2985 | else if ((!strcmp(argv[i], "-xinclude")) || |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2986 | (!strcmp(argv[i], "--xinclude"))) { |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 2987 | xinclude++; |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 2988 | options |= XML_PARSE_XINCLUDE; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2989 | } |
Daniel Veillard | c14c389 | 2004-08-16 12:34:50 +0000 | [diff] [blame] | 2990 | else if ((!strcmp(argv[i], "-noxincludenode")) || |
| 2991 | (!strcmp(argv[i], "--noxincludenode"))) { |
| 2992 | xinclude++; |
| 2993 | options |= XML_PARSE_XINCLUDE; |
| 2994 | options |= XML_PARSE_NOXINCNODE; |
| 2995 | } |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 2996 | #endif |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2997 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2998 | #ifdef HAVE_ZLIB_H |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2999 | else if ((!strcmp(argv[i], "-compress")) || |
| 3000 | (!strcmp(argv[i], "--compress"))) { |
| 3001 | compress++; |
| 3002 | xmlSetCompressMode(9); |
| 3003 | } |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 3004 | #endif |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 3005 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3006 | else if ((!strcmp(argv[i], "-nowarning")) || |
| 3007 | (!strcmp(argv[i], "--nowarning"))) { |
| 3008 | xmlGetWarningsDefaultValue = 0; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 3009 | xmlPedanticParserDefault(0); |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 3010 | options |= XML_PARSE_NOWARNING; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3011 | } |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 3012 | else if ((!strcmp(argv[i], "-pedantic")) || |
| 3013 | (!strcmp(argv[i], "--pedantic"))) { |
| 3014 | xmlGetWarningsDefaultValue = 1; |
| 3015 | xmlPedanticParserDefault(1); |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 3016 | options |= XML_PARSE_PEDANTIC; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 3017 | } |
Daniel Veillard | 64c20ed | 2000-09-22 16:07:02 +0000 | [diff] [blame] | 3018 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 3019 | else if ((!strcmp(argv[i], "-debugent")) || |
| 3020 | (!strcmp(argv[i], "--debugent"))) { |
| 3021 | debugent++; |
| 3022 | xmlParserDebugEntities = 1; |
| 3023 | } |
Daniel Veillard | 64c20ed | 2000-09-22 16:07:02 +0000 | [diff] [blame] | 3024 | #endif |
Daniel Veillard | 25048d8 | 2004-08-14 22:37:54 +0000 | [diff] [blame] | 3025 | #ifdef LIBXML_C14N_ENABLED |
| 3026 | else if ((!strcmp(argv[i], "-c14n")) || |
| 3027 | (!strcmp(argv[i], "--c14n"))) { |
| 3028 | canonical++; |
| 3029 | options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD; |
| 3030 | } |
Aleksey Sanin | 2650df1 | 2005-06-06 17:16:50 +0000 | [diff] [blame] | 3031 | else if ((!strcmp(argv[i], "-exc-c14n")) || |
| 3032 | (!strcmp(argv[i], "--exc-c14n"))) { |
| 3033 | exc_canonical++; |
| 3034 | options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD; |
| 3035 | } |
Daniel Veillard | 25048d8 | 2004-08-14 22:37:54 +0000 | [diff] [blame] | 3036 | #endif |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 3037 | #ifdef LIBXML_CATALOG_ENABLED |
| 3038 | else if ((!strcmp(argv[i], "-catalogs")) || |
| 3039 | (!strcmp(argv[i], "--catalogs"))) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3040 | catalogs++; |
| 3041 | } else if ((!strcmp(argv[i], "-nocatalogs")) || |
| 3042 | (!strcmp(argv[i], "--nocatalogs"))) { |
| 3043 | nocatalogs++; |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 3044 | } |
| 3045 | #endif |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 3046 | else if ((!strcmp(argv[i], "-encode")) || |
| 3047 | (!strcmp(argv[i], "--encode"))) { |
| 3048 | i++; |
| 3049 | encoding = argv[i]; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 3050 | /* |
| 3051 | * OK it's for testing purposes |
| 3052 | */ |
| 3053 | xmlAddEncodingAlias("UTF-8", "DVEnc"); |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 3054 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3055 | else if ((!strcmp(argv[i], "-noblanks")) || |
| 3056 | (!strcmp(argv[i], "--noblanks"))) { |
| 3057 | noblanks++; |
| 3058 | xmlKeepBlanksDefault(0); |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 3059 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 3060 | else if ((!strcmp(argv[i], "-maxmem")) || |
| 3061 | (!strcmp(argv[i], "--maxmem"))) { |
| 3062 | i++; |
| 3063 | if (sscanf(argv[i], "%d", &maxmem) == 1) { |
| 3064 | xmlMemSetup(myFreeFunc, myMallocFunc, myReallocFunc, |
| 3065 | myStrdupFunc); |
| 3066 | } else { |
| 3067 | maxmem = 0; |
| 3068 | } |
| 3069 | } |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 3070 | else if ((!strcmp(argv[i], "-format")) || |
| 3071 | (!strcmp(argv[i], "--format"))) { |
| 3072 | noblanks++; |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 3073 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 3074 | format++; |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 3075 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 3076 | xmlKeepBlanksDefault(0); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 3077 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3078 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 3079 | else if ((!strcmp(argv[i], "-stream")) || |
| 3080 | (!strcmp(argv[i], "--stream"))) { |
| 3081 | stream++; |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 3082 | } |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 3083 | else if ((!strcmp(argv[i], "-walker")) || |
| 3084 | (!strcmp(argv[i], "--walker"))) { |
| 3085 | walker++; |
| 3086 | noout++; |
| 3087 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3088 | #endif /* LIBXML_READER_ENABLED */ |
| 3089 | #ifdef LIBXML_SAX1_ENABLED |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 3090 | else if ((!strcmp(argv[i], "-sax1")) || |
| 3091 | (!strcmp(argv[i], "--sax1"))) { |
| 3092 | sax1++; |
| 3093 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3094 | #endif /* LIBXML_SAX1_ENABLED */ |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 3095 | else if ((!strcmp(argv[i], "-sax")) || |
| 3096 | (!strcmp(argv[i], "--sax"))) { |
| 3097 | sax++; |
| 3098 | } |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 3099 | else if ((!strcmp(argv[i], "-chkregister")) || |
| 3100 | (!strcmp(argv[i], "--chkregister"))) { |
| 3101 | chkregister++; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 3102 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 3103 | } else if ((!strcmp(argv[i], "-relaxng")) || |
| 3104 | (!strcmp(argv[i], "--relaxng"))) { |
| 3105 | i++; |
| 3106 | relaxng = argv[i]; |
| 3107 | noent++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 3108 | options |= XML_PARSE_NOENT; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 3109 | } else if ((!strcmp(argv[i], "-schema")) || |
| 3110 | (!strcmp(argv[i], "--schema"))) { |
| 3111 | i++; |
| 3112 | schema = argv[i]; |
| 3113 | noent++; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 3114 | #endif |
Daniel Veillard | e8b09e4 | 2003-05-13 22:14:13 +0000 | [diff] [blame] | 3115 | } else if ((!strcmp(argv[i], "-nonet")) || |
| 3116 | (!strcmp(argv[i], "--nonet"))) { |
Daniel Veillard | 61b9338 | 2003-11-03 14:28:31 +0000 | [diff] [blame] | 3117 | options |= XML_PARSE_NONET; |
Daniel Veillard | 0bff36d | 2004-08-31 09:37:03 +0000 | [diff] [blame] | 3118 | } else if ((!strcmp(argv[i], "-load-trace")) || |
| 3119 | (!strcmp(argv[i], "--load-trace"))) { |
| 3120 | load_trace++; |
| 3121 | } else if ((!strcmp(argv[i], "-path")) || |
| 3122 | (!strcmp(argv[i], "--path"))) { |
| 3123 | i++; |
| 3124 | parsePath(BAD_CAST argv[i]); |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 3125 | #ifdef LIBXML_PATTERN_ENABLED |
| 3126 | } else if ((!strcmp(argv[i], "-pattern")) || |
| 3127 | (!strcmp(argv[i], "--pattern"))) { |
| 3128 | i++; |
| 3129 | pattern = argv[i]; |
| 3130 | #endif |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 3131 | } else { |
| 3132 | fprintf(stderr, "Unknown option %s\n", argv[i]); |
| 3133 | usage(argv[0]); |
| 3134 | return(1); |
| 3135 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3136 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3137 | |
| 3138 | #ifdef LIBXML_CATALOG_ENABLED |
| 3139 | if (nocatalogs == 0) { |
| 3140 | if (catalogs) { |
| 3141 | const char *catal; |
| 3142 | |
| 3143 | catal = getenv("SGML_CATALOG_FILES"); |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 3144 | if (catal != NULL) { |
| 3145 | xmlLoadCatalogs(catal); |
| 3146 | } else { |
| 3147 | fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n"); |
| 3148 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3149 | } |
| 3150 | } |
| 3151 | #endif |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 3152 | |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3153 | #ifdef LIBXML_SAX1_ENABLED |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 3154 | if (sax1) |
| 3155 | xmlSAXDefaultVersion(1); |
| 3156 | else |
| 3157 | xmlSAXDefaultVersion(2); |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3158 | #endif /* LIBXML_SAX1_ENABLED */ |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 3159 | |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 3160 | if (chkregister) { |
| 3161 | xmlRegisterNodeDefault(registerNode); |
| 3162 | xmlDeregisterNodeDefault(deregisterNode); |
| 3163 | } |
Aleksey Sanin | 693c9bc | 2003-03-09 22:36:52 +0000 | [diff] [blame] | 3164 | |
| 3165 | indent = getenv("XMLLINT_INDENT"); |
| 3166 | if(indent != NULL) { |
| 3167 | xmlTreeIndentString = indent; |
| 3168 | } |
| 3169 | |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 3170 | |
Daniel Veillard | 0bff36d | 2004-08-31 09:37:03 +0000 | [diff] [blame] | 3171 | defaultEntityLoader = xmlGetExternalEntityLoader(); |
| 3172 | xmlSetExternalEntityLoader(xmllintExternalEntityLoader); |
| 3173 | |
Daniel Veillard | d9bad13 | 2001-07-23 19:39:43 +0000 | [diff] [blame] | 3174 | xmlLineNumbersDefault(1); |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 3175 | if (loaddtd != 0) |
| 3176 | xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS; |
| 3177 | if (dtdattrs) |
| 3178 | xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3179 | if (noent != 0) xmlSubstituteEntitiesDefault(1); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 3180 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3181 | if (valid != 0) xmlDoValidityCheckingDefaultValue = 1; |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 3182 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3183 | if ((htmlout) && (!nowrap)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 3184 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3185 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n"); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 3186 | xmlGenericError(xmlGenericErrorContext, |
| 3187 | "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"); |
| 3188 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3189 | "<html><head><title>%s output</title></head>\n", |
| 3190 | argv[0]); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 3191 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3192 | "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n", |
| 3193 | argv[0]); |
| 3194 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 3195 | |
| 3196 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 3197 | if ((relaxng != NULL) && (sax == 0) |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3198 | #ifdef LIBXML_READER_ENABLED |
| 3199 | && (stream == 0) |
| 3200 | #endif /* LIBXML_READER_ENABLED */ |
| 3201 | ) { |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 3202 | xmlRelaxNGParserCtxtPtr ctxt; |
| 3203 | |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 3204 | /* forces loading the DTDs */ |
| 3205 | xmlLoadExtDtdDefaultValue |= 1; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 3206 | options |= XML_PARSE_DTDLOAD; |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 3207 | if (timing) { |
| 3208 | startTimer(); |
| 3209 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 3210 | ctxt = xmlRelaxNGNewParserCtxt(relaxng); |
| 3211 | xmlRelaxNGSetParserErrors(ctxt, |
| 3212 | (xmlRelaxNGValidityErrorFunc) fprintf, |
| 3213 | (xmlRelaxNGValidityWarningFunc) fprintf, |
| 3214 | stderr); |
| 3215 | relaxngschemas = xmlRelaxNGParse(ctxt); |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 3216 | if (relaxngschemas == NULL) { |
| 3217 | xmlGenericError(xmlGenericErrorContext, |
| 3218 | "Relax-NG schema %s failed to compile\n", relaxng); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 3219 | progresult = XMLLINT_ERR_SCHEMACOMP; |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 3220 | relaxng = NULL; |
| 3221 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 3222 | xmlRelaxNGFreeParserCtxt(ctxt); |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 3223 | if (timing) { |
| 3224 | endTimer("Compiling the schemas"); |
| 3225 | } |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 3226 | } else if ((schema != NULL) |
| 3227 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | f10ae12 | 2005-07-10 19:03:16 +0000 | [diff] [blame] | 3228 | && (stream == 0) |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 3229 | #endif |
| 3230 | ) { |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 3231 | xmlSchemaParserCtxtPtr ctxt; |
| 3232 | |
| 3233 | if (timing) { |
| 3234 | startTimer(); |
| 3235 | } |
| 3236 | ctxt = xmlSchemaNewParserCtxt(schema); |
| 3237 | xmlSchemaSetParserErrors(ctxt, |
| 3238 | (xmlSchemaValidityErrorFunc) fprintf, |
| 3239 | (xmlSchemaValidityWarningFunc) fprintf, |
| 3240 | stderr); |
| 3241 | wxschemas = xmlSchemaParse(ctxt); |
| 3242 | if (wxschemas == NULL) { |
| 3243 | xmlGenericError(xmlGenericErrorContext, |
| 3244 | "WXS schema %s failed to compile\n", schema); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 3245 | progresult = XMLLINT_ERR_SCHEMACOMP; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 3246 | schema = NULL; |
| 3247 | } |
| 3248 | xmlSchemaFreeParserCtxt(ctxt); |
| 3249 | if (timing) { |
| 3250 | endTimer("Compiling the schemas"); |
| 3251 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 3252 | } |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 3253 | #endif /* LIBXML_SCHEMAS_ENABLED */ |
| 3254 | #ifdef LIBXML_PATTERN_ENABLED |
Daniel Veillard | 39e5c89 | 2005-07-03 22:48:50 +0000 | [diff] [blame] | 3255 | if ((pattern != NULL) |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 3256 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 39e5c89 | 2005-07-03 22:48:50 +0000 | [diff] [blame] | 3257 | && (walker == 0) |
| 3258 | #endif |
| 3259 | ) { |
Daniel Veillard | ffa7b7e | 2003-12-05 16:10:21 +0000 | [diff] [blame] | 3260 | patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL); |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 3261 | if (patternc == NULL) { |
| 3262 | xmlGenericError(xmlGenericErrorContext, |
| 3263 | "Pattern %s failed to compile\n", pattern); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 3264 | progresult = XMLLINT_ERR_SCHEMAPAT; |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 3265 | pattern = NULL; |
| 3266 | } |
| 3267 | } |
| 3268 | #endif /* LIBXML_PATTERN_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3269 | for (i = 1; i < argc ; i++) { |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 3270 | if ((!strcmp(argv[i], "-encode")) || |
| 3271 | (!strcmp(argv[i], "--encode"))) { |
| 3272 | i++; |
| 3273 | continue; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 3274 | } else if ((!strcmp(argv[i], "-o")) || |
| 3275 | (!strcmp(argv[i], "-output")) || |
| 3276 | (!strcmp(argv[i], "--output"))) { |
| 3277 | i++; |
| 3278 | continue; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 3279 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 3280 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 3281 | if ((!strcmp(argv[i], "-dtdvalid")) || |
| 3282 | (!strcmp(argv[i], "--dtdvalid"))) { |
| 3283 | i++; |
| 3284 | continue; |
Daniel Veillard | 0bff36d | 2004-08-31 09:37:03 +0000 | [diff] [blame] | 3285 | } |
| 3286 | if ((!strcmp(argv[i], "-path")) || |
| 3287 | (!strcmp(argv[i], "--path"))) { |
| 3288 | i++; |
| 3289 | continue; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 3290 | } |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 3291 | if ((!strcmp(argv[i], "-dtdvalidfpi")) || |
| 3292 | (!strcmp(argv[i], "--dtdvalidfpi"))) { |
| 3293 | i++; |
| 3294 | continue; |
| 3295 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 3296 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 3297 | if ((!strcmp(argv[i], "-relaxng")) || |
| 3298 | (!strcmp(argv[i], "--relaxng"))) { |
| 3299 | i++; |
| 3300 | continue; |
| 3301 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 3302 | if ((!strcmp(argv[i], "-maxmem")) || |
| 3303 | (!strcmp(argv[i], "--maxmem"))) { |
| 3304 | i++; |
| 3305 | continue; |
| 3306 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 3307 | if ((!strcmp(argv[i], "-schema")) || |
| 3308 | (!strcmp(argv[i], "--schema"))) { |
| 3309 | i++; |
| 3310 | continue; |
| 3311 | } |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 3312 | #ifdef LIBXML_PATTERN_ENABLED |
| 3313 | if ((!strcmp(argv[i], "-pattern")) || |
| 3314 | (!strcmp(argv[i], "--pattern"))) { |
| 3315 | i++; |
| 3316 | continue; |
| 3317 | } |
| 3318 | #endif |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3319 | if ((timing) && (repeat)) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 3320 | startTimer(); |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 3321 | /* Remember file names. "-" means stdin. <sven@zen.org> */ |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 3322 | if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3323 | if (repeat) { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 3324 | xmlParserCtxtPtr ctxt = NULL; |
| 3325 | |
| 3326 | for (acount = 0;acount < repeat;acount++) { |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3327 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 3328 | if (stream != 0) { |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 3329 | streamFile(argv[i]); |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 3330 | } else { |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3331 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 3332 | if (sax) { |
| 3333 | testSAX(argv[i]); |
| 3334 | } else { |
| 3335 | if (ctxt == NULL) |
| 3336 | ctxt = xmlNewParserCtxt(); |
| 3337 | parseAndPrintFile(argv[i], ctxt); |
| 3338 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3339 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 3340 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3341 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 3342 | } |
| 3343 | if (ctxt != NULL) |
| 3344 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 3345 | } else { |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 3346 | nbregister = 0; |
| 3347 | |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3348 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 3349 | if (stream != 0) |
| 3350 | streamFile(argv[i]); |
| 3351 | else |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 3352 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 3353 | if (sax) { |
| 3354 | testSAX(argv[i]); |
| 3355 | } else { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 3356 | parseAndPrintFile(argv[i], NULL); |
Daniel Veillard | f0af8ec | 2005-07-08 17:27:33 +0000 | [diff] [blame] | 3357 | } |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 3358 | |
| 3359 | if ((chkregister) && (nbregister != 0)) { |
| 3360 | fprintf(stderr, "Registration count off: %d\n", nbregister); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 3361 | progresult = XMLLINT_ERR_RDREGIS; |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 3362 | } |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 3363 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3364 | files ++; |
Daniel Veillard | a786693 | 2001-12-04 13:14:44 +0000 | [diff] [blame] | 3365 | if ((timing) && (repeat)) { |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 3366 | endTimer("%d iterations", repeat); |
Daniel Veillard | a786693 | 2001-12-04 13:14:44 +0000 | [diff] [blame] | 3367 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 3368 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3369 | } |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 3370 | if (generate) |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 3371 | parseAndPrintFile(NULL, NULL); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3372 | if ((htmlout) && (!nowrap)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 3373 | xmlGenericError(xmlGenericErrorContext, "</body></html>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3374 | } |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 3375 | if ((files == 0) && (!generate) && (version == 0)) { |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 3376 | usage(argv[0]); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3377 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 3378 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 3379 | if (relaxngschemas != NULL) |
| 3380 | xmlRelaxNGFree(relaxngschemas); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 3381 | if (wxschemas != NULL) |
| 3382 | xmlSchemaFree(wxschemas); |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 3383 | xmlRelaxNGCleanupTypes(); |
| 3384 | #endif |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 3385 | #ifdef LIBXML_PATTERN_ENABLED |
| 3386 | if (patternc != NULL) |
| 3387 | xmlFreePattern(patternc); |
| 3388 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3389 | xmlCleanupParser(); |
| 3390 | xmlMemoryDump(); |
| 3391 | |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 3392 | return(progresult); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 3393 | } |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 3394 | |