xpath.c revision d46ee884c41b808b239563b1978468aae12e33a2
/*
* xpath.c: XML Path Language implementation
* XPath is a language for addressing parts of an XML document,
* designed to be used by both XSLT and XPointer
*f
* Reference: W3C Recommendation 16 November 1999
* Public reference:
*
* See Copyright for the status of this software
*
* Author: daniel@veillard.com
*
*/
#define IN_LIBXML
#include "libxml.h"
#include <string.h>
#ifdef HAVE_SYS_TYPES_H
#endif
#ifdef HAVE_MATH_H
#include <math.h>
#endif
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif
#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#include <libxml/xmlmemory.h>
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
#ifdef LIBXML_XPTR_ENABLED
#include <libxml/xpointer.h>
#endif
#ifdef LIBXML_DEBUG_ENABLED
#include <libxml/debugXML.h>
#endif
#include <libxml/xmlerror.h>
#ifdef LIBXML_PATTERN_ENABLED
#endif
#ifdef LIBXML_PATTERN_ENABLED
#define XPATH_STREAMING
#endif
#define TODO \
"Unimplemented block at %s:%d\n", \
/*
* XP_OPTIMIZED_NON_ELEM_COMPARISON:
* If defined, this will use xmlXPathCmpNodesExt() instead of
* xmlXPathCmpNodes(). The new function is optimized comparison of
* non-element nodes; actually it will speed up comparison only if
* xmlXPathOrderDocElems() was called in order to index the elements of
* a tree in document order; Libxslt does such an indexing, thus it will
* benefit from this optimization.
*/
#define XP_OPTIMIZED_NON_ELEM_COMPARISON
/*
* XP_OPTIMIZED_FILTER_FIRST:
* If defined, this will optimize expressions like "key('foo', 'val')[b][1]"
* in a way, that it stop evaluation at the first node.
*/
#define XP_OPTIMIZED_FILTER_FIRST
/*
* XP_DEBUG_OBJ_USAGE:
* Internal flag to enable tracking of how much XPath objects have been
* created.
*/
/* #define XP_DEBUG_OBJ_USAGE */
/*
* TODO:
* There are a few spots where some tests are done which depend upon ascii
* data. These should be enhanced for full UTF8 support (see particularly
* any use of the macros IS_ASCII_CHARACTER and IS_ASCII_DIGIT)
*/
#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
/************************************************************************
* *
* Floating point stuff *
* *
************************************************************************/
#ifndef TRIO_REPLACE_STDIO
#define TRIO_PUBLIC static
#endif
#include "trionan.c"
/*
* The lack of portability of this section of the libc is annoying !
*/
double xmlXPathNAN = 0;
double xmlXPathPINF = 1;
double xmlXPathNINF = -1;
static double xmlXPathNZERO = 0; /* not exported from headers */
static int xmlXPathInitialized = 0;
/**
* xmlXPathInit:
*
* Initialize the XPath environment
*/
void
xmlXPathInit(void) {
if (xmlXPathInitialized) return;
xmlXPathPINF = trio_pinf();
xmlXPathNINF = trio_ninf();
xmlXPathNAN = trio_nan();
xmlXPathNZERO = trio_nzero();
xmlXPathInitialized = 1;
}
/**
* xmlXPathIsNaN:
* @val: a double value
*
* Provides a portable isnan() function to detect whether a double
* is a NotaNumber. Based on trio code
*
* Returns 1 if the value is a NaN, 0 otherwise
*/
int
xmlXPathIsNaN(double val) {
return(trio_isnan(val));
}
/**
* xmlXPathIsInf:
* @val: a double value
*
* Provides a portable isinf() function to detect whether a double
* is a +Infinite or -Infinite. Based on trio code
*
* Returns 1 vi the value is +Infinite, -1 if -Infinite, 0 otherwise
*/
int
xmlXPathIsInf(double val) {
return(trio_isinf(val));
}
#endif /* SCHEMAS or XPATH */
#ifdef LIBXML_XPATH_ENABLED
/**
* xmlXPathGetSign:
* @val: a double value
*
* Provides a portable function to detect the sign of a double
* Modified from trio code
*
* Returns 1 if the value is Negative, 0 if positive
*/
static int
xmlXPathGetSign(double val) {
return(trio_signbit(val));
}
/*
* TODO: when compatibility allows remove all "fake node libxslt" strings
* the test should just be name[0] = ' '
*/
/* #define DEBUG */
/* #define DEBUG_STEP */
/* #define DEBUG_STEP_NTH */
/* #define DEBUG_EXPR */
/* #define DEBUG_EVAL_COUNTS */
static xmlNs xmlXPathXMLNamespaceStruct = {
NULL,
BAD_CAST "xml",
NULL,
};
#ifndef LIBXML_THREAD_ENABLED
/*
* Optimizer is disabled only when threaded apps are detected while
* the library ain't compiled for thread safety.
*/
static int xmlXPathDisableOptimizer = 0;
#endif
/************************************************************************
* *
* Error handling routines *
* *
************************************************************************/
/**
* XP_ERRORNULL:
* @X: the error code
*
* Macro to raise an XPath error and return NULL.
*/
#define XP_ERRORNULL(X) \
/*
* The array xmlXPathErrorMessages corresponds to the enum xmlXPathError
*/
static const char *xmlXPathErrorMessages[] = {
"Ok\n",
"Number encoding\n",
"Unfinished literal\n",
"Start of literal\n",
"Expected $ for variable reference\n",
"Undefined variable\n",
"Invalid predicate\n",
"Invalid expression\n",
"Missing closing curly brace\n",
"Unregistered function\n",
"Invalid operand\n",
"Invalid type\n",
"Invalid number of arguments\n",
"Invalid context size\n",
"Invalid context position\n",
"Memory allocation error\n",
"Syntax error\n",
"Resource error\n",
"Sub resource error\n",
"Undefined namespace prefix\n",
"Encoding error\n",
"Char out of XML range\n",
"Invalid or incomplete context\n",
"?? Unknown error ??\n" /* Must be last in the list! */
};
#define MAXERRNO ((int)(sizeof(xmlXPathErrorMessages) / \
sizeof(xmlXPathErrorMessages[0])) - 1)
/**
* xmlXPathErrMemory:
* @ctxt: an XPath context
* @extra: extra informations
*
* Handle a redefinition of attribute error
*/
static void
{
if (extra) {
BAD_CAST "Memory allocation failed : %s\n",
extra);
} else {
}
} else {
if (extra)
"Memory allocation failed : %s\n", extra);
else
"Memory allocation failed\n");
}
}
/**
* xmlXPathPErrMemory:
* @ctxt: an XPath parser context
* @extra: extra informations
*
* Handle a redefinition of attribute error
*/
static void
{
else {
}
}
/**
* xmlXPathErr:
* @ctxt: a XPath parser context
* @error: the error code
*
* Handle an XPath error
*/
void
{
XML_ERR_ERROR, NULL, 0,
return;
}
XML_ERR_ERROR, NULL, 0,
return;
}
/* cleanup current last error */
} else {
XML_ERR_ERROR, NULL, 0,
}
}
/**
* xmlXPatherror:
* @ctxt: the XPath Parser context
* @file: the file name
* @line: the line number
* @no: the error number
*
* Formats an error message.
*/
void
}
/************************************************************************
* *
* Utilities *
* *
************************************************************************/
/**
* xsltPointerList:
*
* Pointer-list for various purposes.
*/
typedef struct _xmlPointerList xmlPointerList;
typedef xmlPointerList *xmlPointerListPtr;
struct _xmlPointerList {
void **items;
int number;
int size;
};
/*
* TODO: Since such a list-handling is used in xmlschemas.c and libxslt
* and here, we should make the functions public.
*/
static int
void *item,
int initialSize)
{
if (initialSize <= 0)
initialSize = 1;
initialSize * sizeof(void *));
"xmlPointerListCreate: allocating item\n");
return(-1);
}
"xmlPointerListCreate: re-allocating item\n");
return(-1);
}
}
return(0);
}
/**
* xsltPointerListCreate:
*
* Creates an xsltPointerList structure.
*
* Returns a xsltPointerList structure or NULL in case of an error.
*/
static xmlPointerListPtr
{
"xmlPointerListCreate: allocating item\n");
return (NULL);
}
if (initialSize > 0) {
}
return (ret);
}
/**
* xsltPointerListFree:
*
* Frees the xsltPointerList structure. This does not free
* the content of the list.
*/
static void
{
return;
}
/************************************************************************
* *
* Parser Types *
* *
************************************************************************/
/*
* Types are private:
*/
typedef enum {
XPATH_OP_END=0,
XPATH_OP_RESET, /* 10 */
XPATH_OP_VALUE, /* 12 */
XPATH_OP_FILTER, /* 17 */
XPATH_OP_SORT /* 18 */
#ifdef LIBXML_XPTR_ENABLED
#endif
} xmlXPathOp;
typedef enum {
AXIS_ANCESTOR = 1,
typedef enum {
NODE_TEST_NONE = 0,
NODE_TEST_TYPE = 1,
NODE_TEST_PI = 2,
NODE_TEST_ALL = 3,
NODE_TEST_NS = 4,
NODE_TEST_NAME = 5
typedef enum {
NODE_TYPE_NODE = 0,
#define XP_REWRITE_DOS_CHILD_ELEM 1
typedef struct _xmlXPathStepOp xmlXPathStepOp;
typedef xmlXPathStepOp *xmlXPathStepOpPtr;
struct _xmlXPathStepOp {
int ch1; /* First child */
int ch2; /* Second child */
int value;
int value2;
int value3;
void *value4;
void *value5;
void *cache;
void *cacheURI;
int rewriteType;
};
struct _xmlXPathCompExpr {
int nbStep; /* Number of steps in this expression */
int maxStep; /* Maximum number of steps allocated */
int last; /* index of last step in expression */
#ifdef DEBUG_EVAL_COUNTS
int nb;
#endif
#ifdef XPATH_STREAMING
#endif
};
/************************************************************************
* *
* Forward declarations *
* *
************************************************************************/
static void
static void
static int
static int
int isPredicate);
/************************************************************************
* *
* Parser Type functions *
* *
************************************************************************/
/**
* xmlXPathNewCompExpr:
*
* Create a new Xpath component
*
* Returns the newly allocated xmlXPathCompExprPtr or NULL in case of error
*/
static xmlXPathCompExprPtr
xmlXPathNewCompExpr(void) {
return(NULL);
}
sizeof(xmlXPathStepOp));
return(NULL);
}
#ifdef DEBUG_EVAL_COUNTS
#endif
return(cur);
}
/**
* xmlXPathFreeCompExpr:
* @comp: an XPATH comp
*
* Free up the memory allocated by @comp
*/
void
{
int i;
return;
else
}
}
} else {
}
}
}
}
#ifdef DEBUG_EVAL_COUNTS
}
#endif
#ifdef XPATH_STREAMING
}
#endif
}
}
/**
* xmlXPathCompExprAdd:
* @comp: the compiled expression
* @ch1: first child index
* @ch2: second child index
* @op: an op
* @value: the first int value
* @value2: the second int value
* @value3: the third int value
* @value4: the first string value
* @value5: the second string value
*
* Add a step to an XPath Compiled Expression
*
* Returns -1 in case of failure, the index otherwise
*/
static int
return(-1);
}
}
(op == XPATH_OP_COLLECT))) {
} else
} else
} else {
}
}
/**
* xmlXPathCompSwap:
* @comp: the compiled expression
* @op: operation index
*
* Swaps 2 operations in the compiled expression
*/
static void
int tmp;
#ifndef LIBXML_THREAD_ENABLED
/*
* Since this manipulates possibly shared variables, this is
* disabled if one detects that the library is used in a multithreaded
* application
*/
return;
#endif
}
/************************************************************************
* *
* XPath object cache structures *
* *
************************************************************************/
/* #define XP_DEFAULT_CACHE_ON */
typedef struct _xmlXPathContextCache xmlXPathContextCache;
typedef xmlXPathContextCache *xmlXPathContextCachePtr;
struct _xmlXPathContextCache {
int maxNodeset;
int maxString;
int maxBoolean;
int maxNumber;
int maxMisc;
#ifdef XP_DEBUG_OBJ_USAGE
int dbgCachedAll;
int dbgCachedNodeset;
int dbgCachedString;
int dbgCachedBool;
int dbgCachedNumber;
int dbgCachedPoint;
int dbgCachedRange;
int dbgCachedLocset;
int dbgCachedUsers;
int dbgCachedXSLTTree;
int dbgCachedUndefined;
int dbgReusedAll;
int dbgReusedNodeset;
int dbgReusedString;
int dbgReusedBool;
int dbgReusedNumber;
int dbgReusedPoint;
int dbgReusedRange;
int dbgReusedLocset;
int dbgReusedUsers;
int dbgReusedXSLTTree;
int dbgReusedUndefined;
#endif
};
/************************************************************************
* *
* Debugging related functions *
* *
************************************************************************/
#define STRANGE \
"Internal error at %s:%d\n", \
#ifdef LIBXML_DEBUG_ENABLED
static void
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
return;
}
else
}
static void
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
return;
}
}
}
static void
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
return;
}
}
}
}
static void
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
return;
}
}
#if defined(LIBXML_XPTR_ENABLED)
static void
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
return;
}
}
}
#endif /* LIBXML_XPTR_ENABLED */
/**
* xmlXPathDebugDumpObject:
* @output: the FILE * to dump the output
* @cur: the object to inspect
* @depth: indentation level
*
* Dump the content of the object for debugging purposes
*/
void
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
return;
}
case XPATH_UNDEFINED:
break;
case XPATH_NODESET:
break;
case XPATH_XSLT_TREE:
break;
case XPATH_BOOLEAN:
break;
case XPATH_NUMBER:
case 1:
break;
case -1:
break;
default:
} else {
}
}
break;
case XPATH_STRING:
break;
case XPATH_POINT:
break;
case XPATH_RANGE:
depth + 1);
} else {
depth + 1);
depth + 1);
}
break;
case XPATH_LOCATIONSET:
#if defined(LIBXML_XPTR_ENABLED)
#endif
break;
case XPATH_USERS:
break;
}
}
static void
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
return;
}
case XPATH_OP_END:
case XPATH_OP_AND:
case XPATH_OP_OR:
case XPATH_OP_EQUAL:
else
break;
case XPATH_OP_CMP:
else
break;
case XPATH_OP_PLUS:
break;
case XPATH_OP_MULT:
else
break;
case XPATH_OP_UNION:
case XPATH_OP_ROOT:
case XPATH_OP_NODE:
case XPATH_OP_RESET:
case XPATH_OP_SORT:
case XPATH_OP_COLLECT: {
switch (axis) {
case AXIS_ANCESTOR:
case AXIS_ANCESTOR_OR_SELF:
case AXIS_ATTRIBUTE:
case AXIS_CHILD:
case AXIS_DESCENDANT:
case AXIS_DESCENDANT_OR_SELF:
case AXIS_FOLLOWING:
case AXIS_FOLLOWING_SIBLING:
case AXIS_NAMESPACE:
case AXIS_PARENT:
case AXIS_PRECEDING:
case AXIS_PRECEDING_SIBLING:
case AXIS_SELF:
}
switch (test) {
case NODE_TEST_NONE:
case NODE_TEST_TYPE:
case NODE_TEST_PI:
case NODE_TEST_ALL:
case NODE_TEST_NS:
case NODE_TEST_NAME:
}
switch (type) {
case NODE_TYPE_NODE:
case NODE_TYPE_COMMENT:
case NODE_TYPE_TEXT:
case NODE_TYPE_PI:
}
break;
}
case XPATH_OP_VALUE: {
goto finish;
}
case XPATH_OP_VARIABLE: {
else
break;
}
case XPATH_OP_FUNCTION: {
else
break;
}
#ifdef LIBXML_XPTR_ENABLED
#endif
default:
}
}
/**
* xmlXPathDebugDumpCompExpr:
* @output: the FILE * for the output
* @comp: the precompiled XPath expression
* @depth: the indentation level.
*
* Dumps the tree of the compiled XPath expression.
*/
void
int depth) {
int i;
char shift[100];
for (i = 0;((i < depth) && (i < 25));i++)
}
#ifdef XP_DEBUG_OBJ_USAGE
/*
* XPath object usage related debugging variables.
*/
static int xmlXPathDebugObjCounterUndefined = 0;
static int xmlXPathDebugObjCounterNodeset = 0;
static int xmlXPathDebugObjCounterBool = 0;
static int xmlXPathDebugObjCounterNumber = 0;
static int xmlXPathDebugObjCounterString = 0;
static int xmlXPathDebugObjCounterPoint = 0;
static int xmlXPathDebugObjCounterRange = 0;
static int xmlXPathDebugObjCounterLocset = 0;
static int xmlXPathDebugObjCounterUsers = 0;
static int xmlXPathDebugObjCounterXSLTTree = 0;
static int xmlXPathDebugObjCounterAll = 0;
static int xmlXPathDebugObjTotalUndefined = 0;
static int xmlXPathDebugObjTotalNodeset = 0;
static int xmlXPathDebugObjTotalBool = 0;
static int xmlXPathDebugObjTotalNumber = 0;
static int xmlXPathDebugObjTotalString = 0;
static int xmlXPathDebugObjTotalPoint = 0;
static int xmlXPathDebugObjTotalRange = 0;
static int xmlXPathDebugObjTotalLocset = 0;
static int xmlXPathDebugObjTotalUsers = 0;
static int xmlXPathDebugObjTotalXSLTTree = 0;
static int xmlXPathDebugObjTotalAll = 0;
static int xmlXPathDebugObjMaxUndefined = 0;
static int xmlXPathDebugObjMaxNodeset = 0;
static int xmlXPathDebugObjMaxBool = 0;
static int xmlXPathDebugObjMaxNumber = 0;
static int xmlXPathDebugObjMaxString = 0;
static int xmlXPathDebugObjMaxPoint = 0;
static int xmlXPathDebugObjMaxRange = 0;
static int xmlXPathDebugObjMaxLocset = 0;
static int xmlXPathDebugObjMaxUsers = 0;
static int xmlXPathDebugObjMaxXSLTTree = 0;
static int xmlXPathDebugObjMaxAll = 0;
/* REVISIT TODO: Make this static when committing */
static void
{
cache->dbgCachedAll = 0;
cache->dbgCachedNodeset = 0;
cache->dbgCachedString = 0;
cache->dbgCachedBool = 0;
cache->dbgCachedNumber = 0;
cache->dbgCachedPoint = 0;
cache->dbgCachedRange = 0;
cache->dbgCachedLocset = 0;
cache->dbgCachedUsers = 0;
cache->dbgCachedXSLTTree = 0;
cache->dbgCachedUndefined = 0;
cache->dbgReusedAll = 0;
cache->dbgReusedNodeset = 0;
cache->dbgReusedString = 0;
cache->dbgReusedBool = 0;
cache->dbgReusedNumber = 0;
cache->dbgReusedPoint = 0;
cache->dbgReusedRange = 0;
cache->dbgReusedLocset = 0;
cache->dbgReusedUsers = 0;
cache->dbgReusedXSLTTree = 0;
cache->dbgReusedUndefined = 0;
}
}
}
static void
{
int isCached = 0;
isCached = 1;
cache->dbgReusedAll++;
switch (objType) {
case XPATH_UNDEFINED:
break;
case XPATH_NODESET:
break;
case XPATH_BOOLEAN:
cache->dbgReusedBool++;
break;
case XPATH_NUMBER:
cache->dbgReusedNumber++;
break;
case XPATH_STRING:
cache->dbgReusedString++;
break;
case XPATH_POINT:
cache->dbgReusedPoint++;
break;
case XPATH_RANGE:
cache->dbgReusedRange++;
break;
case XPATH_LOCATIONSET:
cache->dbgReusedLocset++;
break;
case XPATH_USERS:
cache->dbgReusedUsers++;
break;
case XPATH_XSLT_TREE:
break;
default:
break;
}
}
}
switch (objType) {
case XPATH_UNDEFINED:
if (! isCached)
break;
case XPATH_NODESET:
if (! isCached)
break;
case XPATH_BOOLEAN:
if (! isCached)
break;
case XPATH_NUMBER:
if (! isCached)
break;
case XPATH_STRING:
if (! isCached)
break;
case XPATH_POINT:
if (! isCached)
break;
case XPATH_RANGE:
if (! isCached)
break;
case XPATH_LOCATIONSET:
if (! isCached)
break;
case XPATH_USERS:
if (! isCached)
break;
case XPATH_XSLT_TREE:
if (! isCached)
break;
default:
break;
}
if (! isCached)
}
static void
{
int isCached = 0;
isCached = 1;
cache->dbgCachedAll++;
switch (objType) {
case XPATH_UNDEFINED:
break;
case XPATH_NODESET:
break;
case XPATH_BOOLEAN:
cache->dbgCachedBool++;
break;
case XPATH_NUMBER:
cache->dbgCachedNumber++;
break;
case XPATH_STRING:
cache->dbgCachedString++;
break;
case XPATH_POINT:
cache->dbgCachedPoint++;
break;
case XPATH_RANGE:
cache->dbgCachedRange++;
break;
case XPATH_LOCATIONSET:
cache->dbgCachedLocset++;
break;
case XPATH_USERS:
cache->dbgCachedUsers++;
break;
case XPATH_XSLT_TREE:
break;
default:
break;
}
}
}
switch (objType) {
case XPATH_UNDEFINED:
break;
case XPATH_NODESET:
break;
case XPATH_BOOLEAN:
break;
case XPATH_NUMBER:
break;
case XPATH_STRING:
break;
case XPATH_POINT:
break;
case XPATH_RANGE:
break;
case XPATH_LOCATIONSET:
break;
case XPATH_USERS:
break;
case XPATH_XSLT_TREE:
break;
default:
break;
}
}
/* REVISIT TODO: Make this static when committing */
static void
{
printf("# XPath object usage:\n");
reqNodeset += reNodeset;
if (cache->nodesetObjs)
if (cache->stringObjs)
if (cache->booleanObjs)
if (cache->numberObjs)
}
}
printf("# all\n");
printf("# node-sets\n");
printf("# strings\n");
printf("# booleans\n");
printf("# numbers\n");
printf("# XSLT result tree fragments\n");
printf("# undefined\n");
}
#endif /* XP_DEBUG_OBJ_USAGE */
#endif /* LIBXML_DEBUG_ENABLED */
/************************************************************************
* *
* XPath object caching *
* *
************************************************************************/
/**
* xmlXPathNewCache:
*
* Create a new object cache
*
* Returns the xmlXPathCache just allocated.
*/
static xmlXPathContextCachePtr
xmlXPathNewCache(void)
{
return(NULL);
}
return(ret);
}
static void
{
int i;
return;
/*
* Note that it is already assured that we don't need to
* look out for namespace nodes in the node-set.
*/
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
}
}
static void
{
return;
if (cache->nodesetObjs)
if (cache->stringObjs)
if (cache->booleanObjs)
if (cache->numberObjs)
}
/**
* xmlXPathContextSetCache:
*
* @ctxt: the XPath context
* @value: a value with semantics dependant on @options
* @options: options (currently only the value 0 is used)
*
* If activates XPath objects (xmlXPathObject) will be cached internally
* to be reused.
* @options:
* 0: This will set the XPath object caching:
* @value:
* This will set the maximum number of XPath objects
* to be cached per slot
* There are 5 slots for: node-set, string, number, boolean, and
* misc objects. Use <0 for the default number (100).
* Other values for @options have currently no effect.
*
* Returns 0 if the setting succeeded, and -1 on API or internal errors.
*/
int
int active,
int value,
int options)
{
return(-1);
if (active) {
return(-1);
}
if (options == 0) {
if (value < 0)
value = 100;
}
}
return(0);
}
/**
* xmlXPathCacheWrapNodeSet:
* @ctxt: the XPath context
* @val: the NodePtr value
*
* This is the cached version of xmlXPathWrapNodeSet().
* Wrap the Nodeset @val in a new xmlXPathObjectPtr
*
* Returns the created or reused object.
*/
static xmlXPathObjectPtr
{
{
ret = (xmlXPathObjectPtr)
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
}
return(xmlXPathWrapNodeSet(val));
}
/**
* xmlXPathCacheWrapString:
* @ctxt: the XPath context
* @val: the xmlChar * value
*
* This is the cached version of xmlXPathWrapString().
* Wraps the @val string into an XPath object.
*
* Returns the created or reused object.
*/
static xmlXPathObjectPtr
{
{
ret = (xmlXPathObjectPtr)
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
{
/*
* Fallback to misc-cache.
*/
ret = (xmlXPathObjectPtr)
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
}
return(xmlXPathWrapString(val));
}
/**
* xmlXPathCacheNewNodeSet:
* @ctxt: the XPath context
* @val: the NodePtr value
*
* This is the cached version of xmlXPathNewNodeSet().
* Acquire an xmlXPathObjectPtr of type NodeSet and initialize
* it with the single Node @val
*
* Returns the created or reused object.
*/
static xmlXPathObjectPtr
{
{
/*
* Use the nodset-cache.
*/
ret = (xmlXPathObjectPtr)
if (val) {
{
} else {
}
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
{
/*
* Fallback to misc-cache.
*/
ret = (xmlXPathObjectPtr)
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
}
return(xmlXPathNewNodeSet(val));
}
/**
* xmlXPathCacheNewCString:
* @ctxt: the XPath context
* @val: the char * value
*
* This is the cached version of xmlXPathNewCString().
* Acquire an xmlXPathObjectPtr of type string and of value @val
*
* Returns the created or reused object.
*/
static xmlXPathObjectPtr
{
{
ret = (xmlXPathObjectPtr)
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
{
ret = (xmlXPathObjectPtr)
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
}
return(xmlXPathNewCString(val));
}
/**
* xmlXPathCacheNewString:
* @ctxt: the XPath context
* @val: the xmlChar * value
*
* This is the cached version of xmlXPathNewString().
* Acquire an xmlXPathObjectPtr of type string and of value @val
*
* Returns the created or reused object.
*/
static xmlXPathObjectPtr
{
{
ret = (xmlXPathObjectPtr)
else
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
{
ret = (xmlXPathObjectPtr)
else
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
}
return(xmlXPathNewString(val));
}
/**
* xmlXPathCacheNewBoolean:
* @ctxt: the XPath context
* @val: the boolean value
*
* This is the cached version of xmlXPathNewBoolean().
* Acquires an xmlXPathObjectPtr of type boolean and of value @val
*
* Returns the created or reused object.
*/
static xmlXPathObjectPtr
{
{
ret = (xmlXPathObjectPtr)
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
{
ret = (xmlXPathObjectPtr)
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
}
return(xmlXPathNewBoolean(val));
}
/**
* xmlXPathCacheNewFloat:
* @ctxt: the XPath context
* @val: the double value
*
* This is the cached version of xmlXPathNewFloat().
* Acquires an xmlXPathObjectPtr of type double and of value @val
*
* Returns the created or reused object.
*/
static xmlXPathObjectPtr
{
{
ret = (xmlXPathObjectPtr)
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
{
ret = (xmlXPathObjectPtr)
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
}
return(xmlXPathNewFloat(val));
}
/**
* xmlXPathCacheConvertString:
* @ctxt: the XPath context
* @val: an XPath object
*
* This is the cached version of xmlXPathConvertString().
* Converts an existing object to its string() equivalent
*
* Returns a created or reused object, the old one is freed (cached)
* (or the operation is done directly on @val)
*/
static xmlXPathObjectPtr
case XPATH_UNDEFINED:
#ifdef DEBUG_EXPR
#endif
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
case XPATH_STRING:
return(val);
case XPATH_BOOLEAN:
break;
case XPATH_NUMBER:
break;
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
TODO;
break;
}
}
/**
* xmlXPathCacheObjectCopy:
* @ctxt: the XPath context
* @val: the original object
*
* This is the cached version of xmlXPathObjectCopy().
* Acquire a copy of a given object
*
* Returns a created or reused created object.
*/
static xmlXPathObjectPtr
{
return(NULL);
if (XP_HAS_CACHE(ctxt)) {
case XPATH_NODESET:
return(xmlXPathCacheWrapNodeSet(ctxt,
case XPATH_STRING:
case XPATH_BOOLEAN:
case XPATH_NUMBER:
default:
break;
}
}
return(xmlXPathObjectCopy(val));
}
/**
* xmlXPathCacheConvertBoolean:
* @ctxt: the XPath context
* @val: an XPath object
*
* This is the cached version of xmlXPathConvertBoolean().
* Converts an existing object to its boolean() equivalent
*
* Returns a created or reused object, the old one is freed (or the operation
* is done directly on @val)
*/
static xmlXPathObjectPtr
return(xmlXPathCacheNewBoolean(ctxt, 0));
return(val);
return(ret);
}
/**
* xmlXPathCacheConvertNumber:
* @ctxt: the XPath context
* @val: an XPath object
*
* This is the cached version of xmlXPathConvertNumber().
* Converts an existing object to its number() equivalent
*
* Returns a created or reused object, the old one is freed (or the operation
* is done directly on @val)
*/
static xmlXPathObjectPtr
return(val);
return(ret);
}
/************************************************************************
* *
* Parser stacks related functions and macros *
* *
************************************************************************/
/**
* valuePop:
* @ctxt: an XPath evaluation context
*
* Pops the top XPath object from the value stack
*
* Returns the XPath object just removed
*/
{
return (NULL);
else
return (ret);
}
/**
* valuePush:
* @ctxt: an XPath evaluation context
* @value: the XPath object
*
* Pushes a new XPath object on top of the value stack
*
* returns the number of items on the value stack
*/
int
{
return (0);
}
}
}
/**
* xmlXPathPopBoolean:
* @ctxt: an XPath parser context
*
* Pops a boolean from the stack, handling conversion if needed.
* Check error with #xmlXPathCheckError.
*
* Returns the boolean
*/
int
int ret;
return(0);
}
else
return(ret);
}
/**
* xmlXPathPopNumber:
* @ctxt: an XPath parser context
*
* Pops a number from the stack, handling conversion if needed.
* Check error with #xmlXPathCheckError.
*
* Returns the number
*/
double
double ret;
return(0);
}
else
return(ret);
}
/**
* xmlXPathPopString:
* @ctxt: an XPath parser context
*
* Pops a string from the stack, handling conversion if needed.
* Check error with #xmlXPathCheckError.
*
* Returns the string
*/
xmlChar *
return(NULL);
}
/* TODO: needs refactoring somewhere else */
return(ret);
}
/**
* xmlXPathPopNodeSet:
* @ctxt: an XPath parser context
*
* Pops a node-set from the stack, handling conversion if needed.
* Check error with #xmlXPathCheckError.
*
* Returns the node-set
*/
return(NULL);
}
if (!xmlXPathStackIsNodeSet(ctxt)) {
return(NULL);
}
#if 0
/* to fix memory leak of not clearing obj->user */
#endif
return(ret);
}
/**
* xmlXPathPopExternal:
* @ctxt: an XPath parser context
*
* Pops an external object from the stack, handling conversion if needed.
* Check error with #xmlXPathCheckError.
*
* Returns the object
*/
void *
void * ret;
return(NULL);
}
return(NULL);
}
return(ret);
}
/*
* Macros for accessing the content. Those should be used only by the parser,
* and not exported.
*
* Dirty macros, i.e. one need to make assumption on the context to use them
*
* CUR_PTR return the current pointer to the xmlChar to be parsed.
* CUR returns the current xmlChar value, i.e. a 8 bit value
* in ISO-Latin or UTF-8.
* This should be used internally by the parser
* only to compare to ASCII values otherwise it would break when
* running with UTF-8 encoding.
* NXT(n) returns the n'th next xmlChar. Same as CUR is should be used only
* to compare on ASCII based substring.
* SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined
* strings within the parser.
* CURRENT Returns the current char value, with the full decoding of
* UTF-8 if we are using this mode. It returns an int.
* NEXT Skip to the next character, this does the proper decoding
* in UTF-8 mode. It also pop-up unfinished entities on the fly.
* It returns the pointer to the current xmlChar.
*/
#define COPY_BUF(l,b,i,v) \
if (l == 1) b[i++] = (xmlChar) v; \
else i += xmlCopyChar(l,&b[i],v)
#define SKIP_BLANKS \
#ifndef DBL_DIG
#define DBL_DIG 16
#endif
#ifndef DBL_EPSILON
#define DBL_EPSILON 1E-9
#endif
#define UPPER_DOUBLE 1E9
#define LOWER_DOUBLE 1E-5
#define LOWER_DOUBLE_EXP 5
#define INTEGER_DIGITS DBL_DIG
/**
* xmlXPathFormatNumber:
* @number: number to format
* @buffer: output buffer
* @buffersize: size of output buffer
*
* Convert the number into a string representation.
*/
static void
{
switch (xmlXPathIsInf(number)) {
case 1:
if (buffersize > (int)sizeof("Infinity"))
break;
case -1:
if (buffersize > (int)sizeof("-Infinity"))
break;
default:
if (xmlXPathIsNaN(number)) {
if (buffersize > (int)sizeof("NaN"))
char work[30];
if (value == 0) {
*ptr++ = '0';
} else {
}
}
*ptr = 0;
} else if (buffersize > 0) {
ptr--;
*ptr = 0;
}
} else {
/*
For the dimension of work,
DBL_DIG is number of significant digits
EXPONENT is only needed for "scientific notation"
3 is sign, decimal point, and terminating zero
LOWER_DOUBLE_EXP is max number of leading zeroes in fraction
Note that this dimension is slightly (a few characters)
larger than actually necessary.
*/
int integer_place, fraction_place;
char *ptr;
char *after_fraction;
double absolute_value;
int size;
/*
* First choose format - scientific or regular floating point.
* In either case, result is in work, and after_fraction points
* just past the fractional part.
*/
if ( ((absolute_value > UPPER_DOUBLE) ||
(absolute_value < LOWER_DOUBLE)) &&
(absolute_value != 0.0) ) {
/* Use scientific notation */
}
else {
/* Use regular notation */
if (absolute_value > 0.0) {
if (integer_place > 0)
else
} else {
fraction_place = 1;
}
}
/* Remove fractional trailing zeroes */
while (*(--ptr) == '0')
;
if (*ptr != '.')
ptr++;
while ((*ptr++ = *after_fraction++) != 0);
/* Finally copy result back to caller */
if (size > buffersize) {
size = buffersize;
}
}
break;
}
}
/************************************************************************
* *
* Routines to handle NodeSets *
* *
************************************************************************/
/**
* xmlXPathOrderDocElems:
* @doc: an input document
*
* Call this routine to speed up XPath computation on static documents.
* This stamps all the element nodes with the document order
* Like for line information, the order is kept in the element->content
* field, the value stored is actually - the node number (starting at -1)
* to be able to differentiate from line numbers.
*
* Returns the number of elements found in the document or -1 in case
* of error.
*/
long
long count = 0;
return(-1);
continue;
}
}
continue;
}
do {
break;
break;
}
break;
}
}
return(count);
}
/**
* xmlXPathCmpNodes:
* @node1: the first node
* @node2: the second node
*
* Compare two nodes w.r.t document order
*
* Returns -2 in case of error 1 if first point < second point, 0 if
* it's the same node, -1 otherwise
*/
int
return(-2);
/*
* a couple of optimizations which will avoid computations in most cases
*/
return(0);
attr1 = 1;
}
attr2 = 1;
}
/* not required, but we keep attributes in order */
if (attr1 != 0) {
return (1);
}
return (-1);
}
return(0);
}
if (attr2 == 1)
return(1);
return(-1);
}
return(1);
return(1);
return(-1);
/*
* Speedup using document order if availble.
*/
return(1);
return(-1);
}
/*
* compute depth to root
*/
return(1);
depth2++;
}
return(-1);
depth1++;
}
/*
* Distinct document (or distinct entities :-( ) case.
*/
return(-2);
}
/*
* get the nearest common ancestor.
*/
depth1--;
}
depth2--;
}
/* should not happen but just in case ... */
return(-2);
}
/*
* Find who's first.
*/
return(1);
return(-1);
/*
* Speedup using document order if availble.
*/
return(1);
return(-1);
}
return(1);
return(-1); /* assume there is no sibling list corruption */
}
/**
* xmlXPathCmpNodesExt:
* @node1: the first node
* @node2: the second node
*
* Compare two nodes w.r.t document order.
* This one is optimized for handling of non-element nodes.
*
* Returns -2 in case of error 1 if first point < second point, 0 if
* it's the same node, -1 otherwise
*/
static int
return(-2);
return(0);
/*
* a couple of optimizations which will avoid computations in most cases
*/
case XML_ELEMENT_NODE:
{
return(1);
return(-1);
} else
goto turtle_comparison;
}
break;
case XML_ATTRIBUTE_NODE:
misc = 1;
break;
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_COMMENT_NODE:
case XML_PI_NODE: {
/*
* Find nearest element node.
*/
do {
break;
}
/*
* URGENT TODO: Are there any cases, where the
* parent of such a node is not an element node?
*/
break;
}
} while (1);
} else {
}
/*
* Fallback for whatever case.
*/
precedence1 = 0;
} else
misc = 1;
}
break;
case XML_NAMESPACE_DECL:
/*
* TODO: why do we return 1 for namespace nodes?
*/
return(1);
default:
break;
}
case XML_ELEMENT_NODE:
break;
case XML_ATTRIBUTE_NODE:
misc = 1;
break;
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_COMMENT_NODE:
case XML_PI_NODE: {
do {
break;
}
break;
}
} while (1);
} else {
}
{
precedence2 = 0;
} else
misc = 1;
}
break;
case XML_NAMESPACE_DECL:
return(1);
default:
break;
}
if (misc) {
if (precedence1 == precedence2) {
/*
* The ugly case; but normally there aren't many
* adjacent non-element nodes around.
*/
return(1);
return(-1);
}
return (-1);
} else {
/*
* Evaluate based on higher precedence wrt to the element.
* TODO: This assumes attributes are sorted before content.
* Is this 100% correct?
*/
if (precedence1 < precedence2)
return(1);
else
return(-1);
}
}
/*
* Special case: One of the helper-elements is contained by the other.
* <foo>
* <node2>
* <node1>Text-1(precedence1 == 2)</node1>
* </node2>
* Text-6(precedence2 == 3)
* </foo>
*/
while (cur) {
return(1);
}
}
while (cur) {
return(-1);
}
}
}
/*
* Speedup using document order if availble.
*/
return(1);
return(-1);
}
return(1);
return(-1);
/*
* compute depth to root
*/
return(1);
depth2++;
}
return(-1);
depth1++;
}
/*
* Distinct document (or distinct entities :-( ) case.
*/
return(-2);
}
/*
* get the nearest common ancestor.
*/
depth1--;
}
depth2--;
}
/* should not happen but just in case ... */
return(-2);
}
/*
* Find who's first.
*/
return(1);
return(-1);
/*
* Speedup using document order if availble.
*/
return(1);
return(-1);
}
return(1);
return(-1); /* assume there is no sibling list corruption */
}
#endif /* XP_OPTIMIZED_NON_ELEM_COMPARISON */
/**
* xmlXPathNodeSetSort:
* @set: the node set
*
* Sort the node set in document order
*/
void
return;
/* Use Shell's sort to sort the node-set */
j = i - incr;
while (j >= 0) {
#else
#endif
{
j -= incr;
} else
break;
}
}
}
}
#define XML_NODESET_DEFAULT 10
/**
* xmlXPathNodeSetDupNs:
* @node: the parent node of the namespace XPath node
* @ns: the libxml namespace declaration node.
*
* Namespace node in libxml don't match the XPath semantic. In a node set
* the namespace nodes are duplicated and the next pointer is set to the
* parent node in the XPath semantic.
*
* Returns the newly created object.
*/
static xmlNodePtr
return(NULL);
return((xmlNodePtr) ns);
/*
* Allocate a new Namespace and fill the fields.
*/
return(NULL);
}
return((xmlNodePtr) cur);
}
/**
* xmlXPathNodeSetFreeNs:
* @ns: the XPath namespace node found in a nodeset.
*
* Namespace nodes in libxml don't match the XPath semantic. In a node set
* the namespace nodes are duplicated and the next pointer is set to the
* parent node in the XPath semantic. Check if such a node needs to be freed
*/
void
return;
}
}
/**
* xmlXPathNodeSetCreate:
* @val: an initial xmlNodePtr, or NULL
*
* Create a new xmlNodeSetPtr of type double and of value @val
*
* Returns the newly created object.
*/
return(NULL);
}
sizeof(xmlNodePtr));
return(NULL);
}
} else
}
return(ret);
}
/**
* xmlXPathNodeSetCreateSize:
* @size: the initial size of the set
*
* Create a new xmlNodeSetPtr of type double and of value @val
*
* Returns the newly created object.
*/
static xmlNodeSetPtr
xmlXPathNodeSetCreateSize(int size) {
return(NULL);
}
if (size < XML_NODESET_DEFAULT)
return(NULL);
}
return(ret);
}
/**
* xmlXPathNodeSetContains:
* @cur: the node-set
* @val: the node
*
* checks whether @cur contains @val
*
* Returns true (1) if @cur contains @val, false (0) otherwise
*/
int
int i;
return(1);
return(1);
}
}
} else {
return(1);
}
}
return(0);
}
/**
* xmlXPathNodeSetAddNs:
* @cur: the initial node set
* @node: the hosting node
* @ns: a the namespace node
*
* add a new namespace node to an existing NodeSet
*/
void
int i;
return;
/* @@ with_ns to check whether namespace nodes should be looked at @@ */
/*
* prevent duplicates
*/
return;
}
/*
* grow the nodeTab if needed
*/
sizeof(xmlNodePtr));
return;
}
sizeof(xmlNodePtr));
return;
}
}
}
/**
* xmlXPathNodeSetAdd:
* @cur: the initial node set
* @val: a new xmlNodePtr
*
* add a new xmlNodePtr to an existing NodeSet
*/
void
int i;
#if 0
return; /* an XSLT fake node */
#endif
/* @@ with_ns to check whether namespace nodes should be looked at @@ */
/*
* prevent duplcates
*/
/*
* grow the nodeTab if needed
*/
sizeof(xmlNodePtr));
return;
}
sizeof(xmlNodePtr));
return;
}
}
} else
}
/**
* xmlXPathNodeSetAddUnique:
* @cur: the initial node set
* @val: a new xmlNodePtr
*
* add a new xmlNodePtr to an existing NodeSet, optimized version
* when we are sure the node is not already in the set.
*/
void
#if 0
return; /* an XSLT fake node */
#endif
/* @@ with_ns to check whether namespace nodes should be looked at @@ */
/*
* grow the nodeTab if needed
*/
sizeof(xmlNodePtr));
return;
}
sizeof(xmlNodePtr));
return;
}
}
} else
}
/**
* xmlXPathNodeSetMerge:
* @val1: the first NodeSet or NULL
* @val2: the second NodeSet
*
* Merges two nodesets, all nodes from @val2 are added to @val1
* if @val1 is NULL, a new set is created and copied from @val2
*
* Returns @val1 once extended or NULL in case of error.
*/
#if 0
/*
* TODO: The optimization won't work in every case, since
* those nasty namespace nodes need to be added with
* xmlXPathNodeSetDupNs() to the set; thus a pure
* memcpy is not possible.
* If there was a flag on the nodesetval, indicating that
* some temporary nodes are in, that would be helpfull.
*/
/*
* Optimization: Create an equally sized node-set
* and memcpy the content.
*/
return(NULL);
else {
}
}
return(val1);
#endif
}
/* @@ with_ns to check whether namespace nodes should be looked at @@ */
/*
* check against duplicates
*/
skip = 0;
for (j = 0; j < initNr; j++) {
skip = 1;
break;
{
skip = 1;
break;
}
}
}
if (skip)
continue;
/*
* grow the nodeTab if needed
*/
sizeof(xmlNodePtr));
return(NULL);
}
sizeof(xmlNodePtr));
return(NULL);
}
}
} else
}
return(val1);
}
#if 0 /* xmlXPathNodeSetMergeUnique() is currently not used anymore */
/**
* xmlXPathNodeSetMergeUnique:
* @val1: the first NodeSet or NULL
* @val2: the second NodeSet
*
* Merges two nodesets, all nodes from @val2 are added to @val1
* if @val1 is NULL, a new set is created and copied from @val2
*
* Returns @val1 once extended or NULL in case of error.
*/
static xmlNodeSetPtr
int i;
}
/* @@ with_ns to check whether namespace nodes should be looked at @@ */
/*
* grow the nodeTab if needed
*/
sizeof(xmlNodePtr));
return(NULL);
}
sizeof(xmlNodePtr));
return(NULL);
}
}
} else
}
return(val1);
}
#endif /* xmlXPathNodeSetMergeUnique() is currently not used anymore */
/**
* xmlXPathNodeSetMergeAndClear:
* @set1: the first NodeSet or NULL
* @set2: the second NodeSet
* @hasSet2NsNodes: 1 if set2 contains namespaces nodes
*
* Merges two nodesets, all nodes from @set2 are added to @set1
* if @set1 is NULL, a new set is created and copied from @set2.
* Checks for duplicate nodes. Clears set2.
*
* Returns @set1 once extended or NULL in case of error.
*/
static xmlNodeSetPtr
int hasNullEntries)
{
/*
* Note that doing a memcpy of the list, namespace nodes are
* just assigned to set1, since set2 is cleared anyway.
*/
return(NULL);
}
} else {
int i, j, initNbSet1;
/*
* Skip NULLed entries.
*/
continue;
/*
* Skip duplicates.
*/
for (j = 0; j < initNbSet1; j++) {
goto skip_node;
{
{
/*
* Free the namespace node.
*/
goto skip_node;
}
}
}
/*
* grow the nodeTab if needed
*/
XML_NODESET_DEFAULT * sizeof(xmlNodePtr));
return(NULL);
}
return(NULL);
}
}
} else
{}
}
}
return(set1);
}
/**
* xmlXPathNodeSetMergeAndClearNoDupls:
* @set1: the first NodeSet or NULL
* @set2: the second NodeSet
* @hasSet2NsNodes: 1 if set2 contains namespaces nodes
*
* Merges two nodesets, all nodes from @set2 are added to @set1
* if @set1 is NULL, a new set is created and copied from @set2.
* Doesn't chack for duplicate nodes. Clears set2.
*
* Returns @set1 once extended or NULL in case of error.
*/
static xmlNodeSetPtr
int hasNullEntries)
{
return(set1);
/*
* Note that doing a memcpy of the list, namespace nodes are
* just assigned to set1, since set2 is cleared anyway.
*/
return(NULL);
}
} else {
int i;
/*
* Skip NULLed entries.
*/
continue;
XML_NODESET_DEFAULT * sizeof(xmlNodePtr));
return(NULL);
}
return(NULL);
}
}
}
}
return(set1);
}
/**
* xmlXPathNodeSetDel:
* @cur: the initial node set
* @val: an xmlNodePtr
*
* Removes an xmlNodePtr from an existing NodeSet
*/
void
int i;
/*
* find node in nodeTab
*/
#ifdef DEBUG
"xmlXPathNodeSetDel: Node %s wasn't found in NodeList\n",
#endif
return;
}
}
/**
* xmlXPathNodeSetRemove:
* @cur: the initial node set
* @val: the index to remove
*
* Removes an entry from an existing NodeSet list.
*/
void
}
/**
* xmlXPathFreeNodeSet:
* @obj: the xmlNodeSetPtr to free
*
* Free the NodeSet compound (not the actual nodes !).
*/
void
int i;
/* @@ with_ns to check whether namespace nodes should be looked at @@ */
}
}
/**
* xmlXPathNodeSetClear:
* @set: the node set to clear
*
* Clears the list from all temporary XPath objects (e.g. namespace nodes
* are feed), but does *not* free the list itself. Sets the length of the
* list to 0.
*/
static void
{
return;
else if (hasNsNodes) {
int i;
}
}
}
/**
* xmlXPathNodeSetClearFromPos:
* @set: the node set to be cleared
* @pos: the start position to clear from
*
* Clears the list from temporary XPath objects (e.g. namespace nodes
* are feed) starting with the entry at @pos, but does *not* free the list
* itself. Sets the length of the list to @pos.
*/
static void
{
return;
else if ((hasNsNodes)) {
int i;
}
}
}
/**
* xmlXPathFreeValueTree:
* @obj: the xmlNodeSetPtr to free
*
* Free the NodeSet compound and the actual tree, this is different
* from xmlXPathFreeNodeSet()
*/
static void
int i;
} else {
}
}
}
}
}
#if defined(DEBUG) || defined(DEBUG_STEP)
/**
* xmlGenericErrorContextNodeSet:
* @output: a FILE * for the output
* @obj: the xmlNodeSetPtr to display
*
* Quick display of a NodeSet
*/
void
int i;
return;
}
return;
}
return;
}
return;
}
}
}
#endif
/**
* xmlXPathNewNodeSet:
* @val: the NodePtr value
*
* Create a new xmlXPathObjectPtr of type NodeSet and initialize
* it with the single Node @val
*
* Returns the newly created object.
*/
return(NULL);
}
/* @@ with_ns to check whether namespace nodes should be looked at @@ */
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
/**
* xmlXPathNewValueTree:
* @val: the NodePtr value
*
* Create a new xmlXPathObjectPtr of type Value Tree (XSLT) and initialize
* it with the tree root @val
*
* Returns the newly created object.
*/
return(NULL);
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
/**
* xmlXPathNewNodeSetList:
* @val: an existing NodeSet
*
* Create a new xmlXPathObjectPtr of type NodeSet and initialize
* it with the Nodeset @val
*
* Returns the newly created object.
*/
{
int i;
else {
}
return (ret);
}
/**
* xmlXPathWrapNodeSet:
* @val: the NodePtr value
*
* Wrap the Nodeset @val in a new xmlXPathObjectPtr
*
* Returns the newly created object.
*/
return(NULL);
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
/**
* xmlXPathFreeNodeSetList:
* @obj: an existing NodeSetList object
*
* Free up the xmlXPathObjectPtr @obj but don't deallocate the objects in
* the list contrary to xmlXPathFreeObject().
*/
void
#ifdef XP_DEBUG_OBJ_USAGE
#endif
}
/**
* xmlXPathDifference:
* @nodes1: a node-set
* @nodes2: a node-set
*
* Implements the EXSLT - Sets difference() function:
* node-set set:difference (node-set, node-set)
*
* Returns the difference between the two node sets, or nodes1 if
* nodes2 is empty
*/
int i, l1;
if (xmlXPathNodeSetIsEmpty(nodes2))
return(nodes1);
if (xmlXPathNodeSetIsEmpty(nodes1))
return(ret);
for (i = 0; i < l1; i++) {
}
return(ret);
}
/**
* xmlXPathIntersection:
* @nodes1: a node-set
* @nodes2: a node-set
*
* Implements the EXSLT - Sets intersection() function:
* node-set set:intersection (node-set, node-set)
*
* Returns a node set comprising the nodes that are within both the
* node sets passed as arguments
*/
int i, l1;
if (xmlXPathNodeSetIsEmpty(nodes1))
return(ret);
if (xmlXPathNodeSetIsEmpty(nodes2))
return(ret);
for (i = 0; i < l1; i++) {
}
return(ret);
}
/**
* xmlXPathDistinctSorted:
* @nodes: a node-set, sorted by document order
*
* Implements the EXSLT - Sets distinct() function:
* node-set set:distinct (node-set)
*
* Returns a subset of the nodes contained in @nodes, or @nodes if
* it is empty
*/
int i, l;
if (xmlXPathNodeSetIsEmpty(nodes))
return(nodes);
hash = xmlHashCreate (l);
for (i = 0; i < l; i++) {
} else {
}
}
return(ret);
}
/**
* xmlXPathDistinct:
* @nodes: a node-set
*
* Implements the EXSLT - Sets distinct() function:
* node-set set:distinct (node-set)
* @nodes is sorted by document order, then #exslSetsDistinctSorted
* is called with the sorted node-set
*
* Returns a subset of the nodes contained in @nodes, or @nodes if
* it is empty
*/
if (xmlXPathNodeSetIsEmpty(nodes))
return(nodes);
return(xmlXPathDistinctSorted(nodes));
}
/**
* xmlXPathHasSameNodes:
* @nodes1: a node-set
* @nodes2: a node-set
*
* Implements the EXSLT - Sets has-same-nodes function:
* boolean set:has-same-node(node-set, node-set)
*
* Returns true (1) if @nodes1 shares any node with @nodes2, false (0)
* otherwise
*/
int
int i, l;
if (xmlXPathNodeSetIsEmpty(nodes1) ||
return(0);
for (i = 0; i < l; i++) {
return(1);
}
return(0);
}
/**
* xmlXPathNodeLeadingSorted:
* @nodes: a node-set, sorted by document order
* @node: a node
*
* Implements the EXSLT - Sets leading() function:
* node-set set:leading (node-set, node-set)
*
* Returns the nodes in @nodes that precede @node in document order,
* @nodes if @node is NULL or an empty node-set if @nodes
* doesn't contain @node
*/
int i, l;
return(nodes);
if (xmlXPathNodeSetIsEmpty(nodes) ||
return(ret);
for (i = 0; i < l; i++) {
break;
}
return(ret);
}
/**
* xmlXPathNodeLeading:
* @nodes: a node-set
* @node: a node
*
* Implements the EXSLT - Sets leading() function:
* node-set set:leading (node-set, node-set)
* @nodes is sorted by document order, then #exslSetsNodeLeadingSorted
* is called.
*
* Returns the nodes in @nodes that precede @node in document order,
* @nodes if @node is NULL or an empty node-set if @nodes
* doesn't contain @node
*/
}
/**
* xmlXPathLeadingSorted:
* @nodes1: a node-set, sorted by document order
* @nodes2: a node-set, sorted by document order
*
* Implements the EXSLT - Sets leading() function:
* node-set set:leading (node-set, node-set)
*
* Returns the nodes in @nodes1 that precede the first node in @nodes2
* in document order, @nodes1 if @nodes2 is NULL or empty or
* an empty node-set if @nodes1 doesn't contain @nodes2
*/
if (xmlXPathNodeSetIsEmpty(nodes2))
return(nodes1);
return(xmlXPathNodeLeadingSorted(nodes1,
}
/**
* xmlXPathLeading:
* @nodes1: a node-set
* @nodes2: a node-set
*
* Implements the EXSLT - Sets leading() function:
* node-set set:leading (node-set, node-set)
* @nodes1 and @nodes2 are sorted by document order, then
* #exslSetsLeadingSorted is called.
*
* Returns the nodes in @nodes1 that precede the first node in @nodes2
* in document order, @nodes1 if @nodes2 is NULL or empty or
* an empty node-set if @nodes1 doesn't contain @nodes2
*/
if (xmlXPathNodeSetIsEmpty(nodes2))
return(nodes1);
if (xmlXPathNodeSetIsEmpty(nodes1))
return(xmlXPathNodeSetCreate(NULL));
return(xmlXPathNodeLeadingSorted(nodes1,
}
/**
* xmlXPathNodeTrailingSorted:
* @nodes: a node-set, sorted by document order
* @node: a node
*
* Implements the EXSLT - Sets trailing() function:
* node-set set:trailing (node-set, node-set)
*
* Returns the nodes in @nodes that follow @node in document order,
* @nodes if @node is NULL or an empty node-set if @nodes
* doesn't contain @node
*/
int i, l;
return(nodes);
if (xmlXPathNodeSetIsEmpty(nodes) ||
return(ret);
for (i = l - 1; i >= 0; i--) {
break;
}
return(ret);
}
/**
* xmlXPathNodeTrailing:
* @nodes: a node-set
* @node: a node
*
* Implements the EXSLT - Sets trailing() function:
* node-set set:trailing (node-set, node-set)
* @nodes is sorted by document order, then #xmlXPathNodeTrailingSorted
* is called.
*
* Returns the nodes in @nodes that follow @node in document order,
* @nodes if @node is NULL or an empty node-set if @nodes
* doesn't contain @node
*/
}
/**
* xmlXPathTrailingSorted:
* @nodes1: a node-set, sorted by document order
* @nodes2: a node-set, sorted by document order
*
* Implements the EXSLT - Sets trailing() function:
* node-set set:trailing (node-set, node-set)
*
* Returns the nodes in @nodes1 that follow the first node in @nodes2
* in document order, @nodes1 if @nodes2 is NULL or empty or
* an empty node-set if @nodes1 doesn't contain @nodes2
*/
if (xmlXPathNodeSetIsEmpty(nodes2))
return(nodes1);
return(xmlXPathNodeTrailingSorted(nodes1,
xmlXPathNodeSetItem(nodes2, 0)));
}
/**
* xmlXPathTrailing:
* @nodes1: a node-set
* @nodes2: a node-set
*
* Implements the EXSLT - Sets trailing() function:
* node-set set:trailing (node-set, node-set)
* @nodes1 and @nodes2 are sorted by document order, then
* #xmlXPathTrailingSorted is called.
*
* Returns the nodes in @nodes1 that follow the first node in @nodes2
* in document order, @nodes1 if @nodes2 is NULL or empty or
* an empty node-set if @nodes1 doesn't contain @nodes2
*/
if (xmlXPathNodeSetIsEmpty(nodes2))
return(nodes1);
if (xmlXPathNodeSetIsEmpty(nodes1))
return(xmlXPathNodeSetCreate(NULL));
return(xmlXPathNodeTrailingSorted(nodes1,
xmlXPathNodeSetItem(nodes2, 0)));
}
/************************************************************************
* *
* Routines to handle extra functions *
* *
************************************************************************/
/**
* xmlXPathRegisterFunc:
* @ctxt: the XPath context
* @name: the function name
* @f: the function implementation or NULL
*
* Register a new function. If @f is NULL it unregisters the function
*
* Returns 0 in case of success, -1 in case of error
*/
int
xmlXPathFunction f) {
}
/**
* xmlXPathRegisterFuncNS:
* @ctxt: the XPath context
* @name: the function name
* @ns_uri: the function namespace URI
* @f: the function implementation or NULL
*
* Register a new function. If @f is NULL it unregisters the function
*
* Returns 0 in case of success, -1 in case of error
*/
int
return(-1);
return(-1);
return(-1);
if (f == NULL)
}
/**
* xmlXPathRegisterFuncLookup:
* @ctxt: the XPath context
* @f: the lookup function
* @funcCtxt: the lookup data
*
* Registers an external mechanism to do function lookup.
*/
void
void *funcCtxt) {
return;
ctxt->funcLookupFunc = f;
}
/**
* xmlXPathFunctionLookup:
* @ctxt: the XPath context
* @name: the function name
*
* Search in the Function array of the context for the given
* function.
*
* Returns the xmlXPathFunction or NULL if not found
*/
return (NULL);
f = ctxt->funcLookupFunc;
return(ret);
}
}
/**
* xmlXPathFunctionLookupNS:
* @ctxt: the XPath context
* @name: the function name
* @ns_uri: the function namespace URI
*
* Search in the Function array of the context for the given
* function.
*
* Returns the xmlXPathFunction or NULL if not found
*/
return(NULL);
return(NULL);
f = ctxt->funcLookupFunc;
return(ret);
}
return(NULL);
return(ret);
}
/**
* xmlXPathRegisteredFuncsCleanup:
* @ctxt: the XPath context
*
* Cleanup the XPath context data associated to registered functions
*/
void
return;
}
/************************************************************************
* *
* Routines to handle Variables *
* *
************************************************************************/
/**
* xmlXPathRegisterVariable:
* @ctxt: the XPath context
* @name: the variable name
* @value: the variable value or NULL
*
* Register a new variable value. If @value is NULL it unregisters
* the variable
*
* Returns 0 in case of success, -1 in case of error
*/
int
}
/**
* xmlXPathRegisterVariableNS:
* @ctxt: the XPath context
* @name: the variable name
* @ns_uri: the variable namespace URI
* @value: the variable value or NULL
*
* Register a new variable value. If @value is NULL it unregisters
* the variable
*
* Returns 0 in case of success, -1 in case of error
*/
int
return(-1);
return(-1);
return(-1);
(void *) value,
}
/**
* xmlXPathRegisterVariableLookup:
* @ctxt: the XPath context
* @f: the lookup function
* @data: the lookup data
*
* register an external mechanism to do variable lookup
*/
void
xmlXPathVariableLookupFunc f, void *data) {
return;
ctxt->varLookupFunc = f;
}
/**
* xmlXPathVariableLookup:
* @ctxt: the XPath context
* @name: the variable name
*
* Search in the Variable array of the context for the given
* variable value.
*
* Returns a copy of the value or NULL if not found
*/
return(NULL);
return(ret);
}
}
/**
* xmlXPathVariableLookupNS:
* @ctxt: the XPath context
* @name: the variable name
* @ns_uri: the variable namespace URI
*
* Search in the Variable array of the context for the given
* variable value.
*
* Returns the a copy of the value or NULL if not found
*/
return(NULL);
}
return(NULL);
return(NULL);
}
/**
* xmlXPathRegisteredVariablesCleanup:
* @ctxt: the XPath context
*
* Cleanup the XPath context data associated to registered variables
*/
void
return;
}
/**
* xmlXPathRegisterNs:
* @ctxt: the XPath context
* @prefix: the namespace prefix
* @ns_uri: the namespace name
*
* Register a new namespace. If @ns_uri is NULL it unregisters
* the namespace
*
* Returns 0 in case of success, -1 in case of error
*/
int
return(-1);
return(-1);
return(-1);
}
/**
* xmlXPathNsLookup:
* @ctxt: the XPath context
* @prefix: the namespace prefix value
*
* Search in the namespace declaration array of the context for the given
* namespace name associated to the given prefix
*
* Returns the value or NULL if not found
*/
const xmlChar *
return(NULL);
return(NULL);
#ifdef XML_XML_NAMESPACE
return(XML_XML_NAMESPACE);
#endif
int i;
}
}
}
/**
* xmlXPathRegisteredNsCleanup:
* @ctxt: the XPath context
*
* Cleanup the XPath context data associated to registered variables
*/
void
return;
}
/************************************************************************
* *
* Routines to handle Values *
* *
************************************************************************/
/* Allocations are terrible, one needs to optimize all this !!! */
/**
* xmlXPathNewFloat:
* @val: the double value
*
* Create a new xmlXPathObjectPtr of type double and of value @val
*
* Returns the newly created object.
*/
xmlXPathNewFloat(double val) {
return(NULL);
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
/**
* xmlXPathNewBoolean:
* @val: the boolean value
*
* Create a new xmlXPathObjectPtr of type boolean and of value @val
*
* Returns the newly created object.
*/
xmlXPathNewBoolean(int val) {
return(NULL);
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
/**
* xmlXPathNewString:
* @val: the xmlChar * value
*
* Create a new xmlXPathObjectPtr of type string and of value @val
*
* Returns the newly created object.
*/
return(NULL);
}
else
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
/**
* xmlXPathWrapString:
* @val: the xmlChar * value
*
* Wraps the @val string into an XPath object.
*
* Returns the newly created object.
*/
return(NULL);
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
/**
* xmlXPathNewCString:
* @val: the char * value
*
* Create a new xmlXPathObjectPtr of type string and of value @val
*
* Returns the newly created object.
*/
xmlXPathNewCString(const char *val) {
return(NULL);
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
/**
* xmlXPathWrapCString:
* @val: the char * value
*
* Wraps a string into an XPath object.
*
* Returns the newly created object.
*/
xmlXPathWrapCString (char * val) {
}
/**
* xmlXPathWrapExternal:
* @val: the user data
*
* Wraps the @val data into an XPath object.
*
* Returns the newly created object.
*/
xmlXPathWrapExternal (void *val) {
return(NULL);
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
return(ret);
}
/**
* xmlXPathObjectCopy:
* @val: the original object
*
* allocate a new copy of a given object
*
* Returns the newly created object.
*/
return(NULL);
return(NULL);
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
case XPATH_BOOLEAN:
case XPATH_NUMBER:
case XPATH_POINT:
case XPATH_RANGE:
break;
case XPATH_STRING:
break;
case XPATH_XSLT_TREE:
#if 0
/*
Removed 11 July 2004 - the current handling of xslt tmpRVT nodes means that
this previous handling is no longer correct, and can cause some serious
problems (ref. bug 145547)
*/
}
}
} else
/* Deallocate the copied tree value */
break;
#endif
case XPATH_NODESET:
/* Do not deallocate the copied tree value */
break;
case XPATH_LOCATIONSET:
#ifdef LIBXML_XPTR_ENABLED
{
break;
}
#endif
case XPATH_USERS:
break;
case XPATH_UNDEFINED:
"xmlXPathObjectCopy: unsupported type %d\n",
break;
}
return(ret);
}
/**
* xmlXPathFreeObject:
* @obj: the object to free
*
* Free up an xmlXPathObjectPtr object.
*/
void
#if 0
} else
#endif
} else {
}
#ifdef LIBXML_XPTR_ENABLED
#endif
}
#ifdef XP_DEBUG_OBJ_USAGE
#endif
}
/**
* xmlXPathReleaseObject:
* @obj: the xmlXPathObjectPtr to free or to cache
*
* Depending on the state of the cache this frees the given
* XPath object or stores it in the cache.
*/
static void
{
return;
} else {
case XPATH_NODESET:
case XPATH_XSLT_TREE:
/*
* It looks like the @boolval is used for
* evaluation if this an XSLT Result Tree Fragment.
* TODO: Check if this assumption is correct.
*/
cache->maxNodeset)))
{
goto obj_cached;
} else {
}
}
break;
case XPATH_STRING:
goto obj_cached;
}
break;
case XPATH_BOOLEAN:
goto obj_cached;
}
break;
case XPATH_NUMBER:
goto obj_cached;
}
break;
#ifdef LIBXML_XPTR_ENABLED
case XPATH_LOCATIONSET:
}
goto free_obj;
#endif
default:
goto free_obj;
}
/*
* Fallback to adding to the misc-objects slot.
*/
} else
goto free_obj;
#ifdef XP_DEBUG_OBJ_USAGE
#endif
/*
* TODO: Due to those nasty ns-nodes, we need to traverse
* the list and free the ns-nodes.
* URGENT TODO: Check if it's actually slowing things down.
* Maybe we shouldn't try to preserve the list.
*/
int i;
{
}
}
}
} else
return;
/*
* Cache is full; free the object.
*/
#ifdef XP_DEBUG_OBJ_USAGE
#endif
}
return;
}
/************************************************************************
* *
* Type Casting Routines *
* *
************************************************************************/
/**
* xmlXPathCastBooleanToString:
* @val: a boolean
*
* Converts a boolean to its string value.
*
* Returns a newly allocated string.
*/
xmlChar *
xmlXPathCastBooleanToString (int val) {
if (val)
else
return(ret);
}
/**
* xmlXPathCastNumberToString:
* @val: a number
*
* Converts a number to its string value.
*
* Returns a newly allocated string.
*/
xmlChar *
xmlXPathCastNumberToString (double val) {
switch (xmlXPathIsInf(val)) {
case 1:
break;
case -1:
break;
default:
if (xmlXPathIsNaN(val)) {
} else {
/* could be improved */
char buf[100];
buf[99] = 0;
}
}
return(ret);
}
/**
* xmlXPathCastNodeToString:
* @node: a node
*
* Converts a node to its string value.
*
* Returns a newly allocated string.
*/
xmlChar *
return(ret);
}
/**
* xmlXPathCastNodeSetToString:
* @ns: a node-set
*
* Converts a node-set to its string value.
*
* Returns a newly allocated string.
*/
xmlChar *
}
/**
* xmlXPathCastToString:
* @val: an XPath object
*
* Converts an existing object to its string() equivalent
*
* Returns the allocated string value of the object, NULL in case of error.
* It's up to the caller to free the string memory with xmlFree().
*/
xmlChar *
case XPATH_UNDEFINED:
#ifdef DEBUG_EXPR
#endif
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
case XPATH_STRING:
case XPATH_BOOLEAN:
break;
case XPATH_NUMBER: {
break;
}
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
break;
}
return(ret);
}
/**
* xmlXPathConvertString:
* @val: an XPath object
*
* Converts an existing object to its string() equivalent
*
* Returns the new object, the old one is freed (or the operation
* is done directly on @val)
*/
return(xmlXPathNewCString(""));
case XPATH_UNDEFINED:
#ifdef DEBUG_EXPR
#endif
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
case XPATH_STRING:
return(val);
case XPATH_BOOLEAN:
break;
case XPATH_NUMBER:
break;
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
TODO;
break;
}
return(xmlXPathNewCString(""));
return(xmlXPathWrapString(res));
}
/**
* xmlXPathCastBooleanToNumber:
* @val: a boolean
*
* Converts a boolean to its number value
*
* Returns the number value
*/
double
xmlXPathCastBooleanToNumber(int val) {
if (val)
return(1.0);
return(0.0);
}
/**
* xmlXPathCastStringToNumber:
* @val: a string
*
* Converts a string to its number value
*
* Returns the number value
*/
double
return(xmlXPathStringEvalNumber(val));
}
/**
* xmlXPathCastNodeToNumber:
* @node: a node
*
* Converts a node to its number value
*
* Returns the number value
*/
double
double ret;
return(xmlXPathNAN);
return(xmlXPathNAN);
return(ret);
}
/**
* xmlXPathCastNodeSetToNumber:
* @ns: a node-set
*
* Converts a node-set to its number value
*
* Returns the number value
*/
double
double ret;
return(xmlXPathNAN);
return(ret);
}
/**
* xmlXPathCastToNumber:
* @val: an XPath object
*
* Converts an XPath object to its number value
*
* Returns the number value
*/
double
double ret = 0.0;
return(xmlXPathNAN);
case XPATH_UNDEFINED:
#ifdef DEGUB_EXPR
#endif
ret = xmlXPathNAN;
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
case XPATH_STRING:
break;
case XPATH_NUMBER:
break;
case XPATH_BOOLEAN:
break;
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
TODO;
ret = xmlXPathNAN;
break;
}
return(ret);
}
/**
* xmlXPathConvertNumber:
* @val: an XPath object
*
* Converts an existing object to its number() equivalent
*
* Returns the new object, the old one is freed (or the operation
* is done directly on @val)
*/
return(xmlXPathNewFloat(0.0));
return(val);
return(ret);
}
/**
* xmlXPathCastNumberToBoolean:
* @val: a number
*
* Converts a number to its boolean value
*
* Returns the boolean value
*/
int
xmlXPathCastNumberToBoolean (double val) {
return(0);
return(1);
}
/**
* xmlXPathCastStringToBoolean:
* @val: a string
*
* Converts a string to its boolean value
*
* Returns the boolean value
*/
int
return(0);
return(1);
}
/**
* xmlXPathCastNodeSetToBoolean:
* @ns: a node-set
*
* Converts a node-set to its boolean value
*
* Returns the boolean value
*/
int
return(0);
return(1);
}
/**
* xmlXPathCastToBoolean:
* @val: an XPath object
*
* Converts an XPath object to its boolean value
*
* Returns the boolean value
*/
int
int ret = 0;
return(0);
case XPATH_UNDEFINED:
#ifdef DEBUG_EXPR
#endif
ret = 0;
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
case XPATH_STRING:
break;
case XPATH_NUMBER:
break;
case XPATH_BOOLEAN:
break;
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
TODO;
ret = 0;
break;
}
return(ret);
}
/**
* xmlXPathConvertBoolean:
* @val: an XPath object
*
* Converts an existing object to its boolean() equivalent
*
* Returns the new object, the old one is freed (or the operation
* is done directly on @val)
*/
return(xmlXPathNewBoolean(0));
return(val);
return(ret);
}
/************************************************************************
* *
* Routines to handle XPath contexts *
* *
************************************************************************/
/**
* xmlXPathNewContext:
* @doc: the XML document
*
* Create a new xmlXPathContext
*
* Returns the xmlXPathContext just allocated. The caller will need to free it.
*/
return(NULL);
}
#ifdef XP_DEFAULT_CACHE_ON
return(NULL);
}
#endif
return(ret);
}
/**
* xmlXPathFreeContext:
* @ctxt: the context to free
*
* Free up an xmlXPathContext
*/
void
}
/************************************************************************
* *
* Routines to handle XPath parser contexts *
* *
************************************************************************/
#define CHECK_CTXT(ctxt) \
"NULL context pointer\n"); \
return(NULL); \
} \
#define CHECK_CTXT_NEG(ctxt) \
"NULL context pointer\n"); \
return(-1); \
} \
#define CHECK_CONTEXT(ctxt) \
return(NULL); \
}
/**
* xmlXPathNewParserContext:
* @str: the XPath expression
* @ctxt: the XPath context
*
* Create a new xmlXPathParserContext
*
* Returns the xmlXPathParserContext just allocated.
*/
return(NULL);
}
return(NULL);
}
}
return(ret);
}
/**
* xmlXPathCompParserContext:
* @comp: the XPath compiled expression
* @ctxt: the XPath context
*
* Create a new xmlXPathParserContext when processing a compiled expression
*
* Returns the xmlXPathParserContext just allocated.
*/
static xmlXPathParserContextPtr
return(NULL);
}
/* Allocate the value stack */
return(NULL);
}
return(ret);
}
/**
* xmlXPathFreeParserContext:
* @ctxt: the context to free
*
* Free up an xmlXPathParserContext
*/
void
}
#ifdef XPATH_STREAMING
}
#endif
}
}
/************************************************************************
* *
* The implicit core function library *
* *
************************************************************************/
/**
* xmlXPathNodeValHash:
* @node: a node pointer
*
* Function computing the beginning of the string value of the node,
* used to speed up comparisons
*
* Returns an int usable as a hash
*/
static unsigned int
int len = 2;
unsigned int ret = 0;
return(0);
else
return(0);
}
case XML_COMMENT_NODE:
case XML_PI_NODE:
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
return(0);
if (string[0] == 0)
return(0);
return(((unsigned int) string[0]) +
case XML_NAMESPACE_DECL:
return(0);
if (string[0] == 0)
return(0);
return(((unsigned int) string[0]) +
case XML_ATTRIBUTE_NODE:
break;
case XML_ELEMENT_NODE:
break;
default:
return(0);
}
case XML_COMMENT_NODE:
case XML_PI_NODE:
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
break;
case XML_NAMESPACE_DECL:
break;
default:
break;
}
if (len == 1) {
}
if (string[1] == 0) {
len = 1;
} else {
return(((unsigned int) string[0]) +
}
}
/*
* Skip to next node
*/
continue;
}
}
break;
continue;
}
do {
break;
break;
}
break;
}
}
return(ret);
}
/**
* xmlXPathStringHash:
* @string: a string
*
* Function computing the beginning of the string value of the node,
* used to speed up comparisons
*
* Returns an int usable as a hash
*/
static unsigned int
return((unsigned int) 0);
if (string[0] == 0)
return(0);
return(((unsigned int) string[0]) +
}
/**
* xmlXPathCompareNodeSetFloat:
* @ctxt: the XPath Parser context
* @inf: less than (1) or greater than (0)
* @strict: is the comparison strict
* @arg: the node set
* @f: the value
*
* Implement the compare operation between a nodeset and a number
* @ns < @val (1, 1, ...
* @ns <= @val (1, 0, ...
* @ns > @val (0, 1, ...
* @ns >= @val (0, 0, ...
*
* If one object to be compared is a node-set and the other is a number,
* then the comparison will be true if and only if there is a node in the
* node-set such that the result of performing the comparison on the number
* to be compared and on the result of converting the string-value of that
* node to a number using the number function is true.
*
* Returns 0 or 1 depending on the results of the test.
*/
static int
int i, ret = 0;
return(0);
}
if (ret)
break;
}
}
}
return(ret);
}
/**
* xmlXPathCompareNodeSetString:
* @ctxt: the XPath Parser context
* @inf: less than (1) or greater than (0)
* @strict: is the comparison strict
* @arg: the node set
* @s: the value
*
* Implement the compare operation between a nodeset and a string
* @ns < @val (1, 1, ...
* @ns <= @val (1, 0, ...
* @ns > @val (0, 1, ...
* @ns >= @val (0, 0, ...
*
* If one object to be compared is a node-set and the other is a string,
* then the comparison will be true if and only if there is a node in
* the node-set such that the result of performing the comparison on the
* string-value of the node and the other string is true.
*
* Returns 0 or 1 depending on the results of the test.
*/
static int
int i, ret = 0;
return(0);
}
if (ret)
break;
}
}
}
return(ret);
}
/**
* xmlXPathCompareNodeSets:
* @inf: less than (1) or greater than (0)
* @strict: is the comparison strict
* @arg1: the first node set object
* @arg2: the second node set object
*
* Implement the compare operation on nodesets:
*
* If both objects to be compared are node-sets, then the comparison
* will be true if and only if there is a node in the first node-set
* and a node in the second node-set such that the result of performing
* the comparison on the string-values of the two nodes is true.
* ....
* When neither object to be compared is a node-set and the operator
* is <=, <, >= or >, then the objects are compared by converting both
* objects to numbers and comparing the numbers according to IEEE 754.
* ....
* The number function converts its argument to a number as follows:
* - a string that consists of optional whitespace followed by an
* optional minus sign followed by a Number followed by whitespace
* is converted to the IEEE 754 number that is nearest (according
* to the IEEE 754 round-to-nearest rule) to the mathematical value
* represented by the string; any other string is converted to NaN
*
* Conclusion all nodes need to be converted first to their string value
* and then the comparison must be done when possible
*/
static int
int i, j, init = 0;
double val1;
double *values2;
int ret = 0;
return(0);
}
return(0);
}
return(0);
}
return(0);
}
return(0);
}
if (xmlXPathIsNaN(val1))
continue;
if (init == 0) {
}
if (xmlXPathIsNaN(values2[j]))
continue;
if (ret)
break;
}
if (ret)
break;
init = 1;
}
return(ret);
}
/**
* xmlXPathCompareNodeSetValue:
* @ctxt: the XPath Parser context
* @inf: less than (1) or greater than (0)
* @strict: is the comparison strict
* @arg: the node set
* @val: the value
*
* Implement the compare operation between a nodeset and a value
* @ns < @val (1, 1, ...
* @ns <= @val (1, 0, ...
* @ns > @val (0, 1, ...
* @ns >= @val (0, 0, ...
*
* If one object to be compared is a node-set and the other is a boolean,
* then the comparison will be true if and only if the result of performing
* the comparison on the boolean and on the result of converting
* the node-set to a boolean using the boolean function is true.
*
* Returns 0 or 1 depending on the results of the test.
*/
static int
return(0);
case XPATH_NUMBER:
case XPATH_NODESET:
case XPATH_XSLT_TREE:
case XPATH_STRING:
case XPATH_BOOLEAN:
default:
}
return(0);
}
/**
* xmlXPathEqualNodeSetString:
* @arg: the nodeset object argument
* @str: the string to compare to.
* @neq: flag to show whether for '=' (0) or '!=' (1)
*
* Implement the equal operation on XPath objects content: @arg1 == @arg2
* If one object to be compared is a node-set and the other is a string,
* then the comparison will be true if and only if there is a node in
* the node-set such that the result of performing the comparison on the
* string-value of the node and the other string is true.
*
* Returns 0 or 1 depending on the results of the test.
*/
static int
{
int i;
unsigned int hash;
return (0);
/*
* A NULL nodeset compared with a string is always false
* (since there is no node equal, and no node not equal)
*/
return (0);
if (neq)
continue;
return (1);
if (neq)
continue;
return (1);
} else if (neq) {
return (1);
}
} else if (neq)
return (1);
}
return (0);
}
/**
* xmlXPathEqualNodeSetFloat:
* @arg: the nodeset object argument
* @f: the float to compare to
* @neq: flag to show whether to compare '=' (0) or '!=' (1)
*
* Implement the equal operation on XPath objects content: @arg1 == @arg2
* If one object to be compared is a node-set and the other is a number,
* then the comparison will be true if and only if there is a node in
* the node-set such that the result of performing the comparison on the
* number to be compared and on the result of converting the string-value
* of that node to a number using the number function is true.
*
* Returns 0 or 1 depending on the results of the test.
*/
static int
int i, ret=0;
double v;
return(0);
if (!xmlXPathIsNaN(v)) {
if ((!neq) && (v==f)) {
ret = 1;
break;
} else if ((neq) && (v!=f)) {
ret = 1;
break;
}
} else { /* NaN is unequal to any value */
if (neq)
ret = 1;
}
}
}
}
return(ret);
}
/**
* xmlXPathEqualNodeSets:
* @arg1: first nodeset object argument
* @arg2: second nodeset object argument
* @neq: flag to show whether to test '=' (0) or '!=' (1)
*
* Implement the equal / not equal operation on XPath nodesets:
* @arg1 == @arg2 or @arg1 != @arg2
* If both objects to be compared are node-sets, then the comparison
* will be true if and only if there is a node in the first node-set and
* a node in the second node-set such that the result of performing the
* comparison on the string-values of the two nodes is true.
*
* (needless to say, this is a costly operation)
*
* Returns 0 or 1 depending on the results of the test.
*/
static int
int i, j;
unsigned int *hashs1;
unsigned int *hashs2;
int ret = 0;
return(0);
return(0);
return(0);
return(0);
/*
* for equal, check if there is a node pertaining to both sets
*/
if (neq == 0)
return(1);
return(0);
}
return(0);
}
return(0);
}
return(0);
}
if (i == 0)
if (neq) {
ret = 1;
break;
}
}
else {
if (ret)
break;
}
}
if (ret)
break;
}
return(ret);
}
static int
int ret = 0;
/*
*At this point we are assured neither arg1 nor arg2
*is a nodeset, so we can just pick the appropriate routine.
*/
case XPATH_UNDEFINED:
#ifdef DEBUG_EXPR
"Equal: undefined\n");
#endif
break;
case XPATH_BOOLEAN:
case XPATH_UNDEFINED:
#ifdef DEBUG_EXPR
"Equal: undefined\n");
#endif
break;
case XPATH_BOOLEAN:
#ifdef DEBUG_EXPR
"Equal: %d boolean %d \n",
#endif
break;
case XPATH_NUMBER:
break;
case XPATH_STRING:
else
ret = 1;
break;
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
}
break;
case XPATH_NUMBER:
case XPATH_UNDEFINED:
#ifdef DEBUG_EXPR
"Equal: undefined\n");
#endif
break;
case XPATH_BOOLEAN:
break;
case XPATH_STRING:
/* no break on purpose */
case XPATH_NUMBER:
/* Hand check NaN and Infinity equalities */
ret = 0;
ret = 1;
else
ret = 0;
ret = 1;
else
ret = 0;
ret = 1;
else
ret = 0;
ret = 1;
else
ret = 0;
} else {
}
break;
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
}
break;
case XPATH_STRING:
case XPATH_UNDEFINED:
#ifdef DEBUG_EXPR
"Equal: undefined\n");
#endif
break;
case XPATH_BOOLEAN:
else
ret = 1;
break;
case XPATH_STRING:
break;
case XPATH_NUMBER:
/* Hand check NaN and Infinity equalities */
ret = 0;
ret = 1;
else
ret = 0;
ret = 1;
else
ret = 0;
ret = 1;
else
ret = 0;
ret = 1;
else
ret = 0;
} else {
}
break;
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
}
break;
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
}
return(ret);
}
/**
* xmlXPathEqualValues:
* @ctxt: the XPath Parser context
*
* Implement the equal operation on XPath objects content: @arg1 == @arg2
*
* Returns 0 or 1 depending on the results of the test.
*/
int
int ret = 0;
else
}
#ifdef DEBUG_EXPR
"Equal: by pointer\n");
#endif
return(1);
}
/*
*If either argument is a nodeset, it's a 'special case'
*/
/*
*Hack it to assure arg1 is the nodeset
*/
}
case XPATH_UNDEFINED:
#ifdef DEBUG_EXPR
"Equal: undefined\n");
#endif
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
case XPATH_BOOLEAN:
else
ret = 1;
break;
case XPATH_NUMBER:
break;
case XPATH_STRING:
break;
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
break;
}
return(ret);
}
}
/**
* xmlXPathNotEqualValues:
* @ctxt: the XPath Parser context
*
* Implement the equal operation on XPath objects content: @arg1 == @arg2
*
* Returns 0 or 1 depending on the results of the test.
*/
int
int ret = 0;
else
}
#ifdef DEBUG_EXPR
"NotEqual: by pointer\n");
#endif
return(0);
}
/*
*If either argument is a nodeset, it's a 'special case'
*/
/*
*Hack it to assure arg1 is the nodeset
*/
}
case XPATH_UNDEFINED:
#ifdef DEBUG_EXPR
"NotEqual: undefined\n");
#endif
break;
case XPATH_NODESET:
case XPATH_XSLT_TREE:
break;
case XPATH_BOOLEAN:
else
ret = 1;
break;
case XPATH_NUMBER:
break;
case XPATH_STRING:
break;
case XPATH_USERS:
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
break;
}
return(ret);
}
}
/**
* xmlXPathCompareValues:
* @ctxt: the XPath Parser context
* @inf: less than (1) or greater than (0)
* @strict: is the comparison strict
*
* Implement the compare operation on XPath objects:
* @arg1 < @arg2 (1, 1, ...
* @arg1 <= @arg2 (1, 0, ...
* @arg1 > @arg2 (0, 1, ...
* @arg1 >= @arg2 (0, 0, ...
*
* When neither object to be compared is a node-set and the operator is
* <=, <, >=, >, then the objects are compared by converted both objects
* to numbers and comparing the numbers according to IEEE 754. The <
* comparison will be true if and only if the first number is less than the
* second number. The <= comparison will be true if and only if the first
* number is less than or equal to the second number. The > comparison
* will be true if and only if the first number is greater than the second
* number. The >= comparison will be true if and only if the first number
* is greater than or equal to the second number.
*
* Returns 1 if the comparison succeeded, 0 if it failed
*/
int
else
}
/*
* If either argument is a XPATH_NODESET or XPATH_XSLT_TREE the two arguments
* are not freed from within this routine; they will be freed from the
* called routine, e.g. xmlXPathCompareNodeSets or xmlXPathCompareNodeSetValue
*/
} else {
} else {
}
}
return(ret);
}
}
}
}
}
/*
* Add tests for infinity and nan
* => feedback on 3.4 for Inf and NaN
*/
/* Hand check NaN and Infinity comparisons */
ret=0;
} else {
ret = 1;
} else {
ret = 0;
}
}
ret = 1;
} else {
ret = 0;
}
}
ret = 1;
} else {
ret = 0;
}
}
ret = 1;
} else {
ret = 0;
}
}
}
return(ret);
}
/**
* xmlXPathValueFlipSign:
* @ctxt: the XPath Parser context
*
* Implement the unary - operation on an XPath object
* The numeric operators convert their operands to numbers as if
* by calling the number function.
*/
void
else
}
else
}
/**
* xmlXPathAddValues:
* @ctxt: the XPath Parser context
*
* Implement the add operation on XPath objects:
* The numeric operators convert their operands to numbers as if
* by calling the number function.
*/
void
double val;
}
/**
* xmlXPathSubValues:
* @ctxt: the XPath Parser context
*
* Implement the subtraction operation on XPath objects:
* The numeric operators convert their operands to numbers as if
* by calling the number function.
*/
void
double val;
}
/**
* xmlXPathMultValues:
* @ctxt: the XPath Parser context
*
* Implement the multiply operation on XPath objects:
* The numeric operators convert their operands to numbers as if
* by calling the number function.
*/
void
double val;
}
/**
* xmlXPathDivValues:
* @ctxt: the XPath Parser context
*
* Implement the div operation on XPath objects @arg1 / @arg2:
* The numeric operators convert their operands to numbers as if
* by calling the number function.
*/
void
double val;
}
else if (val == 0) {
} else
}
/**
* xmlXPathModValues:
* @ctxt: the XPath Parser context
*
* Implement the mod operation on XPath objects: @arg1 / @arg2
* The numeric operators convert their operands to numbers as if
* by calling the number function.
*/
void
if (arg2 == 0)
else {
}
}
/************************************************************************
* *
* The traversal functions *
* *
************************************************************************/
/*
* A traversal function enumerates nodes along an axis.
* Initially it must be called with NULL, and it indicates
* termination on the axis by returning NULL.
*/
typedef xmlNodePtr (*xmlXPathTraversalFunction)
/*
* xmlXPathTraversalFunctionExt:
* A traversal function enumerates nodes along an axis.
* Initially it must be called with NULL, and it indicates
* termination on the axis by returning NULL.
* The context node of the traversal is specified via @contextNode.
*/
typedef xmlNodePtr (*xmlXPathTraversalFunctionExt)
/*
* xmlXPathNodeSetMergeFunction:
* Used for merging node sets in xmlXPathCollectAndTest().
*/
typedef xmlNodeSetPtr (*xmlXPathNodeSetMergeFunction)
(xmlNodeSetPtr, xmlNodeSetPtr, int);
/**
* xmlXPathNextSelf:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "self" direction
* The self axis contains just the context node itself
*
* Returns the next element following that axis
*/
return(NULL);
}
/**
* xmlXPathNextChild:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "child" direction
* The child axis contains the children of the context node in document order.
*
* Returns the next element following that axis
*/
case XML_ELEMENT_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_DOCUMENT_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_ATTRIBUTE_NODE:
case XML_NAMESPACE_DECL:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
return(NULL);
}
return(NULL);
}
return(NULL);
}
/**
* xmlXPathNextChildElement:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "child" direction and nodes of type element.
* The child axis contains the children of the context node in document order.
*
* Returns the next element following that axis
*/
static xmlNodePtr
/*
* Get the first element child.
*/
case XML_ELEMENT_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_ENTITY_REF_NODE: /* URGENT TODO: entify-refs as well? */
case XML_ENTITY_NODE:
return(cur);
do {
return(cur);
}
return(NULL);
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
default:
return(NULL);
}
return(NULL);
}
/*
* Get the next sibling element node.
*/
case XML_ELEMENT_NODE:
case XML_TEXT_NODE:
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_CDATA_SECTION_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_XINCLUDE_END:
break;
/* case XML_DTD_NODE: */ /* URGENT TODO: DTD-node as well? */
default:
return(NULL);
}
do {
return(cur);
}
return(NULL);
}
/**
* xmlXPathNextDescendantOrSelfElemParent:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "descendant-or-self" axis.
* Additionally it returns only nodes which can be parents of
* element nodes.
*
*
* Returns the next element following that axis
*/
static xmlNodePtr
{
if (contextNode == NULL)
return(NULL);
switch (contextNode->type) {
case XML_ELEMENT_NODE:
case XML_XINCLUDE_START:
case XML_DOCUMENT_FRAG_NODE:
case XML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_HTML_DOCUMENT_NODE:
return(contextNode);
default:
return(NULL);
}
return(NULL);
} else {
case XML_ELEMENT_NODE:
/* TODO: OK to have XInclude here? */
case XML_XINCLUDE_START:
case XML_DOCUMENT_FRAG_NODE:
return(cur);
continue;
}
break;
/* Not sure if we need those here. */
case XML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_HTML_DOCUMENT_NODE:
return(cur);
default:
break;
}
return(NULL);
} else {
goto next_sibling;
}
}
}
return(NULL);
}
/**
* xmlXPathNextDescendant:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "descendant" direction
* the descendant axis contains the descendants of the context node in document
* order; a descendant is a child or a child of a child and so on.
*
* Returns the next element following that axis
*/
return(NULL);
return(NULL);
}
/*
* Do not descend on entities declarations
*/
/*
* Skip DTDs
*/
return(cur);
}
}
return(cur);
}
do {
return(cur);
}
return(cur);
}
/**
* xmlXPathNextDescendantOrSelf:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "descendant-or-self" direction
* the descendant-or-self axis contains the context node and the descendants
* of the context node in document order; thus the context node is the first
* node on the axis, and the first child of the context node is the second node
* on the axis
*
* Returns the next element following that axis
*/
return(NULL);
return(NULL);
}
}
/**
* xmlXPathNextParent:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "parent" direction
* The parent axis contains the parent of the context node, if there is one.
*
* Returns the next element following that axis
*/
/*
* the parent of an attribute or namespace node is the element
* to which the attribute or namespace node is attached
* Namespace handling !!!
*/
case XML_ELEMENT_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
case XML_ENTITY_DECL:
BAD_CAST "fake node libxslt"))))
return(NULL);
case XML_ATTRIBUTE_NODE: {
}
case XML_DOCUMENT_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
return(NULL);
case XML_NAMESPACE_DECL: {
return(NULL);
}
}
}
return(NULL);
}
/**
* xmlXPathNextAncestor:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "ancestor" direction
* the ancestor axis contains the ancestors of the context node; the ancestors
* of the context node consist of the parent of context node and the parent's
* parent and so on; the nodes are ordered in reverse document order; thus the
* parent is the first node on the axis, and the parent's parent is the second
* node on the axis
*
* Returns the next element following that axis
*/
/*
* the parent of an attribute or namespace node is the element
* to which the attribute or namespace node is attached
* !!!!!!!!!!!!!
*/
case XML_ELEMENT_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_DTD_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_NOTATION_NODE:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
BAD_CAST "fake node libxslt"))))
return(NULL);
case XML_ATTRIBUTE_NODE: {
}
case XML_DOCUMENT_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
return(NULL);
case XML_NAMESPACE_DECL: {
/* Bad, how did that namespace end up here ? */
return(NULL);
}
}
return(NULL);
}
return(NULL);
case XML_ELEMENT_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
return(NULL);
BAD_CAST "fake node libxslt"))))
return(NULL);
case XML_ATTRIBUTE_NODE: {
}
case XML_NAMESPACE_DECL: {
/* Bad, how did that namespace end up here ? */
return(NULL);
}
case XML_DOCUMENT_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
return(NULL);
}
return(NULL);
}
/**
* xmlXPathNextAncestorOrSelf:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "ancestor-or-self" direction
* he ancestor-or-self axis contains the context node and ancestors of
* the context node in reverse document order; thus the context node is
* the first node on the axis, and the context node's parent the second;
* parent here is defined the same as with the parent axis.
*
* Returns the next element following that axis
*/
}
/**
* xmlXPathNextFollowingSibling:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "following-sibling" direction
* The following-sibling axis contains the following siblings of the context
* node in document order.
*
* Returns the next element following that axis
*/
return(NULL);
return(NULL);
}
/**
* xmlXPathNextPrecedingSibling:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "preceding-sibling" direction
* The preceding-sibling axis contains the preceding siblings of the context
* node in reverse document order; the first preceding sibling is first on the
* axis; the sibling preceding that node is the second on the axis and so on.
*
* Returns the next element following that axis
*/
return(NULL);
return(NULL);
}
}
/**
* xmlXPathNextFollowing:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "following" direction
* The following axis contains all nodes in the same document as the context
* node that are after the context node in document order, excluding any
* descendants and excluding attribute nodes and namespace nodes; the nodes
* are ordered in document order
*
* Returns the next element following that axis
*/
do {
return(cur);
}
/*
* xmlXPathIsAncestor:
* @ancestor: the ancestor node
* @node: the current node
*
* Check that @ancestor is a @node's ancestor
*
* returns 1 if @ancestor is a @node's ancestor, 0 otherwise.
*/
static int
/* nodes need to be in the same document */
/* avoid searching if ancestor or node is the root node */
return(1);
}
return(0);
}
/**
* xmlXPathNextPreceding:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "preceding" direction
* the preceding axis contains all nodes in the same document as the context
* node that are before the context node in document order, excluding any
* ancestors and excluding attribute nodes and namespace nodes; the nodes are
* ordered in reverse document order
*
* Returns the next element following that axis
*/
{
return (NULL);
do {
return (cur);
}
return (NULL);
return (NULL);
return (cur);
}
/**
* xmlXPathNextPrecedingInternal:
* @ctxt: the XPath Parser context
* @cur: the current node in the traversal
*
* Traversal function for the "preceding" direction
* the preceding axis contains all nodes in the same document as the context
* node that are before the context node in document order, excluding any
* ancestors and excluding attribute nodes and namespace nodes; the nodes are
* ordered in reverse document order
* This is a faster implementation but internal only since it requires a
* state kept in the parser context: ctxt->ancestor.
*
* Returns the next element following that axis
*/
static xmlNodePtr
{
return (NULL);
}
return (NULL);
return (NULL);
return (cur);
}
return (cur);
}
/**
* xmlXPathNextNamespace:
* @ctxt: the XPath Parser context
* @cur: the current attribute in the traversal
*
* Traversal function for the "namespace" direction
* the namespace axis contains the namespace nodes of the context node;
* the order of nodes on this axis is implementation-defined; the axis will
* be empty unless the context node is an element
*
* We keep the XML namespace node at the end of the list.
*
* Returns the next element following that axis
*/
}
}
return((xmlNodePtr) xmlXPathXMLNamespace);
}
} else {
return(NULL);
}
}
/**
* xmlXPathNextAttribute:
* @ctxt: the XPath Parser context
* @cur: the current attribute in the traversal
*
* Traversal function for the "attribute" direction
* TODO: support DTD inherited default attributes
*
* Returns the next element following that axis
*/
return(NULL);
return(NULL);
return(NULL);
}
}
/************************************************************************
* *
* NodeTest Functions *
* *
************************************************************************/
#define IS_FUNCTION 200
/************************************************************************
* *
* Implicit tree core function library *
* *
************************************************************************/
/**
* xmlXPathRoot:
* @ctxt: the XPath Parser context
*
* Initialize the context to the root of the document
*/
void
return;
}
/************************************************************************
* *
* The explicit core function library *
* *
************************************************************************/
/**
* xmlXPathLastFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the last() XPath function
* number last()
* The last function returns the number of nodes in the context node list.
*/
void
CHECK_ARITY(0);
#ifdef DEBUG_EXPR
#endif
} else {
}
}
/**
* xmlXPathPositionFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the position() XPath function
* number position()
* The position function returns the position of the context node in the
* context node list. The first position is 1, and so the last position
* will be equal to last().
*/
void
CHECK_ARITY(0);
#ifdef DEBUG_EXPR
#endif
} else {
}
}
/**
* xmlXPathCountFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the count() XPath function
* number count(node-set)
*/
void
CHECK_ARITY(1);
} else {
} else {
int i = 0;
i++;
}
}
}
}
}
/**
* xmlXPathGetElementsByIds:
* @doc: the document
* @ids: a whitespace separated list of IDs
*
* Selects elements by their unique ID.
*
* Returns a node-set of selected elements.
*/
static xmlNodeSetPtr
while (*cur != 0) {
cur++;
/*
* We used to check the fact that the value passed
* was an NCName, but this generated much troubles for
* me and Aleksey Sanin, people blatantly violated that
* constaint, like Visa3D spec.
* if (xmlValidateNCName(ID, 1) == 0)
*/
else
}
}
}
return(ret);
}
/**
* xmlXPathIdFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the id() XPath function
* node-set id(object)
* The id function selects elements by their unique ID
* (see [5.2.1 Unique IDs]). When the argument to id is of type node-set,
* then the result is the union of the result of applying id to the
* string value of each of the nodes in the argument node-set. When the
* argument to id is of any other type, the argument is converted to a
* string as if by a call to the string function; the string is split
* into a whitespace-separated list of tokens (whitespace is any sequence
* of characters matching the production S); the result is a node-set
* containing the elements in the same document as the context node that
* have a unique ID equal to any of the tokens in the list.
*/
void
CHECK_ARITY(1);
int i;
tokens =
}
}
return;
}
return;
}
/**
* xmlXPathLocalNameFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the local-name() XPath function
* string local-name(node-set?)
* The local-name function returns a string containing the local part
* of the name of the node in the argument node-set that is first in
* document order. If the node-set is empty or the first node has no
* name, an empty string is returned. If the argument is omitted it
* defaults to the context node.
*/
void
if (nargs == 0) {
nargs = 1;
}
CHECK_ARITY(1);
} else {
int i = 0; /* Should be first in document order !!!!! */
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
case XML_PI_NODE:
else
break;
case XML_NAMESPACE_DECL:
break;
default:
}
}
}
/**
* xmlXPathNamespaceURIFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the namespace-uri() XPath function
* string namespace-uri(node-set?)
* The namespace-uri function returns a string containing the
* namespace URI of the expanded name of the node in the argument
* node-set that is first in document order. If the node-set is empty,
* the first node has no name, or the expanded name has no namespace
* URI, an empty string is returned. If the argument is omitted it
* defaults to the context node.
*/
void
if (nargs == 0) {
nargs = 1;
}
CHECK_ARITY(1);
} else {
int i = 0; /* Should be first in document order !!!!! */
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
else
break;
default:
}
}
}
/**
* xmlXPathNameFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the name() XPath function
* string name(node-set?)
* The name function returns a string containing a QName representing
* the name of the node in the argument node-set that is first in document
* order. The QName must represent the name with respect to the namespace
* declarations in effect on the node whose name is being represented.
* Typically, this will be the form in which the name occurred in the XML
* source. This need not be the case if there are namespace declarations
* in effect on the node that associate multiple prefixes with the same
* namespace. However, an implementation may include information about
* the original prefix in its representation of nodes; in this case, an
* implementation can ensure that the returned string is always the same
* as the QName used in the XML source. If the argument it omitted it
* defaults to the context node.
* Libxml keep the original prefix so the "real qualified name" used is
* returned.
*/
static void
{
if (nargs == 0) {
nargs = 1;
}
CHECK_ARITY(1);
} else {
int i = 0; /* Should be first in document order !!!!! */
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
} else {
NULL, 0);
}
}
break;
default:
}
}
}
/**
* xmlXPathStringFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the string() XPath function
* string string(object?)
* The string function converts an object to a string as follows:
* - A node-set is converted to a string by returning the value of
* the node in the node-set that is first in document order.
* If the node-set is empty, an empty string is returned.
* - A number is converted to a string as follows
* + NaN is converted to the string NaN
* + positive zero is converted to the string 0
* + negative zero is converted to the string 0
* + positive infinity is converted to the string Infinity
* + negative infinity is converted to the string -Infinity
* + if the number is an integer, the number is represented in
* decimal form as a Number with no decimal point and no leading
* zeros, preceded by a minus sign (-) if the number is negative
* + otherwise, the number is represented in decimal form as a
* Number including a decimal point with at least one digit
* before the decimal point and at least one digit after the
* decimal point, preceded by a minus sign (-) if the number
* is negative; there must be no leading zeros before the decimal
* point apart possibly from the one required digit immediately
* before the decimal point; beyond the one required digit
* after the decimal point there must be as many, but only as
* many, more digits as are needed to uniquely distinguish the
* number from all other IEEE 754 numeric values.
* - The boolean false value is converted to the string false.
* The boolean true value is converted to the string true.
*
* If the argument is omitted, it defaults to a node-set with the
* context node as its only member.
*/
void
if (nargs == 0) {
return;
}
CHECK_ARITY(1);
}
/**
* xmlXPathStringLengthFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the string-length() XPath function
* number string-length(string?)
* The string-length returns the number of characters in the string
* (see [3.6 Strings]). If the argument is omitted, it defaults to
* the context node converted to a string, in other words the value
* of the context node.
*/
void
if (nargs == 0) {
return;
} else {
xmlUTF8Strlen(content)));
}
return;
}
CHECK_ARITY(1);
}
/**
* xmlXPathConcatFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the concat() XPath function
* string concat(string, string, string*)
* The concat function returns the concatenation of its arguments.
*/
void
if (nargs < 2) {
CHECK_ARITY(2);
}
return;
}
nargs--;
while (nargs > 0) {
}
nargs--;
}
}
/**
* xmlXPathContainsFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the contains() XPath function
* boolean contains(string, string)
* The contains function returns true if the first argument string
* contains the second argument string, and otherwise returns false.
*/
void
CHECK_ARITY(2);
}
else
}
/**
* xmlXPathStartsWithFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the starts-with() XPath function
* boolean starts-with(string, string)
* The starts-with function returns true if the first argument string
* starts with the second argument string, and otherwise returns false.
*/
void
int n;
CHECK_ARITY(2);
}
else
}
/**
* xmlXPathSubstringFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the substring() XPath function
* string substring(string, number, number?)
* The substring function returns the substring of the first argument
* starting at the position specified in the second argument with
* length specified in the third argument. For example,
* substring("12345",2,3) returns "234". If the third argument is not
* specified, it returns the substring starting at the position specified
* in the second argument and continuing to the end of the string. For
* example, substring("12345",2) returns "2345". More precisely, each
* character in the string (see [3.6 Strings]) is considered to have a
* numeric position: the position of the first character is 1, the position
* of the second character is 2 and so on. The returned substring contains
* those characters for which the position of the character is greater than
* or equal to the second argument and, if the third argument is specified,
* less than the sum of the second and third arguments; the comparisons
* and addition used for the above follow the standard IEEE 754 rules. Thus:
* - substring("12345", 1.5, 2.6) returns "234"
* - substring("12345", 0, 3) returns "12"
* - substring("12345", 0 div 0, 3) returns ""
* - substring("12345", 1, 0 div 0) returns ""
* - substring("12345", -42, 1 div 0) returns "12345"
* - substring("12345", -1 div 0, 1 div 0) returns ""
*/
void
int i, l, m;
if (nargs < 2) {
CHECK_ARITY(2);
}
if (nargs > 3) {
CHECK_ARITY(3);
}
/*
* take care of possible last (position) argument
*/
if (nargs == 3) {
}
/*
* If last pos not present, calculate last position
*/
if (nargs != 3) {
le = (double)m;
if (in < 1.0)
in = 1.0;
}
/* Need to check for the special cases where either
* the index is NaN, the length is NaN, or both
* arguments are infinity (relying on Inf + -Inf = NaN)
*/
/*
* To meet the requirements of the spec, the arguments
* must be converted to integer format before
* initial index calculations are done
*
* First we go to integer form, rounding up
* and checking for special cases
*/
i = (int) in;
if (((double)i)+0.5 <= in) i++;
l = m;
if (i < 1)
i = 1;
}
l = 0;
else {
l = (int) le;
if (((double)l)+0.5 <= le) l++;
}
/* Now we normalize inidices */
i -= 1;
l += i;
if (i < 0)
i = 0;
if (l > m)
l = m;
/* number of chars to copy */
l -= i;
}
else {
}
else {
}
}
/**
* xmlXPathSubstringBeforeFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the substring-before() XPath function
* string substring-before(string, string)
* The substring-before function returns the substring of the first
* argument string that precedes the first occurrence of the second
* argument string in the first argument string, or the empty string
* if the first argument string does not contain the second argument
* string. For example, substring-before("1999/04/01","/") returns 1999.
*/
void
int offset;
CHECK_ARITY(2);
target = xmlBufferCreate();
if (target) {
if (point) {
}
}
}
/**
* xmlXPathSubstringAfterFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the substring-after() XPath function
* string substring-after(string, string)
* The substring-after function returns the substring of the first
* argument string that follows the first occurrence of the second
* argument string in the first argument string, or the empty stringi
* if the first argument string does not contain the second argument
* string. For example, substring-after("1999/04/01","/") returns 04/01,
* and substring-after("1999/04/01","19") returns 99/04/01.
*/
void
int offset;
CHECK_ARITY(2);
target = xmlBufferCreate();
if (target) {
if (point) {
}
}
}
/**
* xmlXPathNormalizeFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the normalize-space() XPath function
* string normalize-space(string?)
* The normalize-space function returns the argument string with white
* space normalized by stripping leading and trailing whitespace
* and replacing sequences of whitespace characters by a single
* space. Whitespace characters are the same allowed by the S production
* in XML. If the argument is omitted, it defaults to the context
* node converted to a string, in other words the value of the context node.
*/
void
if (nargs == 0) {
/* Use current context node */
nargs = 1;
}
CHECK_ARITY(1);
target = xmlBufferCreate();
/* Skip leading whitespaces */
while (IS_BLANK_CH(*source))
source++;
/* Collapse intermediate whitespaces, and skip trailing whitespaces */
blank = 0;
while (*source) {
if (IS_BLANK_CH(*source)) {
blank = 0x20;
} else {
if (blank) {
blank = 0;
}
}
source++;
}
}
}
/**
* xmlXPathTranslateFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the translate() XPath function
* string translate(string, string, string)
* The translate function returns the first argument string with
* occurrences of characters in the second argument string replaced
* by the character at the corresponding position in the third argument
* string. For example, translate("bar","abc","ABC") returns the string
* BAr. If there is a character in the second argument string with no
* character at a corresponding position in the third argument string
* (because the second argument string is longer than the third argument
* string), then occurrences of that character in the first argument
* string are removed. For example, translate("--aaa--","abc-","ABC")
* returns "AAA". If a character occurs more than once in second
* argument string, then the first occurrence determines the replacement
* character. If the third argument string is longer than the second
* argument string, then excess characters are ignored.
*/
void
CHECK_ARITY(3);
target = xmlBufferCreate();
if (target) {
if (offset >= 0) {
if (point)
}
} else
/* Step to next character in input */
cptr++;
if ( ch & 0x80 ) {
/* if not simple ascii, verify proper format */
"xmlXPathTranslateFunction: Invalid UTF8 string\n");
break;
}
/* then skip over remaining bytes for this char */
"xmlXPathTranslateFunction: Invalid UTF8 string\n");
break;
}
break;
}
}
}
}
/**
* xmlXPathBooleanFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the boolean() XPath function
* boolean boolean(object)
* The boolean function converts its argument to a boolean as follows:
* - a number is true if and only if it is neither positive or
* negative zero nor NaN
* - a node-set is true if and only if it is non-empty
* - a string is true if and only if its length is non-zero
*/
void
CHECK_ARITY(1);
}
/**
* xmlXPathNotFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the not() XPath function
* boolean not(boolean)
* The not function returns true if its argument is false,
* and false otherwise.
*/
void
CHECK_ARITY(1);
}
/**
* xmlXPathTrueFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the true() XPath function
* boolean true()
*/
void
CHECK_ARITY(0);
}
/**
* xmlXPathFalseFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the false() XPath function
* boolean false()
*/
void
CHECK_ARITY(0);
}
/**
* xmlXPathLangFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the lang() XPath function
* boolean lang(string)
* The lang function returns true or false depending on whether the
* language of the context node as specified by xml:lang attributes
* is the same as or is a sublanguage of the language specified by
* the argument string. The language of the context node is determined
* by the value of the xml:lang attribute on the context node, or, if
* the context node has no xml:lang attribute, by the value of the
* xml:lang attribute on the nearest ancestor of the context node that
* has an xml:lang attribute. If there is no such attribute, then lang
* returns false. If there is such an attribute, then lang returns
* true if the attribute value is equal to the argument ignoring case,
* or if there is some suffix starting with - such that the attribute
* value is equal to the argument ignoring that suffix of the attribute
* value and ignoring case.
*/
void
int ret = 0;
int i;
CHECK_ARITY(1);
for (i = 0;lang[i] != 0;i++)
goto not_equal;
ret = 1;
}
}
/**
* xmlXPathNumberFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the number() XPath function
* number number(object?)
*/
void
double res;
if (nargs == 0) {
} else {
}
return;
}
CHECK_ARITY(1);
}
/**
* xmlXPathSumFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the sum() XPath function
* number sum(node-set)
* The sum function returns the sum of the values of the nodes in
* the argument node-set.
*/
void
int i;
double res = 0.0;
CHECK_ARITY(1);
}
}
}
/*
* To assure working code on multiple platforms, we want to only depend
* upon the characteristic truncation of converting a floating point value
* to an integer. Unfortunately, because of the different storage sizes
* of our internal floating point value (double) and integer (int), we
* can't directly convert (see bug 301162). This macro is a messy
* 'workaround'
*/
#define XTRUNC(f, v) \
f = (v) - (f) + (double)((int)(f));
/**
* xmlXPathFloorFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the floor() XPath function
* number floor(number)
* The floor function returns the largest (closest to positive infinity)
* number that is not greater than the argument and that is an integer.
*/
void
double f;
CHECK_ARITY(1);
else
}
}
/**
* xmlXPathCeilingFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the ceiling() XPath function
* number ceiling(number)
* The ceiling function returns the smallest (closest to negative infinity)
* number that is not less than the argument and that is an integer.
*/
void
double f;
CHECK_ARITY(1);
#if 0
#else
else {
else
}
}
#endif
}
/**
* xmlXPathRoundFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the round() XPath function
* number round(number)
* The round function returns the number that is closest to the
* argument and that is an integer. If there are two such numbers,
* then the one that is even is returned.
*/
void
double f;
CHECK_ARITY(1);
return;
else
} else {
else
}
}
/************************************************************************
* *
* The Parser *
* *
************************************************************************/
/*
* a few forward declarations since we use a recursive call based
* implementation.
*/
int qualified);
/**
* xmlXPathCurrentChar:
* @ctxt: the XPath parser context
* @cur: pointer to the beginning of the char
* @len: pointer to the length of the char read
*
* The current char value, if using UTF-8 this may actually span multiple
* bytes in the input buffer.
*
* Returns the current char value and its length
*/
static int
unsigned char c;
unsigned int val;
return(0);
/*
* We are supposed to handle UTF8, check it's valid
* From rfc2044: encoding of the Unicode values on UTF-8:
*
* UCS-4 range (hex.) UTF-8 octet sequence (binary)
* 0000 0000-0000 007F 0xxxxxxx
* 0000 0080-0000 07FF 110xxxxx 10xxxxxx
* 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
*
* Check for the 0x110000 limit too
*/
c = *cur;
if (c & 0x80) {
goto encoding_error;
if ((c & 0xe0) == 0xe0) {
goto encoding_error;
if ((c & 0xf0) == 0xf0) {
if (((c & 0xf8) != 0xf0) ||
goto encoding_error;
/* 4-byte code */
*len = 4;
} else {
/* 3-byte code */
*len = 3;
}
} else {
/* 2-byte code */
*len = 2;
}
}
return(val);
} else {
/* 1-byte code */
*len = 1;
return((int) *cur);
}
/*
* If we detect an UTF8 error that probably means that the
* input encoding didn't get properly advertised in the
* declaration header. Report the error and switch the encoding
* to ISO-Latin-1 (if you don't like this policy, just declare the
* encoding !)
*/
*len = 0;
}
/**
* xmlXPathParseNCName:
* @ctxt: the XPath Parser context
*
* parse an XML namespace non qualified name.
*
* [NS 3] NCName ::= (Letter | '_') (NCNameChar)*
*
* [NS 4] NCNameChar ::= Letter | Digit | '.' | '-' | '_' |
* CombiningChar | Extender
*
* Returns the namespace name or NULL
*/
xmlChar *
int count = 0;
/*
* Accelerator for simple ASCII names
*/
(*in == '_')) {
in++;
(*in == '-'))
in++;
if (count == 0)
return(NULL);
return(ret);
}
}
return(xmlXPathParseNameComplex(ctxt, 0));
}
/**
* xmlXPathParseQName:
* @ctxt: the XPath Parser context
* @prefix: a xmlChar **
*
* parse an XML qualified name
*
* [NS 5] QName ::= (Prefix ':')? LocalPart
*
* [NS 6] Prefix ::= NCName
*
* [NS 7] LocalPart ::= NCName
*
* Returns the function returns the local part, and prefix is updated
* to get the Prefix if any.
*/
static xmlChar *
if (CUR == ':') {
NEXT;
}
return(ret);
}
/**
* xmlXPathParseName:
* @ctxt: the XPath Parser context
*
* parse an XML name
*
* [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' |
* CombiningChar | Extender
*
* [5] Name ::= (Letter | '_' | ':') (NameChar)*
*
* Returns the namespace name or NULL
*/
xmlChar *
int count = 0;
/*
* Accelerator for simple ASCII names
*/
in++;
in++;
return(ret);
}
}
}
static xmlChar *
int len = 0, l;
int c;
/*
* Handler for more complex cases
*/
c = CUR_CHAR(l);
if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
(c == '[') || (c == ']') || (c == '@') || /* accelerators */
(c == '*') || /* accelerators */
(!IS_LETTER(c) && (c != '_') &&
((qualified) && (c != ':')))) {
return(NULL);
}
(c == '.') || (c == '-') ||
(IS_COMBINING(c)) ||
(IS_EXTENDER(c)))) {
NEXTL(l);
c = CUR_CHAR(l);
if (len >= XML_MAX_NAMELEN) {
/*
* Okay someone managed to make a huge name, so he's ready to pay
* for the processing speed.
*/
}
(c == '.') || (c == '-') ||
(IS_COMBINING(c)) ||
(IS_EXTENDER(c))) {
max *= 2;
}
}
NEXTL(l);
c = CUR_CHAR(l);
}
return(buffer);
}
}
if (len == 0)
return(NULL);
}
#define MAX_FRAC 20
/*
* These are used as divisors for the fractional part of a number.
* Since the table includes 1.0 (representing '0' fractional digits),
* it must be dimensioned at MAX_FRAC+1 (bug 133921)
*/
1.0, 10.0, 100.0, 1000.0, 10000.0,
100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0,
10000000000.0, 100000000000.0, 1000000000000.0, 10000000000000.0,
100000000000000.0,
1000000000000000.0, 10000000000000000.0, 100000000000000000.0,
1000000000000000000.0, 10000000000000000000.0, 100000000000000000000.0
};
/**
* xmlXPathStringEvalNumber:
* @str: A string to scan
*
* [30a] Float ::= Number ('e' Digits?)?
*
* [30] Number ::= Digits ('.' Digits?)?
* | '.' Digits
* [31] Digits ::= [0-9]+
*
* Compile a Number in the string
* In complement of the Number expression, this function also handles
* negative values : '-' Number.
*
* Returns the double value.
*/
double
double ret;
int ok = 0;
int isneg = 0;
int exponent = 0;
int is_exponent_negative = 0;
#ifdef __GNUC__
unsigned long tmp = 0;
double temp;
#endif
return(xmlXPathNAN);
}
if (*cur == '-') {
isneg = 1;
cur++;
}
#ifdef __GNUC__
/*
*/
ret = 0;
ok = 1;
cur++;
}
#else
ret = 0;
ok = 1;
cur++;
}
#endif
if (*cur == '.') {
int v, frac = 0;
double fraction = 0;
cur++;
return(xmlXPathNAN);
}
v = (*cur - '0');
cur++;
}
cur++;
}
cur++;
if (*cur == '-') {
is_exponent_negative = 1;
cur++;
} else if (*cur == '+') {
cur++;
}
cur++;
}
}
if (*cur != 0) return(xmlXPathNAN);
return(ret);
}
/**
* xmlXPathCompNumber:
* @ctxt: the XPath Parser context
*
* [30] Number ::= Digits ('.' Digits?)?
* | '.' Digits
* [31] Digits ::= [0-9]+
*
* Compile a Number, then push it on the stack
*
*/
static void
{
double ret = 0.0;
double mult = 1;
int ok = 0;
int exponent = 0;
int is_exponent_negative = 0;
#ifdef __GNUC__
unsigned long tmp = 0;
double temp;
#endif
}
#ifdef __GNUC__
/*
*/
ret = 0;
ok = 1;
NEXT;
}
#else
ret = 0;
ok = 1;
NEXT;
}
#endif
if (CUR == '.') {
NEXT;
}
mult /= 10;
NEXT;
}
}
NEXT;
if (CUR == '-') {
is_exponent_negative = 1;
NEXT;
} else if (CUR == '+') {
NEXT;
}
NEXT;
}
if (is_exponent_negative)
}
}
/**
* xmlXPathParseLiteral:
* @ctxt: the XPath Parser context
*
* Parse a Literal
*
* [29] Literal ::= '"' [^"]* '"'
* | "'" [^']* "'"
*
* Returns the value found or NULL in case of error
*/
static xmlChar *
const xmlChar *q;
if (CUR == '"') {
NEXT;
q = CUR_PTR;
NEXT;
if (!IS_CHAR_CH(CUR)) {
} else {
NEXT;
}
} else if (CUR == '\'') {
NEXT;
q = CUR_PTR;
NEXT;
if (!IS_CHAR_CH(CUR)) {
} else {
NEXT;
}
} else {
}
return(ret);
}
/**
* xmlXPathCompLiteral:
* @ctxt: the XPath Parser context
*
* Parse a Literal and push it on the stack.
*
* [29] Literal ::= '"' [^"]* '"'
* | "'" [^']* "'"
*
* TODO: xmlXPathCompLiteral memory allocation could be improved.
*/
static void
const xmlChar *q;
if (CUR == '"') {
NEXT;
q = CUR_PTR;
NEXT;
if (!IS_CHAR_CH(CUR)) {
} else {
NEXT;
}
} else if (CUR == '\'') {
NEXT;
q = CUR_PTR;
NEXT;
if (!IS_CHAR_CH(CUR)) {
} else {
NEXT;
}
} else {
}
}
/**
* xmlXPathCompVariableReference:
* @ctxt: the XPath Parser context
*
* Parse a VariableReference, evaluate it and push it on the stack.
*
* The variable bindings consist of a mapping from variable names
* to variable values. The value of a variable is an object, which can be
* of any of the types that are possible for the value of an expression,
* and may also be of additional types not specified here.
*
* Early evaluation is possible since:
* The variable bindings [...] used to evaluate a subexpression are
* always the same as those used to evaluate the containing expression.
*
* [36] VariableReference ::= '$' QName
*/
static void
if (CUR != '$') {
}
NEXT;
}
PUSH_LONG_EXPR(XPATH_OP_VARIABLE, 0, 0, 0,
}
}
/**
* xmlXPathIsNodeType:
* @name: a name string
*
* Is the name given a NodeType one.
*
* [38] NodeType ::= 'comment'
* | 'text'
* | 'processing-instruction'
* | 'node'
*
* Returns 1 if true 0 otherwise
*/
int
return(0);
return(1);
return(1);
return(1);
return(1);
return(0);
}
/**
* xmlXPathCompFunctionCall:
* @ctxt: the XPath Parser context
*
* [16] FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument)*)? ')'
* [17] Argument ::= Expr
*
* Compile a function call, the evaluation of all arguments are
* pushed on the stack
*/
static void
int nbargs = 0;
int sort = 1;
}
#ifdef DEBUG_EXPR
name);
else
#endif
if (CUR != '(') {
}
NEXT;
/*
* Optimization for count(): we don't need the node-set to be sorted.
*/
{
sort = 0;
}
if (CUR != ')') {
while (CUR != 0) {
nbargs++;
if (CUR == ')') break;
if (CUR != ',') {
}
NEXT;
}
}
NEXT;
}
/**
* xmlXPathCompPrimaryExpr:
* @ctxt: the XPath Parser context
*
* [15] PrimaryExpr ::= VariableReference
* | '(' Expr ')'
* | Literal
* | Number
* | FunctionCall
*
* Compile a primary expression.
*/
static void
else if (CUR == '(') {
NEXT;
if (CUR != ')') {
}
NEXT;
} else {
}
}
/**
* xmlXPathCompFilterExpr:
* @ctxt: the XPath Parser context
*
* [20] FilterExpr ::= PrimaryExpr
* | FilterExpr Predicate
*
* Compile a filter expression.
* Square brackets are used to filter expressions in the same way that
* they are used in location paths. It is an error if the expression to
* be filtered does not evaluate to a node-set. The context node list
* used for evaluating the expression in square brackets is the node-set
* to be filtered listed in document order.
*/
static void
while (CUR == '[') {
}
}
/**
* xmlXPathScanName:
* @ctxt: the XPath Parser context
*
* Trickery: parse an XML name but without consuming the input flow
* Needed to avoid insanity in the parser state.
*
* [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' |
* CombiningChar | Extender
*
* [5] Name ::= (Letter | '_' | ':') (NameChar)*
*
* [6] Names ::= Name (S Name)*
*
* Returns the Name parsed or NULL
*/
static xmlChar *
int len = 0, l;
int c;
c = CUR_CHAR(l);
if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
(!IS_LETTER(c) && (c != '_') &&
(c != ':'))) {
return(NULL);
}
(c == '.') || (c == '-') ||
(c == '_') || (c == ':') ||
(IS_COMBINING(c)) ||
(IS_EXTENDER(c)))) {
len += l;
NEXTL(l);
c = CUR_CHAR(l);
}
return(ret);
}
/**
* xmlXPathCompPathExpr:
* @ctxt: the XPath Parser context
*
* [19] PathExpr ::= LocationPath
* | FilterExpr
* | FilterExpr '/' RelativeLocationPath
* | FilterExpr '//' RelativeLocationPath
*
* Compile a path expression.
* The / operator and // operators combine an arbitrary expression
* and a relative location path. It is an error if the expression
* does not evaluate to a node-set.
* The / operator does composition in the same way as when / is
* used in a location path. As in location paths, // is short for
* /descendant-or-self::node()/.
*/
static void
(IS_ASCII_DIGIT(CUR)) ||
lc = 0;
} else if (CUR == '*') {
/* relative or absolute location path */
lc = 1;
} else if (CUR == '/') {
/* relative or absolute location path */
lc = 1;
} else if (CUR == '@') {
/* relative abbreviated attribute location path */
lc = 1;
} else if (CUR == '.') {
/* relative abbreviated attribute location path */
lc = 1;
} else {
/*
* Problem is finding if we have a name here whether it's:
* - a nodetype
* - a function call in which case it's followed by '('
* - an axis in which case it's followed by ':'
* - a element name
* We do an a priori analysis here rather than having to
* maintain parsed token content through the recursive function
* calls. This looks uglier but makes the code easier to
*/
#ifdef DEBUG_STEP
"PathExpr: Axis\n");
#endif
lc = 1;
/* element name */
#ifdef DEBUG_STEP
"PathExpr: AbbrRelLocation\n");
#endif
lc = 1;
break;
/* ignore blanks */
;
#ifdef DEBUG_STEP
"PathExpr: AbbrRelLocation\n");
#endif
lc = 1;
break;
/* Note Type or Function */
if (xmlXPathIsNodeType(name)) {
#ifdef DEBUG_STEP
"PathExpr: Type search\n");
#endif
lc = 1;
} else {
#ifdef DEBUG_STEP
"PathExpr: function call\n");
#endif
lc = 0;
}
break;
/* element name */
#ifdef DEBUG_STEP
"PathExpr: AbbrRelLocation\n");
#endif
lc = 1;
break;
lc = 1;
break;
} else {
lc = 1;
break;
}
len++;
}
#ifdef DEBUG_STEP
"PathExpr: AbbrRelLocation\n");
#endif
/* element name */
lc = 1;
}
} else {
/* make sure all cases are covered explicitly */
}
}
if (lc) {
if (CUR == '/') {
PUSH_LEAVE_EXPR(XPATH_OP_ROOT, 0, 0);
} else {
PUSH_LEAVE_EXPR(XPATH_OP_NODE, 0, 0);
}
} else {
SKIP(2);
} else if (CUR == '/') {
}
}
}
/**
* xmlXPathCompUnionExpr:
* @ctxt: the XPath Parser context
*
* [18] UnionExpr ::= PathExpr
* | UnionExpr '|' PathExpr
*
* Compile an union expression.
*/
static void
while (CUR == '|') {
PUSH_LEAVE_EXPR(XPATH_OP_NODE, 0, 0);
NEXT;
}
}
/**
* xmlXPathCompUnaryExpr:
* @ctxt: the XPath Parser context
*
* [27] UnaryExpr ::= UnionExpr
* | '-' UnaryExpr
*
* Compile an unary expression.
*/
static void
int minus = 0;
int found = 0;
while (CUR == '-') {
found = 1;
NEXT;
}
if (found) {
if (minus)
else
}
}
/**
* xmlXPathCompMultiplicativeExpr:
* @ctxt: the XPath Parser context
*
* [26] MultiplicativeExpr ::= UnaryExpr
* | MultiplicativeExpr MultiplyOperator UnaryExpr
* | MultiplicativeExpr 'div' UnaryExpr
* | MultiplicativeExpr 'mod' UnaryExpr
* [34] MultiplyOperator ::= '*'
*
* Compile an Additive expression.
*/
static void
while ((CUR == '*') ||
int op = -1;
if (CUR == '*') {
op = 0;
NEXT;
} else if (CUR == 'd') {
op = 1;
SKIP(3);
} else if (CUR == 'm') {
op = 2;
SKIP(3);
}
}
}
/**
* xmlXPathCompAdditiveExpr:
* @ctxt: the XPath Parser context
*
* [25] AdditiveExpr ::= MultiplicativeExpr
* | AdditiveExpr '+' MultiplicativeExpr
* | AdditiveExpr '-' MultiplicativeExpr
*
* Compile an Additive expression.
*/
static void
int plus;
else plus = 0;
NEXT;
}
}
/**
* xmlXPathCompRelationalExpr:
* @ctxt: the XPath Parser context
*
* [24] RelationalExpr ::= AdditiveExpr
* | RelationalExpr '<' AdditiveExpr
* | RelationalExpr '>' AdditiveExpr
* | RelationalExpr '<=' AdditiveExpr
* | RelationalExpr '>=' AdditiveExpr
*
* A <= B > C is allowed ? Answer from James, yes with
* (AdditiveExpr <= AdditiveExpr) > AdditiveExpr
* which is basically what got implemented.
*
* Compile a Relational expression, then push the result
* on the stack
*/
static void
while ((CUR == '<') ||
(CUR == '>') ||
else inf = 0;
else strict = 1;
NEXT;
}
}
/**
* xmlXPathCompEqualityExpr:
* @ctxt: the XPath Parser context
*
* [23] EqualityExpr ::= RelationalExpr
* | EqualityExpr '=' RelationalExpr
* | EqualityExpr '!=' RelationalExpr
*
* A != B != C is allowed ? Answer from James, yes with
* (RelationalExpr = RelationalExpr) = RelationalExpr
* (RelationalExpr != RelationalExpr) != RelationalExpr
* which is basically what got implemented.
*
* Compile an Equality expression.
*
*/
static void
int eq;
else eq = 0;
NEXT;
}
}
/**
* xmlXPathCompAndExpr:
* @ctxt: the XPath Parser context
*
* [22] AndExpr ::= EqualityExpr
* | AndExpr 'and' EqualityExpr
*
* Compile an AND expression.
*
*/
static void
SKIP(3);
}
}
/**
* xmlXPathCompileExpr:
* @ctxt: the XPath Parser context
*
* [14] Expr ::= OrExpr
* [21] OrExpr ::= AndExpr
* | OrExpr 'or' AndExpr
*
* Parse and compile an expression
*/
static void
SKIP(2);
}
/* more ops could be optimized too */
/*
* This is the main place to eliminate sorting for
* operations which don't require a sorted node-set.
* E.g. count().
*/
}
}
/**
* xmlXPathCompPredicate:
* @ctxt: the XPath Parser context
* @filter: act as a filter
*
* [8] Predicate ::= '[' PredicateExpr ']'
* [9] PredicateExpr ::= Expr
*
* Compile a predicate expression
*/
static void
if (CUR != '[') {
}
NEXT;
/*
* This call to xmlXPathCompileExpr() will deactivate sorting
* of the predicate result.
* TODO: Sorting is still activated for filters, since I'm not
* sure if needed. Normally sorting should not be needed, since
* a filter can only diminish the number of items in a sequence,
* but won't change its order; so if the initial sequence is sorted,
* subsequent sorting is not needed.
*/
if (! filter)
xmlXPathCompileExpr(ctxt, 0);
else
if (CUR != ']') {
}
if (filter)
else
NEXT;
}
/**
* xmlXPathCompNodeTest:
* @ctxt: the XPath Parser context
* @test: pointer to a xmlXPathTestVal
* @type: pointer to a xmlXPathTypeVal
* @prefix: placeholder for a possible name prefix
*
* [7] NodeTest ::= NameTest
* | NodeType '(' ')'
* | 'processing-instruction' '(' Literal ')'
*
* [37] NameTest ::= '*'
* | NCName ':' '*'
* | QName
* [38] NodeType ::= 'comment'
* | 'text'
* | 'processing-instruction'
* | 'node'
*
* Returns the name found and updates @test, @type and @prefix appropriately
*/
static xmlChar *
int blanks;
return(NULL);
}
*type = (xmlXPathTypeVal) 0;
*test = (xmlXPathTestVal) 0;
/*
* All elements
*/
NEXT;
*test = NODE_TEST_ALL;
return(NULL);
}
}
if (CUR == '(') {
NEXT;
/*
* NodeType or PI search
*/
*type = NODE_TYPE_NODE;
*type = NODE_TYPE_PI;
*type = NODE_TYPE_TEXT;
else {
}
*test = NODE_TEST_TYPE;
if (*type == NODE_TYPE_PI) {
/*
* Specific case: search a PI by name.
*/
if (CUR != ')') {
*test = NODE_TEST_PI;
}
}
if (CUR != ')') {
}
NEXT;
return(name);
}
*test = NODE_TEST_NAME;
NEXT;
/*
* Since currently the parser context don't have a
* namespace list associated:
* The namespace name for this prefix can be computed
* only at evaluation time. The compilation is done
* outside of any context.
*/
#if 0
}
#else
#endif
if (CUR == '*') {
/*
* All elements
*/
NEXT;
*test = NODE_TEST_ALL;
return(NULL);
}
}
}
return(name);
}
/**
* xmlXPathIsAxisName:
* @name: a preparsed name token
*
* [6] AxisName ::= 'ancestor'
* | 'ancestor-or-self'
* | 'attribute'
* | 'child'
* | 'descendant'
* | 'descendant-or-self'
* | 'following'
* | 'following-sibling'
* | 'namespace'
* | 'parent'
* | 'preceding'
* | 'preceding-sibling'
* | 'self'
*
* Returns the axis or 0
*/
static xmlXPathAxisVal
switch (name[0]) {
case 'a':
ret = AXIS_ANCESTOR;
break;
case 'c':
ret = AXIS_CHILD;
break;
case 'd':
break;
case 'f':
break;
case 'n':
break;
case 'p':
ret = AXIS_PARENT;
break;
case 's':
break;
}
return(ret);
}
/**
* xmlXPathCompStep:
* @ctxt: the XPath Parser context
*
* [4] Step ::= AxisSpecifier NodeTest Predicate*
* | AbbreviatedStep
*
* [12] AbbreviatedStep ::= '.' | '..'
*
* [5] AxisSpecifier ::= AxisName '::'
* | AbbreviatedAxisSpecifier
*
* [13] AbbreviatedAxisSpecifier ::= '@'?
*
* Modified for XPtr range support as:
*
* [4xptr] Step ::= AxisSpecifier NodeTest Predicate*
* | AbbreviatedStep
* | 'range-to' '(' Expr ')' Predicate*
*
* Compile one step in a Location Path
* A location step of . is short for self::node(). This is
* particularly useful in conjunction with //. For example, the
* location path .//para is short for
* self::node()/descendant-or-self::node()/child::para
* and so will select all para descendant elements of the context
* node.
* Similarly, a location step of .. is short for parent::node().
* For example, ../title is short for parent::node()/child::title
* and so will select the title children of the parent of the context
* node.
*/
static void
#ifdef LIBXML_XPTR_ENABLED
int rangeto = 0;
int op2 = -1;
#endif
SKIP(2);
} else if (CUR == '.') {
NEXT;
} else {
int op1;
/*
* The modification needed for XPointer change to the production
*/
#ifdef LIBXML_XPTR_ENABLED
if (CUR != '(') {
}
NEXT;
/* PUSH_BINARY_EXPR(XPATH_OP_RANGETO, op2, ctxt->comp->last, 0, 0); */
if (CUR != ')') {
}
NEXT;
rangeto = 1;
goto eval_predicates;
}
}
#endif
if (CUR == '*') {
axis = AXIS_CHILD;
} else {
if (axis != 0) {
SKIP(2);
} else {
/* an element name can conflict with an axis one :-\ */
axis = AXIS_CHILD;
}
} else {
axis = AXIS_CHILD;
}
} else if (CUR == '@') {
NEXT;
} else {
axis = AXIS_CHILD;
}
}
if (test == 0)
return;
}
}
#ifdef DEBUG_STEP
"Basis : computing new set\n");
#endif
#ifdef DEBUG_STEP
else
#endif
#ifdef LIBXML_XPTR_ENABLED
#endif
while (CUR == '[') {
}
#ifdef LIBXML_XPTR_ENABLED
if (rangeto) {
} else
#endif
}
#ifdef DEBUG_STEP
else
#endif
}
/**
* xmlXPathCompRelativeLocationPath:
* @ctxt: the XPath Parser context
*
* [3] RelativeLocationPath ::= Step
* | RelativeLocationPath '/' Step
* | AbbreviatedRelativeLocationPath
* [11] AbbreviatedRelativeLocationPath ::= RelativeLocationPath '//' Step
*
* Compile a relative location path.
*/
static void
SKIP(2);
} else if (CUR == '/') {
NEXT;
}
while (CUR == '/') {
SKIP(2);
} else if (CUR == '/') {
NEXT;
}
}
}
/**
* xmlXPathCompLocationPath:
* @ctxt: the XPath Parser context
*
* [1] LocationPath ::= RelativeLocationPath
* | AbsoluteLocationPath
* [2] AbsoluteLocationPath ::= '/' RelativeLocationPath?
* | AbbreviatedAbsoluteLocationPath
* [10] AbbreviatedAbsoluteLocationPath ::=
* '//' RelativeLocationPath
*
* Compile a location path
*
* // is short for /descendant-or-self::node()/. For example,
* //para is short for /descendant-or-self::node()/child::para and
* so will select any para element in the document (even a para element
* that is a document element will be selected by //para since the
* document element node is a child of the root node); div//para is
* short for div/descendant-or-self::node()/child::para and so will
* select all para descendants of div children.
*/
static void
if (CUR != '/') {
} else {
while (CUR == '/') {
SKIP(2);
} else if (CUR == '/') {
NEXT;
if ((CUR != 0 ) &&
}
}
}
}
/************************************************************************
* *
* XPath precompiled expression evaluation *
* *
************************************************************************/
static int
#ifdef DEBUG_STEP
static void
int nbNodes)
{
switch (axis) {
case AXIS_ANCESTOR:
break;
case AXIS_ANCESTOR_OR_SELF:
"axis 'ancestors-or-self' ");
break;
case AXIS_ATTRIBUTE:
break;
case AXIS_CHILD:
break;
case AXIS_DESCENDANT:
break;
case AXIS_DESCENDANT_OR_SELF:
"axis 'descendant-or-self' ");
break;
case AXIS_FOLLOWING:
break;
case AXIS_FOLLOWING_SIBLING:
"axis 'following-siblings' ");
break;
case AXIS_NAMESPACE:
break;
case AXIS_PARENT:
break;
case AXIS_PRECEDING:
break;
case AXIS_PRECEDING_SIBLING:
"axis 'preceding-sibling' ");
break;
case AXIS_SELF:
break;
}
" context contains %d nodes\n", nbNodes);
switch (test) {
case NODE_TEST_NONE:
" searching for none !!!\n");
break;
case NODE_TEST_TYPE:
" searching for type %d\n", type);
break;
case NODE_TEST_PI:
" searching for PI !!!\n");
break;
case NODE_TEST_ALL:
" searching for *\n");
break;
case NODE_TEST_NS:
" searching for namespace %s\n",
prefix);
break;
case NODE_TEST_NAME:
" searching for name %s\n", name);
" with namespace %s\n", prefix);
break;
}
}
#endif /* DEBUG_STEP */
static int
int contextSize,
int hasNsNodes)
{
/*
* Process inner predicates first.
*/
/*
* TODO: raise an internal error.
*/
}
if (contextSize <= 0)
return(0);
}
#ifdef LIBXML_XPTR_ENABLED
/*
* URGENT TODO: Check the following:
* We don't expect location sets if evaluating prediates, right?
* Only filters should expect location sets, right?
*/
#endif
/*
* SPEC XPath 1.0:
* "For each node in the node-set to be filtered, the
* PredicateExpr is evaluated with that node as the
* context node, with the number of nodes in the
* node-set as the context size, and with the proximity
* position of the node in the node-set with respect to
* the axis as the context position;"
* @oldset is the node-set" to be filtered.
*
* SPEC XPath 1.0:
* "only predicates change the context position and
* context size (see [2.4 Predicates])."
* Example:
* node-set context pos
* nA 1
* nB 2
* nC 3
* After applying predicate [position() > 1] :
* node-set context pos
* nB 1
* nC 2
*/
/*
* Get the expression of this predicate.
*/
newContextSize = 0;
continue;
/*
* Also set the xpath document in case things like
* key() are evaluated in the predicate.
*/
/*
* Evaluate the predicate expression with 1 context node
* at a time; this node is packaged into a node set; this
* node set is handed over to the evaluation mechanism.
*/
if (contextObj == NULL)
else
newContextSize = 0;
goto evaluation_exit;
}
if (res != 0) {
} else {
/*
* Remove the entry from the initial node set.
*/
}
/*
* Don't free the temporary XPath object holding the
* context node, in order to avoid massive recreation
* inside this loop.
*/
} else {
/*
* TODO: The object was lost in the evaluation machinery.
* Can this happen? Maybe in internal-error cases.
*/
contextObj = NULL;
}
}
if (contextObj != NULL) {
}
/*
* Reset/invalidate the context.
*/
return(newContextSize);
}
return(contextSize);
}
static int
int contextSize,
int minPos,
int maxPos,
int hasNsNodes)
{
/*
* TODO: raise an internal error.
*/
}
if (contextSize <= 0)
return(0);
}
/*
* Check if the node set contains a sufficient number of nodes for
* the requested range.
*/
if (contextSize < minPos) {
return(0);
}
/*
* TODO: Can this ever happen?
*/
return (contextSize);
} else {
#ifdef LIBXML_XPTR_ENABLED
/*
* URGENT TODO: Check the following:
* We don't expect location sets if evaluating prediates, right?
* Only filters should expect location sets, right?
*/
#endif /* LIBXML_XPTR_ENABLED */
/*
* Save old context.
*/
/*
* Get the expression of this predicate.
*/
continue;
/*
* Initialize the new set.
* Also set the xpath document in case things like
* key() evaluation are attempted on the predicate
*/
/*
* Evaluate the predicate expression with 1 context node
* at a time; this node is packaged into a node set; this
* node set is handed over to the evaluation mechanism.
*/
if (contextObj == NULL)
else
/* pop the result */
/* then pop off contextObj, which will be freed later */
goto evaluation_error;
}
if (res)
pos++;
/*
* Fits in the requested range.
*/
/*
* Only 1 node was requested.
*/
/*
* As always: take care of those nasty
* namespace nodes.
*/
}
goto evaluation_exit;
}
/*
* We are done.
*/
goto evaluation_exit;
}
} else {
/*
* Remove the entry from the initial node set.
*/
}
}
/*
* Don't free the temporary XPath object holding the
* context node, in order to avoid massive recreation
* inside this loop.
*/
} else {
/*
* The object was lost in the evaluation machinery.
* Can this happen? Maybe in case of internal-errors.
*/
contextObj = NULL;
}
}
goto evaluation_exit;
newContextSize = 0;
if (contextObj != NULL) {
}
/*
* Reset/invalidate the context.
*/
return(newContextSize);
}
return(contextSize);
}
static int
int *maxPos)
{
/*
* BIG NOTE: This is not intended for XPATH_OP_FILTER yet!
*/
/*
* If not -1, then ch1 will point to:
* 1) For predicates (XPATH_OP_PREDICATE):
* - an inner predicate operator
* 2) For filters (XPATH_OP_FILTER):
* - an inner filter operater OR
* - an expression selecting the node set.
* E.g. "key('a', 'b')" or "(//foo | //bar)".
*/
return(0);
} else
return(0);
{
/*
* We have a "[n]" predicate here.
* TODO: Unfortunately this simplistic test here is not
* able to detect a position() predicate in compound
* expressions like "[@attr = 'a" and position() = 1],
* and even not the usage of position() in
* "[position() = 1]"; thus - obviously - a position-range,
* like it "[position() < 5]", is also not detected.
* Maybe we could rewrite the AST to ease the optimization.
*/
(float) *maxPos)
{
return(1);
}
}
return(0);
}
static int
int toBool)
{
#define XP_TEST_HIT \
if (hasAxisRange != 0) { \
goto axis_range_end; } \
} else { \
if (breakOnFirstHit) goto first_hit; }
#define XP_TEST_HIT_NS \
if (hasAxisRange != 0) { \
hasNsNodes = 1; \
goto axis_range_end; } \
} else { \
hasNsNodes = 1; \
if (breakOnFirstHit) goto first_hit; }
#ifdef DEBUG_STEP
int nbMatches = 0, prevMatches = 0;
#endif
int total = 0, hasNsNodes = 0;
/* The popped object holding the context nodes */
/* The set of context nodes for the node tests */
int contextIdx;
/* The context node for a compound traversal */
/* The final resulting node set wrt to all context nodes */
/*
* The temporary resulting node set wrt 1 context node.
* Used to feed predicate evaluation.
*/
/* First predicate operator */
int maxPos; /* The requested position() (when a "[n]" predicate) */
int breakOnFirstHit;
/* compound axis traversal */
/*
* Setup namespaces.
*/
}
}
/*
* Setup axis.
*
* MAYBE FUTURE TODO: merging optimizations:
* - If the nodes to be traversed wrt to the initial nodes and
* the current axis cannot overlap, then we could avoid searching
* for duplicates during the merge.
* Example: if we know that for two initial nodes, the one is
* not in the ancestor-or-self axis of the other, then we could safely
* avoid a duplicate-aware merge, if the axis to be traversed is e.g.
* the descendant-or-self axis.
*/
switch (axis) {
case AXIS_ANCESTOR:
break;
case AXIS_ANCESTOR_OR_SELF:
break;
case AXIS_ATTRIBUTE:
break;
case AXIS_CHILD:
/*
* This iterator will give us only nodes which can
* hold element nodes.
*/
}
(type == NODE_TYPE_NODE))
{
/*
* Optimization if an element node type is 'element'.
*/
} else
break;
case AXIS_DESCENDANT:
break;
case AXIS_DESCENDANT_OR_SELF:
break;
case AXIS_FOLLOWING:
break;
case AXIS_FOLLOWING_SIBLING:
break;
case AXIS_NAMESPACE:
break;
case AXIS_PARENT:
break;
case AXIS_PRECEDING:
break;
case AXIS_PRECEDING_SIBLING:
break;
case AXIS_SELF:
break;
}
#ifdef DEBUG_STEP
#endif
return(0);
}
return(0);
}
/*
* Predicate optimization ---------------------------------------------
* If this step has a last predicate, which contains a position(),
* then we'll optimize (although not exactly "position()", but only
* the short-hand form, i.e., "[n]".
*
* Example - expression "/foo[parent::bar][1]":
*
* COLLECT 'child' 'name' 'node' foo -- op (we are here)
* ROOT -- op->ch1
* PREDICATE -- op->ch2 (predOp)
* PREDICATE -- predOp->ch1 = [parent::bar]
* SORT
* COLLECT 'parent' 'name' 'node' bar
* NODE
* ELEM Object is a number : 1 -- predOp->ch2 = [1]
*
*/
maxPos = 0;
hasPredicateRange = 0;
hasAxisRange = 0;
/*
* There's at least one predicate. 16 == XPATH_OP_PREDICATE
*/
/*
* Use the next inner predicate operator.
*/
hasPredicateRange = 1;
} else {
/*
* There's no other predicate than the [n] predicate.
*/
hasAxisRange = 1;
}
}
}
/*
* Axis traversal -----------------------------------------------------
*/
/*
* 2.3 Node Tests
* - For the attribute axis, the principal node type is attribute.
* - For the namespace axis, the principal node type is namespace.
* - For other axes, the principal node type is element.
*
* A node test * is true for any node of the
* principal node type. For example, child::* will
* select all element children of the context node
*/
contextNode = NULL;
contextIdx = 0;
/*
* This is a compound traversal.
*/
if (contextNode == NULL) {
/*
* Set the context for the outer traversal.
*/
} else
if (contextNode == NULL)
continue;
/*
* Set the context for the main traversal.
*/
} else
total = 0;
goto error;
}
}
/*
* Traverse the axis and test the nodes.
*/
pos = 0;
hasNsNodes = 0;
do {
break;
/*
* QUESTION TODO: What does the "first" and "last" stuff do?
*/
break;
if (((total % 256) == 0) &&
#else
#endif
{
break;
}
}
break;
if (((total % 256) == 0) &&
#else
#endif
{
break;
}
}
total++;
#ifdef DEBUG_STEP
#endif
switch (test) {
case NODE_TEST_NONE:
total = 0;
goto error;
case NODE_TEST_TYPE:
/*
* TODO: Don't we need to use
* xmlXPathNodeSetAddNs() for namespace nodes here?
* Surprisingly, some c14n tests fail, if we do this.
*/
if (type == NODE_TYPE_NODE) {
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
case XML_NAMESPACE_DECL:
break;
default:
break;
}
if (type == XML_NAMESPACE_DECL)
else
} else if ((type == NODE_TYPE_TEXT) &&
{
}
break;
case NODE_TEST_PI:
{
}
break;
case NODE_TEST_ALL:
if (axis == AXIS_ATTRIBUTE) {
{
}
} else if (axis == AXIS_NAMESPACE) {
{
}
} else {
{
{
}
}
}
break;
case NODE_TEST_NS:{
TODO;
break;
}
case NODE_TEST_NAME:
if (axis == AXIS_ATTRIBUTE) {
break;
} else if (axis == AXIS_NAMESPACE) {
break;
} else {
break;
}
case XML_ELEMENT_NODE:
{
}
} else {
{
}
}
}
break;
case XML_ATTRIBUTE_NODE:{
{
}
} else {
{
}
}
}
break;
}
case XML_NAMESPACE_DECL:
{
}
}
break;
default:
break;
}
break;
} /* switch(test) */
goto apply_predicates;
axis_range_end: /* ----------------------------------------------------- */
/*
* We have a "/foo[n]", and position() = n was reached.
* Note that we can have as well "/foo/::parent::foo[1]", so
* a duplicate-aware merge is still needed.
* Merge with the result.
*/
} else
/*
*/
if (toBool)
break;
continue;
first_hit: /* ---------------------------------------------------------- */
/*
* no predicates existed and a node test succeeded.
*/
} else
break;
#ifdef DEBUG_STEP
#endif
apply_predicates: /* --------------------------------------------------- */
/*
* Apply predicates.
*/
/*
* E.g. when we have a "/foo[some expression][n]".
*/
/*
* QUESTION TODO: The old predicate evaluation took into
* account location-sets.
* (E.g. ctxt->value->type == XPATH_LOCATIONSET)
* Do we expect such a set here?
* All what I learned now from the evaluation semantics
* does not indicate that a location-set will be processed
* here, so this looks OK.
*/
/*
* Iterate over all predicates, starting with the outermost
* predicate.
* TODO: Problem: we cannot execute the inner predicates first
* since we cannot go back *up* the operator tree!
* Options we have:
* 1) Use of recursive functions (like is it currently done
* via xmlXPathCompOpEval())
* 2) Add a predicate evaluation information stack to the
* context struct
* 3) Change the way the operators are linked; we need a
* "parent" field on xmlXPathStepOp
*
* For the moment, I'll try to solve this with a recursive
* function: xmlXPathCompOpEvalPredicate().
*/
if (hasPredicateRange != 0)
else
total = 0;
goto error;
}
/*
* Add the filtered set of nodes to the result node set.
*/
if (newSize == 0) {
/*
* The predicates filtered all nodes out.
*/
/*
* Add to result set.
*/
/*
* We need to merge and clear here, since
* the sequence will contained NULLed entries.
*/
} else {
}
} else
/*
*/
if (toBool)
break;
}
/*
* Add to result set.
*/
} else {
}
}
}
/*
* QUESTION TODO: What does this do and why?
* TODO: Do we have to do this also for the "error"
* cleanup further down?
*/
}
/*
* Ensure we return at least an emtpy set.
*/
else
}
}
/*
* Hand over the result. Better to push the set also in
* case of errors.
*/
/*
* Reset the context node.
*/
#ifdef DEBUG_STEP
"\nExamined %d nodes, found %d nodes at that step\n",
#endif
return(total);
}
static int
/**
* xmlXPathCompOpEvalFirst:
* @ctxt: the XPath parser context with the compiled expression
* @op: an XPath compiled operation
* @first: the first elem found so far
*
* Evaluate the Precompiled XPath operation searching only the first
* element in document order
*
* Returns the number of examined objects.
*/
static int
{
case XPATH_OP_END:
return (0);
case XPATH_OP_UNION:
total =
first);
/*
* limit tree traversing to first node in the result
*/
/*
* OPTIMIZE TODO: This implicitely sorts
* the result, even if not needed. E.g. if the argument
* of the count() function, no sorting is needed.
* OPTIMIZE TODO: How do we know if the node-list wasn't
* aready sorted?
*/
}
cur =
first);
arg2->nodesetval);
/* optimizer */
case XPATH_OP_ROOT:
return (0);
case XPATH_OP_NODE:
return (total);
case XPATH_OP_RESET:
return (total);
case XPATH_OP_COLLECT:{
return (total);
return (total);
}
case XPATH_OP_VALUE:
return (0);
case XPATH_OP_SORT:
total +=
first);
return (total);
#ifdef XP_OPTIMIZED_FILTER_FIRST
case XPATH_OP_FILTER:
return (total);
#endif
default:
}
}
/**
* xmlXPathCompOpEvalLast:
* @ctxt: the XPath parser context with the compiled expression
* @op: an XPath compiled operation
* @last: the last elem found so far
*
* Evaluate the Precompiled XPath operation searching only the last
* element in document order
*
* Returns the number of nodes traversed
*/
static int
xmlNodePtr * last)
{
int pp;
int cs;
case XPATH_OP_END:
return (0);
case XPATH_OP_UNION:
total =
/*
* limit tree traversing to first node in the result
*/
*last =
nodesetval->nodeNr -
1];
}
cur =
}
arg2->nodesetval);
/* optimizer */
case XPATH_OP_ROOT:
return (0);
case XPATH_OP_NODE:
return (total);
case XPATH_OP_RESET:
return (total);
case XPATH_OP_COLLECT:{
return (0);
return (total);
}
case XPATH_OP_VALUE:
return (0);
case XPATH_OP_SORT:
total +=
last);
return (total);
default:
}
}
#ifdef XP_OPTIMIZED_FILTER_FIRST
static int
{
int total = 0;
int i;
/*
* Optimization for ()[last()] selection i.e. the last elem
*/
if ((f != -1) &&
total +=
&last);
/*
* The nodeset should be in document order,
* Keep only the last value
*/
value->
nodeNr -
1];
}
return (total);
}
}
return (total);
return (total);
#ifdef LIBXML_XPTR_ENABLED
/*
* Hum are we filtering the result of an XPointer expression
*/
/*
* Extract the old locset, and then evaluate the result of the
* expression for all the element in the locset. use it to grow
* up a new locset.
*/
}
return (total);
}
/*
* Run the evaluation with a node list made of a
* single item in the nodelocset.
*/
} else {
}
return(0);
}
/*
* The result of the evaluation need to be tested to
* decided whether the filter succeeded or not
*/
}
/*
* Cleanup
*/
}
/*
* REVISIT TODO: Don't create a temporary nodeset
* for everly iteration.
*/
/* OLD: xmlXPathFreeObject(res); */
} else
/*
* Only put the first node in the result, then leave.
*/
break;
}
}
}
/*
* The result is used as the new evaluation locset.
*/
return (total);
}
#endif /* LIBXML_XPTR_ENABLED */
/*
* Extract the old set, and then evaluate the result of the
* expression for all the element in the set. use it to grow
* up a new set.
*/
/* QUESTION TODO: Why was this code commented out?
if (op->ch2 != -1)
total +=
xmlXPathCompOpEval(ctxt,
&comp->steps[op->ch2]);
CHECK_ERROR0;
res = valuePop(ctxt);
if (res != NULL)
xmlXPathFreeObject(res);
*/
} else {
/*
* Initialize the new set.
* Also set the xpath document in case things like
* key() evaluation are attempted on the predicate
*/
/*
* Run the evaluation with a node list made of
* a single item in the nodeset.
*/
} else {
}
return(0);
}
/*
* The result of the evaluation needs to be tested to
* decide whether the filter succeeded or not
*/
}
/*
* Cleanup
*/
}
/*
* Don't free the temporary nodeset
* in order to avoid massive recreation inside this
* loop.
*/
} else
/*
* Only put the first node in the result, then leave.
*/
break;
}
}
}
/*
* The result is used as the new evaluation set.
*/
/* may want to move this past the '}' later */
}
return(total);
}
#endif /* XP_OPTIMIZED_FILTER_FIRST */
/**
* xmlXPathCompOpEval:
* @ctxt: the XPath parser context with the compiled expression
* @op: an XPath compiled operation
*
* Evaluate the Precompiled XPath operation
* Returns the number of nodes traversed
*/
static int
{
int total = 0;
int pp;
int cs;
case XPATH_OP_END:
return (0);
case XPATH_OP_AND:
return (total);
return(0);
}
return (total);
case XPATH_OP_OR:
return (total);
return(0);
}
return (total);
case XPATH_OP_EQUAL:
else
return (total);
case XPATH_OP_CMP:
return (total);
case XPATH_OP_PLUS:
}
}
return (total);
case XPATH_OP_MULT:
return (total);
case XPATH_OP_UNION:
{
arg2->nodesetval);
}
return (total);
case XPATH_OP_ROOT:
return (total);
case XPATH_OP_NODE:
return (total);
case XPATH_OP_RESET:
return (total);
case XPATH_OP_COLLECT:{
return (total);
return (total);
}
case XPATH_OP_VALUE:
return (total);
case XPATH_OP_VARIABLE:{
total +=
return(0);
}
} else {
"xmlXPathCompOpEval: variable %s bound to undefined prefix %s\n",
return (total);
}
return(0);
}
}
return (total);
}
case XPATH_OP_FUNCTION:{
int i;
total +=
"xmlXPathCompOpEval: parameter error\n");
return (total);
}
"xmlXPathCompOpEval: parameter error\n");
return (total);
}
else {
func =
else {
"xmlXPathCompOpEval: function %s bound to undefined prefix %s\n",
return (total);
}
}
"xmlXPathCompOpEval: function %s not found\n",
}
}
return (total);
}
case XPATH_OP_ARG:
}
return (total);
case XPATH_OP_PREDICATE:
case XPATH_OP_FILTER:{
int i;
/*
* Optimization for ()[1] selection i.e. the first elem
*/
#ifdef XP_OPTIMIZED_FILTER_FIRST
/*
* FILTER TODO: Can we assume that the inner processing
* will result in an ordered list if we have an
* XPATH_OP_FILTER?
* What about an additional field or flag on
* xmlXPathObject like @sorted ? This way we wouln'd need
* to assume anything, so it would be more robust and
* easier to optimize.
*/
#else
#endif
total +=
&first);
/*
* The nodeset should be in document order,
* Keep only the first value
*/
return (total);
}
}
/*
* Optimization for ()[last()] selection i.e. the last elem
*/
if ((f != -1) &&
total +=
&last);
/*
* The nodeset should be in document order,
* Keep only the last value
*/
value->
nodeNr -
1];
}
return (total);
}
}
/*
* Process inner predicates first.
* Example "index[parent::book][1]":
* ...
* PREDICATE <-- we are here "[1]"
* PREDICATE <-- process "[parent::book]" first
* SORT
* COLLECT 'parent' 'name' 'node' book
* NODE
* ELEM Object is a number : 1
*/
total +=
return (total);
return (total);
#ifdef LIBXML_XPTR_ENABLED
/*
* Hum are we filtering the result of an XPointer expression
*/
/*
* Extract the old locset, and then evaluate the result of the
* expression for all the element in the locset. use it to grow
* up a new locset.
*/
total +=
}
return (total);
}
/*
* Run the evaluation with a node list made of a
* single item in the nodelocset.
*/
total +=
return(0);
}
/*
* The result of the evaluation need to be tested to
* decided whether the filter succeeded or not
*/
}
/*
* Cleanup
*/
}
}
}
/*
* The result is used as the new evaluation locset.
*/
return (total);
}
#endif /* LIBXML_XPTR_ENABLED */
/*
* Extract the old set, and then evaluate the result of the
* expression for all the element in the set. use it to grow
* up a new set.
*/
/*
if (op->ch2 != -1)
total +=
xmlXPathCompOpEval(ctxt,
&comp->steps[op->ch2]);
CHECK_ERROR0;
res = valuePop(ctxt);
if (res != NULL)
xmlXPathFreeObject(res);
*/
} else {
/*
* Initialize the new set.
* Also set the xpath document in case things like
* key() evaluation are attempted on the predicate
*/
/*
* SPEC XPath 1.0:
* "For each node in the node-set to be filtered, the
* PredicateExpr is evaluated with that node as the
* context node, with the number of nodes in the
* node-set as the context size, and with the proximity
* position of the node in the node-set with respect to
* the axis as the context position;"
* @oldset is the node-set" to be filtered.
*
* SPEC XPath 1.0:
* "only predicates change the context position and
* context size (see [2.4 Predicates])."
* Example:
* node-set context pos
* nA 1
* nB 2
* nC 3
* After applying predicate [position() > 1] :
* node-set context pos
* nB 1
* nC 2
*
* removed the first node in the node-set, then
* the context position of the
*/
/*
* Run the evaluation with a node list made of
* a single item in the nodeset.
*/
} else {
}
/*
* Evaluate the predicate against the context node.
* here (e.g. "[1]")?
*/
total +=
return(0);
}
/*
* The result of the evaluation needs to be tested to
* decide whether the filter succeeded or not
*/
/*
* OPTIMIZE TODO: Can we use
* xmlXPathNodeSetAdd*Unique()* instead?
*/
}
/*
* Cleanup
*/
}
/*
* Don't free the temporary nodeset
* in order to avoid massive recreation inside this
* loop.
*/
} else
}
/*
* The result is used as the new evaluation set.
*/
/* may want to move this past the '}' later */
}
return (total);
}
case XPATH_OP_SORT:
{
}
return (total);
#ifdef LIBXML_XPTR_ENABLED
case XPATH_OP_RANGETO:{
int i, j;
total +=
return (total);
/*
* Extract the old locset, and then evaluate the result of the
* expression for all the element in the locset. use it to grow
* up a new locset.
*/
}
return (total);
}
/*
* Run the evaluation with a node list made of a
* single item in the nodelocset.
*/
total +=
return(0);
}
}
}
} else {
}
}
/*
* Cleanup
*/
}
}
}
} else { /* Not a location set */
/*
* Run the evaluation with a node list made of a single item
* in the nodeset.
*/
/*
* OPTIMIZE TODO: Avoid recreation for every iteration.
*/
total +=
return(0);
}
range =
res);
}
/*
* Cleanup
*/
}
}
}
}
}
/*
* The result is used as the new evaluation set.
*/
return (total);
}
#endif /* LIBXML_XPTR_ENABLED */
}
return (total);
}
/**
* xmlXPathCompOpEvalToBoolean:
* @ctxt: the XPath parser context
*
* Evaluates if the expression evaluates to true.
*
* Returns 1 if true, 0 if false and -1 on API or internal errors.
*/
static int
int isPredicate)
{
/* comp = ctxt->comp; */
case XPATH_OP_END:
return (0);
case XPATH_OP_VALUE:
if (isPredicate)
return(xmlXPathCastToBoolean(resObj));
case XPATH_OP_SORT:
/*
* We don't need sorting for boolean results. Skip this one.
*/
goto start;
}
return(0);
case XPATH_OP_COLLECT:
return(0);
return(-1);
return(-1);
return(-1);
break;
default:
/*
* Fallback to call xmlXPathCompOpEval().
*/
return(-1);
return(-1);
break;
}
if (resObj) {
int res;
} else if (isPredicate) {
/*
* For predicates a result of type "number" is handled
* differently:
* SPEC XPath 1.0:
* "If the result is a number, the result will be converted
* to true if the number is equal to the context position
* and will be converted to false otherwise;"
*/
} else {
}
return(res);
}
return(0);
}
#ifdef XPATH_STREAMING
/**
* xmlXPathRunStreamEval:
* @ctxt: the XPath parser context with the compiled expression
*
* Evaluate the Precompiled Streamable XPath expression in the given context.
*/
static int
{
int from_root;
int eval_all_nodes;
int nb_nodes = 0;
return(-1);
if (max_depth == -1)
return(-1);
if (max_depth == -2)
max_depth = 10000;
if (min_depth == -1)
return(-1);
if (from_root < 0)
return(-1);
#if 0
#endif
if (! toBool) {
return(-1);
return(-1);
}
/*
* handle the special cases of "/" amd "." being matched
*/
if (min_depth == 0) {
if (from_root) {
/* Select "/" */
if (toBool)
return(1);
} else {
/* Select "self::node()" */
if (toBool)
return(1);
}
}
if (max_depth == 0) {
return(0);
}
if (from_root) {
case XML_ELEMENT_NODE:
case XML_DOCUMENT_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
break;
case XML_ATTRIBUTE_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_NAMESPACE_DECL:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
break;
}
}
return(0);
}
/*
* QUESTION TODO: Is this an error?
*/
return(0);
}
if (from_root) {
if (ret < 0) {
} else if (ret == 1) {
if (toBool)
goto return_1;
}
}
depth = 0;
goto scan_children;
do {
nb_nodes++;
case XML_ELEMENT_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_COMMENT_NODE:
case XML_PI_NODE:
} else if (eval_all_nodes)
else
break;
if (ret < 0) {
/* NOP. */
} else if (ret == 1) {
if (toBool)
goto return_1;
}
goto next_node;
}
}
default:
break;
}
/*
* Do not descend on entities declarations
*/
depth++;
/*
* Skip DTDs
*/
continue;
}
}
break;
goto next_node;
}
do {
depth--;
goto done;
} else if ((eval_all_nodes) &&
{
}
break;
}
done:
#if 0
printf("stream eval: checked %d nodes selected %d\n",
#endif
if (patstream)
return(0);
if (patstream)
return(1);
}
#endif /* XPATH_STREAMING */
/**
* xmlXPathRunEval:
* @ctxt: the XPath parser context with the compiled expression
* @toBool: evaluate to a boolean result
*
* Evaluate the Precompiled XPath expression in the given context.
*/
static int
{
return(-1);
/* Allocate the value stack */
}
}
#ifdef XPATH_STREAMING
int res;
if (toBool) {
/*
* Evaluation to boolean result.
*/
if (res != -1)
return(res);
} else {
/*
* Evaluation to a sequence.
*/
return(0);
}
}
/*
* QUESTION TODO: This falls back to normal XPath evaluation
* if res == -1. Is this intended?
*/
}
#endif
"xmlXPathRunEval: last is less than zero\n");
return(-1);
}
if (toBool)
return(xmlXPathCompOpEvalToBoolean(ctxt,
else
return(0);
}
/************************************************************************
* *
* Public interfaces *
* *
************************************************************************/
/**
* xmlXPathEvalPredicate:
* @ctxt: the XPath context
* @res: the Predicate Expression evaluation result
*
* Evaluate a predicate result for the current node.
* A PredicateExpr is evaluated by evaluating the Expr and converting
* the result to a boolean. If the result is a number, the result will
* be converted to true if the number is equal to the position of the
* context node in the context node list (as returned by the position
* function) and will be converted to false otherwise; if the result
* is not a number, then the result will be converted as if by a call
* to the boolean function.
*
* Returns 1 if predicate is true, 0 otherwise
*/
int
case XPATH_BOOLEAN:
case XPATH_NUMBER:
case XPATH_NODESET:
case XPATH_XSLT_TREE:
return(0);
case XPATH_STRING:
default:
}
return(0);
}
/**
* xmlXPathEvaluatePredicateResult:
* @ctxt: the XPath Parser context
* @res: the Predicate Expression evaluation result
*
* Evaluate a predicate result for the current node.
* A PredicateExpr is evaluated by evaluating the Expr and converting
* the result to a boolean. If the result is a number, the result will
* be converted to true if the number is equal to the position of the
* context node in the context node list (as returned by the position
* function) and will be converted to false otherwise; if the result
* is not a number, then the result will be converted as if by a call
* to the boolean function.
*
* Returns 1 if predicate is true, 0 otherwise
*/
int
case XPATH_BOOLEAN:
case XPATH_NUMBER:
#else
#endif
case XPATH_NODESET:
case XPATH_XSLT_TREE:
return(0);
case XPATH_STRING:
#ifdef LIBXML_XPTR_ENABLED
case XPATH_LOCATIONSET:{
return(0);
}
#endif
default:
}
return(0);
}
#ifdef XPATH_STREAMING
/**
* xmlXPathTryStreamCompile:
* @ctxt: an XPath context
* @str: the XPath expression
*
* Try to compile the XPath expression as a streamable subset.
*
* Returns the compiled expression or NULL if failed to compile.
*/
static xmlXPathCompExprPtr
/*
* Optimization: use streaming patterns when the XPath expression can
* be compiled to a stream lookup
*/
int i, j;
/*
* We don't try to handle expressions using the verbose axis
* specifiers ("::"), just the simplied form at this point.
* Additionally, if there is no list of namespaces available and
* there's a ":" in the expression, indicating a prefixed QName,
* then we won't try to compile either. xmlPatterncompile() needs
* to have a list of namespaces at compilation time in order to
* compile prefixed name tests.
*/
return(NULL);
if (namespaces == NULL) {
return(NULL);
}
}
namespaces[i++] = NULL;
namespaces[i++] = NULL;
}
}
&namespaces[0]);
if (namespaces != NULL) {
}
comp = xmlXPathNewCompExpr();
return(NULL);
}
return(comp);
}
}
return(NULL);
}
#endif /* XPATH_STREAMING */
static int
{
return(0);
do {
return(1);
} while (*expr++);
return(0);
}
static void
{
/*
* Try to rewrite "descendant-or-self::node()/foo" to an optimized
* internal representation.
*/
{
/*
* This is a "child::foo"
*/
{
/*
* This is a "/descendant-or-self::node()" without predicates.
* Eliminate it.
*/
}
}
}
}
/**
* xmlXPathCtxtCompile:
* @ctxt: an XPath context
* @str: the XPath expression
*
* Compile an XPath expression
*
* Returns the xmlXPathCompExprPtr resulting from the compilation or NULL.
* the caller has to free the object.
*/
#ifdef XPATH_STREAMING
return(comp);
#endif
xmlXPathInit();
return NULL;
{
return(NULL);
}
/*
* aleksey: in some cases this line prints *second* error message
* (see bug #78858) and probably this should be fixed.
* However, we are not sure that all error messages are printed
* out in other places. It's not critical so we leave it as-is for now
*/
} else {
}
#ifdef DEBUG_EVAL_COUNTS
#endif
{
}
}
return(comp);
}
/**
* xmlXPathCompile:
* @str: the XPath expression
*
* Compile an XPath expression
*
* Returns the xmlXPathCompExprPtr resulting from the compilation or NULL.
* the caller has to free the object.
*/
}
/**
* xmlXPathCompiledEvalInternal:
* @comp: the compiled XPath expression
* @ctxt: the XPath context
* @resObj: the resulting XPath object or NULL
* @toBool: 1 if only a boolean result is requested
*
* Evaluate the Precompiled XPath expression in the given context.
* The caller has to free @resObj.
*
* Returns the xmlXPathObjectPtr resulting from the evaluation or NULL.
* the caller has to free the object.
*/
static int
int toBool)
{
#ifndef LIBXML_THREAD_ENABLED
static int reentance = 0;
#endif
int res;
return(-1);
xmlXPathInit();
#ifndef LIBXML_THREAD_ENABLED
reentance++;
if (reentance > 1)
#endif
#ifdef DEBUG_EVAL_COUNTS
}
#endif
if (resObj) {
"xmlXPathCompiledEval: evaluation failed\n");
} else {
}
}
/*
* Pop all remaining objects from the stack.
*/
int stack = 0;
do {
stack++;
}
if ((stack != 0) &&
{
"xmlXPathCompiledEval: %d objects left on the stack.\n",
stack);
}
}
}
#ifndef LIBXML_THREAD_ENABLED
reentance--;
#endif
return(res);
}
/**
* xmlXPathCompiledEval:
* @comp: the compiled XPath expression
* @ctx: the XPath context
*
* Evaluate the Precompiled XPath expression in the given context.
*
* Returns the xmlXPathObjectPtr resulting from the evaluation or NULL.
* the caller has to free the object.
*/
{
return(res);
}
/**
* xmlXPathCompiledEvalToBoolean:
* @comp: the compiled XPath expression
* @ctxt: the XPath context
*
* Applies the XPath boolean() function on the result of the given
* compiled expression.
*
* Returns 1 if the expression evaluated to true, 0 if to false and
* -1 in API and internal errors.
*/
int
{
}
/**
* xmlXPathEvalExpr:
* @ctxt: the XPath Parser context
*
* Parse and evaluate an XPath expression in the given context,
* then push the result on the context stack
*/
void
#ifdef XPATH_STREAMING
#endif
#ifdef XPATH_STREAMING
} else
#endif
{
/*
* In this scenario the expression string will sit in ctxt->base.
*/
{
}
}
xmlXPathRunEval(ctxt, 0);
}
/**
* xmlXPathEval:
* @str: the XPath expression
* @ctx: the XPath context
*
* Evaluate the XPath Location Path in the given context.
*
* Returns the xmlXPathObjectPtr resulting from the evaluation or NULL.
* the caller has to free the object.
*/
int stack = 0;
xmlXPathInit();
return NULL;
"xmlXPathEval: evaluation failed\n");
#ifdef XPATH_STREAMING
#endif
) {
} else {
}
do {
stack++;
}
"xmlXPathEval: %d object left on the stack\n",
stack);
}
}
return(res);
}
/**
* xmlXPathEvalExpression:
* @str: the XPath expression
* @ctxt: the XPath context
*
* Evaluate the XPath expression in the given context.
*
* Returns the xmlXPathObjectPtr resulting from the evaluation or NULL.
* the caller has to free the object.
*/
int stack = 0;
xmlXPathInit();
return NULL;
} else {
}
do {
stack++;
}
"xmlXPathEvalExpression: %d object left on the stack\n",
stack);
}
return(res);
}
/************************************************************************
* *
* Extra functions not pertaining to the XPath spec *
* *
************************************************************************/
/**
* xmlXPathEscapeUriFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the escape-uri() XPath function
* string escape-uri(string $str, bool $escape-reserved)
*
* This function applies the URI escaping rules defined in section 2 of [RFC
* 2396] to the string supplied as $uri-part, which typically represents all
* or part of a URI. The effect of the function is to replace any special
* character in the string by an escape sequence of the form %xx%yy...,
* where xxyy... is the hexadecimal representation of the octets used to
* represent the character in UTF-8.
*
* The set of characters that are escaped depends on the setting of the
* boolean argument $escape-reserved.
*
* If $escape-reserved is true, all characters are escaped other than lower
* case letters a-z, upper case letters A-Z, digits 0-9, and the characters
* referred to in [RFC 2396] as "marks": specifically, "-" | "_" | "." | "!"
* | "~" | "*" | "'" | "(" | ")". The "%" character itself is escaped only
* if it is not followed by two hexadecimal digits (that is, 0-9, a-f, and
* A-F).
*
* If $escape-reserved is false, the behavior differs in that characters
* referred to in [RFC 2396] as reserved characters are not escaped. These
* characters are ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | ",".
*
* [RFC 2396] does not define whether escaped URIs should use lower case or
* upper case for hexadecimal digits. To ensure that escaped URIs can be
* compared using string comparison functions, this function must always use
* the upper-case letters A-F.
*
* Generally, $escape-reserved should be set to true when escaping a string
* that is to form a single part of a URI, and to false when escaping an
* entire URI or URI reference.
*
* In the case of non-ascii characters, the string is encoded according to
* utf-8 and then converted according to RFC 2396.
*
* Examples
* xf:escape-uri ("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#ocean"), true())
* returns "gopher%3A%2F%2Fspinaltap.micro.umn.edu%2F00%2FWeather%2FCalifornia%2FLos%20Angeles%23ocean"
* xf:escape-uri ("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#ocean"), false())
* returns "gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles%23ocean"
*
*/
static void
int escape_reserved;
CHECK_ARITY(2);
target = xmlBufferCreate();
escape[0] = '%';
escape[3] = 0;
if (target) {
(*cptr == '%' &&
(!escape_reserved &&
*cptr == ','))) {
} else {
else
else
}
}
}
}
/**
* xmlXPathRegisterAllFunctions:
* @ctxt: the XPath context
*
* Registers all default XPath functions in this context
*/
void
{
(const xmlChar *)"http://www.w3.org/2002/08/xquery-functions",
}
#endif /* LIBXML_XPATH_ENABLED */
#define bottom_xpath
#include "elfgcchack.h"