From 2ccf1e5b2a7e4ba23fc2f81e1bcdcab56e8fb9f6 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 15 Sep 2017 16:42:07 +0200 Subject: [PATCH] Add Augeas.transform Simple binding for aug_transform, so it is possible to add/remove file transformations. --- augeas-c.c | 16 ++++++++++++++++ augeas.ml | 6 ++++++ augeas.mli | 9 +++++++++ 3 files changed, 31 insertions(+) diff --git a/augeas-c.c b/augeas-c.c index b81c2b1..160fe34 100644 --- a/augeas-c.c +++ b/augeas-c.c @@ -369,3 +369,19 @@ ocaml_augeas_set (value tv, value pathv, value valuev) CAMLreturn (Val_unit); } + +/* val transform : t -> string -> string -> transform_mode -> unit */ +CAMLprim value +ocaml_augeas_transform (value tv, value lensv, value filev, value modev) +{ + CAMLparam4 (tv, lensv, filev, modev); + augeas_t t = Augeas_t_val (tv); + const char *lens = String_val (lensv); + const char *file = String_val (filev); + const int excl = Int_val (modev) == 1 ? 1 : 0; + + if (aug_transform (t, lens, file, excl) == -1) + raise_error (t, "Augeas.transform"); + + CAMLreturn (Val_unit); +} diff --git a/augeas.ml b/augeas.ml index 974a940..8d6ac6d 100644 --- a/augeas.ml +++ b/augeas.ml @@ -44,6 +44,10 @@ type error_code = | AugErrCpDesc | AugErrUnknown of int +type transform_mode = + | Include + | Exclude + exception Error of error_code * string * string * string type path = string @@ -72,6 +76,8 @@ external load : t -> unit = "ocaml_augeas_load" external set : t -> path -> value option -> unit = "ocaml_augeas_set" +external transform : t -> string -> string -> transform_mode -> unit + = "ocaml_augeas_transform" let () = Callback.register_exception "Augeas.Error" (Error (AugErrInternal, "", "", "")) diff --git a/augeas.mli b/augeas.mli index ef43e43..327dc02 100644 --- a/augeas.mli +++ b/augeas.mli @@ -47,6 +47,11 @@ type error_code = | AugErrUnknown of int (** Possible error codes. *) +type transform_mode = + | Include + | Exclude + (** The operation mode for the {!transform} function. *) + exception Error of error_code * string * string * string (** This exception is thrown when the underlying Augeas library returns an error. The tuple represents: @@ -118,3 +123,7 @@ val load : t -> unit val set : t -> path -> value option -> unit (** [set t path] sets [value] as new value at [path]. *) + +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