X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/9ad884cb5e6c71bf010defc627075ba1610c8eba..95aa056551f52c584698ab9faf16c6e993f2d2a5:/regen_lib.pl diff --git a/regen_lib.pl b/regen_lib.pl index 1c830a2..89ac3f9 100644 --- a/regen_lib.pl +++ b/regen_lib.pl @@ -1,7 +1,9 @@ #!/usr/bin/perl -w use strict; -use vars qw($Is_W32 $Is_OS2 $Is_Cygwin $Is_NetWare $Needs_Write); +use vars qw($Is_W32 $Is_OS2 $Is_Cygwin $Is_NetWare $Needs_Write $Verbose); use Config; # Remember, this is running using an existing perl +use File::Compare; +use Symbol; # Common functions needed by the regen scripts @@ -15,6 +17,8 @@ if ($Is_NetWare) { $Needs_Write = $Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare; +@ARGV = grep { not($_ eq '-v' and $Verbose = 1) } @ARGV; + sub safer_unlink { my @names = @_; my $cnt = 0; @@ -38,8 +42,31 @@ sub safer_rename_silent { rename $from, $to; } -sub safer_rename { +sub rename_if_different { my ($from, $to) = @_; + + if (compare($from, $to) == 0) { + warn "no changes between '$from' & '$to'\n" if $Verbose; + safer_unlink($from); + return; + } + warn "changed '$from' to '$to'\n"; safer_rename_silent($from, $to) or die "renaming $from to $to: $!"; } + +# Saf*er*, but not totally safe. And assumes always open for output. +sub safer_open { + my $name = shift; + my $fh = gensym; + open $fh, ">$name" or die "Can't create $name: $!"; + *{$fh}->{SCALAR} = $name; + binmode $fh; + $fh; +} + +sub safer_close { + my $fh = shift; + close $fh or die 'Error closing ' . *{$fh}->{SCALAR} . ": $!"; +} + 1;