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