From f1edb10c805f5409aed0b85f39da76af0c144041 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 10 Aug 2009 14:43:18 +0200 Subject: xmllint use xmlGetNodePath when not compiled in * xmllint.c: clean up usages of xmlGetNodePath() to make sure it was compiled in. Also clear some space issues, solves #545581 --- xmllint.c | 225 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 117 insertions(+), 108 deletions(-) (limited to 'xmllint.c') diff --git a/xmllint.c b/xmllint.c index c324ef30..d1116afc 100644 --- a/xmllint.c +++ b/xmllint.c @@ -248,7 +248,7 @@ void parsePath(const xmlChar *path) { static xmlExternalEntityLoader defaultEntityLoader = NULL; -static xmlParserInputPtr +static xmlParserInputPtr xmllintExternalEntityLoader(const char *URL, const char *ID, xmlParserCtxtPtr ctxt) { xmlParserInputPtr ret; @@ -306,10 +306,10 @@ xmllintExternalEntityLoader(const char *URL, const char *ID, ctxt->sax->error = err; if (load_trace) { fprintf \ - (stderr, - "Loaded URL=\"%s\" ID=\"%s\"\n", + (stderr, + "Loaded URL=\"%s\" ID=\"%s\"\n", newURL, - ID ? ID : "(null)"); + ID ? ID : "(null)"); } xmlFree(newURL); return(ret); @@ -329,9 +329,9 @@ xmllintExternalEntityLoader(const char *URL, const char *ID, return(NULL); } /************************************************************************ - * * + * * * Memory allocation consumption debugging * - * * + * * ************************************************************************/ static void @@ -392,13 +392,13 @@ myStrdupFunc(const char *str) return (ret); } /************************************************************************ - * * + * * * Internal timing routines to remove the necessity to have * * unix-specific function calls. * - * * + * * ************************************************************************/ -#ifndef HAVE_GETTIMEOFDAY +#ifndef HAVE_GETTIMEOFDAY #ifdef HAVE_SYS_TIMEB_H #ifdef HAVE_SYS_TIME_H #ifdef HAVE_FTIME @@ -524,9 +524,9 @@ endTimer(char *format, ...) } #endif /************************************************************************ - * * - * HTML ouput * - * * + * * + * HTML ouput * + * * ************************************************************************/ static char buffer[50000]; @@ -545,7 +545,7 @@ xmlHTMLEncodeSend(void) { /** * xmlHTMLPrintFileInfo: * @input: an xmlParserInputPtr input - * + * * Displays the associated file and line informations for the current input */ @@ -569,7 +569,7 @@ xmlHTMLPrintFileInfo(xmlParserInputPtr input) { /** * xmlHTMLPrintFileContext: * @input: an xmlParserInputPtr input - * + * * Displays current context within the input content for error tracking */ @@ -594,7 +594,7 @@ xmlHTMLPrintFileContext(xmlParserInputPtr input) { n = 0; while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { len = strlen(buffer); - snprintf(&buffer[len], sizeof(buffer) - len, "%c", + snprintf(&buffer[len], sizeof(buffer) - len, "%c", (unsigned char) *cur++); n++; } @@ -620,7 +620,7 @@ xmlHTMLPrintFileContext(xmlParserInputPtr input) { * @ctx: an XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display - * + * * Display and format an error messages, gives file, line, position and * extra parameters. */ @@ -637,7 +637,7 @@ xmlHTMLError(void *ctx, const char *msg, ...) if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { input = ctxt->inputTab[ctxt->inputNr - 2]; } - + xmlHTMLPrintFileInfo(input); xmlGenericError(xmlGenericErrorContext, "error: "); @@ -657,7 +657,7 @@ xmlHTMLError(void *ctx, const char *msg, ...) * @ctx: an XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display - * + * * Display and format a warning messages, gives file, line, position and * extra parameters. */ @@ -674,13 +674,13 @@ xmlHTMLWarning(void *ctx, const char *msg, ...) if ((input != NULL) && (input->filename == NULL) && (ctxt->inputNr > 1)) { input = ctxt->inputTab[ctxt->inputNr - 2]; } - + xmlHTMLPrintFileInfo(input); - + xmlGenericError(xmlGenericErrorContext, "warning: "); va_start(args, msg); - len = strlen(buffer); + len = strlen(buffer); vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); va_end(args); xmlHTMLEncodeSend(); @@ -695,7 +695,7 @@ xmlHTMLWarning(void *ctx, const char *msg, ...) * @ctx: an XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display - * + * * Display and format an validity error messages, gives file, * line, position and extra parameters. */ @@ -711,7 +711,7 @@ xmlHTMLValidityError(void *ctx, const char *msg, ...) input = ctxt->input; if ((input->filename == NULL) && (ctxt->inputNr > 1)) input = ctxt->inputTab[ctxt->inputNr - 2]; - + xmlHTMLPrintFileInfo(input); xmlGenericError(xmlGenericErrorContext, "validity error: "); @@ -732,7 +732,7 @@ xmlHTMLValidityError(void *ctx, const char *msg, ...) * @ctx: an XML parser context * @msg: the message to display/transmit * @...: extra parameters for the message display - * + * * Display and format a validity warning messages, gives file, line, * position and extra parameters. */ @@ -750,10 +750,10 @@ xmlHTMLValidityWarning(void *ctx, const char *msg, ...) input = ctxt->inputTab[ctxt->inputNr - 2]; xmlHTMLPrintFileInfo(input); - + xmlGenericError(xmlGenericErrorContext, "validity warning: "); va_start(args, msg); - len = strlen(buffer); + len = strlen(buffer); vsnprintf(&buffer[len], sizeof(buffer) - len, msg, args); va_end(args); xmlHTMLEncodeSend(); @@ -764,9 +764,9 @@ xmlHTMLValidityWarning(void *ctx, const char *msg, ...) } /************************************************************************ - * * - * Shell Interface * - * * + * * + * Shell Interface * + * * ************************************************************************/ #ifdef LIBXML_DEBUG_ENABLED #ifdef LIBXML_XPATH_ENABLED @@ -775,7 +775,7 @@ xmlHTMLValidityWarning(void *ctx, const char *msg, ...) * @prompt: the prompt value * * Read a string - * + * * Returns a pointer to it or NULL on EOF the caller is expected to * free the returned string. */ @@ -814,9 +814,9 @@ xmlShellReadline(char *prompt) { #endif /* LIBXML_DEBUG_ENABLED */ /************************************************************************ - * * - * I/O Interfaces * - * * + * * + * I/O Interfaces * + * * ************************************************************************/ static int myRead(FILE *f, char * buf, int len) { @@ -830,7 +830,7 @@ static void myClose(FILE *f) { /************************************************************************ * * - * SAX based tests * + * SAX based tests * * * ************************************************************************/ @@ -1000,7 +1000,7 @@ resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xm return(NULL); /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ - + fprintf(stdout, "SAX.resolveEntity("); if (publicId != NULL) fprintf(stdout, "%s", (char *)publicId); @@ -1055,8 +1055,8 @@ getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) /** * entityDeclDebug: * @ctxt: An XML parser context - * @name: the entity name - * @type: the entity type + * @name: the entity name + * @type: the entity type * @publicId: The public ID of the entity * @systemId: The system ID of the entity * @content: the entity value (without processing). @@ -1085,8 +1085,8 @@ const xmlChar *nullstr = BAD_CAST "(null)"; /** * attributeDeclDebug: * @ctxt: An XML parser context - * @name: the attribute name - * @type: the attribute type + * @name: the attribute name + * @type: the attribute type * * An attribute definition has been parsed */ @@ -1110,8 +1110,8 @@ attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar * elem, /** * elementDeclDebug: * @ctxt: An XML parser context - * @name: the element name - * @type: the element type + * @name: the element name + * @type: the element type * @content: the element value (without processing). * * An element definition has been parsed @@ -1297,7 +1297,7 @@ charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len) * @ctxt: An XML parser context * @name: The entity name * - * called when an entity reference is detected. + * called when an entity reference is detected. */ static void referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) @@ -1533,7 +1533,7 @@ startElementNsDebug(void *ctx ATTRIBUTE_UNUSED, else fprintf(stdout, ", '%s'", (char *) URI); fprintf(stdout, ", %d", nb_namespaces); - + if (namespaces != NULL) { for (i = 0;i < nb_namespaces * 2;i++) { fprintf(stdout, ", xmlns"); @@ -1696,7 +1696,7 @@ testSAX(const char *filename) { goto error; } inputPush(ctxt, inputStream); - + /* do the parsing */ xmlParseDocument(ctxt); @@ -1715,9 +1715,9 @@ error: } /************************************************************************ - * * - * Stream Test processing * - * * + * * + * Stream Test processing * + * * ************************************************************************/ #ifdef LIBXML_READER_ENABLED static void processNode(xmlTextReaderPtr reader) { @@ -1734,8 +1734,8 @@ static void processNode(xmlTextReaderPtr reader) { value = xmlTextReaderConstValue(reader); - - printf("%d %d %s %d %d", + + printf("%d %d %s %d %d", xmlTextReaderDepth(reader), type, name, @@ -1751,14 +1751,19 @@ static void processNode(xmlTextReaderPtr reader) { if (patternc) { 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) { +#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_DEBUG_ENABLED) path = xmlGetNodePath(xmlTextReaderCurrentNode(reader)); printf("Node %s matches pattern %s\n", path, pattern); +#else + printf("Node %s matches pattern %s\n", + xmlTextReaderConstName(reader), pattern); +#endif } } if (patstream != NULL) { @@ -1773,19 +1778,23 @@ static void processNode(xmlTextReaderPtr reader) { xmlFreeStreamCtxt(patstream); patstream = NULL; } else if (ret != match) { +#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_DEBUG_ENABLED) if (path == NULL) { path = xmlGetNodePath( xmlTextReaderCurrentNode(reader)); } +#endif fprintf(stderr, "xmlPatternMatch and xmlStreamPush disagree\n"); - fprintf(stderr, - " pattern %s node %s\n", - pattern, path); + if (path != NULL) + fprintf(stderr, " pattern %s node %s\n", + pattern, path); + else + fprintf(stderr, " pattern %s node %s\n", + pattern, xmlTextReaderConstName(reader)); } - - } + } if ((type == XML_READER_TYPE_END_ELEMENT) || ((type == XML_READER_TYPE_ELEMENT) && (empty))) { ret = xmlStreamPop(patstream); @@ -1812,7 +1821,7 @@ static void streamFile(char *filename) { xmlParserInputBufferPtr input = NULL; if (memory) { - if (stat(filename, &info) < 0) + if (stat(filename, &info) < 0) return; if ((fd = open(filename, O_RDONLY)) < 0) return; @@ -2042,9 +2051,9 @@ static void walkDoc(xmlDocPtr doc) { #endif /* LIBXML_READER_ENABLED */ /************************************************************************ - * * - * Tree Test processing * - * * + * * + * Tree Test processing * + * * ************************************************************************/ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { xmlDocPtr doc = NULL; @@ -2054,7 +2063,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { if ((timing) && (!repeat)) startTimer(); - + #ifdef LIBXML_TREE_ENABLED if (filename == NULL) { @@ -2105,7 +2114,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { int fd; struct stat info; const char *base; - if (stat(filename, &info) < 0) + if (stat(filename, &info) < 0) return; if ((fd = open(filename, O_RDONLY)) < 0) return; @@ -2115,7 +2124,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { doc = htmlReadMemory((char *) base, info.st_size, filename, NULL, options); - + munmap((char *) base, info.st_size); close(fd); } @@ -2200,7 +2209,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { ctxt = xmlNewParserCtxt(); else ctxt = rectxt; - if (ctxt == NULL) { + if (ctxt == NULL) { doc = NULL; } else { ctxt->sax->error = xmlHTMLError; @@ -2218,7 +2227,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { int fd; struct stat info; const char *base; - if (stat(filename, &info) < 0) + if (stat(filename, &info) < 0) return; if ((fd = open(filename, O_RDONLY)) < 0) return; @@ -2232,7 +2241,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { else doc = xmlCtxtReadMemory(rectxt, (char *) base, info.st_size, filename, NULL, options); - + munmap((char *) base, info.st_size); close(fd); #endif @@ -2244,7 +2253,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { ctxt = xmlNewParserCtxt(); else ctxt = rectxt; - if (ctxt == NULL) { + if (ctxt == NULL) { doc = NULL; } else { doc = xmlCtxtReadFile(ctxt, filename, NULL, options); @@ -2365,7 +2374,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { } } } - } + } }else #endif /* LIBXML_VALID_ENABLED */ #ifdef LIBXML_READER_ENABLED @@ -2473,7 +2482,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { if (encoding != NULL) { if ( format ) { xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1); - } else { + } else { xmlDocDumpMemoryEnc(doc, &result, &len, encoding); } } else { @@ -2593,9 +2602,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { startTimer(); } if (dtdvalid != NULL) - dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid); + dtd = xmlParseDTD(NULL, (const xmlChar *)dtdvalid); else - dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL); + dtd = xmlParseDTD((const xmlChar *)dtdvalidfpi, NULL); if ((timing) && (!repeat)) { endTimer("Parsing DTD"); } @@ -2785,9 +2794,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { } /************************************************************************ - * * - * Usage and Main * - * * + * * + * Usage and Main * + * * ************************************************************************/ static void showVersion(const char *name) { @@ -2801,28 +2810,28 @@ static void showVersion(const char *name) { if (xmlHasFeature(XML_WITH_PATTERN)) fprintf(stderr, "Patterns "); if (xmlHasFeature(XML_WITH_WRITER)) fprintf(stderr, "Writer "); if (xmlHasFeature(XML_WITH_SAX1)) fprintf(stderr, "SAXv1 "); - if (xmlHasFeature(XML_WITH_FTP)) fprintf(stderr, "FTP "); - if (xmlHasFeature(XML_WITH_HTTP)) fprintf(stderr, "HTTP "); + if (xmlHasFeature(XML_WITH_FTP)) fprintf(stderr, "FTP "); + if (xmlHasFeature(XML_WITH_HTTP)) fprintf(stderr, "HTTP "); if (xmlHasFeature(XML_WITH_VALID)) fprintf(stderr, "DTDValid "); - if (xmlHasFeature(XML_WITH_HTML)) fprintf(stderr, "HTML "); - if (xmlHasFeature(XML_WITH_LEGACY)) fprintf(stderr, "Legacy "); - if (xmlHasFeature(XML_WITH_C14N)) fprintf(stderr, "C14N "); - if (xmlHasFeature(XML_WITH_CATALOG)) fprintf(stderr, "Catalog "); - if (xmlHasFeature(XML_WITH_XPATH)) fprintf(stderr, "XPath "); - if (xmlHasFeature(XML_WITH_XPTR)) fprintf(stderr, "XPointer "); - if (xmlHasFeature(XML_WITH_XINCLUDE)) fprintf(stderr, "XInclude "); - if (xmlHasFeature(XML_WITH_ICONV)) fprintf(stderr, "Iconv "); - if (xmlHasFeature(XML_WITH_ISO8859X)) fprintf(stderr, "ISO8859X "); - if (xmlHasFeature(XML_WITH_UNICODE)) fprintf(stderr, "Unicode "); - if (xmlHasFeature(XML_WITH_REGEXP)) fprintf(stderr, "Regexps "); - if (xmlHasFeature(XML_WITH_AUTOMATA)) fprintf(stderr, "Automata "); - if (xmlHasFeature(XML_WITH_EXPR)) fprintf(stderr, "Expr "); - if (xmlHasFeature(XML_WITH_SCHEMAS)) fprintf(stderr, "Schemas "); - if (xmlHasFeature(XML_WITH_SCHEMATRON)) fprintf(stderr, "Schematron "); - if (xmlHasFeature(XML_WITH_MODULES)) fprintf(stderr, "Modules "); - if (xmlHasFeature(XML_WITH_DEBUG)) fprintf(stderr, "Debug "); - if (xmlHasFeature(XML_WITH_DEBUG_MEM)) fprintf(stderr, "MemDebug "); - if (xmlHasFeature(XML_WITH_DEBUG_RUN)) fprintf(stderr, "RunDebug "); + if (xmlHasFeature(XML_WITH_HTML)) fprintf(stderr, "HTML "); + if (xmlHasFeature(XML_WITH_LEGACY)) fprintf(stderr, "Legacy "); + if (xmlHasFeature(XML_WITH_C14N)) fprintf(stderr, "C14N "); + if (xmlHasFeature(XML_WITH_CATALOG)) fprintf(stderr, "Catalog "); + if (xmlHasFeature(XML_WITH_XPATH)) fprintf(stderr, "XPath "); + if (xmlHasFeature(XML_WITH_XPTR)) fprintf(stderr, "XPointer "); + if (xmlHasFeature(XML_WITH_XINCLUDE)) fprintf(stderr, "XInclude "); + if (xmlHasFeature(XML_WITH_ICONV)) fprintf(stderr, "Iconv "); + if (xmlHasFeature(XML_WITH_ISO8859X)) fprintf(stderr, "ISO8859X "); + if (xmlHasFeature(XML_WITH_UNICODE)) fprintf(stderr, "Unicode "); + if (xmlHasFeature(XML_WITH_REGEXP)) fprintf(stderr, "Regexps "); + if (xmlHasFeature(XML_WITH_AUTOMATA)) fprintf(stderr, "Automata "); + if (xmlHasFeature(XML_WITH_EXPR)) fprintf(stderr, "Expr "); + if (xmlHasFeature(XML_WITH_SCHEMAS)) fprintf(stderr, "Schemas "); + if (xmlHasFeature(XML_WITH_SCHEMATRON)) fprintf(stderr, "Schematron "); + if (xmlHasFeature(XML_WITH_MODULES)) fprintf(stderr, "Modules "); + if (xmlHasFeature(XML_WITH_DEBUG)) fprintf(stderr, "Debug "); + if (xmlHasFeature(XML_WITH_DEBUG_MEM)) fprintf(stderr, "MemDebug "); + if (xmlHasFeature(XML_WITH_DEBUG_RUN)) fprintf(stderr, "RunDebug "); if (xmlHasFeature(XML_WITH_ZLIB)) fprintf(stderr, "Zlib "); fprintf(stderr, "\n"); } @@ -2958,7 +2967,7 @@ main(int argc, char **argv) { int files = 0; int version = 0; const char* indent; - + if (argc <= 1) { usage(argv[0]); return(1); @@ -2978,7 +2987,7 @@ main(int argc, char **argv) { (!strcmp(argv[i], "--shell"))) { shell++; noout = 1; - } else + } else #endif #ifdef LIBXML_TREE_ENABLED if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) @@ -3147,24 +3156,24 @@ main(int argc, char **argv) { (!strcmp(argv[i], "--debugent"))) { debugent++; xmlParserDebugEntities = 1; - } + } #endif #ifdef LIBXML_C14N_ENABLED else if ((!strcmp(argv[i], "-c14n")) || (!strcmp(argv[i], "--c14n"))) { canonical++; options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD; - } + } else if ((!strcmp(argv[i], "-c14n11")) || (!strcmp(argv[i], "--c14n11"))) { canonical_11++; options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD; - } + } else if ((!strcmp(argv[i], "-exc-c14n")) || (!strcmp(argv[i], "--exc-c14n"))) { exc_canonical++; options |= XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_DTDLOAD; - } + } #endif #ifdef LIBXML_CATALOG_ENABLED else if ((!strcmp(argv[i], "-catalogs")) || @@ -3173,7 +3182,7 @@ main(int argc, char **argv) { } else if ((!strcmp(argv[i], "-nocatalogs")) || (!strcmp(argv[i], "--nocatalogs"))) { nocatalogs++; - } + } #endif else if ((!strcmp(argv[i], "-encode")) || (!strcmp(argv[i], "--encode"))) { @@ -3309,12 +3318,12 @@ main(int argc, char **argv) { xmlRegisterNodeDefault(registerNode); xmlDeregisterNodeDefault(deregisterNode); } - + indent = getenv("XMLLINT_INDENT"); if(indent != NULL) { xmlTreeIndentString = indent; } - + defaultEntityLoader = xmlGetExternalEntityLoader(); xmlSetExternalEntityLoader(xmllintExternalEntityLoader); @@ -3336,7 +3345,7 @@ main(int argc, char **argv) { xmlGenericError(xmlGenericErrorContext, "%s output\n", argv[0]); - xmlGenericError(xmlGenericErrorContext, + xmlGenericError(xmlGenericErrorContext, "

%s output

\n", argv[0]); } @@ -3350,7 +3359,7 @@ main(int argc, char **argv) { xmlSchematronParserCtxtPtr ctxt; /* forces loading the DTDs */ - xmlLoadExtDtdDefaultValue |= 1; + xmlLoadExtDtdDefaultValue |= 1; options |= XML_PARSE_DTDLOAD; if (timing) { startTimer(); @@ -3384,7 +3393,7 @@ main(int argc, char **argv) { xmlRelaxNGParserCtxtPtr ctxt; /* forces loading the DTDs */ - xmlLoadExtDtdDefaultValue |= 1; + xmlLoadExtDtdDefaultValue |= 1; options |= XML_PARSE_DTDLOAD; if (timing) { startTimer(); @@ -3464,7 +3473,7 @@ main(int argc, char **argv) { (!strcmp(argv[i], "--dtdvalid"))) { i++; continue; - } + } if ((!strcmp(argv[i], "-path")) || (!strcmp(argv[i], "--path"))) { i++; @@ -3554,7 +3563,7 @@ main(int argc, char **argv) { } } } - if (generate) + if (generate) parseAndPrintFile(NULL, NULL); if ((htmlout) && (!nowrap)) { xmlGenericError(xmlGenericErrorContext, "\n"); -- cgit v1.2.1