]>
Commit | Line | Data |
---|---|---|
64b66b76 CT |
1 | #!/usr/bin/perl |
2 | # | |
bde978a6 | 3 | ## Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
a151895d AJ |
4 | ## |
5 | ## Squid software is distributed under GPLv2+ license and includes | |
6 | ## contributions from numerous individuals and organizations. | |
7 | ## Please see the COPYING and CONTRIBUTORS files for details. | |
8 | ## | |
9 | # | |
64b66b76 CT |
10 | # Author: Tsantilas Christos |
11 | # (C) 2010 The Measurement Factory | |
12 | # | |
13 | # Usage: | |
14 | # calc-must-ids.pl file1 file2 ... | |
15 | # Compute the ids of Must expressions of the given files. | |
16 | # It returns one line per Must expression in the form: | |
17 | # filename: line: MustID 'Must Text' | |
18 | # | |
19 | ||
20 | use warnings; | |
21 | use strict; | |
22 | ||
23 | # This constant should be synced with ERR_DETAIL_EXCEPTION_START enum | |
24 | # defined in src/err_detail_type.h | |
25 | use constant ERR_DETAIL_EXCEPTION_START => 110000; | |
26 | ||
27 | my $file; | |
28 | while ($file = shift @ARGV) { | |
29 | ComputeMustIds($file); | |
30 | } | |
31 | sub FileNameHash | |
32 | { | |
33 | # Please keep in sync this function with the FileNameHash function in | |
34 | # src/base/TextException.cc file | |
35 | my($name) = @_; | |
36 | $name =~ s/.*\///g; | |
37 | my($i) = 0; | |
38 | my($j) =0; | |
39 | my($n) = 0; | |
40 | my(@na) = split(//, $name); | |
41 | for($j=0; $j < @na; $j++) { | |
42 | $n = $n ^ (271 * ord($na[$j])); | |
43 | } | |
44 | $i = $n ^ ($j *271); | |
45 | ||
46 | # Currently 18bits of a 32 bit integer used for filename hash | |
47 | # (max hash=262143), and 14 bits for storing line number | |
48 | $i = $i % 262143; | |
49 | return $i; | |
50 | } | |
51 | ||
52 | sub ComputeMustIds | |
53 | { | |
54 | my($file) = @_; | |
55 | my($hash) = FileNameHash($file); | |
56 | if(!open(IN, "<$file")) { | |
57 | printf STDERR "error opening file $file. Ignore ..."; | |
58 | return; | |
59 | } | |
60 | while(<IN>) { | |
61 | my($line) = $_; | |
62 | my($id); | |
63 | if ( $line =~ /^\s*Must\s*\(/ || $line =~ /^\s*throw\s*TexcHere\s*\(/){ | |
64 | $line =~ s/^\s*//; | |
65 | $id= ($hash <<14) | ($. & 0x3FFF); | |
66 | $id += ERR_DETAIL_EXCEPTION_START; | |
67 | # print "$file:$.: $id $line"; | |
68 | printf "%s:%d: 0x%X %s", $file, $., $id, $line; | |
69 | } | |
70 | } | |
71 | close(IN); | |
72 | } |