OLD | NEW |
(Empty) | |
| 1 using System; |
| 2 using System.Collections.Generic; |
| 3 using System.Linq; |
| 4 using System.Text; |
| 5 |
| 6 using System.IO; |
| 7 using System.Text.RegularExpressions; |
| 8 |
| 9 namespace NaCl.Build.CPPTasks |
| 10 { |
| 11 class GCCUtilities |
| 12 { |
| 13 public const int s_CommandLineLength = 256; |
| 14 |
| 15 public static string Convert_Path_Windows_To_Posix(string path) |
| 16 { |
| 17 return path.Replace('\\', '/'); |
| 18 } |
| 19 |
| 20 public static string Convert_Path_Posix_To_Windows(string path) |
| 21 { |
| 22 path = path.Replace('/', '\\'); |
| 23 // also make double backslashes a single slash |
| 24 // TODO: speed this up by iterating instead of two replaces |
| 25 return path.Replace("\\\\", "\\"); |
| 26 } |
| 27 |
| 28 // replace GCC error are warning output to Visual Studio format to suppo
rt going to source code from error output. |
| 29 public static string Convert_Output_GCC_to_VS(string line) |
| 30 { |
| 31 string result; |
| 32 foreach (GCCRegexLineConverter converter in s_RegexConverters) |
| 33 { |
| 34 result = converter.Convert(line); |
| 35 if (result.Length > 0) |
| 36 { |
| 37 return result; |
| 38 } |
| 39 } |
| 40 |
| 41 return line; |
| 42 } |
| 43 |
| 44 private class GCCRegexLineConverter |
| 45 { |
| 46 public Regex OutputExpression { get; set; } |
| 47 |
| 48 //public string OutputIdentifier { get; set; } |
| 49 public string FilenameIdentifier { get; set; } |
| 50 public string RemainderIdentifier { get; set; } |
| 51 |
| 52 // returns empty string if cannot convert. |
| 53 public string Convert(string line) |
| 54 { |
| 55 //Regex expression = new Regex(OutputIdentifier); |
| 56 if (OutputExpression.IsMatch(line)) |
| 57 { |
| 58 string filename = OutputExpression.Replace(line, FilenameIde
ntifier); |
| 59 |
| 60 // GetFullPath may throw an exception. |
| 61 try |
| 62 { |
| 63 string fullPath = Path.GetFullPath(filename); |
| 64 string remainder = OutputExpression.Replace(line, Remain
derIdentifier); |
| 65 |
| 66 string newLine = fullPath + remainder; |
| 67 |
| 68 return newLine; |
| 69 } |
| 70 catch |
| 71 { |
| 72 } |
| 73 } |
| 74 |
| 75 return string.Empty; |
| 76 } |
| 77 } // GCCRegexLineConverter |
| 78 |
| 79 private static readonly List<GCCRegexLineConverter> s_RegexConverters =
new List<GCCRegexLineConverter> |
| 80 { |
| 81 new GCCRegexLineConverter |
| 82 { |
| 83 OutputExpression = new Regex(@"^\s*(.?.?[^:]*.*?):([1-9]\d*
):([1-9]\d*):(.*$)"), |
| 84 FilenameIdentifier = @"$1", |
| 85 RemainderIdentifier = @"($2,$3):$4" |
| 86 }, |
| 87 new GCCRegexLineConverter |
| 88 { |
| 89 OutputExpression = new Regex(@"^\s*(.?.?[^:]*.*?):([1-9]\d*
):(.*$)"), |
| 90 FilenameIdentifier = @"$1", |
| 91 RemainderIdentifier = @"($2):$3" |
| 92 }, |
| 93 new GCCRegexLineConverter |
| 94 { |
| 95 OutputExpression = new Regex(@"^\s*(.?.?[^:]*.*?):(.?.?[^:]
*.*?):([1-9]\d*):(.*$)"), |
| 96 FilenameIdentifier = @"$2", |
| 97 RemainderIdentifier = @"($3):'$1' $4" |
| 98 } |
| 99 }; |
| 100 } // GCCUtilities |
| 101 } // namespace |
OLD | NEW |