mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-30 22:43:14 +03:00
code cleanup Daniel
* DOCBparser.c HTMLparser.c parser.c valid.c xpath.c: code cleanup Daniel
This commit is contained in:
@ -1,3 +1,7 @@
|
|||||||
|
Sat Nov 30 12:19:17 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* DOCBparser.c HTMLparser.c parser.c valid.c xpath.c: code cleanup
|
||||||
|
|
||||||
Thu Nov 28 12:53:22 CET 2002 Daniel Veillard <daniel@veillard.com>
|
Thu Nov 28 12:53:22 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* uri.c: Johann Richard pointed out some XPointer problems for
|
* uri.c: Johann Richard pointed out some XPointer problems for
|
||||||
|
85
DOCBparser.c
85
DOCBparser.c
@ -115,42 +115,59 @@ struct _docbElemDesc {
|
|||||||
* *
|
* *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Generic function for accessing stacks in the Parser Context
|
* docbnamePush:
|
||||||
|
* @ctxt: a DocBook SGML parser context
|
||||||
|
* @value: the element name
|
||||||
|
*
|
||||||
|
* Pushes a new element name on top of the name stack
|
||||||
|
*
|
||||||
|
* Returns 0 in case of error, the index in the stack otherwise
|
||||||
*/
|
*/
|
||||||
|
static int
|
||||||
|
docbnamePush(docbParserCtxtPtr ctxt, xmlChar * value)
|
||||||
|
{
|
||||||
|
if (ctxt->nameNr >= ctxt->nameMax) {
|
||||||
|
ctxt->nameMax *= 2;
|
||||||
|
ctxt->nameTab =
|
||||||
|
(xmlChar * *)xmlRealloc(ctxt->nameTab,
|
||||||
|
ctxt->nameMax *
|
||||||
|
sizeof(ctxt->nameTab[0]));
|
||||||
|
if (ctxt->nameTab == NULL) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext, "realloc failed !\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctxt->nameTab[ctxt->nameNr] = value;
|
||||||
|
ctxt->name = value;
|
||||||
|
return (ctxt->nameNr++);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* docbnamePop:
|
||||||
|
* @ctxt: a DocBook SGML parser context
|
||||||
|
*
|
||||||
|
* Pops the top element name from the name stack
|
||||||
|
*
|
||||||
|
* Returns the name just removed
|
||||||
|
*/
|
||||||
|
static xmlChar *
|
||||||
|
docbnamePop(docbParserCtxtPtr ctxt)
|
||||||
|
{
|
||||||
|
xmlChar *ret;
|
||||||
|
|
||||||
#define PUSH_AND_POP(scope, type, name) \
|
if (ctxt->nameNr < 0)
|
||||||
scope int docb##name##Push(docbParserCtxtPtr ctxt, type value) { \
|
return (0);
|
||||||
if (ctxt->name##Nr >= ctxt->name##Max) { \
|
ctxt->nameNr--;
|
||||||
ctxt->name##Max *= 2; \
|
if (ctxt->nameNr < 0)
|
||||||
ctxt->name##Tab = (type *) xmlRealloc(ctxt->name##Tab, \
|
return (0);
|
||||||
ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \
|
if (ctxt->nameNr > 0)
|
||||||
if (ctxt->name##Tab == NULL) { \
|
ctxt->name = ctxt->nameTab[ctxt->nameNr - 1];
|
||||||
xmlGenericError(xmlGenericErrorContext, \
|
else
|
||||||
"realloc failed !\n"); \
|
ctxt->name = NULL;
|
||||||
return(0); \
|
ret = ctxt->nameTab[ctxt->nameNr];
|
||||||
} \
|
ctxt->nameTab[ctxt->nameNr] = 0;
|
||||||
} \
|
return (ret);
|
||||||
ctxt->name##Tab[ctxt->name##Nr] = value; \
|
}
|
||||||
ctxt->name = value; \
|
|
||||||
return(ctxt->name##Nr++); \
|
|
||||||
} \
|
|
||||||
scope type docb##name##Pop(docbParserCtxtPtr ctxt) { \
|
|
||||||
type ret; \
|
|
||||||
if (ctxt->name##Nr < 0) return(0); \
|
|
||||||
ctxt->name##Nr--; \
|
|
||||||
if (ctxt->name##Nr < 0) return(0); \
|
|
||||||
if (ctxt->name##Nr > 0) \
|
|
||||||
ctxt->name = ctxt->name##Tab[ctxt->name##Nr - 1]; \
|
|
||||||
else \
|
|
||||||
ctxt->name = NULL; \
|
|
||||||
ret = ctxt->name##Tab[ctxt->name##Nr]; \
|
|
||||||
ctxt->name##Tab[ctxt->name##Nr] = 0; \
|
|
||||||
return(ret); \
|
|
||||||
} \
|
|
||||||
|
|
||||||
/* PUSH_AND_POP(static, xmlNodePtr, node) */
|
|
||||||
PUSH_AND_POP(static, xmlChar*, name)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Macros for accessing the content. Those should be used only by the parser,
|
* Macros for accessing the content. Those should be used only by the parser,
|
||||||
|
85
HTMLparser.c
85
HTMLparser.c
@ -62,42 +62,59 @@ static void htmlParseComment(htmlParserCtxtPtr ctxt);
|
|||||||
* *
|
* *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Generic function for accessing stacks in the Parser Context
|
* htmlnamePush:
|
||||||
|
* @ctxt: an HTML parser context
|
||||||
|
* @value: the element name
|
||||||
|
*
|
||||||
|
* Pushes a new element name on top of the name stack
|
||||||
|
*
|
||||||
|
* Returns 0 in case of error, the index in the stack otherwise
|
||||||
*/
|
*/
|
||||||
|
static int
|
||||||
|
htmlnamePush(htmlParserCtxtPtr ctxt, xmlChar * value)
|
||||||
|
{
|
||||||
|
if (ctxt->nameNr >= ctxt->nameMax) {
|
||||||
|
ctxt->nameMax *= 2;
|
||||||
|
ctxt->nameTab =
|
||||||
|
(xmlChar * *)xmlRealloc(ctxt->nameTab,
|
||||||
|
ctxt->nameMax *
|
||||||
|
sizeof(ctxt->nameTab[0]));
|
||||||
|
if (ctxt->nameTab == NULL) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext, "realloc failed !\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctxt->nameTab[ctxt->nameNr] = value;
|
||||||
|
ctxt->name = value;
|
||||||
|
return (ctxt->nameNr++);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* htmlnamePop:
|
||||||
|
* @ctxt: an HTML parser context
|
||||||
|
*
|
||||||
|
* Pops the top element name from the name stack
|
||||||
|
*
|
||||||
|
* Returns the name just removed
|
||||||
|
*/
|
||||||
|
static xmlChar *
|
||||||
|
htmlnamePop(htmlParserCtxtPtr ctxt)
|
||||||
|
{
|
||||||
|
xmlChar *ret;
|
||||||
|
|
||||||
#define PUSH_AND_POP(scope, type, name) \
|
if (ctxt->nameNr <= 0)
|
||||||
scope int html##name##Push(htmlParserCtxtPtr ctxt, type value) { \
|
return (0);
|
||||||
if (ctxt->name##Nr >= ctxt->name##Max) { \
|
ctxt->nameNr--;
|
||||||
ctxt->name##Max *= 2; \
|
if (ctxt->nameNr < 0)
|
||||||
ctxt->name##Tab = (type *) xmlRealloc(ctxt->name##Tab, \
|
return (0);
|
||||||
ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \
|
if (ctxt->nameNr > 0)
|
||||||
if (ctxt->name##Tab == NULL) { \
|
ctxt->name = ctxt->nameTab[ctxt->nameNr - 1];
|
||||||
xmlGenericError(xmlGenericErrorContext, \
|
else
|
||||||
"realloc failed !\n"); \
|
ctxt->name = NULL;
|
||||||
return(0); \
|
ret = ctxt->nameTab[ctxt->nameNr];
|
||||||
} \
|
ctxt->nameTab[ctxt->nameNr] = 0;
|
||||||
} \
|
return (ret);
|
||||||
ctxt->name##Tab[ctxt->name##Nr] = value; \
|
}
|
||||||
ctxt->name = value; \
|
|
||||||
return(ctxt->name##Nr++); \
|
|
||||||
} \
|
|
||||||
scope type html##name##Pop(htmlParserCtxtPtr ctxt) { \
|
|
||||||
type ret; \
|
|
||||||
if (ctxt->name##Nr <= 0) return(0); \
|
|
||||||
ctxt->name##Nr--; \
|
|
||||||
if (ctxt->name##Nr < 0) return(0); \
|
|
||||||
if (ctxt->name##Nr > 0) \
|
|
||||||
ctxt->name = ctxt->name##Tab[ctxt->name##Nr - 1]; \
|
|
||||||
else \
|
|
||||||
ctxt->name = NULL; \
|
|
||||||
ret = ctxt->name##Tab[ctxt->name##Nr]; \
|
|
||||||
ctxt->name##Tab[ctxt->name##Nr] = 0; \
|
|
||||||
return(ret); \
|
|
||||||
} \
|
|
||||||
|
|
||||||
/* PUSH_AND_POP(static, xmlNodePtr, node) */
|
|
||||||
PUSH_AND_POP(static, xmlChar*, name)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Macros for accessing the content. Those should be used only by the parser,
|
* Macros for accessing the content. Those should be used only by the parser,
|
||||||
|
195
parser.c
195
parser.c
@ -117,47 +117,6 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt,
|
|||||||
xmlEntityPtr xmlParseStringEntityRef(xmlParserCtxtPtr ctxt,
|
xmlEntityPtr xmlParseStringEntityRef(xmlParserCtxtPtr ctxt,
|
||||||
const xmlChar ** str);
|
const xmlChar ** str);
|
||||||
|
|
||||||
/*
|
|
||||||
* Generic function for accessing stacks in the Parser Context
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define PUSH_AND_POP(scope, type, name) \
|
|
||||||
scope int name##Push(xmlParserCtxtPtr ctxt, type value) { \
|
|
||||||
if (ctxt->name##Nr >= ctxt->name##Max) { \
|
|
||||||
ctxt->name##Max *= 2; \
|
|
||||||
ctxt->name##Tab = (type *) xmlRealloc(ctxt->name##Tab, \
|
|
||||||
ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \
|
|
||||||
if (ctxt->name##Tab == NULL) { \
|
|
||||||
xmlGenericError(xmlGenericErrorContext, \
|
|
||||||
"realloc failed !\n"); \
|
|
||||||
return(0); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
ctxt->name##Tab[ctxt->name##Nr] = value; \
|
|
||||||
ctxt->name = value; \
|
|
||||||
return(ctxt->name##Nr++); \
|
|
||||||
} \
|
|
||||||
scope type name##Pop(xmlParserCtxtPtr ctxt) { \
|
|
||||||
type ret; \
|
|
||||||
if (ctxt->name##Nr <= 0) return(0); \
|
|
||||||
ctxt->name##Nr--; \
|
|
||||||
if (ctxt->name##Nr > 0) \
|
|
||||||
ctxt->name = ctxt->name##Tab[ctxt->name##Nr - 1]; \
|
|
||||||
else \
|
|
||||||
ctxt->name = NULL; \
|
|
||||||
ret = ctxt->name##Tab[ctxt->name##Nr]; \
|
|
||||||
ctxt->name##Tab[ctxt->name##Nr] = 0; \
|
|
||||||
return(ret); \
|
|
||||||
} \
|
|
||||||
|
|
||||||
/**
|
|
||||||
* inputPop:
|
|
||||||
* @ctxt: an XML parser context
|
|
||||||
*
|
|
||||||
* Pops the top parser input from the input stack
|
|
||||||
*
|
|
||||||
* Returns the input just removed
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* inputPush:
|
* inputPush:
|
||||||
* @ctxt: an XML parser context
|
* @ctxt: an XML parser context
|
||||||
@ -167,31 +126,48 @@ scope type name##Pop(xmlParserCtxtPtr ctxt) { \
|
|||||||
*
|
*
|
||||||
* Returns 0 in case of error, the index in the stack otherwise
|
* Returns 0 in case of error, the index in the stack otherwise
|
||||||
*/
|
*/
|
||||||
|
extern int
|
||||||
|
inputPush(xmlParserCtxtPtr ctxt, xmlParserInputPtr value)
|
||||||
|
{
|
||||||
|
if (ctxt->inputNr >= ctxt->inputMax) {
|
||||||
|
ctxt->inputMax *= 2;
|
||||||
|
ctxt->inputTab =
|
||||||
|
(xmlParserInputPtr *) xmlRealloc(ctxt->inputTab,
|
||||||
|
ctxt->inputMax *
|
||||||
|
sizeof(ctxt->inputTab[0]));
|
||||||
|
if (ctxt->inputTab == NULL) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext, "realloc failed !\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctxt->inputTab[ctxt->inputNr] = value;
|
||||||
|
ctxt->input = value;
|
||||||
|
return (ctxt->inputNr++);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* namePop:
|
* inputPop:
|
||||||
* @ctxt: an XML parser context
|
* @ctxt: an XML parser context
|
||||||
*
|
*
|
||||||
* Pops the top element name from the name stack
|
* Pops the top parser input from the input stack
|
||||||
*
|
*
|
||||||
* Returns the name just removed
|
* Returns the input just removed
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* namePush:
|
|
||||||
* @ctxt: an XML parser context
|
|
||||||
* @value: the element name
|
|
||||||
*
|
|
||||||
* Pushes a new element name on top of the name stack
|
|
||||||
*
|
|
||||||
* Returns 0 in case of error, the index in the stack otherwise
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* nodePop:
|
|
||||||
* @ctxt: an XML parser context
|
|
||||||
*
|
|
||||||
* Pops the top element node from the node stack
|
|
||||||
*
|
|
||||||
* Returns the node just removed
|
|
||||||
*/
|
*/
|
||||||
|
extern xmlParserInputPtr
|
||||||
|
inputPop(xmlParserCtxtPtr ctxt)
|
||||||
|
{
|
||||||
|
xmlParserInputPtr ret;
|
||||||
|
|
||||||
|
if (ctxt->inputNr <= 0)
|
||||||
|
return (0);
|
||||||
|
ctxt->inputNr--;
|
||||||
|
if (ctxt->inputNr > 0)
|
||||||
|
ctxt->input = ctxt->inputTab[ctxt->inputNr - 1];
|
||||||
|
else
|
||||||
|
ctxt->input = NULL;
|
||||||
|
ret = ctxt->inputTab[ctxt->inputNr];
|
||||||
|
ctxt->inputTab[ctxt->inputNr] = 0;
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* nodePush:
|
* nodePush:
|
||||||
* @ctxt: an XML parser context
|
* @ctxt: an XML parser context
|
||||||
@ -201,12 +177,99 @@ scope type name##Pop(xmlParserCtxtPtr ctxt) { \
|
|||||||
*
|
*
|
||||||
* Returns 0 in case of error, the index in the stack otherwise
|
* Returns 0 in case of error, the index in the stack otherwise
|
||||||
*/
|
*/
|
||||||
/*
|
extern int
|
||||||
* Those macros actually generate the functions
|
nodePush(xmlParserCtxtPtr ctxt, xmlNodePtr value)
|
||||||
|
{
|
||||||
|
if (ctxt->nodeNr >= ctxt->nodeMax) {
|
||||||
|
ctxt->nodeMax *= 2;
|
||||||
|
ctxt->nodeTab =
|
||||||
|
(xmlNodePtr *) xmlRealloc(ctxt->nodeTab,
|
||||||
|
ctxt->nodeMax *
|
||||||
|
sizeof(ctxt->nodeTab[0]));
|
||||||
|
if (ctxt->nodeTab == NULL) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext, "realloc failed !\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctxt->nodeTab[ctxt->nodeNr] = value;
|
||||||
|
ctxt->node = value;
|
||||||
|
return (ctxt->nodeNr++);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* nodePop:
|
||||||
|
* @ctxt: an XML parser context
|
||||||
|
*
|
||||||
|
* Pops the top element node from the node stack
|
||||||
|
*
|
||||||
|
* Returns the node just removed
|
||||||
*/
|
*/
|
||||||
PUSH_AND_POP(extern, xmlParserInputPtr, input)
|
extern xmlNodePtr
|
||||||
PUSH_AND_POP(extern, xmlNodePtr, node)
|
nodePop(xmlParserCtxtPtr ctxt)
|
||||||
PUSH_AND_POP(extern, xmlChar*, name)
|
{
|
||||||
|
xmlNodePtr ret;
|
||||||
|
|
||||||
|
if (ctxt->nodeNr <= 0)
|
||||||
|
return (0);
|
||||||
|
ctxt->nodeNr--;
|
||||||
|
if (ctxt->nodeNr > 0)
|
||||||
|
ctxt->node = ctxt->nodeTab[ctxt->nodeNr - 1];
|
||||||
|
else
|
||||||
|
ctxt->node = NULL;
|
||||||
|
ret = ctxt->nodeTab[ctxt->nodeNr];
|
||||||
|
ctxt->nodeTab[ctxt->nodeNr] = 0;
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* namePush:
|
||||||
|
* @ctxt: an XML parser context
|
||||||
|
* @value: the element name
|
||||||
|
*
|
||||||
|
* Pushes a new element name on top of the name stack
|
||||||
|
*
|
||||||
|
* Returns 0 in case of error, the index in the stack otherwise
|
||||||
|
*/
|
||||||
|
extern int
|
||||||
|
namePush(xmlParserCtxtPtr ctxt, xmlChar * value)
|
||||||
|
{
|
||||||
|
if (ctxt->nameNr >= ctxt->nameMax) {
|
||||||
|
ctxt->nameMax *= 2;
|
||||||
|
ctxt->nameTab =
|
||||||
|
(xmlChar * *)xmlRealloc(ctxt->nameTab,
|
||||||
|
ctxt->nameMax *
|
||||||
|
sizeof(ctxt->nameTab[0]));
|
||||||
|
if (ctxt->nameTab == NULL) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext, "realloc failed !\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctxt->nameTab[ctxt->nameNr] = value;
|
||||||
|
ctxt->name = value;
|
||||||
|
return (ctxt->nameNr++);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* namePop:
|
||||||
|
* @ctxt: an XML parser context
|
||||||
|
*
|
||||||
|
* Pops the top element name from the name stack
|
||||||
|
*
|
||||||
|
* Returns the name just removed
|
||||||
|
*/
|
||||||
|
extern xmlChar *
|
||||||
|
namePop(xmlParserCtxtPtr ctxt)
|
||||||
|
{
|
||||||
|
xmlChar *ret;
|
||||||
|
|
||||||
|
if (ctxt->nameNr <= 0)
|
||||||
|
return (0);
|
||||||
|
ctxt->nameNr--;
|
||||||
|
if (ctxt->nameNr > 0)
|
||||||
|
ctxt->name = ctxt->nameTab[ctxt->nameNr - 1];
|
||||||
|
else
|
||||||
|
ctxt->name = NULL;
|
||||||
|
ret = ctxt->nameTab[ctxt->nameNr];
|
||||||
|
ctxt->nameTab[ctxt->nameNr] = 0;
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
static int spacePush(xmlParserCtxtPtr ctxt, int val) {
|
static int spacePush(xmlParserCtxtPtr ctxt, int val) {
|
||||||
if (ctxt->spaceNr >= ctxt->spaceMax) {
|
if (ctxt->spaceNr >= ctxt->spaceMax) {
|
||||||
|
93
valid.c
93
valid.c
@ -32,52 +32,12 @@
|
|||||||
xmlGenericError(xmlGenericErrorContext, \
|
xmlGenericError(xmlGenericErrorContext, \
|
||||||
"Unimplemented block at %s:%d\n", \
|
"Unimplemented block at %s:%d\n", \
|
||||||
__FILE__, __LINE__);
|
__FILE__, __LINE__);
|
||||||
/*
|
|
||||||
* Generic function for accessing stacks in the Validity Context
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define PUSH_AND_POP(scope, type, name) \
|
|
||||||
scope int name##VPush(xmlValidCtxtPtr ctxt, type value) { \
|
|
||||||
if (ctxt->name##Max <= 0) { \
|
|
||||||
ctxt->name##Max = 4; \
|
|
||||||
ctxt->name##Tab = (type *) xmlMalloc( \
|
|
||||||
ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \
|
|
||||||
if (ctxt->name##Tab == NULL) { \
|
|
||||||
xmlGenericError(xmlGenericErrorContext, \
|
|
||||||
"malloc failed !\n"); \
|
|
||||||
ctxt->name##Max = 0; \
|
|
||||||
return(0); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
if (ctxt->name##Nr >= ctxt->name##Max) { \
|
|
||||||
ctxt->name##Max *= 2; \
|
|
||||||
ctxt->name##Tab = (type *) xmlRealloc(ctxt->name##Tab, \
|
|
||||||
ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \
|
|
||||||
if (ctxt->name##Tab == NULL) { \
|
|
||||||
xmlGenericError(xmlGenericErrorContext, \
|
|
||||||
"realloc failed !\n"); \
|
|
||||||
return(0); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
ctxt->name##Tab[ctxt->name##Nr] = value; \
|
|
||||||
ctxt->name = value; \
|
|
||||||
return(ctxt->name##Nr++); \
|
|
||||||
} \
|
|
||||||
scope type name##VPop(xmlValidCtxtPtr ctxt) { \
|
|
||||||
type ret; \
|
|
||||||
if (ctxt->name##Nr <= 0) return(0); \
|
|
||||||
ctxt->name##Nr--; \
|
|
||||||
if (ctxt->name##Nr > 0) \
|
|
||||||
ctxt->name = ctxt->name##Tab[ctxt->name##Nr - 1]; \
|
|
||||||
else \
|
|
||||||
ctxt->name = NULL; \
|
|
||||||
ret = ctxt->name##Tab[ctxt->name##Nr]; \
|
|
||||||
ctxt->name##Tab[ctxt->name##Nr] = 0; \
|
|
||||||
return(ret); \
|
|
||||||
} \
|
|
||||||
|
|
||||||
|
#ifndef LIBXML_REGEXP_ENABLED
|
||||||
/*
|
/*
|
||||||
* I use a home made algorithm less complex and easier to
|
* If regexp are not enabled, it uses a home made algorithm less
|
||||||
|
* complex and easier to
|
||||||
* debug/maintain than a generic NFA -> DFA state based algo. The
|
* debug/maintain than a generic NFA -> DFA state based algo. The
|
||||||
* only restriction is on the deepness of the tree limited by the
|
* only restriction is on the deepness of the tree limited by the
|
||||||
* size of the occurs bitfield
|
* size of the occurs bitfield
|
||||||
@ -110,7 +70,6 @@ typedef struct _xmlValidState {
|
|||||||
#define SET_OCCURRENCE ctxt->vstate->occurs |= (1 << DEPTH)
|
#define SET_OCCURRENCE ctxt->vstate->occurs |= (1 << DEPTH)
|
||||||
#define RESET_OCCURRENCE ctxt->vstate->occurs &= ((1 << DEPTH) - 1)
|
#define RESET_OCCURRENCE ctxt->vstate->occurs &= ((1 << DEPTH) - 1)
|
||||||
|
|
||||||
#ifndef LIBXML_REGEXP_ENABLED
|
|
||||||
static int
|
static int
|
||||||
vstateVPush(xmlValidCtxtPtr ctxt, xmlElementContentPtr cont,
|
vstateVPush(xmlValidCtxtPtr ctxt, xmlElementContentPtr cont,
|
||||||
xmlNodePtr node, unsigned char depth, long occurs,
|
xmlNodePtr node, unsigned char depth, long occurs,
|
||||||
@ -163,7 +122,51 @@ vstateVPop(xmlValidCtxtPtr ctxt) {
|
|||||||
|
|
||||||
#endif /* LIBXML_REGEXP_ENABLED */
|
#endif /* LIBXML_REGEXP_ENABLED */
|
||||||
|
|
||||||
PUSH_AND_POP(static, xmlNodePtr, node)
|
static int
|
||||||
|
nodeVPush(xmlValidCtxtPtr ctxt, xmlNodePtr value)
|
||||||
|
{
|
||||||
|
if (ctxt->nodeMax <= 0) {
|
||||||
|
ctxt->nodeMax = 4;
|
||||||
|
ctxt->nodeTab =
|
||||||
|
(xmlNodePtr *) xmlMalloc(ctxt->nodeMax *
|
||||||
|
sizeof(ctxt->nodeTab[0]));
|
||||||
|
if (ctxt->nodeTab == NULL) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext, "malloc failed !\n");
|
||||||
|
ctxt->nodeMax = 0;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ctxt->nodeNr >= ctxt->nodeMax) {
|
||||||
|
ctxt->nodeMax *= 2;
|
||||||
|
ctxt->nodeTab =
|
||||||
|
(xmlNodePtr *) xmlRealloc(ctxt->nodeTab,
|
||||||
|
ctxt->nodeMax *
|
||||||
|
sizeof(ctxt->nodeTab[0]));
|
||||||
|
if (ctxt->nodeTab == NULL) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext, "realloc failed !\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctxt->nodeTab[ctxt->nodeNr] = value;
|
||||||
|
ctxt->node = value;
|
||||||
|
return (ctxt->nodeNr++);
|
||||||
|
}
|
||||||
|
static xmlNodePtr
|
||||||
|
nodeVPop(xmlValidCtxtPtr ctxt)
|
||||||
|
{
|
||||||
|
xmlNodePtr ret;
|
||||||
|
|
||||||
|
if (ctxt->nodeNr <= 0)
|
||||||
|
return (0);
|
||||||
|
ctxt->nodeNr--;
|
||||||
|
if (ctxt->nodeNr > 0)
|
||||||
|
ctxt->node = ctxt->nodeTab[ctxt->nodeNr - 1];
|
||||||
|
else
|
||||||
|
ctxt->node = NULL;
|
||||||
|
ret = ctxt->nodeTab[ctxt->nodeNr];
|
||||||
|
ctxt->nodeTab[ctxt->nodeNr] = 0;
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_VALID_ALGO
|
#ifdef DEBUG_VALID_ALGO
|
||||||
static void
|
static void
|
||||||
|
68
xpath.c
68
xpath.c
@ -885,39 +885,6 @@ xmlXPathDebugDumpCompExpr(FILE *output, xmlXPathCompExprPtr comp,
|
|||||||
* *
|
* *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
/*
|
|
||||||
* Generic function for accessing stacks in the Parser Context
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define PUSH_AND_POP(type, name) \
|
|
||||||
extern int name##Push(xmlXPathParserContextPtr ctxt, type value) { \
|
|
||||||
if (ctxt->name##Nr >= ctxt->name##Max) { \
|
|
||||||
ctxt->name##Max *= 2; \
|
|
||||||
ctxt->name##Tab = (type *) xmlRealloc(ctxt->name##Tab, \
|
|
||||||
ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \
|
|
||||||
if (ctxt->name##Tab == NULL) { \
|
|
||||||
xmlGenericError(xmlGenericErrorContext, \
|
|
||||||
"realloc failed !\n"); \
|
|
||||||
return(0); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
ctxt->name##Tab[ctxt->name##Nr] = value; \
|
|
||||||
ctxt->name = value; \
|
|
||||||
return(ctxt->name##Nr++); \
|
|
||||||
} \
|
|
||||||
extern type name##Pop(xmlXPathParserContextPtr ctxt) { \
|
|
||||||
type ret; \
|
|
||||||
if (ctxt->name##Nr <= 0) return(0); \
|
|
||||||
ctxt->name##Nr--; \
|
|
||||||
if (ctxt->name##Nr > 0) \
|
|
||||||
ctxt->name = ctxt->name##Tab[ctxt->name##Nr - 1]; \
|
|
||||||
else \
|
|
||||||
ctxt->name = NULL; \
|
|
||||||
ret = ctxt->name##Tab[ctxt->name##Nr]; \
|
|
||||||
ctxt->name##Tab[ctxt->name##Nr] = 0; \
|
|
||||||
return(ret); \
|
|
||||||
} \
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* valuePop:
|
* valuePop:
|
||||||
* @ctxt: an XPath evaluation context
|
* @ctxt: an XPath evaluation context
|
||||||
@ -926,6 +893,22 @@ extern type name##Pop(xmlXPathParserContextPtr ctxt) { \
|
|||||||
*
|
*
|
||||||
* Returns the XPath object just removed
|
* Returns the XPath object just removed
|
||||||
*/
|
*/
|
||||||
|
extern xmlXPathObjectPtr
|
||||||
|
valuePop(xmlXPathParserContextPtr ctxt)
|
||||||
|
{
|
||||||
|
xmlXPathObjectPtr ret;
|
||||||
|
|
||||||
|
if (ctxt->valueNr <= 0)
|
||||||
|
return (0);
|
||||||
|
ctxt->valueNr--;
|
||||||
|
if (ctxt->valueNr > 0)
|
||||||
|
ctxt->value = ctxt->valueTab[ctxt->valueNr - 1];
|
||||||
|
else
|
||||||
|
ctxt->value = NULL;
|
||||||
|
ret = ctxt->valueTab[ctxt->valueNr];
|
||||||
|
ctxt->valueTab[ctxt->valueNr] = 0;
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* valuePush:
|
* valuePush:
|
||||||
* @ctxt: an XPath evaluation context
|
* @ctxt: an XPath evaluation context
|
||||||
@ -935,7 +918,24 @@ extern type name##Pop(xmlXPathParserContextPtr ctxt) { \
|
|||||||
*
|
*
|
||||||
* returns the number of items on the value stack
|
* returns the number of items on the value stack
|
||||||
*/
|
*/
|
||||||
PUSH_AND_POP(xmlXPathObjectPtr, value)
|
extern int
|
||||||
|
valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr value)
|
||||||
|
{
|
||||||
|
if (ctxt->valueNr >= ctxt->valueMax) {
|
||||||
|
ctxt->valueMax *= 2;
|
||||||
|
ctxt->valueTab =
|
||||||
|
(xmlXPathObjectPtr *) xmlRealloc(ctxt->valueTab,
|
||||||
|
ctxt->valueMax *
|
||||||
|
sizeof(ctxt->valueTab[0]));
|
||||||
|
if (ctxt->valueTab == NULL) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext, "realloc failed !\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctxt->valueTab[ctxt->valueNr] = value;
|
||||||
|
ctxt->value = value;
|
||||||
|
return (ctxt->valueNr++);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlXPathPopBoolean:
|
* xmlXPathPopBoolean:
|
||||||
|
Reference in New Issue
Block a user