--- /usr/bin/colorgcc	2009-04-29 09:55:55.000000000 +0200
+++ colorgcc	2010-05-26 13:52:39.331399430 +0200
@@ -195,7 +195,7 @@ sub srcscan
    # This substitute 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.
-   $line =~ s/(\`|\')(.*?)\'/\`$srcon$2$srcoff\'/g;
+   $line =~ s/(\`|\'|‘)(.*?)(\'|’)/$1$srcon$2$srcoff$3/gs;
 
    print($line, color("reset"));
 }
@@ -221,7 +221,13 @@ if (-f $configFile)
 $0 =~ m%.*/(.*)$%;
 $progName = $1 || $0;
 
-$compiler = $compilerPaths{$progName} || $compilerPaths{"gcc"};
+# timj: support colorg++-x.y => g++-x.y
+if ($progName =~ m/^color(cc|c\+\+|gcc|g\+\+|g77|f77|gobjc|gnat|gcj|gpc)/) {
+    $compiler = $progName;
+    $compiler =~ s/^color//;
+} else {
+    $compiler = $compilerPaths{$progName} || $compilerPaths{"gcc"};
+}
 @comp_list = split /\s+/, $compiler;
 $compiler = $comp_list[0];
 @comp_args = ( @comp_list[1 .. $#comp_list], @ARGV );
@@ -233,6 +239,12 @@ die "$compiler is self-referencing"
 # Get the terminal type. 
 $terminal = $ENV{"TERM"} || "dumb";
 
+# timj: support compiler cache ccache(1)
+if (-x "/usr/bin/ccache") {
+  unshift @comp_args, $compiler;
+  $compiler = "/usr/bin/ccache";
+}
+
 # If it's in the list of terminal types not to color, or if
 # we're writing to something that's not a tty, don't do color.
 if (! $ENV{"CGCC_FORCE_COLOR"} && (! -t STDOUT || $nocolor{$terminal}))
@@ -250,7 +262,21 @@ binmode(\*STDOUT,":bytes");
 # Colorize the output from the compiler.
 while(<GCCOUT>)
 {
-   if (m/^(.*?):([0-9]+):(.*)$/) # filename:lineno:message
+  NEXTLINE: # Handle next lines after multiline processing
+   # Append line continuations
+   $thisline = $_;
+   $nextline = "";
+   while (<GCCOUT>) {
+     if (m/^\s/) {	# Detect continuations through leading spaces
+       $thisline = $thisline . $_;
+     } else {		# No more continuations
+       $nextline = $_;
+       last;
+     }
+   }
+   $_ = $thisline;
+
+   if (m/^(.*?):([0-9]+):(.*)$/s) # filename:lineno:message
    {
       $field1 = $1 || "";
       $field2 = $2 || "";
@@ -281,9 +307,8 @@ while(<GCCOUT>)
 	 print($colors{"errorNumberColor"}, "$field2:", color("reset"));
 	 srcscan($field3, $colors{"errorMessageColor"});
       }
-      print("\n");
    }
-   elsif (m/^(<command-line>):(.*)$/) # special-location:message
+   elsif (m/^(<command-line>):(.*)$/s) # special-location:message
    {
       $field1 = $1 || "";
       $field2 = $2 || "";
@@ -311,9 +336,13 @@ while(<GCCOUT>)
 	 print($colors{"errorFileNameColor"}, "$field1:", color("reset"));
 	 srcscan($field2, $colors{"errorMessageColor"});
       }
-      print("\n");
    }
-   elsif (m/^(.*?):(.+):$/) # filename:message:
+   elsif (m/^(.*?):(.+):$/m) # filename:message:
+   {
+      # No line number, treat as an "introductory" line of text.
+      srcscan($_, $colors{"introColor"});
+   }
+   elsif (m/^(.*?):\s$/m) # filename: message text
    {
       # No line number, treat as an "introductory" line of text.
       srcscan($_, $colors{"introColor"});
@@ -323,6 +352,12 @@ while(<GCCOUT>)
       # Doesn't seem to be a warning or an error. Print normally.
       print(color("reset"), $_);
    }
+
+   # Continue with next line
+   if ($nextline) {
+     $_ = $nextline;
+     goto NEXTLINE;
+   }
 }
 
 # Get the return code of the compiler and exit with that.
