summaryrefslogtreecommitdiff
blob: 6cc033255a2a2364ea769f7723a02faa5cfb21d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
--- a/colorgcc
+++ b/colorgcc
@@ -95,6 +95,7 @@
 use Cwd 'abs_path';
 
 my(%nocolor, %colors, %compilerPaths);
+my($unfinishedQuote, $previousColor);
 
 sub initDefaults
 {
@@ -159,14 +160,37 @@
 
    my($line, $normalColor) = @_;
 
+   if (defined $normalColor)
+   {
+      $previousColor = $normalColor;
+   }
+   else
+   {
+      $normalColor = $previousColor;
+   }
+
    my($srcon) = color("reset") . $colors{"srcColor"};
    my($srcoff) = color("reset") . $normalColor;
 
-   $line = $normalColor . $line;
+   $line = ($unfinishedQuote? $srcon : $normalColor) . $line;
 
-   # This substitute replaces `foo' with `AfooB' where A is the escape
+   # These substitutions replaces `foo' with `AfooB' where A is the escape
    # sequence that turns on the the desired source color, and B is the
    # escape sequence that returns to $normalColor.
+
+   # Handle multi-line quotes.
+   if ($unfinishedQuote) {
+      if ($line =~ s/^([^\`]*?)\'/$1$srcoff\'/)
+      {
+	 $unfinishedQuote = 0;
+      }
+   }
+   if ($line =~ s/\`([^\']*?)$/\`$srcon$1/)
+   {
+      $unfinishedQuote = 1;
+   }
+
+   # Single line quoting.
    $line =~ s/\`(.*?)\'/\`$srcon$1$srcoff\'/g;
 
    print($line, color("reset"));
@@ -190,6 +214,10 @@
    loadPreferences('/etc/colorgcc/colorgccrc');
 }
 
+# Set our default output color.  This presumes that any unrecognized output
+# is an error.
+$previousColor = $colors{"errorMessageColor"};
+
 # Figure out which compiler to invoke based on our program name.
 $0 =~ m%.*/(.*)$%;
 my $progName = $1 || $0;
@@ -281,10 +309,9 @@
       # No line number, treat as an "introductory" line of text.
       srcscan($_, $colors{"introColor"});
    }
-   else # Anything else.        
+   else # Anything else.
    {
-      # Doesn't seem to be a warning or an error. Print normally.
-      print(color("reset"), $_);
+      srcscan($_, undef);
    }
 }