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