[augeas-devel] augeas: master - * src/pathx.c: add position() function

David Lutterkort lutter at fedoraproject.org
Thu Feb 19 20:05:43 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=317ff153d2173fb503f70433da1972a3e7ac2b06
Commit:        317ff153d2173fb503f70433da1972a3e7ac2b06
Parent:        3c4112d49ea97556721dfcff1d0aca4d8ab549e3
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Wed Feb 18 11:15:24 2009 -0800
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Wed Feb 18 14:58:45 2009 -0800

* src/pathx.c: add position() function

---
 src/pathx.c       |   14 +++++++++++++-
 tests/xpath.tests |    5 ++++-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/pathx.c b/src/pathx.c
index b2872eb..ef41a80 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -221,10 +221,13 @@ struct func {
 };
 
 static void func_last(struct state *state);
+static void func_position(struct state *state);
 
 static const struct func builtin_funcs[] = {
     { .name = "last", .arity = 0, .type = T_NUMBER, .arg_types = NULL,
-      .impl = func_last }
+      .impl = func_last },
+    { .name = "position", .arity = 0, .type = T_NUMBER, .arg_types = NULL,
+      .impl = func_position }
 };
 
 #define CHECK_ERROR                                                     \
@@ -434,6 +437,15 @@ static void func_last(struct state *state) {
     push_value(vind, state);
 }
 
+static void func_position(struct state *state) {
+    value_ind_t vind;
+
+    vind = make_value(T_NUMBER, state);
+    CHECK_ERROR;
+    state->value_pool[vind].number = state->ctx_pos;
+    push_value(vind, state);
+}
+
 static int calc_eq_nodeset_nodeset(struct nodeset *ns1, struct nodeset *ns2,
                                    int neq) {
     for (int i1=0; i1 < ns1->used; i1++) {
diff --git a/tests/xpath.tests b/tests/xpath.tests
index c92869c..8031f23 100644
--- a/tests/xpath.tests
+++ b/tests/xpath.tests
@@ -137,9 +137,12 @@ test lircd-ancestor //*[ancestor::kudzu]
      /augeas/files/etc/sysconfig/kudzu/lens/id = ...
      /files/etc/sysconfig/kudzu/SAFE = no
 
-test wildcard-last /files/etc/hosts/*[last()]
+test wildcard-last /files/etc/hosts/*[position() = last()]
      /files/etc/hosts/2
 
+test wildcard-not-last /files/etc/hosts/*[position() != last()][ipaddr]
+     /files/etc/hosts/1
+
 test nodeset-nodeset-eq /files/etc/sysconfig/network-scripts/*[BRIDGE = /files/etc/sysconfig/network-scripts/ifcfg-br0/DEVICE]
      /files/etc/sysconfig/network-scripts/ifcfg-eth0
 




More information about the augeas-devel mailing list