]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - scripts/formater.pl
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / scripts / formater.pl
index efccfd649bb71517aa15c6956d5f2e3746a302a6..7ae193419ceb3b69ac0474d76781223804a0f274 100755 (executable)
@@ -1,5 +1,12 @@
 #!/usr/bin/perl
 #
+## Copyright (C) 1996-2018 The Squid Software Foundation and contributors
+##
+## Squid software is distributed under GPLv2+ license and includes
+## contributions from numerous individuals and organizations.
+## Please see the COPYING and CONTRIBUTORS files for details.
+##
+#
 # Author: Tsantilas Christos
 # email:  christos@chtsanti.net
 #
 # 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.04 (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.04/bin/astyle";
+}
 
-$ASTYLE_ARGS ="--mode=c -s4 -O -l";
+my $ASTYLE_ARGS ="--mode=c -s4 --convert-tabs --keep-one-line-blocks --lineend=linux";
 #$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") {
@@ -64,7 +75,7 @@ while($out){
          next;
     }
 
-    $in= "$out.astylebak";
+    my $in= "$out.astylebak";
     my($new_in) = $in;
     my($i) = 0;
     while(-e $new_in) {
@@ -75,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);
@@ -132,7 +144,6 @@ while($out){
     $out = shift @ARGV;
 }
 
-
 sub input_filter{
     my($line)=@_;
      #if we have integer declaration, get it all before processing it..
@@ -152,15 +163,17 @@ 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;
+#          print ">>>>> ".$$line."    ($1)\n";
+            my ($name,$val,$extra)=($1,$2,$3);
+            my $prx =~ s/\s*$//g;
            $$line= "unsigned ".$name."__FORASTYLE__".$val.";".$extra;
+#          print "----->".$$line."\n";
        }
        return 1;
     }