File: cflow2dot.pl

package info (click to toggle)
sarien 0.7.0-1
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 1,864 kB
  • ctags: 2,543
  • sloc: ansic: 18,542; sh: 2,363; cpp: 1,371; makefile: 523; objc: 438; perl: 51
file content (74 lines) | stat: -rwxr-xr-x 1,900 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl
#
# $Id: cflow2dot.pl,v 1.1 2001/08/02 16:12:40 cmatsuoka Exp $

$graphic  = "color=red";
$input    = "color=magenta";
$sarien   = "color=blue";
$agisys   = "color=lightgrey";
$interp   = "color=green";
$menu     = "color=orange";
$sound    = "color=lightcyan";
$view     = "color=peachpuff";
$logic    = "color=yellow";

$lowlevel = "shape=box style=bold";
$midlevel = "shape=trapezium";
$optional = "shape=hexagon";

$resource = "style=filled";

$def_edge  = "color=black style=solid";

print "digraph sarien {\n";
print "edge [$def_edge];\n";

while (<>) {
	s/^\d+//;

	# Assign node properties to interesting functions
	#
	$x = $_;
	if (/\t*(\w+) {(\w+)\.c/) {
		(my $x, $_) = ($1, $2);
		/^graphic/ && print "\t$x [$graphic $lowlevel];\n";
		/^sprite/  && print "\t$x [$graphic];\n";
		/^console/ && print "\t$x [$sarien $optional];\n";
		/^keyboar/ && print "\t$x [$input];\n";
		/^agi/     && print "\t$x [$agisys $resource];\n";
		/^motion/  && print "\t$x [$interp $midlevel];\n";
		/^checks/  && print "\t$x [$interp $lowlevel];\n";
		/^cycle/   && print "\t$x [$interp];\n";
		/^menu/    && print "\t$x [$menu];\n";
		/^sound/   && print "\t$x [$sound $resource];\n";
		/^view/    && print "\t$x [$view $resource];\n";
		/^logic/   && print "\t$x [$logic $resource];\n";

		/^console/ && ($edge{$x} = "color=blue");
		/^graphic/ && ($edge{$x} = "color=red");
	}
	$_ = $x;

	($f) = /(\w+)/;
	$i = rindex $_, "\t";
	@m[$i] = $f;
	($i < 1) && next;

	$_ = "\t\"@m[$i - 1]\" -> \"@m[$i]\";\n";

	# Filter out functions we don't want charted
	#
	(/[^\w](_D|report|[sg]etflag|[sg]etvar|main|fixpath)[^\w]/
		|| /[^\w](memset|feof|strtok|atoi|atol|abs|tolower)[^\w]/
		|| /[^\w](strtoul|fseek|ftell|abort)[^\w]/
		|| /[^\w](lohi_|hilo_|__|test_|object_)/) && next;

	$edge{@m[$i - 1]} &&
		($_ = "\tedge [$edge{@m[$i - 1]}];\n$_\tedge [$def_edge];\n");

	print;
}

print "}\n";