]> git.ipfire.org Git - thirdparty/squid.git/blame - scripts/calc-must-ids.pl
MinGW-w64: enable native file locking (#1358)
[thirdparty/squid.git] / scripts / calc-must-ids.pl
CommitLineData
64b66b76
CT
1#!/usr/bin/perl
2#
b8ae064d 3## Copyright (C) 1996-2023 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
47f28373
FC
12#
13# Usage:
64b66b76
CT
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
20use warnings;
21use strict;
22
23# This constant should be synced with ERR_DETAIL_EXCEPTION_START enum
24# defined in src/err_detail_type.h
25use constant ERR_DETAIL_EXCEPTION_START => 110000;
26
27my $file;
28while ($file = shift @ARGV) {
29 ComputeMustIds($file);
30}
31sub FileNameHash
32{
64b66b76 33 my($name) = @_;
ebaabe74
AR
34
35 # Keep in sync with FileNameHash() in src/base/Here.cc!
36
64b66b76
CT
37 $name =~ s/.*\///g;
38 my($i) = 0;
39 my($j) =0;
40 my($n) = 0;
41 my(@na) = split(//, $name);
42 for($j=0; $j < @na; $j++) {
47f28373 43 $n = $n ^ (271 * ord($na[$j]));
64b66b76 44 }
ebaabe74 45 return $n ^ ($j *271);
64b66b76
CT
46}
47
48sub ComputeMustIds
49{
50 my($file) = @_;
ebaabe74
AR
51
52 # Keep in sync with SourceLocation::id() in src/base/Here.cc!
53
54 my $fullHash = &FileNameHash($file);
55 my $hash = $fullHash % 0x3FFFF;
56
64b66b76
CT
57 if(!open(IN, "<$file")) {
58 printf STDERR "error opening file $file. Ignore ...";
59 return;
60 }
61 while(<IN>) {
62 my($line) = $_;
ebaabe74
AR
63
64 next if $line =~ /^\s*#/; # ignore simple single-line C++ macros
65 $line =~ s@//.*@@; # strip simple // comments
66 $line =~ s@/[*].*?[*]/@@; # strip simple single-line /* comments */
67
64b66b76 68 my($id);
2bde9c7c 69 if ($line =~ /\bMust\s*\(/ || # Must(...)
ebaabe74
AR
70 $line =~ /\bTexcHere\s*\(/ || # TexcHere(...)
71 $line =~ /\bHere\s*\(\s*\)/) { # Here()
64b66b76
CT
72 $line =~ s/^\s*//;
73 $id= ($hash <<14) | ($. & 0x3FFF);
74 $id += ERR_DETAIL_EXCEPTION_START;
75# print "$file:$.: $id $line";
76 printf "%s:%d: 0x%X %s", $file, $., $id, $line;
47f28373
FC
77 }
78 }
64b66b76
CT
79 close(IN);
80}