From: Pino Toscano Date: Fri, 15 Sep 2017 14:42:03 +0000 (+0200) Subject: Add Augeas.set X-Git-Tag: v0.6~25 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=a467e365dc114868f948b8b5b18e551b42d64ddd;p=ocaml-augeas.git Add Augeas.set Simple binding for aug_set, so it is possible to actually change the value of nodes. --- diff --git a/augeas-c.c b/augeas-c.c index 4db3f6c..3952910 100644 --- a/augeas-c.c +++ b/augeas-c.c @@ -349,3 +349,23 @@ ocaml_augeas_load (value tv) CAMLreturn (Val_unit); } + +/* val set : t -> -> path -> value option -> unit */ +CAMLprim value +ocaml_augeas_set (value tv, value pathv, value valuev) +{ + CAMLparam3 (tv, pathv, valuev); + augeas_t t = Augeas_t_val (tv); + const char *path = String_val (pathv); + const char *val; + + val = + valuev == Val_int (0) + ? NULL + : String_val (Field (valuev, 0)); + + if (aug_set (t, path, val) == -1) + raise_error (t, "Augeas.set"); + + CAMLreturn (Val_unit); +} diff --git a/augeas.ml b/augeas.ml index ba3626e..974a940 100644 --- a/augeas.ml +++ b/augeas.ml @@ -70,6 +70,8 @@ external save : t -> unit = "ocaml_augeas_save" external load : t -> unit = "ocaml_augeas_load" +external set : t -> path -> value option -> unit + = "ocaml_augeas_set" let () = Callback.register_exception "Augeas.Error" (Error (AugErrInternal, "", "", "")) diff --git a/augeas.mli b/augeas.mli index a896270..ef43e43 100644 --- a/augeas.mli +++ b/augeas.mli @@ -115,3 +115,6 @@ val save : t -> unit val load : t -> unit (** [load t] loads files into the tree. *) + +val set : t -> path -> value option -> unit + (** [set t path] sets [value] as new value at [path]. *)