diff options
author | Nicholas Clark <nick@ccl4.org> | 2008-03-15 18:37:34 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2008-03-15 18:37:34 +0000 |
commit | 424a4936e3f61f4e8db394f496a116e698cede85 (patch) | |
tree | e19475f64cd932d850b6975251ee284844aaf0d8 /regcomp.pl | |
parent | b6b9a09997c80269af874aff41936e014ed728f7 (diff) | |
download | perl-424a4936e3f61f4e8db394f496a116e698cede85.tar.gz |
Rename safer_rename() to rename_if_different(), to accurately describe
what it does. Use File::Compare rather than Digest::MD5, as the files
are small enough to simply read in. (File::Compare dates from 5.004)
Remove safer_rename_always(), which isn't used.
DRY by replacing the cargo-culted "open or die" with a new function
safer_open(), which uses Gensym (5.002) to create an anonymous file
handle, and opens and binmodes the file, or dies.
This necessitates replacing bareword file handles with lexicals in all
the callers.
Correct the names of files in close or die constructions.
p4raw-id: //depot/perl@33538
Diffstat (limited to 'regcomp.pl')
-rw-r--r-- | regcomp.pl | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/regcomp.pl b/regcomp.pl index defbb5f785..b6fc11dae1 100644 --- a/regcomp.pl +++ b/regcomp.pl @@ -68,11 +68,9 @@ my $tmp_h = 'tmp_reg.h'; unlink $tmp_h if -f $tmp_h; -open OUT, ">$tmp_h"; -#*OUT=\*STDOUT; -binmode OUT; +my $out = safer_open($tmp_h); -printf OUT <<EOP, +printf $out <<EOP, /* -*- buffer-read-only: t -*- !!!!!!! DO NOT EDIT THIS FILE !!!!!!! This file is built by regcomp.pl from regcomp.sym. @@ -92,16 +90,16 @@ EOP for ($ind=1; $ind <= $lastregop ; $ind++) { my $oind = $ind - 1; - printf OUT "#define\t%*s\t%d\t/* %#04x %s */\n", + printf $out "#define\t%*s\t%d\t/* %#04x %s */\n", -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind]; } -print OUT "\t/* ------------ States ------------- */\n"; +print $out "\t/* ------------ States ------------- */\n"; for ( ; $ind <= $tot ; $ind++) { - printf OUT "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n", + printf $out "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n", -$width, $name[$ind], $ind - $lastregop, $rest[$ind]; } -print OUT <<EOP; +print $out <<EOP; /* PL_regkind[] What type of regop or state is this. */ @@ -113,13 +111,13 @@ EOP $ind = 0; while (++$ind <= $tot) { - printf OUT "\t%*s\t/* %*s */\n", + printf $out "\t%*s\t/* %*s */\n", -1-$twidth, "$type[$ind],", -$width, $name[$ind]; - print OUT "\t/* ------------ States ------------- */\n" + print $out "\t/* ------------ States ------------- */\n" if $ind == $lastregop and $lastregop != $tot; } -print OUT <<EOP; +print $out <<EOP; }; #endif @@ -134,11 +132,11 @@ while (++$ind <= $lastregop) { my $size = 0; $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind]; - printf OUT "\t%*s\t/* %*s */\n", + printf $out "\t%*s\t/* %*s */\n", -37, "$size,",-$rwidth,$name[$ind]; } -print OUT <<EOP; +print $out <<EOP; }; /* reg_off_by_arg[] - Which argument holds the offset to the next node */ @@ -150,11 +148,11 @@ $ind = 0; while (++$ind <= $lastregop) { my $size = $longj[$ind] || 0; - printf OUT "\t%d,\t/* %*s */\n", + printf $out "\t%d,\t/* %*s */\n", $size, -$rwidth, $name[$ind] } -print OUT <<EOP; +print $out <<EOP; }; #endif /* REG_COMP_C */ @@ -173,17 +171,17 @@ my $sym = ""; while (++$ind <= $tot) { my $size = $longj[$ind] || 0; - printf OUT "\t%*s\t/* $sym%#04x */\n", + printf $out "\t%*s\t/* $sym%#04x */\n", -3-$width,qq("$name[$ind]",), $ind - $ofs; if ($ind == $lastregop and $lastregop != $tot) { - print OUT "\t/* ------------ States ------------- */\n"; + print $out "\t/* ------------ States ------------- */\n"; $ofs = $lastregop; $sym = 'REGNODE_MAX +'; } } -print OUT <<EOP; +print $out <<EOP; }; #endif /* DOINIT */ @@ -211,20 +209,20 @@ while (<$fh>) { } } my %vrxf=reverse %rxfv; -printf OUT "\t/* Bits in extflags defined: %032b */\n",$val; +printf $out "\t/* Bits in extflags defined: %032b */\n",$val; for (0..31) { my $n=$vrxf{2**$_}||"UNUSED_BIT_$_"; $n=~s/^RXf_(PMf_)?//; - printf OUT qq(\t%-20s/* 0x%08x */\n), + printf $out qq(\t%-20s/* 0x%08x */\n), qq("$n",),2**$_; } -print OUT <<EOP; +print $out <<EOP; }; #endif /* DOINIT */ /* ex: set ro: */ EOP -close OUT or die "close $tmp_h: $!"; +close $out or die "close $tmp_h: $!"; -safer_rename $tmp_h, 'regnodes.h'; +rename_if_different $tmp_h, 'regnodes.h'; |