From ab5acbf509abd1aa2aa44712ea9b8172ba41551e Mon Sep 17 00:00:00 2001 From: James Clark Date: Wed, 28 Jul 1999 09:34:18 +0000 Subject: [PATCH] Added start/endDoctypeDeclHandlers --- expat/expat.html | 2 +- expat/xmlparse/xmlparse.c | 25 +++++++++++++++++++++++++ expat/xmlparse/xmlparse.h | 14 ++++++++++++++ expat/xmlwf/xmlwf.c | 29 ++++++++++++++++++++++++----- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/expat/expat.html b/expat/expat.html index 28c08980..df434c13 100755 --- a/expat/expat.html +++ b/expat/expat.html @@ -9,7 +9,7 @@

expat - XML Parser Toolkit

-

Version 19990709

+

Version 19990728

Copyright (c) 1998, 1999 James Clark. Expat is subject to the Mozilla Public diff --git a/expat/xmlparse/xmlparse.c b/expat/xmlparse/xmlparse.c index c1c011e0..d9df3a8e 100755 --- a/expat/xmlparse/xmlparse.c +++ b/expat/xmlparse/xmlparse.c @@ -300,6 +300,8 @@ typedef struct { XML_StartCdataSectionHandler m_startCdataSectionHandler; XML_EndCdataSectionHandler m_endCdataSectionHandler; XML_DefaultHandler m_defaultHandler; + XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler; + XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler; XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler; XML_NotationDeclHandler m_notationDeclHandler; XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler; @@ -364,6 +366,8 @@ typedef struct { #define startCdataSectionHandler (((Parser *)parser)->m_startCdataSectionHandler) #define endCdataSectionHandler (((Parser *)parser)->m_endCdataSectionHandler) #define defaultHandler (((Parser *)parser)->m_defaultHandler) +#define startDoctypeDeclHandler (((Parser *)parser)->m_startDoctypeDeclHandler) +#define endDoctypeDeclHandler (((Parser *)parser)->m_endDoctypeDeclHandler) #define unparsedEntityDeclHandler (((Parser *)parser)->m_unparsedEntityDeclHandler) #define notationDeclHandler (((Parser *)parser)->m_notationDeclHandler) #define startNamespaceDeclHandler (((Parser *)parser)->m_startNamespaceDeclHandler) @@ -452,6 +456,8 @@ XML_Parser XML_ParserCreate(const XML_Char *encodingName) startCdataSectionHandler = 0; endCdataSectionHandler = 0; defaultHandler = 0; + startDoctypeDeclHandler = 0; + endDoctypeDeclHandler = 0; unparsedEntityDeclHandler = 0; notationDeclHandler = 0; startNamespaceDeclHandler = 0; @@ -765,6 +771,14 @@ void XML_SetDefaultHandlerExpand(XML_Parser parser, defaultExpandInternalEntities = 1; } +void XML_SetDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end) +{ + startDoctypeDeclHandler = start; + endDoctypeDeclHandler = end; +} + void XML_SetUnparsedEntityDeclHandler(XML_Parser parser, XML_UnparsedEntityDeclHandler handler) { @@ -2200,6 +2214,15 @@ doProlog(XML_Parser parser, enc = encoding; } break; + case XML_ROLE_DOCTYPE_NAME: + if (startDoctypeDeclHandler) { + const XML_Char *name = poolStoreString(&tempPool, enc, s, next); + if (!name) + return XML_ERROR_NO_MEMORY; + startDoctypeDeclHandler(handlerArg, name); + poolClear(&tempPool); + } + break; #ifdef XML_DTD case XML_ROLE_TEXT_DECL: { @@ -2256,6 +2279,8 @@ doProlog(XML_Parser parser, && !notStandaloneHandler(handlerArg)) return XML_ERROR_NOT_STANDALONE; } + if (endDoctypeDeclHandler) + endDoctypeDeclHandler(handlerArg); break; case XML_ROLE_INSTANCE_START: processor = contentProcessor; diff --git a/expat/xmlparse/xmlparse.h b/expat/xmlparse/xmlparse.h index 065ad036..284c3177 100755 --- a/expat/xmlparse/xmlparse.h +++ b/expat/xmlparse/xmlparse.h @@ -137,6 +137,15 @@ typedef void (*XML_DefaultHandler)(void *userData, const XML_Char *s, int len); +/* This is called for the start of the DOCTYPE declaration when the +name of the DOCTYPE is encountered. */ +typedef void (*XML_StartDoctypeDeclHandler)(void *userData, + const XML_Char *doctypeName); + +/* This is called for the start of the DOCTYPE declaration when the +closing > is encountered, but after processing any external subset. */ +typedef void (*XML_EndDoctypeDeclHandler)(void *userData); + /* This is called for a declaration of an unparsed (NDATA) entity. The base argument is whatever was set by XML_SetBase. The entityName, systemId and notationName arguments will never be null. @@ -308,6 +317,11 @@ void XMLPARSEAPI XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler); +void XMLPARSEAPI +XML_SetDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end); + void XMLPARSEAPI XML_SetUnparsedEntityDeclHandler(XML_Parser parser, XML_UnparsedEntityDeclHandler handler); diff --git a/expat/xmlwf/xmlwf.c b/expat/xmlwf/xmlwf.c index 344108a0..1297a0c0 100755 --- a/expat/xmlwf/xmlwf.c +++ b/expat/xmlwf/xmlwf.c @@ -412,13 +412,31 @@ void metaCharacterData(XML_Parser parser, const XML_Char *s, int len) fputts(T("/>\n"), fp); } +static +void metaStartDoctypeDecl(XML_Parser parser, const XML_Char *doctypeName) +{ + FILE *fp = XML_GetUserData(parser); + ftprintf(fp, T("\n"), fp); +} + +static +void metaEndDoctypeDecl(XML_Parser parser) +{ + FILE *fp = XML_GetUserData(parser); + fputts(T("\n"), fp); +} + static void metaUnparsedEntityDecl(XML_Parser parser, - const XML_Char *entityName, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId, - const XML_Char *notationName) + const XML_Char *entityName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName) { FILE *fp = XML_GetUserData(parser); ftprintf(fp, T("