19#pragma convert("ISO8859-1")
42#ifdef LIBXML_XPTR_ENABLED
45#define XPTR_XMLNS_SCHEME
50 xmlGenericError(xmlGenericErrorContext, \
51 "Unimplemented block at %s:%d\n", \
55 xmlGenericError(xmlGenericErrorContext, \
56 "Internal error at %s:%d\n", \
72xmlXPtrErrMemory(
const char *
extra)
77 "Memory allocation failed : %s\n",
extra);
88xmlXPtrErr(xmlXPathParserContextPtr ctxt,
int error,
93 if ((ctxt ==
NULL) || (ctxt->context ==
NULL)) {
106 ctxt->context->lastError.code =
error;
108 ctxt->context->lastError.str1 = (
char *)
xmlStrdup(ctxt->base);
109 ctxt->context->lastError.int1 = ctxt->cur - ctxt->base;
110 ctxt->context->lastError.node = ctxt->context->debugNode;
111 if (ctxt->context->error !=
NULL) {
112 ctxt->context->error(ctxt->context->userData,
113 &ctxt->context->lastError);
118 (
const char *)
extra, (
const char *) ctxt->base,
NULL,
119 ctxt->cur - ctxt->base, 0,
129#ifdef LIBXML_XPTR_LOCS_ENABLED
131xmlNodePtr xmlXPtrAdvanceNode(xmlNodePtr
cur,
int *
level);
139xmlXPtrGetArity(xmlNodePtr
cur) {
141 if ((
cur ==
NULL) || (
cur->type == XML_NAMESPACE_DECL))
145 if ((
cur->type == XML_ELEMENT_NODE) ||
146 (
cur->type == XML_DOCUMENT_NODE) ||
147 (
cur->type == XML_HTML_DOCUMENT_NODE)) {
162xmlXPtrGetIndex(xmlNodePtr
cur) {
164 if ((
cur ==
NULL) || (
cur->type == XML_NAMESPACE_DECL))
167 if ((
cur->type == XML_ELEMENT_NODE) ||
168 (
cur->type == XML_DOCUMENT_NODE) ||
169 (
cur->type == XML_HTML_DOCUMENT_NODE)) {
185xmlXPtrGetNthChild(xmlNodePtr
cur,
int no) {
187 if ((
cur ==
NULL) || (
cur->type == XML_NAMESPACE_DECL))
193 if ((
cur->type == XML_ELEMENT_NODE) ||
194 (
cur->type == XML_DOCUMENT_NODE) ||
195 (
cur->type == XML_HTML_DOCUMENT_NODE)) {
204#ifdef LIBXML_XPTR_LOCS_ENABLED
224xmlXPtrCmpPoints(xmlNodePtr node1,
int index1, xmlNodePtr node2,
int index2) {
225 if ((node1 ==
NULL) || (node2 ==
NULL))
230 if (node1 == node2) {
237 return(xmlXPathCmpNodes(node1, node2));
249static xmlXPathObjectPtr
250xmlXPtrNewPoint(xmlNodePtr
node,
int indx) {
251 xmlXPathObjectPtr
ret;
258 ret = (xmlXPathObjectPtr)
xmlMalloc(
sizeof(xmlXPathObject));
260 xmlXPtrErrMemory(
"allocating point");
264 ret->type = XPATH_POINT;
277xmlXPtrRangeCheckOrder(xmlXPathObjectPtr
range) {
282 if (
range->type != XPATH_RANGE)
286 tmp = xmlXPtrCmpPoints(
range->user,
range->index,
308xmlXPtrRangesEqual(xmlXPathObjectPtr range1, xmlXPathObjectPtr range2) {
309 if (range1 == range2)
311 if ((range1 ==
NULL) || (range2 ==
NULL))
313 if (range1->type != range2->type)
315 if (range1->type != XPATH_RANGE)
317 if (range1->user != range2->user)
319 if (range1->index != range2->index)
321 if (range1->user2 != range2->user2)
323 if (range1->index2 != range2->index2)
339static xmlXPathObjectPtr
340xmlXPtrNewRangeInternal(xmlNodePtr
start,
int startindex,
341 xmlNodePtr
end,
int endindex) {
342 xmlXPathObjectPtr
ret;
350 if ((
end !=
NULL) && (
end->type == XML_NAMESPACE_DECL))
353 ret = (xmlXPathObjectPtr)
xmlMalloc(
sizeof(xmlXPathObject));
355 xmlXPtrErrMemory(
"allocating range");
359 ret->type = XPATH_RANGE;
361 ret->index = startindex;
363 ret->index2 = endindex;
379xmlXPtrNewRange(xmlNodePtr
start,
int startindex,
380 xmlNodePtr
end,
int endindex) {
381 xmlXPathObjectPtr
ret;
392 ret = xmlXPtrNewRangeInternal(
start, startindex,
end, endindex);
393 xmlXPtrRangeCheckOrder(
ret);
407xmlXPtrNewRangePoints(xmlXPathObjectPtr
start, xmlXPathObjectPtr
end) {
408 xmlXPathObjectPtr
ret;
414 if (
start->type != XPATH_POINT)
416 if (
end->type != XPATH_POINT)
421 xmlXPtrRangeCheckOrder(
ret);
435xmlXPtrNewRangePointNode(xmlXPathObjectPtr
start, xmlNodePtr
end) {
436 xmlXPathObjectPtr
ret;
442 if (
start->type != XPATH_POINT)
446 xmlXPtrRangeCheckOrder(
ret);
460xmlXPtrNewRangeNodePoint(xmlNodePtr
start, xmlXPathObjectPtr
end) {
461 xmlXPathObjectPtr
ret;
467 if (
end->type != XPATH_POINT)
471 xmlXPtrRangeCheckOrder(
ret);
485xmlXPtrNewRangeNodes(xmlNodePtr
start, xmlNodePtr
end) {
486 xmlXPathObjectPtr
ret;
494 xmlXPtrRangeCheckOrder(
ret);
507xmlXPtrNewCollapsedRange(xmlNodePtr
start) {
508 xmlXPathObjectPtr
ret;
527xmlXPtrNewRangeNodeObject(xmlNodePtr
start, xmlXPathObjectPtr
end) {
530 xmlXPathObjectPtr
ret;
539 endIndex =
end->index;
542 endNode =
end->user2;
543 endIndex =
end->index2;
549 if ((
end->nodesetval ==
NULL) || (
end->nodesetval->nodeNr <= 0))
551 endNode =
end->nodesetval->nodeTab[
end->nodesetval->nodeNr - 1];
559 ret = xmlXPtrNewRangeInternal(
start, -1, endNode, endIndex);
560 xmlXPtrRangeCheckOrder(
ret);
564#define XML_RANGESET_DEFAULT 10
575xmlXPtrLocationSetCreate(xmlXPathObjectPtr
val) {
576 xmlLocationSetPtr
ret;
578 ret = (xmlLocationSetPtr)
xmlMalloc(
sizeof(xmlLocationSet));
580 xmlXPtrErrMemory(
"allocating locationset");
585 ret->locTab = (xmlXPathObjectPtr *)
xmlMalloc(XML_RANGESET_DEFAULT *
586 sizeof(xmlXPathObjectPtr));
588 xmlXPtrErrMemory(
"allocating locationset");
593 XML_RANGESET_DEFAULT *
sizeof(xmlXPathObjectPtr));
594 ret->locMax = XML_RANGESET_DEFAULT;
609xmlXPtrLocationSetAdd(xmlLocationSetPtr
cur, xmlXPathObjectPtr
val) {
617 for (
i = 0;
i <
cur->locNr;
i++) {
618 if (xmlXPtrRangesEqual(
cur->locTab[
i],
val)) {
619 xmlXPathFreeObject(
val);
627 if (
cur->locMax == 0) {
628 cur->locTab = (xmlXPathObjectPtr *)
xmlMalloc(XML_RANGESET_DEFAULT *
629 sizeof(xmlXPathObjectPtr));
631 xmlXPtrErrMemory(
"adding location to set");
635 XML_RANGESET_DEFAULT *
sizeof(xmlXPathObjectPtr));
636 cur->locMax = XML_RANGESET_DEFAULT;
637 }
else if (
cur->locNr ==
cur->locMax) {
638 xmlXPathObjectPtr *
temp;
642 sizeof(xmlXPathObjectPtr));
644 xmlXPtrErrMemory(
"adding location to set");
662xmlXPtrLocationSetMerge(xmlLocationSetPtr val1, xmlLocationSetPtr val2) {
666 if (val2 ==
NULL)
return(val1);
673 for (
i = 0;
i < val2->locNr;
i++)
674 xmlXPtrLocationSetAdd(val1, val2->locTab[
i]);
687xmlXPtrLocationSetDel(xmlLocationSetPtr
cur, xmlXPathObjectPtr
val) {
696 for (
i = 0;
i <
cur->locNr;
i++)
697 if (
cur->locTab[
i] ==
val)
break;
699 if (
i >=
cur->locNr) {
703 for (;
i <
cur->locNr;
i++)
704 cur->locTab[
i] =
cur->locTab[
i + 1];
716xmlXPtrLocationSetRemove(xmlLocationSetPtr
cur,
int val) {
718 if (
val >=
cur->locNr)
return;
732xmlXPtrFreeLocationSet(xmlLocationSetPtr
obj) {
737 for (
i = 0;
i <
obj->locNr;
i++) {
738 xmlXPathFreeObject(
obj->locTab[
i]);
756xmlXPtrNewLocationSetNodes(xmlNodePtr
start, xmlNodePtr
end) {
757 xmlXPathObjectPtr
ret;
759 ret = (xmlXPathObjectPtr)
xmlMalloc(
sizeof(xmlXPathObject));
761 xmlXPtrErrMemory(
"allocating locationset");
765 ret->type = XPATH_LOCATIONSET;
767 ret->user = xmlXPtrLocationSetCreate(xmlXPtrNewCollapsedRange(
start));
769 ret->user = xmlXPtrLocationSetCreate(xmlXPtrNewRangeNodes(
start,
end));
783xmlXPtrNewLocationSetNodeSet(xmlNodeSetPtr
set) {
784 xmlXPathObjectPtr
ret;
786 ret = (xmlXPathObjectPtr)
xmlMalloc(
sizeof(xmlXPathObject));
788 xmlXPtrErrMemory(
"allocating locationset");
792 ret->type = XPATH_LOCATIONSET;
795 xmlLocationSetPtr newset;
797 newset = xmlXPtrLocationSetCreate(
NULL);
801 for (
i = 0;
i <
set->nodeNr;
i++)
802 xmlXPtrLocationSetAdd(newset,
803 xmlXPtrNewCollapsedRange(
set->nodeTab[
i]));
805 ret->user = (
void *) newset;
819xmlXPtrWrapLocationSet(xmlLocationSetPtr
val) {
820 xmlXPathObjectPtr
ret;
822 ret = (xmlXPathObjectPtr)
xmlMalloc(
sizeof(xmlXPathObject));
824 xmlXPtrErrMemory(
"allocating locationset");
828 ret->type = XPATH_LOCATIONSET;
840static void xmlXPtrEvalChildSeq(xmlXPathParserContextPtr ctxt,
xmlChar *
name);
864#define CUR (*ctxt->cur)
865#define SKIP(val) ctxt->cur += (val)
866#define NXT(val) ctxt->cur[(val)]
869 while (IS_BLANK_CH(*(ctxt->cur))) NEXT
871#define CURRENT (*ctxt->cur)
872#define NEXT ((*ctxt->cur) ? ctxt->cur++: ctxt->cur)
883xmlXPtrGetChildNo(xmlXPathParserContextPtr ctxt,
int indx) {
885 xmlXPathObjectPtr
obj;
886 xmlNodeSetPtr oldset;
888 CHECK_TYPE(XPATH_NODESET);
889 obj = valuePop(ctxt);
890 oldset =
obj->nodesetval;
891 if ((indx <= 0) || (oldset ==
NULL) || (oldset->nodeNr != 1)) {
892 xmlXPathFreeObject(
obj);
893 valuePush(ctxt, xmlXPathNewNodeSet(
NULL));
896 cur = xmlXPtrGetNthChild(oldset->nodeTab[0], indx);
898 xmlXPathFreeObject(
obj);
899 valuePush(ctxt, xmlXPathNewNodeSet(
NULL));
902 oldset->nodeTab[0] =
cur;
903 valuePush(ctxt,
obj);
941xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt,
xmlChar *
name) {
947 name = xmlXPathParseName(ctxt);
949 XP_ERROR(XPATH_EXPR_ERROR);
953 XP_ERROR(XPATH_EXPR_ERROR);
962 xmlXPtrErrMemory(
"allocating buffer");
975 }
else if (
CUR ==
'(') {
977 }
else if (
CUR ==
'^') {
978 if ((
NXT(1) ==
')') || (
NXT(1) ==
'(') || (
NXT(1) ==
'^')) {
990 XP_ERROR(XPTR_SYNTAX_ERROR);
995 const xmlChar *oldBase = ctxt->base;
996 const xmlChar *oldCur = ctxt->cur;
998 ctxt->cur = ctxt->base =
buffer;
1005 ctxt->context->node = (xmlNodePtr)ctxt->context->doc;
1006 ctxt->context->proximityPosition = 1;
1007 ctxt->context->contextSize = 1;
1008#ifdef LIBXML_XPTR_LOCS_ENABLED
1011 xmlXPathEvalExpr(ctxt);
1012 ctxt->base = oldBase;
1015 const xmlChar *oldBase = ctxt->base;
1016 const xmlChar *oldCur = ctxt->cur;
1019 ctxt->cur = ctxt->base =
buffer;
1022 xmlXPtrEvalChildSeq(ctxt,
NULL);
1024 name2 = xmlXPathParseName(ctxt);
1026 ctxt->base = oldBase;
1030 XP_ERROR(XPATH_EXPR_ERROR);
1032 xmlXPtrEvalChildSeq(ctxt,
name2);
1034 ctxt->base = oldBase;
1036#ifdef XPTR_XMLNS_SCHEME
1038 const xmlChar *oldBase = ctxt->base;
1039 const xmlChar *oldCur = ctxt->cur;
1042 ctxt->cur = ctxt->base =
buffer;
1043 prefix = xmlXPathParseNCName(ctxt);
1045 ctxt->base = oldBase;
1049 XP_ERROR(XPTR_SYNTAX_ERROR);
1053 ctxt->base = oldBase;
1058 XP_ERROR(XPTR_SYNTAX_ERROR);
1063 xmlXPathRegisterNs(ctxt->context,
prefix, ctxt->cur);
1064 ctxt->base = oldBase;
1070 "unsupported scheme '%s'\n",
name);
1104xmlXPtrEvalFullXPtr(xmlXPathParserContextPtr ctxt,
xmlChar *
name) {
1106 name = xmlXPathParseName(ctxt);
1108 XP_ERROR(XPATH_EXPR_ERROR);
1110 ctxt->error = XPATH_EXPRESSION_OK;
1111 xmlXPtrEvalXPtrPart(ctxt,
name);
1114 if ((ctxt->error != XPATH_EXPRESSION_OK) &&
1122 if (ctxt->value !=
NULL) {
1123 xmlXPathObjectPtr
obj = ctxt->value;
1125 switch (
obj->type) {
1126#ifdef LIBXML_XPTR_LOCS_ENABLED
1127 case XPATH_LOCATIONSET: {
1128 xmlLocationSetPtr loc = ctxt->value->user;
1129 if ((loc !=
NULL) && (loc->locNr > 0))
1134 case XPATH_NODESET: {
1135 xmlNodeSetPtr loc = ctxt->value->nodesetval;
1136 if ((loc !=
NULL) && (loc->nodeNr > 0))
1149 obj = valuePop(ctxt);
1151 xmlXPathFreeObject(
obj);
1160 name = xmlXPathParseName(ctxt);
1176xmlXPtrEvalChildSeq(xmlXPathParserContextPtr ctxt,
xmlChar *
name) {
1183 "warning: ChildSeq not starting by /1\n",
NULL);
1187 valuePush(ctxt, xmlXPathNewString(
name));
1189 xmlXPathIdFunction(ctxt, 1);
1193 while (
CUR ==
'/') {
1197 while ((
CUR >=
'0') && (
CUR <=
'9')) {
1211 xmlXPtrGetChildNo(ctxt,
child);
1227xmlXPtrEvalXPointer(xmlXPathParserContextPtr ctxt) {
1228 if (ctxt->valueTab ==
NULL) {
1230 ctxt->valueTab = (xmlXPathObjectPtr *)
1231 xmlMalloc(10 *
sizeof(xmlXPathObjectPtr));
1232 if (ctxt->valueTab ==
NULL) {
1233 xmlXPtrErrMemory(
"allocating evaluation context");
1237 ctxt->valueMax = 10;
1243 xmlXPtrEvalChildSeq(ctxt,
NULL);
1247 name = xmlXPathParseName(ctxt);
1249 XP_ERROR(XPATH_EXPR_ERROR);
1251 xmlXPtrEvalFullXPtr(ctxt,
name);
1256 xmlXPtrEvalChildSeq(ctxt,
name);
1261 XP_ERROR(XPATH_EXPR_ERROR);
1271#ifdef LIBXML_XPTR_LOCS_ENABLED
1273void xmlXPtrStringRangeFunction(xmlXPathParserContextPtr ctxt,
int nargs);
1275void xmlXPtrStartPointFunction(xmlXPathParserContextPtr ctxt,
int nargs);
1277void xmlXPtrEndPointFunction(xmlXPathParserContextPtr ctxt,
int nargs);
1279void xmlXPtrHereFunction(xmlXPathParserContextPtr ctxt,
int nargs);
1281void xmlXPtrOriginFunction(xmlXPathParserContextPtr ctxt,
int nargs);
1283void xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt,
int nargs);
1285void xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt,
int nargs);
1300xmlXPtrNewContext(xmlDocPtr doc, xmlNodePtr here, xmlNodePtr
origin) {
1301 xmlXPathContextPtr
ret;
1305 ret = xmlXPathNewContext(doc);
1308#ifdef LIBXML_XPTR_LOCS_ENABLED
1313 xmlXPathRegisterFunc(
ret, (
xmlChar *)
"range",
1314 xmlXPtrRangeFunction);
1315 xmlXPathRegisterFunc(
ret, (
xmlChar *)
"range-inside",
1316 xmlXPtrRangeInsideFunction);
1317 xmlXPathRegisterFunc(
ret, (
xmlChar *)
"string-range",
1318 xmlXPtrStringRangeFunction);
1319 xmlXPathRegisterFunc(
ret, (
xmlChar *)
"start-point",
1320 xmlXPtrStartPointFunction);
1321 xmlXPathRegisterFunc(
ret, (
xmlChar *)
"end-point",
1322 xmlXPtrEndPointFunction);
1324 xmlXPtrHereFunction);
1325 xmlXPathRegisterFunc(
ret, (
xmlChar *)
" origin",
1326 xmlXPtrOriginFunction);
1344 xmlXPathParserContextPtr ctxt;
1345 xmlXPathObjectPtr
res =
NULL, tmp;
1354 ctxt = xmlXPathNewParserContext(
str,
ctx);
1357 xmlXPtrEvalXPointer(ctxt);
1359 if ((ctxt->value !=
NULL) &&
1360#ifdef LIBXML_XPTR_LOCS_ENABLED
1361 (ctxt->value->type != XPATH_LOCATIONSET) &&
1363 (ctxt->value->type != XPATH_NODESET)) {
1365 "xmlXPtrEval: evaluation failed to return a node set\n",
1368 res = valuePop(ctxt);
1372 tmp = valuePop(ctxt);
1375 if (tmp->type == XPATH_NODESET) {
1380 set = tmp->nodesetval;
1382 (
set->nodeTab[0] != (xmlNodePtr)
ctx->doc))
1387 xmlXPathFreeObject(tmp);
1389 }
while (tmp !=
NULL);
1392 "xmlXPtrEval: object(s) left on the eval stack\n",
1395 if (ctxt->error != XPATH_EXPRESSION_OK) {
1396 xmlXPathFreeObject(
res);
1400 xmlXPathFreeParserContext(ctxt);
1404#ifdef LIBXML_XPTR_LOCS_ENABLED
1415xmlXPtrBuildRangeNodeList(xmlXPathObjectPtr
range) {
1424 if (
range->type != XPATH_RANGE)
1432 return(xmlCopyNode(
start, 1));
1433 if (
end->type == XML_NAMESPACE_DECL)
1437 index1 =
range->index;
1438 index2 =
range->index2;
1441 if (
cur->type == XML_TEXT_NODE) {
1446 tmp = xmlNewTextLen(
NULL, 0);
1449 if ((
cur ==
start) && (index1 > 1)) {
1451 len -= (index1 - 1);
1463 xmlAddNextSibling(
last, tmp);
1465 xmlAddChild(
parent, tmp);
1468 tmp = xmlCopyNode(
cur, 0);
1481 end = xmlXPtrGetNthChild(
cur, index2 - 1);
1484 if ((
cur ==
start) && (index1 > 1)) {
1485 cur = xmlXPtrGetNthChild(
cur, index1 - 1);
1497 if ((
cur->type == XML_TEXT_NODE) ||
1498 (
cur->type == XML_CDATA_SECTION_NODE)) {
1502 tmp = xmlNewTextLen(
NULL, 0);
1511 if ((
cur ==
start) && (index1 > 1)) {
1512 tmp = xmlCopyNode(
cur, 0);
1516 cur = xmlXPtrGetNthChild(
cur, index1 - 1);
1523 tmp = xmlCopyNode(
cur, 1);
1530 switch (
cur->type) {
1532 case XML_ELEMENT_DECL:
1533 case XML_ATTRIBUTE_DECL:
1534 case XML_ENTITY_NODE:
1537 case XML_ENTITY_DECL:
1540 case XML_XINCLUDE_START:
1541 case XML_XINCLUDE_END:
1544 case XML_ATTRIBUTE_NODE:
1549 tmp = xmlCopyNode(
cur, 1);
1558 xmlAddNextSibling(
last, tmp);
1587xmlXPtrBuildNodeList(xmlXPathObjectPtr
obj) {
1593 switch (
obj->type) {
1594 case XPATH_NODESET: {
1595 xmlNodeSetPtr
set =
obj->nodesetval;
1598 for (
i = 0;
i <
set->nodeNr;
i++) {
1601 switch (
set->nodeTab[
i]->type) {
1603 case XML_CDATA_SECTION_NODE:
1604 case XML_ELEMENT_NODE:
1605 case XML_ENTITY_REF_NODE:
1606 case XML_ENTITY_NODE:
1608 case XML_COMMENT_NODE:
1609 case XML_DOCUMENT_NODE:
1610 case XML_HTML_DOCUMENT_NODE:
1611 case XML_XINCLUDE_START:
1612 case XML_XINCLUDE_END:
1614 case XML_ATTRIBUTE_NODE:
1615 case XML_NAMESPACE_DECL:
1616 case XML_DOCUMENT_TYPE_NODE:
1617 case XML_DOCUMENT_FRAG_NODE:
1618 case XML_NOTATION_NODE:
1620 case XML_ELEMENT_DECL:
1621 case XML_ATTRIBUTE_DECL:
1622 case XML_ENTITY_DECL:
1628 xmlAddNextSibling(
last, xmlCopyNode(
set->nodeTab[
i], 1));
1635 case XPATH_LOCATIONSET: {
1636 xmlLocationSetPtr
set = (xmlLocationSetPtr)
obj->user;
1639 for (
i = 0;
i <
set->locNr;
i++) {
1643 xmlAddNextSibling(
last,
1644 xmlXPtrBuildNodeList(
set->locTab[
i]));
1653 return(xmlXPtrBuildRangeNodeList(
obj));
1655 return(xmlCopyNode(
obj->user, 0));
1678xmlXPtrNbLocChildren(xmlNodePtr
node) {
1682 switch (
node->type) {
1683 case XML_HTML_DOCUMENT_NODE:
1684 case XML_DOCUMENT_NODE:
1685 case XML_ELEMENT_NODE:
1688 if (
node->type == XML_ELEMENT_NODE)
1693 case XML_ATTRIBUTE_NODE:
1697 case XML_COMMENT_NODE:
1699 case XML_CDATA_SECTION_NODE:
1700 case XML_ENTITY_REF_NODE:
1718xmlXPtrHereFunction(xmlXPathParserContextPtr ctxt,
int nargs) {
1721 if (ctxt->context->here ==
NULL)
1722 XP_ERROR(XPTR_SYNTAX_ERROR);
1724 valuePush(ctxt, xmlXPtrNewLocationSetNodes(ctxt->context->here,
NULL));
1736xmlXPtrOriginFunction(xmlXPathParserContextPtr ctxt,
int nargs) {
1739 if (ctxt->context->origin ==
NULL)
1740 XP_ERROR(XPTR_SYNTAX_ERROR);
1742 valuePush(ctxt, xmlXPtrNewLocationSetNodes(ctxt->context->origin,
NULL));
1769xmlXPtrStartPointFunction(xmlXPathParserContextPtr ctxt,
int nargs) {
1771 xmlLocationSetPtr newset =
NULL;
1772 xmlLocationSetPtr oldset =
NULL;
1775 if ((ctxt->value ==
NULL) ||
1776 ((ctxt->value->type != XPATH_LOCATIONSET) &&
1777 (ctxt->value->type != XPATH_NODESET)))
1778 XP_ERROR(XPATH_INVALID_TYPE)
1780 obj = valuePop(ctxt);
1781 if (
obj->type == XPATH_NODESET) {
1785 tmp = xmlXPtrNewLocationSetNodeSet(
obj->nodesetval);
1786 xmlXPathFreeObject(
obj);
1788 XP_ERROR(XPATH_MEMORY_ERROR)
1792 newset = xmlXPtrLocationSetCreate(
NULL);
1793 if (newset ==
NULL) {
1794 xmlXPathFreeObject(
obj);
1795 XP_ERROR(XPATH_MEMORY_ERROR);
1797 oldset = (xmlLocationSetPtr)
obj->user;
1801 for (
i = 0;
i < oldset->locNr;
i++) {
1802 tmp = oldset->locTab[
i];
1806 switch (tmp->type) {
1808 point = xmlXPtrNewPoint(tmp->user, tmp->index);
1811 xmlNodePtr
node = tmp->user;
1813 if ((
node->type == XML_ATTRIBUTE_NODE) ||
1814 (
node->type == XML_NAMESPACE_DECL)) {
1815 xmlXPathFreeObject(
obj);
1816 xmlXPtrFreeLocationSet(newset);
1817 XP_ERROR(XPTR_SYNTAX_ERROR);
1819 point = xmlXPtrNewPoint(
node, tmp->index);
1832 xmlXPtrLocationSetAdd(newset,
point);
1835 xmlXPathFreeObject(
obj);
1836 valuePush(ctxt, xmlXPtrWrapLocationSet(newset));
1865xmlXPtrEndPointFunction(xmlXPathParserContextPtr ctxt,
int nargs) {
1867 xmlLocationSetPtr newset =
NULL;
1868 xmlLocationSetPtr oldset =
NULL;
1871 if ((ctxt->value ==
NULL) ||
1872 ((ctxt->value->type != XPATH_LOCATIONSET) &&
1873 (ctxt->value->type != XPATH_NODESET)))
1874 XP_ERROR(XPATH_INVALID_TYPE)
1876 obj = valuePop(ctxt);
1877 if (
obj->type == XPATH_NODESET) {
1881 tmp = xmlXPtrNewLocationSetNodeSet(
obj->nodesetval);
1882 xmlXPathFreeObject(
obj);
1884 XP_ERROR(XPATH_MEMORY_ERROR)
1888 newset = xmlXPtrLocationSetCreate(
NULL);
1889 if (newset ==
NULL) {
1890 xmlXPathFreeObject(
obj);
1891 XP_ERROR(XPATH_MEMORY_ERROR);
1893 oldset = (xmlLocationSetPtr)
obj->user;
1897 for (
i = 0;
i < oldset->locNr;
i++) {
1898 tmp = oldset->locTab[
i];
1902 switch (tmp->type) {
1904 point = xmlXPtrNewPoint(tmp->user, tmp->index);
1907 xmlNodePtr
node = tmp->user2;
1909 if ((
node->type == XML_ATTRIBUTE_NODE) ||
1910 (
node->type == XML_NAMESPACE_DECL)) {
1911 xmlXPathFreeObject(
obj);
1912 xmlXPtrFreeLocationSet(newset);
1913 XP_ERROR(XPTR_SYNTAX_ERROR);
1915 point = xmlXPtrNewPoint(
node, tmp->index2);
1916 }
else if (tmp->user ==
NULL) {
1918 xmlXPtrNbLocChildren(
node));
1931 xmlXPtrLocationSetAdd(newset,
point);
1934 xmlXPathFreeObject(
obj);
1935 valuePush(ctxt, xmlXPtrWrapLocationSet(newset));
1950static xmlXPathObjectPtr
1951xmlXPtrCoveringRange(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr loc) {
1954 if ((ctxt ==
NULL) || (ctxt->context ==
NULL) ||
1955 (ctxt->context->doc ==
NULL))
1957 switch (loc->type) {
1959 return(xmlXPtrNewRange(loc->user, loc->index,
1960 loc->user, loc->index));
1962 if (loc->user2 !=
NULL) {
1963 return(xmlXPtrNewRange(loc->user, loc->index,
1964 loc->user2, loc->index2));
1966 xmlNodePtr
node = (xmlNodePtr) loc->user;
1967 if (
node == (xmlNodePtr) ctxt->context->doc) {
1968 return(xmlXPtrNewRange(
node, 0,
node,
1969 xmlXPtrGetArity(
node)));
1971 switch (
node->type) {
1972 case XML_ATTRIBUTE_NODE:
1974 return(xmlXPtrNewRange(
node, 0,
node,
1975 xmlXPtrGetArity(
node)));
1976 case XML_ELEMENT_NODE:
1978 case XML_CDATA_SECTION_NODE:
1979 case XML_ENTITY_REF_NODE:
1981 case XML_COMMENT_NODE:
1982 case XML_DOCUMENT_NODE:
1983 case XML_NOTATION_NODE:
1984 case XML_HTML_DOCUMENT_NODE: {
1985 int indx = xmlXPtrGetIndex(
node);
1988 return(xmlXPtrNewRange(
node, indx - 1,
2016xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt,
int nargs) {
2018 xmlXPathObjectPtr
set;
2019 xmlLocationSetPtr oldset;
2020 xmlLocationSetPtr newset;
2023 if ((ctxt->value ==
NULL) ||
2024 ((ctxt->value->type != XPATH_LOCATIONSET) &&
2025 (ctxt->value->type != XPATH_NODESET)))
2026 XP_ERROR(XPATH_INVALID_TYPE)
2028 set = valuePop(ctxt);
2029 if (
set->type == XPATH_NODESET) {
2030 xmlXPathObjectPtr tmp;
2035 tmp = xmlXPtrNewLocationSetNodeSet(
set->nodesetval);
2036 xmlXPathFreeObject(
set);
2038 XP_ERROR(XPATH_MEMORY_ERROR)
2041 oldset = (xmlLocationSetPtr)
set->user;
2046 newset = xmlXPtrLocationSetCreate(
NULL);
2047 if (newset ==
NULL) {
2048 xmlXPathFreeObject(
set);
2049 XP_ERROR(XPATH_MEMORY_ERROR);
2051 if (oldset !=
NULL) {
2052 for (
i = 0;
i < oldset->locNr;
i++) {
2053 xmlXPtrLocationSetAdd(newset,
2054 xmlXPtrCoveringRange(ctxt, oldset->locTab[
i]));
2061 valuePush(ctxt, xmlXPtrWrapLocationSet(newset));
2062 xmlXPathFreeObject(
set);
2074static xmlXPathObjectPtr
2075xmlXPtrInsideRange(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr loc) {
2078 if ((ctxt ==
NULL) || (ctxt->context ==
NULL) ||
2079 (ctxt->context->doc ==
NULL))
2081 switch (loc->type) {
2083 xmlNodePtr
node = (xmlNodePtr) loc->user;
2086 case XML_COMMENT_NODE:
2088 case XML_CDATA_SECTION_NODE: {
2090 return(xmlXPtrNewRange(
node, 0,
node, 0));
2092 return(xmlXPtrNewRange(
node, 0,
node,
2096 case XML_ATTRIBUTE_NODE:
2097 case XML_ELEMENT_NODE:
2098 case XML_ENTITY_REF_NODE:
2099 case XML_DOCUMENT_NODE:
2100 case XML_NOTATION_NODE:
2101 case XML_HTML_DOCUMENT_NODE: {
2102 return(xmlXPtrNewRange(
node, 0,
node,
2103 xmlXPtrGetArity(
node)));
2111 xmlNodePtr
node = (xmlNodePtr) loc->user;
2112 if (loc->user2 !=
NULL) {
2113 return(xmlXPtrNewRange(
node, loc->index,
2114 loc->user2, loc->index2));
2116 switch (
node->type) {
2118 case XML_COMMENT_NODE:
2120 case XML_CDATA_SECTION_NODE: {
2122 return(xmlXPtrNewRange(
node, 0,
node, 0));
2124 return(xmlXPtrNewRange(
node, 0,
node,
2128 case XML_ATTRIBUTE_NODE:
2129 case XML_ELEMENT_NODE:
2130 case XML_ENTITY_REF_NODE:
2131 case XML_DOCUMENT_NODE:
2132 case XML_NOTATION_NODE:
2133 case XML_HTML_DOCUMENT_NODE: {
2134 return(xmlXPtrNewRange(
node, 0,
node,
2135 xmlXPtrGetArity(
node)));
2170xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt,
int nargs) {
2172 xmlXPathObjectPtr
set;
2173 xmlLocationSetPtr oldset;
2174 xmlLocationSetPtr newset;
2177 if ((ctxt->value ==
NULL) ||
2178 ((ctxt->value->type != XPATH_LOCATIONSET) &&
2179 (ctxt->value->type != XPATH_NODESET)))
2180 XP_ERROR(XPATH_INVALID_TYPE)
2182 set = valuePop(ctxt);
2183 if (
set->type == XPATH_NODESET) {
2184 xmlXPathObjectPtr tmp;
2189 tmp = xmlXPtrNewLocationSetNodeSet(
set->nodesetval);
2190 xmlXPathFreeObject(
set);
2192 XP_ERROR(XPATH_MEMORY_ERROR)
2199 newset = xmlXPtrLocationSetCreate(
NULL);
2200 if (newset ==
NULL) {
2201 xmlXPathFreeObject(
set);
2202 XP_ERROR(XPATH_MEMORY_ERROR);
2204 oldset = (xmlLocationSetPtr)
set->user;
2206 for (
i = 0;
i < oldset->locNr;
i++) {
2207 xmlXPtrLocationSetAdd(newset,
2208 xmlXPtrInsideRange(ctxt, oldset->locTab[
i]));
2215 valuePush(ctxt, xmlXPtrWrapLocationSet(newset));
2216 xmlXPathFreeObject(
set);
2230xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt,
2232 XP_ERROR(XPATH_EXPR_ERROR);
2246xmlXPtrAdvanceNode(xmlNodePtr
cur,
int *
level) {
2248 if ((
cur ==
NULL) || (
cur->type == XML_NAMESPACE_DECL))
2273 if ((
cur->type != XML_ELEMENT_NODE) &&
2274 (
cur->type != XML_TEXT_NODE) &&
2275 (
cur->type != XML_DOCUMENT_NODE) &&
2276 (
cur->type != XML_HTML_DOCUMENT_NODE) &&
2277 (
cur->type != XML_CDATA_SECTION_NODE)) {
2278 if (
cur->type == XML_ENTITY_REF_NODE) {
2298xmlXPtrAdvanceChar(xmlNodePtr *
node,
int *indx,
int bytes) {
2306 if ((
cur ==
NULL) || (
cur->type == XML_NAMESPACE_DECL))
2310 while (
bytes >= 0) {
2316 ((
cur->type == XML_ELEMENT_NODE) ||
2317 (
cur->type == XML_DOCUMENT_NODE) ||
2318 (
cur->type == XML_HTML_DOCUMENT_NODE))) {
2347 if ((
cur->type != XML_ELEMENT_NODE) &&
2387xmlXPtrMatchString(
const xmlChar *
string, xmlNodePtr
start,
int startindex,
2388 xmlNodePtr *
end,
int *endindex) {
2400 ((*end)->type == XML_NAMESPACE_DECL) || (endindex ==
NULL))
2403 pos = startindex - 1;
2410 if ((
cur->type != XML_ELEMENT_NODE) && (
cur->content !=
NULL)) {
2425 string = &
string[sub];
2457xmlXPtrSearchString(
const xmlChar *
string, xmlNodePtr *
start,
int *startindex,
2458 xmlNodePtr *
end,
int *endindex) {
2468 ((*start)->type == XML_NAMESPACE_DECL) || (startindex ==
NULL))
2473 pos = *startindex - 1;
2477 if ((
cur->type != XML_ELEMENT_NODE) && (
cur->content !=
NULL)) {
2484 if (xmlXPtrMatchString(
string,
cur,
pos + 1,
2487 *startindex =
pos + 1;
2501 *startindex =
pos + 1;
2503 *endindex =
pos + 1;
2508 if ((
cur == *
end) && (
pos >= *endindex))
2528xmlXPtrGetLastChar(xmlNodePtr *
node,
int *indx) {
2533 ((*node)->type == XML_NAMESPACE_DECL) || (indx ==
NULL))
2538 if ((
cur->type == XML_ELEMENT_NODE) ||
2539 (
cur->type == XML_DOCUMENT_NODE) ||
2540 (
cur->type == XML_HTML_DOCUMENT_NODE)) {
2548 else if ((
cur->type != XML_ELEMENT_NODE) &&
2574xmlXPtrGetStartPoint(xmlXPathObjectPtr
obj, xmlNodePtr *
node,
int *indx) {
2578 switch (
obj->type) {
2581 if (
obj->index <= 0)
2588 if (
obj->index <= 0)
2610xmlXPtrGetEndPoint(xmlXPathObjectPtr
obj, xmlNodePtr *
node,
int *indx) {
2614 switch (
obj->type) {
2617 if (
obj->index <= 0)
2624 if (
obj->index <= 0)
2672xmlXPtrStringRangeFunction(xmlXPathParserContextPtr ctxt,
int nargs) {
2673 int i, startindex, endindex = 0, fendindex;
2676 xmlLocationSetPtr oldset;
2677 xmlLocationSetPtr newset =
NULL;
2678 xmlXPathObjectPtr
string =
NULL;
2679 xmlXPathObjectPtr position =
NULL;
2681 int found,
pos = 0,
num = 0;
2686 if ((nargs < 2) || (nargs > 4))
2687 XP_ERROR(XPATH_INVALID_ARITY);
2690 if ((ctxt->value ==
NULL) || (ctxt->value->type != XPATH_NUMBER)) {
2691 xmlXPathErr(ctxt, XPATH_INVALID_TYPE);
2699 if ((ctxt->value ==
NULL) || (ctxt->value->type != XPATH_NUMBER)) {
2700 xmlXPathErr(ctxt, XPATH_INVALID_TYPE);
2703 position = valuePop(ctxt);
2704 if (position !=
NULL)
2705 pos = (
int) position->floatval;
2707 if ((ctxt->value ==
NULL) || (ctxt->value->type != XPATH_STRING)) {
2708 xmlXPathErr(ctxt, XPATH_INVALID_TYPE);
2711 string = valuePop(ctxt);
2712 if ((ctxt->value ==
NULL) ||
2713 ((ctxt->value->type != XPATH_LOCATIONSET) &&
2714 (ctxt->value->type != XPATH_NODESET))) {
2715 xmlXPathErr(ctxt, XPATH_INVALID_TYPE);
2718 set = valuePop(ctxt);
2719 newset = xmlXPtrLocationSetCreate(
NULL);
2720 if (newset ==
NULL) {
2721 xmlXPathErr(ctxt, XPATH_MEMORY_ERROR);
2724 if (
set->nodesetval ==
NULL) {
2727 if (
set->type == XPATH_NODESET) {
2728 xmlXPathObjectPtr tmp;
2733 tmp = xmlXPtrNewLocationSetNodeSet(
set->nodesetval);
2734 xmlXPathFreeObject(
set);
2737 xmlXPathErr(ctxt, XPATH_MEMORY_ERROR);
2742 oldset = (xmlLocationSetPtr)
set->user;
2748 for (
i = 0;
i < oldset->locNr;
i++) {
2750 xmlXPtrGetStartPoint(oldset->locTab[
i], &
start, &startindex);
2751 xmlXPtrGetEndPoint(oldset->locTab[
i], &
end, &endindex);
2752 xmlXPtrAdvanceChar(&
start, &startindex, 0);
2753 xmlXPtrGetLastChar(&
end, &endindex);
2757 fendindex = endindex;
2758 found = xmlXPtrSearchString(
string->stringval, &
start, &startindex,
2761 if (position ==
NULL) {
2762 xmlXPtrLocationSetAdd(newset,
2763 xmlXPtrNewRange(
start, startindex, fend, fendindex));
2764 }
else if (xmlXPtrAdvanceChar(&
start, &startindex,
2770 rindx = startindex - 1;
2771 if (xmlXPtrAdvanceChar(&rend, &rindx,
2773 xmlXPtrLocationSetAdd(newset,
2774 xmlXPtrNewRange(
start, startindex,
2778 xmlXPtrLocationSetAdd(newset,
2779 xmlXPtrNewRange(
start, startindex,
2780 start, startindex));
2782 xmlXPtrLocationSetAdd(newset,
2783 xmlXPtrNewRange(
start, startindex,
2788 startindex = fendindex;
2789 if (
string->stringval[0] == 0)
2792 }
while (found == 1);
2800 valuePush(ctxt, xmlXPtrWrapLocationSet(newset));
2801 xmlXPathFreeObject(
set);
2802 xmlXPathFreeObject(
string);
2803 if (position) xmlXPathFreeObject(position);
2818xmlXPtrEvalRangePredicate(xmlXPathParserContextPtr ctxt) {
2820 xmlXPathObjectPtr
res;
2821 xmlXPathObjectPtr
obj, tmp;
2822 xmlLocationSetPtr newset =
NULL;
2823 xmlLocationSetPtr oldset;
2826 if (ctxt ==
NULL)
return;
2830 XP_ERROR(XPATH_INVALID_PREDICATE_ERROR);
2840 CHECK_TYPE(XPATH_LOCATIONSET);
2841 obj = valuePop(ctxt);
2843 ctxt->context->node =
NULL;
2845 if ((oldset ==
NULL) || (oldset->locNr == 0)) {
2846 ctxt->context->contextSize = 0;
2847 ctxt->context->proximityPosition = 0;
2848 xmlXPathEvalExpr(ctxt);
2849 res = valuePop(ctxt);
2851 xmlXPathFreeObject(
res);
2852 valuePush(ctxt,
obj);
2860 newset = xmlXPtrLocationSetCreate(
NULL);
2862 for (
i = 0;
i < oldset->locNr;
i++) {
2869 ctxt->context->node = oldset->locTab[
i]->user;
2870 tmp = xmlXPathNewNodeSet(ctxt->context->node);
2871 valuePush(ctxt, tmp);
2872 ctxt->context->contextSize = oldset->locNr;
2873 ctxt->context->proximityPosition =
i + 1;
2875 xmlXPathEvalExpr(ctxt);
2882 res = valuePop(ctxt);
2883 if (xmlXPathEvaluatePredicateResult(ctxt,
res)) {
2884 xmlXPtrLocationSetAdd(newset,
2885 xmlXPathObjectCopy(oldset->locTab[
i]));
2892 xmlXPathFreeObject(
res);
2893 if (ctxt->value == tmp) {
2894 res = valuePop(ctxt);
2895 xmlXPathFreeObject(
res);
2898 ctxt->context->node =
NULL;
2904 xmlXPathFreeObject(
obj);
2905 ctxt->context->node =
NULL;
2906 ctxt->context->contextSize = -1;
2907 ctxt->context->proximityPosition = -1;
2908 valuePush(ctxt, xmlXPtrWrapLocationSet(newset));
2911 XP_ERROR(XPATH_INVALID_PREDICATE_ERROR);
static unsigned char bytes[4]
static WCHAR no[MAX_STRING_RESOURCE_LEN]
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
GLint const GLchar GLint stringlen
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
static unsigned int number
static unsigned __int64 next
xmlReallocFunc xmlRealloc
xmlMallocFunc xmlMallocAtomic
XML_GLOBALS_PARSER XMLPUBFUN void xmlInitParser(void)
XML_HIDDEN void __xmlRaiseError(xmlStructuredErrorFunc schannel, xmlGenericErrorFunc channel, void *data, void *ctx, void *nod, int domain, int code, xmlErrorLevel level, const char *file, int line, const char *str1, const char *str2, const char *str3, int int1, int col, const char *msg,...) LIBXML_ATTR_FORMAT(16
Character const *const prefix
XMLPUBFUN void xmlResetError(xmlErrorPtr err)
@ XML_XPTR_UNKNOWN_SCHEME
@ XML_XPTR_CHILDSEQ_START
XMLPUBFUN int xmlStrlen(const xmlChar *str)
XMLPUBFUN int xmlStrncmp(const xmlChar *str1, const xmlChar *str2, int len)
XMLPUBFUN int xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
XMLPUBFUN const xmlChar * xmlStrchr(const xmlChar *str, xmlChar val)
XMLPUBFUN xmlChar * xmlStrdup(const xmlChar *cur)
#define LIBXML_ATTR_FORMAT(fmt, args)