summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2001-01-25 13:55:35 +0000
committerDaniel Veillard <veillard@src.gnome.org>2001-01-25 13:55:35 +0000
commitf17e09bcc8e69f124b4571309f7fa3785550d269 (patch)
treee9a868cc1f7650f4bc6ccb163d9b139422c68cdb
parent48177c22d709ddfa33228b9a3653afa866e17bbf (diff)
downloadlibxml2-f17e09bcc8e69f124b4571309f7fa3785550d269.tar.gz
Incorporated patches, some cleanup:
- xpath.[ch] xpointer.c: added xmlXPathCmpNodes, changed xmlXPtrCmpPoints to use it. - propagated the following patch from Alejandro Forero - include/win32config.h xmlIO.c: applied further suggestions from Igor Zlatkovic <igorz@dialup.nacamar.de> and cleanup - example/gjobread.c: fixed warnings, now that it builds Daniel
-rw-r--r--ChangeLog21
-rw-r--r--aclocal.m440
-rw-r--r--configure.in1
-rw-r--r--example/gjobread.c57
-rw-r--r--include/libxml/xpath.h2
-rw-r--r--include/win32config.h3
-rw-r--r--xmlIO.c86
-rw-r--r--xpath.c111
-rw-r--r--xpath.h2
-rw-r--r--xpointer.c56
10 files changed, 278 insertions, 101 deletions
diff --git a/ChangeLog b/ChangeLog
index 4f3bb44f..2f1fe248 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+Thu Jan 25 13:34:11 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+ * xpath.[ch] xpointer.c: added xmlXPathCmpNodes, changed
+ xmlXPtrCmpPoints to use it.
+ * propagated the following patch from Alejandro Forero
+ * include/win32config.h xmlIO.c: applied further suggestions
+ from Igor Zlatkovic <igorz@dialup.nacamar.de> and cleanup
+ * example/gjobread.c: fixed warnings, now that it builds
+
+Wed Jan 24 20:27:28 COT 2001 Alejandro Forero <bachue@bachue.com>
+
+ * xmlIO.c (xmlFileOpen, xmlFileOpenW): Removed unnecesary checks.
+
+ * xmlIO.c (xmlCheckFilename): Function added to know whether a given
+ filename points to a valid file (not a directory).
+ * xmlIO.c (xmlFileOpen, xmlFileOpenW, xmlGzfileOpen, xmlGzfileOpenW):
+ Added calls to xmlCheckFilenameDir.
+
+ * xmlIO.c (xmlGzfileOpen, xmlGzfileOpenW, xmlFdOpen, xmlFdOpenW): Pass
+ `path' (rather than `filename') as the parameter to gzopen and open.
+
Tue Jan 23 16:26:30 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* Makefile.am: fixed a problem with EXTRA_DIST
diff --git a/aclocal.m4 b/aclocal.m4
index 869e5fcc..e3726759 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -620,31 +620,35 @@ esac
])
# AC_LIBLTDL_CONVENIENCE[(dir)] - sets LIBLTDL to the link flags for
-# the libltdl convenience library, adds --enable-ltdl-convenience to
-# the configure arguments. Note that LIBLTDL is not AC_SUBSTed, nor
-# is AC_CONFIG_SUBDIRS called. If DIR is not provided, it is assumed
-# to be `${top_builddir}/libltdl'. Make sure you start DIR with
-# '${top_builddir}/' (note the single quotes!) if your package is not
-# flat, and, if you're not using automake, define top_builddir as
-# appropriate in the Makefiles.
+# the libltdl convenience library and INCLTDL to the include flags for
+# the libltdl header and adds --enable-ltdl-convenience to the
+# configure arguments. Note that LIBLTDL and INCLTDL are not
+# AC_SUBSTed, nor is AC_CONFIG_SUBDIRS called. If DIR is not
+# provided, it is assumed to be `libltdl'. LIBLTDL will be prefixed
+# with '${top_builddir}/' and INCLTDL will be prefixed with
+# '${top_srcdir}/' (note the single quotes!). If your package is not
+# flat and you're not using automake, define top_builddir and
+# top_srcdir appropriately in the Makefiles.
AC_DEFUN(AC_LIBLTDL_CONVENIENCE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
case "$enable_ltdl_convenience" in
no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;;
"") enable_ltdl_convenience=yes
ac_configure_args="$ac_configure_args --enable-ltdl-convenience" ;;
esac
- LIBLTDL=ifelse($#,1,$1,['${top_builddir}/libltdl'])/libltdlc.la
- INCLTDL=ifelse($#,1,-I$1,['-I${top_builddir}/libltdl'])
+ LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdlc.la
+ INCLTDL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
])
# AC_LIBLTDL_INSTALLABLE[(dir)] - sets LIBLTDL to the link flags for
-# the libltdl installable library, and adds --enable-ltdl-install to
-# the configure arguments. Note that LIBLTDL is not AC_SUBSTed, nor
-# is AC_CONFIG_SUBDIRS called. If DIR is not provided, it is assumed
-# to be `${top_builddir}/libltdl'. Make sure you start DIR with
-# '${top_builddir}/' (note the single quotes!) if your package is not
-# flat, and, if you're not using automake, define top_builddir as
-# appropriate in the Makefiles.
+# the libltdl installable library and INCLTDL to the include flags for
+# the libltdl header and adds --enable-ltdl-install to the configure
+# arguments. Note that LIBLTDL and INCLTDL are not AC_SUBSTed, nor is
+# AC_CONFIG_SUBDIRS called. If DIR is not provided and an installed
+# libltdl is not found, it is assumed to be `libltdl'. LIBLTDL will
+# be prefixed with '${top_builddir}/' and INCLTDL will be prefixed
+# with '${top_srcdir}/' (note the single quotes!). If your package is
+# not flat and you're not using automake, define top_builddir and
+# top_srcdir appropriately in the Makefiles.
# In the future, this macro may have to be called after AC_PROG_LIBTOOL.
AC_DEFUN(AC_LIBLTDL_INSTALLABLE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
AC_CHECK_LIB(ltdl, main,
@@ -657,8 +661,8 @@ AC_DEFUN(AC_LIBLTDL_INSTALLABLE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
])
if test x"$enable_ltdl_install" = x"yes"; then
ac_configure_args="$ac_configure_args --enable-ltdl-install"
- LIBLTDL=ifelse($#,1,$1,['${top_builddir}/libltdl'])/libltdl.la
- INCLTDL=ifelse($#,1,-I$1,['-I${top_builddir}/libltdl'])
+ LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdl.la
+ INCLTDL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
else
ac_configure_args="$ac_configure_args --enable-ltdl-install=no"
LIBLTDL="-lltdl"
diff --git a/configure.in b/configure.in
index fb532b62..b9fdd214 100644
--- a/configure.in
+++ b/configure.in
@@ -103,6 +103,7 @@ AC_FUNC_STRFTIME
AC_CHECK_FUNCS(strdup strndup strerror snprintf)
AC_CHECK_FUNCS(finite isnand fp_class class fpclass)
AC_CHECK_FUNCS(strftime localtime)
+AC_CHECK_FUNCS(stat _stat)
dnl Checks for inet libraries:
AC_CHECK_FUNC(gethostent, , AC_CHECK_LIB(nsl, gethostent))
diff --git a/example/gjobread.c b/example/gjobread.c
index cfd26d19..e4151739 100644
--- a/example/gjobread.c
+++ b/example/gjobread.c
@@ -27,15 +27,16 @@
/*
* A person record
+ * an xmlChar * is really an UTF8 encoded char string (0 terminated)
*/
typedef struct person {
- char *name;
- char *email;
- char *company;
- char *organisation;
- char *smail;
- char *webPage;
- char *phone;
+ xmlChar *name;
+ xmlChar *email;
+ xmlChar *company;
+ xmlChar *organisation;
+ xmlChar *smail;
+ xmlChar *webPage;
+ xmlChar *phone;
} person, *personPtr;
/*
@@ -59,9 +60,11 @@ DEBUG("parsePerson\n");
/* COMPAT xmlChildrenNode is a macro unifying libxml1 and libxml2 names */
cur = cur->xmlChildrenNode;
while (cur != NULL) {
- if ((!strcmp(cur->name, "Person")) && (cur->ns == ns))
+ if ((!xmlStrcmp(cur->name, (const xmlChar *)"Person")) &&
+ (cur->ns == ns))
ret->name = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- if ((!strcmp(cur->name, "Email")) && (cur->ns == ns))
+ if ((!xmlStrcmp(cur->name, (const xmlChar *)"Email")) &&
+ (cur->ns == ns))
ret->email = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
cur = cur->next;
}
@@ -89,9 +92,9 @@ void printPerson(personPtr cur) {
* a Description for a Job
*/
typedef struct job {
- char *projectID;
- char *application;
- char *category;
+ xmlChar *projectID;
+ xmlChar *application;
+ xmlChar *category;
personPtr contact;
int nbDevelopers;
personPtr developers[100]; /* using dynamic alloc is left as an exercise */
@@ -118,17 +121,23 @@ DEBUG("parseJob\n");
cur = cur->xmlChildrenNode;
while (cur != NULL) {
- if ((!strcmp(cur->name, "Project")) && (cur->ns == ns)) {
- ret->projectID = xmlGetProp(cur, "ID");
+ if ((!xmlStrcmp(cur->name, (const xmlChar *) "Project")) &&
+ (cur->ns == ns)) {
+ ret->projectID = xmlGetProp(cur, (const xmlChar *) "ID");
if (ret->projectID == NULL) {
fprintf(stderr, "Project has no ID\n");
}
}
- if ((!strcmp(cur->name, "Application")) && (cur->ns == ns))
- ret->application = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- if ((!strcmp(cur->name, "Category")) && (cur->ns == ns))
- ret->category = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- if ((!strcmp(cur->name, "Contact")) && (cur->ns == ns))
+ if ((!xmlStrcmp(cur->name, (const xmlChar *) "Application")) &&
+ (cur->ns == ns))
+ ret->application =
+ xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+ if ((!xmlStrcmp(cur->name, (const xmlChar *) "Category")) &&
+ (cur->ns == ns))
+ ret->category =
+ xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+ if ((!xmlStrcmp(cur->name, (const xmlChar *) "Contact")) &&
+ (cur->ns == ns))
ret->contact = parsePerson(doc, ns, cur);
cur = cur->next;
}
@@ -186,14 +195,15 @@ gJobPtr parseGjobFile(char *filename) {
xmlFreeDoc(doc);
return(NULL);
}
- ns = xmlSearchNsByHref(doc, cur, "http://www.gnome.org/some-location");
+ ns = xmlSearchNsByHref(doc, cur,
+ (const xmlChar *) "http://www.gnome.org/some-location");
if (ns == NULL) {
fprintf(stderr,
"document of the wrong type, GJob Namespace not found\n");
xmlFreeDoc(doc);
return(NULL);
}
- if (strcmp(cur->name, "Helping")) {
+ if (xmlStrcmp(cur->name, (const xmlChar *) "Helping")) {
fprintf(stderr,"document of the wrong type, root node != Helping");
xmlFreeDoc(doc);
return(NULL);
@@ -221,7 +231,7 @@ gJobPtr parseGjobFile(char *filename) {
}
if ( cur == 0 )
return ( NULL );
- if ((strcmp(cur->name, "Jobs")) || (cur->ns != ns)) {
+ if ((xmlStrcmp(cur->name, (const xmlChar *) "Jobs")) || (cur->ns != ns)) {
fprintf(stderr,"document of the wrong type, was '%s', Jobs expected",
cur->name);
fprintf(stderr,"xmlDocDump follows\n");
@@ -235,7 +245,8 @@ gJobPtr parseGjobFile(char *filename) {
/* Second level is a list of Job, but be laxist */
cur = cur->xmlChildrenNode;
while (cur != NULL) {
- if ((!strcmp(cur->name, "Job")) && (cur->ns == ns)) {
+ if ((!xmlStrcmp(cur->name, (const xmlChar *) "Job")) &&
+ (cur->ns == ns)) {
job = parseJob(doc, ns, cur);
if (job != NULL)
ret->jobs[ret->nbJobs++] = job;
diff --git a/include/libxml/xpath.h b/include/libxml/xpath.h
index 347accff..ca98a184 100644
--- a/include/libxml/xpath.h
+++ b/include/libxml/xpath.h
@@ -265,6 +265,8 @@ xmlNodeSetPtr xmlXPathNodeSetCreate (xmlNodePtr val);
void xmlXPathFreeNodeSetList (xmlXPathObjectPtr obj);
void xmlXPathFreeNodeSet (xmlNodeSetPtr obj);
xmlXPathObjectPtr xmlXPathObjectCopy (xmlXPathObjectPtr val);
+int xmlXPathCmpNodes (xmlNodePtr node1,
+ xmlNodePtr node2);
#ifdef __cplusplus
diff --git a/include/win32config.h b/include/win32config.h
index 5f544a6b..ea2cd506 100644
--- a/include/win32config.h
+++ b/include/win32config.h
@@ -87,3 +87,6 @@ static int isnan (double d) {
}
#include <direct.h>
+
+#define HAVE_SYS_STAT_H #define HAVE__STAT
+
diff --git a/xmlIO.c b/xmlIO.c
index 38de6592..d1554c26 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <string.h>
+#include <errno.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
@@ -36,6 +37,32 @@
#include <zlib.h>
#endif
+/* Figure a portable way to know if a file is a directory. */
+#ifndef HAVE_STAT
+# ifdef HAVE__STAT
+# define stat(x,y) _stat(x,y)
+# define HAVE_STAT
+# endif
+#endif
+#ifdef HAVE_STAT
+# ifndef S_ISDIR
+# ifdef _S_ISDIR
+# define S_ISDIR(x) _S_ISDIR(x)
+# else
+# ifdef S_IFDIR
+# ifndef S_IFMT
+# ifdef _S_IFMT
+# define S_IFMT _S_IFMT
+# endif
+# endif
+# ifdef S_IFMT
+# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+# endif
+# endif
+# endif
+# endif
+#endif
+
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
@@ -97,6 +124,41 @@ int xmlOutputCallbackInitialized = 0;
* *
************************************************************************/
+/**
+ * xmlCheckFilename
+ * @path: the path to check
+ *
+ * function checks to see if @path is a valid source
+ * (file, socket...) for XML.
+ *
+ * if stat is not available on the target machine,
+ * returns 1. if stat fails, returns 0 (if calling
+ * stat on the filename fails, it can't be right).
+ * if stat succeeds and the file is a directory,
+ * sets errno to EISDIR and returns 0. otherwise
+ * returns 1.
+ */
+
+static int
+xmlCheckFilename (const char *path)
+{
+#ifdef HAVE_STAT
+#ifdef S_ISDIR
+ struct stat stat_buffer;
+
+ if (stat(path, &stat_buffer) == -1)
+ return 0;
+
+ if (S_ISDIR(stat_buffer.st_mode)) {
+ errno = EISDIR;
+ return 0;
+ }
+
+#endif
+#endif
+ return 1;
+}
+
int
xmlNop(void) {
return(0);
@@ -144,9 +206,9 @@ xmlFdOpen (const char *filename) {
return(NULL);
#ifdef WIN32
- fd = _open (filename, O_RDONLY | _O_BINARY);
+ fd = _open (path, O_RDONLY | _O_BINARY);
#else
- fd = open (filename, O_RDONLY);
+ fd = open (path, O_RDONLY);
#endif
return((void *) fd);
@@ -180,7 +242,7 @@ xmlFdOpenW (const char *filename) {
if (path == NULL)
return(NULL);
- fd = open (filename, O_WRONLY);
+ fd = open (path, O_WRONLY);
return((void *) fd);
}
@@ -264,8 +326,11 @@ xmlFileOpen (const char *filename) {
path = &filename[8];
else
path = filename;
+
if (path == NULL)
return(NULL);
+ if (!xmlCheckFilename(path))
+ return(NULL);
#ifdef WIN32
fd = fopen(path, "rb");
@@ -300,8 +365,11 @@ xmlFileOpenW (const char *filename) {
path = &filename[8];
else
path = filename;
+
if (path == NULL)
return(NULL);
+ if (!xmlCheckFilename(path))
+ return(NULL);
fd = fopen(path, "w");
return((void *) fd);
@@ -404,6 +472,11 @@ xmlGzfileOpen (const char *filename) {
else
path = filename;
+ if (path == NULL)
+ return(NULL);
+ if (!xmlCheckFilename(path))
+ return(NULL);
+
fd = gzopen(path, "rb");
return((void *) fd);
}
@@ -437,7 +510,12 @@ xmlGzfileOpenW (const char *filename, int compression) {
else
path = filename;
- fd = gzopen(filename, mode);
+ if (path == NULL)
+ return(NULL);
+ if (!xmlCheckFilename(path))
+ return(NULL);
+
+ fd = gzopen(path, mode);
return((void *) fd);
}
diff --git a/xpath.c b/xpath.c
index 409c12d6..dc972449 100644
--- a/xpath.c
+++ b/xpath.c
@@ -34,7 +34,7 @@
#ifdef HAVE_MATH_H
#include <math.h>
#endif
-#ifdef HAVE_MATH_H
+#ifdef HAVE_FLOAT_H
#include <float.h>
#endif
#ifdef HAVE_IEEEFP_H
@@ -508,6 +508,82 @@ xmlXPatherror(xmlXPathParserContextPtr ctxt, const char *file,
* *
************************************************************************/
+/**
+ * xmlXPathCmpNodes:
+ * @node1: the first node
+ * @node2: the second node
+ *
+ * Compare two nodes w.r.t document order
+ *
+ * Returns -2 in case of error 1 if first point < second point, 0 if
+ * that's the same point, -1 otherwise
+ */
+int
+xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) {
+ int depth1, depth2;
+ xmlNodePtr cur, root;
+
+ if ((node1 == NULL) || (node2 == NULL))
+ return(-2);
+ /*
+ * a couple of optimizations which will avoid computations in most cases
+ */
+ if (node1 == node2)
+ return(0);
+ if (node1 == node2->prev)
+ return(1);
+ if (node1 == node2->next)
+ return(-1);
+
+ /*
+ * compute depth to root
+ */
+ for (depth2 = 0, cur = node2;cur->parent != NULL;cur = cur->parent) {
+ if (cur == node1)
+ return(1);
+ depth2++;
+ }
+ root = cur;
+ for (depth1 = 0, cur = node1;cur->parent != NULL;cur = cur->parent) {
+ if (cur == node2)
+ return(-1);
+ depth1++;
+ }
+ /*
+ * Distinct document (or distinct entities :-( ) case.
+ */
+ if (root != cur) {
+ return(-2);
+ }
+ /*
+ * get the nearest common ancestor.
+ */
+ while (depth1 > depth2) {
+ depth1--;
+ node1 = node1->parent;
+ }
+ while (depth2 > depth1) {
+ depth2--;
+ node2 = node2->parent;
+ }
+ while (node1->parent != node2->parent) {
+ node1 = node1->parent;
+ node2 = node2->parent;
+ /* should not happen but just in case ... */
+ if ((node1 == NULL) || (node2 == NULL))
+ return(-2);
+ }
+ /*
+ * Find who's first.
+ */
+ if (node1 == node2->next)
+ return(-1);
+ for (cur = node1->next;cur != NULL;cur = cur->next)
+ if (cur == node2)
+ return(1);
+ return(-1); /* assume there is no sibling list corruption */
+}
+
#define XML_NODESET_DEFAULT 10
/**
* xmlXPathNodeSetCreate:
@@ -3175,6 +3251,7 @@ xmlXPathRoot(xmlXPathParserContextPtr ctxt) {
/**
* xmlXPathLastFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the last() XPath function
* number last()
@@ -3197,6 +3274,7 @@ xmlXPathLastFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathPositionFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the position() XPath function
* number position()
@@ -3222,6 +3300,7 @@ xmlXPathPositionFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathCountFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the count() XPath function
* number count(node-set)
@@ -3241,6 +3320,7 @@ xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathIdFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the id() XPath function
* node-set id(object)
@@ -3338,6 +3418,7 @@ xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathLocalNameFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the local-name() XPath function
* string local-name(node-set?)
@@ -3385,6 +3466,7 @@ xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathNamespaceURIFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the namespace-uri() XPath function
* string namespace-uri(node-set?)
@@ -3430,6 +3512,7 @@ xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathNameFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the name() XPath function
* string name(node-set?)
@@ -3500,6 +3583,7 @@ xmlXPathNameFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathStringFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the string() XPath function
* string string(object?)
@@ -3602,6 +3686,7 @@ xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathStringLengthFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the string-length() XPath function
* number string-length(string?)
@@ -3637,6 +3722,7 @@ xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathConcatFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the concat() XPath function
* string concat(string, string, string*)
@@ -3680,6 +3766,7 @@ xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathContainsFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the contains() XPath function
* boolean contains(string, string)
@@ -3712,6 +3799,7 @@ xmlXPathContainsFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathStartsWithFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the starts-with() XPath function
* boolean starts-with(string, string)
@@ -3746,6 +3834,7 @@ xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathSubstringFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the substring() XPath function
* string substring(string, number, number?)
@@ -3841,6 +3930,7 @@ xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathSubstringBeforeFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the substring-before() XPath function
* string substring-before(string, string)
@@ -3882,6 +3972,7 @@ xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathSubstringAfterFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the substring-after() XPath function
* string substring-after(string, string)
@@ -3925,6 +4016,7 @@ xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathNormalizeFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the normalize-space() XPath function
* string normalize-space(string?)
@@ -3986,6 +4078,7 @@ xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathTranslateFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the translate() XPath function
* string translate(string, string, string)
@@ -4046,6 +4139,7 @@ xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathBooleanFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the boolean() XPath function
* boolean boolean(object)
@@ -4092,6 +4186,7 @@ xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathNotFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the not() XPath function
* boolean not(boolean)
@@ -4109,6 +4204,7 @@ xmlXPathNotFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathTrueFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the true() XPath function
* boolean true()
@@ -4122,6 +4218,7 @@ xmlXPathTrueFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathFalseFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the false() XPath function
* boolean false()
@@ -4135,6 +4232,7 @@ xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathLangFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the lang() XPath function
* boolean lang(string)
@@ -4180,6 +4278,7 @@ not_equal:
/**
* xmlXPathNumberFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the number() XPath function
* number number(object?)
@@ -4243,6 +4342,7 @@ xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathSumFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the sum() XPath function
* number sum(node-set)
@@ -4276,6 +4376,7 @@ xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathFloorFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the floor() XPath function
* number floor(number)
@@ -4298,6 +4399,7 @@ xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathCeilingFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the ceiling() XPath function
* number ceiling(number)
@@ -4324,6 +4426,7 @@ xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs) {
/**
* xmlXPathRoundFunction:
* @ctxt: the XPath Parser context
+ * @nargs: the number of arguments
*
* Implement the round() XPath function
* number round(number)
@@ -6032,6 +6135,12 @@ xmlXPathEvalExpression(const xmlChar *str, xmlXPathContextPtr ctxt) {
return(res);
}
+/**
+ * xmlXPathRegisterAllFunctions:
+ * @ctxt: the XPath context
+ *
+ * Registers all default XPath functions in this context
+ */
void
xmlXPathRegisterAllFunctions(xmlXPathContextPtr ctxt)
{
diff --git a/xpath.h b/xpath.h
index 347accff..ca98a184 100644
--- a/xpath.h
+++ b/xpath.h
@@ -265,6 +265,8 @@ xmlNodeSetPtr xmlXPathNodeSetCreate (xmlNodePtr val);
void xmlXPathFreeNodeSetList (xmlXPathObjectPtr obj);
void xmlXPathFreeNodeSet (xmlNodeSetPtr obj);
xmlXPathObjectPtr xmlXPathObjectCopy (xmlXPathObjectPtr val);
+int xmlXPathCmpNodes (xmlNodePtr node1,
+ xmlNodePtr node2);
#ifdef __cplusplus
diff --git a/xpointer.c b/xpointer.c
index 4ff76cb1..7d2da1b1 100644
--- a/xpointer.c
+++ b/xpointer.c
@@ -151,9 +151,6 @@ xmlXPtrGetNthChild(xmlNodePtr cur, int no) {
*/
int
xmlXPtrCmpPoints(xmlNodePtr node1, int index1, xmlNodePtr node2, int index2) {
- int depth1, depth2;
- xmlNodePtr cur, root;
-
if ((node1 == NULL) || (node2 == NULL))
return(-2);
/*
@@ -166,58 +163,7 @@ xmlXPtrCmpPoints(xmlNodePtr node1, int index1, xmlNodePtr node2, int index2) {
return(-1);
return(0);
}
- if (node1 == node2->prev)
- return(1);
- if (node1 == node2->next)
- return(-1);
-
- /*
- * compute depth to root
- */
- for (depth2 = 0, cur = node2;cur->parent != NULL;cur = cur->parent) {
- if (cur == node1)
- return(1);
- depth2++;
- }
- root = cur;
- for (depth1 = 0, cur = node1;cur->parent != NULL;cur = cur->parent) {
- if (cur == node2)
- return(-1);
- depth1++;
- }
- /*
- * Distinct document (or distinct entities :-( ) case.
- */
- if (root != cur) {
- return(-2);
- }
- /*
- * get the nearest common ancestor.
- */
- while (depth1 > depth2) {
- depth1--;
- node1 = node1->parent;
- }
- while (depth2 > depth1) {
- depth2--;
- node2 = node2->parent;
- }
- while (node1->parent != node2->parent) {
- node1 = node1->parent;
- node2 = node2->parent;
- /* should not happen but just in case ... */
- if ((node1 == NULL) || (node2 == NULL))
- return(-2);
- }
- /*
- * Find who's first.
- */
- if (node1 == node2->next)
- return(-1);
- for (cur = node1->next;cur != NULL;cur = cur->next)
- if (cur == node2)
- return(1);
- return(-1); /* assume there is no sibling list corruption */
+ return(xmlXPathCmpNodes(node1, node2));
}
/**