Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:22:37

0001 #!/ usr / bin / perl
0002 
0003 die "Usage: $0 replacement-rules-file" unless - r $ARGV[0];
0004 
0005 #$TARGET = "functions";
0006 $TARGET = "data-members";
0007 
0008 if ($TARGET eq "functions") {
0009   $PRE = '(::|\s|\.|->|"|\(|\[)';
0010   $POST = '(\s*\()';
0011 }
0012 elsif($TARGET eq "data-members") {
0013   $PRE = '(\W)';
0014   $POST = '(\W)';
0015   push @FILES, map{"MkFitCore/src/Mk$_.h"} qw{Base Fitter Finder};
0016   push @FILES, map{"MkFitCore/src/Mk$_.cc"} qw{Fitter Finder};
0017 }
0018 
0019 open(F, "$ARGV[0]");
0020 
0021 while (my $l = <F>) {
0022   next if $l = ~m / ^\s* $ / ;
0023   next if $l = ~m / ^\s* # / ;
0024   chomp $l;
0025 
0026   my($from, $to) = $l = ~m / ^\s*(\w +)(?:\s + (\w +)\s*) ? $ / ;
0027 
0028   if (not defined $to) {
0029     if ($TARGET eq "functions") {
0030       $to = lcfirst($from);
0031     }
0032     elsif($TARGET eq "data-members") { $to = 'm_'.$from; }
0033   }
0034 
0035 #my @matches = `find.- name \*.h - or -name \*.cc | xargs grep - P '${PRE}${from}${POST}'`;
0036 #print "Replace '$from' --> '$to' in\n ", join(" ", @matches), "\n";
0037 #next;
0038 
0039   my @matched_files;
0040   if ($TARGET eq "functions") {
0041     @matched_files = split("\n", `find.- name \*.h - or -name \*.cc | xargs grep - l - P '${PRE}${from}${POST}'`);
0042   }
0043   elsif($TARGET eq "data-members") { @matched_files = @FILES; }
0044 
0045   next unless @matched_files;
0046 
0047   print "Replace '$from' --> '$to' in ", join(" ", @matched_files), "\n";
0048 
0049     for
0050       my $fname(@matched_files) {
0051         my $xxx = $ / ;
0052         undef $ / ;
0053         open(X, '<', $fname) or die "Can not open $fname for reading";
0054         my $file = <X>;
0055         close(X);
0056         $ / = $xxx;
0057 
0058         $file = ~s / ${PRE} ${from} ${POST} / $1${to} $2 / msg;
0059 
0060         my @matches = $file = ~m / ^ .*$from.*$ / mg;
0061         print $fname, "\n  ", join("\n  ", @matches), "\n";
0062 
0063         open(X, '>', $fname) or die "Can not open $fname for writing";
0064         print X $file;
0065         close(X);
0066       }
0067 
0068     print "\n";
0069 }
0070 
0071 close(F);