xpointer.c revision 38ae7e4efe803ea78b6499cd05a394db32623e41
/*
* xpointer.c : Code to handle XML Pointer
*
* Base implementation was made accordingly to
* W3C Candidate Recommendation 7 June 2000
*
* Added support for the element() scheme described in:
* W3C Proposed Recommendation 13 November 2002
*
* See Copyright for the status of this software.
*
* daniel@veillard.com
*/
#define IN_LIBXML
#include "libxml.h"
/*
* TODO: better handling of error cases, the full expression should
* be parsed beforehand instead of a progressive evaluation
* TODO: Access into entities references are not supported now ...
* need a start to be able to pop out of entities refs since
* parent is the endity declaration, not the ref.
*/
#include <string.h>
#include <libxml/xpointer.h>
#include <libxml/xmlmemory.h>
#include <libxml/parserInternals.h>
#include <libxml/xpathInternals.h>
#include <libxml/xmlerror.h>
#ifdef LIBXML_XPTR_ENABLED
/* Add support of the xmlns() xpointer scheme to initialize the namespaces */
#define XPTR_XMLNS_SCHEME
/* #define DEBUG_RANGES */
#ifdef DEBUG_RANGES
#ifdef LIBXML_DEBUG_ENABLED
#include <libxml/debugXML.h>
#endif
#endif
#define TODO \
"Unimplemented block at %s:%d\n", \
#define STRANGE \
"Internal error at %s:%d\n", \
/************************************************************************
* *
* Some factorized error routines *
* *
************************************************************************/
/**
* xmlXPtrErrMemory:
* @extra: extra informations
*
* Handle a redefinition of attribute error
*/
static void
xmlXPtrErrMemory(const char *extra)
{
"Memory allocation failed : %s\n", extra);
}
/**
* xmlXPtrErr:
* @ctxt: an XPTR evaluation context
* @extra: extra informations
*
* Handle a redefinition of attribute error
*/
static void
{
XML_ERR_ERROR, NULL, 0,
return;
}
} else {
}
}
/************************************************************************
* *
* A few helper functions for child sequences *
* *
************************************************************************/
/* xmlXPtrAdvanceNode is a private function, but used by xinclude.c */
/**
* xmlXPtrGetArity:
* @cur: the node
*
* Returns the number of child for an element, -1 in case of error
*/
static int
int i;
return(-1);
i++;
}
}
return(i);
}
/**
* xmlXPtrGetIndex:
* @cur: the node
*
* Returns the index of the node in its parent children list, -1
* in case of error
*/
static int
int i;
return(-1);
i++;
}
}
return(i);
}
/**
* xmlXPtrGetNthChild:
* @cur: the node
* @no: the child number
*
* Returns the @no'th element child of @cur or NULL
*/
static xmlNodePtr
int i;
return(cur);
return(cur);
i++;
if (i == no)
break;
}
}
return(cur);
}
/************************************************************************
* *
* Handling of XPointer specific types *
* *
************************************************************************/
/**
* xmlXPtrCmpPoints:
* @node1: the first node
* @index1: the first index
* @node2: the second node
* @index2: the second index
*
* Compare two points w.r.t document order
*
* Returns -2 in case of error 1 if first point < second point, 0 if
* that's the same point, -1 otherwise
*/
static int
return(-2);
/*
* a couple of optimizations which will avoid computations in most cases
*/
return(1);
return(-1);
return(0);
}
}
/**
* xmlXPtrNewPoint:
* @node: the xmlNodePtr
* @indx: the indx within the node
*
* Create a new xmlXPathObjectPtr of type point
*
* Returns the newly created object.
*/
static xmlXPathObjectPtr
return(NULL);
if (indx < 0)
return(NULL);
xmlXPtrErrMemory("allocating point");
return(NULL);
}
return(ret);
}
/**
* xmlXPtrRangeCheckOrder:
* @range: an object range
*
* Make sure the points in the range are in the right order
*/
static void
int tmp;
return;
return;
return;
if (tmp == -1) {
}
}
/**
* xmlXPtrRangesEqual:
* @range1: the first range
* @range2: the second range
*
* Compare two ranges
*
* Returns 1 if equal, 0 otherwise
*/
static int
return(1);
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
return(0);
return(1);
}
/**
* xmlXPtrNewRange:
* @start: the starting node
* @startindex: the start index
* @end: the ending point
* @endindex: the ending index
*
* Create a new xmlXPathObjectPtr of type range
*
* Returns the newly created object.
*/
return(NULL);
return(NULL);
if (startindex < 0)
return(NULL);
if (endindex < 0)
return(NULL);
xmlXPtrErrMemory("allocating range");
return(NULL);
}
return(ret);
}
/**
* xmlXPtrNewRangePoints:
* @start: the starting point
* @end: the ending point
*
* Create a new xmlXPathObjectPtr of type range using 2 Points
*
* Returns the newly created object.
*/
return(NULL);
return(NULL);
return(NULL);
return(NULL);
xmlXPtrErrMemory("allocating range");
return(NULL);
}
return(ret);
}
/**
* xmlXPtrNewRangePointNode:
* @start: the starting point
* @end: the ending node
*
* Create a new xmlXPathObjectPtr of type range from a point to a node
*
* Returns the newly created object.
*/
return(NULL);
return(NULL);
return(NULL);
xmlXPtrErrMemory("allocating range");
return(NULL);
}
return(ret);
}
/**
* xmlXPtrNewRangeNodePoint:
* @start: the starting node
* @end: the ending point
*
* Create a new xmlXPathObjectPtr of type range from a node to a point
*
* Returns the newly created object.
*/
return(NULL);
return(NULL);
return(NULL);
return(NULL);
xmlXPtrErrMemory("allocating range");
return(NULL);
}
return(ret);
}
/**
* xmlXPtrNewRangeNodes:
* @start: the starting node
* @end: the ending node
*
* Create a new xmlXPathObjectPtr of type range using 2 nodes
*
* Returns the newly created object.
*/
return(NULL);
return(NULL);
xmlXPtrErrMemory("allocating range");
return(NULL);
}
return(ret);
}
/**
* xmlXPtrNewCollapsedRange:
* @start: the starting and ending node
*
* Create a new xmlXPathObjectPtr of type range using a single nodes
*
* Returns the newly created object.
*/
return(NULL);
xmlXPtrErrMemory("allocating range");
return(NULL);
}
return(ret);
}
/**
* xmlXPtrNewRangeNodeObject:
* @start: the starting node
* @end: the ending object
*
* Create a new xmlXPathObjectPtr of type range from a not to an object
*
* Returns the newly created object.
*/
return(NULL);
return(NULL);
case XPATH_POINT:
case XPATH_RANGE:
break;
case XPATH_NODESET:
/*
* Empty set ...
*/
return(NULL);
break;
default:
/* TODO */
return(NULL);
}
xmlXPtrErrMemory("allocating range");
return(NULL);
}
case XPATH_POINT:
break;
case XPATH_RANGE:
break;
case XPATH_NODESET: {
break;
}
default:
return(NULL);
}
return(ret);
}
#define XML_RANGESET_DEFAULT 10
/**
* xmlXPtrLocationSetCreate:
* @val: an initial xmlXPathObjectPtr, or NULL
*
* Create a new xmlLocationSetPtr of type double and of value @val
*
* Returns the newly created object.
*/
xmlXPtrErrMemory("allocating locationset");
return(NULL);
}
sizeof(xmlXPathObjectPtr));
xmlXPtrErrMemory("allocating locationset");
return(NULL);
}
}
return(ret);
}
/**
* xmlXPtrLocationSetAdd:
* @cur: the initial range set
* @val: a new xmlXPathObjectPtr
*
* add a new xmlXPathObjectPtr to an existing LocationSet
* If the location already exist in the set @val is freed.
*/
void
int i;
/*
* check against doublons
*/
return;
}
}
/*
* grow the locTab if needed
*/
sizeof(xmlXPathObjectPtr));
xmlXPtrErrMemory("adding location to set");
return;
}
sizeof(xmlXPathObjectPtr));
xmlXPtrErrMemory("adding location to set");
return;
}
}
}
/**
* xmlXPtrLocationSetMerge:
* @val1: the first LocationSet
* @val2: the second LocationSet
*
* Merges two rangesets, all ranges from @val2 are added to @val1
*
* Returns val1 once extended or NULL in case of error.
*/
int i;
/*
* !!!!! this can be optimized a lot, knowing that both
* val1 and val2 already have unicity of their values.
*/
return(val1);
}
/**
* xmlXPtrLocationSetDel:
* @cur: the initial range set
* @val: an xmlXPathObjectPtr
*
* Removes an xmlXPathObjectPtr from an existing LocationSet
*/
void
int i;
/*
* check against doublons
*/
#ifdef DEBUG
"xmlXPtrLocationSetDel: Range wasn't found in RangeList\n");
#endif
return;
}
}
/**
* xmlXPtrLocationSetRemove:
* @cur: the initial range set
* @val: the index to remove
*
* Removes an entry from an existing LocationSet list.
*/
void
}
/**
* xmlXPtrFreeLocationSet:
* @obj: the xmlLocationSetPtr to free
*
* Free the LocationSet compound (not the actual ranges !).
*/
void
int i;
}
}
}
/**
* xmlXPtrNewLocationSetNodes:
* @start: the start NodePtr value
* @end: the end NodePtr value or NULL
*
* Create a new xmlXPathObjectPtr of type LocationSet and initialize
* it with the single range made of the two nodes @start and @end
*
* Returns the newly created object.
*/
xmlXPtrErrMemory("allocating locationset");
return(NULL);
}
else
return(ret);
}
/**
* xmlXPtrNewLocationSetNodeSet:
* @set: a node set
*
* Create a new xmlXPathObjectPtr of type LocationSet and initialize
* it with all the nodes from @set
*
* Returns the newly created object.
*/
xmlXPtrErrMemory("allocating locationset");
return(NULL);
}
int i;
return(ret);
}
return(ret);
}
/**
* xmlXPtrWrapLocationSet:
* @val: the LocationSet value
*
* Wrap the LocationSet @val in a new xmlXPathObjectPtr
*
* Returns the newly created object.
*/
xmlXPtrErrMemory("allocating locationset");
return(NULL);
}
return(ret);
}
/************************************************************************
* *
* The parser *
* *
************************************************************************/
/*
* 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 SKIP_BLANKS \
/*
* xmlXPtrGetChildNo:
* @ctxt: the XPointer Parser context
* @index: the child number
*
* Move the current node of the nodeset on the stack to the
* given child if found
*/
static void
return;
}
return;
}
}
/**
* xmlXPtrEvalXPtrPart:
* @ctxt: the XPointer Parser context
* @name: the preparsed Scheme for the XPtrPart
*
* XPtrPart ::= 'xpointer' '(' XPtrExpr ')'
* | Scheme '(' SchemeSpecificExpr ')'
*
* Scheme ::= NCName - 'xpointer' [VC: Non-XPointer schemes]
*
* SchemeSpecificExpr ::= StringWithBalancedParens
*
* StringWithBalancedParens ::=
* [^()]* ('(' StringWithBalancedParens ')' [^()]*)*
* [VC: Parenthesis escaping]
*
* XPtrExpr ::= Expr [VC: Parenthesis escaping]
*
* VC: Parenthesis escaping:
* The end of an XPointer part is signaled by the right parenthesis ")"
* character that is balanced with the left parenthesis "(" character
* that began the part. Any unbalanced parenthesis character inside the
* expression, even within literals, must be escaped with a circumflex (^)
* character preceding it. If the expression contains any literal
* occurrences of the circumflex, each must be escaped with an additional
* circumflex (that is, ^^). If the unescaped parentheses in the expression
* are not balanced, a syntax error results.
*
* Parse and evaluate an XPtrPart. Basically it generates the unescaped
* string and if the scheme is 'xpointer' it will call the XPath interpreter.
*
* TODO: there is no new scheme registration mechanism
*/
static void
int len;
int level;
if (CUR != '(')
NEXT;
level = 1;
len++;
xmlXPtrErrMemory("allocating buffer");
return;
}
while (CUR != 0) {
if (CUR == ')') {
level--;
if (level == 0) {
NEXT;
break;
}
} else if (CUR == '(') {
level++;
} else if (CUR == '^') {
NEXT;
} else {
*cur++ = '^';
}
} else {
}
NEXT;
}
*cur = 0;
}
/*
* To evaluate an xpointer scheme element (4.3) we need:
* context initialized to the root
* context position initalized to 1
* context size initialized to 1
*/
if (buffer[0] == '/') {
} else {
}
}
#ifdef XPTR_XMLNS_SCHEME
}
if (CUR != '=') {
}
NEXT;
/* @@ check escaping in the XPointer WD */
}
}
#endif /* XPTR_XMLNS_SCHEME */
} else {
"unsupported scheme '%s'\n", name);
}
}
/**
* xmlXPtrEvalFullXPtr:
* @ctxt: the XPointer Parser context
* @name: the preparsed Scheme for the first XPtrPart
*
* FullXPtr ::= XPtrPart (S? XPtrPart)*
*
* As the specs says:
* -----------
* When multiple XPtrParts are provided, they must be evaluated in
* left-to-right order. If evaluation of one part fails, the nexti
* is evaluated. The following conditions cause XPointer part failure:
*
* - An unknown scheme
* - A scheme that does not locate any sub-resource present in the resource
* - A scheme that is not applicable to the media type of the resource
*
* The XPointer application must consume a failed XPointer part and
* attempt to evaluate the next one, if any. The result of the first
* XPointer part whose evaluation succeeds is taken to be the fragment
* located by the XPointer as a whole. If all the parts fail, the result
* for the XPointer as a whole is a sub-resource error.
* -----------
*
* Parse and evaluate a Full XPtr i.e. possibly a cascade of XPath based
* expressions or other schemes.
*/
static void
/* in case of syntax error, break here */
return;
/*
* If the returned value is a non-empty nodeset
* or location set, return here.
*/
case XPATH_LOCATIONSET: {
return;
break;
}
case XPATH_NODESET: {
return;
break;
}
default:
break;
}
/*
* Evaluating to improper values is equivalent to
* a sub-resource error, clean-up the stack
*/
do {
}
}
/*
* Is there another XPointer part.
*/
}
}
/**
* xmlXPtrEvalChildSeq:
* @ctxt: the XPointer Parser context
* @name: a possible ID name of the child sequence
*
* ChildSeq ::= '/1' ('/' [0-9]*)*
* | Name ('/' [0-9]*)+
*
* Parse and evaluate a Child Sequence. This routine also handle the
* case of a Bare Name used to get a document ID.
*/
static void
/*
* XPointer don't allow by syntax to address in mutirooted trees
* this might prove useful in some cases, warn about it.
*/
"warning: ChildSeq not starting by /1\n", NULL);
}
}
while (CUR == '/') {
int child = 0;
NEXT;
NEXT;
}
}
}
/**
* xmlXPtrEvalXPointer:
* @ctxt: the XPointer Parser context
*
* XPointer ::= Name
* | ChildSeq
* | FullXPtr
*
* Parse and evaluate an XPointer
*/
static void
/* Allocate the value stack */
xmlXPtrErrMemory("allocating evaluation context");
return;
}
}
if (CUR == '/') {
} else {
if (CUR == '(') {
/* Short evaluation */
return;
} else {
/* this handle both Bare Names and Child Sequences */
}
}
if (CUR != 0)
}
/************************************************************************
* *
* General routines *
* *
************************************************************************/
/**
* xmlXPtrNewContext:
* @doc: the XML document
* @here: the node that directly contains the XPointer being evaluated or NULL
* @origin: the element from which a user or program initiated traversal of
* the link, or NULL.
*
* Create a new XPointer context
*
* Returns the xmlXPathContext just allocated.
*/
return(ret);
return(ret);
}
/**
* xmlXPtrEval:
* @str: the XPointer expression
* @ctx: the XPointer 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);
"xmlXPtrEval: evaluation failed to return a node set\n",
NULL);
} else {
}
do {
/*
* Evaluation may push a root nodeset which is unused
*/
stack++;
} else
stack++;
}
}
if (stack != 0) {
"xmlXPtrEval: object(s) left on the eval stack\n",
NULL);
}
}
return(res);
}
/**
* xmlXPtrBuildRangeNodeList:
* @range: a range object
*
* Build a node list tree copy of the range
*
* Returns an xmlNodePtr list or NULL.
* the caller has to free the node tree.
*/
static xmlNodePtr
/* pointers to generated nodes */
/* pointers to traversal nodes */
return(NULL);
return(NULL);
return(NULL);
int len;
} else {
index1 = 0;
} else {
}
}
/* single sub text node selection */
return(tmp);
/* prune and return full set */
else
return(list);
} else {
else {
else
}
if (index2 > 1) {
index2 = 0;
}
index1 = 0;
} else {
}
/*
* Now gather the remaining nodes from cur to end
*/
continue; /* while */
}
} else {
if (index1 > 1) {
}
}
} else {
index1 = 0;
/*
* Now gather the remaining nodes from cur to end
*/
continue; /* while */
}
}
} else {
case XML_DTD_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_NODE:
/* Do not copy DTD informations */
break;
case XML_ENTITY_DECL:
TODO /* handle crossing entities -> stack needed */
break;
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
/* don't consider it part of the tree content */
break;
case XML_ATTRIBUTE_NODE:
/* Humm, should not happen ! */
break;
default:
break;
}
return(NULL);
}
else {
}
}
}
/*
* Skip to next node in document order
*/
return(NULL);
}
}
return(list);
}
/**
* xmlXPtrBuildNodeList:
* @obj: the XPointer result from the evaluation.
*
* Build a node list tree copy of the XPointer result.
* This will drop Attributes and Namespace declarations.
*
* Returns an xmlNodePtr list or NULL.
* the caller has to free the node tree.
*/
int i;
return(NULL);
case XPATH_NODESET: {
return(NULL);
continue;
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ELEMENT_NODE:
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
break;
case XML_ATTRIBUTE_NODE:
case XML_NAMESPACE_DECL:
case XML_DOCUMENT_TYPE_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_NOTATION_NODE:
case XML_DTD_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
continue; /* for */
}
else {
}
}
break;
}
case XPATH_LOCATIONSET: {
return(NULL);
else
}
}
break;
}
case XPATH_RANGE:
return(xmlXPtrBuildRangeNodeList(obj));
case XPATH_POINT:
default:
break;
}
return(list);
}
/************************************************************************
* *
* XPointer functions *
* *
************************************************************************/
/**
* xmlXPtrNbLocChildren:
* @node: an xmlNodePtr
*
* Count the number of location children of @node or the length of the
*
* Returns the number of location children
*/
static int
int ret = 0;
return(-1);
case XML_HTML_DOCUMENT_NODE:
case XML_DOCUMENT_NODE:
case XML_ELEMENT_NODE:
ret++;
}
break;
case XML_ATTRIBUTE_NODE:
return(-1);
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
break;
default:
return(-1);
}
return(ret);
}
/**
* xmlXPtrHereFunction:
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
* Function implementing here() operation
* as described in 5.4.3
*/
void
CHECK_ARITY(0);
}
/**
* xmlXPtrOriginFunction:
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
* Function implementing origin() operation
* as described in 5.4.3
*/
void
CHECK_ARITY(0);
}
/**
* xmlXPtrStartPointFunction:
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
* Function implementing start-point() operation
* as described in 5.4.3
* ----------------
* location-set start-point(location-set)
*
* For each location x in the argument location-set, start-point adds a
* location of type point to the result location-set. That point represents
* the start point of location x and is determined by the following rules:
*
* - If x is of type point, the start point is x.
* - If x is of type range, the start point is the start point of x.
* - If x is of type root, element, text, comment, or processing instruction,
* - the container node of the start point is x and the index is 0.
* - If x is of type attribute or namespace, the function must signal a
* syntax error.
* ----------------
*
*/
void
CHECK_ARITY(1);
/*
* First convert to a location set
*/
}
}
int i;
continue;
case XPATH_POINT:
break;
case XPATH_RANGE: {
/* TODO: Namespace Nodes ??? */
}
}
break;
}
default:
/*** Should we raise an error ?
xmlXPathFreeObject(obj);
xmlXPathFreeObject(newset);
XP_ERROR(XPATH_INVALID_TYPE)
***/
break;
}
}
}
}
/**
* xmlXPtrEndPointFunction:
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
* Function implementing end-point() operation
* as described in 5.4.3
* ----------------------------
* location-set end-point(location-set)
*
* For each location x in the argument location-set, end-point adds a
* location of type point to the result location-set. That point represents
* the end point of location x and is determined by the following rules:
*
* - If x is of type point, the resulting point is x.
* - If x is of type range, the resulting point is the end point of x.
* - If x is of type root or element, the container node of the resulting
* point is x and the index is the number of location children of x.
* - If x is of type text, comment, or processing instruction, the container
* node of the resulting point is x and the index is the length of the
* string-value of x.
* - If x is of type attribute or namespace, the function must signal a
* syntax error.
* ----------------------------
*/
void
CHECK_ARITY(1);
/*
* First convert to a location set
*/
}
int i;
continue;
case XPATH_POINT:
break;
case XPATH_RANGE: {
/* TODO: Namespace Nodes ??? */
}
}
break;
}
default:
/*** Should we raise an error ?
xmlXPathFreeObject(obj);
xmlXPathFreeObject(newset);
XP_ERROR(XPATH_INVALID_TYPE)
***/
break;
}
}
}
}
/**
* xmlXPtrCoveringRange:
* @ctxt: the XPointer Parser context
* @loc: the location for which the covering range must be computed
*
* A covering range is a range that wholly encompasses a location
* Section 5.3.3. Covering Ranges for All Location Types
* http://www.w3.org/TR/xptr#N2267
*
* Returns a new location or NULL in case of error
*/
static xmlXPathObjectPtr
return(NULL);
return(NULL);
case XPATH_POINT:
case XPATH_RANGE:
} else {
xmlXPtrGetArity(node)));
} else {
case XML_ATTRIBUTE_NODE:
/* !!! our model is slightly different than XPath */
xmlXPtrGetArity(node)));
case XML_ELEMENT_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_DOCUMENT_NODE:
case XML_NOTATION_NODE:
case XML_HTML_DOCUMENT_NODE: {
}
default:
return(NULL);
}
}
}
default:
TODO /* missed one case ??? */
}
return(NULL);
}
/**
* xmlXPtrRangeFunction:
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
* Function implementing the range() function 5.4.3
* location-set range(location-set )
*
* The range function returns ranges covering the locations in
* the argument location-set. For each location x in the argument
* location-set, a range location representing the covering range of
* x is added to the result location-set.
*/
void
int i;
CHECK_ARITY(1);
/*
* First convert to a location set
*/
}
/*
* The loop is to compute the covering range for each item and add it
*/
}
/*
* Save the new value and cleanup
*/
}
/**
* xmlXPtrInsideRange:
* @ctxt: the XPointer Parser context
* @loc: the location for which the inside range must be computed
*
* A inside range is a range described in the range-inside() description
*
* Returns a new location or NULL in case of error
*/
static xmlXPathObjectPtr
return(NULL);
return(NULL);
case XPATH_POINT: {
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE: {
} else {
}
}
case XML_ATTRIBUTE_NODE:
case XML_ELEMENT_NODE:
case XML_ENTITY_REF_NODE:
case XML_DOCUMENT_NODE:
case XML_NOTATION_NODE:
case XML_HTML_DOCUMENT_NODE: {
xmlXPtrGetArity(node)));
}
default:
break;
}
return(NULL);
}
case XPATH_RANGE: {
} else {
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE: {
} else {
}
}
case XML_ATTRIBUTE_NODE:
case XML_ELEMENT_NODE:
case XML_ENTITY_REF_NODE:
case XML_DOCUMENT_NODE:
case XML_NOTATION_NODE:
case XML_HTML_DOCUMENT_NODE: {
xmlXPtrGetArity(node)));
}
default:
break;
}
return(NULL);
}
}
default:
TODO /* missed one case ??? */
}
return(NULL);
}
/**
* xmlXPtrRangeInsideFunction:
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
* Function implementing the range-inside() function 5.4.3
* location-set range-inside(location-set )
*
* The range-inside function returns ranges covering the contents of
* the locations in the argument location-set. For each location x in
* the argument location-set, a range location is added to the result
* location-set. If x is a range location, then x is added to the
* result location-set. If x is not a range location, then x is used
* as the container location of the start and end points of the range
* location to be added; the index of the start point of the range is
* zero; if the end point is a character point then its index is the
* length of the string-value of x, and otherwise is the number of
* location children of x.
*
*/
void
int i;
CHECK_ARITY(1);
/*
* First convert to a location set
*/
}
/*
* The loop is to compute the covering range for each item and add it
*/
}
/*
* Save the new value and cleanup
*/
}
/**
* xmlXPtrRangeToFunction:
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
* Implement the range-to() XPointer function
*/
void
int i;
CHECK_ARITY(1);
/*
* Save the expression pointer since we will have to evaluate
* it multiple times. Initialize the new set.
*/
/*
* Run the evaluation with a node list made of a single item
* in the nodeset.
*/
/*
* 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 set.
*/
}
/**
* xmlXPtrAdvanceNode:
* @cur: the node
* @level: incremented/decremented to show level in tree
*
* Advance to the next element or text node in document order
*
* Returns -1 in case of failure, 0 otherwise
*/
next:
return(NULL);
(*level)++;
goto found;
}
skip: /* This label should only be needed if something is wrong! */
goto found;
}
do {
(*level)--;
goto found;
}
goto skip;
}
goto next;
}
return(cur);
}
/**
* xmlXPtrAdvanceChar:
* @node: the node
* @indx: the indx
* @bytes: the number of bytes
*
* Advance a point of the associated number of bytes (not UTF8 chars)
*
* Returns -1 in case of failure, 0 otherwise
*/
static int
int pos;
int len;
return(-1);
return(-1);
while (bytes >= 0) {
/*
* First position to the beginning of the first text node
* corresponding to this point
*/
if (pos > 0) {
pos = 0;
} else {
pos = 0;
}
}
*indx = 0;
return(-1);
}
/*
* if there is no move needed return the current value.
*/
if (bytes == 0) {
return(0);
}
/*
* We should have a text (or cdata) node ...
*/
len = 0;
}
/* Strange, the indx in the text node is greater than it's len */
}
pos = 0;
return(0);
}
}
return(-1);
}
/**
* xmlXPtrMatchString:
* @string: the string to search
* @start: the start textnode
* @startindex: the start index
*
* Check whether the document contains @string at the position
* (@start, @startindex) and limited by the (@end, @endindex) point
*
* Returns -1 in case of failure, 0 if not found, 1 if found in which case
* (@start, @startindex) will indicate the position of the beginning
* of the range and (@end, @endindex) will indicate the end
* of the range
*/
static int
int pos; /* 0 based */
int len; /* in bytes */
int stringlen; /* in bytes */
int match;
return(-1);
return(-1);
return(-1);
return(-1);
while (stringlen > 0) {
return(0);
if (match) {
#ifdef DEBUG_RANGES
"found range %d bytes at index %d of ->",
#endif
return(1);
} else {
return(0);
}
} else {
if (match) {
#ifdef DEBUG_RANGES
"found subrange %d bytes at index %d of ->",
#endif
} else {
return(0);
}
}
}
return(0);
pos = 0;
}
return(1);
}
/**
* xmlXPtrSearchString:
* @string: the string to search
* @end: the end textnode
* @endindex: the end index
*
* Search the next occurrence of @string within the document content
* until the (@end, @endindex) point is reached
*
* Returns -1 in case of failure, 0 if not found, 1 if found in which case
* (@start, @startindex) will indicate the position of the beginning
* of the range and (@end, @endindex) will indicate the end
* of the range
*/
static int
int pos; /* 0 based */
int len; /* in bytes */
return(-1);
return(-1);
return(-1);
return(-1);
if (first != 0) {
#ifdef DEBUG_RANGES
"found '%c' at index %d of ->",
#endif
return(1);
}
pos++;
} else {
}
} else {
/*
* An empty string is considered to match before each
* character of the string-value and after the final
* character.
*/
#ifdef DEBUG_RANGES
"found '' at index %d of ->",
pos + 1);
#endif
return(1);
}
}
}
return(0);
return(0);
pos = 1;
}
return(0);
}
/**
* xmlXPtrGetLastChar:
* @node: the node
* @index: the index
*
* Computes the point coordinates of the last char of this point
*
* Returns -1 in case of failure, 0 otherwise
*/
static int
return(-1);
return(-1);
if (pos > 0) {
pos = 0;
}
}
break;
} else {
return(-1);
}
}
return(-1);
return(0);
}
/**
* xmlXPtrGetStartPoint:
* @obj: an range
* @node: the resulting node
* @indx: the resulting index
*
* read the object and return the start point coordinates.
*
* Returns -1 in case of failure, 0 otherwise
*/
static int
return(-1);
case XPATH_POINT:
*indx = 0;
else
return(0);
case XPATH_RANGE:
*indx = 0;
else
return(0);
default:
break;
}
return(-1);
}
/**
* xmlXPtrGetEndPoint:
* @obj: an range
* @node: the resulting node
* @indx: the resulting indx
*
* read the object and return the end point coordinates.
*
* Returns -1 in case of failure, 0 otherwise
*/
static int
return(-1);
case XPATH_POINT:
*indx = 0;
else
return(0);
case XPATH_RANGE:
*indx = 0;
else
return(0);
default:
break;
}
return(-1);
}
/**
* xmlXPtrStringRangeFunction:
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
* Function implementing the string-range() function
* range as described in 5.4.2
*
* ------------------------------
* [Definition: For each location in the location-set argument,
* string-range returns a set of string ranges, a set of substrings in a
* string. Specifically, the string-value of the location is searched for
* substrings that match the string argument, and the resulting location-set
* will contain a range location for each non-overlapping match.]
* An empty string is considered to match before each character of the
* string-value and after the final character. Whitespace in a string
* is matched literally, with no normalization except that provided by
* XML for line ends. The third argument gives the position of the first
* character to be in the resulting range, relative to the start of the
* match. The default value is 1, which makes the range start immediately
* before the first character of the matched string. The fourth argument
* gives the number of characters in the range; the default is that the
* range extends to the end of the matched string.
*
* Element boundaries, as well as entire embedded nodes such as processing
* instructions and comments, are ignored as defined in [XPath].
*
* If the string in the second argument is not found in the string-value
* of the location, or if a value in the third or fourth argument indicates
* a string that is beyond the beginning or end of the document, the
* expression fails.
*
* The points of the range-locations in the returned location-set will
* all be character points.
* ------------------------------
*/
void
/*
* Grab the arguments
*/
if (nargs >= 4) {
}
if (nargs >= 3) {
}
goto error;
}
/*
* First convert to a location set
*/
}
/*
* The loop is to search for each element in the location set
* the list of location set corresponding to that search
*/
#ifdef DEBUG_RANGES
#endif
#ifdef DEBUG_RANGES
"from index %d of ->", startindex);
"to index %d of ->", endindex);
#endif
do {
if (found == 1) {
pos - 1) == 0) {
int rindx;
num) == 0) {
}
start, startindex));
} else {
}
}
startindex++;
}
} while (found == 1);
}
/*
* Save the new value and cleanup
*/
}
/**
* xmlXPtrEvalRangePredicate:
* @ctxt: the XPointer Parser context
*
* [8] Predicate ::= '[' PredicateExpr ']'
* [9] PredicateExpr ::= Expr
*
* Evaluate a predicate as in xmlXPathEvalPredicate() but for
* a Location Set instead of a node set
*/
void
int i;
if (CUR != '[') {
}
NEXT;
/*
* 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.
*/
} else {
/*
* Save the expression pointer since we will have to evaluate
* it multiple times. Initialize the new set.
*/
/*
* Run the evaluation with a node list made of a single item
* in the nodeset.
*/
/*
* 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 set.
*/
}
if (CUR != ']') {
}
NEXT;
}
#define bottom_xpointer
#include "elfgcchack.h"
#endif