diff --git a/tools/compare.cs b/tools/compare.cs index a85641ec8..213875e00 100644 --- a/tools/compare.cs +++ b/tools/compare.cs @@ -53,27 +53,34 @@ namespace difftool return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; } + // color theme: + // http://www.eclipsecolorthemes.org/?view=theme&id=47 + private const string foregroundFont = ""; + private const string keywordFont = ""; + private const string numberFont = ""; + private const string stringFont = ""; + private const string singleLineCommentFont = ""; + private const string multiLineCommentFont = ""; + private const string lineNumberFont = ""; + static private void writeSourceFile(string path, string w, string filename) { string errorLoc = w.Substring(0, w.IndexOf(']')); string f = errorLoc.Substring(1, errorLoc.LastIndexOf(':')-1); int errorLine = Int32.Parse(errorLoc.Substring(1 + errorLoc.LastIndexOf(':'))); string[] lines = System.IO.File.ReadAllLines(path + f); - string[] keywords = { "void", "bool", "char", "short", "int", "long", "class", "struct", "enum", "for", "if", "while", "using", "namespace", "unsigned", "signed", "private", "protected", "public", - "static", "const" }; + string[] keywords = { "void", "bool", "char", "short", "int", "long", "double", "float", + "class", "struct", "union", "enum", "namespace", + "for", "if", "while", "using", "return", "unsigned", "signed", + "private", "protected", "public", + "static", "const", "template", "typename", "auto", + "true", "false", "this" }; System.IO.StreamWriter file = new System.IO.StreamWriter(path + filename); - file.Write("
" + textToHtml(w) + "\n");
-            int linenr = 1;
+            file.Write("" + textToHtml(w) + "
" + foregroundFont + textToHtml(w) + "\n");
+            int linenr = 0;
+            bool multiline = false;
             foreach (string line in lines) {
-                if (errorLine == linenr)
-                {
-                    file.Write("" + (linenr.ToString() + ":       ").Substring(0, 8) + textToHtml(line) + "\n");
-                    file.Write("" + textToHtml(w.Substring(errorLoc.Length+2)) + "\n");
-                    linenr++;
-                    continue;
-                }
-
-                file.Write((linenr.ToString() + ":       ").Substring(0, 8));
-                linenr++;
+                ++linenr;
+                file.Write(lineNumberFont + (linenr.ToString() + "        ").Substring(0, 8) + "");
 
                 for (int i = 0; i < line.Length;) {
                     if (line[i] == ' ')
@@ -81,6 +88,18 @@ namespace difftool
                         file.Write(line[i]);
                         i++;
                     }
+                    else if (multiline)
+                    {
+                        string currentToken = "";
+                        while (i < line.Length && multiline)
+                        {
+                            currentToken += line[i];
+                            i++;
+                            if (currentToken.EndsWith("*/"))
+                                multiline = false;
+                        }
+                        file.Write(multiLineCommentFont + textToHtml(currentToken) + "");
+                    }
                     else if (isNameChar(line[i]))
                     {
                         string currentToken = "";
@@ -90,9 +109,9 @@ namespace difftool
                             i++;
                         }
                         if (keywords.Contains(currentToken))
-                            file.Write("" + currentToken + "");
+                            file.Write(keywordFont + currentToken + "");
                         else if (currentToken[0] >= '0' && currentToken[0] <= '9')
-                            file.Write("" + currentToken + "");
+                            file.Write(numberFont + currentToken + "");
                         else
                             file.Write(currentToken);
                     }
@@ -106,22 +125,39 @@ namespace difftool
                             if (currentToken.Length > 1 && currentToken[0] == line[i - 1])
                                 break;
                         }
-                        file.Write("" + textToHtml(currentToken) + "");
+                        file.Write(stringFont + textToHtml(currentToken) + "");
                     }
                     else if (line[i] == '/' && i + 1 < line.Length && line[i + 1] == '/')
                     {
-                        file.Write("" + textToHtml(line.Substring(i)) + "");
+                        file.Write(singleLineCommentFont + textToHtml(line.Substring(i)) + "");
                         i = line.Length;
                     }
+                    else if (line[i] == '/' && i + 1 < line.Length && line[i + 1] == '*')
+                    {
+                        multiline = true;
+                        string currentToken = "/*";
+                        i += 2;
+                        while (i < line.Length && multiline)
+                        {
+                            currentToken += line[i];
+                            i++;
+                            if (currentToken.Length > 3 && currentToken.EndsWith("*/"))
+                                multiline = false;
+                        }
+                        file.Write(multiLineCommentFont + textToHtml(currentToken) + "");
+                    }
                     else
                     {
-                        file.Write(textToHtml(line.Substring(i,1)));
+                        file.Write(textToHtml(line.Substring(i, 1)));
                         i++;
                     }
                 }
                 file.Write('\n');
+
+                if (errorLine == linenr)
+                    file.Write("        " + textToHtml(w.Substring(errorLoc.Length + 2)) + "\n");
             }
-            file.Write("
"); + file.Write("
"); file.Close(); } @@ -157,13 +193,22 @@ namespace difftool file.WriteLine(""); file.WriteLine("Comparison 1.82 / Head"); file.WriteLine(""); - file.WriteLine(""); + file.WriteLine(""); + file.WriteLine(keywordFont); file.WriteLine("

Comparison 1.82 / Head

"); file.WriteLine("

Package: {0}

", @"ftp://ftp.se.debian.org/debian/pool/main/f/firefox/firefox_59.0~b4.orig.tar.bz2"); file.WriteLine("

+ Added warnings {0}

", added.Count); file.WriteLine("

- Removed warnings {0}

", removed.Count); + file.WriteLine("", 60 + Math.Max(added.Count, removed.Count) + 10, 40); + file.WriteLine(" "); + file.WriteLine(" Added"); + file.WriteLine(" Removed"); + file.WriteLine(" ", added.Count); + file.WriteLine(" ", removed.Count); + file.WriteLine(""); + file.WriteLine("

Added warnings

"); file.WriteLine("
");
                 foreach (string w in added)