mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-27 18:50:07 +03:00
Time to work on helping the Gnome Doc project, first step is reintegrating
the SGML DocBook parser in libxml2 distrib: - DOCBparser.c DOCBparser.h testDocbook.c configure.in Makefile.am xmlversion.h.in: started (re)integrating the DocBook SGML parser. - SAX.[ch]: cleanup and updates for DocBook - debugXML.c parser.h tree.[ch] valid.c xpath.c: small macro or ex SGML identifier changes - valid.c: removed a static unused function. Daniel
This commit is contained in:
parent
de57c61c9d
commit
eae522a0d8
@ -1,3 +1,12 @@
|
||||
Mon Apr 23 15:40:04 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
|
||||
|
||||
* DOCBparser.c DOCBparser.h testDocbook.c configure.in Makefile.am
|
||||
xmlversion.h.in: started (re)integrating the DocBook SGML parser.
|
||||
* SAX.[ch]: cleanup and updates for DocBook
|
||||
* debugXML.c parser.h tree.[ch] valid.c xpath.c: small macro or
|
||||
ex SGML identifier changes
|
||||
* valid.c: removed a static unused function.
|
||||
|
||||
Mon Apr 23 11:05:56 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
|
||||
|
||||
* HTMLtree.c: applied change for Paul Sponagl on script saving
|
||||
|
5754
DOCBparser.c
Normal file
5754
DOCBparser.c
Normal file
File diff suppressed because it is too large
Load Diff
73
DOCBparser.h
Normal file
73
DOCBparser.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* SGMLparser.h : interface for a DocBook SGML non-verifying parser
|
||||
*
|
||||
* See Copyright for the status of this software.
|
||||
*
|
||||
* Daniel.Veillard@w3.org
|
||||
*/
|
||||
|
||||
#ifndef __DOCB_PARSER_H__
|
||||
#define __DOCB_PARSER_H__
|
||||
#include <parser.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Most of the back-end structures from XML and SGML are shared
|
||||
*/
|
||||
typedef xmlParserCtxt docbParserCtxt;
|
||||
typedef xmlParserCtxtPtr docbParserCtxtPtr;
|
||||
typedef xmlParserNodeInfo docbParserNodeInfo;
|
||||
typedef xmlSAXHandler docbSAXHandler;
|
||||
typedef xmlSAXHandlerPtr docbSAXHandlerPtr;
|
||||
typedef xmlParserInput docbParserInput;
|
||||
typedef xmlParserInputPtr docbParserInputPtr;
|
||||
typedef xmlDocPtr docbDocPtr;
|
||||
typedef xmlNodePtr docbNodePtr;
|
||||
|
||||
/*
|
||||
* There is only few public functions.
|
||||
*/
|
||||
int docbEncodeEntities(unsigned char* out,
|
||||
int *outlen,
|
||||
const unsigned char* in,
|
||||
int *inlen, int quoteChar);
|
||||
|
||||
docbDocPtr docbSAXParseDoc (xmlChar *cur,
|
||||
const char *encoding,
|
||||
docbSAXHandlerPtr sax,
|
||||
void *userData);
|
||||
docbDocPtr docbParseDoc (xmlChar *cur,
|
||||
const char *encoding);
|
||||
docbDocPtr docbSAXParseFile(const char *filename,
|
||||
const char *encoding,
|
||||
docbSAXHandlerPtr sax,
|
||||
void *userData);
|
||||
docbDocPtr docbParseFile (const char *filename,
|
||||
const char *encoding);
|
||||
|
||||
/**
|
||||
* Interfaces for the Push mode
|
||||
*/
|
||||
void docbFreeParserCtxt (docbParserCtxtPtr ctxt);
|
||||
docbParserCtxtPtr docbCreatePushParserCtxt(docbSAXHandlerPtr sax,
|
||||
void *user_data,
|
||||
const char *chunk,
|
||||
int size,
|
||||
const char *filename,
|
||||
xmlCharEncoding enc);
|
||||
int docbParseChunk (docbParserCtxtPtr ctxt,
|
||||
const char *chunk,
|
||||
int size,
|
||||
int terminate);
|
||||
docbParserCtxtPtr docbCreateFileParserCtxt(const char *filename,
|
||||
const char *encoding);
|
||||
int docbParseDocument (docbParserCtxtPtr ctxt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DOCB_PARSER_H__ */
|
@ -4,7 +4,7 @@ SUBDIRS = . include doc example
|
||||
|
||||
INCLUDES = -I@srcdir@/include -I./include @Z_CFLAGS@ @CORBA_CFLAGS@
|
||||
|
||||
noinst_PROGRAMS=testSAX testHTML testXPath testURI
|
||||
noinst_PROGRAMS=testSAX testHTML testXPath testURI testDocbook
|
||||
|
||||
bin_PROGRAMS = xmllint
|
||||
|
||||
@ -18,7 +18,7 @@ libxml2_la_LDFLAGS = -version-info @LIBXML_VERSION_INFO@
|
||||
libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
|
||||
parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
|
||||
valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \
|
||||
xpointer.c xinclude.c nanohttp.c nanoftp.c \
|
||||
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
|
||||
strio.c strio.h trio.c trio.h triop.h libxml.h
|
||||
|
||||
DEPS = $(top_builddir)/libxml2.la
|
||||
@ -44,6 +44,11 @@ testHTML_LDFLAGS =
|
||||
testHTML_DEPENDENCIES = $(DEPS)
|
||||
testHTML_LDADD= $(LDADDS)
|
||||
|
||||
testDocbook_SOURCES=testDocbook.c
|
||||
testDocbook_LDFLAGS =
|
||||
testDocbook_DEPENDENCIES = $(DEPS)
|
||||
testDocbook_LDADD= $(LDADDS)
|
||||
|
||||
testXPath_SOURCES=testXPath.c
|
||||
testXPath_LDFLAGS =
|
||||
testXPath_DEPENDENCIES = $(DEPS)
|
||||
|
67
SAX.c
67
SAX.c
@ -1628,6 +1628,7 @@ xmlDefaultSAXHandlerInit(void)
|
||||
xmlDefaultSAXHandler.fatalError = xmlParserError;
|
||||
}
|
||||
|
||||
#ifdef LIBXML_HTML_ENABLED
|
||||
/*
|
||||
* Default handler for HTML, builds the DOM tree
|
||||
*/
|
||||
@ -1697,11 +1698,13 @@ htmlDefaultSAXHandlerInit(void)
|
||||
htmlDefaultSAXHandler.error = xmlParserError;
|
||||
htmlDefaultSAXHandler.fatalError = xmlParserError;
|
||||
}
|
||||
#endif /* LIBXML_HTML_ENABLED */
|
||||
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
/*
|
||||
* Default handler for HTML, builds the DOM tree
|
||||
* Default handler for SGML DocBook, builds the DOM tree
|
||||
*/
|
||||
xmlSAXHandler sgmlDefaultSAXHandler = {
|
||||
xmlSAXHandler docbDefaultSAXHandler = {
|
||||
internalSubset,
|
||||
NULL,
|
||||
NULL,
|
||||
@ -1732,38 +1735,40 @@ xmlSAXHandler sgmlDefaultSAXHandler = {
|
||||
};
|
||||
|
||||
/**
|
||||
* sgmlDefaultSAXHandlerInit:
|
||||
* docbDefaultSAXHandlerInit:
|
||||
*
|
||||
* Initialize the default SAX handler
|
||||
*/
|
||||
void
|
||||
sgmlDefaultSAXHandlerInit(void)
|
||||
docbDefaultSAXHandlerInit(void)
|
||||
{
|
||||
sgmlDefaultSAXHandler.internalSubset = internalSubset;
|
||||
sgmlDefaultSAXHandler.externalSubset = NULL;
|
||||
sgmlDefaultSAXHandler.isStandalone = NULL;
|
||||
sgmlDefaultSAXHandler.hasInternalSubset = NULL;
|
||||
sgmlDefaultSAXHandler.hasExternalSubset = NULL;
|
||||
sgmlDefaultSAXHandler.resolveEntity = NULL;
|
||||
sgmlDefaultSAXHandler.getEntity = getEntity;
|
||||
sgmlDefaultSAXHandler.getParameterEntity = NULL;
|
||||
sgmlDefaultSAXHandler.entityDecl = NULL;
|
||||
sgmlDefaultSAXHandler.attributeDecl = NULL;
|
||||
sgmlDefaultSAXHandler.elementDecl = NULL;
|
||||
sgmlDefaultSAXHandler.notationDecl = NULL;
|
||||
sgmlDefaultSAXHandler.unparsedEntityDecl = NULL;
|
||||
sgmlDefaultSAXHandler.setDocumentLocator = setDocumentLocator;
|
||||
sgmlDefaultSAXHandler.startDocument = startDocument;
|
||||
sgmlDefaultSAXHandler.endDocument = endDocument;
|
||||
sgmlDefaultSAXHandler.startElement = startElement;
|
||||
sgmlDefaultSAXHandler.endElement = endElement;
|
||||
sgmlDefaultSAXHandler.reference = NULL;
|
||||
sgmlDefaultSAXHandler.characters = characters;
|
||||
sgmlDefaultSAXHandler.cdataBlock = NULL;
|
||||
sgmlDefaultSAXHandler.ignorableWhitespace = ignorableWhitespace;
|
||||
sgmlDefaultSAXHandler.processingInstruction = NULL;
|
||||
sgmlDefaultSAXHandler.comment = comment;
|
||||
sgmlDefaultSAXHandler.warning = xmlParserWarning;
|
||||
sgmlDefaultSAXHandler.error = xmlParserError;
|
||||
sgmlDefaultSAXHandler.fatalError = xmlParserError;
|
||||
docbDefaultSAXHandler.internalSubset = internalSubset;
|
||||
docbDefaultSAXHandler.externalSubset = NULL;
|
||||
docbDefaultSAXHandler.isStandalone = NULL;
|
||||
docbDefaultSAXHandler.hasInternalSubset = NULL;
|
||||
docbDefaultSAXHandler.hasExternalSubset = NULL;
|
||||
docbDefaultSAXHandler.resolveEntity = NULL;
|
||||
docbDefaultSAXHandler.getEntity = getEntity;
|
||||
docbDefaultSAXHandler.getParameterEntity = NULL;
|
||||
docbDefaultSAXHandler.entityDecl = NULL;
|
||||
docbDefaultSAXHandler.attributeDecl = NULL;
|
||||
docbDefaultSAXHandler.elementDecl = NULL;
|
||||
docbDefaultSAXHandler.notationDecl = NULL;
|
||||
docbDefaultSAXHandler.unparsedEntityDecl = NULL;
|
||||
docbDefaultSAXHandler.setDocumentLocator = setDocumentLocator;
|
||||
docbDefaultSAXHandler.startDocument = startDocument;
|
||||
docbDefaultSAXHandler.endDocument = endDocument;
|
||||
docbDefaultSAXHandler.startElement = startElement;
|
||||
docbDefaultSAXHandler.endElement = endElement;
|
||||
docbDefaultSAXHandler.reference = NULL;
|
||||
docbDefaultSAXHandler.characters = characters;
|
||||
docbDefaultSAXHandler.cdataBlock = NULL;
|
||||
docbDefaultSAXHandler.ignorableWhitespace = ignorableWhitespace;
|
||||
docbDefaultSAXHandler.processingInstruction = NULL;
|
||||
docbDefaultSAXHandler.comment = comment;
|
||||
docbDefaultSAXHandler.warning = xmlParserWarning;
|
||||
docbDefaultSAXHandler.error = xmlParserError;
|
||||
docbDefaultSAXHandler.fatalError = xmlParserError;
|
||||
}
|
||||
|
||||
#endif /* LIBXML_DOCB_ENABLED */
|
||||
|
2
SAX.h
2
SAX.h
@ -113,7 +113,7 @@ void cdataBlock (void *ctx,
|
||||
|
||||
void xmlDefaultSAXHandlerInit (void);
|
||||
void htmlDefaultSAXHandlerInit (void);
|
||||
void sgmlDefaultSAXHandlerInit (void);
|
||||
void docbDefaultSAXHandlerInit (void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
19
configure.in
19
configure.in
@ -235,9 +235,9 @@ if test "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/XML" ; then
|
||||
if test "${with_mem_debug}" = "" ; then
|
||||
with_mem_debug="yes"
|
||||
fi
|
||||
dnl if test "${with_docbook}" = "" ; then
|
||||
dnl with_docbook="yes"
|
||||
dnl fi
|
||||
if test "${with_docbook}" = "" ; then
|
||||
with_docbook="yes"
|
||||
fi
|
||||
if test "${with_xptr}" = "" ; then
|
||||
with_xptr="yes"
|
||||
fi
|
||||
@ -297,6 +297,19 @@ fi
|
||||
AC_SUBST(WITH_HTML)
|
||||
AC_SUBST(HTML_OBJ)
|
||||
|
||||
AC_ARG_WITH(docbook, [ --with-docbook Add Docbook SGML support (off)])
|
||||
if test "$with_docbook" = "yes" ; then
|
||||
echo Enabling Docbook support
|
||||
WITH_DOCB=1
|
||||
DOCB_OBJ="DOCBparser.o"
|
||||
else
|
||||
WITH_DOCB=0
|
||||
DOCB_OBJ=
|
||||
fi
|
||||
AC_SUBST(WITH_DOCB)
|
||||
AC_SUBST(DOCB_OBJ)
|
||||
|
||||
|
||||
AC_ARG_WITH(xpath, [ --with-xpath Add the XPATH support (on)])
|
||||
if test "$with_xpath" = "no" ; then
|
||||
echo Disabling XPATH support
|
||||
|
@ -899,8 +899,8 @@ static int xmlLsCountNode(xmlNodePtr node) {
|
||||
break;
|
||||
case XML_DOCUMENT_NODE:
|
||||
case XML_HTML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
list = ((xmlDocPtr) node)->children;
|
||||
break;
|
||||
|
73
include/libxml/DOCBparser.h
Normal file
73
include/libxml/DOCBparser.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* SGMLparser.h : interface for a DocBook SGML non-verifying parser
|
||||
*
|
||||
* See Copyright for the status of this software.
|
||||
*
|
||||
* Daniel.Veillard@w3.org
|
||||
*/
|
||||
|
||||
#ifndef __DOCB_PARSER_H__
|
||||
#define __DOCB_PARSER_H__
|
||||
#include <parser.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Most of the back-end structures from XML and SGML are shared
|
||||
*/
|
||||
typedef xmlParserCtxt docbParserCtxt;
|
||||
typedef xmlParserCtxtPtr docbParserCtxtPtr;
|
||||
typedef xmlParserNodeInfo docbParserNodeInfo;
|
||||
typedef xmlSAXHandler docbSAXHandler;
|
||||
typedef xmlSAXHandlerPtr docbSAXHandlerPtr;
|
||||
typedef xmlParserInput docbParserInput;
|
||||
typedef xmlParserInputPtr docbParserInputPtr;
|
||||
typedef xmlDocPtr docbDocPtr;
|
||||
typedef xmlNodePtr docbNodePtr;
|
||||
|
||||
/*
|
||||
* There is only few public functions.
|
||||
*/
|
||||
int docbEncodeEntities(unsigned char* out,
|
||||
int *outlen,
|
||||
const unsigned char* in,
|
||||
int *inlen, int quoteChar);
|
||||
|
||||
docbDocPtr docbSAXParseDoc (xmlChar *cur,
|
||||
const char *encoding,
|
||||
docbSAXHandlerPtr sax,
|
||||
void *userData);
|
||||
docbDocPtr docbParseDoc (xmlChar *cur,
|
||||
const char *encoding);
|
||||
docbDocPtr docbSAXParseFile(const char *filename,
|
||||
const char *encoding,
|
||||
docbSAXHandlerPtr sax,
|
||||
void *userData);
|
||||
docbDocPtr docbParseFile (const char *filename,
|
||||
const char *encoding);
|
||||
|
||||
/**
|
||||
* Interfaces for the Push mode
|
||||
*/
|
||||
void docbFreeParserCtxt (docbParserCtxtPtr ctxt);
|
||||
docbParserCtxtPtr docbCreatePushParserCtxt(docbSAXHandlerPtr sax,
|
||||
void *user_data,
|
||||
const char *chunk,
|
||||
int size,
|
||||
const char *filename,
|
||||
xmlCharEncoding enc);
|
||||
int docbParseChunk (docbParserCtxtPtr ctxt,
|
||||
const char *chunk,
|
||||
int size,
|
||||
int terminate);
|
||||
docbParserCtxtPtr docbCreateFileParserCtxt(const char *filename,
|
||||
const char *encoding);
|
||||
int docbParseDocument (docbParserCtxtPtr ctxt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DOCB_PARSER_H__ */
|
@ -113,7 +113,7 @@ void cdataBlock (void *ctx,
|
||||
|
||||
void xmlDefaultSAXHandlerInit (void);
|
||||
void htmlDefaultSAXHandlerInit (void);
|
||||
void sgmlDefaultSAXHandlerInit (void);
|
||||
void docbDefaultSAXHandlerInit (void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -303,7 +303,7 @@ LIBXML_DLL_IMPORT extern const char *xmlParserVersion;
|
||||
LIBXML_DLL_IMPORT extern xmlSAXLocator xmlDefaultSAXLocator;
|
||||
LIBXML_DLL_IMPORT extern xmlSAXHandler xmlDefaultSAXHandler;
|
||||
LIBXML_DLL_IMPORT extern xmlSAXHandler htmlDefaultSAXHandler;
|
||||
LIBXML_DLL_IMPORT extern xmlSAXHandler sgmlDefaultSAXHandler;
|
||||
LIBXML_DLL_IMPORT extern xmlSAXHandler docbDefaultSAXHandler;
|
||||
|
||||
/**
|
||||
* entity substitution default behaviour.
|
||||
|
@ -54,8 +54,8 @@ typedef enum {
|
||||
XML_NAMESPACE_DECL= 18,
|
||||
XML_XINCLUDE_START= 19,
|
||||
XML_XINCLUDE_END= 20
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
,XML_SGML_DOCUMENT_NODE= 21
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
,XML_DOCB_DOCUMENT_NODE= 21
|
||||
#endif
|
||||
} xmlElementType;
|
||||
|
||||
|
@ -62,13 +62,13 @@ extern void xmlCheckVersion(int version);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Whether the Docbook support is configured in
|
||||
#if @WITH_SGML@
|
||||
#define LIBXML_SGML_ENABLED
|
||||
#else
|
||||
#define LIBXML_SGML_DISABLED
|
||||
#endif
|
||||
* Whether the SGML Docbook support is configured in
|
||||
*/
|
||||
#if @WITH_DOCB@
|
||||
#define LIBXML_DOCB_ENABLED
|
||||
#else
|
||||
#define LIBXML_DOCB_DISABLED
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Whether XPath is configured in
|
||||
|
2
parser.h
2
parser.h
@ -303,7 +303,7 @@ LIBXML_DLL_IMPORT extern const char *xmlParserVersion;
|
||||
LIBXML_DLL_IMPORT extern xmlSAXLocator xmlDefaultSAXLocator;
|
||||
LIBXML_DLL_IMPORT extern xmlSAXHandler xmlDefaultSAXHandler;
|
||||
LIBXML_DLL_IMPORT extern xmlSAXHandler htmlDefaultSAXHandler;
|
||||
LIBXML_DLL_IMPORT extern xmlSAXHandler sgmlDefaultSAXHandler;
|
||||
LIBXML_DLL_IMPORT extern xmlSAXHandler docbDefaultSAXHandler;
|
||||
|
||||
/**
|
||||
* entity substitution default behaviour.
|
||||
|
851
testDocbook.c
Normal file
851
testDocbook.c
Normal file
@ -0,0 +1,851 @@
|
||||
/*
|
||||
* testDocbook.c : a small tester program for SGML Docbook input.
|
||||
*
|
||||
* See Copyright for the status of this software.
|
||||
*
|
||||
* Daniel.Veillard@w3.org
|
||||
*/
|
||||
|
||||
#include "libxml.h"
|
||||
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <libxml/xmlmemory.h>
|
||||
#include <libxml/DOCBparser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/debugXML.h>
|
||||
|
||||
#ifdef LIBXML_DEBUG_ENABLED
|
||||
static int debug = 0;
|
||||
#endif
|
||||
static int copy = 0;
|
||||
static int sax = 0;
|
||||
static int repeat = 0;
|
||||
static int noout = 0;
|
||||
static int push = 0;
|
||||
static char *encoding = NULL;
|
||||
|
||||
xmlSAXHandler emptySAXHandlerStruct = {
|
||||
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 */
|
||||
};
|
||||
|
||||
xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
|
||||
extern xmlSAXHandlerPtr debugSAXHandler;
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
* Debug Handlers *
|
||||
* *
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* isStandaloneDebug:
|
||||
* @ctxt: An XML parser context
|
||||
*
|
||||
* Is this document tagged standalone ?
|
||||
*
|
||||
* Returns 1 if true
|
||||
*/
|
||||
static int
|
||||
isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED)
|
||||
{
|
||||
fprintf(stdout, "SAX.isStandalone()\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* hasInternalSubsetDebug:
|
||||
* @ctxt: An XML parser context
|
||||
*
|
||||
* Does this document has an internal subset
|
||||
*
|
||||
* Returns 1 if true
|
||||
*/
|
||||
static int
|
||||
hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
|
||||
{
|
||||
fprintf(stdout, "SAX.hasInternalSubset()\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* hasExternalSubsetDebug:
|
||||
* @ctxt: An XML parser context
|
||||
*
|
||||
* Does this document has an external subset
|
||||
*
|
||||
* Returns 1 if true
|
||||
*/
|
||||
static int
|
||||
hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED)
|
||||
{
|
||||
fprintf(stdout, "SAX.hasExternalSubset()\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* hasInternalSubsetDebug:
|
||||
* @ctxt: An XML parser context
|
||||
*
|
||||
* Does this document has an internal subset
|
||||
*/
|
||||
static void
|
||||
internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
|
||||
const xmlChar *ExternalID, const xmlChar *SystemID)
|
||||
{
|
||||
fprintf(stdout, "SAX.internalSubset(%s,", name);
|
||||
if (ExternalID == NULL)
|
||||
fprintf(stdout, " ,");
|
||||
else
|
||||
fprintf(stdout, " %s,", ExternalID);
|
||||
if (SystemID == NULL)
|
||||
fprintf(stdout, " )\n");
|
||||
else
|
||||
fprintf(stdout, " %s)\n", SystemID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xmlChar *systemId)
|
||||
{
|
||||
/* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
|
||||
|
||||
|
||||
fprintf(stdout, "SAX.resolveEntity(");
|
||||
if (publicId != NULL)
|
||||
fprintf(stdout, "%s", (char *)publicId);
|
||||
else
|
||||
fprintf(stdout, " ");
|
||||
if (systemId != NULL)
|
||||
fprintf(stdout, ", %s)\n", (char *)systemId);
|
||||
else
|
||||
fprintf(stdout, ", )\n");
|
||||
/*********
|
||||
if (systemId != NULL) {
|
||||
return(xmlNewInputFromFile(ctxt, (char *) systemId));
|
||||
}
|
||||
*********/
|
||||
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
|
||||
getEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
|
||||
{
|
||||
fprintf(stdout, "SAX.getEntity(%s)\n", name);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* getParameterEntityDebug:
|
||||
* @ctxt: An XML parser context
|
||||
* @name: The entity name
|
||||
*
|
||||
* Get a parameter entity by name
|
||||
*
|
||||
* Returns the xmlParserInputPtr
|
||||
*/
|
||||
static xmlEntityPtr
|
||||
getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
|
||||
{
|
||||
fprintf(stdout, "SAX.getParameterEntity(%s)\n", name);
|
||||
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
|
||||
entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
|
||||
const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
|
||||
{
|
||||
fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n",
|
||||
name, type, publicId, systemId, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* attributeDeclDebug:
|
||||
* @ctxt: An XML parser context
|
||||
* @name: the attribute name
|
||||
* @type: the attribute type
|
||||
*
|
||||
* An attribute definition has been parsed
|
||||
*/
|
||||
static void
|
||||
attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *elem,
|
||||
const xmlChar *name, int type, int def,
|
||||
const xmlChar *defaultValue,
|
||||
xmlEnumerationPtr tree ATTRIBUTE_UNUSED)
|
||||
{
|
||||
fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n",
|
||||
elem, name, type, def, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type,
|
||||
xmlElementContentPtr content ATTRIBUTE_UNUSED)
|
||||
{
|
||||
fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n",
|
||||
name, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
notationDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
|
||||
const xmlChar *publicId, const xmlChar *systemId)
|
||||
{
|
||||
fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n",
|
||||
(char *) name, (char *) publicId, (char *) systemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
|
||||
const xmlChar *publicId, const xmlChar *systemId,
|
||||
const xmlChar *notationName)
|
||||
{
|
||||
fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
|
||||
(char *) name, (char *) publicId, (char *) systemId,
|
||||
(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
|
||||
setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED,
|
||||
xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
|
||||
{
|
||||
fprintf(stdout, "SAX.setDocumentLocator()\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* startDocumentDebug:
|
||||
* @ctxt: An XML parser context
|
||||
*
|
||||
* called when the document start being processed.
|
||||
*/
|
||||
static void
|
||||
startDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
|
||||
{
|
||||
fprintf(stdout, "SAX.startDocument()\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* endDocumentDebug:
|
||||
* @ctxt: An XML parser context
|
||||
*
|
||||
* called when the document end has been detected.
|
||||
*/
|
||||
static void
|
||||
endDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
|
||||
{
|
||||
fprintf(stdout, "SAX.endDocument()\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* startElementDebug:
|
||||
* @ctxt: An XML parser context
|
||||
* @name: The element name
|
||||
*
|
||||
* called when an opening tag has been processed.
|
||||
*/
|
||||
static void
|
||||
startElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, const xmlChar **atts)
|
||||
{
|
||||
int i;
|
||||
|
||||
fprintf(stdout, "SAX.startElement(%s", (char *) name);
|
||||
if (atts != NULL) {
|
||||
for (i = 0;(atts[i] != NULL);i++) {
|
||||
fprintf(stdout, ", %s", atts[i++]);
|
||||
if (atts[i] != NULL) {
|
||||
unsigned char output[40];
|
||||
const unsigned char *att = atts[i];
|
||||
int outlen, attlen;
|
||||
fprintf(stdout, "='");
|
||||
while ((attlen = strlen((char*)att)) > 0) {
|
||||
outlen = sizeof output - 1;
|
||||
docbEncodeEntities(output, &outlen, att, &attlen, '\'');
|
||||
fprintf(stdout, "%.*s", outlen, output);
|
||||
att += attlen;
|
||||
}
|
||||
fprintf(stdout, "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
fprintf(stdout, ")\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* endElementDebug:
|
||||
* @ctxt: An XML parser context
|
||||
* @name: The element name
|
||||
*
|
||||
* called when the end of an element has been detected.
|
||||
*/
|
||||
static void
|
||||
endElementDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
|
||||
{
|
||||
fprintf(stdout, "SAX.endElement(%s)\n", (char *) name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
charactersDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
|
||||
{
|
||||
unsigned char output[40];
|
||||
int inlen = len, outlen = 30;
|
||||
|
||||
docbEncodeEntities(output, &outlen, ch, &inlen, 0);
|
||||
output[outlen] = 0;
|
||||
|
||||
fprintf(stdout, "SAX.characters(%s, %d)\n", output, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* referenceDebug:
|
||||
* @ctxt: An XML parser context
|
||||
* @name: The entity name
|
||||
*
|
||||
* called when an entity reference is detected.
|
||||
*/
|
||||
static void
|
||||
referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
|
||||
{
|
||||
fprintf(stdout, "SAX.reference(%s)\n", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
|
||||
{
|
||||
char output[40];
|
||||
int i;
|
||||
|
||||
for (i = 0;(i<len) && (i < 30);i++)
|
||||
output[i] = ch[i];
|
||||
output[i] = 0;
|
||||
|
||||
fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target,
|
||||
const xmlChar *data)
|
||||
{
|
||||
fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",
|
||||
(char *) target, (char *) data);
|
||||
}
|
||||
|
||||
/**
|
||||
* commentDebug:
|
||||
* @ctxt: An XML parser context
|
||||
* @value: the comment content
|
||||
*
|
||||
* A comment has been parsed.
|
||||
*/
|
||||
static void
|
||||
commentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value)
|
||||
{
|
||||
fprintf(stdout, "SAX.comment(%s)\n", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value, int len)
|
||||
{
|
||||
fprintf(stdout, "SAX.pcdata(%.20s, %d)\n",
|
||||
(char *) value, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* externalSubsetDebug:
|
||||
* @ctxt: An XML parser context
|
||||
*
|
||||
* Does this document has an external subset
|
||||
*/
|
||||
static void
|
||||
externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name,
|
||||
const xmlChar *ExternalID, const xmlChar *SystemID)
|
||||
{
|
||||
fprintf(stdout, "SAX.externalSubset(%s,", name);
|
||||
if (ExternalID == NULL)
|
||||
fprintf(stdout, " ,");
|
||||
else
|
||||
fprintf(stdout, " %s,", ExternalID);
|
||||
if (SystemID == NULL)
|
||||
fprintf(stdout, " )\n");
|
||||
else
|
||||
fprintf(stdout, " %s)\n", SystemID);
|
||||
}
|
||||
|
||||
/**
|
||||
* warningDebug:
|
||||
* @ctxt: 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.
|
||||
*/
|
||||
static void
|
||||
warningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, msg);
|
||||
fprintf(stdout, "SAX.warning: ");
|
||||
vfprintf(stdout, msg, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* errorDebug:
|
||||
* @ctxt: An XML parser context
|
||||
* @msg: the message to display/transmit
|
||||
* @...: extra parameters for the message display
|
||||
*
|
||||
* Display and format a error messages, gives file, line, position and
|
||||
* extra parameters.
|
||||
*/
|
||||
static void
|
||||
errorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, msg);
|
||||
fprintf(stdout, "SAX.error: ");
|
||||
vfprintf(stdout, msg, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* fatalErrorDebug:
|
||||
* @ctxt: An XML parser context
|
||||
* @msg: the message to display/transmit
|
||||
* @...: extra parameters for the message display
|
||||
*
|
||||
* Display and format a fatalError messages, gives file, line, position and
|
||||
* extra parameters.
|
||||
*/
|
||||
static void
|
||||
fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, msg);
|
||||
fprintf(stdout, "SAX.fatalError: ");
|
||||
vfprintf(stdout, msg, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
xmlSAXHandler debugSAXHandlerStruct = {
|
||||
internalSubsetDebug,
|
||||
isStandaloneDebug,
|
||||
hasInternalSubsetDebug,
|
||||
hasExternalSubsetDebug,
|
||||
resolveEntityDebug,
|
||||
getEntityDebug,
|
||||
entityDeclDebug,
|
||||
notationDeclDebug,
|
||||
attributeDeclDebug,
|
||||
elementDeclDebug,
|
||||
unparsedEntityDeclDebug,
|
||||
setDocumentLocatorDebug,
|
||||
startDocumentDebug,
|
||||
endDocumentDebug,
|
||||
startElementDebug,
|
||||
endElementDebug,
|
||||
referenceDebug,
|
||||
charactersDebug,
|
||||
ignorableWhitespaceDebug,
|
||||
processingInstructionDebug,
|
||||
commentDebug,
|
||||
warningDebug,
|
||||
errorDebug,
|
||||
fatalErrorDebug,
|
||||
getParameterEntityDebug,
|
||||
cdataBlockDebug,
|
||||
externalSubsetDebug
|
||||
};
|
||||
|
||||
xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
|
||||
/************************************************************************
|
||||
* *
|
||||
* Debug *
|
||||
* *
|
||||
************************************************************************/
|
||||
|
||||
static void
|
||||
parseSAXFile(char *filename) {
|
||||
docbDocPtr doc = NULL;
|
||||
|
||||
/*
|
||||
* Empty callbacks for checking
|
||||
*/
|
||||
if (push) {
|
||||
FILE *f;
|
||||
|
||||
f = fopen(filename, "r");
|
||||
if (f != NULL) {
|
||||
int res, size = 3;
|
||||
char chars[4096];
|
||||
docbParserCtxtPtr ctxt;
|
||||
|
||||
/* if (repeat) */
|
||||
size = 4096;
|
||||
res = fread(chars, 1, 4, f);
|
||||
if (res > 0) {
|
||||
ctxt = docbCreatePushParserCtxt(emptySAXHandler, NULL,
|
||||
chars, res, filename, 0);
|
||||
while ((res = fread(chars, 1, size, f)) > 0) {
|
||||
docbParseChunk(ctxt, chars, res, 0);
|
||||
}
|
||||
docbParseChunk(ctxt, chars, 0, 1);
|
||||
doc = ctxt->myDoc;
|
||||
docbFreeParserCtxt(ctxt);
|
||||
}
|
||||
if (doc != NULL) {
|
||||
fprintf(stdout, "sgmlSAXParseFile returned non-NULL\n");
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
if (!noout) {
|
||||
f = fopen(filename, "r");
|
||||
if (f != NULL) {
|
||||
int res, size = 3;
|
||||
char chars[4096];
|
||||
docbParserCtxtPtr ctxt;
|
||||
|
||||
/* if (repeat) */
|
||||
size = 4096;
|
||||
res = fread(chars, 1, 4, f);
|
||||
if (res > 0) {
|
||||
ctxt = docbCreatePushParserCtxt(debugSAXHandler, NULL,
|
||||
chars, res, filename, 0);
|
||||
while ((res = fread(chars, 1, size, f)) > 0) {
|
||||
docbParseChunk(ctxt, chars, res, 0);
|
||||
}
|
||||
docbParseChunk(ctxt, chars, 0, 1);
|
||||
doc = ctxt->myDoc;
|
||||
docbFreeParserCtxt(ctxt);
|
||||
}
|
||||
if (doc != NULL) {
|
||||
fprintf(stdout, "sgmlSAXParseFile returned non-NULL\n");
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
doc = docbSAXParseFile(filename, NULL, emptySAXHandler, NULL);
|
||||
if (doc != NULL) {
|
||||
fprintf(stdout, "sgmlSAXParseFile returned non-NULL\n");
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
|
||||
if (!noout) {
|
||||
/*
|
||||
* Debug callback
|
||||
*/
|
||||
doc = docbSAXParseFile(filename, NULL, debugSAXHandler, NULL);
|
||||
if (doc != NULL) {
|
||||
fprintf(stdout, "sgmlSAXParseFile returned non-NULL\n");
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
parseAndPrintFile(char *filename) {
|
||||
docbDocPtr doc = NULL, tmp;
|
||||
|
||||
/*
|
||||
* build an SGML tree from a string;
|
||||
*/
|
||||
if (push) {
|
||||
FILE *f;
|
||||
|
||||
f = fopen(filename, "r");
|
||||
if (f != NULL) {
|
||||
int res, size = 3;
|
||||
char chars[4096];
|
||||
docbParserCtxtPtr ctxt;
|
||||
|
||||
/* if (repeat) */
|
||||
size = 4096;
|
||||
res = fread(chars, 1, 4, f);
|
||||
if (res > 0) {
|
||||
ctxt = docbCreatePushParserCtxt(NULL, NULL,
|
||||
chars, res, filename, 0);
|
||||
while ((res = fread(chars, 1, size, f)) > 0) {
|
||||
docbParseChunk(ctxt, chars, res, 0);
|
||||
}
|
||||
docbParseChunk(ctxt, chars, 0, 1);
|
||||
doc = ctxt->myDoc;
|
||||
docbFreeParserCtxt(ctxt);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
} else {
|
||||
doc = docbParseFile(filename, NULL);
|
||||
}
|
||||
if (doc == NULL) {
|
||||
fprintf(stderr, "Could not parse %s\n", filename);
|
||||
}
|
||||
|
||||
/*
|
||||
* test intermediate copy if needed.
|
||||
*/
|
||||
if (copy) {
|
||||
tmp = doc;
|
||||
doc = xmlCopyDoc(doc, 1);
|
||||
xmlFreeDoc(tmp);
|
||||
}
|
||||
|
||||
/*
|
||||
* print it.
|
||||
*/
|
||||
if (!noout) {
|
||||
#ifdef LIBXML_DEBUG_ENABLED
|
||||
if (!debug) {
|
||||
if (encoding)
|
||||
xmlSaveFileEnc("-", doc, encoding);
|
||||
else
|
||||
xmlDocDump(stdout, doc);
|
||||
} else
|
||||
xmlDebugDumpDocument(stdout, doc);
|
||||
#else
|
||||
if (encoding)
|
||||
xmlSaveFileEnc("-", doc, encoding);
|
||||
else
|
||||
xmlDocDump(stdout, doc);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* free it.
|
||||
*/
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i, count;
|
||||
int files = 0;
|
||||
|
||||
for (i = 1; i < argc ; i++) {
|
||||
#ifdef LIBXML_DEBUG_ENABLED
|
||||
if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
|
||||
debug++;
|
||||
else
|
||||
#endif
|
||||
if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
|
||||
copy++;
|
||||
else if ((!strcmp(argv[i], "-push")) || (!strcmp(argv[i], "--push")))
|
||||
push++;
|
||||
else if ((!strcmp(argv[i], "-sax")) || (!strcmp(argv[i], "--sax")))
|
||||
sax++;
|
||||
else if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout")))
|
||||
noout++;
|
||||
else if ((!strcmp(argv[i], "-repeat")) ||
|
||||
(!strcmp(argv[i], "--repeat")))
|
||||
repeat++;
|
||||
else if ((!strcmp(argv[i], "-encode")) ||
|
||||
(!strcmp(argv[i], "--encode"))) {
|
||||
i++;
|
||||
encoding = argv[i];
|
||||
}
|
||||
}
|
||||
for (i = 1; i < argc ; i++) {
|
||||
if ((!strcmp(argv[i], "-encode")) ||
|
||||
(!strcmp(argv[i], "--encode"))) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (argv[i][0] != '-') {
|
||||
if (repeat) {
|
||||
for (count = 0;count < 100 * repeat;count++) {
|
||||
if (sax)
|
||||
parseSAXFile(argv[i]);
|
||||
else
|
||||
parseAndPrintFile(argv[i]);
|
||||
}
|
||||
} else {
|
||||
if (sax)
|
||||
parseSAXFile(argv[i]);
|
||||
else
|
||||
parseAndPrintFile(argv[i]);
|
||||
}
|
||||
files ++;
|
||||
}
|
||||
}
|
||||
if (files == 0) {
|
||||
printf("Usage : %s [--debug] [--copy] [--copy] SGMLfiles ...\n",
|
||||
argv[0]);
|
||||
printf("\tParse the Docbook files and output the result of the parsing\n");
|
||||
#ifdef LIBXML_DEBUG_ENABLED
|
||||
printf("\t--debug : dump a debug tree of the in-memory document\n");
|
||||
#endif
|
||||
printf("\t--copy : used to test the internal copy implementation\n");
|
||||
printf("\t--sax : debug the sequence of SAX callbacks\n");
|
||||
printf("\t--repeat : parse the file 100 times, for timing\n");
|
||||
printf("\t--noout : do not print the result\n");
|
||||
printf("\t--push : use the push mode parser\n");
|
||||
printf("\t--encode encoding : output in the given encoding\n");
|
||||
}
|
||||
xmlCleanupParser();
|
||||
xmlMemoryDump();
|
||||
|
||||
return(0);
|
||||
}
|
||||
#else /* !LIBXML_DOCB_ENABLED */
|
||||
#include <stdio.h>
|
||||
int main(int argc, char **argv) {
|
||||
printf("%s : SGML support not compiled in\n", argv[0]);
|
||||
return(0);
|
||||
}
|
||||
#endif
|
32
tree.c
32
tree.c
@ -2952,8 +2952,8 @@ xmlNodeSetLang(xmlNodePtr cur, const xmlChar *lang) {
|
||||
case XML_ENTITY_REF_NODE:
|
||||
case XML_ENTITY_NODE:
|
||||
case XML_NAMESPACE_DECL:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
case XML_XINCLUDE_START:
|
||||
case XML_XINCLUDE_END:
|
||||
@ -3019,8 +3019,8 @@ xmlNodeSetSpacePreserve(xmlNodePtr cur, int val) {
|
||||
case XML_NAMESPACE_DECL:
|
||||
case XML_XINCLUDE_START:
|
||||
case XML_XINCLUDE_END:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
return;
|
||||
case XML_ELEMENT_NODE:
|
||||
@ -3092,8 +3092,8 @@ xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) {
|
||||
case XML_NAMESPACE_DECL:
|
||||
case XML_XINCLUDE_START:
|
||||
case XML_XINCLUDE_END:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
return;
|
||||
case XML_ELEMENT_NODE:
|
||||
@ -3142,8 +3142,8 @@ xmlNodeSetBase(xmlNodePtr cur, xmlChar* uri) {
|
||||
case XML_NAMESPACE_DECL:
|
||||
case XML_XINCLUDE_START:
|
||||
case XML_XINCLUDE_END:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
return;
|
||||
case XML_ELEMENT_NODE:
|
||||
@ -3327,8 +3327,8 @@ xmlNodeGetContent(xmlNodePtr cur) {
|
||||
case XML_DTD_NODE:
|
||||
case XML_XINCLUDE_START:
|
||||
case XML_XINCLUDE_END:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
return(NULL);
|
||||
case XML_NAMESPACE_DECL:
|
||||
@ -3420,8 +3420,8 @@ xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) {
|
||||
case XML_DOCUMENT_TYPE_NODE:
|
||||
case XML_XINCLUDE_START:
|
||||
case XML_XINCLUDE_END:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
break;
|
||||
case XML_NOTATION_NODE:
|
||||
@ -3511,8 +3511,8 @@ xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, int len) {
|
||||
case XML_NAMESPACE_DECL:
|
||||
case XML_XINCLUDE_START:
|
||||
case XML_XINCLUDE_END:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
break;
|
||||
case XML_ELEMENT_DECL:
|
||||
@ -3602,8 +3602,8 @@ xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, int len) {
|
||||
case XML_NAMESPACE_DECL:
|
||||
case XML_XINCLUDE_START:
|
||||
case XML_XINCLUDE_END:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
break;
|
||||
case XML_ELEMENT_DECL:
|
||||
|
4
tree.h
4
tree.h
@ -54,8 +54,8 @@ typedef enum {
|
||||
XML_NAMESPACE_DECL= 18,
|
||||
XML_XINCLUDE_START= 19,
|
||||
XML_XINCLUDE_END= 20
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
,XML_SGML_DOCUMENT_NODE= 21
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
,XML_DOCB_DOCUMENT_NODE= 21
|
||||
#endif
|
||||
} xmlElementType;
|
||||
|
||||
|
67
valid.c
67
valid.c
@ -3601,8 +3601,8 @@ xmlSprintfElements(char *buf, xmlNodePtr node, int glob) {
|
||||
break;
|
||||
case XML_ATTRIBUTE_NODE:
|
||||
case XML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
case XML_HTML_DOCUMENT_NODE:
|
||||
case XML_DOCUMENT_TYPE_NODE:
|
||||
@ -3792,69 +3792,6 @@ done:
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSprintfElementChilds:
|
||||
* @buf: an output buffer
|
||||
* @content: An element
|
||||
* @glob: 1 if one must print the englobing parenthesis, 0 otherwise
|
||||
*
|
||||
* This will dump the list of childs to the buffer
|
||||
* Intended just for the debug routine
|
||||
*/
|
||||
static void
|
||||
xmlSprintfElementChilds(char *buf, xmlNodePtr node, int glob) {
|
||||
xmlNodePtr cur;
|
||||
|
||||
if (node == NULL) return;
|
||||
if (glob) strcat(buf, "(");
|
||||
cur = node->children;
|
||||
while (cur != NULL) {
|
||||
switch (cur->type) {
|
||||
case XML_ELEMENT_NODE:
|
||||
strcat(buf, (char *) cur->name);
|
||||
if (cur->next != NULL)
|
||||
strcat(buf, " ");
|
||||
break;
|
||||
case XML_TEXT_NODE:
|
||||
if (xmlIsBlankNode(cur))
|
||||
break;
|
||||
case XML_CDATA_SECTION_NODE:
|
||||
case XML_ENTITY_REF_NODE:
|
||||
strcat(buf, "CDATA");
|
||||
if (cur->next != NULL)
|
||||
strcat(buf, " ");
|
||||
break;
|
||||
case XML_ATTRIBUTE_NODE:
|
||||
case XML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#endif
|
||||
case XML_HTML_DOCUMENT_NODE:
|
||||
case XML_DOCUMENT_TYPE_NODE:
|
||||
case XML_DOCUMENT_FRAG_NODE:
|
||||
case XML_NOTATION_NODE:
|
||||
case XML_NAMESPACE_DECL:
|
||||
strcat(buf, "???");
|
||||
if (cur->next != NULL)
|
||||
strcat(buf, " ");
|
||||
break;
|
||||
case XML_ENTITY_NODE:
|
||||
case XML_PI_NODE:
|
||||
case XML_DTD_NODE:
|
||||
case XML_COMMENT_NODE:
|
||||
case XML_ELEMENT_DECL:
|
||||
case XML_ATTRIBUTE_DECL:
|
||||
case XML_ENTITY_DECL:
|
||||
case XML_XINCLUDE_START:
|
||||
case XML_XINCLUDE_END:
|
||||
break;
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
if (glob) strcat(buf, ")");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* xmlValidateOneElement:
|
||||
* @ctxt: the validation context
|
||||
|
@ -62,13 +62,13 @@ extern void xmlCheckVersion(int version);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Whether the Docbook support is configured in
|
||||
#if @WITH_SGML@
|
||||
#define LIBXML_SGML_ENABLED
|
||||
#else
|
||||
#define LIBXML_SGML_DISABLED
|
||||
#endif
|
||||
* Whether the SGML Docbook support is configured in
|
||||
*/
|
||||
#if @WITH_DOCB@
|
||||
#define LIBXML_DOCB_ENABLED
|
||||
#else
|
||||
#define LIBXML_DOCB_DISABLED
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Whether XPath is configured in
|
||||
|
16
xpath.c
16
xpath.c
@ -3244,8 +3244,8 @@ xmlXPathNextChild(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
|
||||
case XML_DOCUMENT_TYPE_NODE:
|
||||
case XML_DOCUMENT_FRAG_NODE:
|
||||
case XML_HTML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
return(((xmlDocPtr) ctxt->context->node)->children);
|
||||
case XML_ELEMENT_DECL:
|
||||
@ -3382,8 +3382,8 @@ xmlXPathNextParent(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
|
||||
case XML_DOCUMENT_TYPE_NODE:
|
||||
case XML_DOCUMENT_FRAG_NODE:
|
||||
case XML_HTML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
return(NULL);
|
||||
case XML_NAMESPACE_DECL:
|
||||
@ -3448,8 +3448,8 @@ xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
|
||||
case XML_DOCUMENT_TYPE_NODE:
|
||||
case XML_DOCUMENT_FRAG_NODE:
|
||||
case XML_HTML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
return(NULL);
|
||||
case XML_NAMESPACE_DECL:
|
||||
@ -3491,8 +3491,8 @@ xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
|
||||
case XML_DOCUMENT_TYPE_NODE:
|
||||
case XML_DOCUMENT_FRAG_NODE:
|
||||
case XML_HTML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_SGML_ENABLED
|
||||
case XML_SGML_DOCUMENT_NODE:
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
case XML_DOCB_DOCUMENT_NODE:
|
||||
#endif
|
||||
return(NULL);
|
||||
case XML_NAMESPACE_DECL:
|
||||
|
Loading…
x
Reference in New Issue
Block a user