Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
scripts for the astyle re-indentation & iostream=>QgsDebugMsg migrati…
…on cleanup git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9137 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
jef
committed
Aug 23, 2008
1 parent
619dd2e
commit b4fbd2d
Showing
4 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
if ! astyle.sh >/dev/null 2>&1; then | ||
echo astyle.sh not found in path >&2 | ||
exit 1 | ||
fi | ||
|
||
set -e | ||
|
||
export elcr="$(tput el)$(tput cr)" | ||
|
||
find src -type f -print | while read f; do | ||
case "$f" in | ||
*.cpp|*.h|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H) | ||
;; | ||
|
||
*) | ||
continue | ||
;; | ||
esac | ||
|
||
if [ -f "$f.astyle" ]; then | ||
# reformat backup | ||
cp "$f.astyle" "$f" | ||
touch -r "$f.astyle" "$f" | ||
else | ||
# make backup | ||
cp "$f" "$f.astyle" | ||
touch -r "$f" "$f.astyle" | ||
fi | ||
|
||
echo -ne "Reformating $f$elcr" | ||
astyle.sh "$f" | ||
done | ||
|
||
echo | ||
|
||
# convert CRLF to LF | ||
find .. -type f \ | ||
! -path "*/.svn/*" \ | ||
! -path "*/win_build/*" \ | ||
! -name "*.def" \ | ||
! -name "*.rc" \ | ||
! -name "*.png" \ | ||
-exec file {} \; | | ||
grep CRLF | | ||
cut -d: -f1 | | ||
while read f; do | ||
echo -ne "Flipping $f$elcr" | ||
flip -ub "$f" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
find . \( -name "*.astyle" -o -name "*.iostream" \) -exec rm {} \; | ||
svn revert -R . | ||
svn update | ||
patch -p0 --dry-run <qgslogger-before.diff | ||
patch -p0 <qgslogger-before.diff | ||
mv qgslogger-before.diff qgslogger-before.diff.orig | ||
svn diff >qgslogger-before.diff | ||
diff -u qgslogger-before.diff.orig qgslogger-before.diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
if ! qgsloggermig.pl >/dev/null 2>&1; then | ||
echo qgsloggermig.pl not found in path >&2 | ||
exit 1 | ||
fi | ||
|
||
set -e | ||
|
||
export ARTISTIC_STYLE_OPTIONS="\ | ||
--preserve-date \ | ||
--indent-preprocessor \ | ||
--brackets=break \ | ||
--convert-tabs \ | ||
--indent=spaces=2 \ | ||
--indent-classes \ | ||
--indent-labels \ | ||
--indent-namespaces \ | ||
--indent-switches \ | ||
--one-line=keep-blocks \ | ||
--one-line=keep-statements \ | ||
--max-instatement-indent=40 \ | ||
--min-conditional-indent=-1 \ | ||
--suffix=none" | ||
|
||
#--break-blocks \ | ||
|
||
export ARTISTIC_STYLE_OPTIONS="\ | ||
$ARTISTIC_STYLE_OPTIONS \ | ||
--pad=oper \ | ||
--pad=paren-in \ | ||
--unpad=paren" | ||
|
||
for f in "$@"; do | ||
flip -ub "$f" | ||
qgsloggermig.pl "$f" | ||
astyle $ARTISTIC_STYLE_OPTIONS "$f" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
#!/usr/bin/perl | ||
|
||
# use QgsDebugMsg instead of iostream for debugging output | ||
|
||
# EXAMPLE: | ||
# | ||
# #include <iostream> | ||
# | ||
# #ifdef QGISDEBUG | ||
# std::cout << "A " << a << " B " << b << " A " << a << std::endl; | ||
# // std::cout << "commented out" << std::endl; | ||
# #endif | ||
# | ||
# becomes | ||
# | ||
# #include "qgslogger.h" | ||
# | ||
# QgsDebugMsg(QString("A %1 B %2 A %1").arg(a).arg(b)); | ||
# QgsDebugMsgLevel("commented out", 3); | ||
# | ||
# | ||
# append // OK to keep it as it is. | ||
|
||
use strict; | ||
use warnings; | ||
|
||
for my $file (@ARGV) { | ||
my $output; | ||
my $F; | ||
my @file; | ||
|
||
open $F, $file; | ||
|
||
my $externc = 0; | ||
my $ifdef = 0; | ||
my $loggerseen=0; | ||
my $lastinclude=0; | ||
my $modified = 0; | ||
my $i=0; | ||
my $le; | ||
while(<$F>) { | ||
$i++; | ||
|
||
($le) = /([\r\n]+)$/ unless defined $le; | ||
|
||
if(/\s*#\s*include\s*<iostream>/) { | ||
next; | ||
} | ||
|
||
if(/\s*#\s*include\s*qgslogger\.h/) { | ||
$loggerseen=1; | ||
} | ||
|
||
$externc=1 if /extern\s+\"C\"\s*{/; | ||
$externc=0 if $externc && /^\s*}\s*$/; | ||
$ifdef++ if /^\s*#\s*if/; | ||
$ifdef-- if /^\s*#\s*endif/; | ||
|
||
if($externc==0 && $ifdef==0 && /\s*#\s*include/) { | ||
$lastinclude = scalar(@file)+1; | ||
} | ||
|
||
if(/std::(cout|cerr)/) { | ||
die "nested? [$file]" if defined $output; | ||
$output = ""; | ||
} | ||
|
||
if(defined $output) { | ||
$output .= $_; | ||
if(/;/) { | ||
($le) = ($output =~ /([\r\n]+)$/); | ||
$output =~ s/$le/\n/g; | ||
|
||
my $level = 0; | ||
if($output =~ /^\s*\/\/\s*(std::(cout|cerr))/) { | ||
$level = 3; | ||
$output =~ s/^\s*\/\///; | ||
$output =~ s/\n\s*\/\//\n /g; | ||
} | ||
|
||
my @arr = split /\s*<<\s*/, $output; | ||
my ($indent) = ($arr[0] =~ /^(\s*)/); | ||
$arr[0] =~ s/^\s+//; | ||
if($arr[0] =~ /^\/\// || $arr[-1] =~ /\/\/ OK$/) { | ||
# commented out | ||
push @file, "$output\n"; | ||
undef $output; | ||
next; | ||
} | ||
unless( $arr[0] =~ /^std::(cout|cerr)$/ ) { | ||
die "std::(cerr|cout) expected [$file]: |" . $arr[0] . "|"; | ||
} | ||
$arr[-1] =~ s/\s*;\s*$/;/; | ||
if( $arr[-1] =~ /\\n";$/) { | ||
$arr[-1] =~ s/\\n";/"/; | ||
push @arr, "std::endl;"; | ||
} elsif( $arr[-1] =~ /'\\n';$/) { | ||
$arr[-1] = "std::endl;"; | ||
} | ||
if( $arr[-1] =~ /^std::flush;$/ && | ||
$arr[-2] =~ /^std::endl$/ ) { | ||
pop @arr; | ||
pop @arr; | ||
$arr[-1] = "std::endl;"; | ||
} | ||
unless( $arr[-1] =~ /^std::endl;$/ ) { | ||
die "std::endl; expected [$file]: |" . $arr[-1] . "|"; | ||
} | ||
shift @arr; | ||
pop @arr; | ||
my $str; | ||
my %args; | ||
my @args; | ||
my $fmt = ""; | ||
foreach(@arr) { | ||
if(/^"(.*)"$/) { | ||
$fmt .= $1; | ||
} else { | ||
if(/^QString::number\s*\(\s*([^,]*)\s*\)$/) { | ||
$_ = $1; | ||
} | ||
s/\.toLocal8Bit\(\).data\(\)$//; | ||
s/\.toUtf8\(\).data\(\)$//; | ||
s/\.ascii\(\)$//; | ||
if(exists $args{$_}) { | ||
my $n = $args{$_}; | ||
$fmt .= "%$n"; | ||
} else { | ||
push @args, $_; | ||
$args{$_} = scalar(@args); | ||
$fmt .= "%" . scalar(@args); | ||
} | ||
} | ||
} | ||
if(@args>0) { | ||
if(@args==1 && $fmt eq "%1") { | ||
$str = $args[0]; | ||
} else { | ||
$str = "QString(\"$fmt\").arg(" . join(").arg(", @args) . ")"; | ||
} | ||
} else { | ||
$str = "\"$fmt\""; | ||
} | ||
if($level == 3) { | ||
# push @file, $indent . "QgsDebugMsgLevel($str, 3);$le"; | ||
push @file, $indent . "// QgsDebugMsg($str);$le"; | ||
} else { | ||
push @file, $indent . "QgsDebugMsg($str);$le"; | ||
} | ||
$modified=1; | ||
undef $output; | ||
} | ||
} else { | ||
push @file, $_; | ||
} | ||
} | ||
close $F; | ||
if($modified) { | ||
if(!$loggerseen) { | ||
die "no includes? [$file]" unless defined $lastinclude; | ||
splice @file, $lastinclude, 0, "#include \"qgslogger.h\"$le"; | ||
} | ||
#print "MODIFIED: $file\n"; | ||
my @filtered; | ||
my @output; | ||
my $ifdef_seen=0; | ||
foreach(@file) { | ||
if($ifdef_seen) { | ||
if(/^\s*#\s*if/) { | ||
die "nested #if? [$file]"; | ||
} elsif(/^\s*QgsDebugMsg/) { | ||
push @output, $_; | ||
} elsif(/^\s*#\s*endif/) { | ||
push @filtered, $_ foreach @output; | ||
undef @output; | ||
$ifdef_seen=0; | ||
} else { | ||
push @filtered, "#ifdef QGISDEBUG$le"; | ||
push @filtered, $_ foreach @output; | ||
push @filtered, $_; | ||
undef @output; | ||
$ifdef_seen=0; | ||
} | ||
} elsif(/^\s*#\s*ifdef\s+QGISDEBUG\s*$/) { | ||
die "output pending" if @output; | ||
$ifdef_seen=1; | ||
} else { | ||
push @filtered, $_; | ||
} | ||
} | ||
die "output pending" if @output; | ||
link $file, "$file.iostream" unless -f "$file.iostream"; | ||
unlink $file; | ||
open $F, ">$file"; | ||
foreach (@filtered) { | ||
print $F $_; | ||
} | ||
close $F; | ||
} | ||
} | ||
# vim: set ts=8 noet: |