extern CAMLprim value ocaml_augeas_get (value tv, value pathv);
extern CAMLprim value ocaml_augeas_exists (value tv, value pathv);
extern CAMLprim value ocaml_augeas_insert (value tv, value beforev, value pathv, value labelv);
+extern CAMLprim value ocaml_augeas_label (value tv, value pathv);
extern CAMLprim value ocaml_augeas_mv (value tv, value srcv, value destv);
extern CAMLprim value ocaml_augeas_rm (value tv, value pathv);
extern CAMLprim value ocaml_augeas_match (value tv, value pathv);
CAMLreturn (Val_unit);
}
+/* val label : t -> path -> string option */
+CAMLprim value
+ocaml_augeas_label (value tv, value pathv)
+{
+ CAMLparam2 (tv, pathv);
+ CAMLlocal2 (optv, v);
+ augeas_t t = Augeas_t_val (tv);
+ const char *path = String_val (pathv);
+ const char *val;
+ int r;
+
+ r = aug_label (t, path, &val);
+ if (r == 1 && val) { /* Return Some val */
+ v = caml_copy_string (val);
+ optv = caml_alloc (1, 0);
+ Field (optv, 0) = v;
+ } else if (r == 0 || !val) /* Return None */
+ optv = Val_int (0);
+ else if (r == -1) /* Error or multiple matches */
+ raise_error (t, "Augeas.label");
+ else
+ caml_failwith ("Augeas.label: bad return value");
+
+ CAMLreturn (optv);
+}
+
/* val mv : t -> path -> path -> unit */
CAMLprim value
ocaml_augeas_mv (value tv, value srcv, value destv)
of [path]. By default it is inserted after [path], unless
[~before:true] is specified. *)
+val label : t -> path -> string option
+ (** [label t path] gets the label of [path].
+
+ Returns [Some value] when [path] matches only one node, and
+ that has an associated label. *)
+
val rm : t -> path -> int
(** [rm t path] removes all nodes matching [path].