X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=augeas-c.c;h=885b829d69ce0ee7cbe7278dad6289fdbdf60ee2;hb=05f00ac539c2cd0cf5dcbf90d031023a7e973ae7;hp=b81c2b15776291bc56e0bcdc54a91d76c6a54516;hpb=a9c904a256cb10be03995e265c8446be87b73284;p=ocaml-augeas.git diff --git a/augeas-c.c b/augeas-c.c index b81c2b1..885b829 100644 --- a/augeas-c.c +++ b/augeas-c.c @@ -369,3 +369,46 @@ 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); +} + +/* val source : t -> path -> path option */ +CAMLprim value +ocaml_augeas_source (value tv, value pathv) +{ + CAMLparam2 (tv, pathv); + CAMLlocal2 (optv, v); + augeas_t t = Augeas_t_val (tv); + const char *path = String_val (pathv); + char *file_path; + int r; + + r = aug_source (t, path, &file_path); + if (r == 0) { + if (file_path) { /* Return Some file_path */ + v = caml_copy_string (file_path); + optv = caml_alloc (1, 0); + Field (optv, 0) = v; + free (file_path); + } else /* Return None */ + optv = Val_int (0); + } + else /* Error */ + raise_error (t, "Augeas.source"); + + CAMLreturn (optv); +}