File: remove_virtual_prefix.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 (50 lines) | stat: -rwxr-xr-x 1,544 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
#!/usr/bin/perl -w

# Usage: remove_virtual_prefix.pl *.h 
# remove virtual when we have Q_DECL_OVERRIDE

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

foreach my $file (@ARGV) {

    # 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 $regexp = qr/
           ^(\s*)                        # (1) Indentation
           virtual\s*                    # (2) virtual
           (.*)                          # (3) function
           Q_DECL_OVERRIDE(.*)$
           /x; # /x Enables extended whitespace mode
        if (my ($indent, $function, $end) = $_ =~ $regexp) {
           $_ = $indent . $function . "Q_DECL_OVERRIDE" . $end . "\n";
        }

        my $regexpComment = qr/
           ^(\s*)                        # (1) Indentation
           \/\*\s*reimp\s*\*\/\s*                    # (2) reimp comment
           (.*)                          # (3) function
           Q_DECL_OVERRIDE(.*)$
           /x; # /x Enables extended whitespace mode
        if (my ($indent, $function, $end) = $_ =~ $regexpComment) {
           $_ = $indent . $function . "Q_DECL_OVERRIDE" . $end . "\n";
        }

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

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

functionUtilkde::diffFile( "@ARGV" );