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> |
| 34 | #undef SOCKLEN_T |
| 35 | #define SOCKLEN_T unsigned int |
| 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 | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 88 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 89 | #include <libxml/relaxng.h> |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 90 | #include <libxml/xmlschemas.h> |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 91 | #endif |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 92 | #ifdef LIBXML_PATTERN_ENABLED |
| 93 | #include <libxml/pattern.h> |
| 94 | #endif |
Daniel Veillard | 6ebf3c4 | 2004-08-22 13:11:39 +0000 | [diff] [blame^] | 95 | #ifdef LIBXML_C14N_ENABLED |
| 96 | #include <libxml/c14n.h> |
| 97 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 98 | |
Daniel Veillard | 3be2751 | 2003-01-26 19:49:04 +0000 | [diff] [blame] | 99 | #ifndef XML_XML_DEFAULT_CATALOG |
| 100 | #define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog" |
| 101 | #endif |
| 102 | |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 103 | typedef enum { |
| 104 | XMLLINT_RETURN_OK = 0, /* No error */ |
| 105 | XMLLINT_ERR_UNCLASS, /* Unclassified */ |
| 106 | XMLLINT_ERR_DTD, /* Error in DTD */ |
| 107 | XMLLINT_ERR_VALID, /* Validation error */ |
| 108 | XMLLINT_ERR_RDFILE, /* CtxtReadFile error */ |
| 109 | XMLLINT_ERR_SCHEMACOMP, /* Schema compilation */ |
| 110 | XMLLINT_ERR_OUT, /* Error writing output */ |
| 111 | XMLLINT_ERR_SCHEMAPAT, /* Error in schema pattern */ |
| 112 | XMLLINT_ERR_RDREGIS, /* Error in Reader registration */ |
| 113 | XMLLINT_ERR_MEM /* Out of memory error */ |
| 114 | } xmllintReturnCode; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 115 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 116 | static int shell = 0; |
| 117 | static int debugent = 0; |
| 118 | #endif |
Daniel Veillard | 8326e73 | 2003-01-07 00:19:07 +0000 | [diff] [blame] | 119 | static int debug = 0; |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 120 | static int maxmem = 0; |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 121 | #ifdef LIBXML_TREE_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 122 | static int copy = 0; |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 123 | #endif /* LIBXML_TREE_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 124 | static int recovery = 0; |
| 125 | static int noent = 0; |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 126 | static int noblanks = 0; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 127 | static int noout = 0; |
| 128 | static int nowrap = 0; |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 129 | #ifdef LIBXML_OUTPUT_ENABLED |
| 130 | static int format = 0; |
| 131 | static const char *output = NULL; |
| 132 | static int compress = 0; |
| 133 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 134 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 135 | static int valid = 0; |
| 136 | static int postvalid = 0; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 137 | static char * dtdvalid = NULL; |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 138 | static char * dtdvalidfpi = NULL; |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 139 | #endif |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 140 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 141 | static char * relaxng = NULL; |
| 142 | static xmlRelaxNGPtr relaxngschemas = NULL; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 143 | static char * schema = NULL; |
| 144 | static xmlSchemaPtr wxschemas = NULL; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 145 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 146 | static int repeat = 0; |
| 147 | static int insert = 0; |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 148 | #if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED) |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 149 | static int html = 0; |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 150 | static int xmlout = 0; |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 151 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 152 | static int htmlout = 0; |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 153 | #ifdef LIBXML_PUSH_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 154 | static int push = 0; |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 155 | #endif /* LIBXML_PUSH_ENABLED */ |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 156 | #ifdef HAVE_SYS_MMAN_H |
| 157 | static int memory = 0; |
| 158 | #endif |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 159 | static int testIO = 0; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 160 | static char *encoding = NULL; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 161 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 162 | static int xinclude = 0; |
| 163 | #endif |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 164 | static int dtdattrs = 0; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 165 | static int loaddtd = 0; |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 166 | static xmllintReturnCode progresult = XMLLINT_RETURN_OK; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 167 | static int timing = 0; |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 168 | static int generate = 0; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 169 | static int dropdtd = 0; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 170 | #ifdef LIBXML_CATALOG_ENABLED |
| 171 | static int catalogs = 0; |
| 172 | static int nocatalogs = 0; |
| 173 | #endif |
Daniel Veillard | 25048d8 | 2004-08-14 22:37:54 +0000 | [diff] [blame] | 174 | #ifdef LIBXML_C14N_ENABLED |
| 175 | static int canonical = 0; |
| 176 | #endif |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 177 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 178 | static int stream = 0; |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 179 | static int walker = 0; |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 180 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 181 | static int chkregister = 0; |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 182 | static int nbregister = 0; |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 183 | #ifdef LIBXML_SAX1_ENABLED |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 184 | static int sax1 = 0; |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 185 | #endif /* LIBXML_SAX1_ENABLED */ |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 186 | #ifdef LIBXML_PATTERN_ENABLED |
| 187 | static const char *pattern = NULL; |
| 188 | static xmlPatternPtr patternc = NULL; |
| 189 | #endif |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 190 | static int options = 0; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 191 | |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 192 | /************************************************************************ |
| 193 | * * |
| 194 | * Memory allocation consumption debugging * |
| 195 | * * |
| 196 | ************************************************************************/ |
| 197 | |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 198 | static void |
| 199 | OOM(void) |
| 200 | { |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 201 | fprintf(stderr, "Ran out of memory needs > %d bytes\n", maxmem); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 202 | progresult = XMLLINT_ERR_MEM; |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 205 | static void |
| 206 | myFreeFunc(void *mem) |
| 207 | { |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 208 | xmlMemFree(mem); |
| 209 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 210 | static void * |
| 211 | myMallocFunc(size_t size) |
| 212 | { |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 213 | void *ret; |
| 214 | |
| 215 | ret = xmlMemMalloc(size); |
| 216 | if (ret != NULL) { |
| 217 | if (xmlMemUsed() > maxmem) { |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 218 | OOM(); |
| 219 | xmlMemFree(ret); |
| 220 | return (NULL); |
| 221 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 222 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 223 | return (ret); |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 224 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 225 | static void * |
| 226 | myReallocFunc(void *mem, size_t size) |
| 227 | { |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 228 | void *ret; |
| 229 | |
| 230 | ret = xmlMemRealloc(mem, size); |
| 231 | if (ret != NULL) { |
| 232 | if (xmlMemUsed() > maxmem) { |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 233 | OOM(); |
| 234 | xmlMemFree(ret); |
| 235 | return (NULL); |
| 236 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 237 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 238 | return (ret); |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 239 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 240 | static char * |
| 241 | myStrdupFunc(const char *str) |
| 242 | { |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 243 | char *ret; |
| 244 | |
| 245 | ret = xmlMemoryStrdup(str); |
| 246 | if (ret != NULL) { |
| 247 | if (xmlMemUsed() > maxmem) { |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 248 | OOM(); |
| 249 | xmlFree(ret); |
| 250 | return (NULL); |
| 251 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 252 | } |
Daniel Veillard | 3af3b59 | 2004-05-05 19:22:30 +0000 | [diff] [blame] | 253 | return (ret); |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 254 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 255 | /************************************************************************ |
| 256 | * * |
| 257 | * Internal timing routines to remove the necessity to have * |
| 258 | * unix-specific function calls. * |
| 259 | * * |
| 260 | ************************************************************************/ |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 261 | |
Daniel Veillard | 8c1ae60 | 2002-03-07 11:21:00 +0000 | [diff] [blame] | 262 | #ifndef HAVE_GETTIMEOFDAY |
| 263 | #ifdef HAVE_SYS_TIMEB_H |
| 264 | #ifdef HAVE_SYS_TIME_H |
| 265 | #ifdef HAVE_FTIME |
| 266 | |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 267 | static int |
Daniel Veillard | 8c1ae60 | 2002-03-07 11:21:00 +0000 | [diff] [blame] | 268 | my_gettimeofday(struct timeval *tvp, void *tzp) |
| 269 | { |
| 270 | struct timeb timebuffer; |
| 271 | |
| 272 | ftime(&timebuffer); |
| 273 | if (tvp) { |
| 274 | tvp->tv_sec = timebuffer.time; |
| 275 | tvp->tv_usec = timebuffer.millitm * 1000L; |
| 276 | } |
| 277 | return (0); |
| 278 | } |
| 279 | #define HAVE_GETTIMEOFDAY 1 |
| 280 | #define gettimeofday my_gettimeofday |
| 281 | |
| 282 | #endif /* HAVE_FTIME */ |
| 283 | #endif /* HAVE_SYS_TIME_H */ |
| 284 | #endif /* HAVE_SYS_TIMEB_H */ |
| 285 | #endif /* !HAVE_GETTIMEOFDAY */ |
| 286 | |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 287 | #if defined(HAVE_GETTIMEOFDAY) |
| 288 | static struct timeval begin, end; |
| 289 | |
| 290 | /* |
| 291 | * startTimer: call where you want to start timing |
| 292 | */ |
| 293 | static void |
| 294 | startTimer(void) |
| 295 | { |
| 296 | gettimeofday(&begin, NULL); |
| 297 | } |
| 298 | |
| 299 | /* |
| 300 | * endTimer: call where you want to stop timing and to print out a |
| 301 | * message about the timing performed; format is a printf |
| 302 | * type argument |
| 303 | */ |
| 304 | static void |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 305 | endTimer(const char *fmt, ...) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 306 | { |
| 307 | long msec; |
| 308 | va_list ap; |
| 309 | |
| 310 | gettimeofday(&end, NULL); |
| 311 | msec = end.tv_sec - begin.tv_sec; |
| 312 | msec *= 1000; |
| 313 | msec += (end.tv_usec - begin.tv_usec) / 1000; |
| 314 | |
| 315 | #ifndef HAVE_STDARG_H |
| 316 | #error "endTimer required stdarg functions" |
| 317 | #endif |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 318 | va_start(ap, fmt); |
| 319 | vfprintf(stderr, fmt, ap); |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 320 | va_end(ap); |
| 321 | |
| 322 | fprintf(stderr, " took %ld ms\n", msec); |
| 323 | } |
| 324 | #elif defined(HAVE_TIME_H) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 325 | /* |
| 326 | * No gettimeofday function, so we have to make do with calling clock. |
| 327 | * This is obviously less accurate, but there's little we can do about |
| 328 | * that. |
| 329 | */ |
Daniel Veillard | 90bc371 | 2002-03-07 15:12:58 +0000 | [diff] [blame] | 330 | #ifndef CLOCKS_PER_SEC |
| 331 | #define CLOCKS_PER_SEC 100 |
| 332 | #endif |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 333 | |
| 334 | static clock_t begin, end; |
| 335 | static void |
| 336 | startTimer(void) |
| 337 | { |
| 338 | begin = clock(); |
| 339 | } |
| 340 | static void |
| 341 | endTimer(const char *fmt, ...) |
| 342 | { |
| 343 | long msec; |
| 344 | va_list ap; |
| 345 | |
| 346 | end = clock(); |
| 347 | msec = ((end - begin) * 1000) / CLOCKS_PER_SEC; |
| 348 | |
| 349 | #ifndef HAVE_STDARG_H |
| 350 | #error "endTimer required stdarg functions" |
| 351 | #endif |
| 352 | va_start(ap, fmt); |
| 353 | vfprintf(stderr, fmt, ap); |
| 354 | va_end(ap); |
| 355 | fprintf(stderr, " took %ld ms\n", msec); |
| 356 | } |
| 357 | #else |
| 358 | |
| 359 | /* |
| 360 | * We don't have a gettimeofday or time.h, so we just don't do timing |
| 361 | */ |
| 362 | static void |
| 363 | startTimer(void) |
| 364 | { |
| 365 | /* |
| 366 | * Do nothing |
| 367 | */ |
| 368 | } |
| 369 | static void |
| 370 | endTimer(char *format, ...) |
| 371 | { |
| 372 | /* |
| 373 | * We cannot do anything because we don't have a timing function |
| 374 | */ |
| 375 | #ifdef HAVE_STDARG_H |
| 376 | va_start(ap, format); |
| 377 | vfprintf(stderr, format, ap); |
| 378 | va_end(ap); |
| 379 | fprintf(stderr, " was not timed\n", msec); |
| 380 | #else |
| 381 | /* We don't have gettimeofday, time or stdarg.h, what crazy world is |
| 382 | * this ?! |
| 383 | */ |
| 384 | #endif |
| 385 | } |
| 386 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 387 | /************************************************************************ |
| 388 | * * |
| 389 | * HTML ouput * |
| 390 | * * |
| 391 | ************************************************************************/ |
| 392 | char buffer[50000]; |
| 393 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 394 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 395 | xmlHTMLEncodeSend(void) { |
| 396 | char *result; |
| 397 | |
| 398 | result = (char *) xmlEncodeEntitiesReentrant(NULL, BAD_CAST buffer); |
| 399 | if (result) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 400 | xmlGenericError(xmlGenericErrorContext, "%s", result); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 401 | xmlFree(result); |
| 402 | } |
| 403 | buffer[0] = 0; |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * xmlHTMLPrintFileInfo: |
| 408 | * @input: an xmlParserInputPtr input |
| 409 | * |
| 410 | * Displays the associated file and line informations for the current input |
| 411 | */ |
| 412 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 413 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 414 | xmlHTMLPrintFileInfo(xmlParserInputPtr input) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 415 | int len; |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 416 | xmlGenericError(xmlGenericErrorContext, "<p>"); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 417 | |
| 418 | len = strlen(buffer); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 419 | if (input != NULL) { |
| 420 | if (input->filename) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 421 | snprintf(&buffer[len], sizeof(buffer) - len, "%s:%d: ", input->filename, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 422 | input->line); |
| 423 | } else { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 424 | snprintf(&buffer[len], sizeof(buffer) - len, "Entity: line %d: ", input->line); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | xmlHTMLEncodeSend(); |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * xmlHTMLPrintFileContext: |
| 432 | * @input: an xmlParserInputPtr input |
| 433 | * |
| 434 | * Displays current context within the input content for error tracking |
| 435 | */ |
| 436 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 437 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 438 | xmlHTMLPrintFileContext(xmlParserInputPtr input) { |
| 439 | const xmlChar *cur, *base; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 440 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 441 | int n; |
| 442 | |
| 443 | if (input == NULL) return; |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 444 | xmlGenericError(xmlGenericErrorContext, "<pre>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 445 | cur = input->cur; |
| 446 | base = input->base; |
| 447 | while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { |
| 448 | cur--; |
| 449 | } |
| 450 | n = 0; |
| 451 | while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) |
| 452 | cur--; |
| 453 | if ((*cur == '\n') || (*cur == '\r')) cur++; |
| 454 | base = cur; |
| 455 | n = 0; |
| 456 | while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 457 | len = strlen(buffer); |
| 458 | snprintf(&buffer[len], sizeof(buffer) - len, "%c", |
| 459 | (unsigned char) *cur++); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 460 | n++; |
| 461 | } |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 462 | len = strlen(buffer); |
| 463 | snprintf(&buffer[len], sizeof(buffer) - len, "\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 464 | cur = input->cur; |
| 465 | while ((*cur == '\n') || (*cur == '\r')) |
| 466 | cur--; |
| 467 | n = 0; |
| 468 | while ((cur != base) && (n++ < 80)) { |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 469 | len = strlen(buffer); |
| 470 | snprintf(&buffer[len], sizeof(buffer) - len, " "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 471 | base++; |
| 472 | } |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 473 | len = strlen(buffer); |
| 474 | snprintf(&buffer[len], sizeof(buffer) - len, "^\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 475 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 476 | xmlGenericError(xmlGenericErrorContext, "</pre>"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
| 480 | * xmlHTMLError: |
| 481 | * @ctx: an XML parser context |
| 482 | * @msg: the message to display/transmit |
| 483 | * @...: extra parameters for the message display |
| 484 | * |
| 485 | * Display and format an error messages, gives file, line, position and |
| 486 | * extra parameters. |
| 487 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 488 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 489 | xmlHTMLError(void *ctx, const char *msg, ...) |
| 490 | { |
| 491 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 492 | xmlParserInputPtr input; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 493 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 494 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 495 | |
| 496 | buffer[0] = 0; |
| 497 | input = ctxt->input; |
| 498 | if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 499 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 500 | } |
| 501 | |
| 502 | xmlHTMLPrintFileInfo(input); |
| 503 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 504 | xmlGenericError(xmlGenericErrorContext, "<b>error</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 505 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 506 | len = strlen(buffer); |
| 507 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 508 | va_end(args); |
| 509 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 510 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 511 | |
| 512 | xmlHTMLPrintFileContext(input); |
| 513 | xmlHTMLEncodeSend(); |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * xmlHTMLWarning: |
| 518 | * @ctx: an XML parser context |
| 519 | * @msg: the message to display/transmit |
| 520 | * @...: extra parameters for the message display |
| 521 | * |
| 522 | * Display and format a warning messages, gives file, line, position and |
| 523 | * extra parameters. |
| 524 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 525 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 526 | xmlHTMLWarning(void *ctx, const char *msg, ...) |
| 527 | { |
| 528 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 529 | xmlParserInputPtr input; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 530 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 531 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 532 | |
| 533 | buffer[0] = 0; |
| 534 | input = ctxt->input; |
| 535 | if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 536 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 537 | } |
| 538 | |
| 539 | |
| 540 | xmlHTMLPrintFileInfo(input); |
| 541 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 542 | xmlGenericError(xmlGenericErrorContext, "<b>warning</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 543 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 544 | len = strlen(buffer); |
| 545 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 546 | va_end(args); |
| 547 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 548 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 549 | |
| 550 | xmlHTMLPrintFileContext(input); |
| 551 | xmlHTMLEncodeSend(); |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * xmlHTMLValidityError: |
| 556 | * @ctx: an XML parser context |
| 557 | * @msg: the message to display/transmit |
| 558 | * @...: extra parameters for the message display |
| 559 | * |
| 560 | * Display and format an validity error messages, gives file, |
| 561 | * line, position and extra parameters. |
| 562 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 563 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 564 | xmlHTMLValidityError(void *ctx, const char *msg, ...) |
| 565 | { |
| 566 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 567 | xmlParserInputPtr input; |
| 568 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 569 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 570 | |
| 571 | buffer[0] = 0; |
| 572 | input = ctxt->input; |
| 573 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 574 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 575 | |
| 576 | xmlHTMLPrintFileInfo(input); |
| 577 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 578 | xmlGenericError(xmlGenericErrorContext, "<b>validity error</b>: "); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 579 | len = strlen(buffer); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 580 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 581 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 582 | va_end(args); |
| 583 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 584 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 585 | |
| 586 | xmlHTMLPrintFileContext(input); |
| 587 | xmlHTMLEncodeSend(); |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * xmlHTMLValidityWarning: |
| 592 | * @ctx: an XML parser context |
| 593 | * @msg: the message to display/transmit |
| 594 | * @...: extra parameters for the message display |
| 595 | * |
| 596 | * Display and format a validity warning messages, gives file, line, |
| 597 | * position and extra parameters. |
| 598 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 599 | static void |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 600 | xmlHTMLValidityWarning(void *ctx, const char *msg, ...) |
| 601 | { |
| 602 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 603 | xmlParserInputPtr input; |
| 604 | va_list args; |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 605 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 606 | |
| 607 | buffer[0] = 0; |
| 608 | input = ctxt->input; |
| 609 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 610 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 611 | |
| 612 | xmlHTMLPrintFileInfo(input); |
| 613 | |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 614 | xmlGenericError(xmlGenericErrorContext, "<b>validity warning</b>: "); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 615 | va_start(args, msg); |
Aleksey Sanin | 49cc975 | 2002-06-14 17:07:10 +0000 | [diff] [blame] | 616 | len = strlen(buffer); |
| 617 | vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 618 | va_end(args); |
| 619 | xmlHTMLEncodeSend(); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 620 | xmlGenericError(xmlGenericErrorContext, "</p>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 621 | |
| 622 | xmlHTMLPrintFileContext(input); |
| 623 | xmlHTMLEncodeSend(); |
| 624 | } |
| 625 | |
| 626 | /************************************************************************ |
| 627 | * * |
| 628 | * Shell Interface * |
| 629 | * * |
| 630 | ************************************************************************/ |
Daniel Veillard | 56ada1d | 2003-01-07 11:17:25 +0000 | [diff] [blame] | 631 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 632 | /** |
| 633 | * xmlShellReadline: |
| 634 | * @prompt: the prompt value |
| 635 | * |
| 636 | * Read a string |
| 637 | * |
| 638 | * Returns a pointer to it or NULL on EOF the caller is expected to |
| 639 | * free the returned string. |
| 640 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 641 | static char * |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 642 | xmlShellReadline(char *prompt) { |
| 643 | #ifdef HAVE_LIBREADLINE |
| 644 | char *line_read; |
| 645 | |
| 646 | /* Get a line from the user. */ |
| 647 | line_read = readline (prompt); |
| 648 | |
| 649 | /* If the line has any text in it, save it on the history. */ |
| 650 | if (line_read && *line_read) |
| 651 | add_history (line_read); |
| 652 | |
| 653 | return (line_read); |
| 654 | #else |
| 655 | char line_read[501]; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 656 | char *ret; |
| 657 | int len; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 658 | |
| 659 | if (prompt != NULL) |
| 660 | fprintf(stdout, "%s", prompt); |
| 661 | if (!fgets(line_read, 500, stdin)) |
| 662 | return(NULL); |
| 663 | line_read[500] = 0; |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 664 | len = strlen(line_read); |
| 665 | ret = (char *) malloc(len + 1); |
| 666 | if (ret != NULL) { |
| 667 | memcpy (ret, line_read, len + 1); |
| 668 | } |
| 669 | return(ret); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 670 | #endif |
| 671 | } |
Daniel Veillard | 56ada1d | 2003-01-07 11:17:25 +0000 | [diff] [blame] | 672 | #endif /* LIBXML_DEBUG_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 673 | |
| 674 | /************************************************************************ |
| 675 | * * |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 676 | * I/O Interfaces * |
| 677 | * * |
| 678 | ************************************************************************/ |
| 679 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 680 | static int myRead(FILE *f, char * buf, int len) { |
| 681 | return(fread(buf, 1, len, f)); |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 682 | } |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 683 | static void myClose(FILE *f) { |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 684 | if (f != stdin) { |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 685 | fclose(f); |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 686 | } |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 689 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 690 | /************************************************************************ |
| 691 | * * |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 692 | * Stream Test processing * |
| 693 | * * |
| 694 | ************************************************************************/ |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 695 | static void processNode(xmlTextReaderPtr reader) { |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 696 | const xmlChar *name, *value; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 697 | |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 698 | name = xmlTextReaderConstName(reader); |
Daniel Veillard | e59494f | 2003-01-04 16:35:29 +0000 | [diff] [blame] | 699 | if (name == NULL) |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 700 | name = BAD_CAST "--"; |
Daniel Veillard | 99737f5 | 2003-03-22 14:55:50 +0000 | [diff] [blame] | 701 | |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 702 | value = xmlTextReaderConstValue(reader); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 703 | |
Daniel Veillard | 99737f5 | 2003-03-22 14:55:50 +0000 | [diff] [blame] | 704 | printf("%d %d %s %d %d", |
Daniel Veillard | e59494f | 2003-01-04 16:35:29 +0000 | [diff] [blame] | 705 | xmlTextReaderDepth(reader), |
| 706 | xmlTextReaderNodeType(reader), |
| 707 | name, |
Daniel Veillard | 99737f5 | 2003-03-22 14:55:50 +0000 | [diff] [blame] | 708 | xmlTextReaderIsEmptyElement(reader), |
| 709 | xmlTextReaderHasValue(reader)); |
Daniel Veillard | e59494f | 2003-01-04 16:35:29 +0000 | [diff] [blame] | 710 | if (value == NULL) |
| 711 | printf("\n"); |
| 712 | else { |
| 713 | printf(" %s\n", value); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 714 | } |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 715 | #ifdef LIBXML_PATTERN_ENABLED |
| 716 | if (patternc) { |
| 717 | if (xmlPatternMatch(patternc, xmlTextReaderCurrentNode(reader)) == 1) { |
| 718 | printf("Node matches pattern %s\n", pattern); |
| 719 | } |
| 720 | } |
| 721 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | static void streamFile(char *filename) { |
| 725 | xmlTextReaderPtr reader; |
| 726 | int ret; |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 727 | #ifdef HAVE_SYS_MMAN_H |
| 728 | int fd = -1; |
| 729 | struct stat info; |
| 730 | const char *base = NULL; |
| 731 | xmlParserInputBufferPtr input = NULL; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 732 | |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 733 | if (memory) { |
| 734 | if (stat(filename, &info) < 0) |
| 735 | return; |
| 736 | if ((fd = open(filename, O_RDONLY)) < 0) |
| 737 | return; |
| 738 | base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; |
| 739 | if (base == (void *) MAP_FAILED) |
| 740 | return; |
| 741 | |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 742 | reader = xmlReaderForMemory(base, info.st_size, filename, |
| 743 | NULL, options); |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 744 | } else |
| 745 | #endif |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 746 | reader = xmlReaderForFile(filename, NULL, options); |
| 747 | |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 748 | |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 749 | if (reader != NULL) { |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 750 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 751 | if (valid) |
| 752 | xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1); |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 753 | else |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 754 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 755 | xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1); |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 756 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 757 | if (relaxng != NULL) { |
Daniel Veillard | 81514ba | 2003-09-16 23:17:26 +0000 | [diff] [blame] | 758 | if ((timing) && (!repeat)) { |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 759 | startTimer(); |
| 760 | } |
| 761 | ret = xmlTextReaderRelaxNGValidate(reader, relaxng); |
| 762 | if (ret < 0) { |
| 763 | xmlGenericError(xmlGenericErrorContext, |
| 764 | "Relax-NG schema %s failed to compile\n", relaxng); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 765 | progresult = XMLLINT_ERR_SCHEMACOMP; |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 766 | relaxng = NULL; |
| 767 | } |
Daniel Veillard | 81514ba | 2003-09-16 23:17:26 +0000 | [diff] [blame] | 768 | if ((timing) && (!repeat)) { |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 769 | endTimer("Compiling the schemas"); |
| 770 | } |
| 771 | } |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 772 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 773 | |
| 774 | /* |
| 775 | * Process all nodes in sequence |
| 776 | */ |
Daniel Veillard | 81514ba | 2003-09-16 23:17:26 +0000 | [diff] [blame] | 777 | if ((timing) && (!repeat)) { |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 778 | startTimer(); |
| 779 | } |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 780 | ret = xmlTextReaderRead(reader); |
| 781 | while (ret == 1) { |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 782 | if ((debug) |
| 783 | #ifdef LIBXML_PATTERN_ENABLED |
| 784 | || (patternc) |
| 785 | #endif |
| 786 | ) |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 787 | processNode(reader); |
| 788 | ret = xmlTextReaderRead(reader); |
| 789 | } |
Daniel Veillard | 81514ba | 2003-09-16 23:17:26 +0000 | [diff] [blame] | 790 | if ((timing) && (!repeat)) { |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 791 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | f54cd53 | 2004-02-25 11:52:31 +0000 | [diff] [blame] | 792 | if (relaxng != NULL) |
Daniel Veillard | 49138f1 | 2004-02-19 12:58:36 +0000 | [diff] [blame] | 793 | endTimer("Parsing and validating"); |
| 794 | else |
Daniel Veillard | f54cd53 | 2004-02-25 11:52:31 +0000 | [diff] [blame] | 795 | #endif |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 796 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 797 | if (valid) |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 798 | endTimer("Parsing and validating"); |
| 799 | else |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 800 | #endif |
Daniel Veillard | f54cd53 | 2004-02-25 11:52:31 +0000 | [diff] [blame] | 801 | endTimer("Parsing"); |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 802 | } |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 803 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 804 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | f6bad79 | 2003-04-11 19:38:54 +0000 | [diff] [blame] | 805 | if (valid) { |
| 806 | if (xmlTextReaderIsValid(reader) != 1) { |
| 807 | xmlGenericError(xmlGenericErrorContext, |
| 808 | "Document %s does not validate\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 809 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | f6bad79 | 2003-04-11 19:38:54 +0000 | [diff] [blame] | 810 | } |
| 811 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 812 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 813 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 814 | if (relaxng != NULL) { |
| 815 | if (xmlTextReaderIsValid(reader) != 1) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 816 | fprintf(stderr, "%s fails to validate\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 817 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 818 | } else { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 819 | fprintf(stderr, "%s validates\n", filename); |
Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 820 | } |
| 821 | } |
Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 822 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 823 | /* |
| 824 | * Done, cleanup and status |
| 825 | */ |
| 826 | xmlFreeTextReader(reader); |
| 827 | if (ret != 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 828 | fprintf(stderr, "%s : failed to parse\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 829 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 830 | } |
| 831 | } else { |
| 832 | fprintf(stderr, "Unable to open %s\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 833 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 834 | } |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 835 | #ifdef HAVE_SYS_MMAN_H |
| 836 | if (memory) { |
| 837 | xmlFreeParserInputBuffer(input); |
| 838 | munmap((char *) base, info.st_size); |
| 839 | close(fd); |
| 840 | } |
| 841 | #endif |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 842 | } |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 843 | |
| 844 | static void walkDoc(xmlDocPtr doc) { |
| 845 | xmlTextReaderPtr reader; |
| 846 | int ret; |
| 847 | |
| 848 | reader = xmlReaderWalker(doc); |
| 849 | if (reader != NULL) { |
| 850 | if ((timing) && (!repeat)) { |
| 851 | startTimer(); |
| 852 | } |
| 853 | ret = xmlTextReaderRead(reader); |
| 854 | while (ret == 1) { |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 855 | if ((debug) |
| 856 | #ifdef LIBXML_PATTERN_ENABLED |
| 857 | || (patternc) |
| 858 | #endif |
| 859 | ) |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 860 | processNode(reader); |
| 861 | ret = xmlTextReaderRead(reader); |
| 862 | } |
| 863 | if ((timing) && (!repeat)) { |
| 864 | endTimer("walking through the doc"); |
| 865 | } |
| 866 | xmlFreeTextReader(reader); |
| 867 | if (ret != 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 868 | fprintf(stderr, "failed to walk through the doc\n"); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 869 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 870 | } |
| 871 | } else { |
| 872 | fprintf(stderr, "Failed to crate a reader from the document\n"); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 873 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 874 | } |
| 875 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 876 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 877 | |
| 878 | /************************************************************************ |
| 879 | * * |
| 880 | * Tree Test processing * |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 881 | * * |
| 882 | ************************************************************************/ |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 883 | static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 884 | xmlDocPtr doc = NULL; |
| 885 | #ifdef LIBXML_TREE_ENABLED |
| 886 | xmlDocPtr tmp; |
| 887 | #endif /* LIBXML_TREE_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 888 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 889 | if ((timing) && (!repeat)) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 890 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 891 | |
| 892 | |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 893 | #ifdef LIBXML_TREE_ENABLED |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 894 | if (filename == NULL) { |
| 895 | if (generate) { |
| 896 | xmlNodePtr n; |
| 897 | |
| 898 | doc = xmlNewDoc(BAD_CAST "1.0"); |
| 899 | n = xmlNewNode(NULL, BAD_CAST "info"); |
| 900 | xmlNodeSetContent(n, BAD_CAST "abc"); |
| 901 | xmlDocSetRootElement(doc, n); |
| 902 | } |
| 903 | } |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 904 | #endif /* LIBXML_TREE_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 905 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 906 | #ifdef LIBXML_PUSH_ENABLED |
William M. Brack | 78637da | 2003-07-31 14:47:38 +0000 | [diff] [blame] | 907 | else if ((html) && (push)) { |
| 908 | FILE *f; |
| 909 | |
William M. Brack | 3403add | 2004-06-27 02:07:51 +0000 | [diff] [blame] | 910 | #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 911 | f = fopen(filename, "rb"); |
| 912 | #else |
| 913 | f = fopen(filename, "r"); |
| 914 | #endif |
William M. Brack | 78637da | 2003-07-31 14:47:38 +0000 | [diff] [blame] | 915 | if (f != NULL) { |
| 916 | int res, size = 3; |
| 917 | char chars[4096]; |
| 918 | htmlParserCtxtPtr ctxt; |
| 919 | |
| 920 | /* if (repeat) */ |
| 921 | size = 4096; |
| 922 | res = fread(chars, 1, 4, f); |
| 923 | if (res > 0) { |
| 924 | ctxt = htmlCreatePushParserCtxt(NULL, NULL, |
William M. Brack | 1d75c8a | 2003-10-27 13:48:16 +0000 | [diff] [blame] | 925 | chars, res, filename, XML_CHAR_ENCODING_NONE); |
William M. Brack | 78637da | 2003-07-31 14:47:38 +0000 | [diff] [blame] | 926 | while ((res = fread(chars, 1, size, f)) > 0) { |
| 927 | htmlParseChunk(ctxt, chars, res, 0); |
| 928 | } |
| 929 | htmlParseChunk(ctxt, chars, 0, 1); |
| 930 | doc = ctxt->myDoc; |
| 931 | htmlFreeParserCtxt(ctxt); |
| 932 | } |
| 933 | fclose(f); |
| 934 | } |
| 935 | } |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 936 | #endif /* LIBXML_PUSH_ENABLED */ |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 937 | else if (html) { |
Daniel Veillard | 9475a35 | 2003-09-26 12:47:50 +0000 | [diff] [blame] | 938 | doc = htmlReadFile(filename, NULL, options); |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 939 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 940 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 941 | else { |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 942 | #ifdef LIBXML_PUSH_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 943 | /* |
| 944 | * build an XML tree from a string; |
| 945 | */ |
| 946 | if (push) { |
| 947 | FILE *f; |
| 948 | |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 949 | /* '-' Usually means stdin -<sven@zen.org> */ |
| 950 | if ((filename[0] == '-') && (filename[1] == 0)) { |
| 951 | f = stdin; |
| 952 | } else { |
William M. Brack | 3403add | 2004-06-27 02:07:51 +0000 | [diff] [blame] | 953 | #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 954 | f = fopen(filename, "rb"); |
| 955 | #else |
| 956 | f = fopen(filename, "r"); |
| 957 | #endif |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 958 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 959 | if (f != NULL) { |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 960 | int ret; |
Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 961 | int res, size = 1024; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 962 | char chars[1024]; |
| 963 | xmlParserCtxtPtr ctxt; |
| 964 | |
Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 965 | /* if (repeat) size = 1024; */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 966 | res = fread(chars, 1, 4, f); |
| 967 | if (res > 0) { |
| 968 | ctxt = xmlCreatePushParserCtxt(NULL, NULL, |
| 969 | chars, res, filename); |
Daniel Veillard | 500a1de | 2004-03-22 15:22:58 +0000 | [diff] [blame] | 970 | xmlCtxtUseOptions(ctxt, options); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 971 | while ((res = fread(chars, 1, size, f)) > 0) { |
| 972 | xmlParseChunk(ctxt, chars, res, 0); |
| 973 | } |
| 974 | xmlParseChunk(ctxt, chars, 0, 1); |
| 975 | doc = ctxt->myDoc; |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 976 | ret = ctxt->wellFormed; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 977 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | e715dd2 | 2000-08-29 18:29:38 +0000 | [diff] [blame] | 978 | if (!ret) { |
| 979 | xmlFreeDoc(doc); |
| 980 | doc = NULL; |
| 981 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 982 | } |
| 983 | } |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 984 | } else |
| 985 | #endif /* LIBXML_PUSH_ENABLED */ |
| 986 | if (testIO) { |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 987 | if ((filename[0] == '-') && (filename[1] == 0)) { |
Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 988 | doc = xmlReadFd(0, NULL, NULL, options); |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 989 | } else { |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 990 | FILE *f; |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 991 | |
William M. Brack | 3403add | 2004-06-27 02:07:51 +0000 | [diff] [blame] | 992 | #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 993 | f = fopen(filename, "rb"); |
| 994 | #else |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 995 | f = fopen(filename, "r"); |
William M. Brack | 3403add | 2004-06-27 02:07:51 +0000 | [diff] [blame] | 996 | #endif |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 997 | if (f != NULL) { |
| 998 | if (rectxt == NULL) |
| 999 | doc = xmlReadIO((xmlInputReadCallback) myRead, |
| 1000 | (xmlInputCloseCallback) myClose, f, |
Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 1001 | filename, NULL, options); |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1002 | else |
| 1003 | doc = xmlCtxtReadIO(rectxt, |
| 1004 | (xmlInputReadCallback) myRead, |
| 1005 | (xmlInputCloseCallback) myClose, f, |
Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 1006 | filename, NULL, options); |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1007 | } else |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 1008 | doc = NULL; |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 1009 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1010 | } else if (htmlout) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1011 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1012 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1013 | if (rectxt == NULL) |
| 1014 | ctxt = xmlNewParserCtxt(); |
| 1015 | else |
| 1016 | ctxt = rectxt; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 1017 | if (ctxt == NULL) { |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1018 | doc = NULL; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 1019 | } else { |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1020 | ctxt->sax->error = xmlHTMLError; |
| 1021 | ctxt->sax->warning = xmlHTMLWarning; |
| 1022 | ctxt->vctxt.error = xmlHTMLValidityError; |
| 1023 | ctxt->vctxt.warning = xmlHTMLValidityWarning; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1024 | |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1025 | doc = xmlCtxtReadFile(ctxt, filename, NULL, options); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1026 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1027 | if (rectxt == NULL) |
| 1028 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1029 | } |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 1030 | #ifdef HAVE_SYS_MMAN_H |
| 1031 | } else if (memory) { |
| 1032 | int fd; |
| 1033 | struct stat info; |
| 1034 | const char *base; |
| 1035 | if (stat(filename, &info) < 0) |
| 1036 | return; |
| 1037 | if ((fd = open(filename, O_RDONLY)) < 0) |
| 1038 | return; |
| 1039 | base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; |
Daniel Veillard | 2957936 | 2000-08-14 17:57:48 +0000 | [diff] [blame] | 1040 | if (base == (void *) MAP_FAILED) |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 1041 | return; |
| 1042 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1043 | if (rectxt == NULL) |
Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 1044 | doc = xmlReadMemory((char *) base, info.st_size, |
| 1045 | filename, NULL, options); |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1046 | else |
Daniel Veillard | 60942de | 2003-09-25 21:05:58 +0000 | [diff] [blame] | 1047 | doc = xmlCtxtReadMemory(rectxt, (char *) base, info.st_size, |
| 1048 | filename, NULL, options); |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1049 | |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 1050 | munmap((char *) base, info.st_size); |
| 1051 | #endif |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1052 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1053 | } else if (valid) { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1054 | xmlParserCtxtPtr ctxt = NULL; |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1055 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1056 | if (rectxt == NULL) |
| 1057 | ctxt = xmlNewParserCtxt(); |
| 1058 | else |
| 1059 | ctxt = rectxt; |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1060 | if (ctxt == NULL) { |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1061 | doc = NULL; |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1062 | } else { |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1063 | doc = xmlCtxtReadFile(ctxt, filename, NULL, options); |
| 1064 | |
| 1065 | if (ctxt->valid == 0) |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1066 | progresult = XMLLINT_ERR_RDFILE; |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1067 | if (rectxt == NULL) |
| 1068 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1069 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1070 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1071 | } else { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1072 | if (rectxt != NULL) |
| 1073 | doc = xmlCtxtReadFile(rectxt, filename, NULL, options); |
| 1074 | else |
| 1075 | doc = xmlReadFile(filename, NULL, options); |
Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1076 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1077 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1078 | |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 1079 | /* |
| 1080 | * If we don't have a document we might as well give up. Do we |
| 1081 | * want an error message here? <sven@zen.org> */ |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 1082 | if (doc == NULL) { |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1083 | progresult = XMLLINT_ERR_UNCLASS; |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 1084 | return; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1087 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1088 | endTimer("Parsing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 1091 | /* |
| 1092 | * Remove DOCTYPE nodes |
| 1093 | */ |
| 1094 | if (dropdtd) { |
| 1095 | xmlDtdPtr dtd; |
| 1096 | |
| 1097 | dtd = xmlGetIntSubset(doc); |
| 1098 | if (dtd != NULL) { |
| 1099 | xmlUnlinkNode((xmlNodePtr)dtd); |
| 1100 | xmlFreeDtd(dtd); |
| 1101 | } |
| 1102 | } |
| 1103 | |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 1104 | #ifdef LIBXML_XINCLUDE_ENABLED |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1105 | if (xinclude) { |
| 1106 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1107 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1108 | } |
Daniel Veillard | e74d2e1 | 2003-12-09 11:35:37 +0000 | [diff] [blame] | 1109 | xmlXIncludeProcessFlags(doc, options); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1110 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1111 | endTimer("Xinclude processing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1112 | } |
| 1113 | } |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 1114 | #endif |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 1115 | |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1116 | #ifdef LIBXML_DEBUG_ENABLED |
| 1117 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1118 | * shell interaction |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1119 | */ |
| 1120 | if (shell) |
| 1121 | xmlShell(doc, filename, xmlShellReadline, stdout); |
| 1122 | #endif |
| 1123 | |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 1124 | #ifdef LIBXML_TREE_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1125 | /* |
| 1126 | * test intermediate copy if needed. |
| 1127 | */ |
| 1128 | if (copy) { |
| 1129 | tmp = doc; |
| 1130 | doc = xmlCopyDoc(doc, 1); |
| 1131 | xmlFreeDoc(tmp); |
| 1132 | } |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 1133 | #endif /* LIBXML_TREE_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1134 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1135 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1136 | if ((insert) && (!html)) { |
| 1137 | const xmlChar* list[256]; |
| 1138 | int nb, i; |
| 1139 | xmlNodePtr node; |
| 1140 | |
| 1141 | if (doc->children != NULL) { |
| 1142 | node = doc->children; |
| 1143 | while ((node != NULL) && (node->last == NULL)) node = node->next; |
| 1144 | if (node != NULL) { |
| 1145 | nb = xmlValidGetValidElements(node->last, NULL, list, 256); |
| 1146 | if (nb < 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1147 | fprintf(stderr, "could not get valid list of elements\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1148 | } else if (nb == 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1149 | fprintf(stderr, "No element can be inserted under root\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1150 | } else { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1151 | fprintf(stderr, "%d element types can be inserted under root:\n", |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1152 | nb); |
| 1153 | for (i = 0;i < nb;i++) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1154 | fprintf(stderr, "%s\n", (char *) list[i]); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1159 | }else |
| 1160 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1161 | #ifdef LIBXML_READER_ENABLED |
| 1162 | if (walker) { |
| 1163 | walkDoc(doc); |
| 1164 | } |
| 1165 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1166 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1167 | if (noout == 0) { |
Daniel Veillard | 3df0118 | 2003-12-10 10:17:51 +0000 | [diff] [blame] | 1168 | int ret; |
| 1169 | |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1170 | /* |
| 1171 | * print it. |
| 1172 | */ |
| 1173 | #ifdef LIBXML_DEBUG_ENABLED |
| 1174 | if (!debug) { |
| 1175 | #endif |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1176 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1177 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1178 | } |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 1179 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 1180 | if ((html) && (!xmlout)) { |
| 1181 | if (compress) { |
| 1182 | htmlSaveFile(output ? output : "-", doc); |
| 1183 | } |
| 1184 | else if (encoding != NULL) { |
| 1185 | if ( format ) { |
| 1186 | htmlSaveFileFormat(output ? output : "-", doc, encoding, 1); |
| 1187 | } |
| 1188 | else { |
| 1189 | htmlSaveFileFormat(output ? output : "-", doc, encoding, 0); |
| 1190 | } |
| 1191 | } |
| 1192 | else if (format) { |
| 1193 | htmlSaveFileFormat(output ? output : "-", doc, NULL, 1); |
| 1194 | } |
| 1195 | else { |
| 1196 | FILE *out; |
| 1197 | if (output == NULL) |
| 1198 | out = stdout; |
| 1199 | else { |
| 1200 | out = fopen(output,"wb"); |
| 1201 | } |
| 1202 | if (out != NULL) { |
| 1203 | if (htmlDocDump(out, doc) < 0) |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1204 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 1205 | |
| 1206 | if (output != NULL) |
| 1207 | fclose(out); |
| 1208 | } else { |
| 1209 | fprintf(stderr, "failed to open %s\n", output); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1210 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | if ((timing) && (!repeat)) { |
| 1214 | endTimer("Saving"); |
| 1215 | } |
| 1216 | } else |
| 1217 | #endif |
Daniel Veillard | 25048d8 | 2004-08-14 22:37:54 +0000 | [diff] [blame] | 1218 | #ifdef LIBXML_C14N_ENABLED |
| 1219 | if (canonical) { |
| 1220 | xmlChar *result = NULL; |
| 1221 | int size; |
| 1222 | |
| 1223 | size = xmlC14NDocDumpMemory(doc, NULL, 0, NULL, 1, &result); |
| 1224 | if (size >= 0) { |
| 1225 | write(1, result, size); |
| 1226 | xmlFree(result); |
| 1227 | } else { |
| 1228 | fprintf(stderr, "Failed to canonicalize\n"); |
| 1229 | progresult = XMLLINT_ERR_OUT; |
| 1230 | } |
| 1231 | } else |
| 1232 | #endif |
Daniel Veillard | 3b2c261 | 2001-04-04 00:09:00 +0000 | [diff] [blame] | 1233 | #ifdef HAVE_SYS_MMAN_H |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 1234 | if (memory) { |
| 1235 | xmlChar *result; |
| 1236 | int len; |
| 1237 | |
| 1238 | if (encoding != NULL) { |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 1239 | if ( format ) { |
| 1240 | xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1); |
| 1241 | } else { |
| 1242 | xmlDocDumpMemoryEnc(doc, &result, &len, encoding); |
| 1243 | } |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 1244 | } else { |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 1245 | if (format) |
| 1246 | xmlDocDumpFormatMemory(doc, &result, &len, 1); |
| 1247 | else |
| 1248 | xmlDocDumpMemory(doc, &result, &len); |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 1249 | } |
| 1250 | if (result == NULL) { |
| 1251 | fprintf(stderr, "Failed to save\n"); |
Daniel Veillard | 25048d8 | 2004-08-14 22:37:54 +0000 | [diff] [blame] | 1252 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 1253 | } else { |
| 1254 | write(1, result, len); |
| 1255 | xmlFree(result); |
| 1256 | } |
Daniel Veillard | 3b2c261 | 2001-04-04 00:09:00 +0000 | [diff] [blame] | 1257 | } else |
| 1258 | #endif /* HAVE_SYS_MMAN_H */ |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1259 | if (compress) { |
| 1260 | xmlSaveFile(output ? output : "-", doc); |
| 1261 | } |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 1262 | else if (encoding != NULL) { |
| 1263 | if ( format ) { |
Daniel Veillard | 3df0118 | 2003-12-10 10:17:51 +0000 | [diff] [blame] | 1264 | ret = xmlSaveFormatFileEnc(output ? output : "-", doc, |
| 1265 | encoding, 1); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1266 | } |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 1267 | else { |
Daniel Veillard | 3df0118 | 2003-12-10 10:17:51 +0000 | [diff] [blame] | 1268 | ret = xmlSaveFileEnc(output ? output : "-", doc, encoding); |
| 1269 | } |
| 1270 | if (ret < 0) { |
| 1271 | fprintf(stderr, "failed save to %s\n", |
| 1272 | output ? output : "-"); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1273 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | d536f70 | 2001-11-08 17:32:47 +0000 | [diff] [blame] | 1274 | } |
| 1275 | } |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1276 | else if (format) { |
Daniel Veillard | 3df0118 | 2003-12-10 10:17:51 +0000 | [diff] [blame] | 1277 | ret = xmlSaveFormatFile(output ? output : "-", doc, 1); |
| 1278 | if (ret < 0) { |
| 1279 | fprintf(stderr, "failed save to %s\n", |
| 1280 | output ? output : "-"); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1281 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 3df0118 | 2003-12-10 10:17:51 +0000 | [diff] [blame] | 1282 | } |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1283 | } |
| 1284 | else { |
| 1285 | FILE *out; |
| 1286 | if (output == NULL) |
| 1287 | out = stdout; |
| 1288 | else { |
| 1289 | out = fopen(output,"wb"); |
| 1290 | } |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 1291 | if (out != NULL) { |
Daniel Veillard | 828ce83 | 2003-10-08 19:19:10 +0000 | [diff] [blame] | 1292 | if (xmlDocDump(out, doc) < 0) |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1293 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1294 | |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 1295 | if (output != NULL) |
| 1296 | fclose(out); |
| 1297 | } else { |
| 1298 | fprintf(stderr, "failed to open %s\n", output); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1299 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 1300 | } |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1301 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1302 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1303 | endTimer("Saving"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1304 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1305 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 1306 | } else { |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1307 | FILE *out; |
| 1308 | if (output == NULL) |
| 1309 | out = stdout; |
| 1310 | else { |
| 1311 | out = fopen(output,"wb"); |
| 1312 | } |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 1313 | if (out != NULL) { |
| 1314 | xmlDebugDumpDocument(out, doc); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1315 | |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 1316 | if (output != NULL) |
| 1317 | fclose(out); |
| 1318 | } else { |
| 1319 | fprintf(stderr, "failed to open %s\n", output); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1320 | progresult = XMLLINT_ERR_OUT; |
Daniel Veillard | 05d987b | 2003-10-08 11:54:57 +0000 | [diff] [blame] | 1321 | } |
Daniel Veillard | a6d8eb6 | 2000-12-27 10:46:47 +0000 | [diff] [blame] | 1322 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1323 | #endif |
| 1324 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1325 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1326 | |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1327 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1328 | /* |
| 1329 | * A posteriori validation test |
| 1330 | */ |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 1331 | if ((dtdvalid != NULL) || (dtdvalidfpi != NULL)) { |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1332 | xmlDtdPtr dtd; |
| 1333 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1334 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1335 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1336 | } |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 1337 | if (dtdvalid != NULL) |
| 1338 | dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid); |
| 1339 | else |
| 1340 | dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1341 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1342 | endTimer("Parsing DTD"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1343 | } |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1344 | if (dtd == NULL) { |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 1345 | if (dtdvalid != NULL) |
| 1346 | xmlGenericError(xmlGenericErrorContext, |
| 1347 | "Could not parse DTD %s\n", dtdvalid); |
| 1348 | else |
| 1349 | xmlGenericError(xmlGenericErrorContext, |
| 1350 | "Could not parse DTD %s\n", dtdvalidfpi); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1351 | progresult = XMLLINT_ERR_DTD; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1352 | } else { |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 1353 | xmlValidCtxtPtr cvp; |
| 1354 | |
| 1355 | if ((cvp = xmlNewValidCtxt()) == NULL) { |
| 1356 | xmlGenericError(xmlGenericErrorContext, |
| 1357 | "Couldn't allocate validation context\n"); |
| 1358 | exit(-1); |
| 1359 | } |
| 1360 | cvp->userData = (void *) stderr; |
| 1361 | cvp->error = (xmlValidityErrorFunc) fprintf; |
| 1362 | cvp->warning = (xmlValidityWarningFunc) fprintf; |
| 1363 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1364 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1365 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1366 | } |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 1367 | if (!xmlValidateDtd(cvp, doc, dtd)) { |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 1368 | if (dtdvalid != NULL) |
| 1369 | xmlGenericError(xmlGenericErrorContext, |
| 1370 | "Document %s does not validate against %s\n", |
| 1371 | filename, dtdvalid); |
| 1372 | else |
| 1373 | xmlGenericError(xmlGenericErrorContext, |
| 1374 | "Document %s does not validate against %s\n", |
| 1375 | filename, dtdvalidfpi); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1376 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1377 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1378 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1379 | endTimer("Validating against DTD"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1380 | } |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 1381 | xmlFreeValidCtxt(cvp); |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1382 | xmlFreeDtd(dtd); |
| 1383 | } |
| 1384 | } else if (postvalid) { |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 1385 | xmlValidCtxtPtr cvp; |
| 1386 | |
| 1387 | if ((cvp = xmlNewValidCtxt()) == NULL) { |
| 1388 | xmlGenericError(xmlGenericErrorContext, |
| 1389 | "Couldn't allocate validation context\n"); |
| 1390 | exit(-1); |
| 1391 | } |
| 1392 | |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1393 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1394 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1395 | } |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 1396 | cvp->userData = (void *) stderr; |
| 1397 | cvp->error = (xmlValidityErrorFunc) fprintf; |
| 1398 | cvp->warning = (xmlValidityWarningFunc) fprintf; |
| 1399 | if (!xmlValidateDocument(cvp, doc)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1400 | xmlGenericError(xmlGenericErrorContext, |
| 1401 | "Document %s does not validate\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1402 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1403 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1404 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1405 | endTimer("Validating"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1406 | } |
Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 1407 | xmlFreeValidCtxt(cvp); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1408 | } |
| 1409 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1410 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1411 | if (relaxngschemas != NULL) { |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1412 | xmlRelaxNGValidCtxtPtr ctxt; |
| 1413 | int ret; |
| 1414 | |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 1415 | if ((timing) && (!repeat)) { |
| 1416 | startTimer(); |
| 1417 | } |
| 1418 | |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1419 | ctxt = xmlRelaxNGNewValidCtxt(relaxngschemas); |
| 1420 | xmlRelaxNGSetValidErrors(ctxt, |
| 1421 | (xmlRelaxNGValidityErrorFunc) fprintf, |
| 1422 | (xmlRelaxNGValidityWarningFunc) fprintf, |
| 1423 | stderr); |
| 1424 | ret = xmlRelaxNGValidateDoc(ctxt, doc); |
| 1425 | if (ret == 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1426 | fprintf(stderr, "%s validates\n", filename); |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1427 | } else if (ret > 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1428 | fprintf(stderr, "%s fails to validate\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1429 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1430 | } else { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1431 | fprintf(stderr, "%s validation generated an internal error\n", |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1432 | filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1433 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1434 | } |
| 1435 | xmlRelaxNGFreeValidCtxt(ctxt); |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 1436 | if ((timing) && (!repeat)) { |
| 1437 | endTimer("Validating"); |
| 1438 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1439 | } else if (wxschemas != NULL) { |
| 1440 | xmlSchemaValidCtxtPtr ctxt; |
| 1441 | int ret; |
| 1442 | |
| 1443 | if ((timing) && (!repeat)) { |
| 1444 | startTimer(); |
| 1445 | } |
| 1446 | |
| 1447 | ctxt = xmlSchemaNewValidCtxt(wxschemas); |
| 1448 | xmlSchemaSetValidErrors(ctxt, |
| 1449 | (xmlSchemaValidityErrorFunc) fprintf, |
| 1450 | (xmlSchemaValidityWarningFunc) fprintf, |
| 1451 | stderr); |
| 1452 | ret = xmlSchemaValidateDoc(ctxt, doc); |
| 1453 | if (ret == 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1454 | fprintf(stderr, "%s validates\n", filename); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1455 | } else if (ret > 0) { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1456 | fprintf(stderr, "%s fails to validate\n", filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1457 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1458 | } else { |
Daniel Veillard | d21f61b | 2003-12-29 10:31:21 +0000 | [diff] [blame] | 1459 | fprintf(stderr, "%s validation generated an internal error\n", |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1460 | filename); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 1461 | progresult = XMLLINT_ERR_VALID; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1462 | } |
| 1463 | xmlSchemaFreeValidCtxt(ctxt); |
| 1464 | if ((timing) && (!repeat)) { |
| 1465 | endTimer("Validating"); |
| 1466 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1467 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1468 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1469 | |
| 1470 | #ifdef LIBXML_DEBUG_ENABLED |
| 1471 | if ((debugent) && (!html)) |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1472 | xmlDebugDumpEntities(stderr, doc); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1473 | #endif |
| 1474 | |
| 1475 | /* |
| 1476 | * free it. |
| 1477 | */ |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1478 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1479 | startTimer(); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1480 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1481 | xmlFreeDoc(doc); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1482 | if ((timing) && (!repeat)) { |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 1483 | endTimer("Freeing"); |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1484 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1487 | /************************************************************************ |
| 1488 | * * |
| 1489 | * Usage and Main * |
| 1490 | * * |
| 1491 | ************************************************************************/ |
| 1492 | |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 1493 | static void showVersion(const char *name) { |
| 1494 | fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion); |
| 1495 | fprintf(stderr, " compiled with: "); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1496 | #ifdef LIBXML_VALID_ENABLED |
| 1497 | fprintf(stderr, "DTDValid "); |
| 1498 | #endif |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 1499 | #ifdef LIBXML_FTP_ENABLED |
| 1500 | fprintf(stderr, "FTP "); |
| 1501 | #endif |
| 1502 | #ifdef LIBXML_HTTP_ENABLED |
| 1503 | fprintf(stderr, "HTTP "); |
| 1504 | #endif |
| 1505 | #ifdef LIBXML_HTML_ENABLED |
| 1506 | fprintf(stderr, "HTML "); |
| 1507 | #endif |
| 1508 | #ifdef LIBXML_C14N_ENABLED |
| 1509 | fprintf(stderr, "C14N "); |
| 1510 | #endif |
| 1511 | #ifdef LIBXML_CATALOG_ENABLED |
| 1512 | fprintf(stderr, "Catalog "); |
| 1513 | #endif |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 1514 | #ifdef LIBXML_XPATH_ENABLED |
| 1515 | fprintf(stderr, "XPath "); |
| 1516 | #endif |
| 1517 | #ifdef LIBXML_XPTR_ENABLED |
| 1518 | fprintf(stderr, "XPointer "); |
| 1519 | #endif |
| 1520 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 1521 | fprintf(stderr, "XInclude "); |
| 1522 | #endif |
| 1523 | #ifdef LIBXML_ICONV_ENABLED |
| 1524 | fprintf(stderr, "Iconv "); |
| 1525 | #endif |
| 1526 | #ifdef DEBUG_MEMORY_LOCATION |
| 1527 | fprintf(stderr, "MemDebug "); |
| 1528 | #endif |
| 1529 | #ifdef LIBXML_UNICODE_ENABLED |
| 1530 | fprintf(stderr, "Unicode "); |
| 1531 | #endif |
| 1532 | #ifdef LIBXML_REGEXP_ENABLED |
| 1533 | fprintf(stderr, "Regexps "); |
| 1534 | #endif |
| 1535 | #ifdef LIBXML_AUTOMATA_ENABLED |
| 1536 | fprintf(stderr, "Automata "); |
| 1537 | #endif |
| 1538 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 1539 | fprintf(stderr, "Schemas "); |
| 1540 | #endif |
| 1541 | fprintf(stderr, "\n"); |
| 1542 | } |
| 1543 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1544 | static void usage(const char *name) { |
| 1545 | printf("Usage : %s [options] XMLfiles ...\n", name); |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1546 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1547 | 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] | 1548 | #else |
| 1549 | printf("\tParse the XML files\n"); |
| 1550 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1551 | printf("\t--version : display the version of the XML library used\n"); |
| 1552 | #ifdef LIBXML_DEBUG_ENABLED |
| 1553 | printf("\t--debug : dump a debug tree of the in-memory document\n"); |
| 1554 | printf("\t--shell : run a navigating shell\n"); |
| 1555 | printf("\t--debugent : debug the entities defined in the document\n"); |
Daniel Veillard | 8326e73 | 2003-01-07 00:19:07 +0000 | [diff] [blame] | 1556 | #else |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1557 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 8326e73 | 2003-01-07 00:19:07 +0000 | [diff] [blame] | 1558 | printf("\t--debug : dump the nodes content when using --stream\n"); |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1559 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1560 | #endif |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 1561 | #ifdef LIBXML_TREE_ENABLED |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1562 | printf("\t--copy : used to test the internal copy implementation\n"); |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 1563 | #endif /* LIBXML_TREE_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1564 | printf("\t--recover : output what was parsable on broken XML documents\n"); |
| 1565 | printf("\t--noent : substitute entity references by their value\n"); |
| 1566 | printf("\t--noout : don't output the result tree\n"); |
Daniel Veillard | e8b09e4 | 2003-05-13 22:14:13 +0000 | [diff] [blame] | 1567 | printf("\t--nonet : refuse to fetch DTDs or entities over network\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1568 | printf("\t--htmlout : output results as HTML\n"); |
Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 1569 | printf("\t--nowrap : do not put HTML doc wrapper\n"); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1570 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1571 | printf("\t--valid : validate the document in addition to std well-formed check\n"); |
| 1572 | printf("\t--postvalid : do a posteriori validation, i.e after parsing\n"); |
| 1573 | 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] | 1574 | 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] | 1575 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1576 | printf("\t--timing : print some timings\n"); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1577 | 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] | 1578 | printf("\t--repeat : repeat 100 times, for timing or profiling\n"); |
| 1579 | printf("\t--insert : ad-hoc test for valid insertions\n"); |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1580 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1581 | #ifdef HAVE_ZLIB_H |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1582 | printf("\t--compress : turn on gzip compression of output\n"); |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1583 | #endif |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1584 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1585 | #ifdef LIBXML_HTML_ENABLED |
| 1586 | printf("\t--html : use the HTML parser\n"); |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 1587 | printf("\t--xmlout : force to use the XML serializer when using --html\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1588 | #endif |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 1589 | #ifdef LIBXML_PUSH_ENABLED |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1590 | printf("\t--push : use the push mode of the parser\n"); |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 1591 | #endif /* LIBXML_PUSH_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1592 | #ifdef HAVE_SYS_MMAN_H |
| 1593 | printf("\t--memory : parse from memory\n"); |
| 1594 | #endif |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 1595 | printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1596 | printf("\t--nowarning : do not emit warnings from parser/validator\n"); |
| 1597 | printf("\t--noblanks : drop (ignorable?) blanks spaces\n"); |
Daniel Veillard | dca8cc7 | 2003-09-26 13:53:14 +0000 | [diff] [blame] | 1598 | printf("\t--nocdata : replace cdata section with text nodes\n"); |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1599 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 1600 | printf("\t--format : reformat/reindent the input\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1601 | printf("\t--encode encoding : output in the given encoding\n"); |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1602 | printf("\t--dropdtd : remove the DOCTYPE of the input docs\n"); |
| 1603 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 25048d8 | 2004-08-14 22:37:54 +0000 | [diff] [blame] | 1604 | printf("\t--c14n: save in W3C canonical format (with comments)\n"); |
| 1605 | #ifdef LIBXML_C14N_ENABLED |
| 1606 | #endif /* LIBXML_C14N_ENABLED */ |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1607 | printf("\t--nsclean : remove redundant namespace declarations\n"); |
| 1608 | printf("\t--testIO : test user I/O support\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1609 | #ifdef LIBXML_CATALOG_ENABLED |
Daniel Veillard | bd9b0e8 | 2001-11-26 10:32:08 +0000 | [diff] [blame] | 1610 | printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n"); |
| 1611 | printf("\t otherwise XML Catalogs starting from \n"); |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 1612 | printf("\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG); |
Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 1613 | printf("\t--nocatalogs: deactivate all catalogs\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1614 | #endif |
| 1615 | printf("\t--auto : generate a small doc on the fly\n"); |
| 1616 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 1617 | printf("\t--xinclude : do XInclude processing\n"); |
Daniel Veillard | c14c389 | 2004-08-16 12:34:50 +0000 | [diff] [blame] | 1618 | printf("\t--noxincludenode : same but do not generate XInclude nodes\n"); |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1619 | #endif |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1620 | printf("\t--loaddtd : fetch external DTD\n"); |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 1621 | printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n"); |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1622 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1623 | 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] | 1624 | 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] | 1625 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 1626 | #ifdef LIBXML_PATTERN_ENABLED |
| 1627 | printf("\t--pattern pattern_value : test the pattern support\n"); |
| 1628 | #endif |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1629 | printf("\t--chkregister : verify the node registration code\n"); |
Daniel Veillard | ef4d3bc | 2003-02-07 12:38:22 +0000 | [diff] [blame] | 1630 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1631 | printf("\t--relaxng schema : do RelaxNG validation against the schema\n"); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1632 | printf("\t--schema schema : do validation against the WXS schema\n"); |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1633 | #endif |
Daniel Veillard | a42f25f | 2002-01-25 14:15:40 +0000 | [diff] [blame] | 1634 | printf("\nLibxml project home page: http://xmlsoft.org/\n"); |
| 1635 | 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] | 1636 | } |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1637 | |
| 1638 | static void registerNode(xmlNodePtr node) |
| 1639 | { |
| 1640 | node->_private = malloc(sizeof(long)); |
| 1641 | *(long*)node->_private = (long) 0x81726354; |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 1642 | nbregister++; |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | static void deregisterNode(xmlNodePtr node) |
| 1646 | { |
| 1647 | assert(node->_private != NULL); |
| 1648 | assert(*(long*)node->_private == (long) 0x81726354); |
| 1649 | free(node->_private); |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 1650 | nbregister--; |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 1653 | int |
| 1654 | main(int argc, char **argv) { |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1655 | int i, acount; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1656 | int files = 0; |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 1657 | int version = 0; |
Aleksey Sanin | 693c9bc | 2003-03-09 22:36:52 +0000 | [diff] [blame] | 1658 | const char* indent; |
| 1659 | |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1660 | if (argc <= 1) { |
| 1661 | usage(argv[0]); |
| 1662 | return(1); |
| 1663 | } |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1664 | LIBXML_TEST_VERSION |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1665 | for (i = 1; i < argc ; i++) { |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1666 | if (!strcmp(argv[i], "-")) |
| 1667 | break; |
| 1668 | |
| 1669 | if (argv[i][0] != '-') |
| 1670 | continue; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1671 | if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) |
| 1672 | debug++; |
Daniel Veillard | 56ada1d | 2003-01-07 11:17:25 +0000 | [diff] [blame] | 1673 | else |
| 1674 | #ifdef LIBXML_DEBUG_ENABLED |
| 1675 | if ((!strcmp(argv[i], "-shell")) || |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1676 | (!strcmp(argv[i], "--shell"))) { |
| 1677 | shell++; |
| 1678 | noout = 1; |
| 1679 | } else |
| 1680 | #endif |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 1681 | #ifdef LIBXML_TREE_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1682 | if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) |
| 1683 | copy++; |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 1684 | else |
| 1685 | #endif /* LIBXML_TREE_ENABLED */ |
| 1686 | if ((!strcmp(argv[i], "-recover")) || |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1687 | (!strcmp(argv[i], "--recover"))) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1688 | recovery++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1689 | options |= XML_PARSE_RECOVER; |
| 1690 | } else if ((!strcmp(argv[i], "-noent")) || |
| 1691 | (!strcmp(argv[i], "--noent"))) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1692 | noent++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1693 | options |= XML_PARSE_NOENT; |
Daniel Veillard | dca8cc7 | 2003-09-26 13:53:14 +0000 | [diff] [blame] | 1694 | } else if ((!strcmp(argv[i], "-nsclean")) || |
| 1695 | (!strcmp(argv[i], "--nsclean"))) { |
| 1696 | options |= XML_PARSE_NSCLEAN; |
| 1697 | } else if ((!strcmp(argv[i], "-nocdata")) || |
| 1698 | (!strcmp(argv[i], "--nocdata"))) { |
| 1699 | options |= XML_PARSE_NOCDATA; |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 1700 | } else if ((!strcmp(argv[i], "-nodict")) || |
| 1701 | (!strcmp(argv[i], "--nodict"))) { |
| 1702 | options |= XML_PARSE_NODICT; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1703 | } else if ((!strcmp(argv[i], "-version")) || |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 1704 | (!strcmp(argv[i], "--version"))) { |
Daniel Veillard | 0f04f8e | 2002-09-17 23:04:40 +0000 | [diff] [blame] | 1705 | showVersion(argv[0]); |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 1706 | version = 1; |
| 1707 | } else if ((!strcmp(argv[i], "-noout")) || |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1708 | (!strcmp(argv[i], "--noout"))) |
| 1709 | noout++; |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1710 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1711 | else if ((!strcmp(argv[i], "-o")) || |
| 1712 | (!strcmp(argv[i], "-output")) || |
| 1713 | (!strcmp(argv[i], "--output"))) { |
| 1714 | i++; |
Daniel Veillard | 6e4f1c0 | 2002-04-09 09:55:20 +0000 | [diff] [blame] | 1715 | output = argv[i]; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1716 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1717 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1718 | else if ((!strcmp(argv[i], "-htmlout")) || |
| 1719 | (!strcmp(argv[i], "--htmlout"))) |
| 1720 | htmlout++; |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1721 | else if ((!strcmp(argv[i], "-nowrap")) || |
| 1722 | (!strcmp(argv[i], "--nowrap"))) |
| 1723 | nowrap++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1724 | #ifdef LIBXML_HTML_ENABLED |
| 1725 | else if ((!strcmp(argv[i], "-html")) || |
| 1726 | (!strcmp(argv[i], "--html"))) { |
| 1727 | html++; |
| 1728 | } |
Daniel Veillard | 42fd412 | 2003-11-04 08:47:48 +0000 | [diff] [blame] | 1729 | else if ((!strcmp(argv[i], "-xmlout")) || |
| 1730 | (!strcmp(argv[i], "--xmlout"))) { |
| 1731 | xmlout++; |
| 1732 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1733 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1734 | else if ((!strcmp(argv[i], "-loaddtd")) || |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1735 | (!strcmp(argv[i], "--loaddtd"))) { |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1736 | loaddtd++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1737 | options |= XML_PARSE_DTDLOAD; |
| 1738 | } else if ((!strcmp(argv[i], "-dtdattr")) || |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 1739 | (!strcmp(argv[i], "--dtdattr"))) { |
| 1740 | loaddtd++; |
| 1741 | dtdattrs++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1742 | options |= XML_PARSE_DTDATTR; |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1743 | } |
| 1744 | #ifdef LIBXML_VALID_ENABLED |
| 1745 | else if ((!strcmp(argv[i], "-valid")) || |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1746 | (!strcmp(argv[i], "--valid"))) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1747 | valid++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1748 | options |= XML_PARSE_DTDVALID; |
| 1749 | } else if ((!strcmp(argv[i], "-postvalid")) || |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1750 | (!strcmp(argv[i], "--postvalid"))) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1751 | postvalid++; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1752 | loaddtd++; |
Daniel Veillard | 5a30b2d | 2003-12-09 13:54:39 +0000 | [diff] [blame] | 1753 | options |= XML_PARSE_DTDLOAD; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1754 | } else if ((!strcmp(argv[i], "-dtdvalid")) || |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1755 | (!strcmp(argv[i], "--dtdvalid"))) { |
| 1756 | i++; |
| 1757 | dtdvalid = argv[i]; |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1758 | loaddtd++; |
Daniel Veillard | 5a30b2d | 2003-12-09 13:54:39 +0000 | [diff] [blame] | 1759 | options |= XML_PARSE_DTDLOAD; |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 1760 | } else if ((!strcmp(argv[i], "-dtdvalidfpi")) || |
| 1761 | (!strcmp(argv[i], "--dtdvalidfpi"))) { |
| 1762 | i++; |
| 1763 | dtdvalidfpi = argv[i]; |
| 1764 | loaddtd++; |
Daniel Veillard | 5a30b2d | 2003-12-09 13:54:39 +0000 | [diff] [blame] | 1765 | options |= XML_PARSE_DTDLOAD; |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 1766 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1767 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 29e4399 | 2001-12-13 22:21:58 +0000 | [diff] [blame] | 1768 | else if ((!strcmp(argv[i], "-dropdtd")) || |
| 1769 | (!strcmp(argv[i], "--dropdtd"))) |
| 1770 | dropdtd++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1771 | else if ((!strcmp(argv[i], "-insert")) || |
| 1772 | (!strcmp(argv[i], "--insert"))) |
| 1773 | insert++; |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 1774 | else if ((!strcmp(argv[i], "-timing")) || |
| 1775 | (!strcmp(argv[i], "--timing"))) |
| 1776 | timing++; |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 1777 | else if ((!strcmp(argv[i], "-auto")) || |
| 1778 | (!strcmp(argv[i], "--auto"))) |
| 1779 | generate++; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1780 | else if ((!strcmp(argv[i], "-repeat")) || |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 1781 | (!strcmp(argv[i], "--repeat"))) { |
| 1782 | if (repeat) |
| 1783 | repeat *= 10; |
| 1784 | else |
| 1785 | repeat = 100; |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 1786 | } |
| 1787 | #ifdef LIBXML_PUSH_ENABLED |
| 1788 | else if ((!strcmp(argv[i], "-push")) || |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1789 | (!strcmp(argv[i], "--push"))) |
| 1790 | push++; |
Daniel Veillard | 73b013f | 2003-09-30 12:36:01 +0000 | [diff] [blame] | 1791 | #endif /* LIBXML_PUSH_ENABLED */ |
Daniel Veillard | 46e370e | 2000-07-21 20:32:03 +0000 | [diff] [blame] | 1792 | #ifdef HAVE_SYS_MMAN_H |
| 1793 | else if ((!strcmp(argv[i], "-memory")) || |
| 1794 | (!strcmp(argv[i], "--memory"))) |
| 1795 | memory++; |
| 1796 | #endif |
Daniel Veillard | 5e873c4 | 2000-04-12 13:27:38 +0000 | [diff] [blame] | 1797 | else if ((!strcmp(argv[i], "-testIO")) || |
| 1798 | (!strcmp(argv[i], "--testIO"))) |
| 1799 | testIO++; |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 1800 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 1801 | else if ((!strcmp(argv[i], "-xinclude")) || |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1802 | (!strcmp(argv[i], "--xinclude"))) { |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 1803 | xinclude++; |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1804 | options |= XML_PARSE_XINCLUDE; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1805 | } |
Daniel Veillard | c14c389 | 2004-08-16 12:34:50 +0000 | [diff] [blame] | 1806 | else if ((!strcmp(argv[i], "-noxincludenode")) || |
| 1807 | (!strcmp(argv[i], "--noxincludenode"))) { |
| 1808 | xinclude++; |
| 1809 | options |= XML_PARSE_XINCLUDE; |
| 1810 | options |= XML_PARSE_NOXINCNODE; |
| 1811 | } |
Daniel Veillard | 9e8bfae | 2000-11-06 16:43:11 +0000 | [diff] [blame] | 1812 | #endif |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1813 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1814 | #ifdef HAVE_ZLIB_H |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1815 | else if ((!strcmp(argv[i], "-compress")) || |
| 1816 | (!strcmp(argv[i], "--compress"))) { |
| 1817 | compress++; |
| 1818 | xmlSetCompressMode(9); |
| 1819 | } |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 1820 | #endif |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1821 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1822 | else if ((!strcmp(argv[i], "-nowarning")) || |
| 1823 | (!strcmp(argv[i], "--nowarning"))) { |
| 1824 | xmlGetWarningsDefaultValue = 0; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1825 | xmlPedanticParserDefault(0); |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1826 | options |= XML_PARSE_NOWARNING; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1827 | } |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1828 | else if ((!strcmp(argv[i], "-pedantic")) || |
| 1829 | (!strcmp(argv[i], "--pedantic"))) { |
| 1830 | xmlGetWarningsDefaultValue = 1; |
| 1831 | xmlPedanticParserDefault(1); |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1832 | options |= XML_PARSE_PEDANTIC; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1833 | } |
Daniel Veillard | 64c20ed | 2000-09-22 16:07:02 +0000 | [diff] [blame] | 1834 | #ifdef LIBXML_DEBUG_ENABLED |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1835 | else if ((!strcmp(argv[i], "-debugent")) || |
| 1836 | (!strcmp(argv[i], "--debugent"))) { |
| 1837 | debugent++; |
| 1838 | xmlParserDebugEntities = 1; |
| 1839 | } |
Daniel Veillard | 64c20ed | 2000-09-22 16:07:02 +0000 | [diff] [blame] | 1840 | #endif |
Daniel Veillard | 25048d8 | 2004-08-14 22:37:54 +0000 | [diff] [blame] | 1841 | #ifdef LIBXML_C14N_ENABLED |
| 1842 | else if ((!strcmp(argv[i], "-c14n")) || |
| 1843 | (!strcmp(argv[i], "--c14n"))) { |
| 1844 | canonical++; |
| 1845 | options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD; |
| 1846 | } |
| 1847 | #endif |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 1848 | #ifdef LIBXML_CATALOG_ENABLED |
| 1849 | else if ((!strcmp(argv[i], "-catalogs")) || |
| 1850 | (!strcmp(argv[i], "--catalogs"))) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1851 | catalogs++; |
| 1852 | } else if ((!strcmp(argv[i], "-nocatalogs")) || |
| 1853 | (!strcmp(argv[i], "--nocatalogs"))) { |
| 1854 | nocatalogs++; |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 1855 | } |
| 1856 | #endif |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1857 | else if ((!strcmp(argv[i], "-encode")) || |
| 1858 | (!strcmp(argv[i], "--encode"))) { |
| 1859 | i++; |
| 1860 | encoding = argv[i]; |
Daniel Veillard | f0cc7cc | 2000-08-26 21:40:43 +0000 | [diff] [blame] | 1861 | /* |
| 1862 | * OK it's for testing purposes |
| 1863 | */ |
| 1864 | xmlAddEncodingAlias("UTF-8", "DVEnc"); |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 1865 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1866 | else if ((!strcmp(argv[i], "-noblanks")) || |
| 1867 | (!strcmp(argv[i], "--noblanks"))) { |
| 1868 | noblanks++; |
| 1869 | xmlKeepBlanksDefault(0); |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 1870 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 1871 | else if ((!strcmp(argv[i], "-maxmem")) || |
| 1872 | (!strcmp(argv[i], "--maxmem"))) { |
| 1873 | i++; |
| 1874 | if (sscanf(argv[i], "%d", &maxmem) == 1) { |
| 1875 | xmlMemSetup(myFreeFunc, myMallocFunc, myReallocFunc, |
| 1876 | myStrdupFunc); |
| 1877 | } else { |
| 1878 | maxmem = 0; |
| 1879 | } |
| 1880 | } |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 1881 | else if ((!strcmp(argv[i], "-format")) || |
| 1882 | (!strcmp(argv[i], "--format"))) { |
| 1883 | noblanks++; |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1884 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 1885 | format++; |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1886 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 90493a9 | 2001-08-14 14:12:47 +0000 | [diff] [blame] | 1887 | xmlKeepBlanksDefault(0); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1888 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1889 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 1890 | else if ((!strcmp(argv[i], "-stream")) || |
| 1891 | (!strcmp(argv[i], "--stream"))) { |
| 1892 | stream++; |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1893 | } |
Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1894 | else if ((!strcmp(argv[i], "-walker")) || |
| 1895 | (!strcmp(argv[i], "--walker"))) { |
| 1896 | walker++; |
| 1897 | noout++; |
| 1898 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1899 | #endif /* LIBXML_READER_ENABLED */ |
| 1900 | #ifdef LIBXML_SAX1_ENABLED |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 1901 | else if ((!strcmp(argv[i], "-sax1")) || |
| 1902 | (!strcmp(argv[i], "--sax1"))) { |
| 1903 | sax1++; |
| 1904 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1905 | #endif /* LIBXML_SAX1_ENABLED */ |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1906 | else if ((!strcmp(argv[i], "-chkregister")) || |
| 1907 | (!strcmp(argv[i], "--chkregister"))) { |
| 1908 | chkregister++; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1909 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 1910 | } else if ((!strcmp(argv[i], "-relaxng")) || |
| 1911 | (!strcmp(argv[i], "--relaxng"))) { |
| 1912 | i++; |
| 1913 | relaxng = argv[i]; |
| 1914 | noent++; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 1915 | options |= XML_PARSE_NOENT; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 1916 | } else if ((!strcmp(argv[i], "-schema")) || |
| 1917 | (!strcmp(argv[i], "--schema"))) { |
| 1918 | i++; |
| 1919 | schema = argv[i]; |
| 1920 | noent++; |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1921 | #endif |
Daniel Veillard | e8b09e4 | 2003-05-13 22:14:13 +0000 | [diff] [blame] | 1922 | } else if ((!strcmp(argv[i], "-nonet")) || |
| 1923 | (!strcmp(argv[i], "--nonet"))) { |
Daniel Veillard | 61b9338 | 2003-11-03 14:28:31 +0000 | [diff] [blame] | 1924 | options |= XML_PARSE_NONET; |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 1925 | #ifdef LIBXML_PATTERN_ENABLED |
| 1926 | } else if ((!strcmp(argv[i], "-pattern")) || |
| 1927 | (!strcmp(argv[i], "--pattern"))) { |
| 1928 | i++; |
| 1929 | pattern = argv[i]; |
| 1930 | #endif |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 1931 | } else { |
| 1932 | fprintf(stderr, "Unknown option %s\n", argv[i]); |
| 1933 | usage(argv[0]); |
| 1934 | return(1); |
| 1935 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1936 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1937 | |
| 1938 | #ifdef LIBXML_CATALOG_ENABLED |
| 1939 | if (nocatalogs == 0) { |
| 1940 | if (catalogs) { |
| 1941 | const char *catal; |
| 1942 | |
| 1943 | catal = getenv("SGML_CATALOG_FILES"); |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 1944 | if (catal != NULL) { |
| 1945 | xmlLoadCatalogs(catal); |
| 1946 | } else { |
| 1947 | fprintf(stderr, "Variable $SGML_CATALOG_FILES not set\n"); |
| 1948 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1949 | } |
| 1950 | } |
| 1951 | #endif |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1952 | |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1953 | #ifdef LIBXML_SAX1_ENABLED |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 1954 | if (sax1) |
| 1955 | xmlSAXDefaultVersion(1); |
| 1956 | else |
| 1957 | xmlSAXDefaultVersion(2); |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1958 | #endif /* LIBXML_SAX1_ENABLED */ |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 1959 | |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1960 | if (chkregister) { |
| 1961 | xmlRegisterNodeDefault(registerNode); |
| 1962 | xmlDeregisterNodeDefault(deregisterNode); |
| 1963 | } |
Aleksey Sanin | 693c9bc | 2003-03-09 22:36:52 +0000 | [diff] [blame] | 1964 | |
| 1965 | indent = getenv("XMLLINT_INDENT"); |
| 1966 | if(indent != NULL) { |
| 1967 | xmlTreeIndentString = indent; |
| 1968 | } |
| 1969 | |
Daniel Veillard | 8a1b185 | 2003-01-05 22:37:17 +0000 | [diff] [blame] | 1970 | |
Daniel Veillard | d9bad13 | 2001-07-23 19:39:43 +0000 | [diff] [blame] | 1971 | xmlLineNumbersDefault(1); |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 1972 | if (loaddtd != 0) |
| 1973 | xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS; |
| 1974 | if (dtdattrs) |
| 1975 | xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1976 | if (noent != 0) xmlSubstituteEntitiesDefault(1); |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1977 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1978 | if (valid != 0) xmlDoValidityCheckingDefaultValue = 1; |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 1979 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1980 | if ((htmlout) && (!nowrap)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1981 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1982 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n"); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1983 | xmlGenericError(xmlGenericErrorContext, |
| 1984 | "\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"); |
| 1985 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1986 | "<html><head><title>%s output</title></head>\n", |
| 1987 | argv[0]); |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 1988 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 1989 | "<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n", |
| 1990 | argv[0]); |
| 1991 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1992 | |
| 1993 | #ifdef LIBXML_SCHEMAS_ENABLED |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1994 | if ((relaxng != NULL) |
| 1995 | #ifdef LIBXML_READER_ENABLED |
| 1996 | && (stream == 0) |
| 1997 | #endif /* LIBXML_READER_ENABLED */ |
| 1998 | ) { |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 1999 | xmlRelaxNGParserCtxtPtr ctxt; |
| 2000 | |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 2001 | /* forces loading the DTDs */ |
| 2002 | xmlLoadExtDtdDefaultValue |= 1; |
Daniel Veillard | 16fa96c | 2003-09-23 21:50:54 +0000 | [diff] [blame] | 2003 | options |= XML_PARSE_DTDLOAD; |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 2004 | if (timing) { |
| 2005 | startTimer(); |
| 2006 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2007 | ctxt = xmlRelaxNGNewParserCtxt(relaxng); |
| 2008 | xmlRelaxNGSetParserErrors(ctxt, |
| 2009 | (xmlRelaxNGValidityErrorFunc) fprintf, |
| 2010 | (xmlRelaxNGValidityWarningFunc) fprintf, |
| 2011 | stderr); |
| 2012 | relaxngschemas = xmlRelaxNGParse(ctxt); |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 2013 | if (relaxngschemas == NULL) { |
| 2014 | xmlGenericError(xmlGenericErrorContext, |
| 2015 | "Relax-NG schema %s failed to compile\n", relaxng); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2016 | progresult = XMLLINT_ERR_SCHEMACOMP; |
Daniel Veillard | ce192eb | 2003-04-16 15:58:05 +0000 | [diff] [blame] | 2017 | relaxng = NULL; |
| 2018 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2019 | xmlRelaxNGFreeParserCtxt(ctxt); |
Daniel Veillard | 42f12e9 | 2003-03-07 18:32:59 +0000 | [diff] [blame] | 2020 | if (timing) { |
| 2021 | endTimer("Compiling the schemas"); |
| 2022 | } |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 2023 | } else if ((schema != NULL) |
| 2024 | #ifdef LIBXML_READER_ENABLED |
| 2025 | && (stream == 0) |
| 2026 | #endif |
| 2027 | ) { |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 2028 | xmlSchemaParserCtxtPtr ctxt; |
| 2029 | |
| 2030 | if (timing) { |
| 2031 | startTimer(); |
| 2032 | } |
| 2033 | ctxt = xmlSchemaNewParserCtxt(schema); |
| 2034 | xmlSchemaSetParserErrors(ctxt, |
| 2035 | (xmlSchemaValidityErrorFunc) fprintf, |
| 2036 | (xmlSchemaValidityWarningFunc) fprintf, |
| 2037 | stderr); |
| 2038 | wxschemas = xmlSchemaParse(ctxt); |
| 2039 | if (wxschemas == NULL) { |
| 2040 | xmlGenericError(xmlGenericErrorContext, |
| 2041 | "WXS schema %s failed to compile\n", schema); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2042 | progresult = XMLLINT_ERR_SCHEMACOMP; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 2043 | schema = NULL; |
| 2044 | } |
| 2045 | xmlSchemaFreeParserCtxt(ctxt); |
| 2046 | if (timing) { |
| 2047 | endTimer("Compiling the schemas"); |
| 2048 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2049 | } |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 2050 | #endif /* LIBXML_SCHEMAS_ENABLED */ |
| 2051 | #ifdef LIBXML_PATTERN_ENABLED |
| 2052 | if (pattern != NULL) { |
Daniel Veillard | ffa7b7e | 2003-12-05 16:10:21 +0000 | [diff] [blame] | 2053 | patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL); |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 2054 | if (patternc == NULL) { |
| 2055 | xmlGenericError(xmlGenericErrorContext, |
| 2056 | "Pattern %s failed to compile\n", pattern); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2057 | progresult = XMLLINT_ERR_SCHEMAPAT; |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 2058 | pattern = NULL; |
| 2059 | } |
| 2060 | } |
| 2061 | #endif /* LIBXML_PATTERN_ENABLED */ |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2062 | for (i = 1; i < argc ; i++) { |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2063 | if ((!strcmp(argv[i], "-encode")) || |
| 2064 | (!strcmp(argv[i], "--encode"))) { |
| 2065 | i++; |
| 2066 | continue; |
Daniel Veillard | 1df3dfc | 2001-12-18 11:14:16 +0000 | [diff] [blame] | 2067 | } else if ((!strcmp(argv[i], "-o")) || |
| 2068 | (!strcmp(argv[i], "-output")) || |
| 2069 | (!strcmp(argv[i], "--output"))) { |
| 2070 | i++; |
| 2071 | continue; |
Daniel Veillard | be80396 | 2000-06-28 23:40:59 +0000 | [diff] [blame] | 2072 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2073 | #ifdef LIBXML_VALID_ENABLED |
Daniel Veillard | cd42961 | 2000-10-11 15:57:05 +0000 | [diff] [blame] | 2074 | if ((!strcmp(argv[i], "-dtdvalid")) || |
| 2075 | (!strcmp(argv[i], "--dtdvalid"))) { |
| 2076 | i++; |
| 2077 | continue; |
| 2078 | } |
Daniel Veillard | 66f68e7 | 2003-08-18 16:39:51 +0000 | [diff] [blame] | 2079 | if ((!strcmp(argv[i], "-dtdvalidfpi")) || |
| 2080 | (!strcmp(argv[i], "--dtdvalidfpi"))) { |
| 2081 | i++; |
| 2082 | continue; |
| 2083 | } |
Daniel Veillard | 4432df2 | 2003-09-28 18:58:27 +0000 | [diff] [blame] | 2084 | #endif /* LIBXML_VALID_ENABLED */ |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2085 | if ((!strcmp(argv[i], "-relaxng")) || |
| 2086 | (!strcmp(argv[i], "--relaxng"))) { |
| 2087 | i++; |
| 2088 | continue; |
| 2089 | } |
Daniel Veillard | 8707604 | 2004-05-03 22:54:49 +0000 | [diff] [blame] | 2090 | if ((!strcmp(argv[i], "-maxmem")) || |
| 2091 | (!strcmp(argv[i], "--maxmem"))) { |
| 2092 | i++; |
| 2093 | continue; |
| 2094 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 2095 | if ((!strcmp(argv[i], "-schema")) || |
| 2096 | (!strcmp(argv[i], "--schema"))) { |
| 2097 | i++; |
| 2098 | continue; |
| 2099 | } |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 2100 | #ifdef LIBXML_PATTERN_ENABLED |
| 2101 | if ((!strcmp(argv[i], "-pattern")) || |
| 2102 | (!strcmp(argv[i], "--pattern"))) { |
| 2103 | i++; |
| 2104 | continue; |
| 2105 | } |
| 2106 | #endif |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2107 | if ((timing) && (repeat)) |
Daniel Veillard | 01db67c | 2001-12-18 07:09:59 +0000 | [diff] [blame] | 2108 | startTimer(); |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2109 | /* Remember file names. "-" means stdin. <sven@zen.org> */ |
Daniel Veillard | 4a6845d | 2001-01-03 13:32:39 +0000 | [diff] [blame] | 2110 | if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) { |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2111 | if (repeat) { |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2112 | xmlParserCtxtPtr ctxt = NULL; |
| 2113 | |
| 2114 | for (acount = 0;acount < repeat;acount++) { |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2115 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 2116 | if (stream != 0) { |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 2117 | streamFile(argv[i]); |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 2118 | } else { |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2119 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2120 | if (ctxt == NULL) |
| 2121 | ctxt = xmlNewParserCtxt(); |
| 2122 | parseAndPrintFile(argv[i], ctxt); |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2123 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2124 | } |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2125 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2126 | } |
| 2127 | if (ctxt != NULL) |
| 2128 | xmlFreeParserCtxt(ctxt); |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 2129 | } else { |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 2130 | nbregister = 0; |
| 2131 | |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2132 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 2133 | if (stream != 0) |
| 2134 | streamFile(argv[i]); |
| 2135 | else |
Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 2136 | #endif /* LIBXML_READER_ENABLED */ |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2137 | parseAndPrintFile(argv[i], NULL); |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 2138 | |
| 2139 | if ((chkregister) && (nbregister != 0)) { |
| 2140 | fprintf(stderr, "Registration count off: %d\n", nbregister); |
William M. Brack | 8304d87 | 2004-06-08 13:29:32 +0000 | [diff] [blame] | 2141 | progresult = XMLLINT_ERR_RDREGIS; |
Daniel Veillard | a2d51fc | 2004-04-30 22:25:59 +0000 | [diff] [blame] | 2142 | } |
Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 2143 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2144 | files ++; |
Daniel Veillard | a786693 | 2001-12-04 13:14:44 +0000 | [diff] [blame] | 2145 | if ((timing) && (repeat)) { |
Daniel Veillard | 8d8bf2c | 2003-09-17 19:36:25 +0000 | [diff] [blame] | 2146 | endTimer("%d iterations", repeat); |
Daniel Veillard | a786693 | 2001-12-04 13:14:44 +0000 | [diff] [blame] | 2147 | } |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 2148 | } |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2149 | } |
Daniel Veillard | d2f3ec7 | 2001-04-11 07:50:02 +0000 | [diff] [blame] | 2150 | if (generate) |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2151 | parseAndPrintFile(NULL, NULL); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2152 | if ((htmlout) && (!nowrap)) { |
Daniel Veillard | d6d7f7b | 2000-10-25 19:56:55 +0000 | [diff] [blame] | 2153 | xmlGenericError(xmlGenericErrorContext, "</body></html>\n"); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2154 | } |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 2155 | if ((files == 0) && (!generate) && (version == 0)) { |
Daniel Veillard | 10ea86c | 2001-06-20 13:55:33 +0000 | [diff] [blame] | 2156 | usage(argv[0]); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2157 | } |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2158 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 2159 | if (relaxngschemas != NULL) |
| 2160 | xmlRelaxNGFree(relaxngschemas); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 2161 | if (wxschemas != NULL) |
| 2162 | xmlSchemaFree(wxschemas); |
Daniel Veillard | 71531f3 | 2003-02-05 13:19:53 +0000 | [diff] [blame] | 2163 | xmlRelaxNGCleanupTypes(); |
| 2164 | #endif |
Daniel Veillard | b3de70c | 2003-12-02 22:32:15 +0000 | [diff] [blame] | 2165 | #ifdef LIBXML_PATTERN_ENABLED |
| 2166 | if (patternc != NULL) |
| 2167 | xmlFreePattern(patternc); |
| 2168 | #endif |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2169 | xmlCleanupParser(); |
| 2170 | xmlMemoryDump(); |
| 2171 | |
Daniel Veillard | f7cd481 | 2001-02-23 18:44:52 +0000 | [diff] [blame] | 2172 | return(progresult); |
Daniel Veillard | ce8b83b | 2000-04-05 18:38:42 +0000 | [diff] [blame] | 2173 | } |
Daniel Veillard | 88a172f | 2000-08-04 18:23:10 +0000 | [diff] [blame] | 2174 | |