[augeas-devel] augeas: master - * src/pathx.c: factor test if a step matches into step_matches
David Lutterkort
lutter at fedoraproject.org
Mon Feb 2 05:57:12 UTC 2009
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=cbb33c84bad6275a40697d1dd6a1d45cc11a14a2
Commit: cbb33c84bad6275a40697d1dd6a1d45cc11a14a2
Parent: dd069cf55675c8595f353c5fe653687c7ba49ccc
Author: David Lutterkort <lutter at redhat.com>
AuthorDate: Fri Jan 30 21:48:18 2009 -0800
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Fri Jan 30 21:48:18 2009 -0800
* src/pathx.c: factor test if a step matches into step_matches
This also fixes a problem matching, test also included
---
src/pathx.c | 13 ++++++++-----
tests/xpath.tests | 3 +++
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/pathx.c b/src/pathx.c
index 2f9c5b3..9c94640 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -1321,6 +1321,10 @@ int pathx_parse(const struct tree *tree, const char *txt,
* Searching in the tree
*************************************************************************/
+static bool step_matches(struct step *step, struct tree *tree) {
+ return (step->name == NULL || streqv(step->name, tree->label));
+}
+
/* Return the 1-based position of STEP->CUR amongst its siblings */
static int position(struct step *step) {
int pos = 0;
@@ -1329,7 +1333,7 @@ static int position(struct step *step) {
for (struct tree *t = step_first(step, step->ctx);
t != NULL;
t = step_next(step)) {
- if (streqv(t->label, cur->label)) {
+ if (step_matches(step, t)) {
pos += 1;
if (t == cur) {
step->cur = cur;
@@ -1403,7 +1407,7 @@ static struct tree *step_first(struct step *step, struct tree *ctx) {
}
if (step->cur == NULL)
return NULL;
- if (step->name != NULL && ! streqv(step->cur->label, step->name))
+ if (! step_matches(step, step->cur))
step_next(step);
return step->cur;
}
@@ -1445,9 +1449,8 @@ static struct tree *step_next(struct step *step) {
default:
assert(0);
}
- if (step->cur != NULL)
- if (step->name == NULL || streqv(step->cur->label, step->name))
- break;
+ if (step->cur != NULL && step_matches(step, step->cur))
+ break;
}
return step->cur;
}
diff --git a/tests/xpath.tests b/tests/xpath.tests
index 6af4c41..51f9824 100644
--- a/tests/xpath.tests
+++ b/tests/xpath.tests
@@ -136,3 +136,6 @@ test lircd-ancestor //*[ancestor::kudzu]
/augeas/files/etc/sysconfig/kudzu/lens/info = ...
/augeas/files/etc/sysconfig/kudzu/lens/id = ...
/files/etc/sysconfig/kudzu/SAFE = no
+
+test wildcard-last /files/etc/hosts/*[last()]
+ /files/etc/hosts/2
More information about the augeas-devel
mailing list