Subject: [PATCH 01/18] Print the line number of opening of unterminated heredoc or quoted str

From: Raphael Geissert <[email-masked]>
Date: Fri, 19 Oct 2012 17:59:46 -0500

It is particularly useful when debugging such errors in big scripts.

Signed-off-by: Raphael Geissert <[email-masked]>
---
 scripts/checkbashisms.pl |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/scripts/checkbashisms.pl b/scripts/checkbashisms.pl
index 479e782..cb19ad3 100755
--- a/scripts/checkbashisms.pl
+++ b/scripts/checkbashisms.pl
@@ -124,6 +124,7 @@ foreach my $filename (@ARGV) {
     my $found_rules = 0;
     my $buffered_orig_line = "";
     my $buffered_line = "";
+    my %start_lines;
 
     while (<C>) {
 	next unless ($check_lines_count == -1 or $. <= $check_lines_count);
@@ -314,6 +315,7 @@ foreach my $filename (@ARGV) {
 		    # start of a quoted block.
 		    if ($count % 2 == 1) {
 			$quote_string = $quote;
+			$start_lines{'quote_string'} = $.;
 			$line =~ s/^(.*)$quote.*$/$1/;
 			last;
 		    }
@@ -415,13 +417,14 @@ foreach my $filename (@ARGV) {
 		$cat_indented = ($1 && $1 eq '-')? 1 : 0;
 		$cat_string = $2;
 		$cat_string = $3 if not defined $cat_string;
+		$start_lines{'cat_string'} = $.;
             }
 	}
     }
 
-    warn "error: $filename:  Unterminated heredoc found, EOF reached. Wanted: <$cat_string>\n"
+    warn "error: $filename:  Unterminated heredoc found, EOF reached. Wanted: <$cat_string>, opened in line $start_lines{'cat_string'}\n"
 	if ($cat_string ne '');
-    warn "error: $filename: Unterminated quoted string found, EOF reached. Wanted: <$quote_string>\n"
+    warn "error: $filename: Unterminated quoted string found, EOF reached. Wanted: <$quote_string>, opened in line $start_lines{'quote_string'}\n"
 	if ($quote_string ne '');
     warn "error: $filename: EOF reached while on line continuation.\n"
 	if ($buffered_line ne '');
-- 
1.7.10