From 6e245c6e952b1d7c811a92a2078e9a4aa176b460 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 22 Apr 2021 20:09:25 +0200 Subject: [PATCH] Simplify line ending management and make it work on Windows Instead of manipulating CR explicitly to cope with CRLF (Windows) line endings in input and produce output with CRLF line endings, just convert files from/to CRLF line endings when reading/writing. The minimum required Perl version remains 5.8, since this both the version that introduced Digest::MD5 (which was used before this patch) and the version that introduced open "<:crlf" (which this patch introduces). Signed-off-by: Gilles Peskine --- scripts/generate_visualc_files.pl | 51 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/scripts/generate_visualc_files.pl b/scripts/generate_visualc_files.pl index f325e9a98..5500c6fad 100755 --- a/scripts/generate_visualc_files.pl +++ b/scripts/generate_visualc_files.pl @@ -79,31 +79,30 @@ my @excluded_files = qw( my %excluded_files = (); foreach (@excluded_files) { $excluded_files{$_} = 1 } -# Need windows line endings! my $vsx_hdr_tpl = <\r + EOT my $vsx_src_tpl = <\r + EOT my $vsx_sln_app_entry_tpl = <; close $fh; @@ -137,7 +136,7 @@ sub slurp_file { sub content_to_file { my ($content, $filename) = @_; - open my $fh, '>', $filename or die "Could not write to $filename\n"; + open my $fh, '>:crlf', $filename or die "Could not write to $filename\n"; print $fh $content; close $fh; } @@ -161,17 +160,17 @@ sub gen_app { my $srcs = ""; if( $appname eq "ssl_client2" or $appname eq "ssl_server2" or $appname eq "query_compile_time_config" ) { - $srcs .= "\r\n "; + $srcs .= "\n "; } if( $appname eq "ssl_client2" or $appname eq "ssl_server2" ) { - $srcs .= "\r\n "; + $srcs .= "\n "; } my $content = $template; $content =~ s//$srcs/g; $content =~ s//$appname/g; $content =~ s//$guid/g; - $content =~ s/INCLUDE_DIRECTORIES\r\n/$include_directories/g; + $content =~ s/INCLUDE_DIRECTORIES\n/$include_directories/g; content_to_file( $content, "$dir/$appname.$ext" ); } @@ -214,9 +213,9 @@ sub gen_main_file { my $source_entries = gen_entry_list( $src_tpl, @$sources ); my $out = slurp_file( $main_tpl ); - $out =~ s/SOURCE_ENTRIES\r\n/$source_entries/m; - $out =~ s/HEADER_ENTRIES\r\n/$header_entries/m; - $out =~ s/INCLUDE_DIRECTORIES\r\n/$library_include_directories/g; + $out =~ s/SOURCE_ENTRIES\n/$source_entries/m; + $out =~ s/HEADER_ENTRIES\n/$header_entries/m; + $out =~ s/INCLUDE_DIRECTORIES\n/$library_include_directories/g; content_to_file( $out, $main_out ); } @@ -242,8 +241,8 @@ sub gen_vsx_solution { } my $out = slurp_file( $vsx_sln_tpl_file ); - $out =~ s/APP_ENTRIES\r\n/$app_entries/m; - $out =~ s/CONF_ENTRIES\r\n/$conf_entries/m; + $out =~ s/APP_ENTRIES\n/$app_entries/m; + $out =~ s/CONF_ENTRIES\n/$conf_entries/m; content_to_file( $out, $vsx_sln_file ); }