1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-25 23:21:26 +03:00

removing the broken pseudo SGML DocBook parser code. Daniel

* Makefile.am DOCBparser.c parserInternals.c testDocbook.c
  xmllint.c doc/xmllint.xml doc/xmllint.1: removing the
  broken pseudo SGML DocBook parser code.
Daniel
This commit is contained in:
Daniel Veillard 2003-09-13 00:16:32 +00:00
parent 5dd3c9622a
commit 877a7bd6a3
9 changed files with 237 additions and 7371 deletions

View File

@ -1,3 +1,9 @@
Sat Sep 13 02:13:50 CEST 2003 Daniel Veillard <daniel@veillard.com>
* Makefile.am DOCBparser.c parserInternals.c testDocbook.c
xmllint.c doc/xmllint.xml doc/xmllint.1: removing the
broken pseudo SGML DocBook parser code.
Fri Sep 12 17:24:11 CEST 2003 Daniel Veillard <daniel@veillard.com>
* xpath.c: fix a problem with strcpy() in xmlXPathFormatNumber()

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ DIST_SUBDIRS = include . doc example python
INCLUDES = -I$(top_builddir)/include -I@srcdir@/include @THREAD_CFLAGS@ @Z_CFLAGS@
noinst_PROGRAMS=testSchemas testRelax testSAX testHTML testXPath testURI \
testDocbook testThreads testC14N testAutomata testRegexp \
testThreads testC14N testAutomata testRegexp \
testReader
bin_PROGRAMS = xmllint xmlcatalog
@ -61,11 +61,6 @@ testHTML_LDFLAGS =
testHTML_DEPENDENCIES = $(DEPS)
testHTML_LDADD= $(LDADDS)
testDocbook_SOURCES=testDocbook.c
testDocbook_LDFLAGS =
testDocbook_DEPENDENCIES = $(DEPS)
testDocbook_LDADD= $(LDADDS)
xmlcatalog_SOURCES=xmlcatalog.c
xmlcatalog_LDFLAGS =
xmlcatalog_DEPENDENCIES = $(DEPS)

View File

@ -27,7 +27,7 @@ xmllint \- command line XML tool
\fB--copy\fR | \fB--recover\fR | \fB--noent\fR | \fB--noout\fR | \fB--htmlout\fR
| \fB--nowrap\fR | \fB--valid\fR | \fB--postvalid\fR | \fB--dtdvalid
\fIURL\fR\fR | \fB--dtdvalidfpi \fIFPI\fR\fR | \fB--timing\fR | \fB--repeat\fR
| \fB--insert\fR | \fB--compress\fR | \fB--sgml\fR | \fB--html\fR | \fB--push\fR | \fB--memory\fR | \fB--nowarning\fR | \fB--noblanks\fR | \fB--format\fR | \fB--testIO\fR | \fB--encode \fIencoding\fR\fR | \fB--catalogs\fR | \fB--nocatalogs\fR | \fB--auto\fR | \fB--xinclude\fR | \fB--loaddtd\fR | \fB--dtdattr\fR | \fB--dropdtd\fR | \fB--stream\fR | \fB--chkregister\fR | \fB--relaxng\fR | \fB--schema\fR | \fB--nonet\fR] [\fBxmlfile\fR]
| \fB--insert\fR | \fB--compress\fR | \fB--html\fR | \fB--push\fR | \fB--memory\fR | \fB--nowarning\fR | \fB--noblanks\fR | \fB--format\fR | \fB--testIO\fR | \fB--encode \fIencoding\fR\fR | \fB--catalogs\fR | \fB--nocatalogs\fR | \fB--auto\fR | \fB--xinclude\fR | \fB--loaddtd\fR | \fB--dtdattr\fR | \fB--dropdtd\fR | \fB--stream\fR | \fB--chkregister\fR | \fB--relaxng\fR | \fB--schema\fR | \fB--nonet\fR] [\fBxmlfile\fR]
.fi
@ -113,10 +113,6 @@ Test for valid insertions.
\fB--compress\fR
Turn on gzip compression of output.
.TP
\fB--sgml\fR
Use the DocBook SGML parser. This allows documents written in SGML DocBook to be converted into an in-memory tree and treated as if they were written in XML.
.TP
\fB--html\fR
Use the HTML parser.

View File

@ -61,7 +61,6 @@
<arg>--repeat</arg>
<arg>--insert</arg>
<arg>--compress</arg>
<arg>--sgml</arg>
<arg>--html</arg>
<arg>--push</arg>
<arg>--memory</arg>
@ -288,16 +287,6 @@
</listitem>
</varlistentry>
<varlistentry>
<term><option>--sgml</option></term>
<listitem>
<simpara>Use the DocBook <acronym>SGML</acronym> parser. This allows
documents written in <acronym>SGML</acronym> DocBook to be converted
into an in-memory tree and treated as if they were written in
<acronym>XML</acronym>.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--html</option></term>
<listitem>

View File

@ -11,6 +11,9 @@
#include <libxml/xmlversion.h>
#include <libxml/parser.h>
#ifndef IN_LIBXML
#warning "The DOCBparser module has been deprecated in libxml2-2.6.0"
#else
#ifdef __cplusplus
extern "C" {
#endif
@ -20,13 +23,11 @@ extern "C" {
*/
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.
@ -80,5 +81,6 @@ XMLPUBFUN int XMLCALL
#ifdef __cplusplus
}
#endif
#endif /* IN_LIBXML */
#endif /* __DOCB_PARSER_H__ */

View File

@ -1052,10 +1052,6 @@ xmlParserInputShrink(xmlParserInputPtr in) {
* Do not shrink on large buffers whose only a tiny fraction
* was consumed
*/
#if 0
if ((int) in->buf->buffer->use > used + 2 * INPUT_CHUNK)
return;
#endif
if (used > INPUT_CHUNK) {
ret = xmlBufferShrink(in->buf->buffer, used - LINE_LEN);
if (ret > 0) {
@ -2714,56 +2710,57 @@ xmlKeepBlanksDefault(int val) {
* Returns 1 if correct 0 otherwise
**/
int
xmlCheckLanguageID(const xmlChar *lang) {
xmlCheckLanguageID(const xmlChar * lang)
{
const xmlChar *cur = lang;
if (cur == NULL)
return(0);
return (0);
if (((cur[0] == 'i') && (cur[1] == '-')) ||
((cur[0] == 'I') && (cur[1] == '-'))) {
/*
* IANA code
*/
cur += 2;
while (((cur[0] >= 'A') && (cur[0] <= 'Z')) || /* non input consuming */
((cur[0] >= 'a') && (cur[0] <= 'z')))
cur++;
((cur[0] == 'I') && (cur[1] == '-'))) {
/*
* IANA code
*/
cur += 2;
while (((cur[0] >= 'A') && (cur[0] <= 'Z')) || /* non input consuming */
((cur[0] >= 'a') && (cur[0] <= 'z')))
cur++;
} else if (((cur[0] == 'x') && (cur[1] == '-')) ||
((cur[0] == 'X') && (cur[1] == '-'))) {
/*
* User code
*/
cur += 2;
while (((cur[0] >= 'A') && (cur[0] <= 'Z')) || /* non input consuming */
((cur[0] >= 'a') && (cur[0] <= 'z')))
cur++;
((cur[0] == 'X') && (cur[1] == '-'))) {
/*
* User code
*/
cur += 2;
while (((cur[0] >= 'A') && (cur[0] <= 'Z')) || /* non input consuming */
((cur[0] >= 'a') && (cur[0] <= 'z')))
cur++;
} else if (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||
((cur[0] >= 'a') && (cur[0] <= 'z'))) {
/*
* ISO639
*/
cur++;
((cur[0] >= 'a') && (cur[0] <= 'z'))) {
/*
* ISO639
*/
cur++;
if (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||
((cur[0] >= 'a') && (cur[0] <= 'z')))
cur++;
else
return(0);
((cur[0] >= 'a') && (cur[0] <= 'z')))
cur++;
else
return (0);
} else
return(0);
while (cur[0] != 0) { /* non input consuming */
if (cur[0] != '-')
return(0);
cur++;
return (0);
while (cur[0] != 0) { /* non input consuming */
if (cur[0] != '-')
return (0);
cur++;
if (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||
((cur[0] >= 'a') && (cur[0] <= 'z')))
cur++;
else
return(0);
while (((cur[0] >= 'A') && (cur[0] <= 'Z')) || /* non input consuming */
((cur[0] >= 'a') && (cur[0] <= 'z')))
cur++;
((cur[0] >= 'a') && (cur[0] <= 'z')))
cur++;
else
return (0);
while (((cur[0] >= 'A') && (cur[0] <= 'Z')) || /* non input consuming */
((cur[0] >= 'a') && (cur[0] <= 'z')))
cur++;
}
return(1);
return (1);
}
/**
@ -2788,121 +2785,20 @@ xmlCheckLanguageID(const xmlChar *lang) {
* must deallocate it !
*/
xmlChar *
xmlDecodeEntities(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED, int what ATTRIBUTE_UNUSED,
xmlChar end ATTRIBUTE_UNUSED, xmlChar end2 ATTRIBUTE_UNUSED, xmlChar end3 ATTRIBUTE_UNUSED) {
#if 0
xmlChar *buffer = NULL;
unsigned int buffer_size = 0;
unsigned int nbchars = 0;
xmlChar *current = NULL;
xmlEntityPtr ent;
unsigned int max = (unsigned int) len;
int c,l;
#endif
xmlDecodeEntities(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
int len ATTRIBUTE_UNUSED, int what ATTRIBUTE_UNUSED,
xmlChar end ATTRIBUTE_UNUSED,
xmlChar end2 ATTRIBUTE_UNUSED,
xmlChar end3 ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlDecodeEntities() deprecated function reached\n");
deprecated = 1;
xmlGenericError(xmlGenericErrorContext,
"xmlDecodeEntities() deprecated function reached\n");
deprecated = 1;
}
#if 0
if (ctxt->depth > 40) {
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"Detected entity reference loop\n");
ctxt->wellFormed = 0;
if (ctxt->recovery == 0) ctxt->disableSAX = 1;
ctxt->errNo = XML_ERR_ENTITY_LOOP;
return(NULL);
}
/*
* allocate a translation buffer.
*/
buffer_size = XML_PARSER_BIG_BUFFER_SIZE;
buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
if (buffer == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlDecodeEntities: malloc failed");
return(NULL);
}
/*
* OK loop until we reach one of the ending char or a size limit.
*/
GROW;
c = CUR_CHAR(l);
while ((nbchars < max) && (c != end) && /* NOTUSED */
(c != end2) && (c != end3)) {
GROW;
if (c == 0) break;
if ((c == '&') && (NXT(1) == '#')) {
int val = xmlParseCharRef(ctxt);
COPY_BUF(0,buffer,nbchars,val);
NEXTL(l);
} else if (c == '&') &&
(what & XML_SUBSTITUTE_REF)) {
if (xmlParserDebugEntities)
xmlGenericError(xmlGenericErrorContext,
"decoding Entity Reference\n");
ent = xmlParseEntityRef(ctxt);
if ((ent != NULL) &&
(ctxt->replaceEntities != 0)) {
current = ent->content;
while (*current != 0) { /* non input consuming loop */
buffer[nbchars++] = *current++;
if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) {
growBuffer(buffer);
}
}
} else if (ent != NULL) {
const xmlChar *cur = ent->name;
buffer[nbchars++] = '&';
if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) {
growBuffer(buffer);
}
while (*cur != 0) { /* non input consuming loop */
buffer[nbchars++] = *cur++;
}
buffer[nbchars++] = ';';
}
} else if (c == '%' && (what & XML_SUBSTITUTE_PEREF)) {
/*
* a PEReference induce to switch the entity flow,
* we break here to flush the current set of chars
* parsed if any. We will be called back later.
*/
if (xmlParserDebugEntities)
xmlGenericError(xmlGenericErrorContext,
"decoding PE Reference\n");
if (nbchars != 0) break;
xmlParsePEReference(ctxt);
/*
* Pop-up of finished entities.
*/
while ((RAW == 0) && (ctxt->inputNr > 1)) /* non input consuming */
xmlPopInput(ctxt);
break;
} else {
COPY_BUF(l,buffer,nbchars,c);
NEXTL(l);
if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) {
growBuffer(buffer);
}
}
c = CUR_CHAR(l);
}
buffer[nbchars++] = 0;
return(buffer);
#endif
return(NULL);
return (NULL);
}
/**
@ -2923,52 +2819,16 @@ xmlDecodeEntities(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUS
*/
xmlChar *
xmlNamespaceParseNCName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED) {
#if 0
xmlChar buf[XML_MAX_NAMELEN + 5];
int len = 0, l;
int cur = CUR_CHAR(l);
#endif
xmlNamespaceParseNCName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlNamespaceParseNCName() deprecated function reached\n");
deprecated = 1;
xmlGenericError(xmlGenericErrorContext,
"xmlNamespaceParseNCName() deprecated function reached\n");
deprecated = 1;
}
#if 0
/* load first the value of the char !!! */
GROW;
if (!IS_LETTER(cur) && (cur != '_')) return(NULL);
xmlGenericError(xmlGenericErrorContext,
"xmlNamespaceParseNCName: reached loop 3\n");
while ((IS_LETTER(cur)) || (IS_DIGIT(cur)) || /* NOT REACHED */
(cur == '.') || (cur == '-') ||
(cur == '_') ||
(IS_COMBINING(cur)) ||
(IS_EXTENDER(cur))) {
COPY_BUF(l,buf,len,cur);
NEXTL(l);
cur = CUR_CHAR(l);
if (len >= XML_MAX_NAMELEN) {
xmlGenericError(xmlGenericErrorContext,
"xmlNamespaceParseNCName: reached XML_MAX_NAMELEN limit\n");
while ((IS_LETTER(cur)) || (IS_DIGIT(cur)) ||/* NOT REACHED */
(cur == '.') || (cur == '-') ||
(cur == '_') ||
(IS_COMBINING(cur)) ||
(IS_EXTENDER(cur))) {
NEXTL(l);
cur = CUR_CHAR(l);
}
break;
}
}
return(xmlStrndup(buf, len));
#endif
return(NULL);
return (NULL);
}
/**
@ -2992,29 +2852,18 @@ xmlGenericError(xmlGenericErrorContext,
*/
xmlChar *
xmlNamespaceParseQName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlChar **prefix ATTRIBUTE_UNUSED) {
xmlNamespaceParseQName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
xmlChar ** prefix ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlNamespaceParseQName() deprecated function reached\n");
deprecated = 1;
xmlGenericError(xmlGenericErrorContext,
"xmlNamespaceParseQName() deprecated function reached\n");
deprecated = 1;
}
#if 0
xmlChar *ret = NULL;
*prefix = NULL;
ret = xmlNamespaceParseNCName(ctxt);
if (RAW == ':') {
*prefix = ret;
NEXT;
ret = xmlNamespaceParseNCName(ctxt);
}
return(ret);
#endif
return(NULL);
return (NULL);
}
/**
@ -3034,28 +2883,16 @@ xmlNamespaceParseQName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlChar **prefix
*/
xmlChar *
xmlNamespaceParseNSDef(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED) {
xmlNamespaceParseNSDef(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlNamespaceParseNSDef() deprecated function reached\n");
deprecated = 1;
}
return(NULL);
#if 0
xmlChar *name = NULL;
if ((RAW == 'x') && (NXT(1) == 'm') &&
(NXT(2) == 'l') && (NXT(3) == 'n') &&
(NXT(4) == 's')) {
SKIP(5);
if (RAW == ':') {
NEXT;
name = xmlNamespaceParseNCName(ctxt);
}
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlNamespaceParseNSDef() deprecated function reached\n");
deprecated = 1;
}
return(name);
#endif
return (NULL);
}
/**
@ -3069,86 +2906,16 @@ xmlNamespaceParseNSDef(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED) {
* Returns the string parser or NULL.
*/
xmlChar *
xmlParseQuotedString(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED) {
xmlParseQuotedString(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlParseQuotedString() deprecated function reached\n");
deprecated = 1;
xmlGenericError(xmlGenericErrorContext,
"xmlParseQuotedString() deprecated function reached\n");
deprecated = 1;
}
return(NULL);
#if 0
xmlChar *buf = NULL;
int len = 0,l;
int size = XML_PARSER_BUFFER_SIZE;
int c;
buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar));
if (buf == NULL) {
xmlGenericError(xmlGenericErrorContext,
"malloc of %d byte failed\n", size);
return(NULL);
}
xmlGenericError(xmlGenericErrorContext,
"xmlParseQuotedString: reached loop 4\n");
if (RAW == '"') {
NEXT;
c = CUR_CHAR(l);
while (IS_CHAR(c) && (c != '"')) { /* NOTUSED */
if (len + 5 >= size) {
size *= 2;
buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
if (buf == NULL) {
xmlGenericError(xmlGenericErrorContext,
"realloc of %d byte failed\n", size);
return(NULL);
}
}
COPY_BUF(l,buf,len,c);
NEXTL(l);
c = CUR_CHAR(l);
}
if (c != '"') {
ctxt->errNo = XML_ERR_STRING_NOT_CLOSED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"String not closed \"%.50s\"\n", buf);
ctxt->wellFormed = 0;
if (ctxt->recovery == 0) ctxt->disableSAX = 1;
} else {
NEXT;
}
} else if (RAW == '\''){
NEXT;
c = CUR;
while (IS_CHAR(c) && (c != '\'')) { /* NOTUSED */
if (len + 1 >= size) {
size *= 2;
buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
if (buf == NULL) {
xmlGenericError(xmlGenericErrorContext,
"realloc of %d byte failed\n", size);
return(NULL);
}
}
buf[len++] = c;
NEXT;
c = CUR;
}
if (RAW != '\'') {
ctxt->errNo = XML_ERR_STRING_NOT_CLOSED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"String not closed \"%.50s\"\n", buf);
ctxt->wellFormed = 0;
if (ctxt->recovery == 0) ctxt->disableSAX = 1;
} else {
NEXT;
}
}
return(buf);
#endif
return (NULL);
}
/**
@ -3167,110 +2934,15 @@ xmlGenericError(xmlGenericErrorContext,
*/
void
xmlParseNamespace(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED) {
xmlParseNamespace(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlParseNamespace() deprecated function reached\n");
deprecated = 1;
xmlGenericError(xmlGenericErrorContext,
"xmlParseNamespace() deprecated function reached\n");
deprecated = 1;
}
#if 0
xmlChar *href = NULL;
xmlChar *prefix = NULL;
int garbage = 0;
/*
* We just skipped "namespace" or "xml:namespace"
*/
SKIP_BLANKS;
xmlGenericError(xmlGenericErrorContext,
"xmlParseNamespace: reached loop 5\n");
while (IS_CHAR(RAW) && (RAW != '>')) { /* NOT REACHED */
/*
* We can have "ns" or "prefix" attributes
* Old encoding as 'href' or 'AS' attributes is still supported
*/
if ((RAW == 'n') && (NXT(1) == 's')) {
garbage = 0;
SKIP(2);
SKIP_BLANKS;
if (RAW != '=') continue;
NEXT;
SKIP_BLANKS;
href = xmlParseQuotedString(ctxt);
SKIP_BLANKS;
} else if ((RAW == 'h') && (NXT(1) == 'r') &&
(NXT(2) == 'e') && (NXT(3) == 'f')) {
garbage = 0;
SKIP(4);
SKIP_BLANKS;
if (RAW != '=') continue;
NEXT;
SKIP_BLANKS;
href = xmlParseQuotedString(ctxt);
SKIP_BLANKS;
} else if ((RAW == 'p') && (NXT(1) == 'r') &&
(NXT(2) == 'e') && (NXT(3) == 'f') &&
(NXT(4) == 'i') && (NXT(5) == 'x')) {
garbage = 0;
SKIP(6);
SKIP_BLANKS;
if (RAW != '=') continue;
NEXT;
SKIP_BLANKS;
prefix = xmlParseQuotedString(ctxt);
SKIP_BLANKS;
} else if ((RAW == 'A') && (NXT(1) == 'S')) {
garbage = 0;
SKIP(2);
SKIP_BLANKS;
if (RAW != '=') continue;
NEXT;
SKIP_BLANKS;
prefix = xmlParseQuotedString(ctxt);
SKIP_BLANKS;
} else if ((RAW == '?') && (NXT(1) == '>')) {
garbage = 0;
NEXT;
} else {
/*
* Found garbage when parsing the namespace
*/
if (!garbage) {
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"xmlParseNamespace found garbage\n");
}
ctxt->errNo = XML_ERR_NS_DECL_ERROR;
ctxt->wellFormed = 0;
if (ctxt->recovery == 0) ctxt->disableSAX = 1;
NEXT;
}
}
MOVETO_ENDTAG(CUR_PTR);
NEXT;
/*
* Register the DTD.
if (href != NULL)
if ((ctxt->sax != NULL) && (ctxt->sax->globalNamespace != NULL))
ctxt->sax->globalNamespace(ctxt->userData, href, prefix);
*/
if (prefix != NULL) xmlFree(prefix);
if (href != NULL) xmlFree(href);
#endif
}
/**
@ -3294,49 +2966,16 @@ xmlGenericError(xmlGenericErrorContext,
*/
xmlChar *
xmlScanName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED) {
xmlScanName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlScanName() deprecated function reached\n");
deprecated = 1;
xmlGenericError(xmlGenericErrorContext,
"xmlScanName() deprecated function reached\n");
deprecated = 1;
}
return(NULL);
#if 0
xmlChar buf[XML_MAX_NAMELEN];
int len = 0;
GROW;
if (!IS_LETTER(RAW) && (RAW != '_') &&
(RAW != ':')) {
return(NULL);
}
while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) || /* NOT REACHED */
(NXT(len) == '.') || (NXT(len) == '-') ||
(NXT(len) == '_') || (NXT(len) == ':') ||
(IS_COMBINING(NXT(len))) ||
(IS_EXTENDER(NXT(len)))) {
GROW;
buf[len] = NXT(len);
len++;
if (len >= XML_MAX_NAMELEN) {
xmlGenericError(xmlGenericErrorContext,
"xmlScanName: reached XML_MAX_NAMELEN limit\n");
while ((IS_LETTER(NXT(len))) || /* NOT REACHED */
(IS_DIGIT(NXT(len))) ||
(NXT(len) == '.') || (NXT(len) == '-') ||
(NXT(len) == '_') || (NXT(len) == ':') ||
(IS_COMBINING(NXT(len))) ||
(IS_EXTENDER(NXT(len))))
len++;
break;
}
}
return(xmlStrndup(buf, len));
#endif
return (NULL);
}
/**
@ -3367,12 +3006,14 @@ xmlScanName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED) {
* http://www.w3.org/TR/REC-xml#entproc
*/
void
xmlParserHandleReference(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED) {
xmlParserHandleReference(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlParserHandleReference() deprecated function reached\n");
deprecated = 1;
xmlGenericError(xmlGenericErrorContext,
"xmlParserHandleReference() deprecated function reached\n");
deprecated = 1;
}
return;
@ -3390,45 +3031,16 @@ xmlParserHandleReference(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED) {
*/
void
xmlHandleEntity(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlEntityPtr entity ATTRIBUTE_UNUSED) {
xmlHandleEntity(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
xmlEntityPtr entity ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlHandleEntity() deprecated function reached\n");
deprecated = 1;
xmlGenericError(xmlGenericErrorContext,
"xmlHandleEntity() deprecated function reached\n");
deprecated = 1;
}
#if 0
int len;
xmlParserInputPtr input;
if (entity->content == NULL) {
ctxt->errNo = XML_ERR_INTERNAL_ERROR;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData, "xmlHandleEntity %s: content == NULL\n",
entity->name);
ctxt->wellFormed = 0;
if (ctxt->recovery == 0) ctxt->disableSAX = 1;
return;
}
len = xmlStrlen(entity->content);
if (len <= 2) goto handle_as_char;
/*
* Redefine its content as an input stream.
*/
input = xmlNewEntityInputStream(ctxt, entity);
xmlPushInput(ctxt, input);
return;
handle_as_char:
/*
* Just handle the content as a set of chars.
*/
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
(ctxt->sax->characters != NULL))
ctxt->sax->characters(ctxt->userData, entity->content, len);
#endif
}
/**
@ -3443,58 +3055,18 @@ handle_as_char:
* Returns NULL this functionality had been removed
*/
xmlNsPtr
xmlNewGlobalNs(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *href ATTRIBUTE_UNUSED,
const xmlChar *prefix ATTRIBUTE_UNUSED) {
xmlNewGlobalNs(xmlDocPtr doc ATTRIBUTE_UNUSED,
const xmlChar * href ATTRIBUTE_UNUSED,
const xmlChar * prefix ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlNewGlobalNs() deprecated function reached\n");
deprecated = 1;
}
return(NULL);
#if 0
xmlNodePtr root;
xmlNsPtr cur;
root = xmlDocGetRootElement(doc);
if (root != NULL)
return(xmlNewNs(root, href, prefix));
/*
* if there is no root element yet, create an old Namespace type
* and it will be moved to the root at save time.
*/
cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
if (cur == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlNewGlobalNs : malloc failed\n");
return(NULL);
"xmlNewGlobalNs() deprecated function reached\n");
deprecated = 1;
}
memset(cur, 0, sizeof(xmlNs));
cur->type = XML_GLOBAL_NAMESPACE;
if (href != NULL)
cur->href = xmlStrdup(href);
if (prefix != NULL)
cur->prefix = xmlStrdup(prefix);
/*
* Add it at the end to preserve parsing order ...
*/
if (doc != NULL) {
if (doc->oldNs == NULL) {
doc->oldNs = cur;
} else {
xmlNsPtr prev = doc->oldNs;
while (prev->next != NULL) prev = prev->next;
prev->next = cur;
}
}
return(NULL);
#endif
return (NULL);
}
/**
@ -3505,34 +3077,13 @@ xmlNewGlobalNs(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *href ATTRIBUTE_UNU
* DEPRECATED
*/
void
xmlUpgradeOldNs(xmlDocPtr doc ATTRIBUTE_UNUSED) {
xmlUpgradeOldNs(xmlDocPtr doc ATTRIBUTE_UNUSED)
{
static int deprecated = 0;
if (!deprecated) {
xmlGenericError(xmlGenericErrorContext,
"xmlUpgradeOldNs() deprecated function reached\n");
deprecated = 1;
}
#if 0
xmlNsPtr cur;
if ((doc == NULL) || (doc->oldNs == NULL)) return;
if (doc->children == NULL) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlUpgradeOldNs: failed no root !\n");
#endif
return;
"xmlUpgradeOldNs() deprecated function reached\n");
deprecated = 1;
}
cur = doc->oldNs;
while (cur->next != NULL) {
cur->type = XML_LOCAL_NAMESPACE;
cur = cur->next;
}
cur->type = XML_LOCAL_NAMESPACE;
cur->next = doc->children->nsDef;
doc->children->nsDef = doc->oldNs;
doc->oldNs = NULL;
#endif
}

View File

@ -1,858 +0,0 @@
/*
* testDocbook.c : a small tester program for SGML Docbook input.
*
* See Copyright for the status of this software.
*
* daniel@veillard.com
*/
#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>
#include <libxml/globals.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 noent = 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 */
1
};
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 *ctxt 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 *ctxt 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 *ctxt ATTRIBUTE_UNUSED)
{
fprintf(stdout, "SAX.hasExternalSubset()\n");
return(0);
}
/**
* internalSubsetDebug:
* @ctxt: An XML parser context
*
* Does this document has an internal subset
*/
static void
internalSubsetDebug(void *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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 *ctxt 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,
1
};
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, XML_CHAR_ENCODING_NONE);
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, XML_CHAR_ENCODING_NONE);
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, XML_CHAR_ENCODING_NONE);
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], "-noent")) || (!strcmp(argv[i], "--noent")))
noent++;
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];
}
}
if (noent != 0) xmlSubstituteEntitiesDefault(1);
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

View File

@ -83,9 +83,6 @@
#ifdef LIBXML_CATALOG_ENABLED
#include <libxml/catalog.h>
#endif
#ifdef LIBXML_DOCB_ENABLED
#include <libxml/DOCBparser.h>
#endif
#include <libxml/globals.h>
#include <libxml/xmlreader.h>
#ifdef LIBXML_SCHEMAS_ENABLED
@ -120,9 +117,6 @@ static xmlSchemaPtr wxschemas = NULL;
static int repeat = 0;
static int insert = 0;
static int compress = 0;
#ifdef LIBXML_DOCB_ENABLED
static int sgml = 0;
#endif
static int html = 0;
static int htmlout = 0;
static int push = 0;
@ -715,38 +709,6 @@ static void parseAndPrintFile(char *filename) {
xmlDocSetRootElement(doc, n);
}
}
#ifdef LIBXML_DOCB_ENABLED
/*
* build an SGML tree from a string;
*/
else if ((sgml) && (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, XML_CHAR_ENCODING_NONE);
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 if (sgml) {
doc = docbParseFile(filename, NULL);
}
#endif
#ifdef LIBXML_HTML_ENABLED
else if ((html) && (push)) {
FILE *f;
@ -1258,9 +1220,6 @@ static void showVersion(const char *name) {
#ifdef LIBXML_CATALOG_ENABLED
fprintf(stderr, "Catalog ");
#endif
#ifdef LIBXML_DOCB_ENABLED
fprintf(stderr, "DocBook ");
#endif
#ifdef LIBXML_XPATH_ENABLED
fprintf(stderr, "XPath ");
#endif
@ -1320,9 +1279,6 @@ static void usage(const char *name) {
#ifdef HAVE_ZLIB_H
printf("\t--compress : turn on gzip compression of output\n");
#endif
#ifdef LIBXML_DOCB_ENABLED
printf("\t--sgml : use the DocBook SGML parser\n");
#endif
#ifdef LIBXML_HTML_ENABLED
printf("\t--html : use the HTML parser\n");
#endif
@ -1423,12 +1379,6 @@ main(int argc, char **argv) {
else if ((!strcmp(argv[i], "-htmlout")) ||
(!strcmp(argv[i], "--htmlout")))
htmlout++;
#ifdef LIBXML_DOCB_ENABLED
else if ((!strcmp(argv[i], "-sgml")) ||
(!strcmp(argv[i], "--sgml"))) {
sgml++;
}
#endif
#ifdef LIBXML_HTML_ENABLED
else if ((!strcmp(argv[i], "-html")) ||
(!strcmp(argv[i], "--html"))) {