README.md edited online with Bitbucket
[swg-src.git] / tools / gatherWarnings.pl
blobb671c291c34c8ba65661d0c5269f49b2e1511628
1 #!/usr/perl/bin
3 sub usage
5 die "usage: perl gatherWarnings.pl [-c] [-s ##] [-dv] [-nl] sourceFile ...\n" .
6 "\t-c = count repeated warnings\n" .
7 "\t-s = combine similar warnings that differ by no more than ## words (implies -c)\n" .
8 "\t-dv = strip debug view timestamps\n" .
9 "\t-nl = strip warning locations\n";
12 while ($ARGV[0] =~ /^-/ && $ARGV[0] ne "-")
14 if ($ARGV[0] eq "-dv")
16 $debugView = 1;
18 elsif ($ARGV[0] eq "-nl")
20 $noLocation = 1;
22 elsif ($ARGV[0] eq "-s")
24 $similar = $ARGV[1];
25 $count = 1;
26 shift;
28 elsif ($ARGV[0] eq "-c")
30 $count = 1;
32 else
34 usage();
37 shift @ARGV;
40 usage if (@ARGV == 0);
42 sub numerically
44 return -($a <=> $b);
47 while (<>)
49 s/^\s*\d+\s+\d+\.\d+\s+\[\d+\]\s+// if ($debugView);
50 s/\S+ : WARNING:/WARNING:/ if ($noLocation);
51 s/\s+/ /;
53 if (/WARNING:/)
55 if ($similar)
57 chomp;
59 foreach $compare (keys %warnings)
61 @current = split(/\s+/, $_);
62 @compare = split(/\s+/, $compare);
64 if (scalar(@current) == scalar(@compare))
66 $count = 0;
67 $out = "";
68 while (@current)
70 $a = shift @current;
71 $b = shift @compare;
73 if ($a eq $b)
75 $out .= " $a";
77 else
79 $out .= " XXXX";
80 $count += 1;
84 if ($count <= $similar)
86 $out =~ s/^ //;
87 if ($warnings{$out} ne $warnings{$compare})
89 $warnings{$out} = $warnings{$compare};
90 delete $warnings{$compare};
93 $_ = $out;
95 else
101 $warnings{$_} += 1 if ($repeat == 0)
103 elsif ($count)
105 chomp;
106 $warnings{$_} += 1;
108 else
110 print;
115 if ($count)
117 foreach (keys %warnings)
119 push(@warnings, sprintf("%5d %s", $warnings{$_}, $_));
122 foreach (sort numerically @warnings)
124 print $_, "\n";