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