From: squidadm@squid-cache.org <> Date: Sat, 20 Dec 2014 07:49:33 +0000 (+0000) Subject: scripts/formater.pl: use strict perl syntax checking X-Git-Tag: merge-candidate-3-v1~420 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0278ba4dd04bba01cb7e42f0026e0298caa1b80a;p=thirdparty%2Fsquid.git scripts/formater.pl: use strict perl syntax checking --- diff --git a/scripts/formater.pl b/scripts/formater.pl index cbc6ea510d..7df24ed463 100755 --- a/scripts/formater.pl +++ b/scripts/formater.pl @@ -26,30 +26,34 @@ # See COPYING or http://www.gnu.org/licenses/gpl.html for details. # - +use strict; use IPC::Open2; # -# NP: The Squid code requires astyle version 1.22 (exactly for now) +# NP: The Squid code requires astyle version 2.03 (exactly for now) # -$ASTYLE_BIN="/usr/local/bin/astyle"; -#$ASTYLE_BIN="/usr/bin/astyle"; -#$ASTYLE_BIN="/usr/local/src/astyle-1.22/bin/astyle"; +my $ASTYLE_BIN="/usr/local/bin/astyle"; +if (! -x $ASTYLE_BIN) { + $ASTYLE_BIN="/usr/bin/astyle"; +} +if (! -x $ASTYLE_BIN) { + $ASTYLE_BIN="/usr/local/src/astyle-2.03/bin/astyle"; +} -$ASTYLE_ARGS ="--mode=c -s4 -O -l"; +my $ASTYLE_ARGS ="--mode=c -s4 --convert-tabs --keep-one-line-blocks "; #$ASTYLE_ARGS="--mode=c -s4 -O --break-blocks -l"; -if(! -e $ASTYLE_BIN){ +if(! -e $ASTYLE_BIN || ! -x $ASTYLE_BIN){ print "\nFile $ASTYLE_BIN not found\n"; print "Please fix the ASTYLE_BIN variable in this script!\n\n"; exit -1; } $ASTYLE_BIN=$ASTYLE_BIN." ".$ASTYLE_ARGS; -$INDENT = ""; +my $INDENT = ""; -$out = shift @ARGV; +my $out = shift @ARGV; #read options, currently no options available while($out eq "" || $out =~ /^-\w+$/){ if($out eq "-h") { @@ -71,7 +75,7 @@ while($out){ next; } - $in= "$out.astylebak"; + my $in= "$out.astylebak"; my($new_in) = $in; my($i) = 0; while(-e $new_in) { @@ -82,13 +86,14 @@ while($out){ rename($out, $in); local (*FROM_ASTYLE, *TO_ASTYLE); - $pid_style=open2(\*FROM_ASTYLE, \*TO_ASTYLE, $ASTYLE_BIN); + my $pid_style=open2(\*FROM_ASTYLE, \*TO_ASTYLE, $ASTYLE_BIN); if(!$pid_style){ print "An error while open2\n"; exit -1; } + my $pid; if($pid=fork()){ #do parrent staf close(FROM_ASTYLE); @@ -139,7 +144,6 @@ while($out){ $out = shift @ARGV; } - sub input_filter{ my($line)=@_; #if we have integer declaration, get it all before processing it.. @@ -159,14 +163,14 @@ sub input_filter{ if($$line =~ /(.*)\s*int\s+([^:]*):\s*(\w+)\s*\;(.*)/s){ # print ">>>>> ".$$line." ($1)\n"; - local($prx,$name,$val,$extra)=($1,$2,$3,$4); + my ($prx,$name,$val,$extra)=($1,$2,$3,$4); $prx =~ s/\s*$//g; $$line= $prx." int ".$name."__FORASTYLE__".$val.";".$extra; # print "----->".$$line."\n"; } elsif($$line =~ /\s*unsigned\s+([^:]*):\s*(\w+)\s*\;(.*)/s){ - local($name,$val,$extra)=($1,$2,$3); - $prx =~ s/\s*$//g; + my ($name,$val,$extra)=($1,$2,$3); + my $prx =~ s/\s*$//g; $$line= "unsigned ".$name."__FORASTYLE__".$val.";".$extra; } return 1; diff --git a/scripts/source-maintenance.sh b/scripts/source-maintenance.sh index 5782d4b455..fd30e2dd82 100755 --- a/scripts/source-maintenance.sh +++ b/scripts/source-maintenance.sh @@ -70,10 +70,11 @@ for FILENAME in `bzr ls --versioned`; do md51=`cat $FILENAME| tr -d "\n \t\r" | $MD5`; md52=`cat $FILENAME.astylebak| tr -d "\n \t\r" | $MD5`; - if test "$md51" != "$md52" ; then + if test "$md51" != "$md52"; then echo "ERROR: File $PWD/$FILENAME not formating well"; mv $FILENAME $FILENAME.astylebad mv $FILENAME.astylebak $FILENAME + bzr revert ${FILENAME} else rm -f $FILENAME.astylebak fi