From 4a91c1a0b53f5415b7437b8e14ddfc848bf67dac Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Mon, 9 Oct 2017 17:22:07 +0100 Subject: [PATCH 1/3] Change generate_errors.pl to call perl grep Change the script generate_errors.pl to call the grep function in Perl instead of calling the external tool grep directly as this causes problems when ANSI escape sequences are included in the grep output string. --- scripts/generate_errors.pl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/generate_errors.pl b/scripts/generate_errors.pl index 9605d6802..623335eb5 100755 --- a/scripts/generate_errors.pl +++ b/scripts/generate_errors.pl @@ -46,7 +46,14 @@ close(FORMAT_FILE); $/ = $line_separator; -open(GREP, "grep \"define MBEDTLS_ERR_\" $include_dir/* |") || die("Failure when calling grep: $!"); +my @files = <$include_dir/*>; +my @matches; +foreach my $file (@files) { + open(FILE, "$file"); + my @grep_res = grep(/define MBEDTLS_ERR_/, ); + push(@matches, @grep_res); + close FILE; +} my $ll_old_define = ""; my $hl_old_define = ""; @@ -58,7 +65,8 @@ my $headers = ""; my %error_codes_seen; -while (my $line = ) + +foreach my $line (@matches) { next if ($line =~ /compat-1.2.h/); my ($error_name, $error_code) = $line =~ /(MBEDTLS_ERR_\w+)\s+\-(0x\w+)/; From 8936ffe66ace704ee2bf4b3a153aa81e77f84c4d Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 17 Oct 2017 21:23:15 +0100 Subject: [PATCH 2/3] Ensure that only .h files are parsed in generate_errors.pl --- scripts/generate_errors.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_errors.pl b/scripts/generate_errors.pl index 623335eb5..31fef28dd 100755 --- a/scripts/generate_errors.pl +++ b/scripts/generate_errors.pl @@ -46,7 +46,7 @@ close(FORMAT_FILE); $/ = $line_separator; -my @files = <$include_dir/*>; +my @files = <$include_dir/*.h>; my @matches; foreach my $file (@files) { open(FILE, "$file"); From 387ff071579c0011b33b85de16cfb414725c045e Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 17 Oct 2017 21:24:56 +0100 Subject: [PATCH 3/3] Make matching more robbust in generate_errors.pl --- scripts/generate_errors.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_errors.pl b/scripts/generate_errors.pl index 31fef28dd..cc9527e48 100755 --- a/scripts/generate_errors.pl +++ b/scripts/generate_errors.pl @@ -50,7 +50,7 @@ my @files = <$include_dir/*.h>; my @matches; foreach my $file (@files) { open(FILE, "$file"); - my @grep_res = grep(/define MBEDTLS_ERR_/, ); + my @grep_res = grep(/^\s*#define\s+MBEDTLS_ERR_\w+\s+\-0x[0-9A-Fa-f]+/, ); push(@matches, @grep_res); close FILE; }