diff --git a/core/CCKTree.ml b/core/CCKTree.ml index f19fd14d..3813e5b7 100644 --- a/core/CCKTree.ml +++ b/core/CCKTree.ml @@ -294,5 +294,20 @@ module Dot = struct Format.pp_print_flush fmt () let pp_single name buf t = pp buf (singleton ~name t) + + let print_to_file filename g = + let oc = open_out filename in + let fmt = Format.formatter_of_out_channel oc in + try + print fmt g; + Format.pp_print_flush fmt (); + close_out oc + with e -> + close_out oc; + raise e + + let to_file ?(name="graph") filename trees = + let g = make ~name trees in + print_to_file filename g end diff --git a/core/CCKTree.mli b/core/CCKTree.mli index 1235ebc0..8137fe19 100644 --- a/core/CCKTree.mli +++ b/core/CCKTree.mli @@ -126,5 +126,18 @@ module Dot : sig val pp_single : string -> attribute list t printer val print : graph formatter + (** Printer with indentation, etc. + @since NEXT_RELEASE *) + + val print_to_file : string -> graph -> unit + (** [print_to_file filename g] prints [g] into a file whose name + is [filename]. + @since NEXT_RELEASE *) + + val to_file : ?name:string -> string -> attribute list t list -> unit + (** [to_file filename trees] makes a graph out of the trees, opens the + file [filename] and prints the graph into the file. + @param name name of the graph + @since NEXT_RELEASE *) end