diff options
author | Mike Hommey <glandium@debian.org> | 2005-03-27 13:13:58 +0000 |
---|---|---|
committer | Mike Hommey <glandium@debian.org> | 2005-03-27 13:13:58 +0000 |
commit | 50e5b428562964b1eb2f876370058b34b47c5e90 (patch) | |
tree | c66bcae6dbbce07128ee881353ff60090524462c /xmllint.c | |
parent | a7457388701e6ccba9091ba3ec09505dc903b758 (diff) | |
download | libxml2-50e5b428562964b1eb2f876370058b34b47c5e90.tar.gz |
Load /tmp/tmp.XJZ6qc/libxml2-2.6.18 intoupstream/2.6.18
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'xmllint.c')
-rw-r--r-- | xmllint.c | 167 |
1 files changed, 146 insertions, 21 deletions
@@ -186,6 +186,7 @@ static int sax1 = 0; #ifdef LIBXML_PATTERN_ENABLED static const char *pattern = NULL; static xmlPatternPtr patternc = NULL; +static xmlStreamCtxtPtr patstream = NULL; #endif static int options = 0; @@ -805,29 +806,82 @@ static void myClose(FILE *f) { ************************************************************************/ static void processNode(xmlTextReaderPtr reader) { const xmlChar *name, *value; - - name = xmlTextReaderConstName(reader); - if (name == NULL) - name = BAD_CAST "--"; - - value = xmlTextReaderConstValue(reader); - - printf("%d %d %s %d %d", - xmlTextReaderDepth(reader), - xmlTextReaderNodeType(reader), - name, - xmlTextReaderIsEmptyElement(reader), - xmlTextReaderHasValue(reader)); - if (value == NULL) - printf("\n"); - else { - printf(" %s\n", value); + int type, empty; + + type = xmlTextReaderNodeType(reader); + empty = xmlTextReaderIsEmptyElement(reader); + + if (debug) { + name = xmlTextReaderConstName(reader); + if (name == NULL) + name = BAD_CAST "--"; + + value = xmlTextReaderConstValue(reader); + + + printf("%d %d %s %d %d", + xmlTextReaderDepth(reader), + type, + name, + empty, + xmlTextReaderHasValue(reader)); + if (value == NULL) + printf("\n"); + else { + printf(" %s\n", value); + } } #ifdef LIBXML_PATTERN_ENABLED if (patternc) { - if (xmlPatternMatch(patternc, xmlTextReaderCurrentNode(reader)) == 1) { - printf("Node matches pattern %s\n", pattern); + xmlChar *path = NULL; + int match = -1; + + if (type == XML_READER_TYPE_ELEMENT) { + /* do the check only on element start */ + match = xmlPatternMatch(patternc, xmlTextReaderCurrentNode(reader)); + + if (match) { + path = xmlGetNodePath(xmlTextReaderCurrentNode(reader)); + printf("Node %s matches pattern %s\n", path, pattern); + } + } + if (patstream != NULL) { + int ret; + + if (type == XML_READER_TYPE_ELEMENT) { + ret = xmlStreamPush(patstream, + xmlTextReaderConstLocalName(reader), + xmlTextReaderConstNamespaceUri(reader)); + if (ret < 0) { + fprintf(stderr, "xmlStreamPush() failure\n"); + xmlFreeStreamCtxt(patstream); + patstream = NULL; + } else if (ret != match) { + if (path == NULL) { + path = xmlGetNodePath( + xmlTextReaderCurrentNode(reader)); + } + fprintf(stderr, + "xmlPatternMatch and xmlStreamPush disagree\n"); + fprintf(stderr, + " pattern %s node %s\n", + pattern, path); + } + + + } + if ((type == XML_READER_TYPE_END_ELEMENT) || + ((type == XML_READER_TYPE_ELEMENT) && (empty))) { + ret = xmlStreamPop(patstream); + if (ret < 0) { + fprintf(stderr, "xmlStreamPop() failure\n"); + xmlFreeStreamCtxt(patstream); + patstream = NULL; + } + } } + if (path != NULL) + xmlFree(path); } #endif } @@ -855,6 +909,28 @@ static void streamFile(char *filename) { } else #endif reader = xmlReaderForFile(filename, NULL, options); +#ifdef LIBXML_PATTERN_ENABLED + if (pattern != NULL) { + patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL); + if (patternc == NULL) { + xmlGenericError(xmlGenericErrorContext, + "Pattern %s failed to compile\n", pattern); + progresult = XMLLINT_ERR_SCHEMAPAT; + pattern = NULL; + } + } + if (patternc != NULL) { + patstream = xmlPatternGetStreamCtxt(patternc); + if (patstream != NULL) { + ret = xmlStreamPush(patstream, NULL, NULL); + if (ret < 0) { + fprintf(stderr, "xmlStreamPush() failure\n"); + xmlFreeStreamCtxt(patstream); + patstream = NULL; + } + } + } +#endif if (reader != NULL) { @@ -943,6 +1019,12 @@ static void streamFile(char *filename) { fprintf(stderr, "Unable to open %s\n", filename); progresult = XMLLINT_ERR_UNCLASS; } +#ifdef LIBXML_PATTERN_ENABLED + if (patstream != NULL) { + xmlFreeStreamCtxt(patstream); + patstream = NULL; + } +#endif #ifdef HAVE_SYS_MMAN_H if (memory) { xmlFreeParserInputBuffer(input); @@ -956,6 +1038,42 @@ static void walkDoc(xmlDocPtr doc) { xmlTextReaderPtr reader; int ret; +#ifdef LIBXML_PATTERN_ENABLED + xmlNodePtr root; + const xmlChar *namespaces[22]; + int i; + xmlNsPtr ns; + + root = xmlDocGetRootElement(doc); + for (ns = root->nsDef, i = 0;ns != NULL && i < 20;ns=ns->next) { + namespaces[i++] = ns->href; + namespaces[i++] = ns->prefix; + } + namespaces[i++] = NULL; + namespaces[i++] = NULL; + + if (pattern != NULL) { + patternc = xmlPatterncompile((const xmlChar *) pattern, doc->dict, + 0, &namespaces[0]); + if (patternc == NULL) { + xmlGenericError(xmlGenericErrorContext, + "Pattern %s failed to compile\n", pattern); + progresult = XMLLINT_ERR_SCHEMAPAT; + pattern = NULL; + } + } + if (patternc != NULL) { + patstream = xmlPatternGetStreamCtxt(patternc); + if (patstream != NULL) { + ret = xmlStreamPush(patstream, NULL, NULL); + if (ret < 0) { + fprintf(stderr, "xmlStreamPush() failure\n"); + xmlFreeStreamCtxt(patstream); + patstream = NULL; + } + } + } +#endif /* LIBXML_PATTERN_ENABLED */ reader = xmlReaderWalker(doc); if (reader != NULL) { if ((timing) && (!repeat)) { @@ -983,6 +1101,12 @@ static void walkDoc(xmlDocPtr doc) { fprintf(stderr, "Failed to crate a reader from the document\n"); progresult = XMLLINT_ERR_UNCLASS; } +#ifdef LIBXML_PATTERN_ENABLED + if (patstream != NULL) { + xmlFreeStreamCtxt(patstream); + patstream = NULL; + } +#endif } #endif /* LIBXML_READER_ENABLED */ @@ -1217,7 +1341,8 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { if ((timing) && (!repeat)) { startTimer(); } - xmlXIncludeProcessFlags(doc, options); + if (xmlXIncludeProcessFlags(doc, options) < 0) + progresult = XMLLINT_ERR_UNCLASS; if ((timing) && (!repeat)) { endTimer("Xinclude processing"); } @@ -2189,7 +2314,7 @@ main(int argc, char **argv) { } #endif /* LIBXML_SCHEMAS_ENABLED */ #ifdef LIBXML_PATTERN_ENABLED - if (pattern != NULL) { + if ((pattern != NULL) && (walker == 0)) { patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL); if (patternc == NULL) { xmlGenericError(xmlGenericErrorContext, |