]>
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/bin/astyle";
30 #$ASTYLE_BIN="/usr/local/src/astyle-1.22/bin/astyle";
31 $ASTYLE_ARGS ="--mode=c -s4 -O -l";
33 #$ASTYLE_ARGS="--mode=c -s4 -O --break-blocks -l";
34 #$ASTYLE_BIN="/usr/local/src/astyle-1.22/bin/astyle";
38 print "\nFile $ASTYLE_BIN not found\n";
39 print "Please fix the ASTYLE_BIN variable in this script!\n\n";
42 $ASTYLE_BIN=$ASTYLE_BIN." ".$ASTYLE_ARGS;
47 #read options, currently no options available
48 while($out eq "" || $out =~ /^-\w+$/){
62 if( $out !~ /\.cc$|\.cci$|\.h$|\.c$/) {
63 print "Unknown suffix for file $out, ignoring....\n";
68 $in= "$out.astylebak";
78 local (*FROM_ASTYLE
, *TO_ASTYLE
);
79 $pid_style=open2
(\
*FROM_ASTYLE
, \
*TO_ASTYLE
, $ASTYLE_BIN);
82 print "An error while open2\n";
91 if(!open(IN
, "<$in")){
92 print "Can not open input file: $in\n";
98 if(input_filter
(\
$line)==0){
101 print TO_ASTYLE
$line;
105 print TO_ASTYLE
$line;
114 if(!open(OUT
,">$out")){
115 print "Can't open output file: $out\n";
119 while(<FROM_ASTYLE
>){
121 if(output_filter
(\
$line)==0){
140 #if we have integer declaration, get it all before processing it..
142 if($$line =~/\s+int\s+.*/s || $$line=~ /\s+unsigned\s+.*/s ||
143 $$line =~/^int\s+.*/s || $$line=~ /^unsigned\s+.*/s
145 if( $$line =~ /(\(|,|\)|\#|typedef)/s ){
146 #excluding int/unsigned appeared inside function prototypes,typedefs etc....
150 if(index($$line,";") == -1){
151 # print "Getting one more for \"".$$line."\"\n";
155 if($$line =~ /(.*)\s*int\s+([^:]*):\s*(\w+)\s*\;(.*)/s){
156 # print ">>>>> ".$$line." ($1)\n";
157 local($prx,$name,$val,$extra)=($1,$2,$3,$4);
159 $$line= $prx." int ".$name."__FORASTYLE__".$val.";".$extra;
160 # print "----->".$$line."\n";
162 elsif($$line =~ /\s*unsigned\s+([^:]*):\s*(\w+)\s*\;(.*)/s){
163 local($name,$val,$extra)=($1,$2,$3);
165 $$line= "unsigned ".$name."__FORASTYLE__".$val.";".$extra;
170 if($$line =~ /\#endif/ ||
171 $$line =~ /\#else/ ||
174 $$line =$$line."//__ASTYLECOMMENT__\n";
184 if($$line =~ /^\s*$/){
188 if($$line =~ s/\s*\/\/__ASTYLECOMMENT__
//) {
192 # "The "unsigned int:1; case ....."
193 $$line =~ s/__FORASTYLE__/:/;
200 print "Usage:\n $name file1 file2 file3 ....\n";