2 Node of string * node list ref (* label, children *)
6 (************************************************)
7 (* SIMPLIFICATION AND PRETTY-PRINTING *)
8 (************************************************)
10 let reachable target source_arcs =
12 if s = target then true
14 let Node (_,arcs) = s in
15 List.fold_left (fun i n -> i or find n) false !arcs
21 (* this is the arc we would like to get rid of *)
29 let consider_arc (source,target,rest) =
30 let Node (source_name,source_arcs) = source in
31 let Node (target_name,_) = target in
32 if not (reachable target !source_arcs) then
33 print_endline (source_name ^ " -> " ^ target_name ^ rest ^ ";")
36 print_endline (source_name ^ " -> " ^ target_name ^ " [color=green];")
39 let simplify_deps_and_output_them =
40 List.iter consider_arc
43 (************************************************)
45 (************************************************)
48 let arcs = ref [];; (* (source,target) *)
51 List.find (function Node (s',_) -> s' = s) !nodes
57 let line = read_line () in
58 if Str.string_match (Str.regexp " \\([^ ]*\\) -> \\([^ ;]*\\)\\(\\( \\[.*\\]\\)?\\);") line 0 then
59 let source = Str.matched_group 1 line in
60 let target = Str.matched_group 2 line in
62 if source <> target then
64 let rest = Str.matched_group 3 line in
70 let tar = Node (target,ref []) in
71 nodes := tar :: !nodes ;
76 let sou = search_node source in
77 let Node (_,ts) = sou in
82 let sou = Node (source,ref [tar]) in
83 nodes := sou :: !nodes ;
86 arcs := (sou,tar,rest)::!arcs
95 (************************************************)
97 (************************************************)
101 simplify_deps_and_output_them !arcs