summaryrefslogtreecommitdiff
path: root/regen/opcode.pl
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-01-23 10:07:52 +0000
committerNicholas Clark <nick@ccl4.org>2011-01-23 10:07:52 +0000
commitf038801aea0ff24cf86511fa6679d7dcb859cd8d (patch)
tree8f46ea92b16a9121bab4ee0da59cdf219e43a254 /regen/opcode.pl
parent396ce246b9969d83ec11500def9604b58fb4c726 (diff)
downloadperl-f038801aea0ff24cf86511fa6679d7dcb859cd8d.tar.gz
In regen/*.pl, refactor the repeated code for close and rename if different.
Pass the final file name as an optional second argument of safer_open() and store it with the file handle. Add a function close_and_rename() which closes the file handle, then retrieves the final name, and renames the temporary file if the two differ.
Diffstat (limited to 'regen/opcode.pl')
-rwxr-xr-xregen/opcode.pl19
1 files changed, 5 insertions, 14 deletions
diff --git a/regen/opcode.pl b/regen/opcode.pl
index d0a3e1b90f..676583d0e3 100755
--- a/regen/opcode.pl
+++ b/regen/opcode.pl
@@ -20,10 +20,8 @@ BEGIN {
require 'regen/regen_lib.pl';
}
-my $opcode_new = 'opcode.h-new';
-my $opname_new = 'opnames.h-new';
-my $oc = safer_open($opcode_new);
-my $on = safer_open($opname_new);
+my $oc = safer_open('opcode.h-new', 'opcode.h');
+my $on = safer_open('opnames.h-new', 'opnames.h');
select $oc;
# Read data.
@@ -459,15 +457,10 @@ sub gen_op_is_macro {
foreach ($oc, $on) {
print $_ "/* ex: set ro: */\n";
- safer_close($_);
+ close_and_rename($_);
}
-rename_if_different $opcode_new, 'opcode.h';
-rename_if_different $opname_new, 'opnames.h';
-
-my $pp_proto_new = 'pp_proto.h-new';
-
-my $pp = safer_open($pp_proto_new);
+my $pp = safer_open('pp_proto.h-new', 'pp_proto.h');
print $pp read_only_top(lang => 'C', by => 'opcode.pl', from => 'its data');
@@ -481,9 +474,7 @@ print $pp read_only_top(lang => 'C', by => 'opcode.pl', from => 'its data');
}
print $pp "\n/* ex: set ro: */\n";
-safer_close($pp);
-
-rename_if_different $pp_proto_new, 'pp_proto.h';
+close_and_rename($pp);
###########################################################################
sub tab {