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