/*
* xmllint.c : a small tester program for XML input.
*
* See Copyright for the status of this software.
*
* daniel@veillard.com
*/
#include "libxml.h"
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#if defined (_WIN32) && !defined(__CYGWIN__)
#if defined (_MSC_VER) || defined(__BORLANDC__)
#include <winsock2.h>
#endif /* _MSC_VER */
#endif /* _WIN32 */
#ifdef HAVE_SYS_TIME_H
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#ifdef __MINGW32__
#define _WINSOCKAPI_
#include <wsockcompat.h>
#include <winsock2.h>
#define XML_SOCKLEN_T unsigned int
#endif
#ifdef HAVE_SYS_TIMEB_H
#endif
#ifdef HAVE_SYS_TYPES_H
#endif
#ifdef HAVE_SYS_STAT_H
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_MMAN_H
/* seems needed for Solaris */
#ifndef MAP_FAILED
#endif
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_LIBREADLINE
#include <readline/readline.h>
#ifdef HAVE_LIBHISTORY
#endif
#endif
#include <libxml/xmlmemory.h>
#include <libxml/parserInternals.h>
#include <libxml/HTMLparser.h>
#include <libxml/HTMLtree.h>
#include <libxml/debugXML.h>
#include <libxml/xmlerror.h>
#ifdef LIBXML_XINCLUDE_ENABLED
#include <libxml/xinclude.h>
#endif
#ifdef LIBXML_CATALOG_ENABLED
#endif
#include <libxml/xmlreader.h>
#ifdef LIBXML_SCHEMATRON_ENABLED
#include <libxml/schematron.h>
#endif
#ifdef LIBXML_SCHEMAS_ENABLED
#include <libxml/xmlschemas.h>
#endif
#ifdef LIBXML_PATTERN_ENABLED
#endif
#ifdef LIBXML_C14N_ENABLED
#endif
#ifdef LIBXML_OUTPUT_ENABLED
#endif
#ifndef XML_XML_DEFAULT_CATALOG
#endif
typedef enum {
#ifdef LIBXML_DEBUG_ENABLED
static int shell = 0;
static int debugent = 0;
#endif
static int debug = 0;
static int maxmem = 0;
#ifdef LIBXML_TREE_ENABLED
static int copy = 0;
#endif /* LIBXML_TREE_ENABLED */
static int recovery = 0;
static int noent = 0;
static int noblanks = 0;
static int noout = 0;
static int nowrap = 0;
#ifdef LIBXML_OUTPUT_ENABLED
static int format = 0;
static int compress = 0;
static int oldout = 0;
#endif /* LIBXML_OUTPUT_ENABLED */
#ifdef LIBXML_VALID_ENABLED
static int valid = 0;
static int postvalid = 0;
#endif
#ifdef LIBXML_SCHEMAS_ENABLED
#endif
#ifdef LIBXML_SCHEMATRON_ENABLED
#endif
static int repeat = 0;
static int insert = 0;
#if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED)
static int html = 0;
static int xmlout = 0;
#endif
static int htmlout = 0;
#ifdef LIBXML_PUSH_ENABLED
static int push = 0;
#endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_SYS_MMAN_H
static int memory = 0;
#endif
static int testIO = 0;
#ifdef LIBXML_XINCLUDE_ENABLED
static int xinclude = 0;
#endif
static int dtdattrs = 0;
static int loaddtd = 0;
static int timing = 0;
static int generate = 0;
static int dropdtd = 0;
#ifdef LIBXML_CATALOG_ENABLED
static int catalogs = 0;
static int nocatalogs = 0;
#endif
#ifdef LIBXML_C14N_ENABLED
static int canonical = 0;
static int exc_canonical = 0;
#endif
#ifdef LIBXML_READER_ENABLED
static int stream = 0;
static int walker = 0;
#endif /* LIBXML_READER_ENABLED */
static int chkregister = 0;
static int nbregister = 0;
#ifdef LIBXML_SAX1_ENABLED
static int sax1 = 0;
#endif /* LIBXML_SAX1_ENABLED */
#ifdef LIBXML_PATTERN_ENABLED
#endif
static int sax = 0;
/************************************************************************
* *
* Entity loading control and customization. *
* *
************************************************************************/
#ifdef _WIN32
#else
#endif
static int nbpaths = 0;
static int load_trace = 0;
static
return;
while (*path != 0) {
return;
}
cur++;
cur++;
nbpaths++;
}
}
}
static xmlParserInputPtr
int i;
while (*iter != 0) {
if (*iter == '/')
iter++;
}
}
}
if (defaultEntityLoader != NULL) {
if (load_trace) {
fprintf \
(stderr,
"Loaded URL=\"%s\" ID=\"%s\"\n",
}
return(ret);
}
}
for (i = 0;i < nbpaths;i++) {
if (load_trace) {
fprintf \
(stderr,
"Loaded URL=\"%s\" ID=\"%s\"\n",
}
return(ret);
}
}
}
}
return(NULL);
}
/************************************************************************
* *
* Memory allocation consumption debugging *
* *
************************************************************************/
static void
OOM(void)
{
}
static void
{
}
static void *
{
void *ret;
if (xmlMemUsed() > maxmem) {
OOM();
return (NULL);
}
}
return (ret);
}
static void *
{
void *ret;
if (xmlMemUsed() > maxmem) {
OOM();
return (NULL);
}
}
return (ret);
}
static char *
{
char *ret;
if (xmlMemUsed() > maxmem) {
OOM();
return (NULL);
}
}
return (ret);
}
/************************************************************************
* *
* Internal timing routines to remove the necessity to have *
* unix-specific function calls. *
* *
************************************************************************/
#ifndef HAVE_GETTIMEOFDAY
#ifdef HAVE_SYS_TIMEB_H
#ifdef HAVE_SYS_TIME_H
#ifdef HAVE_FTIME
static int
{
ftime(&timebuffer);
if (tvp) {
}
return (0);
}
#endif /* HAVE_FTIME */
#endif /* HAVE_SYS_TIME_H */
#endif /* HAVE_SYS_TIMEB_H */
#endif /* !HAVE_GETTIMEOFDAY */
#if defined(HAVE_GETTIMEOFDAY)
/*
* startTimer: call where you want to start timing
*/
static void
startTimer(void)
{
}
/*
* endTimer: call where you want to stop timing and to print out a
* message about the timing performed; format is a printf
* type argument
*/
static void XMLCDECL
{
long msec;
msec *= 1000;
#ifndef HAVE_STDARG_H
#error "endTimer required stdarg functions"
#endif
}
#elif defined(HAVE_TIME_H)
/*
* No gettimeofday function, so we have to make do with calling clock.
* This is obviously less accurate, but there's little we can do about
* that.
*/
#ifndef CLOCKS_PER_SEC
#endif
static void
startTimer(void)
{
}
static void XMLCDECL
{
long msec;
#ifndef HAVE_STDARG_H
#error "endTimer required stdarg functions"
#endif
}
#else
/*
* We don't have a gettimeofday or time.h, so we just don't do timing
*/
static void
startTimer(void)
{
/*
* Do nothing
*/
}
static void XMLCDECL
{
/*
* We cannot do anything because we don't have a timing function
*/
#ifdef HAVE_STDARG_H
#else
/* We don't have gettimeofday, time or stdarg.h, what crazy world is
* this ?!
*/
#endif
}
#endif
/************************************************************************
* *
* HTML ouput *
* *
************************************************************************/
static void
xmlHTMLEncodeSend(void) {
char *result;
if (result) {
}
buffer[0] = 0;
}
/**
* xmlHTMLPrintFileInfo:
* @input: an xmlParserInputPtr input
*
* Displays the associated file and line informations for the current input
*/
static void
int len;
} else {
}
}
}
/**
* xmlHTMLPrintFileContext:
* @input: an xmlParserInputPtr input
*
* Displays current context within the input content for error tracking
*/
static void
int len;
int n;
cur--;
}
n = 0;
cur--;
n = 0;
(unsigned char) *cur++);
n++;
}
cur--;
n = 0;
base++;
}
}
/**
* xmlHTMLError:
* @ctx: an XML parser context
* @...: extra parameters for the message display
*
* Display and format an error messages, gives file, line, position and
* extra parameters.
*/
static void XMLCDECL
{
int len;
buffer[0] = 0;
}
}
/**
* xmlHTMLWarning:
* @ctx: an XML parser context
* @...: extra parameters for the message display
*
* Display and format a warning messages, gives file, line, position and
* extra parameters.
*/
static void XMLCDECL
{
int len;
buffer[0] = 0;
}
}
/**
* xmlHTMLValidityError:
* @ctx: an XML parser context
* @...: extra parameters for the message display
*
* Display and format an validity error messages, gives file,
* line, position and extra parameters.
*/
static void XMLCDECL
{
int len;
buffer[0] = 0;
}
/**
* xmlHTMLValidityWarning:
* @ctx: an XML parser context
* @...: extra parameters for the message display
*
* Display and format a validity warning messages, gives file, line,
* position and extra parameters.
*/
static void XMLCDECL
{
int len;
buffer[0] = 0;
}
/************************************************************************
* *
* Shell Interface *
* *
************************************************************************/
#ifdef LIBXML_DEBUG_ENABLED
#ifdef LIBXML_XPATH_ENABLED
/**
* xmlShellReadline:
* @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.
*/
static char *
#ifdef HAVE_LIBREADLINE
char *line_read;
/* Get a line from the user. */
/* If the line has any text in it, save it on the history. */
return (line_read);
#else
char line_read[501];
char *ret;
int len;
return(NULL);
line_read[500] = 0;
}
return(ret);
#endif
}
#endif /* LIBXML_XPATH_ENABLED */
#endif /* LIBXML_DEBUG_ENABLED */
/************************************************************************
* *
* I/O Interfaces *
* *
************************************************************************/
}
if (f != stdin) {
fclose(f);
}
}
/************************************************************************
* *
* SAX based tests *
* *
************************************************************************/
/*
* empty SAX block
*/
NULL, /* internalSubset */
NULL, /* isStandalone */
NULL, /* hasInternalSubset */
NULL, /* hasExternalSubset */
NULL, /* resolveEntity */
NULL, /* getEntity */
NULL, /* entityDecl */
NULL, /* notationDecl */
NULL, /* attributeDecl */
NULL, /* elementDecl */
NULL, /* unparsedEntityDecl */
NULL, /* setDocumentLocator */
NULL, /* startDocument */
NULL, /* endDocument */
NULL, /* startElement */
NULL, /* endElement */
NULL, /* reference */
NULL, /* characters */
NULL, /* ignorableWhitespace */
NULL, /* processingInstruction */
NULL, /* comment */
NULL, /* xmlParserWarning */
NULL, /* xmlParserError */
NULL, /* xmlParserError */
NULL, /* getParameterEntity */
NULL, /* cdataBlock; */
NULL, /* externalSubset; */
NULL,
NULL, /* startElementNs */
NULL, /* endElementNs */
NULL /* xmlStructuredErrorFunc */
};
extern xmlSAXHandlerPtr debugSAXHandler;
static int callbacks;
/**
* isStandaloneDebug:
* @ctxt: An XML parser context
*
* Is this document tagged standalone ?
*
* Returns 1 if true
*/
static int
{
callbacks++;
if (noout)
return(0);
return(0);
}
/**
* hasInternalSubsetDebug:
* @ctxt: An XML parser context
*
* Does this document has an internal subset
*
* Returns 1 if true
*/
static int
{
callbacks++;
if (noout)
return(0);
return(0);
}
/**
* hasExternalSubsetDebug:
* @ctxt: An XML parser context
*
* Does this document has an external subset
*
* Returns 1 if true
*/
static int
{
callbacks++;
if (noout)
return(0);
return(0);
}
/**
* internalSubsetDebug:
* @ctxt: An XML parser context
*
* Does this document has an internal subset
*/
static void
{
callbacks++;
if (noout)
return;
if (ExternalID == NULL)
else
else
}
/**
* externalSubsetDebug:
* @ctxt: An XML parser context
*
* Does this document has an external subset
*/
static void
{
callbacks++;
if (noout)
return;
if (ExternalID == NULL)
else
else
}
/**
* resolveEntityDebug:
* @ctxt: An XML parser context
* @publicId: The public ID of the entity
* @systemId: The system ID of the entity
*
* Special entity resolver, better left to the parser, it has
* more context than the application layer.
* The default behaviour is to NOT resolve the entities, in that case
* the ENTITY_REF nodes are built in the structure (and the parameter
* values).
*
* Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
*/
static xmlParserInputPtr
{
callbacks++;
if (noout)
return(NULL);
/* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
else
else
return(NULL);
}
/**
* getEntityDebug:
* @ctxt: An XML parser context
* @name: The entity name
*
* Get an entity by name
*
* Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
*/
static xmlEntityPtr
{
callbacks++;
if (noout)
return(NULL);
return(NULL);
}
/**
* getParameterEntityDebug:
* @ctxt: An XML parser context
* @name: The entity name
*
* Get a parameter entity by name
*
* Returns the xmlParserInputPtr
*/
static xmlEntityPtr
{
callbacks++;
if (noout)
return(NULL);
return(NULL);
}
/**
* entityDeclDebug:
* @ctxt: An XML parser context
* @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).
*
* An entity definition has been parsed
*/
static void
{
/* not all libraries handle printing null pointers nicely */
callbacks++;
if (noout)
return;
}
/**
* attributeDeclDebug:
* @ctxt: An XML parser context
* @name: the attribute name
* @type: the attribute type
*
* An attribute definition has been parsed
*/
static void
{
callbacks++;
if (noout)
return;
if (defaultValue == NULL)
else
}
/**
* elementDeclDebug:
* @ctxt: An XML parser context
* @name: the element name
* @type: the element type
* @content: the element value (without processing).
*
* An element definition has been parsed
*/
static void
{
callbacks++;
if (noout)
return;
}
/**
* notationDeclDebug:
* @ctxt: An XML parser context
* @name: The name of the notation
* @publicId: The public ID of the entity
* @systemId: The system ID of the entity
*
* What to do when a notation declaration has been parsed.
*/
static void
{
callbacks++;
if (noout)
return;
}
/**
* unparsedEntityDeclDebug:
* @ctxt: An XML parser context
* @name: The name of the entity
* @publicId: The public ID of the entity
* @systemId: The system ID of the entity
* @notationName: the name of the notation
*
* What to do when an unparsed entity declaration is parsed
*/
static void
const xmlChar *notationName)
{
if (notationName == NULL)
callbacks++;
if (noout)
return;
(char *) notationName);
}
/**
* setDocumentLocatorDebug:
* @ctxt: An XML parser context
* @loc: A SAX Locator
*
* Receive the document locator at startup, actually xmlDefaultSAXLocator
* Everything is available on the context, so this is useless in our case.
*/
static void
{
callbacks++;
if (noout)
return;
}
/**
* startDocumentDebug:
* @ctxt: An XML parser context
*
* called when the document start being processed.
*/
static void
{
callbacks++;
if (noout)
return;
}
/**
* endDocumentDebug:
* @ctxt: An XML parser context
*
* called when the document end has been detected.
*/
static void
{
callbacks++;
if (noout)
return;
}
/**
* startElementDebug:
* @ctxt: An XML parser context
* @name: The element name
*
* called when an opening tag has been processed.
*/
static void
{
int i;
callbacks++;
if (noout)
return;
}
}
}
/**
* endElementDebug:
* @ctxt: An XML parser context
* @name: The element name
*
* called when the end of an element has been detected.
*/
static void
{
callbacks++;
if (noout)
return;
}
/**
* charactersDebug:
* @ctxt: An XML parser context
* @ch: a xmlChar string
* @len: the number of xmlChar
*
* receiving some chars from the parser.
* Question: how much at a time ???
*/
static void
{
int i;
callbacks++;
if (noout)
return;
for (i = 0;(i<len) && (i < 30);i++)
out[i] = 0;
}
/**
* referenceDebug:
* @ctxt: An XML parser context
* @name: The entity name
*
* called when an entity reference is detected.
*/
static void
{
callbacks++;
if (noout)
return;
}
/**
* ignorableWhitespaceDebug:
* @ctxt: An XML parser context
* @ch: a xmlChar string
* @start: the first char in the string
* @len: the number of xmlChar
*
* receiving some ignorable whitespaces from the parser.
* Question: how much at a time ???
*/
static void
{
int i;
callbacks++;
if (noout)
return;
for (i = 0;(i<len) && (i < 30);i++)
out[i] = 0;
}
/**
* processingInstructionDebug:
* @ctxt: An XML parser context
* @target: the target name
* @data: the PI data's
* @len: the number of xmlChar
*
* A processing instruction has been parsed.
*/
static void
{
callbacks++;
if (noout)
return;
else
(char *) target);
}
/**
* cdataBlockDebug:
* @ctx: the user data (XML parser context)
* @value: The pcdata content
* @len: the block length
*
* called when a pcdata block has been parsed
*/
static void
{
callbacks++;
if (noout)
return;
}
/**
* commentDebug:
* @ctxt: An XML parser context
* @value: the comment content
*
* A comment has been parsed.
*/
static void
{
callbacks++;
if (noout)
return;
}
/**
* warningDebug:
* @ctxt: An XML parser context
* @...: extra parameters for the message display
*
* Display and format a warning messages, gives file, line, position and
* extra parameters.
*/
static void XMLCDECL
{
callbacks++;
if (noout)
return;
}
/**
* errorDebug:
* @ctxt: An XML parser context
* @...: extra parameters for the message display
*
* Display and format a error messages, gives file, line, position and
* extra parameters.
*/
static void XMLCDECL
{
callbacks++;
if (noout)
return;
}
/**
* fatalErrorDebug:
* @ctxt: An XML parser context
* @...: extra parameters for the message display
*
* Display and format a fatalError messages, gives file, line, position and
* extra parameters.
*/
static void XMLCDECL
{
callbacks++;
if (noout)
return;
}
1,
NULL,
NULL,
NULL,
};
/*
* SAX2 specific callbacks
*/
/**
* startElementNsDebug:
* @ctxt: An XML parser context
* @name: The element name
*
* called when an opening tag has been processed.
*/
static void
int nb_namespaces,
const xmlChar **namespaces,
int nb_attributes,
int nb_defaulted,
const xmlChar **attributes)
{
int i;
callbacks++;
if (noout)
return;
else
else
if (namespaces != NULL) {
for (i = 0;i < nb_namespaces * 2;i++) {
if (namespaces[i] != NULL)
i++;
}
}
if (attributes != NULL) {
else
}
}
}
/**
* endElementDebug:
* @ctxt: An XML parser context
* @name: The element name
*
* called when the end of an element has been detected.
*/
static void
{
callbacks++;
if (noout)
return;
else
else
}
NULL,
NULL,
NULL,
};
static void
callbacks = 0;
if (noout) {
#ifdef LIBXML_SAX1_ENABLED
} else if (sax1) {
#endif
} else {
}
/*
* it's not the simplest code but the most generic in term of I/O
*/
goto error;
}
#ifdef LIBXML_SCHEMAS_ENABLED
int ret;
stderr);
(void *)user_data);
if (repeat == 0) {
if (ret == 0) {
} else if (ret > 0) {
} else {
filename);
}
}
} else
#endif
{
/*
* Create the parser context amd hook the input
*/
ctxt = xmlNewParserCtxt();
goto error;
}
if (inputStream == NULL) {
goto error;
}
/* do the parsing */
}
}
}
}
/************************************************************************
* *
* Stream Test processing *
* *
************************************************************************/
#ifdef LIBXML_READER_ENABLED
if (debug) {
printf("%d %d %s %d %d",
type,
name,
printf("\n");
else {
}
}
#ifdef LIBXML_PATTERN_ENABLED
if (patternc) {
if (type == XML_READER_TYPE_ELEMENT) {
/* do the check only on element start */
if (match) {
}
}
int ret;
if (type == XML_READER_TYPE_ELEMENT) {
if (ret < 0) {
}
"xmlPatternMatch and xmlStreamPush disagree\n");
" pattern %s node %s\n",
}
}
if ((type == XML_READER_TYPE_END_ELEMENT) ||
if (ret < 0) {
}
}
}
}
#endif
}
int ret;
#ifdef HAVE_SYS_MMAN_H
if (memory) {
return;
return;
if (base == (void *) MAP_FAILED)
return;
} else
#endif
#ifdef LIBXML_PATTERN_ENABLED
"Pattern %s failed to compile\n", pattern);
}
}
if (ret < 0) {
}
}
}
#endif
#ifdef LIBXML_VALID_ENABLED
if (valid)
else
#endif /* LIBXML_VALID_ENABLED */
#ifdef LIBXML_SCHEMAS_ENABLED
startTimer();
}
if (ret < 0) {
"Relax-NG schema %s failed to compile\n", relaxng);
}
endTimer("Compiling the schemas");
}
}
startTimer();
}
if (ret < 0) {
"XSD schema %s failed to compile\n", schema);
}
endTimer("Compiling the schemas");
}
}
#endif
/*
* Process all nodes in sequence
*/
startTimer();
}
while (ret == 1) {
if ((debug)
#ifdef LIBXML_PATTERN_ENABLED
|| (patternc)
#endif
)
}
#ifdef LIBXML_SCHEMAS_ENABLED
endTimer("Parsing and validating");
else
#endif
#ifdef LIBXML_VALID_ENABLED
if (valid)
endTimer("Parsing and validating");
else
#endif
endTimer("Parsing");
}
#ifdef LIBXML_VALID_ENABLED
if (valid) {
"Document %s does not validate\n", filename);
}
}
#endif /* LIBXML_VALID_ENABLED */
#ifdef LIBXML_SCHEMAS_ENABLED
} else {
}
}
#endif
/*
* Done, cleanup and status
*/
if (ret != 0) {
}
} else {
}
#ifdef LIBXML_PATTERN_ENABLED
}
#endif
#ifdef HAVE_SYS_MMAN_H
if (memory) {
}
#endif
}
int ret;
#ifdef LIBXML_PATTERN_ENABLED
int i;
}
namespaces[i++] = NULL;
namespaces[i++] = NULL;
0, &namespaces[0]);
"Pattern %s failed to compile\n", pattern);
}
}
if (ret < 0) {
}
}
}
#endif /* LIBXML_PATTERN_ENABLED */
startTimer();
}
while (ret == 1) {
if ((debug)
#ifdef LIBXML_PATTERN_ENABLED
|| (patternc)
#endif
)
}
endTimer("walking through the doc");
}
if (ret != 0) {
}
} else {
}
#ifdef LIBXML_PATTERN_ENABLED
}
#endif
}
#endif /* LIBXML_READER_ENABLED */
/************************************************************************
* *
* Tree Test processing *
* *
************************************************************************/
#ifdef LIBXML_TREE_ENABLED
#endif /* LIBXML_TREE_ENABLED */
startTimer();
#ifdef LIBXML_TREE_ENABLED
if (generate) {
xmlNodePtr n;
xmlDocSetRootElement(doc, n);
}
}
#endif /* LIBXML_TREE_ENABLED */
#ifdef LIBXML_HTML_ENABLED
#ifdef LIBXML_PUSH_ENABLED
FILE *f;
#else
#endif
if (f != NULL) {
/* if (repeat) */
size = 4096;
if (res > 0) {
}
}
fclose(f);
}
}
#endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_SYS_MMAN_H
int fd;
const char *base;
return;
return;
if (base == (void *) MAP_FAILED)
return;
}
#endif
else if (html) {
}
#endif /* LIBXML_HTML_ENABLED */
else {
#ifdef LIBXML_PUSH_ENABLED
/*
* build an XML tree from a string;
*/
if (push) {
FILE *f;
/* '-' Usually means stdin -<sven@zen.org> */
f = stdin;
} else {
#else
#endif
}
if (f != NULL) {
int ret;
/* if (repeat) size = 1024; */
if (res > 0) {
}
if (!ret) {
}
}
}
} else
#endif /* LIBXML_PUSH_ENABLED */
if (testIO) {
} else {
FILE *f;
#else
#endif
if (f != NULL) {
(xmlInputCloseCallback) myClose, f,
else
(xmlInputCloseCallback) myClose, f,
} else
}
} else if (htmlout) {
ctxt = xmlNewParserCtxt();
else
} else {
}
#ifdef HAVE_SYS_MMAN_H
} else if (memory) {
int fd;
const char *base;
return;
return;
if (base == (void *) MAP_FAILED)
return;
else
#endif
#ifdef LIBXML_VALID_ENABLED
} else if (valid) {
ctxt = xmlNewParserCtxt();
else
} else {
}
#endif /* LIBXML_VALID_ENABLED */
} else {
else {
#ifdef LIBXML_SAX1_ENABLED
if (sax1)
else
#endif /* LIBXML_SAX1_ENABLED */
}
}
}
/*
* If we don't have a document we might as well give up. Do we
* want an error message here? <sven@zen.org> */
return;
}
endTimer("Parsing");
}
/*
* Remove DOCTYPE nodes
*/
if (dropdtd) {
}
}
#ifdef LIBXML_XINCLUDE_ENABLED
if (xinclude) {
startTimer();
}
endTimer("Xinclude processing");
}
}
#endif
#ifdef LIBXML_DEBUG_ENABLED
#ifdef LIBXML_XPATH_ENABLED
/*
* shell interaction
*/
if (shell) {
}
#endif
#endif
#ifdef LIBXML_TREE_ENABLED
/*
* test intermediate copy if needed.
*/
if (copy) {
if (timing) {
startTimer();
}
if (timing) {
endTimer("Copying");
}
if (timing) {
startTimer();
}
if (timing) {
endTimer("Freeing original");
}
}
#endif /* LIBXML_TREE_ENABLED */
#ifdef LIBXML_VALID_ENABLED
int nb, i;
if (nb < 0) {
} else if (nb == 0) {
} else {
nb);
for (i = 0;i < nb;i++) {
}
}
}
}
}else
#endif /* LIBXML_VALID_ENABLED */
#ifdef LIBXML_READER_ENABLED
if (walker) {
}
#endif /* LIBXML_READER_ENABLED */
#ifdef LIBXML_OUTPUT_ENABLED
if (noout == 0) {
int ret;
/*
* print it.
*/
#ifdef LIBXML_DEBUG_ENABLED
if (!debug) {
#endif
startTimer();
}
#ifdef LIBXML_HTML_ENABLED
if (compress) {
}
if ( format ) {
}
else {
}
}
else if (format) {
}
else {
else {
}
} else {
}
}
endTimer("Saving");
}
} else
#endif
#ifdef LIBXML_C14N_ENABLED
if (canonical) {
int size;
if (size >= 0) {
} else {
}
} else
if (exc_canonical) {
int size;
if (size >= 0) {
} else {
}
} else
#endif
#ifdef HAVE_SYS_MMAN_H
if (memory) {
int len;
if ( format ) {
} else {
}
} else {
if (format)
else
}
} else {
}
} else
#endif /* HAVE_SYS_MMAN_H */
if (compress) {
} else if (oldout) {
if ( format ) {
encoding, 1);
}
else {
encoding);
}
if (ret < 0) {
}
} else if (format) {
if (ret < 0) {
}
} else {
else {
}
} else {
}
}
} else {
int saveOpts = 0;
if (format)
else
}
} else {
}
}
endTimer("Saving");
}
#ifdef LIBXML_DEBUG_ENABLED
} else {
else {
}
} else {
}
}
#endif
}
#endif /* LIBXML_OUTPUT_ENABLED */
#ifdef LIBXML_VALID_ENABLED
/*
* A posteriori validation test
*/
startTimer();
}
else
endTimer("Parsing DTD");
}
"Could not parse DTD %s\n", dtdvalid);
else
"Could not parse DTD %s\n", dtdvalidfpi);
} else {
"Couldn't allocate validation context\n");
exit(-1);
}
startTimer();
}
"Document %s does not validate against %s\n",
else
"Document %s does not validate against %s\n",
}
endTimer("Validating against DTD");
}
}
} else if (postvalid) {
"Couldn't allocate validation context\n");
exit(-1);
}
startTimer();
}
"Document %s does not validate\n", filename);
}
endTimer("Validating");
}
}
#endif /* LIBXML_VALID_ENABLED */
#ifdef LIBXML_SCHEMATRON_ENABLED
if (wxschematron != NULL) {
int ret;
int flag;
startTimer();
}
if (debug)
else
if (noout)
#if 0
stderr);
#endif
if (ret == 0) {
} else if (ret > 0) {
} else {
filename);
}
endTimer("Validating");
}
}
#endif
#ifdef LIBXML_SCHEMAS_ENABLED
if (relaxngschemas != NULL) {
int ret;
startTimer();
}
stderr);
if (ret == 0) {
} else if (ret > 0) {
} else {
filename);
}
endTimer("Validating");
}
int ret;
startTimer();
}
stderr);
if (ret == 0) {
} else if (ret > 0) {
} else {
filename);
}
endTimer("Validating");
}
}
#endif
#ifdef LIBXML_DEBUG_ENABLED
#endif
/*
* free it.
*/
startTimer();
}
endTimer("Freeing");
}
}
/************************************************************************
* *
* Usage and Main *
* *
************************************************************************/
}
#ifdef LIBXML_OUTPUT_ENABLED
printf("\tParse the XML files and output the result of the parsing\n");
#else
printf("\tParse the XML files\n");
#endif /* LIBXML_OUTPUT_ENABLED */
printf("\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");
#else
#ifdef LIBXML_READER_ENABLED
printf("\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");
#endif /* LIBXML_TREE_ENABLED */
printf("\t--recover : output what was parsable on broken XML documents\n");
printf("\t--noent : substitute entity references by their value\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 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
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");
#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");
#ifdef LIBXML_OUTPUT_ENABLED
#ifdef HAVE_ZLIB_H
printf("\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");
#endif
#ifdef LIBXML_PUSH_ENABLED
printf("\t--push : use the push mode of the parser\n");
#endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_SYS_MMAN_H
printf("\t--memory : parse from memory\n");
#endif
printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");
printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
printf("\t--nocdata : replace cdata section with text nodes\n");
#ifdef LIBXML_OUTPUT_ENABLED
printf("\t--encode encoding : output in the given encoding\n");
printf("\t--dropdtd : remove the DOCTYPE of the input docs\n");
#endif /* LIBXML_OUTPUT_ENABLED */
printf("\t--c14n : save in W3C canonical format (with comments)\n");
printf("\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");
#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--nocatalogs : deactivate all catalogs\n");
#endif
printf("\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");
#endif
printf("\t--loaddtd : fetch external DTD\n");
printf("\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");
#endif /* LIBXML_READER_ENABLED */
#ifdef LIBXML_PATTERN_ENABLED
printf("\t--pattern pattern_value : test the pattern support\n");
#endif
printf("\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");
#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
printf("\t--sax : do not build a tree but work just at the SAX level\n");
printf("\nLibxml project home page: http://xmlsoft.org/\n");
printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
}
{
nbregister++;
}
{
nbregister--;
}
int
int i, acount;
int files = 0;
int version = 0;
const char* indent;
if (argc <= 1) {
return(1);
}
for (i = 1; i < argc ; i++) {
break;
if (argv[i][0] != '-')
continue;
debug++;
else
#ifdef LIBXML_DEBUG_ENABLED
shell++;
noout = 1;
} else
#endif
#ifdef LIBXML_TREE_ENABLED
copy++;
else
#endif /* LIBXML_TREE_ENABLED */
recovery++;
noent++;
showVersion(argv[0]);
version = 1;
noout++;
#ifdef LIBXML_OUTPUT_ENABLED
i++;
}
#endif /* LIBXML_OUTPUT_ENABLED */
htmlout++;
nowrap++;
#ifdef LIBXML_HTML_ENABLED
html++;
}
xmlout++;
}
#endif /* LIBXML_HTML_ENABLED */
loaddtd++;
loaddtd++;
dtdattrs++;
}
#ifdef LIBXML_VALID_ENABLED
valid++;
postvalid++;
loaddtd++;
i++;
loaddtd++;
i++;
dtdvalidfpi = argv[i];
loaddtd++;
}
#endif /* LIBXML_VALID_ENABLED */
dropdtd++;
insert++;
timing++;
generate++;
if (repeat)
repeat *= 10;
else
repeat = 100;
}
#ifdef LIBXML_PUSH_ENABLED
push++;
#endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_SYS_MMAN_H
memory++;
#endif
testIO++;
#ifdef LIBXML_XINCLUDE_ENABLED
xinclude++;
}
xinclude++;
}
#endif
#ifdef LIBXML_OUTPUT_ENABLED
#ifdef HAVE_ZLIB_H
compress++;
}
#endif
#endif /* LIBXML_OUTPUT_ENABLED */
}
}
#ifdef LIBXML_DEBUG_ENABLED
debugent++;
}
#endif
#ifdef LIBXML_C14N_ENABLED
canonical++;
}
}
#endif
#ifdef LIBXML_CATALOG_ENABLED
catalogs++;
nocatalogs++;
}
#endif
i++;
/*
* OK it's for testing purposes
*/
}
noblanks++;
}
i++;
} else {
maxmem = 0;
}
}
noblanks++;
#ifdef LIBXML_OUTPUT_ENABLED
format++;
#endif /* LIBXML_OUTPUT_ENABLED */
}
#ifdef LIBXML_READER_ENABLED
stream++;
}
walker++;
noout++;
}
#endif /* LIBXML_READER_ENABLED */
#ifdef LIBXML_SAX1_ENABLED
sax1++;
}
#endif /* LIBXML_SAX1_ENABLED */
sax++;
}
chkregister++;
#ifdef LIBXML_SCHEMAS_ENABLED
i++;
noent++;
i++;
noent++;
#endif
#ifdef LIBXML_SCHEMATRON_ENABLED
i++;
schematron = argv[i];
noent++;
#endif
options &= ~XML_PARSE_COMPACT;
load_trace++;
i++;
#ifdef LIBXML_PATTERN_ENABLED
i++;
#endif
} else {
return(1);
}
}
#ifdef LIBXML_CATALOG_ENABLED
if (nocatalogs == 0) {
if (catalogs) {
const char *catal;
} else {
}
}
}
#endif
#ifdef LIBXML_SAX1_ENABLED
if (sax1)
else
#endif /* LIBXML_SAX1_ENABLED */
if (chkregister) {
}
}
if (loaddtd != 0)
if (dtdattrs)
#ifdef LIBXML_VALID_ENABLED
#endif /* LIBXML_VALID_ENABLED */
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n");
"\t\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n");
"<html><head><title>%s output</title></head>\n",
argv[0]);
"<body bgcolor=\"#ffffff\"><h1 align=\"center\">%s output</h1>\n",
argv[0]);
}
#ifdef LIBXML_SCHEMATRON_ENABLED
#ifdef LIBXML_READER_ENABLED
&& (stream == 0)
#endif /* LIBXML_READER_ENABLED */
) {
/* forces loading the DTDs */
if (timing) {
startTimer();
}
#if 0
stderr);
#endif
if (wxschematron == NULL) {
"Schematron schema %s failed to compile\n", schematron);
schematron = NULL;
}
if (timing) {
endTimer("Compiling the schemas");
}
}
#endif
#ifdef LIBXML_SCHEMAS_ENABLED
#ifdef LIBXML_READER_ENABLED
&& (stream == 0)
#endif /* LIBXML_READER_ENABLED */
) {
/* forces loading the DTDs */
if (timing) {
startTimer();
}
stderr);
if (relaxngschemas == NULL) {
"Relax-NG schema %s failed to compile\n", relaxng);
}
if (timing) {
endTimer("Compiling the schemas");
}
#ifdef LIBXML_READER_ENABLED
&& (stream == 0)
#endif
) {
if (timing) {
startTimer();
}
stderr);
"WXS schema %s failed to compile\n", schema);
}
if (timing) {
endTimer("Compiling the schemas");
}
}
#endif /* LIBXML_SCHEMAS_ENABLED */
#ifdef LIBXML_PATTERN_ENABLED
#ifdef LIBXML_READER_ENABLED
&& (walker == 0)
#endif
) {
"Pattern %s failed to compile\n", pattern);
}
}
#endif /* LIBXML_PATTERN_ENABLED */
for (i = 1; i < argc ; i++) {
i++;
continue;
i++;
continue;
}
#ifdef LIBXML_VALID_ENABLED
i++;
continue;
}
i++;
continue;
}
i++;
continue;
}
#endif /* LIBXML_VALID_ENABLED */
i++;
continue;
}
i++;
continue;
}
i++;
continue;
}
i++;
continue;
}
#ifdef LIBXML_PATTERN_ENABLED
i++;
continue;
}
#endif
startTimer();
/* Remember file names. "-" means stdin. <sven@zen.org> */
if (repeat) {
#ifdef LIBXML_READER_ENABLED
if (stream != 0) {
streamFile(argv[i]);
} else {
#endif /* LIBXML_READER_ENABLED */
if (sax) {
} else {
ctxt = xmlNewParserCtxt();
}
#ifdef LIBXML_READER_ENABLED
}
#endif /* LIBXML_READER_ENABLED */
}
} else {
nbregister = 0;
#ifdef LIBXML_READER_ENABLED
if (stream != 0)
streamFile(argv[i]);
else
#endif /* LIBXML_READER_ENABLED */
if (sax) {
} else {
}
if ((chkregister) && (nbregister != 0)) {
}
}
files ++;
}
}
}
if (generate)
}
}
#ifdef LIBXML_SCHEMATRON_ENABLED
if (wxschematron != NULL)
#endif
#ifdef LIBXML_SCHEMAS_ENABLED
if (relaxngschemas != NULL)
#endif
#ifdef LIBXML_PATTERN_ENABLED
#endif
return(progresult);
}