[augeas-devel] augeas: master - * src/pathx.c: function label() returning the label of the ctx node

David Lutterkort lutter at fedoraproject.org
Tue Mar 3 23:49:34 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=8afa95e099ccab6842c2c2e0ec6d7d866f44d3f6
Commit:        8afa95e099ccab6842c2c2e0ec6d7d866f44d3f6
Parent:        bfe4ac42e2397a4ccc2e124a59bbd5ce38ecec3c
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Mon Mar 2 14:30:38 2009 -0800
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Mon Mar 2 14:30:38 2009 -0800

* src/pathx.c: function label() returning the label of the ctx node

---
 src/pathx.c       |   21 +++++++++++++++++++++
 tests/xpath.tests |    5 +++++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/pathx.c b/src/pathx.c
index 15a51b6..6a92e9a 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -231,6 +231,7 @@ struct func {
 static void func_last(struct state *state);
 static void func_position(struct state *state);
 static void func_count(struct state *state);
+static void func_label(struct state *state);
 
 static const enum type const count_arg_types[] = { T_NODESET };
 
@@ -239,6 +240,8 @@ static const struct func builtin_funcs[] = {
       .impl = func_last },
     { .name = "position", .arity = 0, .type = T_NUMBER, .arg_types = NULL,
       .impl = func_position },
+    { .name = "label", .arity = 0, .type = T_STRING, .arg_types = NULL,
+      .impl = func_label },
     { .name = "count", .arity = 1, .type = T_NUMBER,
       .arg_types = count_arg_types,
       .impl = func_count }
@@ -470,6 +473,24 @@ static void func_count(struct state *state) {
     push_value(vind, state);
 }
 
+static void func_label(struct state *state) {
+    value_ind_t vind;
+    char *s;
+
+    vind = make_value(T_STRING, state);
+    CHECK_ERROR;
+    if (state->ctx->label)
+        s = strdup(state->ctx->label);
+    else
+        s = strdup("");
+    if (s == NULL) {
+        STATE_ENOMEM;
+        return;
+    }
+    state->value_pool[vind].string = s;
+    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 b5eeb67..74d435e 100644
--- a/tests/xpath.tests
+++ b/tests/xpath.tests
@@ -167,3 +167,8 @@ test pred-and-or /files/etc/hosts/*[(canonical = 'localhost' or alias = 'localho
 test path-with-dot /files/etc/.notthere
 
 test str-neq /files/etc/*['foo' != 'foo']
+
+# label() returns the label of the context node as a string
+test label-neq /files/etc/hosts/*[label() != 'comment']
+     /files/etc/hosts/1
+     /files/etc/hosts/2




More information about the augeas-devel mailing list