]>
Commit | Line | Data |
---|---|---|
3d41e53a FC |
1 | #!/usr/bin/perl |
2 | # | |
ef57eb7b | 3 | ## Copyright (C) 1996-2016 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 | ||
10 | # AUTHOR: Francesco Chemolli <kinkie@squid-cache.org> | |
3d41e53a | 11 | # |
3d41e53a FC |
12 | # USAGE: sort-includes.pl filename.cc >filename.cc.sorted |
13 | # | |
14 | # This tool helps to sort the #include directives in a c or c++ source file | |
15 | # according to the Squid Coding guidelines. | |
16 | # | |
17 | # The output of the tool is a source file where each block of consecutive | |
18 | # include directives for project-specific files (#include "header.h") | |
19 | # is sorted with this specification: squid.h (if present) is alwasy first, | |
20 | # then the other directives are sorted in case-insensitive alphabetical order. | |
21 | # | |
22 | # Suggested usage: | |
23 | # for file in $(find . -name \*.cc); do /full/path/to/sort-includes.pl $file >$file.sorted; mv $file.sorted $file; done | |
24 | ||
25 | use strict; | |
26 | use warnings; | |
27 | my @acc=(); #if empty, we're not accumulating | |
28 | while (<>) { | |
29 | if (m!^#include "!) { | |
30 | if (m!squid.h!) { | |
31 | print; | |
32 | } else { | |
33 | push @acc,$_; | |
34 | } | |
35 | } else { | |
36 | &dump_acc; | |
37 | print; | |
38 | } | |
39 | } | |
40 | &dump_acc; | |
41 | ||
42 | sub dump_acc { | |
43 | return unless @acc; | |
44 | print sort {lc($a) cmp lc($b)} @acc; | |
45 | @acc=(); | |
46 | } |