aboutsummaryrefslogtreecommitdiffstats
path: root/xmllint.c
diff options
context:
space:
mode:
Diffstat (limited to 'xmllint.c')
-rw-r--r--xmllint.c200
1 files changed, 91 insertions, 109 deletions
diff --git a/xmllint.c b/xmllint.c
index 67f7adb2..65125409 100644
--- a/xmllint.c
+++ b/xmllint.c
@@ -12,14 +12,6 @@
#include <stdarg.h>
#include <assert.h>
-#if defined (_WIN32) && !defined(__CYGWIN__)
-#if defined (_MSC_VER) || defined(__BORLANDC__)
-#include <winsock2.h>
-#pragma comment(lib, "ws2_32.lib")
-#define gettimeofday(p1,p2)
-#endif /* _MSC_VER */
-#endif /* _WIN32 */
-
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@@ -27,14 +19,6 @@
#include <time.h>
#endif
-#ifdef __MINGW32__
-#define _WINSOCKAPI_
-#include <wsockcompat.h>
-#include <winsock2.h>
-#undef XML_SOCKLEN_T
-#define XML_SOCKLEN_T unsigned int
-#endif
-
#ifdef HAVE_SYS_TIMEB_H
#include <sys/timeb.h>
#endif
@@ -830,13 +814,14 @@ xmlShellReadline(char *prompt) {
* *
************************************************************************/
-static int myRead(FILE *f, char * buf, int len) {
- return(fread(buf, 1, len, f));
+static int myRead(void *f, char *buf, int len) {
+ return(fread(buf, 1, len, (FILE *) f));
}
-static void myClose(FILE *f) {
- if (f != stdin) {
- fclose(f);
- }
+static int myClose(void *context) {
+ FILE *f = (FILE *) context;
+ if (f == stdin)
+ return(0);
+ return(fclose(f));
}
/************************************************************************
@@ -2319,14 +2304,11 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
#endif
if (f != NULL) {
if (rectxt == NULL)
- doc = xmlReadIO((xmlInputReadCallback) myRead,
- (xmlInputCloseCallback) myClose, f,
- filename, NULL, options);
+ doc = xmlReadIO(myRead, myClose, f, filename, NULL,
+ options);
else
- doc = xmlCtxtReadIO(rectxt,
- (xmlInputReadCallback) myRead,
- (xmlInputCloseCallback) myClose, f,
- filename, NULL, options);
+ doc = xmlCtxtReadIO(rectxt, myRead, myClose, f,
+ filename, NULL, options);
} else
doc = NULL;
}
@@ -2991,124 +2973,124 @@ static void showVersion(const char *name) {
fprintf(stderr, "\n");
}
-static void usage(const char *name) {
- printf("Usage : %s [options] XMLfiles ...\n", name);
+static void usage(FILE *f, const char *name) {
+ fprintf(f, "Usage : %s [options] XMLfiles ...\n", name);
#ifdef LIBXML_OUTPUT_ENABLED
- printf("\tParse the XML files and output the result of the parsing\n");
+ fprintf(f, "\tParse the XML files and output the result of the parsing\n");
#else
- printf("\tParse the XML files\n");
+ fprintf(f, "\tParse the XML files\n");
#endif /* LIBXML_OUTPUT_ENABLED */
- printf("\t--version : display the version of the XML library used\n");
+ fprintf(f, "\t--version : display the version of the XML library used\n");
#ifdef LIBXML_DEBUG_ENABLED
- printf("\t--debug : dump a debug tree of the in-memory document\n");
- printf("\t--shell : run a navigating shell\n");
- printf("\t--debugent : debug the entities defined in the document\n");
+ fprintf(f, "\t--debug : dump a debug tree of the in-memory document\n");
+ fprintf(f, "\t--shell : run a navigating shell\n");
+ fprintf(f, "\t--debugent : debug the entities defined in the document\n");
#else
#ifdef LIBXML_READER_ENABLED
- printf("\t--debug : dump the nodes content when using --stream\n");
+ fprintf(f, "\t--debug : dump the nodes content when using --stream\n");
#endif /* LIBXML_READER_ENABLED */
#endif
#ifdef LIBXML_TREE_ENABLED
- printf("\t--copy : used to test the internal copy implementation\n");
+ fprintf(f, "\t--copy : used to test the internal copy implementation\n");
#endif /* LIBXML_TREE_ENABLED */
- printf("\t--recover : output what was parsable on broken XML documents\n");
- printf("\t--huge : remove any internal arbitrary parser limits\n");
- printf("\t--noent : substitute entity references by their value\n");
- printf("\t--noenc : ignore any encoding specified inside the document\n");
- printf("\t--noout : don't output the result tree\n");
- printf("\t--path 'paths': provide a set of paths for resources\n");
- printf("\t--load-trace : print trace of all external entities loaded\n");
- printf("\t--nonet : refuse to fetch DTDs or entities over network\n");
- printf("\t--nocompact : do not generate compact text nodes\n");
- printf("\t--htmlout : output results as HTML\n");
- printf("\t--nowrap : do not put HTML doc wrapper\n");
+ fprintf(f, "\t--recover : output what was parsable on broken XML documents\n");
+ fprintf(f, "\t--huge : remove any internal arbitrary parser limits\n");
+ fprintf(f, "\t--noent : substitute entity references by their value\n");
+ fprintf(f, "\t--noenc : ignore any encoding specified inside the document\n");
+ fprintf(f, "\t--noout : don't output the result tree\n");
+ fprintf(f, "\t--path 'paths': provide a set of paths for resources\n");
+ fprintf(f, "\t--load-trace : print trace of all external entities loaded\n");
+ fprintf(f, "\t--nonet : refuse to fetch DTDs or entities over network\n");
+ fprintf(f, "\t--nocompact : do not generate compact text nodes\n");
+ fprintf(f, "\t--htmlout : output results as HTML\n");
+ fprintf(f, "\t--nowrap : do not put HTML doc wrapper\n");
#ifdef LIBXML_VALID_ENABLED
- printf("\t--valid : validate the document in addition to std well-formed check\n");
- printf("\t--postvalid : do a posteriori validation, i.e after parsing\n");
- printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
- printf("\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
+ fprintf(f, "\t--valid : validate the document in addition to std well-formed check\n");
+ fprintf(f, "\t--postvalid : do a posteriori validation, i.e after parsing\n");
+ fprintf(f, "\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
+ fprintf(f, "\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
#endif /* LIBXML_VALID_ENABLED */
- printf("\t--timing : print some timings\n");
- printf("\t--output file or -o file: save to a given file\n");
- printf("\t--repeat : repeat 100 times, for timing or profiling\n");
- printf("\t--insert : ad-hoc test for valid insertions\n");
+ fprintf(f, "\t--timing : print some timings\n");
+ fprintf(f, "\t--output file or -o file: save to a given file\n");
+ fprintf(f, "\t--repeat : repeat 100 times, for timing or profiling\n");
+ fprintf(f, "\t--insert : ad-hoc test for valid insertions\n");
#ifdef LIBXML_OUTPUT_ENABLED
-#ifdef HAVE_ZLIB_H
- printf("\t--compress : turn on gzip compression of output\n");
+#ifdef LIBXML_ZLIB_ENABLED
+ fprintf(f, "\t--compress : turn on gzip compression of output\n");
#endif
#endif /* LIBXML_OUTPUT_ENABLED */
#ifdef LIBXML_HTML_ENABLED
- printf("\t--html : use the HTML parser\n");
- printf("\t--xmlout : force to use the XML serializer when using --html\n");
- printf("\t--nodefdtd : do not default HTML doctype\n");
+ fprintf(f, "\t--html : use the HTML parser\n");
+ fprintf(f, "\t--xmlout : force to use the XML serializer when using --html\n");
+ fprintf(f, "\t--nodefdtd : do not default HTML doctype\n");
#endif
#ifdef LIBXML_PUSH_ENABLED
- printf("\t--push : use the push mode of the parser\n");
- printf("\t--pushsmall : use the push mode of the parser using tiny increments\n");
+ fprintf(f, "\t--push : use the push mode of the parser\n");
+ fprintf(f, "\t--pushsmall : use the push mode of the parser using tiny increments\n");
#endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_MMAP
- printf("\t--memory : parse from memory\n");
+ fprintf(f, "\t--memory : parse from memory\n");
#endif
- printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");
- printf("\t--nowarning : do not emit warnings from parser/validator\n");
- printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
- printf("\t--nocdata : replace cdata section with text nodes\n");
+ fprintf(f, "\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");
+ fprintf(f, "\t--nowarning : do not emit warnings from parser/validator\n");
+ fprintf(f, "\t--noblanks : drop (ignorable?) blanks spaces\n");
+ fprintf(f, "\t--nocdata : replace cdata section with text nodes\n");
#ifdef LIBXML_OUTPUT_ENABLED
- printf("\t--format : reformat/reindent the output\n");
- printf("\t--encode encoding : output in the given encoding\n");
- printf("\t--dropdtd : remove the DOCTYPE of the input docs\n");
- printf("\t--pretty STYLE : pretty-print in a particular style\n");
- printf("\t 0 Do not pretty print\n");
- printf("\t 1 Format the XML content, as --format\n");
- printf("\t 2 Add whitespace inside tags, preserving content\n");
+ fprintf(f, "\t--format : reformat/reindent the output\n");
+ fprintf(f, "\t--encode encoding : output in the given encoding\n");
+ fprintf(f, "\t--dropdtd : remove the DOCTYPE of the input docs\n");
+ fprintf(f, "\t--pretty STYLE : pretty-print in a particular style\n");
+ fprintf(f, "\t 0 Do not pretty print\n");
+ fprintf(f, "\t 1 Format the XML content, as --format\n");
+ fprintf(f, "\t 2 Add whitespace inside tags, preserving content\n");
#endif /* LIBXML_OUTPUT_ENABLED */
- printf("\t--c14n : save in W3C canonical format v1.0 (with comments)\n");
- printf("\t--c14n11 : save in W3C canonical format v1.1 (with comments)\n");
- printf("\t--exc-c14n : save in W3C exclusive canonical format (with comments)\n");
+ fprintf(f, "\t--c14n : save in W3C canonical format v1.0 (with comments)\n");
+ fprintf(f, "\t--c14n11 : save in W3C canonical format v1.1 (with comments)\n");
+ fprintf(f, "\t--exc-c14n : save in W3C exclusive canonical format (with comments)\n");
#ifdef LIBXML_C14N_ENABLED
#endif /* LIBXML_C14N_ENABLED */
- printf("\t--nsclean : remove redundant namespace declarations\n");
- printf("\t--testIO : test user I/O support\n");
+ fprintf(f, "\t--nsclean : remove redundant namespace declarations\n");
+ fprintf(f, "\t--testIO : test user I/O support\n");
#ifdef LIBXML_CATALOG_ENABLED
- printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");
- printf("\t otherwise XML Catalogs starting from \n");
- printf("\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG);
- printf("\t--nocatalogs: deactivate all catalogs\n");
+ fprintf(f, "\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");
+ fprintf(f, "\t otherwise XML Catalogs starting from \n");
+ fprintf(f, "\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG);
+ fprintf(f, "\t--nocatalogs: deactivate all catalogs\n");
#endif
- printf("\t--auto : generate a small doc on the fly\n");
+ fprintf(f, "\t--auto : generate a small doc on the fly\n");
#ifdef LIBXML_XINCLUDE_ENABLED
- printf("\t--xinclude : do XInclude processing\n");
- printf("\t--noxincludenode : same but do not generate XInclude nodes\n");
- printf("\t--nofixup-base-uris : do not fixup xml:base uris\n");
+ fprintf(f, "\t--xinclude : do XInclude processing\n");
+ fprintf(f, "\t--noxincludenode : same but do not generate XInclude nodes\n");
+ fprintf(f, "\t--nofixup-base-uris : do not fixup xml:base uris\n");
#endif
- printf("\t--loaddtd : fetch external DTD\n");
- printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
+ fprintf(f, "\t--loaddtd : fetch external DTD\n");
+ fprintf(f, "\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
#ifdef LIBXML_READER_ENABLED
- printf("\t--stream : use the streaming interface to process very large files\n");
- printf("\t--walker : create a reader and walk though the resulting doc\n");
+ fprintf(f, "\t--stream : use the streaming interface to process very large files\n");
+ fprintf(f, "\t--walker : create a reader and walk though the resulting doc\n");
#endif /* LIBXML_READER_ENABLED */
#ifdef LIBXML_PATTERN_ENABLED
- printf("\t--pattern pattern_value : test the pattern support\n");
+ fprintf(f, "\t--pattern pattern_value : test the pattern support\n");
#endif
- printf("\t--chkregister : verify the node registration code\n");
+ fprintf(f, "\t--chkregister : verify the node registration code\n");
#ifdef LIBXML_SCHEMAS_ENABLED
- printf("\t--relaxng schema : do RelaxNG validation against the schema\n");
- printf("\t--schema schema : do validation against the WXS schema\n");
+ fprintf(f, "\t--relaxng schema : do RelaxNG validation against the schema\n");
+ fprintf(f, "\t--schema schema : do validation against the WXS schema\n");
#endif
#ifdef LIBXML_SCHEMATRON_ENABLED
- printf("\t--schematron schema : do validation against a schematron\n");
+ fprintf(f, "\t--schematron schema : do validation against a schematron\n");
#endif
#ifdef LIBXML_SAX1_ENABLED
- printf("\t--sax1: use the old SAX1 interfaces for processing\n");
+ fprintf(f, "\t--sax1: use the old SAX1 interfaces for processing\n");
#endif
- printf("\t--sax: do not build a tree but work just at the SAX level\n");
- printf("\t--oldxml10: use XML-1.0 parsing rules before the 5th edition\n");
+ fprintf(f, "\t--sax: do not build a tree but work just at the SAX level\n");
+ fprintf(f, "\t--oldxml10: use XML-1.0 parsing rules before the 5th edition\n");
#ifdef LIBXML_XPATH_ENABLED
- printf("\t--xpath expr: evaluate the XPath expression, imply --noout\n");
+ fprintf(f, "\t--xpath expr: evaluate the XPath expression, imply --noout\n");
#endif
- printf("\nLibxml project home page: http://xmlsoft.org/\n");
- printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
+ fprintf(f, "\nLibxml project home page: http://xmlsoft.org/\n");
+ fprintf(f, "To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
}
static void registerNode(xmlNodePtr node)
@@ -3138,7 +3120,7 @@ main(int argc, char **argv) {
const char* indent;
if (argc <= 1) {
- usage(argv[0]);
+ usage(stderr, argv[0]);
return(1);
}
LIBXML_TEST_VERSION
@@ -3313,7 +3295,7 @@ main(int argc, char **argv) {
}
#endif
#ifdef LIBXML_OUTPUT_ENABLED
-#ifdef HAVE_ZLIB_H
+#ifdef LIBXML_ZLIB_ENABLED
else if ((!strcmp(argv[i], "-compress")) ||
(!strcmp(argv[i], "--compress"))) {
compress++;
@@ -3490,7 +3472,7 @@ main(int argc, char **argv) {
options |= XML_PARSE_OLD10;
} else {
fprintf(stderr, "Unknown option %s\n", argv[i]);
- usage(argv[0]);
+ usage(stderr, argv[0]);
return(1);
}
}
@@ -3784,7 +3766,7 @@ main(int argc, char **argv) {
xmlGenericError(xmlGenericErrorContext, "</body></html>\n");
}
if ((files == 0) && (!generate) && (version == 0)) {
- usage(argv[0]);
+ usage(stderr, argv[0]);
}
#ifdef LIBXML_SCHEMATRON_ENABLED
if (wxschematron != NULL)