This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: Large omnibus patch to clean up the JRRT quotes
[perl5.git] / regen_lib.pl
CommitLineData
9ad884cb
JH
1#!/usr/bin/perl -w
2use strict;
523b3031
NC
3use vars qw($Is_W32 $Is_OS2 $Is_Cygwin $Is_NetWare $Needs_Write $Verbose
4 @Changed);
9ad884cb 5use Config; # Remember, this is running using an existing perl
424a4936
NC
6use File::Compare;
7use Symbol;
9ad884cb
JH
8
9# Common functions needed by the regen scripts
10
11$Is_W32 = $^O eq 'MSWin32';
12$Is_OS2 = $^O eq 'os2';
13$Is_Cygwin = $^O eq 'cygwin';
14$Is_NetWare = $Config{osname} eq 'NetWare';
15if ($Is_NetWare) {
16 $Is_W32 = 0;
17}
18
19$Needs_Write = $Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare;
20
523b3031
NC
21$Verbose = 0;
22@ARGV = grep { not($_ eq '-q' and $Verbose = -1) }
23 grep { not($_ eq '-v' and $Verbose = 1) } @ARGV;
24
25END {
26 print STDOUT "Changed: @Changed\n" if @Changed;
27}
95aa0565 28
9ad884cb
JH
29sub safer_unlink {
30 my @names = @_;
31 my $cnt = 0;
32
33 my $name;
34 foreach $name (@names) {
35 next unless -e $name;
36 chmod 0777, $name if $Needs_Write;
37 ( CORE::unlink($name) and ++$cnt
38 or warn "Couldn't unlink $name: $!\n" );
39 }
40 return $cnt;
41}
42
43sub safer_rename_silent {
44 my ($from, $to) = @_;
45
46 # Some dosish systems can't rename over an existing file:
47 safer_unlink $to;
48 chmod 0600, $from if $Needs_Write;
49 rename $from, $to;
50}
51
424a4936 52sub rename_if_different {
9ad884cb 53 my ($from, $to) = @_;
b6b9a099 54
424a4936 55 if (compare($from, $to) == 0) {
523b3031 56 warn "no changes between '$from' & '$to'\n" if $Verbose > 0;
b6b9a099
JC
57 safer_unlink($from);
58 return;
59 }
523b3031
NC
60 warn "changed '$from' to '$to'\n" if $Verbose > 0;
61 push @Changed, $to unless $Verbose < 0;
9ad884cb
JH
62 safer_rename_silent($from, $to) or die "renaming $from to $to: $!";
63}
424a4936
NC
64
65# Saf*er*, but not totally safe. And assumes always open for output.
66sub safer_open {
67 my $name = shift;
68 my $fh = gensym;
69 open $fh, ">$name" or die "Can't create $name: $!";
08858ed2 70 *{$fh}->{SCALAR} = $name;
424a4936
NC
71 binmode $fh;
72 $fh;
73}
74
08858ed2
NC
75sub safer_close {
76 my $fh = shift;
77 close $fh or die 'Error closing ' . *{$fh}->{SCALAR} . ": $!";
78}
79
9ad884cb 801;