Warning, file /sdk/kde-dev-scripts/kf5/convert-kcolordialog.pl was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #!/usr/bin/perl -w 0002 0003 # Laurent Montel <montel@kde.org> (2014) 0004 # KColorDialog::getColor => QColorDialog::getColor 0005 # find -iname "*.cpp" -o -iname "*.h" |xargs kde-dev-scripts/kf5/convert-kcolordialog.pl 0006 # TODO need to improve it. 0007 use strict; 0008 use File::Basename; 0009 use lib dirname($0); 0010 use functionUtilkde; 0011 0012 foreach my $file (@ARGV) { 0013 0014 my $modified; 0015 open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n"; 0016 my %varname = (); 0017 my %finalized_called = (); 0018 my @l = map { 0019 my $orig = $_; 0020 0021 my $regexp = qr/ 0022 ^(\s*) # (1) Indentation 0023 (.*?) # (2) Possibly "Classname *" (the ? means non-greedy) 0024 KColorDialog::getColor\s*\((.*)\) # 3 (args) 0025 (.*) 0026 /x; # /x Enables extended whitespace mode 0027 if (my ($indent, $left, $args, $endline) = $_ =~ $regexp) { 0028 #warn "Found kcolordialog::getColor \'$left\', argument: \'$args\'\n"; 0029 my $constructor_regexp = qr/ 0030 ^([^,]*)\s* # color 0031 (?:,\s([^,]*))? # defaultColor 0032 (?:,\s([^,]*))? # widget parent 0033 (.*)$ # after 0034 /x; 0035 if (my ($color, $defaultcolor, $parent, $after) = $args =~ $constructor_regexp ) { 0036 #warn "Argument found : color \'$color\', defaultColor \'$defaultcolor\'\n"; 0037 #if (defined $parent) { 0038 # warn "We specified a parent \'$parent\'\n"; 0039 #} 0040 $color =~ s, ,,g; 0041 $endline =~ s, ,,g; 0042 if (defined $defaultcolor) { 0043 $defaultcolor =~ s, ,,g; 0044 } 0045 if ( $left =~ /^if\s*\(/ ) { 0046 if (defined $defaultcolor) { 0047 $_ = $indent . "$color = QColorDialog::getColor($defaultcolor"; 0048 } else { 0049 $_ = $indent . "$color = QColorDialog::getColor("; 0050 } 0051 if ( defined $parent) { 0052 $_ .= ", $parent"; 0053 if ( $parent =~ /\)/) { 0054 $_ .= ";\n"; 0055 } else { 0056 $_ .= ");\n"; 0057 } 0058 } else { 0059 $_ .= ");\n"; 0060 } 0061 $_ .= $indent . "if ( $color.isValid() )"; 0062 if ($endline =~ /{$/) { 0063 $_ .= " {"; 0064 } 0065 $_ .= "\n"; 0066 #warn "code is in a if\n"; 0067 } else { 0068 if (defined $defaultcolor) { 0069 $_ = $indent . "$color = QColorDialog::getColor($defaultcolor"; 0070 } else { 0071 $_ = $indent . "$color = QColorDialog::getColor("; 0072 } 0073 if ( defined $parent) { 0074 $_ .= ", $parent"; 0075 if ( $parent =~ /\)/) { 0076 $_ .= ";\n"; 0077 } else { 0078 $_ .= ");\n"; 0079 } 0080 } else { 0081 $_ .= ");\n"; 0082 } 0083 $_ .= $indent . "if ( $color.isValid() ) {\n"; 0084 $_ .= $indent . "//PORTING SCRIPT: move old code when color was valid\n"; 0085 $_ .= $indent . "}\n"; 0086 warn "Need to adapt code in $file\n"; 0087 } 0088 } 0089 } 0090 0091 s/\bKColorDialog\b/QColorDialog/g; 0092 s/\<KColorDialog\b\>/\<QColorDialog>/ if (/#include/); 0093 s/\<kcolordialog.h\>/\<QColorDialog>/ if (/#include/); 0094 $modified ||= $orig ne $_; 0095 $_; 0096 } <$FILE>; 0097 0098 if ($modified) { 0099 open (my $OUT, ">", $file); 0100 print $OUT @l; 0101 close ($OUT); 0102 } 0103 } 0104 0105 functionUtilkde::diffFile( "@ARGV" );