3 use vars qw($Needs_Write $Verbose @Changed $TAP);
8 # Common functions needed by the regen scripts
10 $Needs_Write = $^O eq 'cygwin' || $^O eq 'os2' || $^O eq 'MSWin32';
13 @ARGV = grep { not($_ eq '-q' and $Verbose = -1) }
14 grep { not($_ eq '--tap' and $TAP = 1) }
15 grep { not($_ eq '-v' and $Verbose = 1) } @ARGV;
18 print STDOUT "Changed: @Changed\n" if @Changed;
26 foreach $name (@names) {
28 chmod 0777, $name if $Needs_Write;
29 ( CORE::unlink($name) and ++$cnt
30 or warn "Couldn't unlink $name: $!\n" );
35 sub safer_rename_silent {
38 # Some dosish systems can't rename over an existing file:
40 chmod 0600, $from if $Needs_Write;
44 sub rename_if_different {
48 my $not = compare($from, $to) ? 'not ' : '';
49 print STDOUT $not . "ok - $0 $to\n";
53 if (compare($from, $to) == 0) {
54 warn "no changes between '$from' & '$to'\n" if $Verbose > 0;
58 warn "changed '$from' to '$to'\n" if $Verbose > 0;
59 push @Changed, $to unless $Verbose < 0;
60 safer_rename_silent($from, $to) or die "renaming $from to $to: $!";
63 # Saf*er*, but not totally safe. And assumes always open for output.
67 unlink $name or die "$name exists but can't unlink: $!";
70 open $fh, ">$name" or die "Can't create $name: $!";
71 *{$fh}->{name} = $name;
78 close $fh or die 'Error closing ' . *{$fh}->{name} . ": $!";
83 die "Missing language argument" unless defined $args{lang};
84 die "Unknown language argument '$args{lang}'"
85 unless $args{lang} eq 'Perl' or $args{lang} eq 'C';
86 my $style = $args{style} ? " $args{style} " : ' ';
88 my $raw = "-*- buffer-read-only: t -*-\n";
91 $raw .= "\n $args{file}\n";
93 if ($args{copyright}) {
95 local $Text::Wrap::columns = 75;
96 $raw .= wrap(' ', ' ', <<"EOM") . "\n";
98 Copyright (C) @{$args{copyright}} by\0Larry\0Wall\0and\0others
100 You may distribute under the terms of either the GNU General Public
101 License or the Artistic License, as specified in the README file.
105 $raw .= "!!!!!!! DO NOT EDIT THIS FILE !!!!!!!\n";
108 $raw .= "This file is built by $args{by}";
110 my @from = ref $args{from} eq 'ARRAY' ? @{$args{from}} : $args{from};
111 my $last = pop @from;
113 $raw .= ' from ' . join (', ', @from) . " and $last";
115 $raw .= " from $last";
120 $raw .= "Any changes made here will be lost!\n";
121 $raw .= $args{final} if $args{final};
123 local $Text::Wrap::columns = 78;
124 my $cooked = $args{lang} eq 'Perl'
125 ? wrap('# ', '# ', $raw) . "\n" : wrap('/* ', $style, $raw) . " */\n\n";
126 $cooked =~ tr/\0/ /; # Don't break Larry's name etc
127 $cooked =~ s/ +$//mg; # Remove all trailing spaces