From 3ad8256f8c4340156860373043bb28babe005049 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 29 May 2019 11:48:43 +0200 Subject: [PATCH] Add Augeas.setm Simple binding for aug_setm. --- augeas-c.c | 19 +++++++++++++++++++ augeas.ml | 2 ++ augeas.mli | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/augeas-c.c b/augeas-c.c index d2a19b0..5dbaa83 100644 --- a/augeas-c.c +++ b/augeas-c.c @@ -51,6 +51,7 @@ extern CAMLprim value ocaml_augeas_count_matches (value tv, value pathv); extern CAMLprim value ocaml_augeas_save (value tv); extern CAMLprim value ocaml_augeas_load (value tv); extern CAMLprim value ocaml_augeas_set (value tv, value pathv, value valuev); +extern CAMLprim value ocaml_augeas_setm (value tv, value basev, value subv, value valv); extern CAMLprim value ocaml_augeas_transform (value tv, value lensv, value filev, value modev); extern CAMLprim value ocaml_augeas_source (value tv, value pathv) #ifndef HAVE_AUG_SOURCE @@ -481,6 +482,24 @@ ocaml_augeas_set (value tv, value pathv, value valuev) CAMLreturn (Val_unit); } +/* val setm : t -> path -> string option -> value option -> int */ +CAMLprim value +ocaml_augeas_setm (value tv, value basev, value subv, value valv) +{ + CAMLparam4 (tv, basev, subv, valv); + augeas_t t = Augeas_t_val (tv); + const char *base = String_val (basev); + const char *sub = Optstring_val (subv); + const char *val = Optstring_val (valv); + int r; + + r = aug_setm (t, base, sub, val); + if (r == -1) + raise_error (t, "Augeas.setm"); + + CAMLreturn (Val_int (r)); +} + /* val transform : t -> string -> string -> transform_mode -> unit */ CAMLprim value ocaml_augeas_transform (value tv, value lensv, value filev, value modev) diff --git a/augeas.ml b/augeas.ml index e2a2e67..63379a2 100644 --- a/augeas.ml +++ b/augeas.ml @@ -86,6 +86,8 @@ external mv : t -> path -> path -> unit = "ocaml_augeas_mv" external set : t -> path -> value option -> unit = "ocaml_augeas_set" +external setm : t -> path -> string option -> value option -> int + = "ocaml_augeas_setm" external transform : t -> string -> string -> transform_mode -> unit = "ocaml_augeas_transform" external source : t -> path -> path option diff --git a/augeas.mli b/augeas.mli index 8e6ec6d..c1862f1 100644 --- a/augeas.mli +++ b/augeas.mli @@ -140,6 +140,13 @@ val load : t -> unit val set : t -> path -> value option -> unit (** [set t path] sets [value] as new value at [path]. *) +val setm : t -> path -> string option -> value option -> int + (** [setm t base sub value] sets [value] as new value for all the + nodes under [base] that match [sub] (or all, if [sub] is + [None]). + + Returns the number of nodes modified. *) + val transform : t -> string -> string -> transform_mode -> unit (** [transform t lens file mode] adds or removes (depending on [mode]) the transformation of the specified [lens] for [file]. *) -- 1.8.3.1