]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/extlib/graphvizPp.ml
made executable again
[helm.git] / helm / software / components / extlib / graphvizPp.ml
index 18ebd94d9fb690f3c0749a3fef4514022fd3c0dd..46432883744ad7c68406be2d040dbe40134f25ce 100644 (file)
@@ -29,7 +29,12 @@ type attribute = string * string  (* <key, value> pair *)
 
 module type GraphvizFormatter =
   sig
-    val header: ?name:string -> Format.formatter -> unit
+    val header:
+      ?graph_type:string -> 
+      ?name:string -> ?graph_attrs:(attribute list) ->
+      ?node_attrs:(attribute list) -> ?edge_attrs:(attribute list) ->
+      Format.formatter ->
+        unit
     val node: string -> ?attrs:(attribute list) -> Format.formatter -> unit
     val edge:
       string -> string -> ?attrs:(attribute list) -> Format.formatter ->
@@ -44,16 +49,32 @@ module Dot =
   struct
     let attribute fmt (k, v) = fprintf fmt "@[<hv2>%s=@,\"%s\",@]" k v
     let attributes attrs fmt = List.iter (attribute fmt) attrs
+    let quote_string quote s = if quote then "\"" ^s ^ "\"" else s
 
-    let header ?(name = "g") fmt = fprintf fmt "@[<hv2>digraph %s {@," name
-    let node name ?(attrs = []) fmt =
-      fprintf fmt "@[<hov2>%s@ [" name;
+    let node name ~quote ?(attrs = []) fmt =
+      fprintf fmt "@[<hov2>%s@ [" (quote_string quote name);
       attributes attrs fmt;
       fprintf fmt "];@]@,"
-    let edge name1 name2 ?(attrs = []) fmt =
-      fprintf fmt "@[<hov2>%s ->@ %s@ [" name1 name2;
+
+    let edge ~quote name1 name2 ?(attrs = []) fmt =
+      fprintf fmt "@[<hov2>%s ->@ %s@ [" 
+         (quote_string quote name1) (quote_string quote name2);
       attributes attrs fmt;
       fprintf fmt "];@]@,"
+
+    let header ?(graph_type = "digraph") ?(name = "g") ?(graph_attrs = []) ?node_attrs ?edge_attrs fmt =
+      fprintf fmt "@[<hv2>%s %s {@," graph_type name;
+      List.iter (fun (k, v) -> fprintf fmt "@[<hv2>%s=@,%s;@]@," k v)
+        graph_attrs;
+      (match node_attrs with
+      | Some attrs -> node "node" ~quote:false ~attrs fmt
+      | None -> ());
+      (match edge_attrs with
+      | Some attrs -> node "edge" ~quote:false ~attrs fmt
+      | None -> ())
+
+    let node = node ~quote:true
+    let edge = edge ~quote:true
     let raw s fmt = pp_print_string fmt s
     let trailer fmt = fprintf fmt "@,}@]%!"
   end