summaryrefslogtreecommitdiff
path: root/regen/regen_lib.pl
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-01-23 10:38:58 +0000
committerNicholas Clark <nick@ccl4.org>2011-01-23 10:41:25 +0000
commitce716c52d393ac84495b7b8f262c39ecc5447cc9 (patch)
tree8053d9bd192b318367aa7c50b3910bc88b706422 /regen/regen_lib.pl
parentf038801aea0ff24cf86511fa6679d7dcb859cd8d (diff)
downloadperl-ce716c52d393ac84495b7b8f262c39ecc5447cc9.tar.gz
Change close_and_rename() to read_only_bottom_close_and_rename()
All users of close_and_rename() were printing out the appropriate "ex: set ro:" string to the file handle immediately before closing it. So move that into the common function and rename it to reflect what it now does. [Except overload.pl, which should have been, given that it calls read_only_top()] Print a newline above the "ex: set ro:" line. This removes many newlines from the regen scripts, but does add newlines to a couple of generated files.
Diffstat (limited to 'regen/regen_lib.pl')
-rw-r--r--regen/regen_lib.pl10
1 files changed, 8 insertions, 2 deletions
diff --git a/regen/regen_lib.pl b/regen/regen_lib.pl
index d8cbd12bf5..90f10b57bc 100644
--- a/regen/regen_lib.pl
+++ b/regen/regen_lib.pl
@@ -69,7 +69,10 @@ sub safer_open {
my $fh = gensym;
open $fh, ">$name" or die "Can't create $name: $!";
*{$fh}->{name} = $name;
- *{$fh}->{final_name} = $final_name if defined $final_name;
+ if (defined $final_name) {
+ *{$fh}->{final_name} = $final_name;
+ *{$fh}->{lang} = ($final_name =~ /\.[ch]$/ ? 'C' : 'Perl');
+ }
binmode $fh;
$fh;
}
@@ -129,11 +132,14 @@ EOM
return $cooked;
}
-sub close_and_rename {
+sub read_only_bottom_close_and_rename {
my $fh = shift;
my $name = *{$fh}->{name};
+ my $lang = *{$fh}->{lang};
die "No final name specified at open time for $name"
unless *{$fh}->{final_name};
+ print $fh $lang eq 'Perl'
+ ? "\n# ex: set ro:\n" : "\n/* ex: set ro: */\n";
safer_close($fh);
rename_if_different($name, *{$fh}->{final_name});
}