[augeas-devel] augeas: master - * src/pathx.c: add count() function
David Lutterkort
lutter at fedoraproject.org
Thu Feb 19 20:05:49 UTC 2009
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=1c8f54acc28df867222319ed77b1bb053ae74ec4
Commit: 1c8f54acc28df867222319ed77b1bb053ae74ec4
Parent: 141b9b085d0013df0ddf188f8ca52eabcd864a55
Author: David Lutterkort <lutter at redhat.com>
AuthorDate: Wed Feb 18 11:31:34 2009 -0800
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Wed Feb 18 14:58:45 2009 -0800
* src/pathx.c: add count() function
---
src/pathx.c | 18 +++++++++++++++++-
tests/xpath.tests | 3 +++
2 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/src/pathx.c b/src/pathx.c
index 09374e1..feca067 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -222,12 +222,18 @@ struct func {
static void func_last(struct state *state);
static void func_position(struct state *state);
+static void func_count(struct state *state);
+
+static const enum type const count_arg_types[] = { T_NODESET };
static const struct func builtin_funcs[] = {
{ .name = "last", .arity = 0, .type = T_NUMBER, .arg_types = NULL,
.impl = func_last },
{ .name = "position", .arity = 0, .type = T_NUMBER, .arg_types = NULL,
- .impl = func_position }
+ .impl = func_position },
+ { .name = "count", .arity = 1, .type = T_NUMBER,
+ .arg_types = count_arg_types,
+ .impl = func_count }
};
#define CHECK_ERROR \
@@ -446,6 +452,16 @@ static void func_position(struct state *state) {
push_value(vind, state);
}
+static void func_count(struct state *state) {
+ value_ind_t vind;
+ struct value *ns = pop_value(state);
+
+ vind = make_value(T_NUMBER, state);
+ CHECK_ERROR;
+ state->value_pool[vind].number = ns->nodeset->used;
+ 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 8031f23..33685d6 100644
--- a/tests/xpath.tests
+++ b/tests/xpath.tests
@@ -148,3 +148,6 @@ test nodeset-nodeset-eq /files/etc/sysconfig/network-scripts/*[BRIDGE = /files/e
test last-ssh-service /files/etc/services/service-name[port = '22'][last()]
/files/etc/services/service-name[24] = ssh
+
+test count-one-alias /files/etc/hosts/*[count(alias) = 1]
+ /files/etc/hosts/2
More information about the augeas-devel
mailing list