]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Modify Critic
authoralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 17 Aug 2006 05:06:49 +0000 (05:06 +0000)
committeralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 17 Aug 2006 05:06:49 +0000 (05:06 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1302 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/MigrationTools/org/tianocore/migration/Common.java
Tools/Source/MigrationTools/org/tianocore/migration/Critic.java

index 3468a43cebb3c26fffcd260ddbae8834f8ec99ed..d3d781f32213b89d81c635c338ad874866a12a44 100644 (file)
@@ -29,6 +29,14 @@ public class Common {
                return wholefile.toString();\r
        }\r
 \r
+       public static void string2file(String content, String filename) throws Exception {\r
+               ensureDir(filename);\r
+               PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));\r
+               outfile.append(content);\r
+               outfile.flush();\r
+               outfile.close();\r
+       }\r
+\r
        public static void ensureDir(String objFileWhole) {\r
                File tempdir;\r
                Matcher mtrseparate = ptnseparate.matcher(objFileWhole);\r
@@ -38,14 +46,6 @@ public class Common {
                }\r
        }\r
        \r
-       public static void string2file(String content, String filename) throws Exception {\r
-               ensureDir(filename);\r
-               PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));\r
-               outfile.append(content);\r
-               outfile.flush();\r
-               outfile.close();\r
-       }\r
-       \r
        public static HashSet<String> dirScan(String path) {                    // use HashSet, persue speed rather than space\r
                HashSet<String> filelist = new HashSet<String>();\r
                String[] list = new File(path).list();\r
@@ -63,6 +63,14 @@ public class Common {
                return filelist;\r
        }\r
 \r
+       public static String replaceAll(String line, Pattern ptn, String des) {\r
+               Matcher mtr = ptn.matcher(line);\r
+               if (mtr.find()) {\r
+                        return mtr.replaceAll(des);\r
+               }\r
+               return line;\r
+       }\r
+       \r
        public static String dirCopy_(String src) throws Exception {\r
                Matcher mtrseparate = Common.ptnseparate.matcher(src);\r
                if (mtrseparate.find()) {\r
index 821305edf0035ae83508ea2ea31460459c375614..9c81282038593f12c0c51ab632e7942c8d853350 100644 (file)
@@ -15,46 +15,36 @@ package org.tianocore.migration;
 import java.util.regex.*;\r
 \r
 public class Critic implements Common.ForDoAll {\r
-       Critic() {\r
-               filepath = null;\r
-       }\r
-       Critic(String path) {\r
-               filepath = path;\r
-       }\r
-       \r
-       private String filepath = null;\r
-       \r
        private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
-       private static Matcher mtrheadcomment;\r
        private static Pattern ptnfunccomment = Pattern.compile("([\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)(\\/\\*\\+\\+.*?)(\\-\\-\\*\\/\\s*)(.*?)([\\{;])",Pattern.DOTALL);\r
-       private static Matcher mtrfunccomment;\r
-       private static Pattern ptncommentstructure = Pattern.compile("Routine Description:\\s*(\\w.*?\\w)\\s*Arguments:(\\s*\\w.*?\\w\\s*)Returns:(\\s*\\w.*?\\w\\s*)&%",Pattern.DOTALL);\r
-       private static Matcher mtrcommentstructure;\r
-       private static Pattern ptntempcomment = Pattern.compile("\\/\\*\\+\\+(.*?)\\-\\-\\*\\/\\s*[\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)",Pattern.DOTALL);\r
-       private static Matcher mtrtempcomment;\r
-       private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*-\\s*(\\w.*\\w)");\r
+       private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);\r
+       private static Pattern ptninfequation = Pattern.compile("#%%\\s*([^\\s]*\\s*-\\s*.*\\s*)*",Pattern.MULTILINE);\r
        private static Matcher mtrinfequation;\r
        \r
        public void toDo(String filepath) throws Exception {\r
-               String funccomment = null;\r
                if (filepath.contains(".c") || filepath.contains(".h")) {\r
                        System.out.println("Criticing   " + filepath);\r
                        String wholeline = Common.file2string(filepath);\r
                        \r
-                       // find head comment\r
-                       mtrheadcomment = ptnheadcomment.matcher(wholeline);\r
-                       if (mtrheadcomment.find()) {                    //as we find only the head comment here, use 'if' not 'while'\r
-                               wholeline = mtrheadcomment.replaceFirst("/** @file$1**/");\r
-                       }\r
+                       wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");\r
+                       wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$2$3$4$1$5");\r
+                       wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");\r
                        \r
-                       // find func comment\r
-                       mtrfunccomment = ptnfunccomment.matcher(wholeline);\r
+                       /* -----slow edition of replacefirst with stringbuffer-----\r
+                       line.append(wholeline);\r
+                       mtrfunccomment = ptnfunccomment.matcher(line);\r
                        while (mtrfunccomment.find()) {\r
-                               funccomment = mtrfunccomment.group(2) + "&%";\r
-                               mtrcommentstructure = ptncommentstructure.matcher(funccomment);\r
-                               wholeline = mtrfunccomment.replaceAll("$2$4$3$1$5");\r
+                               line.replace(0, line.length()-1, mtrfunccomment.replaceFirst("$2$4$3$1$5"));\r
                        }\r
-                       \r
+                       */\r
+                       /* -----slow edition of replacefirst with string-----\r
+                       while ((mtrfunccomment = ptnfunccomment.matcher(wholeline)).find()) {\r
+                               //funccomment = mtrfunccomment.group(2);\r
+                               //mtrcommentstructure = ptncommentstructure.matcher(funccomment);\r
+                               wholeline = mtrfunccomment.replaceFirst("$2$4$3$1$5");\r
+                       }\r
+                       */\r
+                       /*\r
                        // edit func comment\r
                        mtrtempcomment = ptntempcomment.matcher(wholeline);\r
                        while (mtrtempcomment.find()) {\r
@@ -62,6 +52,7 @@ public class Critic implements Common.ForDoAll {
                                System.out.println(mtrtempcomment.group());\r
                                System.out.println("-----------------------------");\r
                        }\r
+                       */\r
                        Common.string2file(wholeline, filepath);\r
                }\r
        }\r