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
61 let rest = Str.matched_group 3 line in
67 let tar = Node (target,ref []) in
68 nodes := tar :: !nodes ;
73 let sou = search_node source in
74 let Node (_,ts) = sou in
79 let sou = Node (source,ref [tar]) in
80 nodes := sou :: !nodes ;
83 arcs := (sou,tar,rest)::!arcs
91 (************************************************)
93 (************************************************)
97 simplify_deps_and_output_them !arcs