From e078b8d80273f7b1df94b4acc2eca2f6f44a0a66 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Added Augeas.count_matches --- augeas.ml | 2 ++ augeas.mli | 4 ++++ augeas_c.c | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/augeas.ml b/augeas.ml index b7e1c58..40833b2 100644 --- a/augeas.ml +++ b/augeas.ml @@ -45,6 +45,8 @@ external rm : t -> path -> int = "ocaml_augeas_rm" external matches : t -> path -> path list = "ocaml_augeas_match" +external count_matches : t -> path -> int + = "ocaml_augeas_count_matches" external save : t -> unit = "ocaml_augeas_save" diff --git a/augeas.mli b/augeas.mli index 1123f05..3fe1e87 100644 --- a/augeas.mli +++ b/augeas.mli @@ -81,5 +81,9 @@ val matches : t -> path -> path list (** [matches t path] returns a list of path expressions of all nodes matching [path]. *) +val count_matches : t -> path -> int + (** [count_matches t path] counts the number of nodes matching + [path] but does not return them (see {!matches}). *) + val save : t -> unit (** [save t] saves all pending changes to disk. *) diff --git a/augeas_c.c b/augeas_c.c index e070bc4..3cc1021 100644 --- a/augeas_c.c +++ b/augeas_c.c @@ -222,7 +222,7 @@ ocaml_augeas_match (value tv, value pathv) r = aug_match (t, path, &matches); if (r == -1) - raise_error ("Augeas.match"); + raise_error ("Augeas.matches"); /* Copy the paths to a list. */ rv = Val_int (0); @@ -240,6 +240,22 @@ ocaml_augeas_match (value tv, value pathv) CAMLreturn (rv); } +/* val count_matches : t -> path -> int */ +CAMLprim value +ocaml_augeas_count_matches (value tv, value pathv) +{ + CAMLparam2 (tv, pathv); + augeas_t t = Augeas_t_val (tv); + char *path = String_val (path); + int r; + + r = aug_match (t, path, NULL); + if (r == -1) + raise_error ("Augeas.count_matches"); + + CAMLreturn (Val_int (r)); +} + /* val save : t -> unit */ CAMLprim value ocaml_augeas_save (value tv) -- 1.8.3.1