]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/MigrationTools/org/tianocore/migration/Critic.java
slow edition
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Critic.java
index 9c81282038593f12c0c51ab632e7942c8d853350..97129b561b80570ea985197802b2e7f096c0d53b 100644 (file)
 package org.tianocore.migration;\r
 \r
 import java.util.regex.*;\r
+import java.io.*;\r
 \r
 public class Critic implements Common.ForDoAll {\r
        private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
        private static Pattern ptnfunccomment = Pattern.compile("([\\w\\d]*\\s*[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)(\\/\\*\\+\\+.*?)(\\-\\-\\*\\/\\s*)(.*?)([\\{;])",Pattern.DOTALL);\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 Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*-\\s*(.*)\\s*");\r
        private static Matcher mtrinfequation;\r
+       private static Matcher mtrfunccomment;\r
        \r
        public void toDo(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 description = false;\r
+                       boolean arguments = false;\r
+                       boolean returns = false;\r
+                       \r
                        System.out.println("Criticing   " + filepath);\r
                        String wholeline = Common.file2string(filepath);\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
+                       //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
+                       rd = new BufferedReader(new StringReader(wholeline));\r
+                       while ((line = rd.readLine()) != null) {\r
+                               if (line.contains("\\-\\-\\*\\/")) {\r
+                                       description = false;\r
+                                       arguments = false;\r
+                                       returns = false;\r
+                                       templine.append(line + "\n");\r
+                               } else 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
+                               } else if (line.contains("Returns:")) {\r
+                                       description = false;\r
+                                       arguments = false;\r
+                                       returns = true;\r
+                               } else if (description) {\r
+                                       templine.append(line + "\n");\r
+                                       //System.out.println("Description:" + line);\r
+                               } else if (arguments) {\r
+                                       mtrinfequation = ptninfequation.matcher(line);\r
+                                       if (mtrinfequation.find()) {\r
+                                               templine.append("  @param   " + mtrinfequation.group(1) + "     " + mtrinfequation.group(2) + "\n");\r
+                                       } else {\r
+                                               templine.append(line + "\n");\r
+                                       }\r
+                                       //System.out.println("Arguments:" + line);\r
+                               } else if (returns) {\r
+                                       mtrinfequation = ptninfequation.matcher(line);\r
+                                       if (mtrinfequation.find()) {\r
+                                               templine.append("  @retval   " + mtrinfequation.group(1) + "     " + mtrinfequation.group(2) + "\n");\r
+                                       } else {\r
+                                               templine.append(line + "\n");\r
+                                       }\r
+                                       //System.out.println("Returns:" + line);\r
+                               } else {\r
+                                       templine.append(line + "\n");\r
+                               }\r
+                       }\r
+                       wholeline = templine.toString();*/\r
                        /* -----slow edition of replacefirst with stringbuffer-----\r
                        line.append(wholeline);\r
                        mtrfunccomment = ptnfunccomment.matcher(line);\r
@@ -37,13 +89,13 @@ public class Critic implements Common.ForDoAll {
                                line.replace(0, line.length()-1, mtrfunccomment.replaceFirst("$2$4$3$1$5"));\r
                        }\r
                        */\r
-                       /* -----slow edition of replacefirst with string-----\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
                        /*\r
                        // edit func comment\r
                        mtrtempcomment = ptntempcomment.matcher(wholeline);\r