From d9bd7570d07a93026a3147971c8e34be6c1c6c86 Mon Sep 17 00:00:00 2001
From: Simon Ruderich <simon@ruderich.org>
Date: Thu, 22 Mar 2012 00:20:08 +0100
Subject: [PATCH] Don't split on ; in quotes.

---
 Build.PL              | 1 +
 bin/blhc              | 7 +++++--
 t/logs/bad-multiline  | 3 +++
 t/logs/good-multiline | 3 +++
 t/tests.t             | 2 ++
 5 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/Build.PL b/Build.PL
index 3edcfb8..051de84 100644
--- a/Build.PL
+++ b/Build.PL
@@ -35,6 +35,7 @@ my $build = Module::Build->new(
                             'Getopt::Long' => 0,
                             'Pod::Usage' => 0,
                             'Term::ANSIColor' => 0,
+                            'Text::ParseWords' => 0,
                           },
 );
 $build->create_build_script;
diff --git a/bin/blhc b/bin/blhc
index 3d5f73c..e183027 100755
--- a/bin/blhc
+++ b/bin/blhc
@@ -23,6 +23,7 @@ use warnings;
 
 use Getopt::Long ();
 use Term::ANSIColor ();
+use Text::ParseWords ();
 
 our $VERSION = '0.01';
 
@@ -393,8 +394,10 @@ while (my $line = <>) {
     my $non_verbose = is_non_verbose_build($line);
 
     # One line may contain multiple commands (";"). Treat each one as single
-    # line.
-    my @line = split /(?<!\\);/, $line;
+    # line. parse_line() is slow, only use it when necessary.
+    my @line = (not $line =~ /;/)
+             ? ($line)
+             : Text::ParseWords::parse_line(';', 1, $line);
     foreach $line (@line) {
         # Add newline, drop all other whitespace at the end of a line.
         $line =~ s/\s+$//;
diff --git a/t/logs/bad-multiline b/t/logs/bad-multiline
index ff7a826..e7c179b 100644
--- a/t/logs/bad-multiline
+++ b/t/logs/bad-multiline
@@ -40,3 +40,6 @@ else
     echo bad; \
 fi; \
 gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=1 -c test-b.c
+
+gcc -c test.c `echo -g -O2 -fstack-protector --param=ssp-buffer-size=4 echo -Wformat -Wformat-security -Werror=format-security | sed 's/.../; s/.../'` -o test.o
+gcc -c test.c `echo -g -O2 -fstack-protector --param=ssp-buffer-size=4 echo -Wformat -Wformat-security -Werror=format-security | sed "s/.../; s/.../"` -o test.o
diff --git a/t/logs/good-multiline b/t/logs/good-multiline
index 39bba6b..24a684f 100644
--- a/t/logs/good-multiline
+++ b/t/logs/good-multiline
@@ -38,3 +38,6 @@ gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-securit
 gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-b.c
 # Escaped ";" - not really useful, just to check it works.
 gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security \; -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-a.c
+
+gcc -c test.c `echo -g -O2 -fstack-protector --param=ssp-buffer-size=4 echo -Wformat -Wformat-security -Werror=format-security | sed 's/.../; s/.../'` -D_FORTIFY_SOURCE=2 -o test.o
+gcc -c test.c `echo -g -O2 -fstack-protector --param=ssp-buffer-size=4 echo -Wformat -Wformat-security -Werror=format-security | sed "s/.../; s/.../"` -D_FORTIFY_SOURCE=2 -o test.o
diff --git a/t/tests.t b/t/tests.t
index d754c64..2e31fdd 100644
--- a/t/tests.t
+++ b/t/tests.t
@@ -331,6 +331,8 @@ CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 --param=ssp-buffer-size=4 -Wf
 CFLAGS missing (-g -O2 --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security):  \ gcc -D_FORTIFY_SOURCE=2 -fstack-protector -c test-b.c
 CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security \; -Werror=format-security -D_FORTIFY_SOURCE=1 -c test-a.c
 CPPFLAGS missing (-D_FORTIFY_SOURCE=2):  \ gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=1 -c test-b.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -c test.c `echo -g -O2 -fstack-protector --param=ssp-buffer-size=4 echo -Wformat -Wformat-security -Werror=format-security | sed \'s/.../; s/.../\'` -o test.o
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -c test.c `echo -g -O2 -fstack-protector --param=ssp-buffer-size=4 echo -Wformat -Wformat-security -Werror=format-security | sed "s/.../; s/.../"` -o test.o
 ';
 
 is_blhc 'bad-library', '--all', 8,
-- 
2.49.0