diff options
Diffstat (limited to 'xmllint.c')
-rw-r--r-- | xmllint.c | 218 |
1 files changed, 152 insertions, 66 deletions
@@ -85,6 +85,9 @@ #endif #include <libxml/globals.h> #include <libxml/xmlreader.h> +#ifdef LIBXML_SCHEMATRON_ENABLED +#include <libxml/schematron.h> +#endif #ifdef LIBXML_SCHEMAS_ENABLED #include <libxml/relaxng.h> #include <libxml/xmlschemas.h> @@ -143,6 +146,10 @@ static xmlRelaxNGPtr relaxngschemas = NULL; static char * schema = NULL; static xmlSchemaPtr wxschemas = NULL; #endif +#ifdef LIBXML_SCHEMAS_ENABLED +static char * schematron = NULL; +static xmlSchematronPtr wxschematron = NULL; +#endif static int repeat = 0; static int insert = 0; #if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED) @@ -189,7 +196,7 @@ static const char *pattern = NULL; static xmlPatternPtr patternc = NULL; static xmlStreamCtxtPtr patstream = NULL; #endif -static int options = 0; +static int options = XML_PARSE_COMPACT; static int sax = 0; /************************************************************************ @@ -228,7 +235,7 @@ void parsePath(const xmlChar *path) { } } -xmlExternalEntityLoader defaultEntityLoader = NULL; +static xmlExternalEntityLoader defaultEntityLoader = NULL; static xmlParserInputPtr xmllintExternalEntityLoader(const char *URL, const char *ID, @@ -413,7 +420,7 @@ startTimer(void) * message about the timing performed; format is a printf * type argument */ -static void +static void XMLCDECL endTimer(const char *fmt, ...) { long msec; @@ -449,7 +456,7 @@ startTimer(void) { begin = clock(); } -static void +static void XMLCDECL endTimer(const char *fmt, ...) { long msec; @@ -478,7 +485,7 @@ startTimer(void) * Do nothing */ } -static void +static void XMLCDECL endTimer(char *format, ...) { /* @@ -501,7 +508,7 @@ endTimer(char *format, ...) * HTML ouput * * * ************************************************************************/ -char buffer[50000]; +static char buffer[50000]; static void xmlHTMLEncodeSend(void) { @@ -597,7 +604,7 @@ xmlHTMLPrintFileContext(xmlParserInputPtr input) { * Display and format an error messages, gives file, line, position and * extra parameters. */ -static void +static void XMLCDECL xmlHTMLError(void *ctx, const char *msg, ...) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; @@ -634,7 +641,7 @@ xmlHTMLError(void *ctx, const char *msg, ...) * Display and format a warning messages, gives file, line, position and * extra parameters. */ -static void +static void XMLCDECL xmlHTMLWarning(void *ctx, const char *msg, ...) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; @@ -672,7 +679,7 @@ xmlHTMLWarning(void *ctx, const char *msg, ...) * Display and format an validity error messages, gives file, * line, position and extra parameters. */ -static void +static void XMLCDECL xmlHTMLValidityError(void *ctx, const char *msg, ...) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; @@ -709,7 +716,7 @@ xmlHTMLValidityError(void *ctx, const char *msg, ...) * Display and format a validity warning messages, gives file, line, * position and extra parameters. */ -static void +static void XMLCDECL xmlHTMLValidityWarning(void *ctx, const char *msg, ...) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; @@ -810,7 +817,7 @@ static void myClose(FILE *f) { /* * empty SAX block */ -xmlSAXHandler emptySAXHandlerStruct = { +static xmlSAXHandler emptySAXHandlerStruct = { NULL, /* internalSubset */ NULL, /* isStandalone */ NULL, /* hasInternalSubset */ @@ -845,7 +852,7 @@ xmlSAXHandler emptySAXHandlerStruct = { NULL /* xmlStructuredErrorFunc */ }; -xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct; +static xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct; extern xmlSAXHandlerPtr debugSAXHandler; static int callbacks; @@ -1373,7 +1380,7 @@ commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value) * Display and format a warning messages, gives file, line, position and * extra parameters. */ -static void +static void XMLCDECL warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { va_list args; @@ -1396,7 +1403,7 @@ warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) * Display and format a error messages, gives file, line, position and * extra parameters. */ -static void +static void XMLCDECL errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { va_list args; @@ -1419,7 +1426,7 @@ errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) * Display and format a fatalError messages, gives file, line, position and * extra parameters. */ -static void +static void XMLCDECL fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { va_list args; @@ -1433,7 +1440,7 @@ fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) va_end(args); } -xmlSAXHandler debugSAXHandlerStruct = { +static xmlSAXHandler debugSAXHandlerStruct = { internalSubsetDebug, isStandaloneDebug, hasInternalSubsetDebug, @@ -1557,7 +1564,7 @@ endElementNsDebug(void *ctx ATTRIBUTE_UNUSED, fprintf(stdout, ", '%s')\n", (char *) URI); } -xmlSAXHandler debugSAX2HandlerStruct = { +static xmlSAXHandler debugSAX2HandlerStruct = { internalSubsetDebug, isStandaloneDebug, hasInternalSubsetDebug, @@ -1592,7 +1599,7 @@ xmlSAXHandler debugSAX2HandlerStruct = { NULL }; -xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct; +static xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct; static void testSAX(const char *filename) { @@ -2580,6 +2587,46 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { xmlFreeValidCtxt(cvp); } #endif /* LIBXML_VALID_ENABLED */ +#ifdef LIBXML_SCHEMATRON_ENABLED + if (wxschematron != NULL) { + xmlSchematronValidCtxtPtr ctxt; + int ret; + int flag; + + if ((timing) && (!repeat)) { + startTimer(); + } + + if (debug) + flag = XML_SCHEMATRON_OUT_XML; + else + flag = XML_SCHEMATRON_OUT_TEXT; + if (noout) + flag |= XML_SCHEMATRON_OUT_QUIET; + ctxt = xmlSchematronNewValidCtxt(wxschematron, flag); +#if 0 + xmlSchematronSetValidErrors(ctxt, + (xmlSchematronValidityErrorFunc) fprintf, + (xmlSchematronValidityWarningFunc) fprintf, + stderr); +#endif + ret = xmlSchematronValidateDoc(ctxt, doc); + if (ret == 0) { + fprintf(stderr, "%s validates\n", filename); + } else if (ret > 0) { + fprintf(stderr, "%s fails to validate\n", filename); + progresult = XMLLINT_ERR_VALID; + } else { + fprintf(stderr, "%s validation generated an internal error\n", + filename); + progresult = XMLLINT_ERR_VALID; + } + xmlSchematronFreeValidCtxt(ctxt); + if ((timing) && (!repeat)) { + endTimer("Validating"); + } + } +#endif #ifdef LIBXML_SCHEMAS_ENABLED if (relaxngschemas != NULL) { xmlRelaxNGValidCtxtPtr ctxt; @@ -2666,54 +2713,36 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { static void showVersion(const char *name) { fprintf(stderr, "%s: using libxml version %s\n", name, xmlParserVersion); fprintf(stderr, " compiled with: "); -#ifdef LIBXML_VALID_ENABLED - fprintf(stderr, "DTDValid "); -#endif -#ifdef LIBXML_FTP_ENABLED - fprintf(stderr, "FTP "); -#endif -#ifdef LIBXML_HTTP_ENABLED - fprintf(stderr, "HTTP "); -#endif -#ifdef LIBXML_HTML_ENABLED - fprintf(stderr, "HTML "); -#endif -#ifdef LIBXML_C14N_ENABLED - fprintf(stderr, "C14N "); -#endif -#ifdef LIBXML_CATALOG_ENABLED - fprintf(stderr, "Catalog "); -#endif -#ifdef LIBXML_XPATH_ENABLED - fprintf(stderr, "XPath "); -#endif -#ifdef LIBXML_XPTR_ENABLED - fprintf(stderr, "XPointer "); -#endif -#ifdef LIBXML_XINCLUDE_ENABLED - fprintf(stderr, "XInclude "); -#endif -#ifdef LIBXML_ICONV_ENABLED - fprintf(stderr, "Iconv "); -#endif -#ifdef DEBUG_MEMORY_LOCATION - fprintf(stderr, "MemDebug "); -#endif -#ifdef LIBXML_UNICODE_ENABLED - fprintf(stderr, "Unicode "); -#endif -#ifdef LIBXML_REGEXP_ENABLED - fprintf(stderr, "Regexps "); -#endif -#ifdef LIBXML_AUTOMATA_ENABLED - fprintf(stderr, "Automata "); -#endif -#ifdef LIBXML_SCHEMAS_ENABLED - fprintf(stderr, "Schemas "); -#endif -#ifdef LIBXML_MODULES_ENABLED - fprintf(stderr, "Modules "); -#endif + if (xmlHasFeature(XML_FEATURE_THREAD)) fprintf(stderr, "Threads "); + if (xmlHasFeature(XML_FEATURE_TREE)) fprintf(stderr, "Tree "); + if (xmlHasFeature(XML_FEATURE_OUTPUT)) fprintf(stderr, "Output "); + if (xmlHasFeature(XML_FEATURE_PUSH)) fprintf(stderr, "Push "); + if (xmlHasFeature(XML_FEATURE_READER)) fprintf(stderr, "Reader "); + if (xmlHasFeature(XML_FEATURE_PATTERN)) fprintf(stderr, "Patterns "); + if (xmlHasFeature(XML_FEATURE_WRITER)) fprintf(stderr, "Writer "); + if (xmlHasFeature(XML_FEATURE_SAX1)) fprintf(stderr, "SAXv1 "); + if (xmlHasFeature(XML_FEATURE_FTP)) fprintf(stderr, "FTP "); + if (xmlHasFeature(XML_FEATURE_HTTP)) fprintf(stderr, "HTTP "); + if (xmlHasFeature(XML_FEATURE_VALID)) fprintf(stderr, "DTDValid "); + if (xmlHasFeature(XML_FEATURE_HTML)) fprintf(stderr, "HTML "); + if (xmlHasFeature(XML_FEATURE_LEGACY)) fprintf(stderr, "Legacy "); + if (xmlHasFeature(XML_FEATURE_C14N)) fprintf(stderr, "C14N "); + if (xmlHasFeature(XML_FEATURE_CATALOG)) fprintf(stderr, "Catalog "); + if (xmlHasFeature(XML_FEATURE_XPATH)) fprintf(stderr, "XPath "); + if (xmlHasFeature(XML_FEATURE_XPTR)) fprintf(stderr, "XPointer "); + if (xmlHasFeature(XML_FEATURE_XINCLUDE)) fprintf(stderr, "XInclude "); + if (xmlHasFeature(XML_FEATURE_ICONV)) fprintf(stderr, "Iconv "); + if (xmlHasFeature(XML_FEATURE_ISO8859X)) fprintf(stderr, "ISO8859X "); + if (xmlHasFeature(XML_FEATURE_UNICODE)) fprintf(stderr, "Unicode "); + if (xmlHasFeature(XML_FEATURE_REGEXP)) fprintf(stderr, "Regexps "); + if (xmlHasFeature(XML_FEATURE_AUTOMATA)) fprintf(stderr, "Automata "); + if (xmlHasFeature(XML_FEATURE_EXPR)) fprintf(stderr, "Expr "); + if (xmlHasFeature(XML_FEATURE_SCHEMAS)) fprintf(stderr, "Schemas "); + if (xmlHasFeature(XML_FEATURE_SCHEMATRON)) fprintf(stderr, "Schematron "); + if (xmlHasFeature(XML_FEATURE_MODULES)) fprintf(stderr, "Modules "); + if (xmlHasFeature(XML_FEATURE_DEBUG)) fprintf(stderr, "Debug "); + if (xmlHasFeature(XML_FEATURE_DEBUG_MEM)) fprintf(stderr, "MemDebug "); + if (xmlHasFeature(XML_FEATURE_DEBUG_RUN)) fprintf(stderr, "RunDebug "); fprintf(stderr, "\n"); } @@ -2743,6 +2772,7 @@ static void usage(const char *name) { printf("\t--path 'paths': provide a set of paths for resources\n"); printf("\t--load-trace : print trace of all external entites 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"); #ifdef LIBXML_VALID_ENABLED @@ -2810,6 +2840,9 @@ static void usage(const char *name) { printf("\t--relaxng schema : do RelaxNG validation against the schema\n"); printf("\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"); +#endif #ifdef LIBXML_SAX1_ENABLED printf("\t--sax1: use the old SAX1 interfaces for processing\n"); #endif @@ -3112,9 +3145,19 @@ main(int argc, char **argv) { schema = argv[i]; noent++; #endif +#ifdef LIBXML_SCHEMATRON_ENABLED + } else if ((!strcmp(argv[i], "-schematron")) || + (!strcmp(argv[i], "--schematron"))) { + i++; + schematron = argv[i]; + noent++; +#endif } else if ((!strcmp(argv[i], "-nonet")) || (!strcmp(argv[i], "--nonet"))) { options |= XML_PARSE_NONET; + } else if ((!strcmp(argv[i], "-nocompact")) || + (!strcmp(argv[i], "--nocompact"))) { + options &= ~XML_PARSE_COMPACT; } else if ((!strcmp(argv[i], "-load-trace")) || (!strcmp(argv[i], "--load-trace"))) { load_trace++; @@ -3193,6 +3236,40 @@ main(int argc, char **argv) { argv[0]); } +#ifdef LIBXML_SCHEMATRON_ENABLED + if ((schematron != NULL) && (sax == 0) +#ifdef LIBXML_READER_ENABLED + && (stream == 0) +#endif /* LIBXML_READER_ENABLED */ + ) { + xmlSchematronParserCtxtPtr ctxt; + + /* forces loading the DTDs */ + xmlLoadExtDtdDefaultValue |= 1; + options |= XML_PARSE_DTDLOAD; + if (timing) { + startTimer(); + } + ctxt = xmlSchematronNewParserCtxt(schematron); +#if 0 + xmlSchematronSetParserErrors(ctxt, + (xmlSchematronValidityErrorFunc) fprintf, + (xmlSchematronValidityWarningFunc) fprintf, + stderr); +#endif + wxschematron = xmlSchematronParse(ctxt); + if (wxschematron == NULL) { + xmlGenericError(xmlGenericErrorContext, + "Schematron schema %s failed to compile\n", schematron); + progresult = XMLLINT_ERR_SCHEMACOMP; + schematron = NULL; + } + xmlSchematronFreeParserCtxt(ctxt); + if (timing) { + endTimer("Compiling the schemas"); + } + } +#endif #ifdef LIBXML_SCHEMAS_ENABLED if ((relaxng != NULL) && (sax == 0) #ifdef LIBXML_READER_ENABLED @@ -3309,6 +3386,11 @@ main(int argc, char **argv) { i++; continue; } + if ((!strcmp(argv[i], "-schematron")) || + (!strcmp(argv[i], "--schematron"))) { + i++; + continue; + } #ifdef LIBXML_PATTERN_ENABLED if ((!strcmp(argv[i], "-pattern")) || (!strcmp(argv[i], "--pattern"))) { @@ -3375,6 +3457,10 @@ main(int argc, char **argv) { if ((files == 0) && (!generate) && (version == 0)) { usage(argv[0]); } +#ifdef LIBXML_SCHEMATRON_ENABLED + if (wxschematron != NULL) + xmlSchematronFree(wxschematron); +#endif #ifdef LIBXML_SCHEMAS_ENABLED if (relaxngschemas != NULL) xmlRelaxNGFree(relaxngschemas); |