]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/MigrationTools/org/tianocore/migration/Critic.java
\t 2 \ \ \ \
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Critic.java
index c987b9fe87c89548fb558e96ad2a431fc6e085e1..45670d94c2be9e5c3aa37f762322234ad9485e08 100644 (file)
@@ -16,192 +16,192 @@ import java.util.regex.*;
 import java.io.*;\r
 \r
 public final class Critic {\r
-       public static final Pattern PTN_NEW_HEAD_COMMENT = Pattern.compile("^\\/\\*\\*.*?\\*\\*\\/",Pattern.DOTALL);\r
-       private static final Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
-       private static final Pattern ptnfunccomment = Pattern.compile("([\\};\\/\">]\\s*)([\\w\\s\\*]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/(\\s*.*?)(?=[\\{;])",Pattern.DOTALL);              // find function with {;">/ , may be unsafe\r
-       //private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);\r
-       private static final Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");\r
-       private static Matcher mtrcommentequation;\r
-       private static final Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");\r
-       private static Matcher mtrnewcomment;\r
-       \r
-       private static final int totallinelength = 82;\r
-       \r
-       public static final void run(String filepath) throws Exception {\r
-               if (MigrationTool.doCritic) {                                   // this is left here to set an example for future structure\r
-                       critic(filepath);\r
-               }\r
-       }\r
-       \r
-       private static final void critic(String filepath) throws Exception {\r
-               if (filepath.contains(".c") || filepath.contains(".h")) {\r
-                       BufferedReader rd = null;\r
-                       String line = null;\r
-                       StringBuffer templine = new StringBuffer();\r
-                       boolean incomment = false;\r
+    public static final Pattern PTN_NEW_HEAD_COMMENT = Pattern.compile("^\\/\\*\\*.*?\\*\\*\\/",Pattern.DOTALL);\r
+    private static final Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
+    private static final Pattern ptnfunccomment = Pattern.compile("([\\};\\/\">]\\s*)([\\w\\s\\*]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/(\\s*.*?)(?=[\\{;])",Pattern.DOTALL);        // find function with {;">/ , may be unsafe\r
+    //private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);\r
+    private static final Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");\r
+    private static Matcher mtrcommentequation;\r
+    private static final Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");\r
+    private static Matcher mtrnewcomment;\r
+    \r
+    private static final int totallinelength = 82;\r
+    \r
+    public static final void run(String filepath) throws Exception {\r
+        if (MigrationTool.doCritic) {                    // this is left here to set an example for future structure\r
+            critic(filepath);\r
+        }\r
+    }\r
+    \r
+    private static final void critic(String filepath) throws Exception {\r
+        if (filepath.contains(".c") || filepath.contains(".h")) {\r
+            BufferedReader rd = null;\r
+            String line = null;\r
+            StringBuffer templine = new StringBuffer();\r
+            boolean incomment = false;\r
 \r
-                       System.out.println("Criticing   " + filepath);\r
-                       String wholeline = Common.file2string(filepath);\r
+            System.out.println("Criticing   " + filepath);\r
+            String wholeline = Common.file2string(filepath);\r
 \r
-                       wholeline = wholeline.replaceAll("\t", "  ");\r
-                       wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");\r
-                       wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1/**$3**/$4$2");\r
-                       //wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");\r
+            wholeline = wholeline.replaceAll("\t", "  ");\r
+            wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");\r
+            wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1/**$3**/$4$2");\r
+            //wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");\r
 \r
-                       // first scan\r
-                       boolean description = false;\r
-                       boolean arguments = false;\r
-                       boolean returns = false;\r
-                       boolean inequation = false;\r
-                       rd = new BufferedReader(new StringReader(wholeline));\r
-                       while ((line = rd.readLine()) != null) {\r
-                               if (line.matches("\\/\\*\\*")) {\r
-                                       incomment = true;\r
-                                       description = false;\r
-                                       arguments = false;\r
-                                       returns = false;\r
-                                       templine.append(line + "\n");\r
-                               } else if (line.matches("\\*\\*\\/")) {\r
-                                       incomment = false;\r
-                                       templine.append("\n" + line + "\n");\r
-                               } else if (incomment) {\r
-                                       if (line.contains("Routine Description:")) {\r
-                                               description = true;\r
-                                               arguments = false;\r
-                                               returns = false;\r
-                                       } else if (line.contains("Arguments:")) {\r
-                                               description = false;\r
-                                               arguments = true;\r
-                                               returns = false;\r
-                                               templine.append("\n");\r
-                                       } else if (line.contains("Returns:")) {\r
-                                               description = false;\r
-                                               arguments = false;\r
-                                               returns = true;\r
-                                               templine.append("\n");\r
-                                       } else if (description) {\r
-                                               if (line.trim().length() != 0) {\r
-                                                       templine.append("  " + line.trim() + "\n");\r
-                                               }\r
-                                       } else if (arguments) {\r
-                                               mtrcommentequation = ptncommentequation.matcher(line);\r
-                                               if (mtrcommentequation.find()) {\r
-                                                       inequation = true;\r
-                                                       templine.append("  @param  " + mtrcommentequation.group(1) + "     " + mtrcommentequation.group(2) + "\n");\r
-                                               } else if (inequation && line.trim().length() == 0) {\r
-                                                       inequation = false;\r
-                                               } else if (inequation && line.trim().length() != 0) {\r
-                                                       templine.append("#%#%" + line + "\n");\r
-                                               } else {\r
-                                                       if (line.trim().length() != 0) {\r
-                                                               templine.append("  " + line.trim() + "\n");\r
-                                                       }\r
-                                               }\r
-                                       } else if (returns) {\r
-                                               mtrcommentequation = ptncommentequation.matcher(line);\r
-                                               if (mtrcommentequation.find()) {\r
-                                                       inequation = true;\r
-                                                       templine.append("  @retval " + mtrcommentequation.group(1) + "     " + mtrcommentequation.group(2) + "\n");\r
-                                               } else if (inequation && line.trim().length() == 0) {\r
-                                                       inequation = false;\r
-                                               } else if (inequation && line.trim().length() != 0) {\r
-                                                       templine.append("#%#%" + line + "\n");\r
-                                               } else {\r
-                                                       if (line.trim().length() != 0) {\r
-                                                               templine.append("  @return " + line.trim() + "\n");\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                               } else {\r
-                                       templine.append(line + "\n");\r
-                               }\r
-                       }\r
-                       wholeline = templine.toString();\r
-                       wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");\r
-                       //\r
-                       \r
-                       // secend scan\r
-                       int startmax = 0;\r
-                       rd = new BufferedReader(new StringReader(wholeline));\r
-                       while ((line = rd.readLine()) != null) {\r
-                               if (line.matches("\\/\\*\\*")) {\r
-                                       incomment = true;\r
-                                       templine.append(line + "\n");\r
-                               } else if (line.matches("\\*\\*\\/")) {\r
-                                       incomment = false;\r
-                                       templine.append(line + "\n");\r
-                               } else if (incomment) {\r
-                                       mtrnewcomment = ptnnewcomment.matcher(line);\r
-                                       if (mtrnewcomment.find()) {\r
-                                               startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment.group(1).length() : startmax;\r
-                                       }\r
-                               }\r
-                       }\r
-                       startmax++;\r
-                       //\r
-                       \r
-                       // third scan\r
-                       int n = 0;\r
-                       String temp = null;\r
-                       String[] tempcont = null;\r
-                       int count = 0;\r
-                       templine = new StringBuffer();\r
-                       rd = new BufferedReader(new StringReader(wholeline));\r
-                       while ((line = rd.readLine()) != null) {\r
-                               if (line.matches("\\/\\*\\*")) {\r
-                                       incomment = true;\r
-                                       templine.append(line + "\n");\r
-                               } else if (line.matches("\\*\\*\\/")) {\r
-                                       incomment = false;\r
-                                       templine.append(line + "\n");\r
-                               } else if (incomment) {\r
-                                       mtrnewcomment = ptnnewcomment.matcher(line);\r
-                                       if (mtrnewcomment.find()) {\r
-                                               n = startmax - mtrnewcomment.group(1).length();\r
-                                               templine.append(mtrnewcomment.group(1));\r
-                                               while (n-- >= 0) {\r
-                                                       templine.append(" ");\r
-                                               }\r
-                                               temp = mtrnewcomment.group(3);\r
-                                               tempcont = temp.split(" ");                                                     // use \\s+ ?\r
-                                               \r
-                                               count = 0;\r
-                                               for (int i = 0; i < tempcont.length; i++) {\r
-                                                       count += tempcont[i].length();\r
-                                                       if (count <= (totallinelength - startmax)) {\r
-                                                               templine.append(tempcont[i] + " ");\r
-                                                               count += 1;\r
-                                                       } else {\r
-                                                               templine.append("\n");\r
-                                                               n = startmax;\r
-                                                               while (n-- >= 0) {\r
-                                                                       templine.append(" ");\r
-                                                               }\r
-                                                               templine.append(tempcont[i] + " ");\r
-                                                               count = tempcont[i].length() + 1;\r
-                                                       }\r
-                                               }\r
-                                               templine.append("\n");\r
-                                       } else {\r
-                                               templine.append(line + "\n");\r
-                                       }\r
-                               } else {\r
-                                       templine.append(line + "\n");\r
-                               }\r
-                       }\r
-                       wholeline = templine.toString();\r
-                       //\r
-                       // Remove trailing blanks.\r
-                       // \r
-                       wholeline = wholeline.replaceAll (" +\n", "\n");\r
-                       Common.string2file(wholeline, filepath);\r
-               }\r
-       }\r
-       \r
-       public static final void fireAt(String path) throws Exception {\r
-               //Common.toDoAll(Common.dirCopy_(path), Critic.class.getMethod("critic", String.class), null, null, Common.FILE);\r
-               Common.toDoAll(path, Critic.class.getMethod("run", String.class), null, null, Common.FILE);\r
-               //Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);\r
-               System.out.println("Critic Done");\r
-       }\r
+            // first scan\r
+            boolean description = false;\r
+            boolean arguments = false;\r
+            boolean returns = false;\r
+            boolean inequation = false;\r
+            rd = new BufferedReader(new StringReader(wholeline));\r
+            while ((line = rd.readLine()) != null) {\r
+                if (line.matches("\\/\\*\\*")) {\r
+                    incomment = true;\r
+                    description = false;\r
+                    arguments = false;\r
+                    returns = false;\r
+                    templine.append(line + "\n");\r
+                } else if (line.matches("\\*\\*\\/")) {\r
+                    incomment = false;\r
+                    templine.append("\n" + line + "\n");\r
+                } else if (incomment) {\r
+                    if (line.contains("Routine Description:")) {\r
+                        description = true;\r
+                        arguments = false;\r
+                        returns = false;\r
+                    } else if (line.contains("Arguments:")) {\r
+                        description = false;\r
+                        arguments = true;\r
+                        returns = false;\r
+                        templine.append("\n");\r
+                    } else if (line.contains("Returns:")) {\r
+                        description = false;\r
+                        arguments = false;\r
+                        returns = true;\r
+                        templine.append("\n");\r
+                    } else if (description) {\r
+                        if (line.trim().length() != 0) {\r
+                            templine.append("  " + line.trim() + "\n");\r
+                        }\r
+                    } else if (arguments) {\r
+                        mtrcommentequation = ptncommentequation.matcher(line);\r
+                        if (mtrcommentequation.find()) {\r
+                            inequation = true;\r
+                            templine.append("  @param  " + mtrcommentequation.group(1) + "     " + mtrcommentequation.group(2) + "\n");\r
+                        } else if (inequation && line.trim().length() == 0) {\r
+                            inequation = false;\r
+                        } else if (inequation && line.trim().length() != 0) {\r
+                            templine.append("#%#%" + line + "\n");\r
+                        } else {\r
+                            if (line.trim().length() != 0) {\r
+                                templine.append("  " + line.trim() + "\n");\r
+                            }\r
+                        }\r
+                    } else if (returns) {\r
+                        mtrcommentequation = ptncommentequation.matcher(line);\r
+                        if (mtrcommentequation.find()) {\r
+                            inequation = true;\r
+                            templine.append("  @retval " + mtrcommentequation.group(1) + "     " + mtrcommentequation.group(2) + "\n");\r
+                        } else if (inequation && line.trim().length() == 0) {\r
+                            inequation = false;\r
+                        } else if (inequation && line.trim().length() != 0) {\r
+                            templine.append("#%#%" + line + "\n");\r
+                        } else {\r
+                            if (line.trim().length() != 0) {\r
+                                templine.append("  @return " + line.trim() + "\n");\r
+                            }\r
+                        }\r
+                    }\r
+                } else {\r
+                    templine.append(line + "\n");\r
+                }\r
+            }\r
+            wholeline = templine.toString();\r
+            wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");\r
+            //\r
+            \r
+            // secend scan\r
+            int startmax = 0;\r
+            rd = new BufferedReader(new StringReader(wholeline));\r
+            while ((line = rd.readLine()) != null) {\r
+                if (line.matches("\\/\\*\\*")) {\r
+                    incomment = true;\r
+                    templine.append(line + "\n");\r
+                } else if (line.matches("\\*\\*\\/")) {\r
+                    incomment = false;\r
+                    templine.append(line + "\n");\r
+                } else if (incomment) {\r
+                    mtrnewcomment = ptnnewcomment.matcher(line);\r
+                    if (mtrnewcomment.find()) {\r
+                        startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment.group(1).length() : startmax;\r
+                    }\r
+                }\r
+            }\r
+            startmax++;\r
+            //\r
+            \r
+            // third scan\r
+            int n = 0;\r
+            String temp = null;\r
+            String[] tempcont = null;\r
+            int count = 0;\r
+            templine = new StringBuffer();\r
+            rd = new BufferedReader(new StringReader(wholeline));\r
+            while ((line = rd.readLine()) != null) {\r
+                if (line.matches("\\/\\*\\*")) {\r
+                    incomment = true;\r
+                    templine.append(line + "\n");\r
+                } else if (line.matches("\\*\\*\\/")) {\r
+                    incomment = false;\r
+                    templine.append(line + "\n");\r
+                } else if (incomment) {\r
+                    mtrnewcomment = ptnnewcomment.matcher(line);\r
+                    if (mtrnewcomment.find()) {\r
+                        n = startmax - mtrnewcomment.group(1).length();\r
+                        templine.append(mtrnewcomment.group(1));\r
+                        while (n-- >= 0) {\r
+                            templine.append(" ");\r
+                        }\r
+                        temp = mtrnewcomment.group(3);\r
+                        tempcont = temp.split(" ");                            // use \\s+ ?\r
+                        \r
+                        count = 0;\r
+                        for (int i = 0; i < tempcont.length; i++) {\r
+                            count += tempcont[i].length();\r
+                            if (count <= (totallinelength - startmax)) {\r
+                                templine.append(tempcont[i] + " ");\r
+                                count += 1;\r
+                            } else {\r
+                                templine.append("\n");\r
+                                n = startmax;\r
+                                while (n-- >= 0) {\r
+                                    templine.append(" ");\r
+                                }\r
+                                templine.append(tempcont[i] + " ");\r
+                                count = tempcont[i].length() + 1;\r
+                            }\r
+                        }\r
+                        templine.append("\n");\r
+                    } else {\r
+                        templine.append(line + "\n");\r
+                    }\r
+                } else {\r
+                    templine.append(line + "\n");\r
+                }\r
+            }\r
+            wholeline = templine.toString();\r
+            //\r
+            // Remove trailing blanks.\r
+            // \r
+            wholeline = wholeline.replaceAll (" +\n", "\n");\r
+            Common.string2file(wholeline, filepath);\r
+        }\r
+    }\r
+    \r
+    public static final void fireAt(String path) throws Exception {\r
+        //Common.toDoAll(Common.dirCopy_(path), Critic.class.getMethod("critic", String.class), null, null, Common.FILE);\r
+        Common.toDoAll(path, Critic.class.getMethod("run", String.class), null, null, Common.FILE);\r
+        //Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);\r
+        System.out.println("Critic Done");\r
+    }\r
 }
\ No newline at end of file