]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/formater.pl
3 ## Copyright (C) 1996-2015 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 # Author: Tsantilas Christos
11 # email: christos@chtsanti.net
13 # Distributed under the terms of the GNU General Public License as published
14 # by the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # Distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # Library General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 # See COPYING or http://www.gnu.org/licenses/gpl.html for details.
33 # NP: The Squid code requires astyle version 2.04 (exactly for now)
35 my $ASTYLE_BIN="/usr/local/bin/astyle";
36 if (! -x
$ASTYLE_BIN) {
37 $ASTYLE_BIN="/usr/bin/astyle";
39 if (! -x
$ASTYLE_BIN) {
40 $ASTYLE_BIN="/usr/local/src/astyle-2.04/bin/astyle";
43 my $ASTYLE_ARGS ="--mode=c -s4 --convert-tabs --keep-one-line-blocks --lineend=linux";
44 #$ASTYLE_ARGS="--mode=c -s4 -O --break-blocks -l";
47 if(! -e
$ASTYLE_BIN || ! -x
$ASTYLE_BIN){
48 print "\nFile $ASTYLE_BIN not found\n";
49 print "Please fix the ASTYLE_BIN variable in this script!\n\n";
52 $ASTYLE_BIN=$ASTYLE_BIN." ".$ASTYLE_ARGS;
56 my $out = shift @ARGV;
57 #read options, currently no options available
58 while($out eq "" || $out =~ /^-\w+$/){
72 if( $out !~ /\.cc$|\.cci$|\.h$|\.c$/) {
73 print "Unknown suffix for file $out, ignoring....\n";
78 my $in= "$out.astylebak";
88 local (*FROM_ASTYLE
, *TO_ASTYLE
);
89 my $pid_style=open2
(\
*FROM_ASTYLE
, \
*TO_ASTYLE
, $ASTYLE_BIN);
92 print "An error while open2\n";
101 if(!open(IN
, "<$in")){
102 print "Can not open input file: $in\n";
108 if(input_filter
(\
$line)==0){
111 print TO_ASTYLE
$line;
115 print TO_ASTYLE
$line;
124 if(!open(OUT
,">$out")){
125 print "Can't open output file: $out\n";
129 while(<FROM_ASTYLE
>){
131 if(output_filter
(\
$line)==0){
149 #if we have integer declaration, get it all before processing it..
151 if($$line =~/\s+int\s+.*/s || $$line=~ /\s+unsigned\s+.*/s ||
152 $$line =~/^int\s+.*/s || $$line=~ /^unsigned\s+.*/s
154 if( $$line =~ /(\(|,|\)|\#|typedef)/s ){
155 #excluding int/unsigned appeared inside function prototypes,typedefs etc....
159 if(index($$line,";") == -1){
160 # print "Getting one more for \"".$$line."\"\n";
164 if($$line =~ /(.*)\s*int\s+([^:]*):\s*(\w+)\s*\;(.*)/s){
165 # print ">>>>> ".$$line." ($1)\n";
166 my ($prx,$name,$val,$extra)=($1,$2,$3,$4);
168 $$line= $prx." int ".$name."__FORASTYLE__".$val.";".$extra;
169 # print "----->".$$line."\n";
171 elsif($$line =~ /\s*unsigned\s+([^:]*):\s*(\w+)\s*\;(.*)/s){
172 # print ">>>>> ".$$line." ($1)\n";
173 my ($name,$val,$extra)=($1,$2,$3);
174 my $prx =~ s/\s*$//g;
175 $$line= "unsigned ".$name."__FORASTYLE__".$val.";".$extra;
176 # print "----->".$$line."\n";
181 if($$line =~ /\#endif/ ||
182 $$line =~ /\#else/ ||
185 $$line =$$line."//__ASTYLECOMMENT__\n";
192 my $last_line_was_empty=0;
193 #param: a reference to input line
194 #retval 1: print line
195 #retval 0: don't print line
199 # collapse multiple empty lines onto the first one
200 if($$line =~ /^\s*$/){
201 if ($last_line_was_empty==1) {
205 $last_line_was_empty=1;
209 $last_line_was_empty=0;
212 if($$line =~ s/\s*\/\/__ASTYLECOMMENT__
//) {
216 # "The "unsigned int:1; case ....."
217 $$line =~ s/__FORASTYLE__/:/;
224 print "Usage:\n $name file1 file2 file3 ....\n";