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