diff options
author | Richard Levitte <levitte@openssl.org> | 2016-02-11 21:47:30 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2016-02-11 22:11:48 +0100 |
commit | 9ba96fbb2523cb12747c559c704c58bd8f9e7982 (patch) | |
tree | c93cfeeea0efd2e65b513c1fd8caf7acaf259a7c /util/mkdef.pl | |
parent | c15e95a61dacfc326cf9cdf05935ae8c6c97bcf6 (diff) | |
download | openssl-9ba96fbb2523cb12747c559c704c58bd8f9e7982.tar.gz |
Perl's chop / chomp considered bad, use a regexp instead
Once upon a time, there was chop, which somply chopped off the last
character of $_ or a given variable, and it was used to take off the
EOL character (\n) of strings.
... but then, you had to check for the presence of such character.
So came chomp, the better chop which checks for \n before chopping it
off. And this worked well, as long as Perl made internally sure that
all EOLs were converted to \n.
These days, though, there seems to be a mixture of perls, so lines
from files in the "wrong" environment might have \r\n as EOL, or just
\r (Mac OS, unless I'm misinformed).
So it's time we went for the more generic variant and use s|\R$||, the
better chomp which recognises all kinds of known EOLs and chops them
off.
A few chops were left alone, as they are use as surgical tools to
remove one last slash or one last comma.
NOTE: \R came with perl 5.10.0. It means that from now on, our
scripts will fail with any older version.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'util/mkdef.pl')
-rwxr-xr-x | util/mkdef.pl | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/util/mkdef.pl b/util/mkdef.pl index aa85ec8251..b5ebc18b8e 100755 --- a/util/mkdef.pl +++ b/util/mkdef.pl @@ -459,7 +459,7 @@ sub do_defs if($parens > 0) { #Inside a DEPRECATEDIN $stored_multiline .= $_; - chomp $stored_multiline; + $stored_multiline =~ s|\R$||; # Better chomp print STDERR "DEBUG: Continuing multiline DEPRECATEDIN: $stored_multiline\n" if $debug; $parens = count_parens($stored_multiline); if ($parens == 0) { @@ -480,9 +480,7 @@ sub do_defs } if (/\\$/) { - chomp; # remove eol - chop; # remove ending backslash - $line = $_; + $line = $`; # keep what was before the backslash next; } @@ -499,7 +497,7 @@ sub do_defs $cpp++ if /^#\s*if/; $cpp-- if /^#\s*endif/; next; - } + } $cpp = 1 if /^#.*ifdef.*cplusplus/; s/{[^{}]*}//gs; # ignore {} blocks @@ -867,7 +865,7 @@ sub do_defs \@current_algorithms); } else { $stored_multiline = $_; - chomp $stored_multiline; + $stored_multiline =~ s|\R$||; print STDERR "DEBUG: Found multiline DEPRECATEDIN starting with: $stored_multiline\n" if $debug; next; } @@ -1365,7 +1363,7 @@ sub load_numbers open(IN,"<$name") || die "unable to open $name:$!\n"; while (<IN>) { - chop; + s|\R$||; # Better chomp s/#.*$//; next if /^\s*$/; @a=split; |