new tool
[hband-tools.git] / user-tools / indent2dot
blobb7e615aaa70fe965f86fb6820ee743d59f1e6987
1 #!/usr/bin/env perl
3 use Data::Dumper;
5 $\ = "\n";
7 while(<STDIN>)
9 /^(\s*)(.*)$/;
10 my $indent_level = length $1;
11 my $node = $2;
12 my $related_node;
14 if($indent_level > $prev_indent_level)
16 $parent_of_level{$indent_level} = $prev_node;
19 $related_node = $parent_of_level{$indent_level};
21 if(defined $related_node)
23 $relation{$node}->{$related_node} = 1;
26 $prev_indent_level = $indent_level;
27 $prev_node = $node;
31 $rankdir = $ENV{'INDENT2DOT_RANKDIR'} || 'LR';
33 print "digraph {";
34 print "rankdir=$rankdir;";
35 print "node [shape=box];";
37 for my $node (sort keys %relation)
39 for my $related_node (sort keys %{$relation{$node}})
41 if($ENV{'INDENT2DOT_ASCENDENT_CHART'})
43 print "\"$node\" -> \"$related_node\";";
45 else
47 print "\"$related_node\" -> \"$node\";";
52 print "}";