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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#!/usr/bin/perl -w
# Laurent Montel <montel@kde.org> (2014)
# KColorDialog::getColor => QColorDialog::getColor
# find -iname "*.cpp" -o -iname "*.h" |xargs kde-dev-scripts/kf5/convert-kcolordialog.pl
# TODO need to improve it.
use strict;
use File::Basename;
use lib dirname($0);
use functionUtilkde;
foreach my $file (@ARGV) {
my $modified;
open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n";
my %varname = ();
my %finalized_called = ();
my @l = map {
my $orig = $_;
my $regexp = qr/
^(\s*) # (1) Indentation
(.*?) # (2) Possibly "Classname *" (the ? means non-greedy)
KColorDialog::getColor\s*\((.*)\) # 3 (args)
(.*)
/x; # /x Enables extended whitespace mode
if (my ($indent, $left, $args, $endline) = $_ =~ $regexp) {
#warn "Found kcolordialog::getColor \'$left\', argument: \'$args\'\n";
my $constructor_regexp = qr/
^([^,]*)\s* # color
(?:,\s([^,]*))? # defaultColor
(?:,\s([^,]*))? # widget parent
(.*)$ # after
/x;
if (my ($color, $defaultcolor, $parent, $after) = $args =~ $constructor_regexp ) {
#warn "Argument found : color \'$color\', defaultColor \'$defaultcolor\'\n";
#if (defined $parent) {
# warn "We specified a parent \'$parent\'\n";
#}
$color =~ s, ,,g;
$endline =~ s, ,,g;
if (defined $defaultcolor) {
$defaultcolor =~ s, ,,g;
}
if ( $left =~ /^if\s*\(/ ) {
if (defined $defaultcolor) {
$_ = $indent . "$color = QColorDialog::getColor($defaultcolor";
} else {
$_ = $indent . "$color = QColorDialog::getColor(";
}
if ( defined $parent) {
$_ .= ", $parent";
if ( $parent =~ /\)/) {
$_ .= ";\n";
} else {
$_ .= ");\n";
}
} else {
$_ .= ");\n";
}
$_ .= $indent . "if ( $color.isValid() )";
if ($endline =~ /{$/) {
$_ .= " {";
}
$_ .= "\n";
#warn "code is in a if\n";
} else {
if (defined $defaultcolor) {
$_ = $indent . "$color = QColorDialog::getColor($defaultcolor";
} else {
$_ = $indent . "$color = QColorDialog::getColor(";
}
if ( defined $parent) {
$_ .= ", $parent";
if ( $parent =~ /\)/) {
$_ .= ";\n";
} else {
$_ .= ");\n";
}
} else {
$_ .= ");\n";
}
$_ .= $indent . "if ( $color.isValid() ) {\n";
$_ .= $indent . "//PORTING SCRIPT: move old code when color was valid\n";
$_ .= $indent . "}\n";
warn "Need to adapt code in $file\n";
}
}
}
s/\bKColorDialog\b/QColorDialog/g;
s/\<KColorDialog\b\>/\<QColorDialog>/ if (/#include/);
s/\<kcolordialog.h\>/\<QColorDialog>/ if (/#include/);
$modified ||= $orig ne $_;
$_;
} <$FILE>;
if ($modified) {
open (my $OUT, ">", $file);
print $OUT @l;
close ($OUT);
}
}
functionUtilkde::diffFile( "@ARGV" );
|