diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e1e4a2b..41ebdc54 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ .test: image: registry.gitlab.gnome.org/gnome/libxml2 variables: - BASE_CONFIG: "--with-legacy --with-xptr-locs" + BASE_CONFIG: "--with-legacy" before_script: - rm -rf libxml2-build - mkdir libxml2-build @@ -72,7 +72,7 @@ clang:msan: tags: - win32-ps variables: - BASE_CONFIG: "--with-legacy --with-xptr-locs" + BASE_CONFIG: "--with-legacy" # Disabled for now, see #658 CONFIG: "--without-python" CHERE_INVOKING: "yes" diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dd13b5b..ef4e0e7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,6 @@ option(LIBXML2_WITH_WRITER "Add the xmlWriter saving interface" ON) option(LIBXML2_WITH_XINCLUDE "Add the XInclude support" ON) option(LIBXML2_WITH_XPATH "Add the XPATH support" ON) option(LIBXML2_WITH_XPTR "Add the XPointer support" ON) -option(LIBXML2_WITH_XPTR_LOCS "Add support for XPointer locations" OFF) option(LIBXML2_WITH_ZLIB "Use libz" OFF) set(LIBXML2_XMLCONF_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Working directory for XML Conformance Test Suite") @@ -71,7 +70,7 @@ if(LIBXML2_WITH_PYTHON) CACHE PATH "Python bindings install directory") endif() -foreach(VARIABLE IN ITEMS WITH_AUTOMATA WITH_C14N WITH_CATALOG WITH_DEBUG WITH_EXPR WITH_HTML WITH_HTTP WITH_ICONV WITH_ICU WITH_ISO8859X WITH_LEGACY WITH_LZMA WITH_MODULES WITH_OUTPUT WITH_PATTERN WITH_PUSH WITH_READER WITH_REGEXPS WITH_SAX1 WITH_SCHEMAS WITH_SCHEMATRON WITH_THREADS WITH_THREAD_ALLOC WITH_TREE WITH_UNICODE WITH_VALID WITH_WRITER WITH_XINCLUDE WITH_XPATH WITH_XPTR WITH_XPTR_LOCS WITH_ZLIB) +foreach(VARIABLE IN ITEMS WITH_AUTOMATA WITH_C14N WITH_CATALOG WITH_DEBUG WITH_EXPR WITH_HTML WITH_HTTP WITH_ICONV WITH_ICU WITH_ISO8859X WITH_LEGACY WITH_LZMA WITH_MODULES WITH_OUTPUT WITH_PATTERN WITH_PUSH WITH_READER WITH_REGEXPS WITH_SAX1 WITH_SCHEMAS WITH_SCHEMATRON WITH_THREADS WITH_THREAD_ALLOC WITH_TREE WITH_UNICODE WITH_VALID WITH_WRITER WITH_XINCLUDE WITH_XPATH WITH_XPTR WITH_ZLIB) if(LIBXML2_${VARIABLE}) set(${VARIABLE} 1) else() diff --git a/configure.ac b/configure.ac index 33845a98..bdd37f8e 100644 --- a/configure.ac +++ b/configure.ac @@ -121,8 +121,6 @@ AC_ARG_WITH(xpath, [ --with-xpath XPath 1.0 support (on)]) AC_ARG_WITH(xptr, [ --with-xptr XPointer support (on)]) -AC_ARG_WITH(xptr-locs, -[ --with-xptr-locs XPointer ranges and points (off)]) AC_ARG_WITH(zlib, [ --with-zlib[[=DIR]] use libz in DIR (off)]) @@ -212,12 +210,6 @@ if test "$with_xinclude" = "yes"; then fi with_xpath=yes fi -if test "$with_xptr_locs" = "yes"; then - if test "$with_xptr" = "no"; then - echo WARNING: --with-xptr-locs overrides --without-xptr - fi - with_xptr=yes -fi if test "$with_xptr" = "yes"; then if test "$with_xpath" = "no"; then echo WARNING: --with-xptr overrides --without-xpath @@ -609,21 +601,12 @@ AM_CONDITIONAL(WITH_CATALOG_SOURCES, test "$WITH_CATALOG" = "1") if test "$with_xptr" = "no" ; then echo Disabling XPointer support WITH_XPTR=0 - WITH_XPTR_LOCS=0 else WITH_XPTR=1 fi AC_SUBST(WITH_XPTR) AM_CONDITIONAL(WITH_XPTR_SOURCES, test "$WITH_XPTR" = "1") -if test "$with_xptr_locs" != "yes" ; then - WITH_XPTR_LOCS=0 -else - echo Enabling Xpointer locations support - WITH_XPTR_LOCS=1 -fi -AC_SUBST(WITH_XPTR_LOCS) - if test "$with_c14n" = "no" ; then echo Disabling C14N support WITH_C14N=0 diff --git a/debugXML.c b/debugXML.c index ed56b0f8..90563984 100644 --- a/debugXML.c +++ b/debugXML.c @@ -1830,20 +1830,6 @@ xmlShellPrintXPathError(int errorType, const char *arg) fprintf(stderr, "%s is a string\n", arg); break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - fprintf(stderr, - "%s is a point\n", arg); - break; - case XPATH_RANGE: - fprintf(stderr, - "%s is a range\n", arg); - break; - case XPATH_LOCATIONSET: - fprintf(stderr, - "%s is a range\n", arg); - break; -#endif /* LIBXML_XPTR_LOCS_ENABLED */ case XPATH_USERS: fprintf(stderr, "%s is user-defined\n", arg); @@ -2992,20 +2978,6 @@ xmlShell(xmlDocPtr doc, const char *filename, xmlShellReadlineFunc input, fprintf(ctxt->output, "%s is a string\n", arg); break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - fprintf(ctxt->output, - "%s is a point\n", arg); - break; - case XPATH_RANGE: - fprintf(ctxt->output, - "%s is a range\n", arg); - break; - case XPATH_LOCATIONSET: - fprintf(ctxt->output, - "%s is a range\n", arg); - break; -#endif /* LIBXML_XPTR_LOCS_ENABLED */ case XPATH_USERS: fprintf(ctxt->output, "%s is user-defined\n", arg); @@ -3111,20 +3083,6 @@ xmlShell(xmlDocPtr doc, const char *filename, xmlShellReadlineFunc input, fprintf(ctxt->output, "%s is a string\n", arg); break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - fprintf(ctxt->output, - "%s is a point\n", arg); - break; - case XPATH_RANGE: - fprintf(ctxt->output, - "%s is a range\n", arg); - break; - case XPATH_LOCATIONSET: - fprintf(ctxt->output, - "%s is a range\n", arg); - break; -#endif /* LIBXML_XPTR_LOCS_ENABLED */ case XPATH_USERS: fprintf(ctxt->output, "%s is user-defined\n", arg); @@ -3190,20 +3148,6 @@ xmlShell(xmlDocPtr doc, const char *filename, xmlShellReadlineFunc input, fprintf(ctxt->output, "%s is a string\n", arg); break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - fprintf(ctxt->output, - "%s is a point\n", arg); - break; - case XPATH_RANGE: - fprintf(ctxt->output, - "%s is a range\n", arg); - break; - case XPATH_LOCATIONSET: - fprintf(ctxt->output, - "%s is a range\n", arg); - break; -#endif /* LIBXML_XPTR_LOCS_ENABLED */ case XPATH_USERS: fprintf(ctxt->output, "%s is user-defined\n", arg); @@ -3277,20 +3221,6 @@ xmlShell(xmlDocPtr doc, const char *filename, xmlShellReadlineFunc input, fprintf(ctxt->output, "%s is a string\n", arg); break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - fprintf(ctxt->output, - "%s is a point\n", arg); - break; - case XPATH_RANGE: - fprintf(ctxt->output, - "%s is a range\n", arg); - break; - case XPATH_LOCATIONSET: - fprintf(ctxt->output, - "%s is a range\n", arg); - break; -#endif /* LIBXML_XPTR_LOCS_ENABLED */ case XPATH_USERS: fprintf(ctxt->output, "%s is user-defined\n", arg); @@ -3357,20 +3287,6 @@ xmlShell(xmlDocPtr doc, const char *filename, xmlShellReadlineFunc input, fprintf(ctxt->output, "%s is a string\n", arg); break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - fprintf(ctxt->output, - "%s is a point\n", arg); - break; - case XPATH_RANGE: - fprintf(ctxt->output, - "%s is a range\n", arg); - break; - case XPATH_LOCATIONSET: - fprintf(ctxt->output, - "%s is a range\n", arg); - break; -#endif /* LIBXML_XPTR_LOCS_ENABLED */ case XPATH_USERS: fprintf(ctxt->output, "%s is user-defined\n", arg); diff --git a/gentest.py b/gentest.py index 3e5ba159..482d6830 100755 --- a/gentest.py +++ b/gentest.py @@ -155,13 +155,6 @@ skipped_functions = [ # Legacy "xmlCleanupPredefinedEntities", "xmlInitializePredefinedEntities", "xmlSetFeature", "xmlGetFeature", "xmlGetFeaturesList", -# location sets -"xmlXPtrLocationSetAdd", -"xmlXPtrLocationSetCreate", -"xmlXPtrLocationSetDel", -"xmlXPtrLocationSetMerge", -"xmlXPtrLocationSetRemove", -"xmlXPtrWrapLocationSet", ] # diff --git a/include/libxml/meson.build b/include/libxml/meson.build index 4b497c5f..a3c37a74 100644 --- a/include/libxml/meson.build +++ b/include/libxml/meson.build @@ -32,7 +32,6 @@ xmlversion_h.set10('WITH_WRITER', want_writer) xmlversion_h.set10('WITH_XINCLUDE', want_xinclude) xmlversion_h.set10('WITH_XPATH', want_xpath) xmlversion_h.set10('WITH_XPTR', want_xptr) -xmlversion_h.set10('WITH_XPTR_LOCS', want_xptr_locs) xmlversion_h.set10('WITH_ZLIB', zlib_dep.found()) configure_file( diff --git a/include/libxml/xmlversion.h.in b/include/libxml/xmlversion.h.in index 708c287d..0525b4ad 100644 --- a/include/libxml/xmlversion.h.in +++ b/include/libxml/xmlversion.h.in @@ -199,15 +199,6 @@ #define LIBXML_XPTR_ENABLED #endif -/** - * LIBXML_XPTR_LOCS_ENABLED: - * - * Whether support for XPointer locations is configured in - */ -#if @WITH_XPTR_LOCS@ -#define LIBXML_XPTR_LOCS_ENABLED -#endif - /** * LIBXML_XINCLUDE_ENABLED: * diff --git a/include/libxml/xpath.h b/include/libxml/xpath.h index b89e105c..902a1983 100644 --- a/include/libxml/xpath.h +++ b/include/libxml/xpath.h @@ -104,22 +104,15 @@ typedef enum { XPATH_BOOLEAN = 2, XPATH_NUMBER = 3, XPATH_STRING = 4, -#ifdef LIBXML_XPTR_LOCS_ENABLED - XPATH_POINT = 5, - XPATH_RANGE = 6, - XPATH_LOCATIONSET = 7, -#endif XPATH_USERS = 8, XPATH_XSLT_TREE = 9 /* An XSLT value tree, non modifiable */ } xmlXPathObjectType; -#ifndef LIBXML_XPTR_LOCS_ENABLED /** DOC_DISABLE */ #define XPATH_POINT 5 #define XPATH_RANGE 6 #define XPATH_LOCATIONSET 7 /** DOC_ENABLE */ -#endif typedef struct _xmlXPathObject xmlXPathObject; typedef xmlXPathObject *xmlXPathObjectPtr; diff --git a/include/libxml/xpointer.h b/include/libxml/xpointer.h index a5260008..16bd5b9f 100644 --- a/include/libxml/xpointer.h +++ b/include/libxml/xpointer.h @@ -28,88 +28,10 @@ extern "C" { #endif -#if defined(LIBXML_XPTR_LOCS_ENABLED) -/* - * A Location Set - */ -typedef struct _xmlLocationSet xmlLocationSet; -typedef xmlLocationSet *xmlLocationSetPtr; -struct _xmlLocationSet { - int locNr; /* number of locations in the set */ - int locMax; /* size of the array as allocated */ - xmlXPathObjectPtr *locTab;/* array of locations */ -}; - -/* - * Handling of location sets. - */ - -XML_DEPRECATED -XMLPUBFUN xmlLocationSetPtr - xmlXPtrLocationSetCreate (xmlXPathObjectPtr val); -XML_DEPRECATED -XMLPUBFUN void - xmlXPtrFreeLocationSet (xmlLocationSetPtr obj); -XML_DEPRECATED -XMLPUBFUN xmlLocationSetPtr - xmlXPtrLocationSetMerge (xmlLocationSetPtr val1, - xmlLocationSetPtr val2); -XML_DEPRECATED -XMLPUBFUN xmlXPathObjectPtr - xmlXPtrNewRange (xmlNodePtr start, - int startindex, - xmlNodePtr end, - int endindex); -XML_DEPRECATED -XMLPUBFUN xmlXPathObjectPtr - xmlXPtrNewRangePoints (xmlXPathObjectPtr start, - xmlXPathObjectPtr end); -XML_DEPRECATED -XMLPUBFUN xmlXPathObjectPtr - xmlXPtrNewRangeNodePoint (xmlNodePtr start, - xmlXPathObjectPtr end); -XML_DEPRECATED -XMLPUBFUN xmlXPathObjectPtr - xmlXPtrNewRangePointNode (xmlXPathObjectPtr start, - xmlNodePtr end); -XML_DEPRECATED -XMLPUBFUN xmlXPathObjectPtr - xmlXPtrNewRangeNodes (xmlNodePtr start, - xmlNodePtr end); -XML_DEPRECATED -XMLPUBFUN xmlXPathObjectPtr - xmlXPtrNewLocationSetNodes (xmlNodePtr start, - xmlNodePtr end); -XML_DEPRECATED -XMLPUBFUN xmlXPathObjectPtr - xmlXPtrNewLocationSetNodeSet(xmlNodeSetPtr set); -XML_DEPRECATED -XMLPUBFUN xmlXPathObjectPtr - xmlXPtrNewRangeNodeObject (xmlNodePtr start, - xmlXPathObjectPtr end); -XML_DEPRECATED -XMLPUBFUN xmlXPathObjectPtr - xmlXPtrNewCollapsedRange (xmlNodePtr start); -XML_DEPRECATED -XMLPUBFUN void - xmlXPtrLocationSetAdd (xmlLocationSetPtr cur, - xmlXPathObjectPtr val); -XML_DEPRECATED -XMLPUBFUN xmlXPathObjectPtr - xmlXPtrWrapLocationSet (xmlLocationSetPtr val); -XML_DEPRECATED -XMLPUBFUN void - xmlXPtrLocationSetDel (xmlLocationSetPtr cur, - xmlXPathObjectPtr val); -XML_DEPRECATED -XMLPUBFUN void - xmlXPtrLocationSetRemove (xmlLocationSetPtr cur, - int val); -#endif /* defined(LIBXML_XPTR_LOCS_ENABLED) */ - /* * Functions. */ +XML_DEPRECATED XMLPUBFUN xmlXPathContextPtr xmlXPtrNewContext (xmlDocPtr doc, xmlNodePtr here, @@ -118,18 +40,6 @@ XMLPUBFUN xmlXPathObjectPtr xmlXPtrEval (const xmlChar *str, xmlXPathContextPtr ctx); -#if defined(LIBXML_XPTR_LOCS_ENABLED) -XML_DEPRECATED -XMLPUBFUN void - xmlXPtrRangeToFunction (xmlXPathParserContextPtr ctxt, - int nargs); -XML_DEPRECATED -XMLPUBFUN xmlNodePtr - xmlXPtrBuildNodeList (xmlXPathObjectPtr obj); -XML_DEPRECATED -XMLPUBFUN void - xmlXPtrEvalRangePredicate (xmlXPathParserContextPtr ctxt); -#endif /* defined(LIBXML_XPTR_LOCS_ENABLED) */ #ifdef __cplusplus } #endif diff --git a/legacy.c b/legacy.c index bb444f98..69a71bb2 100644 --- a/legacy.c +++ b/legacy.c @@ -1597,174 +1597,163 @@ xmlIOFTPClose(void *context ATTRIBUTE_UNUSED) { * xpointer.h */ -#ifndef LIBXML_XPTR_LOCS_ENABLED - -#include -#include -#include - /** DOC_DISABLE */ -typedef struct _xmlLocationSet *xmlLocationSetPtr; +XMLPUBFUN void * +xmlXPtrNewRange(void *start, int startindex, + void *end, int endindex); -XMLPUBFUN xmlXPathObjectPtr -xmlXPtrNewRange(xmlNodePtr start, int startindex, - xmlNodePtr end, int endindex); - -xmlXPathObjectPtr -xmlXPtrNewRange(xmlNodePtr start ATTRIBUTE_UNUSED, +void * +xmlXPtrNewRange(void *start ATTRIBUTE_UNUSED, int startindex ATTRIBUTE_UNUSED, - xmlNodePtr end ATTRIBUTE_UNUSED, + void *end ATTRIBUTE_UNUSED, int endindex ATTRIBUTE_UNUSED) { return(NULL); } -XMLPUBFUN xmlXPathObjectPtr -xmlXPtrNewRangePoints(xmlXPathObjectPtr start, xmlXPathObjectPtr end); +XMLPUBFUN void * +xmlXPtrNewRangePoints(void *start, void *end); -xmlXPathObjectPtr -xmlXPtrNewRangePoints(xmlXPathObjectPtr start ATTRIBUTE_UNUSED, - xmlXPathObjectPtr end ATTRIBUTE_UNUSED) { +void * +xmlXPtrNewRangePoints(void *start ATTRIBUTE_UNUSED, + void *end ATTRIBUTE_UNUSED) { return(NULL); } -XMLPUBFUN xmlXPathObjectPtr -xmlXPtrNewRangePointNode(xmlXPathObjectPtr start, xmlNodePtr end); +XMLPUBFUN void * +xmlXPtrNewRangePointNode(void *start, void *end); -xmlXPathObjectPtr -xmlXPtrNewRangePointNode(xmlXPathObjectPtr start ATTRIBUTE_UNUSED, - xmlNodePtr end ATTRIBUTE_UNUSED) { +void * +xmlXPtrNewRangePointNode(void *start ATTRIBUTE_UNUSED, + void *end ATTRIBUTE_UNUSED) { return(NULL); } -XMLPUBFUN xmlXPathObjectPtr -xmlXPtrNewRangeNodePoint(xmlNodePtr start, xmlXPathObjectPtr end); +XMLPUBFUN void * +xmlXPtrNewRangeNodePoint(void *start, void *end); -xmlXPathObjectPtr -xmlXPtrNewRangeNodePoint(xmlNodePtr start ATTRIBUTE_UNUSED, - xmlXPathObjectPtr end ATTRIBUTE_UNUSED) { +void * +xmlXPtrNewRangeNodePoint(void *start ATTRIBUTE_UNUSED, + void *end ATTRIBUTE_UNUSED) { return(NULL); } -XMLPUBFUN xmlXPathObjectPtr -xmlXPtrNewRangeNodes(xmlNodePtr start, xmlNodePtr end); +XMLPUBFUN void * +xmlXPtrNewRangeNodes(void *start, void *end); -xmlXPathObjectPtr -xmlXPtrNewRangeNodes(xmlNodePtr start ATTRIBUTE_UNUSED, - xmlNodePtr end ATTRIBUTE_UNUSED) { +void * +xmlXPtrNewRangeNodes(void *start ATTRIBUTE_UNUSED, + void *end ATTRIBUTE_UNUSED) { return(NULL); } -XMLPUBFUN xmlXPathObjectPtr -xmlXPtrNewCollapsedRange(xmlNodePtr start); +XMLPUBFUN void * +xmlXPtrNewCollapsedRange(void *start); -xmlXPathObjectPtr -xmlXPtrNewCollapsedRange(xmlNodePtr start ATTRIBUTE_UNUSED) { +void * +xmlXPtrNewCollapsedRange(void *start ATTRIBUTE_UNUSED) { return(NULL); } -XMLPUBFUN xmlXPathObjectPtr -xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end); +XMLPUBFUN void * +xmlXPtrNewRangeNodeObject(void *start, void *end); -xmlXPathObjectPtr -xmlXPtrNewRangeNodeObject(xmlNodePtr start ATTRIBUTE_UNUSED, - xmlXPathObjectPtr end ATTRIBUTE_UNUSED) { +void * +xmlXPtrNewRangeNodeObject(void *start ATTRIBUTE_UNUSED, + void *end ATTRIBUTE_UNUSED) { return(NULL); } -XMLPUBFUN xmlLocationSetPtr -xmlXPtrLocationSetCreate(xmlXPathObjectPtr val); +XMLPUBFUN void * +xmlXPtrLocationSetCreate(void *val); -xmlLocationSetPtr -xmlXPtrLocationSetCreate(xmlXPathObjectPtr val ATTRIBUTE_UNUSED) { +void * +xmlXPtrLocationSetCreate(void *val ATTRIBUTE_UNUSED) { return(NULL); } XMLPUBFUN void -xmlXPtrLocationSetAdd(xmlLocationSetPtr cur, xmlXPathObjectPtr val); +xmlXPtrLocationSetAdd(void *cur, void *val); void -xmlXPtrLocationSetAdd(xmlLocationSetPtr cur ATTRIBUTE_UNUSED, - xmlXPathObjectPtr val ATTRIBUTE_UNUSED) { +xmlXPtrLocationSetAdd(void *cur ATTRIBUTE_UNUSED, + void *val ATTRIBUTE_UNUSED) { } -XMLPUBFUN xmlLocationSetPtr -xmlXPtrLocationSetMerge(xmlLocationSetPtr val1, xmlLocationSetPtr val2); +XMLPUBFUN void * +xmlXPtrLocationSetMerge(void *val1, void *val2); -xmlLocationSetPtr -xmlXPtrLocationSetMerge(xmlLocationSetPtr val1 ATTRIBUTE_UNUSED, - xmlLocationSetPtr val2 ATTRIBUTE_UNUSED) { +void * +xmlXPtrLocationSetMerge(void *val1 ATTRIBUTE_UNUSED, + void *val2 ATTRIBUTE_UNUSED) { return(NULL); } XMLPUBFUN void -xmlXPtrLocationSetDel(xmlLocationSetPtr cur, xmlXPathObjectPtr val); +xmlXPtrLocationSetDel(void *cur, void *val); void -xmlXPtrLocationSetDel(xmlLocationSetPtr cur ATTRIBUTE_UNUSED, - xmlXPathObjectPtr val ATTRIBUTE_UNUSED) { +xmlXPtrLocationSetDel(void *cur ATTRIBUTE_UNUSED, + void *val ATTRIBUTE_UNUSED) { } XMLPUBFUN void -xmlXPtrLocationSetRemove(xmlLocationSetPtr cur, int val); +xmlXPtrLocationSetRemove(void *cur, int val); void -xmlXPtrLocationSetRemove(xmlLocationSetPtr cur ATTRIBUTE_UNUSED, +xmlXPtrLocationSetRemove(void *cur ATTRIBUTE_UNUSED, int val ATTRIBUTE_UNUSED) { } XMLPUBFUN void -xmlXPtrFreeLocationSet(xmlLocationSetPtr obj); +xmlXPtrFreeLocationSet(void *obj); void -xmlXPtrFreeLocationSet(xmlLocationSetPtr obj ATTRIBUTE_UNUSED) { +xmlXPtrFreeLocationSet(void *obj ATTRIBUTE_UNUSED) { } -XMLPUBFUN xmlXPathObjectPtr -xmlXPtrNewLocationSetNodes(xmlNodePtr start, xmlNodePtr end); +XMLPUBFUN void * +xmlXPtrNewLocationSetNodes(void *start, void *end); -xmlXPathObjectPtr -xmlXPtrNewLocationSetNodes(xmlNodePtr start ATTRIBUTE_UNUSED, - xmlNodePtr end ATTRIBUTE_UNUSED) { +void * +xmlXPtrNewLocationSetNodes(void *start ATTRIBUTE_UNUSED, + void *end ATTRIBUTE_UNUSED) { return(NULL); } -XMLPUBFUN xmlXPathObjectPtr -xmlXPtrNewLocationSetNodeSet(xmlNodeSetPtr set); +XMLPUBFUN void * +xmlXPtrNewLocationSetNodeSet(void *set); -xmlXPathObjectPtr -xmlXPtrNewLocationSetNodeSet(xmlNodeSetPtr set ATTRIBUTE_UNUSED) { +void * +xmlXPtrNewLocationSetNodeSet(void *set ATTRIBUTE_UNUSED) { return(NULL); } -XMLPUBFUN xmlXPathObjectPtr -xmlXPtrWrapLocationSet(xmlLocationSetPtr val); +XMLPUBFUN void * +xmlXPtrWrapLocationSet(void *val); -xmlXPathObjectPtr -xmlXPtrWrapLocationSet(xmlLocationSetPtr val ATTRIBUTE_UNUSED) { +void * +xmlXPtrWrapLocationSet(void *val ATTRIBUTE_UNUSED) { return(NULL); } -XMLPUBFUN xmlNodePtr -xmlXPtrBuildNodeList(xmlXPathObjectPtr obj); +XMLPUBFUN void * +xmlXPtrBuildNodeList(void *obj); -xmlNodePtr -xmlXPtrBuildNodeList(xmlXPathObjectPtr obj ATTRIBUTE_UNUSED) { +void * +xmlXPtrBuildNodeList(void *obj ATTRIBUTE_UNUSED) { return(NULL); } XMLPUBFUN void -xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt, int nargs); +xmlXPtrRangeToFunction(void *ctxt, int nargs); void -xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt, +xmlXPtrRangeToFunction(void *ctxt ATTRIBUTE_UNUSED, int nargs ATTRIBUTE_UNUSED) { - XP_ERROR(XPATH_EXPR_ERROR); } /** DOC_ENABLE */ -#endif /* #ifndef LIBXML_XPTR_LOCS_ENABLED */ - #endif /* LIBXML_LEGACY_ENABLED */ diff --git a/meson.build b/meson.build index 6bbb45a7..5d2622f7 100644 --- a/meson.build +++ b/meson.build @@ -80,7 +80,6 @@ want_writer = get_option('writer') want_xinclude = get_option('xinclude') want_xpath = get_option('xpath') want_xptr = get_option('xptr') -want_xptr_locs = get_option('xptr-locs') # TODO: Options should be three-valued: "yes", "no", default @@ -154,13 +153,6 @@ if want_xinclude == true want_xpath = true endif -if want_xptr_locs == true - if want_xptr == false - message('-Dxptr-locs=true overrides -Dxptr') - endif - want_xptr = true -endif - if want_xptr == true if want_xpath == false message('-Dxptr=true overrides -Dxpath') @@ -197,7 +189,6 @@ if get_option('minimum') want_xinclude = false want_xpath = false want_xptr = false - want_xptr_locs = false else # Disable dependent modules if want_output == false @@ -833,7 +824,6 @@ summary( 'xinclude': want_xinclude, 'xpath': want_xpath, 'xptr': want_xptr, - 'xptr-locs': want_xptr_locs, 'zlib': zlib_dep.found(), }, section: 'Configuration Options Summary:', diff --git a/meson_options.txt b/meson_options.txt index 92979127..c45fbbe9 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -32,7 +32,6 @@ # [X] xinclude # [X] xpath # [X] xptr -# [X] xptr-locs # [X] zlib # [X] minimum @@ -228,12 +227,6 @@ option('xptr', description: 'XPointer support' ) -option('xptr-locs', - type: 'boolean', - value: false, - description: 'XPointer ranges and points' -) - option('zlib', type: 'feature', description: 'ZLIB support' diff --git a/python/generator.py b/python/generator.py index 149e0dfe..1b20ae99 100755 --- a/python/generator.py +++ b/python/generator.py @@ -414,6 +414,7 @@ deprecated_funcs = { 'xmlXPathInit': True, 'xmlXPtrEvalRangePredicate': True, 'xmlXPtrNewCollapsedRange': True, + 'xmlXPtrNewContext': True, 'xmlXPtrNewLocationSetNodes': True, 'xmlXPtrNewRange': True, 'xmlXPtrNewRangeNodes': True, diff --git a/python/types.c b/python/types.c index 480c925b..664e9550 100644 --- a/python/types.c +++ b/python/types.c @@ -558,109 +558,6 @@ libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj) case XPATH_STRING: ret = PY_IMPORT_STRING((char *) obj->stringval); break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - { - PyObject *node; - PyObject *indexIntoNode; - PyObject *tuple; - - node = libxml_xmlNodePtrWrap(obj->user); - indexIntoNode = PY_IMPORT_INT((long) obj->index); - - tuple = PyTuple_New(2); - PyTuple_SetItem(tuple, 0, node); - PyTuple_SetItem(tuple, 1, indexIntoNode); - - ret = tuple; - break; - } - case XPATH_RANGE: - { - unsigned short bCollapsedRange; - - bCollapsedRange = ( (obj->user2 == NULL) || - ((obj->user2 == obj->user) && (obj->index == obj->index2)) ); - if ( bCollapsedRange ) { - PyObject *node; - PyObject *indexIntoNode; - PyObject *tuple; - PyObject *list; - - list = PyList_New(1); - - node = libxml_xmlNodePtrWrap(obj->user); - indexIntoNode = PY_IMPORT_INT((long) obj->index); - - tuple = PyTuple_New(2); - PyTuple_SetItem(tuple, 0, node); - PyTuple_SetItem(tuple, 1, indexIntoNode); - - PyList_SetItem(list, 0, tuple); - - ret = list; - } else { - PyObject *node; - PyObject *indexIntoNode; - PyObject *tuple; - PyObject *list; - - list = PyList_New(2); - - node = libxml_xmlNodePtrWrap(obj->user); - indexIntoNode = PY_IMPORT_INT((long) obj->index); - - tuple = PyTuple_New(2); - PyTuple_SetItem(tuple, 0, node); - PyTuple_SetItem(tuple, 1, indexIntoNode); - - PyList_SetItem(list, 0, tuple); - - node = libxml_xmlNodePtrWrap(obj->user2); - indexIntoNode = PY_IMPORT_INT((long) obj->index2); - - tuple = PyTuple_New(2); - PyTuple_SetItem(tuple, 0, node); - PyTuple_SetItem(tuple, 1, indexIntoNode); - - PyList_SetItem(list, 1, tuple); - - ret = list; - } - break; - } - case XPATH_LOCATIONSET: - { - xmlLocationSetPtr set; - - set = obj->user; - if ( set && set->locNr > 0 ) { - int i; - PyObject *list; - - list = PyList_New(set->locNr); - - for (i=0; ilocNr; i++) { - xmlXPathObjectPtr setobj; - PyObject *pyobj; - - setobj = set->locTab[i]; /*xmlXPathObjectPtr setobj*/ - - pyobj = libxml_xmlXPathObjectPtrWrap(setobj); - /* xmlXPathFreeObject(setobj) is called */ - set->locTab[i] = NULL; - - PyList_SetItem(list, i, pyobj); - } - set->locNr = 0; - ret = list; - } else { - Py_INCREF(Py_None); - ret = Py_None; - } - break; - } -#endif /* LIBXML_XPTR_LOCS_ENABLED */ default: Py_INCREF(Py_None); ret = Py_None; diff --git a/result/XPath/xptr-xp1/chaptersparts b/result/XPath/xptr-xp1/chaptersparts deleted file mode 100644 index 83e0569b..00000000 --- a/result/XPath/xptr-xp1/chaptersparts +++ /dev/null @@ -1,44 +0,0 @@ - -======================== -Expression: xpath1(//chapitre[2]) -Object is empty (NULL) - -======================== -Expression: xpath1(//chapter[2]) -Object is a Node Set : -Set contains 1 nodes: -1 ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter2 - -======================== -Expression: xpath1(//chapitre[2])xpath1(//chapter[2]) -Object is a Node Set : -Set contains 1 nodes: -1 ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter2 - -======================== -Expression: xpath1(id("chapter1")) -Object is empty (NULL) - -======================== -Expression: xpath1(//*[@id="chapter1"]) -Object is a Node Set : -Set contains 1 nodes: -1 ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter1 - -======================== -Expression: xpath1(id("chapter1"))xpath1(//*[@id="chapter1"]) -Object is a Node Set : -Set contains 1 nodes: -1 ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter1 diff --git a/result/XPath/xptr-xp1/issue289base b/result/XPath/xptr-xp1/issue289base deleted file mode 100644 index ffae7e80..00000000 --- a/result/XPath/xptr-xp1/issue289base +++ /dev/null @@ -1,7 +0,0 @@ - -======================== -Expression: xmlns(b=abc://d/e:f) xpath1(/b:rootB) -Object is a Node Set : -Set contains 1 nodes: -1 ELEMENT rootB - default namespace href=abc://d/e:f diff --git a/result/XPath/xptr-xp1/vidbase b/result/XPath/xptr-xp1/vidbase deleted file mode 100644 index a5447b05..00000000 --- a/result/XPath/xptr-xp1/vidbase +++ /dev/null @@ -1,9 +0,0 @@ - -======================== -Expression: xpath1(id('chapter1')/p) -Object is a Node Set : -Set contains 4 nodes: -1 ELEMENT p -2 ELEMENT p -3 ELEMENT p -4 ELEMENT p diff --git a/result/XPath/xptr-xp1/viderror b/result/XPath/xptr-xp1/viderror deleted file mode 100644 index 562cab4a..00000000 --- a/result/XPath/xptr-xp1/viderror +++ /dev/null @@ -1,4 +0,0 @@ - -======================== -Expression: xpath1(non-existing-fn()) -Object is empty (NULL) diff --git a/result/XPath/xptr-xp1/vidparts b/result/XPath/xptr-xp1/vidparts deleted file mode 100644 index 918a08f0..00000000 --- a/result/XPath/xptr-xp1/vidparts +++ /dev/null @@ -1,27 +0,0 @@ - -======================== -Expression: xpath1(id("chapter1")) -Object is a Node Set : -Set contains 1 nodes: -1 ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter1 - -======================== -Expression: xpath1(//*[@id="chapter1"]) -Object is a Node Set : -Set contains 1 nodes: -1 ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter1 - -======================== -Expression: xpath1(id("chapter1"))xpath1(//*[@id="chapter1"]) -Object is a Node Set : -Set contains 1 nodes: -1 ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter1 diff --git a/result/XPath/xptr-xp1/chapterschildseq b/result/XPath/xptr/chapterschildseq similarity index 100% rename from result/XPath/xptr-xp1/chapterschildseq rename to result/XPath/xptr/chapterschildseq diff --git a/result/XPath/xptr/chaptersparts b/result/XPath/xptr/chaptersparts index 70b561b3..83e0569b 100644 --- a/result/XPath/xptr/chaptersparts +++ b/result/XPath/xptr/chaptersparts @@ -1,10 +1,10 @@ ======================== -Expression: xpointer(//chapitre[2]) +Expression: xpath1(//chapitre[2]) Object is empty (NULL) ======================== -Expression: xpointer(//chapter[2]) +Expression: xpath1(//chapter[2]) Object is a Node Set : Set contains 1 nodes: 1 ELEMENT chapter @@ -13,7 +13,7 @@ Set contains 1 nodes: content=chapter2 ======================== -Expression: xpointer(//chapitre[2])xpointer(//chapter[2]) +Expression: xpath1(//chapitre[2])xpath1(//chapter[2]) Object is a Node Set : Set contains 1 nodes: 1 ELEMENT chapter @@ -22,11 +22,11 @@ Set contains 1 nodes: content=chapter2 ======================== -Expression: xpointer(id("chapter1")) +Expression: xpath1(id("chapter1")) Object is empty (NULL) ======================== -Expression: xpointer(//*[@id="chapter1"]) +Expression: xpath1(//*[@id="chapter1"]) Object is a Node Set : Set contains 1 nodes: 1 ELEMENT chapter @@ -35,7 +35,7 @@ Set contains 1 nodes: content=chapter1 ======================== -Expression: xpointer(id("chapter1"))xpointer(//*[@id="chapter1"]) +Expression: xpath1(id("chapter1"))xpath1(//*[@id="chapter1"]) Object is a Node Set : Set contains 1 nodes: 1 ELEMENT chapter diff --git a/result/XPath/xptr/chaptersrange b/result/XPath/xptr/chaptersrange deleted file mode 100644 index c1b9cde0..00000000 --- a/result/XPath/xptr/chaptersrange +++ /dev/null @@ -1,64 +0,0 @@ - -======================== -Expression: xpointer(//chapter[position() = 2]/range-to(following::chapter[1])) -Object is a Location Set: -1 : Object is a range : - From node - ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter2 - To node - ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter3 - - -======================== -Expression: xpointer(//chapter[position() <= 2]/range-to(following::chapter[1])) -Object is a Location Set: -1 : Object is a range : - From node - ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter1 - To node - ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter2 - -2 : Object is a range : - From node - ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter2 - To node - ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter3 - - -======================== -Expression: xpointer(//chapter[position() = last()]/range-to(following::chapter[1])) -Object is empty (NULL) - -======================== -Expression: xpointer(//chapter[position() = 3]/range-to(/.//chapter[position() = 1])) -Object is a Location Set: -1 : Object is a range : - From node - ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter1 - To node - ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter3 - diff --git a/result/XPath/xptr/issue289base b/result/XPath/xptr/issue289base index ec56aef2..ffae7e80 100644 --- a/result/XPath/xptr/issue289base +++ b/result/XPath/xptr/issue289base @@ -1,6 +1,6 @@ ======================== -Expression: xmlns(b=abc://d/e:f) xpointer(/b:rootB) +Expression: xmlns(b=abc://d/e:f) xpath1(/b:rootB) Object is a Node Set : Set contains 1 nodes: 1 ELEMENT rootB diff --git a/result/XPath/xptr/strpoint b/result/XPath/xptr/strpoint deleted file mode 100644 index d6ecab39..00000000 --- a/result/XPath/xptr/strpoint +++ /dev/null @@ -1,75 +0,0 @@ - -======================== -Expression: xpointer(start-point(string-range(//p,'multiple'))) -Object is a Location Set: -1 : Object is a point : index 1 in node TEXT - content=multiple tests - - -======================== -Expression: xpointer(end-point(string-range(//p,'multiple'))) -Object is a Location Set: -1 : Object is a point : index 8 in node TEXT - content=multiple tests - - -======================== -Expression: xpointer(start-point(string-range(//p,'test'))) -Object is a Location Set: -1 : Object is a point : index 10 in node TEXT - content=a simple test - -2 : Object is a point : index 10 in node TEXT - content=multiple tests - -3 : Object is a point : index 7 in node TEXT - content=anced test - - -======================== -Expression: xpointer(end-point(string-range(//p,'test'))) -Object is a Location Set: -1 : Object is a point : index 13 in node TEXT - content=a simple test - -2 : Object is a point : index 13 in node TEXT - content=multiple tests - -3 : Object is a point : index 10 in node TEXT - content=anced test - - -======================== -Expression: xpointer(start-point(string-range(//*,'multiple',1,0))) -Object is a Location Set: -1 : Object is a point : index 1 in node TEXT - content=multiple tests - - -======================== -Expression: xpointer(end-point(string-range(//*,'multiple',1,0))) -Object is a Location Set: -1 : Object is a point : index 1 in node TEXT - content=multiple tests - - -======================== -Expression: xpointer(start-point(string-range(//*,'multiple',1,1))) -Object is a Location Set: -1 : Object is a point : index 1 in node TEXT - content=multiple tests - - -======================== -Expression: xpointer(end-point(string-range(//*,'multiple',1,1))) -Object is a Location Set: -1 : Object is a point : index 2 in node TEXT - content=multiple tests - - -======================== -Expression: xpointer(start-point(string-range(//p,'test'))[1]) -Object is a Location Set: -1 : Object is a point : index 10 in node TEXT - content=a simple test - diff --git a/result/XPath/xptr/strrange b/result/XPath/xptr/strrange deleted file mode 100644 index c14ed917..00000000 --- a/result/XPath/xptr/strrange +++ /dev/null @@ -1,96 +0,0 @@ - -======================== -Expression: xpointer(string-range(//p, 'simple')) -Object is a Location Set: -1 : Object is a range : - From index 3 in node - TEXT - content=a simple test - To index 8 in node - TEXT - content=a simple test - - -======================== -Expression: xpointer(string-range(//p, 'test')) -Object is a Location Set: -1 : Object is a range : - From index 10 in node - TEXT - content=a simple test - To index 13 in node - TEXT - content=a simple test - -2 : Object is a range : - From index 10 in node - TEXT - content=multiple tests - To index 13 in node - TEXT - content=multiple tests - -3 : Object is a range : - From index 7 in node - TEXT - content=anced test - To index 10 in node - TEXT - content=anced test - - -======================== -Expression: xpointer(string-range(//p, 'difficult')) -Object is a Location Set: -1 : Object is a range : - From index 3 in node - TEXT - content=a diff - To index 4 in node - TEXT - content=cult one - - -======================== -Expression: xpointer(string-range(//p, 'spanning')) -Object is a Location Set: -1 : Object is a range : - From index 3 in node - TEXT - content=a span - To index 3 in node - TEXT - content=ing one - - -======================== -Expression: xpointer(string-range(//p, 'unbalanced')) -Object is a Location Set: -1 : Object is a range : - From index 8 in node - TEXT - content=and an unbal - To index 5 in node - TEXT - content=anced test - - -======================== -Expression: xpointer(string-range(//seq, '')) -Object is a Location Set: -1 : Object is a collapsed range : - index 1 in node - TEXT - content=123 -2 : Object is a collapsed range : - index 2 in node - TEXT - content=123 -3 : Object is a collapsed range : - index 3 in node - TEXT - content=123 -4 : Object is a collapsed range : - index 4 in node - TEXT - content=123 diff --git a/result/XPath/xptr/strrange2 b/result/XPath/xptr/strrange2 deleted file mode 100644 index ea6ee45a..00000000 --- a/result/XPath/xptr/strrange2 +++ /dev/null @@ -1,64 +0,0 @@ - -======================== -Expression: xpointer(string-range(//p, 'test', 2)) -Object is a Location Set: -1 : Object is a range : - From index 11 in node - TEXT - content=a simple test - To index 13 in node - TEXT - content=a simple test - -2 : Object is a range : - From index 11 in node - TEXT - content=multiple tests - To index 13 in node - TEXT - content=multiple tests - -3 : Object is a range : - From index 8 in node - TEXT - content=anced test - To index 10 in node - TEXT - content=anced test - - -======================== -Expression: xpointer(string-range(//p, 'test', 2, 2)) -Object is a Location Set: -1 : Object is a range : - From index 11 in node - TEXT - content=a simple test - To index 12 in node - TEXT - content=a simple test - -2 : Object is a range : - From index 11 in node - TEXT - content=multiple tests - To index 12 in node - TEXT - content=multiple tests - -3 : Object is a range : - From index 8 in node - TEXT - content=anced test - To index 9 in node - TEXT - content=anced test - - -======================== -Expression: xpointer(string-range(//p, 'difficult', 1, 0)) -Object is a Location Set: -1 : Object is a collapsed range : - index 3 in node - TEXT - content=a diff diff --git a/result/XPath/xptr/strrange3 b/result/XPath/xptr/strrange3 deleted file mode 100644 index 6d3114a8..00000000 --- a/result/XPath/xptr/strrange3 +++ /dev/null @@ -1,48 +0,0 @@ - -======================== -Expression: xpointer(string-range(//p, 'test', 1, 0)) -Object is a Location Set: -1 : Object is a collapsed range : - index 10 in node - TEXT - content=a simple test -2 : Object is a collapsed range : - index 10 in node - TEXT - content=multiple tests -3 : Object is a collapsed range : - index 7 in node - TEXT - content=anced test - -======================== -Expression: xpointer(string-range(//*, 'test', 1, 0)) -Object is a Location Set: -1 : Object is a collapsed range : - index 10 in node - TEXT - content=a simple test -2 : Object is a collapsed range : - index 10 in node - TEXT - content=multiple tests -3 : Object is a collapsed range : - index 7 in node - TEXT - content=anced test - -======================== -Expression: xpointer(string-range(//p, 'test', 1, 0)[2]) -Object is a Location Set: -1 : Object is a collapsed range : - index 10 in node - TEXT - content=multiple tests - -======================== -Expression: xpointer(string-range(//*, 'test', 1, 0)[2]) -Object is a Location Set: -1 : Object is a collapsed range : - index 10 in node - TEXT - content=multiple tests diff --git a/result/XPath/xptr/vidbase b/result/XPath/xptr/vidbase index f19193e7..a5447b05 100644 --- a/result/XPath/xptr/vidbase +++ b/result/XPath/xptr/vidbase @@ -1,32 +1,9 @@ ======================== -Expression: xpointer(id('chapter1')/p) +Expression: xpath1(id('chapter1')/p) Object is a Node Set : Set contains 4 nodes: 1 ELEMENT p 2 ELEMENT p 3 ELEMENT p 4 ELEMENT p - -======================== -Expression: xpointer(id('chapter1')/p[1]/range-to(following-sibling::p[2])) -Object is a Location Set: -1 : Object is a range : - From node - ELEMENT p - To node - ELEMENT p - - -======================== -Expression: xpointer(range-to(id('chapter2'))) -Object is a Location Set: -1 : Object is a range : - From node - / - To node - ELEMENT chapter - ATTRIBUTE id - TEXT - content=chapter2 - diff --git a/result/XPath/xptr-xp1/vidchildseq b/result/XPath/xptr/vidchildseq similarity index 100% rename from result/XPath/xptr-xp1/vidchildseq rename to result/XPath/xptr/vidchildseq diff --git a/result/XPath/xptr/viderror b/result/XPath/xptr/viderror index d589882d..562cab4a 100644 --- a/result/XPath/xptr/viderror +++ b/result/XPath/xptr/viderror @@ -1,4 +1,4 @@ ======================== -Expression: xpointer(non-existing-fn()/range-to(id('chapter2'))) +Expression: xpath1(non-existing-fn()) Object is empty (NULL) diff --git a/result/XPath/xptr/vidparts b/result/XPath/xptr/vidparts index bd5bd3c1..918a08f0 100644 --- a/result/XPath/xptr/vidparts +++ b/result/XPath/xptr/vidparts @@ -1,6 +1,6 @@ ======================== -Expression: xpointer(id("chapter1")) +Expression: xpath1(id("chapter1")) Object is a Node Set : Set contains 1 nodes: 1 ELEMENT chapter @@ -9,7 +9,7 @@ Set contains 1 nodes: content=chapter1 ======================== -Expression: xpointer(//*[@id="chapter1"]) +Expression: xpath1(//*[@id="chapter1"]) Object is a Node Set : Set contains 1 nodes: 1 ELEMENT chapter @@ -18,7 +18,7 @@ Set contains 1 nodes: content=chapter1 ======================== -Expression: xpointer(id("chapter1"))xpointer(//*[@id="chapter1"]) +Expression: xpath1(id("chapter1"))xpath1(//*[@id="chapter1"]) Object is a Node Set : Set contains 1 nodes: 1 ELEMENT chapter diff --git a/runtest.c b/runtest.c index ae04d34c..c66be092 100644 --- a/runtest.c +++ b/runtest.c @@ -2532,7 +2532,7 @@ testXPath(const char *str, int xptr, int expr) { nb_tests++; #if defined(LIBXML_XPTR_ENABLED) if (xptr) { - ctxt = xmlXPtrNewContext(xpathDocument, NULL, NULL); + ctxt = xmlXPathNewContext(xpathDocument); xmlXPathSetErrorHandler(ctxt, testStructuredErrorHandler, NULL); res = xmlXPtrEval(BAD_CAST str, ctxt); } else { @@ -2713,14 +2713,13 @@ static int xptrDocTest(const char *filename, const char *resul ATTRIBUTE_UNUSED, const char *err ATTRIBUTE_UNUSED, - int options) { + int options ATTRIBUTE_UNUSED) { char pattern[500]; char result[500]; glob_t globbuf; size_t i; int ret = 0, res; - const char *subdir = options == -1 ? "xptr-xp1" : "xptr"; xpathDocument = xmlReadFile(filename, NULL, XML_PARSE_DTDATTR | XML_PARSE_NOENT); @@ -2729,15 +2728,15 @@ xptrDocTest(const char *filename, return(-1); } - res = snprintf(pattern, 499, "./test/XPath/%s/%s*", - subdir, baseFilename(filename)); + res = snprintf(pattern, 499, "./test/XPath/xptr/%s*", + baseFilename(filename)); if (res >= 499) pattern[499] = 0; globbuf.gl_offs = 0; glob(pattern, GLOB_DOOFFS, NULL, &globbuf); for (i = 0;i < globbuf.gl_pathc;i++) { - res = snprintf(result, 499, "result/XPath/%s/%s", - subdir, baseFilename(globbuf.gl_pathv[i])); + res = snprintf(result, 499, "result/XPath/xptr/%s", + baseFilename(globbuf.gl_pathv[i])); if (res >= 499) result[499] = 0; res = xpathCommonTest(globbuf.gl_pathv[i], &result[0], 1, 0); @@ -4834,11 +4833,6 @@ testDesc testDescriptions[] = { 0 }, #ifdef LIBXML_XPTR_ENABLED { "XPointer document queries regression tests" , - xptrDocTest, "./test/XPath/docs/*", NULL, NULL, NULL, - -1 }, -#endif -#ifdef LIBXML_XPTR_LOCS_ENABLED - { "XPointer xpointer() queries regression tests" , xptrDocTest, "./test/XPath/docs/*", NULL, NULL, NULL, 0 }, #endif diff --git a/schematron.c b/schematron.c index 1de25deb..d5e81ecf 100644 --- a/schematron.c +++ b/schematron.c @@ -1864,11 +1864,6 @@ xmlSchematronRunTest(xmlSchematronValidCtxtPtr ctxt, failed = 1; break; case XPATH_UNDEFINED: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif case XPATH_USERS: failed = 1; break; diff --git a/test/XPath/xptr-xp1/chaptersparts b/test/XPath/xptr-xp1/chaptersparts deleted file mode 100644 index 8b203576..00000000 --- a/test/XPath/xptr-xp1/chaptersparts +++ /dev/null @@ -1,6 +0,0 @@ -xpath1(//chapitre[2]) -xpath1(//chapter[2]) -xpath1(//chapitre[2])xpath1(//chapter[2]) -xpath1(id("chapter1")) -xpath1(//*[@id="chapter1"]) -xpath1(id("chapter1"))xpath1(//*[@id="chapter1"]) diff --git a/test/XPath/xptr-xp1/issue289base b/test/XPath/xptr-xp1/issue289base deleted file mode 100644 index 59379ef3..00000000 --- a/test/XPath/xptr-xp1/issue289base +++ /dev/null @@ -1 +0,0 @@ -xmlns(b=abc://d/e:f) xpath1(/b:rootB) diff --git a/test/XPath/xptr-xp1/vidbase b/test/XPath/xptr-xp1/vidbase deleted file mode 100644 index 82e098b6..00000000 --- a/test/XPath/xptr-xp1/vidbase +++ /dev/null @@ -1 +0,0 @@ -xpath1(id('chapter1')/p) diff --git a/test/XPath/xptr-xp1/viderror b/test/XPath/xptr-xp1/viderror deleted file mode 100644 index 104e57f1..00000000 --- a/test/XPath/xptr-xp1/viderror +++ /dev/null @@ -1 +0,0 @@ -xpath1(non-existing-fn()) diff --git a/test/XPath/xptr-xp1/vidparts b/test/XPath/xptr-xp1/vidparts deleted file mode 100644 index bbf61768..00000000 --- a/test/XPath/xptr-xp1/vidparts +++ /dev/null @@ -1,3 +0,0 @@ -xpath1(id("chapter1")) -xpath1(//*[@id="chapter1"]) -xpath1(id("chapter1"))xpath1(//*[@id="chapter1"]) diff --git a/test/XPath/xptr-xp1/chapterschildseq b/test/XPath/xptr/chapterschildseq similarity index 100% rename from test/XPath/xptr-xp1/chapterschildseq rename to test/XPath/xptr/chapterschildseq diff --git a/test/XPath/xptr/chaptersparts b/test/XPath/xptr/chaptersparts index aadc47c1..8b203576 100644 --- a/test/XPath/xptr/chaptersparts +++ b/test/XPath/xptr/chaptersparts @@ -1,6 +1,6 @@ -xpointer(//chapitre[2]) -xpointer(//chapter[2]) -xpointer(//chapitre[2])xpointer(//chapter[2]) -xpointer(id("chapter1")) -xpointer(//*[@id="chapter1"]) -xpointer(id("chapter1"))xpointer(//*[@id="chapter1"]) +xpath1(//chapitre[2]) +xpath1(//chapter[2]) +xpath1(//chapitre[2])xpath1(//chapter[2]) +xpath1(id("chapter1")) +xpath1(//*[@id="chapter1"]) +xpath1(id("chapter1"))xpath1(//*[@id="chapter1"]) diff --git a/test/XPath/xptr/chaptersrange b/test/XPath/xptr/chaptersrange deleted file mode 100644 index 4d7a55b4..00000000 --- a/test/XPath/xptr/chaptersrange +++ /dev/null @@ -1,4 +0,0 @@ -xpointer(//chapter[position() = 2]/range-to(following::chapter[1])) -xpointer(//chapter[position() <= 2]/range-to(following::chapter[1])) -xpointer(//chapter[position() = last()]/range-to(following::chapter[1])) -xpointer(//chapter[position() = 3]/range-to(/.//chapter[position() = 1])) diff --git a/test/XPath/xptr/issue289base b/test/XPath/xptr/issue289base index 716a92fd..59379ef3 100644 --- a/test/XPath/xptr/issue289base +++ b/test/XPath/xptr/issue289base @@ -1 +1 @@ -xmlns(b=abc://d/e:f) xpointer(/b:rootB) +xmlns(b=abc://d/e:f) xpath1(/b:rootB) diff --git a/test/XPath/xptr/strpoint b/test/XPath/xptr/strpoint deleted file mode 100644 index 0916ef10..00000000 --- a/test/XPath/xptr/strpoint +++ /dev/null @@ -1,9 +0,0 @@ -xpointer(start-point(string-range(//p,'multiple'))) -xpointer(end-point(string-range(//p,'multiple'))) -xpointer(start-point(string-range(//p,'test'))) -xpointer(end-point(string-range(//p,'test'))) -xpointer(start-point(string-range(//*,'multiple',1,0))) -xpointer(end-point(string-range(//*,'multiple',1,0))) -xpointer(start-point(string-range(//*,'multiple',1,1))) -xpointer(end-point(string-range(//*,'multiple',1,1))) -xpointer(start-point(string-range(//p,'test'))[1]) diff --git a/test/XPath/xptr/strrange b/test/XPath/xptr/strrange deleted file mode 100644 index 32319273..00000000 --- a/test/XPath/xptr/strrange +++ /dev/null @@ -1,6 +0,0 @@ -xpointer(string-range(//p, 'simple')) -xpointer(string-range(//p, 'test')) -xpointer(string-range(//p, 'difficult')) -xpointer(string-range(//p, 'spanning')) -xpointer(string-range(//p, 'unbalanced')) -xpointer(string-range(//seq, '')) diff --git a/test/XPath/xptr/strrange2 b/test/XPath/xptr/strrange2 deleted file mode 100644 index 51335470..00000000 --- a/test/XPath/xptr/strrange2 +++ /dev/null @@ -1,3 +0,0 @@ -xpointer(string-range(//p, 'test', 2)) -xpointer(string-range(//p, 'test', 2, 2)) -xpointer(string-range(//p, 'difficult', 1, 0)) diff --git a/test/XPath/xptr/strrange3 b/test/XPath/xptr/strrange3 deleted file mode 100644 index aea56652..00000000 --- a/test/XPath/xptr/strrange3 +++ /dev/null @@ -1,4 +0,0 @@ -xpointer(string-range(//p, 'test', 1, 0)) -xpointer(string-range(//*, 'test', 1, 0)) -xpointer(string-range(//p, 'test', 1, 0)[2]) -xpointer(string-range(//*, 'test', 1, 0)[2]) diff --git a/test/XPath/xptr/vidbase b/test/XPath/xptr/vidbase index 884b1065..82e098b6 100644 --- a/test/XPath/xptr/vidbase +++ b/test/XPath/xptr/vidbase @@ -1,3 +1 @@ -xpointer(id('chapter1')/p) -xpointer(id('chapter1')/p[1]/range-to(following-sibling::p[2])) -xpointer(range-to(id('chapter2'))) +xpath1(id('chapter1')/p) diff --git a/test/XPath/xptr-xp1/vidchildseq b/test/XPath/xptr/vidchildseq similarity index 100% rename from test/XPath/xptr-xp1/vidchildseq rename to test/XPath/xptr/vidchildseq diff --git a/test/XPath/xptr/viderror b/test/XPath/xptr/viderror index da8c53b2..104e57f1 100644 --- a/test/XPath/xptr/viderror +++ b/test/XPath/xptr/viderror @@ -1 +1 @@ -xpointer(non-existing-fn()/range-to(id('chapter2'))) +xpath1(non-existing-fn()) diff --git a/test/XPath/xptr/vidparts b/test/XPath/xptr/vidparts index 3afbbdde..bbf61768 100644 --- a/test/XPath/xptr/vidparts +++ b/test/XPath/xptr/vidparts @@ -1,3 +1,3 @@ -xpointer(id("chapter1")) -xpointer(//*[@id="chapter1"]) -xpointer(id("chapter1"))xpointer(//*[@id="chapter1"]) +xpath1(id("chapter1")) +xpath1(//*[@id="chapter1"]) +xpath1(id("chapter1"))xpath1(//*[@id="chapter1"]) diff --git a/testapi.c b/testapi.c index 3b1192a4..72a29597 100644 --- a/testapi.c +++ b/testapi.c @@ -52072,40 +52072,6 @@ test_xpathInternals(void) { return(test_ret); } -static int -test_xmlXPtrBuildNodeList(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlNodePtr ret_val; - xmlXPathObjectPtr obj; /* the XPointer result from the evaluation. */ - int n_obj; - - for (n_obj = 0;n_obj < gen_nb_xmlXPathObjectPtr;n_obj++) { - mem_base = xmlMemBlocks(); - obj = gen_xmlXPathObjectPtr(n_obj, 0); - - ret_val = xmlXPtrBuildNodeList(obj); - desret_xmlNodePtr(ret_val); - call_tests++; - des_xmlXPathObjectPtr(n_obj, obj, 0); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrBuildNodeList", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_obj); - printf("\n"); - } - } - function_tests++; -#endif - - return(test_ret); -} - - static int test_xmlXPtrEval(void) { int test_ret = 0; @@ -52147,72 +52113,6 @@ test_xmlXPtrEval(void) { } -static int -test_xmlXPtrEvalRangePredicate(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathParserContextPtr ctxt; /* the XPointer Parser context */ - int n_ctxt; - - for (n_ctxt = 0;n_ctxt < gen_nb_xmlXPathParserContextPtr;n_ctxt++) { - mem_base = xmlMemBlocks(); - ctxt = gen_xmlXPathParserContextPtr(n_ctxt, 0); - - xmlXPtrEvalRangePredicate(ctxt); - call_tests++; - des_xmlXPathParserContextPtr(n_ctxt, ctxt, 0); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrEvalRangePredicate", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_ctxt); - printf("\n"); - } - } - function_tests++; -#endif - - return(test_ret); -} - - -static int -test_xmlXPtrNewCollapsedRange(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathObjectPtr ret_val; - xmlNodePtr start; /* the starting and ending node */ - int n_start; - - for (n_start = 0;n_start < gen_nb_xmlNodePtr;n_start++) { - mem_base = xmlMemBlocks(); - start = gen_xmlNodePtr(n_start, 0); - - ret_val = xmlXPtrNewCollapsedRange(start); - desret_xmlXPathObjectPtr(ret_val); - call_tests++; - des_xmlNodePtr(n_start, start, 0); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrNewCollapsedRange", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_start); - printf("\n"); - } - } - function_tests++; -#endif - - return(test_ret); -} - - static int test_xmlXPtrNewContext(void) { int test_ret = 0; @@ -52222,399 +52122,13 @@ test_xmlXPtrNewContext(void) { return(test_ret); } - -static int -test_xmlXPtrNewLocationSetNodeSet(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathObjectPtr ret_val; - xmlNodeSetPtr set; /* a node set */ - int n_set; - - for (n_set = 0;n_set < gen_nb_xmlNodeSetPtr;n_set++) { - mem_base = xmlMemBlocks(); - set = gen_xmlNodeSetPtr(n_set, 0); - - ret_val = xmlXPtrNewLocationSetNodeSet(set); - desret_xmlXPathObjectPtr(ret_val); - call_tests++; - des_xmlNodeSetPtr(n_set, set, 0); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrNewLocationSetNodeSet", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_set); - printf("\n"); - } - } - function_tests++; -#endif - - return(test_ret); -} - - -static int -test_xmlXPtrNewLocationSetNodes(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathObjectPtr ret_val; - xmlNodePtr start; /* the start NodePtr value */ - int n_start; - xmlNodePtr end; /* the end NodePtr value or NULL */ - int n_end; - - for (n_start = 0;n_start < gen_nb_xmlNodePtr;n_start++) { - for (n_end = 0;n_end < gen_nb_xmlNodePtr;n_end++) { - mem_base = xmlMemBlocks(); - start = gen_xmlNodePtr(n_start, 0); - end = gen_xmlNodePtr(n_end, 1); - - ret_val = xmlXPtrNewLocationSetNodes(start, end); - desret_xmlXPathObjectPtr(ret_val); - call_tests++; - des_xmlNodePtr(n_start, start, 0); - des_xmlNodePtr(n_end, end, 1); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrNewLocationSetNodes", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_start); - printf(" %d", n_end); - printf("\n"); - } - } - } - function_tests++; -#endif - - return(test_ret); -} - - -static int -test_xmlXPtrNewRange(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathObjectPtr ret_val; - xmlNodePtr start; /* the starting node */ - int n_start; - int startindex; /* the start index */ - int n_startindex; - xmlNodePtr end; /* the ending point */ - int n_end; - int endindex; /* the ending index */ - int n_endindex; - - for (n_start = 0;n_start < gen_nb_xmlNodePtr;n_start++) { - for (n_startindex = 0;n_startindex < gen_nb_int;n_startindex++) { - for (n_end = 0;n_end < gen_nb_xmlNodePtr;n_end++) { - for (n_endindex = 0;n_endindex < gen_nb_int;n_endindex++) { - mem_base = xmlMemBlocks(); - start = gen_xmlNodePtr(n_start, 0); - startindex = gen_int(n_startindex, 1); - end = gen_xmlNodePtr(n_end, 2); - endindex = gen_int(n_endindex, 3); - - ret_val = xmlXPtrNewRange(start, startindex, end, endindex); - desret_xmlXPathObjectPtr(ret_val); - call_tests++; - des_xmlNodePtr(n_start, start, 0); - des_int(n_startindex, startindex, 1); - des_xmlNodePtr(n_end, end, 2); - des_int(n_endindex, endindex, 3); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrNewRange", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_start); - printf(" %d", n_startindex); - printf(" %d", n_end); - printf(" %d", n_endindex); - printf("\n"); - } - } - } - } - } - function_tests++; -#endif - - return(test_ret); -} - - -static int -test_xmlXPtrNewRangeNodeObject(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathObjectPtr ret_val; - xmlNodePtr start; /* the starting node */ - int n_start; - xmlXPathObjectPtr end; /* the ending object */ - int n_end; - - for (n_start = 0;n_start < gen_nb_xmlNodePtr;n_start++) { - for (n_end = 0;n_end < gen_nb_xmlXPathObjectPtr;n_end++) { - mem_base = xmlMemBlocks(); - start = gen_xmlNodePtr(n_start, 0); - end = gen_xmlXPathObjectPtr(n_end, 1); - - ret_val = xmlXPtrNewRangeNodeObject(start, end); - desret_xmlXPathObjectPtr(ret_val); - call_tests++; - des_xmlNodePtr(n_start, start, 0); - des_xmlXPathObjectPtr(n_end, end, 1); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrNewRangeNodeObject", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_start); - printf(" %d", n_end); - printf("\n"); - } - } - } - function_tests++; -#endif - - return(test_ret); -} - - -static int -test_xmlXPtrNewRangeNodePoint(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathObjectPtr ret_val; - xmlNodePtr start; /* the starting node */ - int n_start; - xmlXPathObjectPtr end; /* the ending point */ - int n_end; - - for (n_start = 0;n_start < gen_nb_xmlNodePtr;n_start++) { - for (n_end = 0;n_end < gen_nb_xmlXPathObjectPtr;n_end++) { - mem_base = xmlMemBlocks(); - start = gen_xmlNodePtr(n_start, 0); - end = gen_xmlXPathObjectPtr(n_end, 1); - - ret_val = xmlXPtrNewRangeNodePoint(start, end); - desret_xmlXPathObjectPtr(ret_val); - call_tests++; - des_xmlNodePtr(n_start, start, 0); - des_xmlXPathObjectPtr(n_end, end, 1); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrNewRangeNodePoint", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_start); - printf(" %d", n_end); - printf("\n"); - } - } - } - function_tests++; -#endif - - return(test_ret); -} - - -static int -test_xmlXPtrNewRangeNodes(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathObjectPtr ret_val; - xmlNodePtr start; /* the starting node */ - int n_start; - xmlNodePtr end; /* the ending node */ - int n_end; - - for (n_start = 0;n_start < gen_nb_xmlNodePtr;n_start++) { - for (n_end = 0;n_end < gen_nb_xmlNodePtr;n_end++) { - mem_base = xmlMemBlocks(); - start = gen_xmlNodePtr(n_start, 0); - end = gen_xmlNodePtr(n_end, 1); - - ret_val = xmlXPtrNewRangeNodes(start, end); - desret_xmlXPathObjectPtr(ret_val); - call_tests++; - des_xmlNodePtr(n_start, start, 0); - des_xmlNodePtr(n_end, end, 1); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrNewRangeNodes", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_start); - printf(" %d", n_end); - printf("\n"); - } - } - } - function_tests++; -#endif - - return(test_ret); -} - - -static int -test_xmlXPtrNewRangePointNode(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathObjectPtr ret_val; - xmlXPathObjectPtr start; /* the starting point */ - int n_start; - xmlNodePtr end; /* the ending node */ - int n_end; - - for (n_start = 0;n_start < gen_nb_xmlXPathObjectPtr;n_start++) { - for (n_end = 0;n_end < gen_nb_xmlNodePtr;n_end++) { - mem_base = xmlMemBlocks(); - start = gen_xmlXPathObjectPtr(n_start, 0); - end = gen_xmlNodePtr(n_end, 1); - - ret_val = xmlXPtrNewRangePointNode(start, end); - desret_xmlXPathObjectPtr(ret_val); - call_tests++; - des_xmlXPathObjectPtr(n_start, start, 0); - des_xmlNodePtr(n_end, end, 1); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrNewRangePointNode", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_start); - printf(" %d", n_end); - printf("\n"); - } - } - } - function_tests++; -#endif - - return(test_ret); -} - - -static int -test_xmlXPtrNewRangePoints(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathObjectPtr ret_val; - xmlXPathObjectPtr start; /* the starting point */ - int n_start; - xmlXPathObjectPtr end; /* the ending point */ - int n_end; - - for (n_start = 0;n_start < gen_nb_xmlXPathObjectPtr;n_start++) { - for (n_end = 0;n_end < gen_nb_xmlXPathObjectPtr;n_end++) { - mem_base = xmlMemBlocks(); - start = gen_xmlXPathObjectPtr(n_start, 0); - end = gen_xmlXPathObjectPtr(n_end, 1); - - ret_val = xmlXPtrNewRangePoints(start, end); - desret_xmlXPathObjectPtr(ret_val); - call_tests++; - des_xmlXPathObjectPtr(n_start, start, 0); - des_xmlXPathObjectPtr(n_end, end, 1); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrNewRangePoints", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_start); - printf(" %d", n_end); - printf("\n"); - } - } - } - function_tests++; -#endif - - return(test_ret); -} - - -static int -test_xmlXPtrRangeToFunction(void) { - int test_ret = 0; - -#if defined(LIBXML_XPTR_ENABLED) && defined(LIBXML_XPTR_LOCS_ENABLED) - int mem_base; - xmlXPathParserContextPtr ctxt; /* the XPointer Parser context */ - int n_ctxt; - int nargs; /* the number of args */ - int n_nargs; - - for (n_ctxt = 0;n_ctxt < gen_nb_xmlXPathParserContextPtr;n_ctxt++) { - for (n_nargs = 0;n_nargs < gen_nb_int;n_nargs++) { - mem_base = xmlMemBlocks(); - ctxt = gen_xmlXPathParserContextPtr(n_ctxt, 0); - nargs = gen_int(n_nargs, 1); - - xmlXPtrRangeToFunction(ctxt, nargs); - call_tests++; - des_xmlXPathParserContextPtr(n_ctxt, ctxt, 0); - des_int(n_nargs, nargs, 1); - xmlResetLastError(); - if (mem_base != xmlMemBlocks()) { - printf("Leak of %d blocks found in xmlXPtrRangeToFunction", - xmlMemBlocks() - mem_base); - test_ret++; - printf(" %d", n_ctxt); - printf(" %d", n_nargs); - printf("\n"); - } - } - } - function_tests++; -#endif - - return(test_ret); -} - static int test_xpointer(void) { int test_ret = 0; - if (quiet == 0) printf("Testing xpointer : 13 of 21 functions ...\n"); - test_ret += test_xmlXPtrBuildNodeList(); + if (quiet == 0) printf("Testing xpointer : 1 of 2 functions ...\n"); test_ret += test_xmlXPtrEval(); - test_ret += test_xmlXPtrEvalRangePredicate(); - test_ret += test_xmlXPtrNewCollapsedRange(); test_ret += test_xmlXPtrNewContext(); - test_ret += test_xmlXPtrNewLocationSetNodeSet(); - test_ret += test_xmlXPtrNewLocationSetNodes(); - test_ret += test_xmlXPtrNewRange(); - test_ret += test_xmlXPtrNewRangeNodeObject(); - test_ret += test_xmlXPtrNewRangeNodePoint(); - test_ret += test_xmlXPtrNewRangeNodes(); - test_ret += test_xmlXPtrNewRangePointNode(); - test_ret += test_xmlXPtrNewRangePoints(); - test_ret += test_xmlXPtrRangeToFunction(); if (test_ret != 0) printf("Module xpointer: %d errors\n", test_ret); diff --git a/win32/configure.js b/win32/configure.js index 5ae25a69..92f3fc7d 100644 --- a/win32/configure.js +++ b/win32/configure.js @@ -35,7 +35,6 @@ var withC14n = true; var withCatalog = true; var withXpath = true; var withXptr = true; -var withXptrLocs = false; var withXinclude = true; var withIconv = true; var withIcu = false; @@ -117,7 +116,6 @@ function usage() txt += " catalog: Enable catalog support (" + (withCatalog? "yes" : "no") + ")\n"; txt += " xpath: Enable XPath support (" + (withXpath? "yes" : "no") + ")\n"; txt += " xptr: Enable XPointer support (" + (withXptr? "yes" : "no") + ")\n"; - txt += " xptr_locs: Enable XPointer locs support (" + (withXptrLocs? "yes" : "no") + ")\n"; txt += " xinclude: Enable XInclude support (" + (withXinclude? "yes" : "no") + ")\n"; txt += " iconv: Enable iconv support (" + (withIconv? "yes" : "no") + ")\n"; txt += " icu: Enable icu support (" + (withIcu? "yes" : "no") + ")\n"; @@ -210,7 +208,6 @@ function discoverVersion() vf.WriteLine("WITH_CATALOG=" + (withCatalog? "1" : "0")); vf.WriteLine("WITH_XPATH=" + (withXpath? "1" : "0")); vf.WriteLine("WITH_XPTR=" + (withXptr? "1" : "0")); - vf.WriteLine("WITH_XPTR_LOCS=" + (withXptrLocs? "1" : "0")); vf.WriteLine("WITH_XINCLUDE=" + (withXinclude? "1" : "0")); vf.WriteLine("WITH_ICONV=" + (withIconv? "1" : "0")); vf.WriteLine("WITH_ICU=" + (withIcu? "1" : "0")); @@ -303,8 +300,6 @@ function configureLibxml() of.WriteLine(s.replace(/\@WITH_XPATH\@/, withXpath? "1" : "0")); } else if (s.search(/\@WITH_XPTR\@/) != -1) { of.WriteLine(s.replace(/\@WITH_XPTR\@/, withXptr? "1" : "0")); - } else if (s.search(/\@WITH_XPTR_LOCS\@/) != -1) { - of.WriteLine(s.replace(/\@WITH_XPTR_LOCS\@/, withXptrLocs? "1" : "0")); } else if (s.search(/\@WITH_XINCLUDE\@/) != -1) { of.WriteLine(s.replace(/\@WITH_XINCLUDE\@/, withXinclude? "1" : "0")); } else if (s.search(/\@WITH_ICONV\@/) != -1) { @@ -450,8 +445,6 @@ for (i = 0; (i < WScript.Arguments.length) && (error == 0); i++) { withXpath = strToBool(arg.substring(opt.length + 1, arg.length)); else if (opt == "xptr") withXptr = strToBool(arg.substring(opt.length + 1, arg.length)); - else if (opt == "xptr_locs") - withXptrLocs = strToBool(arg.substring(opt.length + 1, arg.length)); else if (opt == "xinclude") withXinclude = strToBool(arg.substring(opt.length + 1, arg.length)); else if (opt == "iconv") @@ -633,7 +626,6 @@ txtOut += " C14N support: " + boolToStr(withC14n) + "\n"; txtOut += " Catalog support: " + boolToStr(withCatalog) + "\n"; txtOut += " XPath support: " + boolToStr(withXpath) + "\n"; txtOut += " XPointer support: " + boolToStr(withXptr) + "\n"; -txtOut += " XPointer locs: " + boolToStr(withXptrLocs) + "\n"; txtOut += " XInclude support: " + boolToStr(withXinclude) + "\n"; txtOut += " iconv support: " + boolToStr(withIconv) + "\n"; txtOut += " icu support: " + boolToStr(withIcu) + "\n"; diff --git a/xinclude.c b/xinclude.c index b3db1daf..c177b939 100644 --- a/xinclude.c +++ b/xinclude.c @@ -786,244 +786,6 @@ error: return(NULL); } -#ifdef LIBXML_XPTR_LOCS_ENABLED -/** - * xmlXIncludeGetNthChild: - * @cur: the node - * @no: the child number - * - * Returns the @n'th element child of @cur or NULL - */ -static xmlNodePtr -xmlXIncludeGetNthChild(xmlNodePtr cur, int no) { - int i; - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) - return(NULL); - cur = cur->children; - for (i = 0;i <= no;cur = cur->next) { - if (cur == NULL) - return(cur); - if ((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_DOCUMENT_NODE) || - (cur->type == XML_HTML_DOCUMENT_NODE)) { - i++; - if (i == no) - break; - } - } - return(cur); -} - -xmlNodePtr xmlXPtrAdvanceNode(xmlNodePtr cur, int *level); /* in xpointer.c */ -/** - * xmlXIncludeCopyRange: - * @ctxt: the XInclude context - * @obj: the XPointer result from the evaluation. - * - * Build a node list tree copy of the XPointer result. - * - * Returns an xmlNodePtr list or NULL. - * The caller has to free the node tree. - */ -static xmlNodePtr -xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlXPathObjectPtr range) { - /* pointers to generated nodes */ - xmlNodePtr list = NULL, last = NULL, listParent = NULL; - xmlNodePtr tmp, tmp2; - /* pointers to traversal nodes */ - xmlNodePtr start, cur, end; - int index1, index2; - int level = 0, lastLevel = 0, endLevel = 0, endFlag = 0; - - if ((ctxt == NULL) || (range == NULL)) - return(NULL); - if (range->type != XPATH_RANGE) - return(NULL); - start = (xmlNodePtr) range->user; - - if ((start == NULL) || (start->type == XML_NAMESPACE_DECL)) - return(NULL); - end = range->user2; - if (end == NULL) - return(xmlDocCopyNode(start, ctxt->doc, 1)); - if (end->type == XML_NAMESPACE_DECL) - return(NULL); - - cur = start; - index1 = range->index; - index2 = range->index2; - /* - * level is depth of the current node under consideration - * list is the pointer to the root of the output tree - * listParent is a pointer to the parent of output tree (within - the included file) in case we need to add another level - * last is a pointer to the last node added to the output tree - * lastLevel is the depth of last (relative to the root) - */ - while (cur != NULL) { - /* - * Check if our output tree needs a parent - */ - if (level < 0) { - while (level < 0) { - /* copy must include namespaces and properties */ - tmp2 = xmlDocCopyNode(listParent, ctxt->doc, 2); - xmlAddChild(tmp2, list); - list = tmp2; - listParent = listParent->parent; - level++; - } - last = list; - lastLevel = 0; - } - /* - * Check whether we need to change our insertion point - */ - while (level < lastLevel) { - last = last->parent; - lastLevel --; - } - if (cur == end) { /* Are we at the end of the range? */ - if (cur->type == XML_TEXT_NODE) { - const xmlChar *content = cur->content; - int len; - - if (content == NULL) { - tmp = xmlNewDocTextLen(ctxt->doc, NULL, 0); - } else { - len = index2; - if ((cur == start) && (index1 > 1)) { - content += (index1 - 1); - len -= (index1 - 1); - } else { - len = index2; - } - tmp = xmlNewDocTextLen(ctxt->doc, content, len); - } - /* single sub text node selection */ - if (list == NULL) - return(tmp); - /* prune and return full set */ - if (level == lastLevel) - xmlAddNextSibling(last, tmp); - else - xmlAddChild(last, tmp); - return(list); - } else { /* ending node not a text node */ - endLevel = level; /* remember the level of the end node */ - endFlag = 1; - /* last node - need to take care of properties + namespaces */ - tmp = xmlDocCopyNode(cur, ctxt->doc, 2); - if (list == NULL) { - list = tmp; - listParent = cur->parent; - last = tmp; - } else { - if (level == lastLevel) - last = xmlAddNextSibling(last, tmp); - else { - last = xmlAddChild(last, tmp); - lastLevel = level; - } - } - - if (index2 > 1) { - end = xmlXIncludeGetNthChild(cur, index2 - 1); - index2 = 0; - } - if ((cur == start) && (index1 > 1)) { - cur = xmlXIncludeGetNthChild(cur, index1 - 1); - index1 = 0; - } else { - cur = cur->children; - } - level++; /* increment level to show change */ - /* - * Now gather the remaining nodes from cur to end - */ - continue; /* while */ - } - } else if (cur == start) { /* Not at the end, are we at start? */ - if ((cur->type == XML_TEXT_NODE) || - (cur->type == XML_CDATA_SECTION_NODE)) { - const xmlChar *content = cur->content; - - if (content == NULL) { - tmp = xmlNewDocTextLen(ctxt->doc, NULL, 0); - } else { - if (index1 > 1) { - content += (index1 - 1); - index1 = 0; - } - tmp = xmlNewDocText(ctxt->doc, content); - } - last = list = tmp; - listParent = cur->parent; - } else { /* Not text node */ - /* - * start of the range - need to take care of - * properties and namespaces - */ - tmp = xmlDocCopyNode(cur, ctxt->doc, 2); - list = last = tmp; - listParent = cur->parent; - if (index1 > 1) { /* Do we need to position? */ - cur = xmlXIncludeGetNthChild(cur, index1 - 1); - level = lastLevel = 1; - index1 = 0; - /* - * Now gather the remaining nodes from cur to end - */ - continue; /* while */ - } - } - } else { - tmp = NULL; - switch (cur->type) { - case XML_DTD_NODE: - case XML_ELEMENT_DECL: - case XML_ATTRIBUTE_DECL: - case XML_ENTITY_NODE: - /* Do not copy DTD information */ - break; - case XML_ENTITY_DECL: - /* 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: - /* - * Middle of the range - need to take care of - * properties and namespaces - */ - tmp = xmlDocCopyNode(cur, ctxt->doc, 2); - break; - } - if (tmp != NULL) { - if (level == lastLevel) - last = xmlAddNextSibling(last, tmp); - else { - last = xmlAddChild(last, tmp); - lastLevel = level; - } - } - } - /* - * Skip to next node in document order - */ - cur = xmlXPtrAdvanceNode(cur, &level); - if (endFlag && (level >= endLevel)) - break; - } - return(list); -} -#endif /* LIBXML_XPTR_LOCS_ENABLED */ - #ifdef LIBXML_XPTR_ENABLED /** * xmlXIncludeCopyXPointer: @@ -1103,33 +865,6 @@ xmlXIncludeCopyXPointer(xmlXIncludeCtxtPtr ctxt, xmlXPathObjectPtr obj, } break; } -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_LOCATIONSET: { - xmlLocationSetPtr set = (xmlLocationSetPtr) obj->user; - if (set == NULL) - return(NULL); - for (i = 0;i < set->locNr;i++) { - if (last == NULL) - list = last = xmlXIncludeCopyXPointer(ctxt, - set->locTab[i], - targetBase); - else - xmlAddNextSibling(last, - xmlXIncludeCopyXPointer(ctxt, set->locTab[i], - targetBase)); - if (last != NULL) { - while (last->next != NULL) - last = last->next; - } - } - break; - } - case XPATH_RANGE: - return(xmlXIncludeCopyRange(ctxt, obj)); - case XPATH_POINT: - /* points are ignored in XInclude */ - break; -#endif default: break; } @@ -1465,7 +1200,7 @@ loaded: } if (ctxt->xpctxt == NULL) { - ctxt->xpctxt = xmlXPtrNewContext(doc, NULL, NULL); + ctxt->xpctxt = xmlXPathNewContext(doc); if (ctxt->xpctxt == NULL) { xmlXIncludeErrMemory(ctxt); goto error; @@ -1492,9 +1227,6 @@ loaded: case XPATH_BOOLEAN: case XPATH_NUMBER: case XPATH_STRING: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: -#endif case XPATH_USERS: case XPATH_XSLT_TREE: xmlXIncludeErr(ctxt, ref->elem, XML_XINCLUDE_XPTR_RESULT, @@ -1505,11 +1237,6 @@ loaded: case XPATH_NODESET: break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_RANGE: - case XPATH_LOCATIONSET: - break; -#endif } set = xptr->nodesetval; if (set != NULL) { diff --git a/xpath.c b/xpath.c index 0ddde8d4..e9fddc90 100644 --- a/xpath.c +++ b/xpath.c @@ -35,9 +35,6 @@ #include #include #include -#ifdef LIBXML_XPTR_LOCS_ENABLED -#include -#endif #ifdef LIBXML_DEBUG_ENABLED #include #endif @@ -790,9 +787,6 @@ typedef enum { XPATH_OP_PREDICATE, XPATH_OP_FILTER, /* 16 */ XPATH_OP_SORT /* 17 */ -#ifdef LIBXML_XPTR_LOCS_ENABLED - ,XPATH_OP_RANGETO -#endif } xmlXPathOp; typedef enum { @@ -1187,30 +1181,6 @@ xmlXPathDebugDumpValueTree(FILE *output, xmlNodeSetPtr cur, int depth) { fprintf(output, "%d", i + 1); xmlXPathDebugDumpNodeList(output, cur->nodeTab[0]->children, depth + 1); } -#if defined(LIBXML_XPTR_LOCS_ENABLED) -static void -xmlXPathDebugDumpLocationSet(FILE *output, xmlLocationSetPtr cur, int depth) { - int i; - char shift[100]; - - for (i = 0;((i < depth) && (i < 25));i++) - shift[2 * i] = shift[2 * i + 1] = ' '; - shift[2 * i] = shift[2 * i + 1] = 0; - - if (cur == NULL) { - fprintf(output, "%s", shift); - fprintf(output, "LocationSet is NULL !\n"); - return; - - } - - for (i = 0;i < cur->locNr;i++) { - fprintf(output, "%s", shift); - fprintf(output, "%d : ", i + 1); - xmlXPathDebugDumpObject(output, cur->locTab[i], depth + 1); - } -} -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /** * xmlXPathDebugDumpObject: @@ -1279,47 +1249,6 @@ xmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth) { xmlDebugDumpString(output, cur->stringval); fprintf(output, "\n"); break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - fprintf(output, "Object is a point : index %d in node", cur->index); - xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user, depth + 1); - fprintf(output, "\n"); - break; - case XPATH_RANGE: - if ((cur->user2 == NULL) || - ((cur->user2 == cur->user) && (cur->index == cur->index2))) { - fprintf(output, "Object is a collapsed range :\n"); - fprintf(output, "%s", shift); - if (cur->index >= 0) - fprintf(output, "index %d in ", cur->index); - fprintf(output, "node\n"); - xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user, - depth + 1); - } else { - fprintf(output, "Object is a range :\n"); - fprintf(output, "%s", shift); - fprintf(output, "From "); - if (cur->index >= 0) - fprintf(output, "index %d in ", cur->index); - fprintf(output, "node\n"); - xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user, - depth + 1); - fprintf(output, "%s", shift); - fprintf(output, "To "); - if (cur->index2 >= 0) - fprintf(output, "index %d in ", cur->index2); - fprintf(output, "node\n"); - xmlXPathDebugDumpNode(output, (xmlNodePtr) cur->user2, - depth + 1); - fprintf(output, "\n"); - } - break; - case XPATH_LOCATIONSET: - fprintf(output, "Object is a Location Set:\n"); - xmlXPathDebugDumpLocationSet(output, - (xmlLocationSetPtr) cur->user, depth); - break; -#endif /* LIBXML_XPTR_LOCS_ENABLED */ case XPATH_USERS: fprintf(output, "Object is user defined\n"); break; @@ -1487,9 +1416,6 @@ xmlXPathDebugDumpStepOp(FILE *output, xmlXPathCompExprPtr comp, case XPATH_OP_ARG: fprintf(output, "ARG"); break; case XPATH_OP_PREDICATE: fprintf(output, "PREDICATE"); break; case XPATH_OP_FILTER: fprintf(output, "FILTER"); break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_OP_RANGETO: fprintf(output, "RANGETO"); break; -#endif default: fprintf(output, "UNKNOWN %d\n", op->op); return; } @@ -2024,11 +1950,6 @@ xmlXPathCastToNumberInternal(xmlXPathParserContextPtr ctxt, ret = xmlXPathCastBooleanToNumber(val->boolval); break; case XPATH_USERS: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /* TODO */ ret = xmlXPathNAN; break; @@ -4460,10 +4381,6 @@ xmlXPathObjectCopy(xmlXPathObjectPtr val) { switch (val->type) { case XPATH_BOOLEAN: case XPATH_NUMBER: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ break; case XPATH_STRING: ret->stringval = xmlStrdup(val->stringval); @@ -4514,14 +4431,6 @@ xmlXPathObjectCopy(xmlXPathObjectPtr val) { /* Do not deallocate the copied tree value */ ret->boolval = 0; break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_LOCATIONSET: - { - xmlLocationSetPtr loc = val->user; - ret->user = (void *) xmlXPtrLocationSetMerge(NULL, loc); - break; - } -#endif case XPATH_USERS: ret->user = val->user; break; @@ -4545,11 +4454,6 @@ xmlXPathFreeObject(xmlXPathObjectPtr obj) { if ((obj->type == XPATH_NODESET) || (obj->type == XPATH_XSLT_TREE)) { if (obj->nodesetval != NULL) xmlXPathFreeNodeSet(obj->nodesetval); -#ifdef LIBXML_XPTR_LOCS_ENABLED - } else if (obj->type == XPATH_LOCATIONSET) { - if (obj->user != NULL) - xmlXPtrFreeLocationSet(obj->user); -#endif } else if (obj->type == XPATH_STRING) { if (obj->stringval != NULL) xmlFree(obj->stringval); @@ -4604,13 +4508,6 @@ xmlXPathReleaseObject(xmlXPathContextPtr ctxt, xmlXPathObjectPtr obj) case XPATH_BOOLEAN: case XPATH_NUMBER: break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_LOCATIONSET: - if (obj->user != NULL) { - xmlXPtrFreeLocationSet(obj->user); - } - goto free_obj; -#endif default: goto free_obj; } @@ -4786,11 +4683,6 @@ xmlXPathCastToString(xmlXPathObjectPtr val) { break; } case XPATH_USERS: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /* TODO */ ret = xmlStrdup((const xmlChar *) ""); break; @@ -4830,11 +4722,6 @@ xmlXPathConvertString(xmlXPathObjectPtr val) { res = xmlXPathCastNumberToString(val->floatval); break; case XPATH_USERS: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /* TODO */ break; } @@ -5044,11 +4931,6 @@ xmlXPathCastToBoolean (xmlXPathObjectPtr val) { ret = val->boolval; break; case XPATH_USERS: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /* TODO */ ret = 0; break; @@ -5964,11 +5846,6 @@ xmlXPathEqualValuesCommon(xmlXPathParserContextPtr ctxt, ret = (arg1->boolval == ret); break; case XPATH_USERS: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /* TODO */ break; case XPATH_NODESET: @@ -6021,11 +5898,6 @@ xmlXPathEqualValuesCommon(xmlXPathParserContextPtr ctxt, } break; case XPATH_USERS: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /* TODO */ break; case XPATH_NODESET: @@ -6082,11 +5954,6 @@ xmlXPathEqualValuesCommon(xmlXPathParserContextPtr ctxt, } break; case XPATH_USERS: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /* TODO */ break; case XPATH_NODESET: @@ -6095,11 +5962,6 @@ xmlXPathEqualValuesCommon(xmlXPathParserContextPtr ctxt, } break; case XPATH_USERS: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /* TODO */ break; case XPATH_NODESET: @@ -6175,11 +6037,6 @@ xmlXPathEqualValues(xmlXPathParserContextPtr ctxt) { arg2->stringval, 0); break; case XPATH_USERS: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /* TODO */ break; } @@ -6255,11 +6112,6 @@ xmlXPathNotEqualValues(xmlXPathParserContextPtr ctxt) { arg2->stringval, 1); break; case XPATH_USERS: -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_POINT: - case XPATH_RANGE: - case XPATH_LOCATIONSET: -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /* TODO */ break; } @@ -9599,11 +9451,6 @@ xmlXPathCompPathExpr(xmlXPathParserContextPtr ctxt) { /* Node Type or Function */ if (xmlXPathIsNodeType(name)) { lc = 1; -#ifdef LIBXML_XPTR_LOCS_ENABLED - } else if (ctxt->xptr && - xmlStrEqual(name, BAD_CAST "range-to")) { - lc = 1; -#endif } else { lc = 0; } @@ -10234,11 +10081,6 @@ xmlXPathIsAxisName(const xmlChar *name) { */ static void xmlXPathCompStep(xmlXPathParserContextPtr ctxt) { -#ifdef LIBXML_XPTR_LOCS_ENABLED - int rangeto = 0; - int op2 = -1; -#endif - SKIP_BLANKS; if ((CUR == '.') && (NXT(1) == '.')) { SKIP(2); @@ -10256,36 +10098,6 @@ xmlXPathCompStep(xmlXPathParserContextPtr ctxt) { xmlXPathTypeVal type = (xmlXPathTypeVal) 0; int op1; - /* - * The modification needed for XPointer change to the production - */ -#ifdef LIBXML_XPTR_LOCS_ENABLED - if (ctxt->xptr) { - name = xmlXPathParseNCName(ctxt); - if ((name != NULL) && (xmlStrEqual(name, BAD_CAST "range-to"))) { - op2 = ctxt->comp->last; - xmlFree(name); - SKIP_BLANKS; - if (CUR != '(') { - XP_ERROR(XPATH_EXPR_ERROR); - } - NEXT; - SKIP_BLANKS; - - xmlXPathCompileExpr(ctxt, 1); - /* PUSH_BINARY_EXPR(XPATH_OP_RANGETO, op2, ctxt->comp->last, 0, 0); */ - CHECK_ERROR; - - SKIP_BLANKS; - if (CUR != ')') { - XP_ERROR(XPATH_EXPR_ERROR); - } - NEXT; - rangeto = 1; - goto eval_predicates; - } - } -#endif if (CUR == '*') { axis = AXIS_CHILD; } else { @@ -10330,9 +10142,6 @@ xmlXPathCompStep(xmlXPathParserContextPtr ctxt) { } } -#ifdef LIBXML_XPTR_LOCS_ENABLED -eval_predicates: -#endif op1 = ctxt->comp->last; ctxt->comp->last = -1; @@ -10341,11 +10150,6 @@ eval_predicates: xmlXPathCompPredicate(ctxt, 0); } -#ifdef LIBXML_XPTR_LOCS_ENABLED - if (rangeto) { - PUSH_BINARY_EXPR(XPATH_OP_RANGETO, op2, op1, 0, 0); - } else -#endif if (PUSH_FULL_EXPR(XPATH_OP_COLLECT, op1, ctxt->comp->last, axis, test, type, (void *)prefix, (void *)name) == -1) { xmlFree(prefix); @@ -10587,125 +10391,6 @@ xmlXPathNodeSetFilter(xmlXPathParserContextPtr ctxt, xpctxt->proximityPosition = oldpp; } -#ifdef LIBXML_XPTR_LOCS_ENABLED -/** - * xmlXPathLocationSetFilter: - * @ctxt: the XPath Parser context - * @locset: the location set to filter - * @filterOpIndex: the index of the predicate/filter op - * @minPos: minimum position in the filtered set (1-based) - * @maxPos: maximum position in the filtered set (1-based) - * - * Filter a location set, keeping only nodes for which the predicate - * expression matches. Afterwards, keep only nodes between minPos and maxPos - * in the filtered result. - */ -static void -xmlXPathLocationSetFilter(xmlXPathParserContextPtr ctxt, - xmlLocationSetPtr locset, - int filterOpIndex, - int minPos, int maxPos) -{ - xmlXPathContextPtr xpctxt; - xmlNodePtr oldnode; - xmlDocPtr olddoc; - xmlXPathStepOpPtr filterOp; - int oldcs, oldpp; - int i, j, pos; - - if ((locset == NULL) || (locset->locNr == 0) || (filterOpIndex == -1)) - return; - - xpctxt = ctxt->context; - oldnode = xpctxt->node; - olddoc = xpctxt->doc; - oldcs = xpctxt->contextSize; - oldpp = xpctxt->proximityPosition; - filterOp = &ctxt->comp->steps[filterOpIndex]; - - xpctxt->contextSize = locset->locNr; - - for (i = 0, j = 0, pos = 1; i < locset->locNr; i++) { - xmlNodePtr contextNode = locset->locTab[i]->user; - int res; - - xpctxt->node = contextNode; - xpctxt->proximityPosition = i + 1; - - /* - * Also set the xpath document in case things like - * key() are evaluated in the predicate. - * - * TODO: Get real doc for namespace nodes. - */ - if ((contextNode->type != XML_NAMESPACE_DECL) && - (contextNode->doc != NULL)) - xpctxt->doc = contextNode->doc; - - res = xmlXPathCompOpEvalToBoolean(ctxt, filterOp, 1); - - if (ctxt->error != XPATH_EXPRESSION_OK) - break; - if (res < 0) { - /* Shouldn't happen */ - xmlXPathErr(ctxt, XPATH_EXPR_ERROR); - break; - } - - if ((res != 0) && ((pos >= minPos) && (pos <= maxPos))) { - if (i != j) { - locset->locTab[j] = locset->locTab[i]; - locset->locTab[i] = NULL; - } - - j += 1; - } else { - /* Remove the entry from the initial location set. */ - xmlXPathFreeObject(locset->locTab[i]); - locset->locTab[i] = NULL; - } - - if (res != 0) { - if (pos == maxPos) { - i += 1; - break; - } - - pos += 1; - } - } - - /* Free remaining nodes. */ - for (; i < locset->locNr; i++) - xmlXPathFreeObject(locset->locTab[i]); - - locset->locNr = j; - - /* If too many elements were removed, shrink table to preserve memory. */ - if ((locset->locMax > XML_NODESET_DEFAULT) && - (locset->locNr < locset->locMax / 2)) { - xmlXPathObjectPtr *tmp; - int locMax = locset->locNr; - - if (locMax < XML_NODESET_DEFAULT) - locMax = XML_NODESET_DEFAULT; - tmp = (xmlXPathObjectPtr *) xmlRealloc(locset->locTab, - locMax * sizeof(xmlXPathObjectPtr)); - if (tmp == NULL) { - xmlXPathPErrMemory(ctxt); - } else { - locset->locTab = tmp; - locset->locMax = locMax; - } - } - - xpctxt->node = oldnode; - xpctxt->doc = olddoc; - xpctxt->contextSize = oldcs; - xpctxt->proximityPosition = oldpp; -} -#endif /* LIBXML_XPTR_LOCS_ENABLED */ - /** * xmlXPathCompOpEvalPredicate: * @ctxt: the XPath Parser context @@ -11745,23 +11430,6 @@ xmlXPathCompOpEvalFilterFirst(xmlXPathParserContextPtr ctxt, if (ctxt->value == NULL) return (total); -#ifdef LIBXML_XPTR_LOCS_ENABLED - /* - * Hum are we filtering the result of an XPointer expression - */ - if (ctxt->value->type == XPATH_LOCATIONSET) { - xmlLocationSetPtr locset = ctxt->value->user; - - if (locset != NULL) { - xmlXPathLocationSetFilter(ctxt, locset, op->ch2, 1, 1); - if (locset->locNr > 0) - *first = (xmlNodePtr) locset->locTab[0]->user; - } - - return (total); - } -#endif /* LIBXML_XPTR_LOCS_ENABLED */ - /* * In case of errors, xmlXPathNodeSetFilter can pop additional nodes from * the stack. We have to temporarily remove the nodeset object from the @@ -12148,18 +11816,6 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) if (ctxt->value == NULL) break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - /* - * Hum are we filtering the result of an XPointer expression - */ - if (ctxt->value->type == XPATH_LOCATIONSET) { - xmlLocationSetPtr locset = ctxt->value->user; - xmlXPathLocationSetFilter(ctxt, locset, op->ch2, - 1, locset->locNr); - break; - } -#endif /* LIBXML_XPTR_LOCS_ENABLED */ - /* * In case of errors, xmlXPathNodeSetFilter can pop additional * nodes from the stack. We have to temporarily remove the @@ -12187,165 +11843,6 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) xmlXPathNodeSetSort(ctxt->value->nodesetval); } break; -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_OP_RANGETO:{ - xmlXPathObjectPtr range; - xmlXPathObjectPtr res, obj; - xmlXPathObjectPtr tmp; - xmlLocationSetPtr newlocset = NULL; - xmlLocationSetPtr oldlocset; - xmlNodeSetPtr oldset; - xmlNodePtr oldnode = ctxt->context->node; - int oldcs = ctxt->context->contextSize; - int oldpp = ctxt->context->proximityPosition; - int i, j; - - if (op->ch1 != -1) { - total += - xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); - CHECK_ERROR0; - } - if (ctxt->value == NULL) { - XP_ERROR0(XPATH_INVALID_OPERAND); - } - if (op->ch2 == -1) - break; - - if (ctxt->value->type == XPATH_LOCATIONSET) { - /* - * 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. - */ - CHECK_TYPE0(XPATH_LOCATIONSET); - - if ((ctxt->value->user == NULL) || - (((xmlLocationSetPtr) ctxt->value->user)->locNr == 0)) - break; - - obj = valuePop(ctxt); - oldlocset = obj->user; - - newlocset = xmlXPtrLocationSetCreate(NULL); - - for (i = 0; i < oldlocset->locNr; i++) { - /* - * Run the evaluation with a node list made of a - * single item in the nodelocset. - */ - ctxt->context->node = oldlocset->locTab[i]->user; - ctxt->context->contextSize = oldlocset->locNr; - ctxt->context->proximityPosition = i + 1; - tmp = xmlXPathCacheNewNodeSet(ctxt, - ctxt->context->node); - valuePush(ctxt, tmp); - - if (op->ch2 != -1) - total += - xmlXPathCompOpEval(ctxt, - &comp->steps[op->ch2]); - if (ctxt->error != XPATH_EXPRESSION_OK) { - xmlXPtrFreeLocationSet(newlocset); - goto rangeto_error; - } - - res = valuePop(ctxt); - if (res->type == XPATH_LOCATIONSET) { - xmlLocationSetPtr rloc = - (xmlLocationSetPtr)res->user; - for (j=0; jlocNr; j++) { - range = xmlXPtrNewRange( - oldlocset->locTab[i]->user, - oldlocset->locTab[i]->index, - rloc->locTab[j]->user2, - rloc->locTab[j]->index2); - if (range != NULL) { - xmlXPtrLocationSetAdd(newlocset, range); - } - } - } else { - range = xmlXPtrNewRangeNodeObject( - (xmlNodePtr)oldlocset->locTab[i]->user, res); - if (range != NULL) { - xmlXPtrLocationSetAdd(newlocset,range); - } - } - - /* - * Cleanup - */ - if (res != NULL) { - xmlXPathReleaseObject(ctxt->context, res); - } - if (ctxt->value == tmp) { - res = valuePop(ctxt); - xmlXPathReleaseObject(ctxt->context, res); - } - } - } else { /* Not a location set */ - CHECK_TYPE0(XPATH_NODESET); - obj = valuePop(ctxt); - oldset = obj->nodesetval; - - newlocset = xmlXPtrLocationSetCreate(NULL); - - if (oldset != NULL) { - for (i = 0; i < oldset->nodeNr; i++) { - /* - * Run the evaluation with a node list made of a single item - * in the nodeset. - */ - ctxt->context->node = oldset->nodeTab[i]; - /* - * OPTIMIZE TODO: Avoid recreation for every iteration. - */ - tmp = xmlXPathCacheNewNodeSet(ctxt, - ctxt->context->node); - valuePush(ctxt, tmp); - - if (op->ch2 != -1) - total += - xmlXPathCompOpEval(ctxt, - &comp->steps[op->ch2]); - if (ctxt->error != XPATH_EXPRESSION_OK) { - xmlXPtrFreeLocationSet(newlocset); - goto rangeto_error; - } - - res = valuePop(ctxt); - range = - xmlXPtrNewRangeNodeObject(oldset->nodeTab[i], - res); - if (range != NULL) { - xmlXPtrLocationSetAdd(newlocset, range); - } - - /* - * Cleanup - */ - if (res != NULL) { - xmlXPathReleaseObject(ctxt->context, res); - } - if (ctxt->value == tmp) { - res = valuePop(ctxt); - xmlXPathReleaseObject(ctxt->context, res); - } - } - } - } - - /* - * The result is used as the new evaluation set. - */ - valuePush(ctxt, xmlXPtrWrapLocationSet(newlocset)); -rangeto_error: - xmlXPathReleaseObject(ctxt->context, obj); - ctxt->context->node = oldnode; - ctxt->context->contextSize = oldcs; - ctxt->context->proximityPosition = oldpp; - break; - } -#endif /* LIBXML_XPTR_LOCS_ENABLED */ default: XP_ERROR0(XPATH_INVALID_OPERAND); break; @@ -12839,14 +12336,6 @@ xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt, return(res->nodesetval->nodeNr != 0); case XPATH_STRING: return((res->stringval != NULL) && (res->stringval[0] != 0)); -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_LOCATIONSET:{ - xmlLocationSetPtr ptr = res->user; - if (ptr == NULL) - return(0); - return (ptr->locNr != 0); - } -#endif default: break; } diff --git a/xpointer.c b/xpointer.c index 87ea85bb..e643ab6b 100644 --- a/xpointer.c +++ b/xpointer.c @@ -113,53 +113,6 @@ xmlXPtrErr(xmlXPathParserContextPtr ctxt, int code, * A few helper functions for child sequences * * * ************************************************************************/ -#ifdef LIBXML_XPTR_LOCS_ENABLED -/* xmlXPtrAdvanceNode is a private function, but used by xinclude.c */ -xmlNodePtr xmlXPtrAdvanceNode(xmlNodePtr cur, int *level); -/** - * xmlXPtrGetArity: - * @cur: the node - * - * Returns the number of child for an element, -1 in case of error - */ -static int -xmlXPtrGetArity(xmlNodePtr cur) { - int i; - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) - return(-1); - cur = cur->children; - for (i = 0;cur != NULL;cur = cur->next) { - if ((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_DOCUMENT_NODE) || - (cur->type == XML_HTML_DOCUMENT_NODE)) { - 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 -xmlXPtrGetIndex(xmlNodePtr cur) { - int i; - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) - return(-1); - for (i = 1;cur != NULL;cur = cur->prev) { - if ((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_DOCUMENT_NODE) || - (cur->type == XML_HTML_DOCUMENT_NODE)) { - i++; - } - } - return(i); -} -#endif /* LIBXML_XPTR_LOCS_ENABLED */ /** * xmlXPtrGetNthChild: @@ -188,648 +141,6 @@ xmlXPtrGetNthChild(xmlNodePtr cur, int no) { return(cur); } -#ifdef LIBXML_XPTR_LOCS_ENABLED -/************************************************************************ - * * - * Handling of XPointer specific types * - * * - ************************************************************************/ - -/** - * xmlXPtrErrMemory: - * @extra: extra information - * - * Handle a redefinition of attribute error - */ -static void -xmlXPtrErrMemory(const char *extra ATTRIBUTE_UNUSED) -{ - xmlRaiseMemoryError(NULL, NULL, NULL, XML_FROM_XPOINTER, NULL); -} - -/** - * 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 -xmlXPtrCmpPoints(xmlNodePtr node1, int index1, xmlNodePtr node2, int index2) { - if ((node1 == NULL) || (node2 == NULL)) - return(-2); - /* - * a couple of optimizations which will avoid computations in most cases - */ - if (node1 == node2) { - if (index1 < index2) - return(1); - if (index1 > index2) - return(-1); - return(0); - } - return(xmlXPathCmpNodes(node1, node2)); -} - -/** - * xmlXPtrNewPoint: - * @node: the xmlNodePtr - * @indx: the indx within the node - * - * Create a new xmlXPathObjectPtr of type point - * - * Returns the newly created object. - */ -static xmlXPathObjectPtr -xmlXPtrNewPoint(xmlNodePtr node, int indx) { - xmlXPathObjectPtr ret; - - if (node == NULL) - return(NULL); - if (indx < 0) - return(NULL); - - ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); - if (ret == NULL) { - xmlXPtrErrMemory("allocating point"); - return(NULL); - } - memset(ret, 0 , sizeof(xmlXPathObject)); - ret->type = XPATH_POINT; - ret->user = (void *) node; - ret->index = indx; - return(ret); -} - -/** - * xmlXPtrRangeCheckOrder: - * @range: an object range - * - * Make sure the points in the range are in the right order - */ -static void -xmlXPtrRangeCheckOrder(xmlXPathObjectPtr range) { - int tmp; - xmlNodePtr tmp2; - if (range == NULL) - return; - if (range->type != XPATH_RANGE) - return; - if (range->user2 == NULL) - return; - tmp = xmlXPtrCmpPoints(range->user, range->index, - range->user2, range->index2); - if (tmp == -1) { - tmp2 = range->user; - range->user = range->user2; - range->user2 = tmp2; - tmp = range->index; - range->index = range->index2; - range->index2 = tmp; - } -} - -/** - * xmlXPtrRangesEqual: - * @range1: the first range - * @range2: the second range - * - * Compare two ranges - * - * Returns 1 if equal, 0 otherwise - */ -static int -xmlXPtrRangesEqual(xmlXPathObjectPtr range1, xmlXPathObjectPtr range2) { - if (range1 == range2) - return(1); - if ((range1 == NULL) || (range2 == NULL)) - return(0); - if (range1->type != range2->type) - return(0); - if (range1->type != XPATH_RANGE) - return(0); - if (range1->user != range2->user) - return(0); - if (range1->index != range2->index) - return(0); - if (range1->user2 != range2->user2) - return(0); - if (range1->index2 != range2->index2) - return(0); - return(1); -} - -/** - * xmlXPtrNewRangeInternal: - * @start: the starting node - * @startindex: the start index - * @end: the ending point - * @endindex: the ending index - * - * Internal function to create a new xmlXPathObjectPtr of type range - * - * Returns the newly created object. - */ -static xmlXPathObjectPtr -xmlXPtrNewRangeInternal(xmlNodePtr start, int startindex, - xmlNodePtr end, int endindex) { - xmlXPathObjectPtr ret; - - /* - * Namespace nodes must be copied (see xmlXPathNodeSetDupNs). - * Disallow them for now. - */ - if ((start != NULL) && (start->type == XML_NAMESPACE_DECL)) - return(NULL); - if ((end != NULL) && (end->type == XML_NAMESPACE_DECL)) - return(NULL); - - ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); - if (ret == NULL) { - xmlXPtrErrMemory("allocating range"); - return(NULL); - } - memset(ret, 0, sizeof(xmlXPathObject)); - ret->type = XPATH_RANGE; - ret->user = start; - ret->index = startindex; - ret->user2 = end; - ret->index2 = endindex; - return(ret); -} - -/** - * 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. - */ -xmlXPathObjectPtr -xmlXPtrNewRange(xmlNodePtr start, int startindex, - xmlNodePtr end, int endindex) { - xmlXPathObjectPtr ret; - - if (start == NULL) - return(NULL); - if (end == NULL) - return(NULL); - if (startindex < 0) - return(NULL); - if (endindex < 0) - return(NULL); - - ret = xmlXPtrNewRangeInternal(start, startindex, end, endindex); - xmlXPtrRangeCheckOrder(ret); - 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. - */ -xmlXPathObjectPtr -xmlXPtrNewRangePoints(xmlXPathObjectPtr start, xmlXPathObjectPtr end) { - xmlXPathObjectPtr ret; - - if (start == NULL) - return(NULL); - if (end == NULL) - return(NULL); - if (start->type != XPATH_POINT) - return(NULL); - if (end->type != XPATH_POINT) - return(NULL); - - ret = xmlXPtrNewRangeInternal(start->user, start->index, end->user, - end->index); - xmlXPtrRangeCheckOrder(ret); - 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. - */ -xmlXPathObjectPtr -xmlXPtrNewRangePointNode(xmlXPathObjectPtr start, xmlNodePtr end) { - xmlXPathObjectPtr ret; - - if (start == NULL) - return(NULL); - if (end == NULL) - return(NULL); - if (start->type != XPATH_POINT) - return(NULL); - - ret = xmlXPtrNewRangeInternal(start->user, start->index, end, -1); - xmlXPtrRangeCheckOrder(ret); - 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. - */ -xmlXPathObjectPtr -xmlXPtrNewRangeNodePoint(xmlNodePtr start, xmlXPathObjectPtr end) { - xmlXPathObjectPtr ret; - - if (start == NULL) - return(NULL); - if (end == NULL) - return(NULL); - if (end->type != XPATH_POINT) - return(NULL); - - ret = xmlXPtrNewRangeInternal(start, -1, end->user, end->index); - xmlXPtrRangeCheckOrder(ret); - 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. - */ -xmlXPathObjectPtr -xmlXPtrNewRangeNodes(xmlNodePtr start, xmlNodePtr end) { - xmlXPathObjectPtr ret; - - if (start == NULL) - return(NULL); - if (end == NULL) - return(NULL); - - ret = xmlXPtrNewRangeInternal(start, -1, end, -1); - xmlXPtrRangeCheckOrder(ret); - 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. - */ -xmlXPathObjectPtr -xmlXPtrNewCollapsedRange(xmlNodePtr start) { - xmlXPathObjectPtr ret; - - if (start == NULL) - return(NULL); - - ret = xmlXPtrNewRangeInternal(start, -1, NULL, -1); - 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. - */ -xmlXPathObjectPtr -xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) { - xmlNodePtr endNode; - int endIndex; - xmlXPathObjectPtr ret; - - if (start == NULL) - return(NULL); - if (end == NULL) - return(NULL); - switch (end->type) { - case XPATH_POINT: - endNode = end->user; - endIndex = end->index; - break; - case XPATH_RANGE: - endNode = end->user2; - endIndex = end->index2; - break; - case XPATH_NODESET: - /* - * Empty set ... - */ - if ((end->nodesetval == NULL) || (end->nodesetval->nodeNr <= 0)) - return(NULL); - endNode = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1]; - endIndex = -1; - break; - default: - /* TODO */ - return(NULL); - } - - ret = xmlXPtrNewRangeInternal(start, -1, endNode, endIndex); - xmlXPtrRangeCheckOrder(ret); - 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. - */ -xmlLocationSetPtr -xmlXPtrLocationSetCreate(xmlXPathObjectPtr val) { - xmlLocationSetPtr ret; - - ret = (xmlLocationSetPtr) xmlMalloc(sizeof(xmlLocationSet)); - if (ret == NULL) { - xmlXPtrErrMemory("allocating locationset"); - return(NULL); - } - memset(ret, 0 , sizeof(xmlLocationSet)); - if (val != NULL) { - ret->locTab = (xmlXPathObjectPtr *) xmlMalloc(XML_RANGESET_DEFAULT * - sizeof(xmlXPathObjectPtr)); - if (ret->locTab == NULL) { - xmlXPtrErrMemory("allocating locationset"); - xmlFree(ret); - return(NULL); - } - memset(ret->locTab, 0 , - XML_RANGESET_DEFAULT * sizeof(xmlXPathObjectPtr)); - ret->locMax = XML_RANGESET_DEFAULT; - ret->locTab[ret->locNr++] = val; - } - 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 -xmlXPtrLocationSetAdd(xmlLocationSetPtr cur, xmlXPathObjectPtr val) { - int i; - - if ((cur == NULL) || (val == NULL)) return; - - /* - * check against doublons - */ - for (i = 0;i < cur->locNr;i++) { - if (xmlXPtrRangesEqual(cur->locTab[i], val)) { - xmlXPathFreeObject(val); - return; - } - } - - /* - * grow the locTab if needed - */ - if (cur->locMax == 0) { - cur->locTab = (xmlXPathObjectPtr *) xmlMalloc(XML_RANGESET_DEFAULT * - sizeof(xmlXPathObjectPtr)); - if (cur->locTab == NULL) { - xmlXPtrErrMemory("adding location to set"); - return; - } - memset(cur->locTab, 0 , - XML_RANGESET_DEFAULT * sizeof(xmlXPathObjectPtr)); - cur->locMax = XML_RANGESET_DEFAULT; - } else if (cur->locNr == cur->locMax) { - xmlXPathObjectPtr *temp; - - cur->locMax *= 2; - temp = (xmlXPathObjectPtr *) xmlRealloc(cur->locTab, cur->locMax * - sizeof(xmlXPathObjectPtr)); - if (temp == NULL) { - xmlXPtrErrMemory("adding location to set"); - return; - } - cur->locTab = temp; - } - cur->locTab[cur->locNr++] = val; -} - -/** - * 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. - */ -xmlLocationSetPtr -xmlXPtrLocationSetMerge(xmlLocationSetPtr val1, xmlLocationSetPtr val2) { - int i; - - if (val1 == NULL) return(NULL); - if (val2 == NULL) return(val1); - - /* - * !!!!! this can be optimized a lot, knowing that both - * val1 and val2 already have unicity of their values. - */ - - for (i = 0;i < val2->locNr;i++) - xmlXPtrLocationSetAdd(val1, val2->locTab[i]); - - return(val1); -} - -/** - * xmlXPtrLocationSetDel: - * @cur: the initial range set - * @val: an xmlXPathObjectPtr - * - * Removes an xmlXPathObjectPtr from an existing LocationSet - */ -void -xmlXPtrLocationSetDel(xmlLocationSetPtr cur, xmlXPathObjectPtr val) { - int i; - - if (cur == NULL) return; - if (val == NULL) return; - - /* - * check against doublons - */ - for (i = 0;i < cur->locNr;i++) - if (cur->locTab[i] == val) break; - - if (i >= cur->locNr) { - return; - } - cur->locNr--; - for (;i < cur->locNr;i++) - cur->locTab[i] = cur->locTab[i + 1]; - cur->locTab[cur->locNr] = NULL; -} - -/** - * xmlXPtrLocationSetRemove: - * @cur: the initial range set - * @val: the index to remove - * - * Removes an entry from an existing LocationSet list. - */ -void -xmlXPtrLocationSetRemove(xmlLocationSetPtr cur, int val) { - if (cur == NULL) return; - if (val >= cur->locNr) return; - cur->locNr--; - for (;val < cur->locNr;val++) - cur->locTab[val] = cur->locTab[val + 1]; - cur->locTab[cur->locNr] = NULL; -} - -/** - * xmlXPtrFreeLocationSet: - * @obj: the xmlLocationSetPtr to free - * - * Free the LocationSet compound (not the actual ranges !). - */ -void -xmlXPtrFreeLocationSet(xmlLocationSetPtr obj) { - int i; - - if (obj == NULL) return; - if (obj->locTab != NULL) { - for (i = 0;i < obj->locNr; i++) { - xmlXPathFreeObject(obj->locTab[i]); - } - xmlFree(obj->locTab); - } - xmlFree(obj); -} - -/** - * 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. - */ -xmlXPathObjectPtr -xmlXPtrNewLocationSetNodes(xmlNodePtr start, xmlNodePtr end) { - xmlXPathObjectPtr ret; - - ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); - if (ret == NULL) { - xmlXPtrErrMemory("allocating locationset"); - return(NULL); - } - memset(ret, 0 , sizeof(xmlXPathObject)); - ret->type = XPATH_LOCATIONSET; - if (end == NULL) - ret->user = xmlXPtrLocationSetCreate(xmlXPtrNewCollapsedRange(start)); - else - ret->user = xmlXPtrLocationSetCreate(xmlXPtrNewRangeNodes(start,end)); - 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. - */ -xmlXPathObjectPtr -xmlXPtrNewLocationSetNodeSet(xmlNodeSetPtr set) { - xmlXPathObjectPtr ret; - - ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); - if (ret == NULL) { - xmlXPtrErrMemory("allocating locationset"); - return(NULL); - } - memset(ret, 0, sizeof(xmlXPathObject)); - ret->type = XPATH_LOCATIONSET; - if (set != NULL) { - int i; - xmlLocationSetPtr newset; - - newset = xmlXPtrLocationSetCreate(NULL); - if (newset == NULL) - return(ret); - - for (i = 0;i < set->nodeNr;i++) - xmlXPtrLocationSetAdd(newset, - xmlXPtrNewCollapsedRange(set->nodeTab[i])); - - ret->user = (void *) newset; - } - return(ret); -} - -/** - * xmlXPtrWrapLocationSet: - * @val: the LocationSet value - * - * Wrap the LocationSet @val in a new xmlXPathObjectPtr - * - * Returns the newly created object. - */ -xmlXPathObjectPtr -xmlXPtrWrapLocationSet(xmlLocationSetPtr val) { - xmlXPathObjectPtr ret; - - ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); - if (ret == NULL) { - xmlXPtrErrMemory("allocating locationset"); - return(NULL); - } - memset(ret, 0, sizeof(xmlXPathObject)); - ret->type = XPATH_LOCATIONSET; - ret->user = (void *) val; - return(ret); -} -#endif /* LIBXML_XPTR_LOCS_ENABLED */ - /************************************************************************ * * * The parser * @@ -1004,9 +315,6 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) { ctxt->context->node = (xmlNodePtr)ctxt->context->doc; ctxt->context->proximityPosition = 1; ctxt->context->contextSize = 1; -#ifdef LIBXML_XPTR_LOCS_ENABLED - ctxt->xptr = xmlStrEqual(name, (xmlChar *) "xpointer"); -#endif xmlXPathEvalExpr(ctxt); ctxt->base = oldBase; ctxt->cur = oldCur; @@ -1123,14 +431,6 @@ xmlXPtrEvalFullXPtr(xmlXPathParserContextPtr ctxt, xmlChar *name) { xmlXPathObjectPtr obj = ctxt->value; switch (obj->type) { -#ifdef LIBXML_XPTR_LOCS_ENABLED - case XPATH_LOCATIONSET: { - xmlLocationSetPtr loc = ctxt->value->user; - if ((loc != NULL) && (loc->locNr > 0)) - return; - break; - } -#endif case XPATH_NODESET: { xmlNodeSetPtr loc = ctxt->value->nodesetval; if ((loc != NULL) && (loc->nodeNr > 0)) @@ -1268,23 +568,6 @@ xmlXPtrEvalXPointer(xmlXPathParserContextPtr ctxt) { * * ************************************************************************/ -#ifdef LIBXML_XPTR_LOCS_ENABLED -static -void xmlXPtrStringRangeFunction(xmlXPathParserContextPtr ctxt, int nargs); -static -void xmlXPtrStartPointFunction(xmlXPathParserContextPtr ctxt, int nargs); -static -void xmlXPtrEndPointFunction(xmlXPathParserContextPtr ctxt, int nargs); -static -void xmlXPtrHereFunction(xmlXPathParserContextPtr ctxt, int nargs); -static -void xmlXPtrOriginFunction(xmlXPathParserContextPtr ctxt, int nargs); -static -void xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt, int nargs); -static -void xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt, int nargs); -#endif /* LIBXML_XPTR_LOCS_ENABLED */ - /** * xmlXPtrNewContext: * @doc: the XML document @@ -1305,26 +588,6 @@ xmlXPtrNewContext(xmlDocPtr doc, xmlNodePtr here, xmlNodePtr origin) { ret = xmlXPathNewContext(doc); if (ret == NULL) return(ret); -#ifdef LIBXML_XPTR_LOCS_ENABLED - ret->xptr = 1; - ret->here = here; - ret->origin = origin; - - xmlXPathRegisterFunc(ret, (xmlChar *)"range", - xmlXPtrRangeFunction); - xmlXPathRegisterFunc(ret, (xmlChar *)"range-inside", - xmlXPtrRangeInsideFunction); - xmlXPathRegisterFunc(ret, (xmlChar *)"string-range", - xmlXPtrStringRangeFunction); - xmlXPathRegisterFunc(ret, (xmlChar *)"start-point", - xmlXPtrStartPointFunction); - xmlXPathRegisterFunc(ret, (xmlChar *)"end-point", - xmlXPtrEndPointFunction); - xmlXPathRegisterFunc(ret, (xmlChar *)"here", - xmlXPtrHereFunction); - xmlXPathRegisterFunc(ret, (xmlChar *)" origin", - xmlXPtrOriginFunction); -#endif /* LIBXML_XPTR_LOCS_ENABLED */ return(ret); } @@ -1363,9 +626,6 @@ xmlXPtrEval(const xmlChar *str, xmlXPathContextPtr ctx) { goto error; if ((ctxt->value != NULL) && -#ifdef LIBXML_XPTR_LOCS_ENABLED - (ctxt->value->type != XPATH_LOCATIONSET) && -#endif (ctxt->value->type != XPATH_NODESET)) { xmlXPtrErr(ctxt, XML_XPTR_EVAL_FAILED, "xmlXPtrEval: evaluation failed to return a node set\n", @@ -1408,1517 +668,5 @@ error: return(res); } -#ifdef LIBXML_XPTR_LOCS_ENABLED -/** - * 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 -xmlXPtrBuildRangeNodeList(xmlXPathObjectPtr range) { - /* pointers to generated nodes */ - xmlNodePtr list = NULL, last = NULL, parent = NULL, tmp; - /* pointers to traversal nodes */ - xmlNodePtr start, cur, end; - int index1, index2; - - if (range == NULL) - return(NULL); - if (range->type != XPATH_RANGE) - return(NULL); - start = (xmlNodePtr) range->user; - - if ((start == NULL) || (start->type == XML_NAMESPACE_DECL)) - return(NULL); - end = range->user2; - if (end == NULL) - return(xmlCopyNode(start, 1)); - if (end->type == XML_NAMESPACE_DECL) - return(NULL); - - cur = start; - index1 = range->index; - index2 = range->index2; - while (cur != NULL) { - if (cur == end) { - if (cur->type == XML_TEXT_NODE) { - const xmlChar *content = cur->content; - int len; - - if (content == NULL) { - tmp = xmlNewTextLen(NULL, 0); - } else { - len = index2; - if ((cur == start) && (index1 > 1)) { - content += (index1 - 1); - len -= (index1 - 1); - index1 = 0; - } else { - len = index2; - } - tmp = xmlNewTextLen(content, len); - } - /* single sub text node selection */ - if (list == NULL) - return(tmp); - /* prune and return full set */ - if (last != NULL) - xmlAddNextSibling(last, tmp); - else - xmlAddChild(parent, tmp); - return(list); - } else { - tmp = xmlCopyNode(cur, 0); - if (list == NULL) { - list = tmp; - parent = tmp; - } else { - if (last != NULL) - parent = xmlAddNextSibling(last, tmp); - else - parent = xmlAddChild(parent, tmp); - } - last = NULL; - - if (index2 > 1) { - end = xmlXPtrGetNthChild(cur, index2 - 1); - index2 = 0; - } - if ((cur == start) && (index1 > 1)) { - cur = xmlXPtrGetNthChild(cur, index1 - 1); - index1 = 0; - } else { - cur = cur->children; - } - /* - * Now gather the remaining nodes from cur to end - */ - continue; /* while */ - } - } else if ((cur == start) && - (list == NULL) /* looks superfluous but ... */ ) { - if ((cur->type == XML_TEXT_NODE) || - (cur->type == XML_CDATA_SECTION_NODE)) { - const xmlChar *content = cur->content; - - if (content == NULL) { - tmp = xmlNewTextLen(NULL, 0); - } else { - if (index1 > 1) { - content += (index1 - 1); - } - tmp = xmlNewText(content); - } - last = list = tmp; - } else { - if ((cur == start) && (index1 > 1)) { - tmp = xmlCopyNode(cur, 0); - list = tmp; - parent = tmp; - last = NULL; - cur = xmlXPtrGetNthChild(cur, index1 - 1); - index1 = 0; - /* - * Now gather the remaining nodes from cur to end - */ - continue; /* while */ - } - tmp = xmlCopyNode(cur, 1); - list = tmp; - parent = NULL; - last = tmp; - } - } else { - tmp = NULL; - switch (cur->type) { - case XML_DTD_NODE: - case XML_ELEMENT_DECL: - case XML_ATTRIBUTE_DECL: - case XML_ENTITY_NODE: - /* Do not copy DTD information */ - 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: - tmp = xmlCopyNode(cur, 1); - break; - } - if (tmp != NULL) { - if ((list == NULL) || ((last == NULL) && (parent == NULL))) { - return(NULL); - } - if (last != NULL) - xmlAddNextSibling(last, tmp); - else { - last = xmlAddChild(parent, tmp); - } - } - } - /* - * Skip to next node in document order - */ - if ((list == NULL) || ((last == NULL) && (parent == NULL))) { - return(NULL); - } - cur = xmlXPtrAdvanceNode(cur, 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. - */ -xmlNodePtr -xmlXPtrBuildNodeList(xmlXPathObjectPtr obj) { - xmlNodePtr list = NULL, last = NULL; - int i; - - if (obj == NULL) - return(NULL); - switch (obj->type) { - case XPATH_NODESET: { - xmlNodeSetPtr set = obj->nodesetval; - if (set == NULL) - return(NULL); - for (i = 0;i < set->nodeNr;i++) { - if (set->nodeTab[i] == NULL) - continue; - switch (set->nodeTab[i]->type) { - 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: - 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 */ - } - if (last == NULL) - list = last = xmlCopyNode(set->nodeTab[i], 1); - else { - xmlAddNextSibling(last, xmlCopyNode(set->nodeTab[i], 1)); - if (last->next != NULL) - last = last->next; - } - } - break; - } - case XPATH_LOCATIONSET: { - xmlLocationSetPtr set = (xmlLocationSetPtr) obj->user; - if (set == NULL) - return(NULL); - for (i = 0;i < set->locNr;i++) { - if (last == NULL) - list = last = xmlXPtrBuildNodeList(set->locTab[i]); - else - xmlAddNextSibling(last, - xmlXPtrBuildNodeList(set->locTab[i])); - if (last != NULL) { - while (last->next != NULL) - last = last->next; - } - } - break; - } - case XPATH_RANGE: - return(xmlXPtrBuildRangeNodeList(obj)); - case XPATH_POINT: - return(xmlCopyNode(obj->user, 0)); - default: - break; - } - return(list); -} - -/************************************************************************ - * * - * XPointer functions * - * * - ************************************************************************/ - -/** - * xmlXPtrNbLocChildren: - * @node: an xmlNodePtr - * - * Count the number of location children of @node or the length of the - * string value in case of text/PI/Comments nodes - * - * Returns the number of location children - */ -static int -xmlXPtrNbLocChildren(xmlNodePtr node) { - int ret = 0; - if (node == NULL) - return(-1); - switch (node->type) { - case XML_HTML_DOCUMENT_NODE: - case XML_DOCUMENT_NODE: - case XML_ELEMENT_NODE: - node = node->children; - while (node != NULL) { - if (node->type == XML_ELEMENT_NODE) - ret++; - node = node->next; - } - 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: - ret = xmlStrlen(node->content); - 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 - */ -static void -xmlXPtrHereFunction(xmlXPathParserContextPtr ctxt, int nargs) { - CHECK_ARITY(0); - - if (ctxt->context->here == NULL) - XP_ERROR(XPTR_SYNTAX_ERROR); - - valuePush(ctxt, xmlXPtrNewLocationSetNodes(ctxt->context->here, NULL)); -} - -/** - * xmlXPtrOriginFunction: - * @ctxt: the XPointer Parser context - * @nargs: the number of args - * - * Function implementing origin() operation - * as described in 5.4.3 - */ -static void -xmlXPtrOriginFunction(xmlXPathParserContextPtr ctxt, int nargs) { - CHECK_ARITY(0); - - if (ctxt->context->origin == NULL) - XP_ERROR(XPTR_SYNTAX_ERROR); - - valuePush(ctxt, xmlXPtrNewLocationSetNodes(ctxt->context->origin, NULL)); -} - -/** - * 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. - * ---------------- - * - */ -static void -xmlXPtrStartPointFunction(xmlXPathParserContextPtr ctxt, int nargs) { - xmlXPathObjectPtr tmp, obj, point; - xmlLocationSetPtr newset = NULL; - xmlLocationSetPtr oldset = NULL; - - CHECK_ARITY(1); - if ((ctxt->value == NULL) || - ((ctxt->value->type != XPATH_LOCATIONSET) && - (ctxt->value->type != XPATH_NODESET))) - XP_ERROR(XPATH_INVALID_TYPE) - - obj = valuePop(ctxt); - if (obj->type == XPATH_NODESET) { - /* - * First convert to a location set - */ - tmp = xmlXPtrNewLocationSetNodeSet(obj->nodesetval); - xmlXPathFreeObject(obj); - if (tmp == NULL) - XP_ERROR(XPATH_MEMORY_ERROR) - obj = tmp; - } - - newset = xmlXPtrLocationSetCreate(NULL); - if (newset == NULL) { - xmlXPathFreeObject(obj); - XP_ERROR(XPATH_MEMORY_ERROR); - } - oldset = (xmlLocationSetPtr) obj->user; - if (oldset != NULL) { - int i; - - for (i = 0; i < oldset->locNr; i++) { - tmp = oldset->locTab[i]; - if (tmp == NULL) - continue; - point = NULL; - switch (tmp->type) { - case XPATH_POINT: - point = xmlXPtrNewPoint(tmp->user, tmp->index); - break; - case XPATH_RANGE: { - xmlNodePtr node = tmp->user; - if (node != NULL) { - if ((node->type == XML_ATTRIBUTE_NODE) || - (node->type == XML_NAMESPACE_DECL)) { - xmlXPathFreeObject(obj); - xmlXPtrFreeLocationSet(newset); - XP_ERROR(XPTR_SYNTAX_ERROR); - } - point = xmlXPtrNewPoint(node, tmp->index); - } - break; - } - default: - /*** Should we raise an error ? - xmlXPathFreeObject(obj); - xmlXPathFreeObject(newset); - XP_ERROR(XPATH_INVALID_TYPE) - ***/ - break; - } - if (point != NULL) - xmlXPtrLocationSetAdd(newset, point); - } - } - xmlXPathFreeObject(obj); - valuePush(ctxt, xmlXPtrWrapLocationSet(newset)); -} - -/** - * 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. - * ---------------------------- - */ -static void -xmlXPtrEndPointFunction(xmlXPathParserContextPtr ctxt, int nargs) { - xmlXPathObjectPtr tmp, obj, point; - xmlLocationSetPtr newset = NULL; - xmlLocationSetPtr oldset = NULL; - - CHECK_ARITY(1); - if ((ctxt->value == NULL) || - ((ctxt->value->type != XPATH_LOCATIONSET) && - (ctxt->value->type != XPATH_NODESET))) - XP_ERROR(XPATH_INVALID_TYPE) - - obj = valuePop(ctxt); - if (obj->type == XPATH_NODESET) { - /* - * First convert to a location set - */ - tmp = xmlXPtrNewLocationSetNodeSet(obj->nodesetval); - xmlXPathFreeObject(obj); - if (tmp == NULL) - XP_ERROR(XPATH_MEMORY_ERROR) - obj = tmp; - } - - newset = xmlXPtrLocationSetCreate(NULL); - if (newset == NULL) { - xmlXPathFreeObject(obj); - XP_ERROR(XPATH_MEMORY_ERROR); - } - oldset = (xmlLocationSetPtr) obj->user; - if (oldset != NULL) { - int i; - - for (i = 0; i < oldset->locNr; i++) { - tmp = oldset->locTab[i]; - if (tmp == NULL) - continue; - point = NULL; - switch (tmp->type) { - case XPATH_POINT: - point = xmlXPtrNewPoint(tmp->user, tmp->index); - break; - case XPATH_RANGE: { - xmlNodePtr node = tmp->user2; - if (node != NULL) { - if ((node->type == XML_ATTRIBUTE_NODE) || - (node->type == XML_NAMESPACE_DECL)) { - xmlXPathFreeObject(obj); - xmlXPtrFreeLocationSet(newset); - XP_ERROR(XPTR_SYNTAX_ERROR); - } - point = xmlXPtrNewPoint(node, tmp->index2); - } else if (tmp->user == NULL) { - point = xmlXPtrNewPoint(node, - xmlXPtrNbLocChildren(node)); - } - break; - } - default: - /*** Should we raise an error ? - xmlXPathFreeObject(obj); - xmlXPathFreeObject(newset); - XP_ERROR(XPATH_INVALID_TYPE) - ***/ - break; - } - if (point != NULL) - xmlXPtrLocationSetAdd(newset, point); - } - } - xmlXPathFreeObject(obj); - valuePush(ctxt, xmlXPtrWrapLocationSet(newset)); -} - - -/** - * 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 -xmlXPtrCoveringRange(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr loc) { - if (loc == NULL) - return(NULL); - if ((ctxt == NULL) || (ctxt->context == NULL) || - (ctxt->context->doc == NULL)) - return(NULL); - switch (loc->type) { - case XPATH_POINT: - return(xmlXPtrNewRange(loc->user, loc->index, - loc->user, loc->index)); - case XPATH_RANGE: - if (loc->user2 != NULL) { - return(xmlXPtrNewRange(loc->user, loc->index, - loc->user2, loc->index2)); - } else { - xmlNodePtr node = (xmlNodePtr) loc->user; - if (node == (xmlNodePtr) ctxt->context->doc) { - return(xmlXPtrNewRange(node, 0, node, - xmlXPtrGetArity(node))); - } else { - switch (node->type) { - case XML_ATTRIBUTE_NODE: - /* !!! our model is slightly different than XPath */ - return(xmlXPtrNewRange(node, 0, node, - 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: { - int indx = xmlXPtrGetIndex(node); - - node = node->parent; - return(xmlXPtrNewRange(node, indx - 1, - node, indx + 1)); - } - default: - return(NULL); - } - } - } - default: - /* TODO: missed one case ??? */ - break; - } - 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. - */ -static void -xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt, int nargs) { - int i; - xmlXPathObjectPtr set; - xmlLocationSetPtr oldset; - xmlLocationSetPtr newset; - - CHECK_ARITY(1); - if ((ctxt->value == NULL) || - ((ctxt->value->type != XPATH_LOCATIONSET) && - (ctxt->value->type != XPATH_NODESET))) - XP_ERROR(XPATH_INVALID_TYPE) - - set = valuePop(ctxt); - if (set->type == XPATH_NODESET) { - xmlXPathObjectPtr tmp; - - /* - * First convert to a location set - */ - tmp = xmlXPtrNewLocationSetNodeSet(set->nodesetval); - xmlXPathFreeObject(set); - if (tmp == NULL) - XP_ERROR(XPATH_MEMORY_ERROR) - set = tmp; - } - oldset = (xmlLocationSetPtr) set->user; - - /* - * The loop is to compute the covering range for each item and add it - */ - newset = xmlXPtrLocationSetCreate(NULL); - if (newset == NULL) { - xmlXPathFreeObject(set); - XP_ERROR(XPATH_MEMORY_ERROR); - } - if (oldset != NULL) { - for (i = 0;i < oldset->locNr;i++) { - xmlXPtrLocationSetAdd(newset, - xmlXPtrCoveringRange(ctxt, oldset->locTab[i])); - } - } - - /* - * Save the new value and cleanup - */ - valuePush(ctxt, xmlXPtrWrapLocationSet(newset)); - xmlXPathFreeObject(set); -} - -/** - * 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 -xmlXPtrInsideRange(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr loc) { - if (loc == NULL) - return(NULL); - if ((ctxt == NULL) || (ctxt->context == NULL) || - (ctxt->context->doc == NULL)) - return(NULL); - switch (loc->type) { - case XPATH_POINT: { - xmlNodePtr node = (xmlNodePtr) loc->user; - switch (node->type) { - case XML_PI_NODE: - case XML_COMMENT_NODE: - case XML_TEXT_NODE: - case XML_CDATA_SECTION_NODE: { - if (node->content == NULL) { - return(xmlXPtrNewRange(node, 0, node, 0)); - } else { - return(xmlXPtrNewRange(node, 0, node, - xmlStrlen(node->content))); - } - } - 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: { - return(xmlXPtrNewRange(node, 0, node, - xmlXPtrGetArity(node))); - } - default: - break; - } - return(NULL); - } - case XPATH_RANGE: { - xmlNodePtr node = (xmlNodePtr) loc->user; - if (loc->user2 != NULL) { - return(xmlXPtrNewRange(node, loc->index, - loc->user2, loc->index2)); - } else { - switch (node->type) { - case XML_PI_NODE: - case XML_COMMENT_NODE: - case XML_TEXT_NODE: - case XML_CDATA_SECTION_NODE: { - if (node->content == NULL) { - return(xmlXPtrNewRange(node, 0, node, 0)); - } else { - return(xmlXPtrNewRange(node, 0, node, - xmlStrlen(node->content))); - } - } - 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: { - return(xmlXPtrNewRange(node, 0, node, - xmlXPtrGetArity(node))); - } - default: - break; - } - return(NULL); - } - } - default: - /* TODO: missed one case ??? */ - break; - } - 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. - * - */ -static void -xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt, int nargs) { - int i; - xmlXPathObjectPtr set; - xmlLocationSetPtr oldset; - xmlLocationSetPtr newset; - - CHECK_ARITY(1); - if ((ctxt->value == NULL) || - ((ctxt->value->type != XPATH_LOCATIONSET) && - (ctxt->value->type != XPATH_NODESET))) - XP_ERROR(XPATH_INVALID_TYPE) - - set = valuePop(ctxt); - if (set->type == XPATH_NODESET) { - xmlXPathObjectPtr tmp; - - /* - * First convert to a location set - */ - tmp = xmlXPtrNewLocationSetNodeSet(set->nodesetval); - xmlXPathFreeObject(set); - if (tmp == NULL) - XP_ERROR(XPATH_MEMORY_ERROR) - set = tmp; - } - - /* - * The loop is to compute the covering range for each item and add it - */ - newset = xmlXPtrLocationSetCreate(NULL); - if (newset == NULL) { - xmlXPathFreeObject(set); - XP_ERROR(XPATH_MEMORY_ERROR); - } - oldset = (xmlLocationSetPtr) set->user; - if (oldset != NULL) { - for (i = 0;i < oldset->locNr;i++) { - xmlXPtrLocationSetAdd(newset, - xmlXPtrInsideRange(ctxt, oldset->locTab[i])); - } - } - - /* - * Save the new value and cleanup - */ - valuePush(ctxt, xmlXPtrWrapLocationSet(newset)); - xmlXPathFreeObject(set); -} - -/** - * xmlXPtrRangeToFunction: - * @ctxt: the XPointer Parser context - * @nargs: the number of args - * - * Implement the range-to() XPointer function - * - * Obsolete. range-to is not a real function but a special type of location - * step which is handled in xpath.c. - */ -void -xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt, - int nargs ATTRIBUTE_UNUSED) { - XP_ERROR(XPATH_EXPR_ERROR); -} - -/** - * xmlXPtrAdvanceNode: - * @cur: the node - * @level: incremented/decremented to show level in tree - * - * Advance to the next element or text node in document order - * TODO: add a stack for entering/exiting entities - * - * Returns -1 in case of failure, 0 otherwise - */ -xmlNodePtr -xmlXPtrAdvanceNode(xmlNodePtr cur, int *level) { -next: - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) - return(NULL); - if (cur->children != NULL) { - cur = cur->children ; - if (level != NULL) - (*level)++; - goto found; - } -skip: /* This label should only be needed if something is wrong! */ - if (cur->next != NULL) { - cur = cur->next; - goto found; - } - do { - cur = cur->parent; - if (level != NULL) - (*level)--; - if (cur == NULL) return(NULL); - if (cur->next != NULL) { - cur = cur->next; - goto found; - } - } while (cur != NULL); - -found: - if ((cur->type != XML_ELEMENT_NODE) && - (cur->type != XML_TEXT_NODE) && - (cur->type != XML_DOCUMENT_NODE) && - (cur->type != XML_HTML_DOCUMENT_NODE) && - (cur->type != XML_CDATA_SECTION_NODE)) { - if (cur->type == XML_ENTITY_REF_NODE) { /* Shouldn't happen */ - 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 -xmlXPtrAdvanceChar(xmlNodePtr *node, int *indx, int bytes) { - xmlNodePtr cur; - int pos; - int len; - - if ((node == NULL) || (indx == NULL)) - return(-1); - cur = *node; - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) - return(-1); - pos = *indx; - - while (bytes >= 0) { - /* - * First position to the beginning of the first text node - * corresponding to this point - */ - while ((cur != NULL) && - ((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_DOCUMENT_NODE) || - (cur->type == XML_HTML_DOCUMENT_NODE))) { - if (pos > 0) { - cur = xmlXPtrGetNthChild(cur, pos); - pos = 0; - } else { - cur = xmlXPtrAdvanceNode(cur, NULL); - pos = 0; - } - } - - if (cur == NULL) { - *node = NULL; - *indx = 0; - return(-1); - } - - /* - * if there is no move needed return the current value. - */ - if (pos == 0) pos = 1; - if (bytes == 0) { - *node = cur; - *indx = pos; - return(0); - } - /* - * We should have a text (or cdata) node ... - */ - len = 0; - if ((cur->type != XML_ELEMENT_NODE) && - (cur->content != NULL)) { - len = xmlStrlen(cur->content); - } - if (pos > len) { - /* Strange, the indx in the text node is greater than it's len */ - pos = len; - } - if (pos + bytes >= len) { - bytes -= (len - pos); - cur = xmlXPtrAdvanceNode(cur, NULL); - pos = 0; - } else if (pos + bytes < len) { - pos += bytes; - *node = cur; - *indx = pos; - return(0); - } - } - return(-1); -} - -/** - * xmlXPtrMatchString: - * @string: the string to search - * @start: the start textnode - * @startindex: the start index - * @end: the end textnode IN/OUT - * @endindex: the end index IN/OUT - * - * 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 -xmlXPtrMatchString(const xmlChar *string, xmlNodePtr start, int startindex, - xmlNodePtr *end, int *endindex) { - xmlNodePtr cur; - int pos; /* 0 based */ - int len; /* in bytes */ - int stringlen; /* in bytes */ - int match; - - if (string == NULL) - return(-1); - if ((start == NULL) || (start->type == XML_NAMESPACE_DECL)) - return(-1); - if ((end == NULL) || (*end == NULL) || - ((*end)->type == XML_NAMESPACE_DECL) || (endindex == NULL)) - return(-1); - cur = start; - pos = startindex - 1; - stringlen = xmlStrlen(string); - - while (stringlen > 0) { - if ((cur == *end) && (pos + stringlen > *endindex)) - return(0); - - if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { - len = xmlStrlen(cur->content); - if (len >= pos + stringlen) { - match = (!xmlStrncmp(&cur->content[pos], string, stringlen)); - if (match) { - *end = cur; - *endindex = pos + stringlen; - return(1); - } else { - return(0); - } - } else { - int sub = len - pos; - match = (!xmlStrncmp(&cur->content[pos], string, sub)); - if (match) { - string = &string[sub]; - stringlen -= sub; - } else { - return(0); - } - } - } - cur = xmlXPtrAdvanceNode(cur, NULL); - if (cur == NULL) - return(0); - pos = 0; - } - return(1); -} - -/** - * xmlXPtrSearchString: - * @string: the string to search - * @start: the start textnode IN/OUT - * @startindex: the start index IN/OUT - * @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 -xmlXPtrSearchString(const xmlChar *string, xmlNodePtr *start, int *startindex, - xmlNodePtr *end, int *endindex) { - xmlNodePtr cur; - const xmlChar *str; - int pos; /* 0 based */ - int len; /* in bytes */ - xmlChar first; - - if (string == NULL) - return(-1); - if ((start == NULL) || (*start == NULL) || - ((*start)->type == XML_NAMESPACE_DECL) || (startindex == NULL)) - return(-1); - if ((end == NULL) || (endindex == NULL)) - return(-1); - cur = *start; - pos = *startindex - 1; - first = string[0]; - - while (cur != NULL) { - if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { - len = xmlStrlen(cur->content); - while (pos <= len) { - if (first != 0) { - str = xmlStrchr(&cur->content[pos], first); - if (str != NULL) { - pos = (str - (xmlChar *)(cur->content)); - if (xmlXPtrMatchString(string, cur, pos + 1, - end, endindex)) { - *start = cur; - *startindex = pos + 1; - return(1); - } - pos++; - } else { - pos = len + 1; - } - } else { - /* - * An empty string is considered to match before each - * character of the string-value and after the final - * character. - */ - *start = cur; - *startindex = pos + 1; - *end = cur; - *endindex = pos + 1; - return(1); - } - } - } - if ((cur == *end) && (pos >= *endindex)) - return(0); - cur = xmlXPtrAdvanceNode(cur, NULL); - if (cur == NULL) - 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 -xmlXPtrGetLastChar(xmlNodePtr *node, int *indx) { - xmlNodePtr cur; - int pos, len = 0; - - if ((node == NULL) || (*node == NULL) || - ((*node)->type == XML_NAMESPACE_DECL) || (indx == NULL)) - return(-1); - cur = *node; - pos = *indx; - - if ((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_DOCUMENT_NODE) || - (cur->type == XML_HTML_DOCUMENT_NODE)) { - if (pos > 0) { - cur = xmlXPtrGetNthChild(cur, pos); - } - } - while (cur != NULL) { - if (cur->last != NULL) - cur = cur->last; - else if ((cur->type != XML_ELEMENT_NODE) && - (cur->content != NULL)) { - len = xmlStrlen(cur->content); - break; - } else { - return(-1); - } - } - if (cur == NULL) - return(-1); - *node = cur; - *indx = len; - 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 -xmlXPtrGetStartPoint(xmlXPathObjectPtr obj, xmlNodePtr *node, int *indx) { - if ((obj == NULL) || (node == NULL) || (indx == NULL)) - return(-1); - - switch (obj->type) { - case XPATH_POINT: - *node = obj->user; - if (obj->index <= 0) - *indx = 0; - else - *indx = obj->index; - return(0); - case XPATH_RANGE: - *node = obj->user; - if (obj->index <= 0) - *indx = 0; - else - *indx = obj->index; - 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 -xmlXPtrGetEndPoint(xmlXPathObjectPtr obj, xmlNodePtr *node, int *indx) { - if ((obj == NULL) || (node == NULL) || (indx == NULL)) - return(-1); - - switch (obj->type) { - case XPATH_POINT: - *node = obj->user; - if (obj->index <= 0) - *indx = 0; - else - *indx = obj->index; - return(0); - case XPATH_RANGE: - *node = obj->user; - if (obj->index <= 0) - *indx = 0; - else - *indx = obj->index; - 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. - * ------------------------------ - */ -static void -xmlXPtrStringRangeFunction(xmlXPathParserContextPtr ctxt, int nargs) { - int i, startindex, endindex = 0, fendindex; - xmlNodePtr start, end = 0, fend; - xmlXPathObjectPtr set = NULL; - xmlLocationSetPtr oldset; - xmlLocationSetPtr newset = NULL; - xmlXPathObjectPtr string = NULL; - xmlXPathObjectPtr position = NULL; - xmlXPathObjectPtr number = NULL; - int found, pos = 0, num = 0; - - /* - * Grab the arguments - */ - if ((nargs < 2) || (nargs > 4)) - XP_ERROR(XPATH_INVALID_ARITY); - - if (nargs >= 4) { - if ((ctxt->value == NULL) || (ctxt->value->type != XPATH_NUMBER)) { - xmlXPathErr(ctxt, XPATH_INVALID_TYPE); - goto error; - } - number = valuePop(ctxt); - if (number != NULL) - num = (int) number->floatval; - } - if (nargs >= 3) { - if ((ctxt->value == NULL) || (ctxt->value->type != XPATH_NUMBER)) { - xmlXPathErr(ctxt, XPATH_INVALID_TYPE); - goto error; - } - position = valuePop(ctxt); - if (position != NULL) - pos = (int) position->floatval; - } - if ((ctxt->value == NULL) || (ctxt->value->type != XPATH_STRING)) { - xmlXPathErr(ctxt, XPATH_INVALID_TYPE); - goto error; - } - string = valuePop(ctxt); - if ((ctxt->value == NULL) || - ((ctxt->value->type != XPATH_LOCATIONSET) && - (ctxt->value->type != XPATH_NODESET))) { - xmlXPathErr(ctxt, XPATH_INVALID_TYPE); - goto error; - } - set = valuePop(ctxt); - newset = xmlXPtrLocationSetCreate(NULL); - if (newset == NULL) { - xmlXPathErr(ctxt, XPATH_MEMORY_ERROR); - goto error; - } - if (set->nodesetval == NULL) { - goto error; - } - if (set->type == XPATH_NODESET) { - xmlXPathObjectPtr tmp; - - /* - * First convert to a location set - */ - tmp = xmlXPtrNewLocationSetNodeSet(set->nodesetval); - xmlXPathFreeObject(set); - set = NULL; - if (tmp == NULL) { - xmlXPathErr(ctxt, XPATH_MEMORY_ERROR); - goto error; - } - set = tmp; - } - oldset = (xmlLocationSetPtr) set->user; - - /* - * The loop is to search for each element in the location set - * the list of location set corresponding to that search - */ - for (i = 0;i < oldset->locNr;i++) { - - xmlXPtrGetStartPoint(oldset->locTab[i], &start, &startindex); - xmlXPtrGetEndPoint(oldset->locTab[i], &end, &endindex); - xmlXPtrAdvanceChar(&start, &startindex, 0); - xmlXPtrGetLastChar(&end, &endindex); - - do { - fend = end; - fendindex = endindex; - found = xmlXPtrSearchString(string->stringval, &start, &startindex, - &fend, &fendindex); - if (found == 1) { - if (position == NULL) { - xmlXPtrLocationSetAdd(newset, - xmlXPtrNewRange(start, startindex, fend, fendindex)); - } else if (xmlXPtrAdvanceChar(&start, &startindex, - pos - 1) == 0) { - if ((number != NULL) && (num > 0)) { - int rindx; - xmlNodePtr rend; - rend = start; - rindx = startindex - 1; - if (xmlXPtrAdvanceChar(&rend, &rindx, - num) == 0) { - xmlXPtrLocationSetAdd(newset, - xmlXPtrNewRange(start, startindex, - rend, rindx)); - } - } else if ((number != NULL) && (num <= 0)) { - xmlXPtrLocationSetAdd(newset, - xmlXPtrNewRange(start, startindex, - start, startindex)); - } else { - xmlXPtrLocationSetAdd(newset, - xmlXPtrNewRange(start, startindex, - fend, fendindex)); - } - } - start = fend; - startindex = fendindex; - if (string->stringval[0] == 0) - startindex++; - } - } while (found == 1); - } - - /* - * Save the new value and cleanup - */ -error: - if (newset != NULL) - valuePush(ctxt, xmlXPtrWrapLocationSet(newset)); - xmlXPathFreeObject(set); - xmlXPathFreeObject(string); - if (position) xmlXPathFreeObject(position); - if (number) xmlXPathFreeObject(number); -} - -/** - * 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 -xmlXPtrEvalRangePredicate(xmlXPathParserContextPtr ctxt) { - const xmlChar *cur; - xmlXPathObjectPtr res; - xmlXPathObjectPtr obj, tmp; - xmlLocationSetPtr newset = NULL; - xmlLocationSetPtr oldset; - int i; - - if (ctxt == NULL) return; - - SKIP_BLANKS; - if (CUR != '[') { - XP_ERROR(XPATH_INVALID_PREDICATE_ERROR); - } - NEXT; - SKIP_BLANKS; - - /* - * 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. - */ - CHECK_TYPE(XPATH_LOCATIONSET); - obj = valuePop(ctxt); - oldset = obj->user; - ctxt->context->node = NULL; - - if ((oldset == NULL) || (oldset->locNr == 0)) { - ctxt->context->contextSize = 0; - ctxt->context->proximityPosition = 0; - xmlXPathEvalExpr(ctxt); - res = valuePop(ctxt); - if (res != NULL) - xmlXPathFreeObject(res); - valuePush(ctxt, obj); - CHECK_ERROR; - } else { - /* - * Save the expression pointer since we will have to evaluate - * it multiple times. Initialize the new set. - */ - cur = ctxt->cur; - newset = xmlXPtrLocationSetCreate(NULL); - - for (i = 0; i < oldset->locNr; i++) { - ctxt->cur = cur; - - /* - * Run the evaluation with a node list made of a single item - * in the nodeset. - */ - ctxt->context->node = oldset->locTab[i]->user; - tmp = xmlXPathNewNodeSet(ctxt->context->node); - valuePush(ctxt, tmp); - ctxt->context->contextSize = oldset->locNr; - ctxt->context->proximityPosition = i + 1; - - xmlXPathEvalExpr(ctxt); - CHECK_ERROR; - - /* - * The result of the evaluation need to be tested to - * decided whether the filter succeeded or not - */ - res = valuePop(ctxt); - if (xmlXPathEvaluatePredicateResult(ctxt, res)) { - xmlXPtrLocationSetAdd(newset, - xmlXPathObjectCopy(oldset->locTab[i])); - } - - /* - * Cleanup - */ - if (res != NULL) - xmlXPathFreeObject(res); - if (ctxt->value == tmp) { - res = valuePop(ctxt); - xmlXPathFreeObject(res); - } - - ctxt->context->node = NULL; - } - - /* - * The result is used as the new evaluation set. - */ - xmlXPathFreeObject(obj); - ctxt->context->node = NULL; - ctxt->context->contextSize = -1; - ctxt->context->proximityPosition = -1; - valuePush(ctxt, xmlXPtrWrapLocationSet(newset)); - } - if (CUR != ']') { - XP_ERROR(XPATH_INVALID_PREDICATE_ERROR); - } - - NEXT; - SKIP_BLANKS; -} -#endif /* LIBXML_XPTR_LOCS_ENABLED */ - #endif