3
# use QgsDebugMsg instead of iostream for debugging output
10
# std::cout << "A " << a << " B " << b << " A " << a << std::endl;
11
# // std::cout << "commented out" << std::endl;
16
# #include "qgslogger.h"
18
# QgsDebugMsg(QString("A %1 B %2 A %1").arg(a).arg(b));
19
# QgsDebugMsgLevel("commented out", 3);
22
# append // OK to keep it as it is.
27
for my $file (@ARGV) {
44
($le) = /([\r\n]+)$/ unless defined $le;
46
if(/\s*#\s*include\s*<iostream>/) {
50
if(/\s*#\s*include\s*qgslogger\.h/) {
54
$externc=1 if /extern\s+\"C\"\s*{/;
55
$externc=0 if $externc && /^\s*}\s*$/;
56
$ifdef++ if /^\s*#\s*if/;
57
$ifdef-- if /^\s*#\s*endif/;
59
if($externc==0 && $ifdef==0 && /\s*#\s*include/) {
60
$lastinclude = scalar(@file)+1;
63
if(/(std::)?(cout|cerr)/) {
64
die "nested? [$file]" if defined $output;
71
($le) = ($output =~ /([\r\n]+)$/);
72
$output =~ s/$le/\n/g;
75
if($output =~ /^\s*\/\/\s*((std::)?(cout|cerr))/) {
77
$output =~ s/^\s*\/\///;
78
$output =~ s/\n\s*\/\//\n /g;
81
my @arr = split /\s*<<\s*/, $output;
82
my ($indent) = ($arr[0] =~ /^(\s*)/);
85
if($arr[0] =~ /^\/\// || $arr[-1] =~ /\/\/ OK$/) {
87
push @file, "$output\n";
92
unless( $arr[0] =~ /^(std::)?(cout|cerr)$/ ) {
93
die "std::(cerr|cout) expected [$file]: |" . $arr[0] . "|";
96
$arr[-1] =~ s/\s*;\s*$/;/;
98
if( $arr[-1] =~ /\\n";$/) {
99
$arr[-1] =~ s/\\n";/"/;
100
push @arr, "std::endl;";
101
} elsif( $arr[-1] =~ /'\\n';$/) {
102
$arr[-1] = "std::endl;";
105
if( $arr[-1] =~ /^(std::)?flush;$/ &&
106
$arr[-2] =~ /^(std::)?endl$/ ) {
109
push @arr, "std::endl;";
112
unless( $arr[-1] =~ /^(std::)?endl;$/ ) {
113
die "std::endl; expected [$file]: |" . $arr[-1] . "|";
127
if(/^QString::number\s*\(\s*([^,]*)\s*\)$/) {
131
s/\.toLocal8Bit\(\).data\(\)$//;
132
s/\.toUtf8\(\).data\(\)$//;
135
if(exists $args{$_}) {
140
$args{$_} = scalar(@args);
141
$fmt .= "%" . scalar(@args);
147
if(@args==1 && $fmt eq "%1") {
150
$str = "QString(\"$fmt\").arg(" . join(").arg(", @args) . ")";
157
# push @file, $indent . "QgsDebugMsgLevel($str, 3);$le";
158
push @file, $indent . "// QgsDebugMsg($str);$le";
160
push @file, $indent . "QgsDebugMsg($str);$le";
176
die "no includes? [$file]" unless defined $lastinclude;
177
splice @file, $lastinclude, 0, "#include \"qgslogger.h\"$le";
180
#print "MODIFIED: $file\n";
189
die "nested #if? [$file]";
190
} elsif(/^\s*QgsDebugMsg/) {
192
} elsif(/^\s*#\s*endif/) {
193
push @filtered, $_ foreach @output;
197
push @filtered, "#ifdef QGISDEBUG$le";
198
push @filtered, $_ foreach @output;
203
} elsif(/^\s*#\s*ifdef\s+QGISDEBUG\s*$/) {
204
die "output pending" if @output;
211
die "output pending" if @output;
213
link $file, "$file.iostream" unless -f "$file.iostream";
217
foreach (@filtered) {
224
# vim: set ts=8 noet: