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