This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mk_PL_charclass.pl: Correct comment
[perl5.git] / Porting / fixvars
1 #!/usr/bin/perl -w
2 use Data::Dumper;
3
4 my $targ = (@ARGV) ? join(' ',@ARGV) : 'miniperl' ;
5
6 my $work = 1;
7 while ($work)
8  {
9   open(PIPE,"make $targ 2>&1 |") || die "Cannot open pipe to make:$!";
10   my %fix;
11   while (<PIPE>)
12    {
13     if (/^(.*):(\d+):\s+\`(\w+)'\s+undeclared/ && -f $1 )
14      {
15       my ($file,$line,$var) = ($1,$2,$3);
16       $fix{$file} = [] unless exists $fix{$file}; 
17       push(@{$fix{$file}},[$line => $var]) unless ($var =~ /^PL_/ || $file =~ /\.h$/);
18      }
19     print;
20    }
21   close(PIPE);
22   warn "Make retured $?\n";
23   last unless $?;
24   my $changed = 0;
25   foreach my $file (keys %fix)
26    {          
27     my @ar = sort( { $a->[0] <=> $b->[0] } @{delete $fix{$file}});
28     my @miss;
29     my $fixed = 0;
30     unless (-w $file)
31      {
32       system("d4","edit",$file);
33      }             
34     @ARGV = ($file);
35     $. = 0;
36     local $^I = '.sav';
37     while (<>)
38      {
39       while (@ar && $. == $ar[0][0])
40        {
41         my ($line,$var) = @{shift(@ar)};
42         if (s/\b$var\b/PL_$var/)
43          {
44           warn "$file:$line: FIX $var\n"; 
45           $fixed++;
46           $changed++;
47          }
48         else
49          {
50           push(@miss,[$line,$var,$_]);
51          }
52        }
53       print;
54      }
55     unless ($fixed)
56      {
57       rename("$file$^I",$file);
58       if (@miss)
59        {
60         while (@miss)
61          {
62           my ($line,$var,$txt) = @{shift(@miss)};
63           warn "$file:$line:$var | $txt";
64          }
65        }
66      }    
67    }
68   last unless $changed;
69  }