aboutsummaryrefslogtreecommitdiff
path: root/gfsm/gfsm/src/libgfsm/inc2dot.perl
blob: f4062628a433b8b2e0c303d95b6019b513bbd69e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl -w

%inc = qw();
%nod = qw();
foreach $file (@ARGV) {
  open(F,"<$file") or die("$0: open failed for '$file': $!");
  @incs = qw();
  while (<F>) {
    chomp;
    if ($_ =~ m/^\s*\#\s*include\s*[\<\"\']\s*(\S+)[\>\"\']/) { push(@incs,$1); }
  }
  close(F);
  $inc{$file} = [@incs];
  @nod{$file,@incs} = undef;
}

##-- subs
sub safestr {
  my $str = shift;
  $str =~ s/[\.\,\+\-\=]/_/g;
  return $str;
}

##-- write dot file
print
  ("digraph include {\n",
   "  rankdir = LR;\n",
   "  rotate = 90;\n",
  );

##-- all nodes
foreach $f (sort keys(%nod)) {
  $f_str = safestr($f);
  if (exists($inc{$f})) { $attrs = "[ label=\"$f\", shape=box  ]"; }
  else                  { $attrs = "[ label=\"$f\", shape=box, style=filled, fill=gray ]"; }
  print " $f_str $attrs;\n";

  ##-- arcs
  if (defined($incs=$inc{$f})) {
    foreach $i (@$incs) {
      $i_str = safestr($i);
      if (exists($inc{$i})) { $e_attrs = "[ color=black ]"; }
      else                  { $e_attrs = "[ color=red, style=dashed ]" }
      print "\t$f_str -> $i_str $e_attrs;\n"
    }
  }
}
print "}\n";