]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/formater.pl
3 # Author: Tsantilas Christos
4 # email: christos@chtsanti.net
6 # Distributed under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # The ldap_manager library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Library General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See LICENSE or http://www.gnu.org/licenses/gpl.html for details .
26 # NP: The Squid code requires astyle version 1.22 or later
28 #$ASTYLE_BIN="/usr/local/bin/astyle";
29 $ASTYLE_BIN="/usr/bin/astyle";
31 #$ASTYLE_BIN="/usr/local/src/astyle-1.22/bin/astyle";
32 $ASTYLE_ARGS ="--mode=c -s4 -O -l";
34 #$ASTYLE_ARGS="--mode=c -s4 -O --break-blocks -l";
35 #$ASTYLE_BIN="/usr/local/src/astyle-1.22/bin/astyle";
39 print "\nFile $ASTYLE_BIN not found\n";
40 print "Please fix the ASTYLE_BIN variable in this script!\n\n";
43 $ASTYLE_BIN=$ASTYLE_BIN." ".$ASTYLE_ARGS;
48 #read options, currently no options available
49 while($out eq "" || $out =~ /^-\w+$/){
63 if( $out !~ /\.cc$|\.cci$|\.h$|\.c$/) {
64 print "Unknown suffix for file $out, ignoring....\n";
69 $in= "$out.astylebak";
79 local (*FROM_ASTYLE
, *TO_ASTYLE
);
80 $pid_style=open2
(\
*FROM_ASTYLE
, \
*TO_ASTYLE
, $ASTYLE_BIN);
83 print "An error while open2\n";
92 if(!open(IN
, "<$in")){
93 print "Can not open input file: $in\n";
99 if(input_filter
(\
$line)==0){
102 print TO_ASTYLE
$line;
106 print TO_ASTYLE
$line;
115 if(!open(OUT
,">$out")){
116 print "Can't open output file: $out\n";
120 while(<FROM_ASTYLE
>){
122 if(output_filter
(\
$line)==0){
141 #if we have integer declaration, get it all before processing it..
143 if($$line =~/\s+int\s+.*/s || $$line=~ /\s+unsigned\s+.*/s ||
144 $$line =~/^int\s+.*/s || $$line=~ /^unsigned\s+.*/s
146 if( $$line =~ /(\(|,|\)|\#|typedef)/s ){
147 #excluding int/unsigned appeared inside function prototypes,typedefs etc....
151 if(index($$line,";") == -1){
152 # print "Getting one more for \"".$$line."\"\n";
156 if($$line =~ /(.*)\s*int\s+([^:]*):\s*(\w+)\s*\;(.*)/s){
157 # print ">>>>> ".$$line." ($1)\n";
158 local($prx,$name,$val,$extra)=($1,$2,$3,$4);
160 $$line= $prx." int ".$name."__FORASTYLE__".$val.";".$extra;
161 # print "----->".$$line."\n";
163 elsif($$line =~ /\s*unsigned\s+([^:]*):\s*(\w+)\s*\;(.*)/s){
164 local($name,$val,$extra)=($1,$2,$3);
166 $$line= "unsigned ".$name."__FORASTYLE__".$val.";".$extra;
171 if($$line =~ /\#endif/ ||
172 $$line =~ /\#else/ ||
175 $$line =$$line."//__ASTYLECOMMENT__\n";
185 if($$line =~ /^\s*$/){
189 if($$line =~ s/\s*\/\/__ASTYLECOMMENT__
//) {
193 # "The "unsigned int:1; case ....."
194 $$line =~ s/__FORASTYLE__/:/;
201 print "Usage:\n $name file1 file2 file3 ....\n";