1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#!/usr/bin/perl
# laurent Montel <montel@kde.org> 2006 GPL
# Reinhold Kainhofer <reinhold@kainhofer.com> 2006 GPL
#
# simple script to replace QT3_SUPPORT find by indexOf
#
# usage:
# convert-find-to-indexof.pl *.cpp
#
# CAUTION: This script replaces all calls to methods named 'find', even if the
# object is not a class where the find method is deprecated.
# I apply the script only to files that
# throw a deprecated warning and compare the # of deprecated warnings to the nr
# of replacements.
#
# NOTE: The results need a lot of manual tweaking!!!!
use File::Basename;
use lib dirname( $0 );
use functionUtilkde;
use strict;
foreach my $file (@ARGV) {
chomp $file;
next if functionUtilkde::excludeFile( $file);
my $modified;
my @necessaryIncludes = ();
open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n";
my @l = map {
my $orig = $_;
if ( m![\.>]find\s*\(! ) {
# s/(.*\.)find/!XXX-\1-XXXYYY-\2-YYY/g;
# s/(.*\.)find(\(.*\)\s*)==\s*([.*]\.)end\s*\(\s*\)/!\1contains\2/g;
s/([^ ].*(.|->))find(\(.*\)\s*)==\s*\1end\s*\(\s*\)/!\1contains\3/g;
s/([^ ]*(.|->))find(\(.*\)\s*)==\s*-1\s*/!\1contains\3/g;
s/([^ ].*(.|->))find(\(.*\)\s*)!=\s*\1end\s*\(\s*\)/\1contains\3/g;
s/([^ ]*(.|->))find(\(.*\)\s*)>=\s*0\s*/\1contains\3/g;
s/([^ ]*(.|->))find(\(.*\)\s*)!=\s*-1\s*/\1contains\3/g;
# print "Old line: \n$orig";
# print "New line: \n$_====================\n";
}
if ( m![\.>]find\s*\(! && ! m/[mM]ap/ ) {
s/([\.>])find(\s*)\(/\1indexOf\2(/g;
}
# third argument of find was changed from bool to Qt::CaseSensitivity cs = Qt::CaseSensitive
if ( my ($head, $parm1, $parm2, $ws, $parm3,$trailer) = m!^(.*ndexOf\s*)\(([^,]*),([^,]*),(\s*)([^, \)]*)(\s*\).*$)! ) {
if ( $parm3 eq 'true' ) {
$_ = "$head($parm1,$parm2,$ws"."Qt::CaseSensitive$trailer\n";
} elsif ( $parm3 eq 'false' ) {
$_ = "$head($parm1,$parm2,$ws"."Qt::CaseInsensitive$trailer\n";
}
#if ( $orig ne $_ ) {
# print "Old line: \n$orig";
# print "New line: \n$_====================\n";
#}
}
$modified ||= $orig ne $_;
$_;
} <$FILE>;
if ($modified) {
print "Modified: $file\n";
open (my $OUT, ">", $file);
print $OUT @l;
close $OUT;
}
}
functionUtilkde::diffFile( @ARGV );
|