Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f
[chromium-blink-merge.git] / third_party / lcov / contrib / galaxy / conglomerate_functions.pl
blob4e259feee11c929e093289cce7c87f25f34bb562
1 #! /usr/bin/perl -w
3 # Takes a set of ps images (belonging to one file) and produces a
4 # conglomerate picture of that file: static functions in the middle,
5 # others around it. Each one gets a box about its area.
7 use strict;
9 my $SCRUNCH = $ARGV [0];
10 my $BOXSCRUNCH = $ARGV [1];
11 my $Tmp;
12 my $DEBUG = 1;
14 shift @ARGV; # skip SCRUNCH and BOXSCRUNCH
15 shift @ARGV;
18 DecorateFuncs (@ARGV);
21 #TMPFILE=`mktemp ${TMPDIR:-/tmp}/$$.XXXXXX`
23 # Arrange.
24 my $ArgList = "";
26 foreach $Tmp (@ARGV) {
27 $ArgList .= "'$Tmp' ";
30 my @Arranged = `../draw_arrangement $SCRUNCH 0 360 0 $ArgList`;
32 my $CFile = $ARGV [0];
33 $CFile =~ s/\.c\..*$/.c/;
34 if ($DEBUG) { print ("% Conglomeration of $CFile\n"); }
36 print "gsave angle rotate\n";
38 # Now output the file, except last line.
39 my $LastLine = pop (@Arranged);
40 my $Fill = Box_2 ($LastLine,$CFile);
41 print $Fill;
42 # Draw box with file name
43 my @Output = Box ('normal', 'Helvetica-Bold', 32, $CFile, $LastLine);
44 splice(@Output, $#Output, 0, "grestore\n");
45 #print @Output;
47 print (@Arranged);
48 #add a duplicate box to test if this works
49 print @Output;
52 sub ParseBound
54 my $BBoxLine = shift;
56 $BBoxLine =~ /(-?[\d.]+)\s+(-?[\d.]+)\s+(-?[\d.]+)\s+(-?[\d.]+)/;
58 # XMin, YMin, XMax, YMax
59 return ($1 * $BOXSCRUNCH, $2 * $BOXSCRUNCH,
60 $3 * $BOXSCRUNCH, $4 * $BOXSCRUNCH);
65 # Box (type, font, fontsize, Label, BBoxLine)
66 sub Box
68 my $Type = shift;
69 my $Font = shift;
70 my $Fontsize = shift;
71 my $Label = shift;
72 my $BBoxLine = shift;
73 my @Output = ();
75 # print (STDERR "Box ('$Type', '$Font', '$Fontsize', '$Label', '$BBoxLine')\n");
76 push (@Output, "% start of box\n");
78 push (@Output, "D5\n") if ($Type eq "dashed");
80 # print (STDERR "BBoxLine: '$BBoxLine'\n");
81 # print (STDERR "Parsed: '" . join ("' '", ParseBound ($BBoxLine)) . "\n");
82 my ($XMin, $YMin, $XMax, $YMax) = ParseBound ($BBoxLine);
84 my $LeftSpaced = $XMin + 6;
85 my $BottomSpaced = $YMin + 6;
87 # Put black box around it
88 push (@Output, (
89 "($Label) $LeftSpaced $BottomSpaced $Fontsize /$Font\n",
90 "$YMin $XMin $YMax $XMax U\n"
94 push (@Output, "D\n") if ($Type eq "dashed");
95 # fill bounding box
96 push (@Output, "% end of box\n");
98 # Output bounding box
99 push (@Output, "% bound $XMin $YMin $XMax $YMax\n");
101 return @Output;
104 sub Box_2
106 my $BBoxLine = shift;
107 my $CFile = shift;
108 my $CovFile = "./coverage.dat";
109 my ($XMin, $YMin, $XMax, $YMax) = ParseBound ($BBoxLine);
110 my @output = `fgrep $CFile $CovFile`;
111 chomp $output[0];
112 my ($junk, $Class, $per) = split /\t/, $output[0];
113 return "$XMin $YMin $XMax $YMax $Class\n";
115 # Decorate (rgb-vals(1 string) filename)
116 sub Decorate
118 my $RGB = shift;
119 my $Filename = shift;
121 my @Input = ReadPS ($Filename);
122 my $LastLine = pop (@Input);
123 my @Output = ();
125 # Color at the beginning.
126 push (@Output, "C$RGB\n");
128 # Now output the file, except last line.
129 push (@Output, @Input);
131 # Draw dashed box with function name
132 # FIXME Make bound cover the label as well!
133 my $FuncName = $Filename;
134 $FuncName =~ s/^[^.]+\.c\.(.+?)\..*$/$1/;
136 push (@Output, Box ('dashed', 'Helvetica', 24, $FuncName, $LastLine));
138 # Slap over the top.
139 WritePS ($Filename, @Output);
144 # Add colored boxes around functions
145 sub DecorateFuncs
147 my $FName = "";
148 my $FType = "";
150 foreach $FName (@ARGV)
152 $FName =~ /\+([A-Z]+)\+/;
153 $FType = $1;
155 if ($FType eq 'STATIC') {
156 Decorate ("2", $FName); # Light green.
158 elsif ($FType eq 'INDIRECT') {
159 Decorate ("3", $FName); # Green.
161 elsif ($FType eq 'EXPORTED') {
162 Decorate ("4", $FName); # Red.
164 elsif ($FType eq 'NORMAL') {
165 Decorate ("5", $FName); # Blue.
167 else {
168 die ("Unknown extension $FName");
174 sub ReadPS
176 my $Filename = shift;
177 my @Contents = ();
179 open (INFILE, "$Filename") or die ("Could not read $Filename: $!");
180 @Contents = <INFILE>;
181 close (INFILE);
183 return @Contents;
186 sub WritePS
188 my $Filename = shift;
190 open (OUTFILE, ">$Filename")
191 or die ("Could not write $Filename: $!");
192 print (OUTFILE @_);
193 close (OUTFILE);