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

0001 #!/usr/bin/perl -w
0002 
0003 # Usage: add_destructor_override.pl *.h 
0004 # add overide when we have virtual destructor (not perfect as sometimes we define destructor as virtual.
0005 # so you need to test compile.
0006 
0007 use strict;
0008 use File::Basename;
0009 use lib dirname($0);
0010 use functionUtilkde;
0011 
0012 foreach my $file (@ARGV) {
0013 
0014     # I don't use functionUtilkde::substInFile because it touches all files, even those which were not modified.
0015     my $modified;
0016     open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n";
0017     my @l = map {
0018         my $orig = $_;
0019 
0020         my $regexp = qr/
0021            ^(\s*)                        # (1) Indentation
0022            virtual\s*~                   # (2) virtual
0023            (.*)                          # (3) function
0024            \(\);$
0025            /x; # /x Enables extended whitespace mode
0026         if (my ($indent, $function) = $_ =~ $regexp) {
0027            $_ = $indent . "~" . $function . "() override;" . "\n";
0028         }
0029 
0030         $modified ||= $orig ne $_;
0031         $_;
0032     } <$FILE>;
0033 
0034     if ($modified) {
0035         open (my $OUT, ">", $file);
0036         print $OUT @l;
0037         close ($OUT);
0038     }
0039 }
0040 
0041 functionUtilkde::diffFile( "@ARGV" );