File: rename-private.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 (71 lines) | stat: -rwxr-xr-x 1,544 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl -w

# Usage: rename-private.pl

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

open(my $F, '-|', qw(find . -type f));
my $file;
while ($file = <$F>) {
    chomp $file;
    next if functionUtilkde::selectHeaderFile( $file);
    $file =~ s/\.h$//;

    open(my $HEADER, "$file.h") or warn "Unable to open file $file.h:$!\n";
    my $modified;
    my $classname;
    my $fwddecl;
    my @l = map {
       my $orig = $_;
       if (/^class [A-Z_]+_EXPORT (\w+)/) {
           $classname = $1;
       }
       if (defined $classname && /class Private;/) {
           $_ = "";
           $fwddecl = "class ${classname}Private;";
       } elsif (defined $classname && /\bPrivate\s*/) {
           s/Private/${classname}Private/;
       }

       $modified ||= $orig ne $_;
       $_;
    } <$HEADER>;
    close $HEADER;

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

    if (defined $fwddecl) {
       functionUtilkde::addAfterAllIncludes("$file.h", $fwddecl);
    }

    if (defined $classname) {

       open(my $IMPL, "$file.cpp") or warn "Unable to open file $file.cpp:$!\n";

       undef $modified;

       @l = map {
          my $orig = $_;

          s/::Private/Private/g;
          s/\bPrivate/${classname}Private/g;

          $modified ||= $orig ne $_;
          $_;
       } <$IMPL>;
       close $IMPL;

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