From d34f7efe4e4fa9ee0a2a05ebad5ad73dbb390373 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 29 May 2019 11:48:41 +0200 Subject: [PATCH] Add Augeas.defnode Simple binding for aug_defnode. --- augeas-c.c | 25 +++++++++++++++++++++++++ augeas.ml | 2 ++ augeas.mli | 4 ++++ 3 files changed, 31 insertions(+) diff --git a/augeas-c.c b/augeas-c.c index 2baca22..7580497 100644 --- a/augeas-c.c +++ b/augeas-c.c @@ -39,6 +39,7 @@ extern CAMLprim value ocaml_augeas_create (value rootv, value loadpathv, value flagsv); extern CAMLprim value ocaml_augeas_close (value tv); +extern CAMLprim value ocaml_augeas_defnode (value tv, value namev, value exprv, value valv); extern CAMLprim value ocaml_augeas_defvar (value tv, value namev, value exprv); extern CAMLprim value ocaml_augeas_get (value tv, value pathv); extern CAMLprim value ocaml_augeas_exists (value tv, value pathv); @@ -243,6 +244,30 @@ ocaml_augeas_close (value tv) CAMLreturn (Val_unit); } +/* val defnode : t -> string -> string -> string option -> int * bool */ +CAMLprim value +ocaml_augeas_defnode (value tv, value namev, value exprv, value valv) +{ + CAMLparam4 (tv, namev, exprv, valv); + CAMLlocal2 (optv, v); + augeas_t t = Augeas_t_val (tv); + const char *name = String_val (namev); + const char *expr = String_val (exprv); + const char *val = Optstring_val (valv); + int r, created; + + r = aug_defnode (t, name, expr, val, &created); + if (r == -1) { + raise_error (t, "Augeas.defnode"); + } + + v = caml_alloc (2, 0); + Store_field (v, 0, Val_int (r)); + Store_field (v, 1, Val_bool (created)); + + CAMLreturn (v); +} + /* val defvar : t -> string -> string option -> int option */ CAMLprim value ocaml_augeas_defvar (value tv, value namev, value exprv) diff --git a/augeas.ml b/augeas.ml index 0101b91..e9dd26a 100644 --- a/augeas.ml +++ b/augeas.ml @@ -62,6 +62,8 @@ external create : string -> string option -> flag list -> t = "ocaml_augeas_create" external close : t -> unit = "ocaml_augeas_close" +external defnode : t -> string -> string -> string option -> int * bool + = "ocaml_augeas_defnode" external defvar : t -> string -> string option -> int option = "ocaml_augeas_defvar" external get : t -> path -> value option diff --git a/augeas.mli b/augeas.mli index 80a94f2..af4b608 100644 --- a/augeas.mli +++ b/augeas.mli @@ -94,6 +94,10 @@ val close : t -> unit Do not use the handle after closing it. *) +val defnode : t -> string -> string -> string option -> int * bool + (** [defnode t name expr value] defines [name] whose value is the + result of evaluating [expr], which is a nodeset. *) + val defvar : t -> string -> string option -> int option (** [defvar t name expr] defines [name] whose value is the result of evaluating [expr], replacing the old value if existing. -- 1.8.3.1