File indexing completed on 2024-04-21 05:41:57

0001 #!/usr/bin/perl -w
0002 
0003 # Usage: rename-private.pl
0004 
0005 use strict;
0006 use File::Basename;
0007 use lib dirname( $0 );
0008 use functionUtilkde;
0009 
0010 open(my $F, '-|', qw(find . -type f));
0011 my $file;
0012 while ($file = <$F>) {
0013     chomp $file;
0014     next if functionUtilkde::selectHeaderFile( $file);
0015     $file =~ s/\.h$//;
0016 
0017     open(my $HEADER, "$file.h") or warn "Unable to open file $file.h:$!\n";
0018     my $modified;
0019     my $classname;
0020     my $fwddecl;
0021     my @l = map {
0022        my $orig = $_;
0023        if (/^class [A-Z_]+_EXPORT (\w+)/) {
0024            $classname = $1;
0025        }
0026        if (defined $classname && /class Private;/) {
0027            $_ = "";
0028            $fwddecl = "class ${classname}Private;";
0029        } elsif (defined $classname && /\bPrivate\s*/) {
0030            s/Private/${classname}Private/;
0031        }
0032 
0033        $modified ||= $orig ne $_;
0034        $_;
0035     } <$HEADER>;
0036     close $HEADER;
0037 
0038     if ($modified) {
0039        open(my $OUT, ">$file.h");
0040        print $OUT @l;
0041        close $OUT;
0042     }
0043 
0044     if (defined $fwddecl) {
0045        functionUtilkde::addAfterAllIncludes("$file.h", $fwddecl);
0046     }
0047 
0048     if (defined $classname) {
0049 
0050        open(my $IMPL, "$file.cpp") or warn "Unable to open file $file.cpp:$!\n";
0051 
0052        undef $modified;
0053 
0054        @l = map {
0055           my $orig = $_;
0056 
0057           s/::Private/Private/g;
0058           s/\bPrivate/${classname}Private/g;
0059 
0060           $modified ||= $orig ne $_;
0061           $_;
0062        } <$IMPL>;
0063        close $IMPL;
0064 
0065        if ($modified) {
0066            open(my $OUT, ">$file.cpp");
0067            print $OUT @l;
0068            close $OUT;
0069        }
0070    }
0071 }