File: convert-qt5.pl

package info (click to toggle)
kde-dev-scripts 4%3A18.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,496 kB
  • sloc: perl: 15,466; lisp: 5,627; sh: 4,157; python: 3,892; ruby: 2,158; makefile: 16; sed: 9
file content (67 lines) | stat: -rwxr-xr-x 2,230 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w

# David Faure <faure@kde.org>
# Qt4 -> Qt5

use strict;
use File::Basename;
use lib dirname($0);
use functionUtilkde;

foreach my $file (@ARGV) {

    my $infoVar;
    my $urlVar;

    # I don't use functionUtilkde::substInFile because it touches all files, even those which were not modified.
    my $modified;
    open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n";
    my @l = map {
        my $orig = $_;

        my $regexpqFindChild = qr/
           ^(\s*)              # (1) Indentation
           (.*?)\s*=\s*           # (2) before
           qFindChild<([^>]*)> # (3) class name
           \(\s*([&\w]+)\s*,\s*   # (4) variable
           (.*)$               # (5) end              
           /x; # /x Enables extended whitespace mode
        if (my ($indent, $before, $classname, $variable, $end) = $_ =~ $regexpqFindChild) {
           warn "found qFindChild \n";
           if ($variable =~ /^&/ ) {
             $variable =~ s/^&//;
             $_ = $indent . $before . " = " . $variable . ".findChild<$classname>(" . $end . "\n";
           } else {
             $_ = $indent . $before . " = " . $variable . "->findChild<$classname>(" . $end . "\n";
           }
        }

        my $regexpqFindChilden = qr/
           ^(\s*)              # (1) Indentation
           (.*?)\s*=\s*           # (2) before
           qFindChilden<([^>]*)> # (3) class name
           \(\s*([&\w]+)\s*,\s*   # (4) variable
           (.*)$               # (5) end              
           /x; # /x Enables extended whitespace mode
        if (my ($indent, $before, $classname, $variable, $end) = $_ =~ $regexpqFindChild) {
           warn "found qFindChilden \n";
           if ($variable =~ /^&/ ) {
             $variable =~ s/^&//;
             $_ = $indent . $before . " = " . $variable . ".findChilden<$classname>(" . $end . "\n";
           } else {
             $_ = $indent . $before . " = " . $variable . "->findChilden<$classname>(" . $end . "\n";
           }
        }

        $modified ||= $orig ne $_;
        $_;
    } <$FILE>;

    if ($modified) {
        open (my $OUT, ">", $file);
        print $OUT @l;
        close ($OUT);
    }
}

functionUtilkde::diffFile( "@ARGV" );