]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/sort-includes.pl
1b1cdf90be7d569a8e7c764b5880dd88991871cf
3 ## Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
10 # USAGE: sort-includes.pl filename.cc >filename.cc.sorted
12 # This tool helps to sort the #include directives in a c or c++ source file
13 # according to the Squid Coding guidelines.
15 # The output of the tool is a source file where each block of consecutive
16 # include directives for project-specific files (#include "header.h")
17 # is sorted with this specification: squid.h (if present) is alwasy first,
18 # then the other directives are sorted in case-insensitive alphabetical order.
21 # for file in $(find . -name \*.cc); do /full/path/to/sort-includes.pl $file >$file.sorted; mv $file.sorted $file; done
26 my %Seen = (); # preprocessor #include lines, indexed by file name
29 if (/^\s*#\s*include\s*"(.+?)"/) {
31 # skip repeated file names that have identical #include lines
32 if (defined $Seen{$fname}) {
33 next if $Seen{$fname} eq $_;
34 warn("$ARGV:$.: Warning: inconsistent $fname #include lines:\n");
35 warn(" $Seen{$fname}");
37 # fall through to preserve every unique #include line
48 my $alwaysFirst = 'squid.h';
49 if (defined $Seen{$alwaysFirst}) {
50 print $Seen{$alwaysFirst};
51 delete $Seen{$alwaysFirst};
53 print sort { lc($a) cmp lc($b) } values %Seen;