From: Alex Rousskov Date: Wed, 30 Mar 2016 13:25:34 +0000 (+1300) Subject: Cleanup: Automatically remove duplicated #include lines. X-Git-Tag: SQUID_3_5_16~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4573944872b45fdd927175167e32dda30cc9e9e;p=thirdparty%2Fsquid.git Cleanup: Automatically remove duplicated #include lines. --- diff --git a/scripts/sort-includes.pl b/scripts/sort-includes.pl index 5c81e66d89..6252dd2e38 100755 --- a/scripts/sort-includes.pl +++ b/scripts/sort-includes.pl @@ -7,8 +7,6 @@ ## Please see the COPYING and CONTRIBUTORS files for details. ## -# AUTHOR: Francesco Chemolli -# # USAGE: sort-includes.pl filename.cc >filename.cc.sorted # # This tool helps to sort the #include directives in a c or c++ source file @@ -24,23 +22,34 @@ use strict; use warnings; -my @acc=(); #if empty, we're not accumulating + +my %Seen = (); # preprocessor #include lines, indexed by file name + while (<>) { - if (m!^#include "!) { - if (m!squid.h!) { - print; - } else { - push @acc,$_; + if (/^\s*#\s*include\s*"(.+?)"/) { + my $fname = $1; + # skip repeated file names that have identical #include lines + if (defined $Seen{$fname}) { + next if $Seen{$fname} eq $_; + warn("$ARGV:$.: Warning: inconsistent $fname #include lines:\n"); + warn(" $Seen{$fname}"); + warn(" $_"); + # fall through to preserve every unique #include line } + $Seen{$fname} = $_; } else { - &dump_acc; + &dumpSeen(); print; } } -&dump_acc; +&dumpSeen(); -sub dump_acc { - return unless @acc; - print sort {lc($a) cmp lc($b)} @acc; - @acc=(); +sub dumpSeen { + my $alwaysFirst = 'squid.h'; + if (defined $Seen{$alwaysFirst}) { + print $Seen{$alwaysFirst}; + delete $Seen{$alwaysFirst}; + } + print sort { lc($a) cmp lc($b) } values %Seen; + %Seen = (); } diff --git a/src/acl/Asn.cc b/src/acl/Asn.cc index 7dfa26778b..551c182d5e 100644 --- a/src/acl/Asn.cc +++ b/src/acl/Asn.cc @@ -26,7 +26,6 @@ #include "SquidConfig.h" #include "Store.h" #include "StoreClient.h" -#include "StoreClient.h" #define WHOIS_PORT 43 #define AS_REQBUF_SZ 4096 diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 8b1750de66..690f9ec2e7 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -20,7 +20,6 @@ #include "format/Token.h" #include "FwdState.h" #include "globals.h" -#include "globals.h" #include "HttpHeaderTools.h" #include "HttpReply.h" #include "HttpRequest.h" diff --git a/src/log/access_log.cc b/src/log/access_log.cc index 1d6a1c79c8..68dcae8633 100644 --- a/src/log/access_log.cc +++ b/src/log/access_log.cc @@ -17,8 +17,6 @@ #include "CachePeer.h" #include "err_detail_type.h" #include "errorpage.h" -#include "errorpage.h" -#include "errorpage.h" #include "format/Token.h" #include "globals.h" #include "hier_code.h"