+/** @file\r
+ \r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+ \r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ \r
+ **/\r
package org.tianocore.migration;\r
\r
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 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
if (filepath.contains(".c") || filepath.contains(".h")) {\r
+ System.out.println("Criticing " + filepath);\r
String wholeline = Common.file2string(filepath);\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
- Common.string2file(wholeline, 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
+ /* -----slow edition of replacefirst with stringbuffer-----\r
+ line.append(wholeline);\r
+ mtrfunccomment = ptnfunccomment.matcher(line);\r
+ while (mtrfunccomment.find()) {\r
+ line.replace(0, line.length()-1, mtrfunccomment.replaceFirst("$2$4$3$1$5"));\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
+ System.out.println("-----------------------------");\r
+ System.out.println(mtrtempcomment.group());\r
+ System.out.println("-----------------------------");\r
+ }\r
+ */\r
+ Common.string2file(wholeline, filepath);\r
}\r
}\r
\r
public static void fireAt(String path) throws Exception {\r
- Common.toDoAll(path, new Critic());\r
+ Critic critic = new Critic();\r
+ Common.toDoAll(Common.dirCopy_(path), critic);\r
System.out.println("Critic Done");\r
}\r
}\r
+//analyze func comment\r
+/*if (mtrcommentstructure.find()) {\r
+ newcomment.append("/*++\n\n" + mtrcommentstructure.group(1) + "\n\n");\r
+ \r
+ //System.out.println("-------1-------");\r
+ //System.out.println(mtrcommentstructure.group(1));\r
+ \r
+ // arg\r
+ //System.out.println("-------2-------");\r
+ //System.out.println(mtrcommentstructure.group(2));\r
+ mtrinfequation = ptninfequation.matcher(mtrcommentstructure.group(2));\r
+ while (mtrinfequation.find()) {\r
+ newcomment.append("@param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");\r
+ //System.out.println("@param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2));\r
+ }\r
+ newcomment.append("\n");\r
+ // return\r
+ //System.out.println("-------3-------");\r
+ //System.out.println(mtrcommentstructure.group(3));\r
+ mtrinfequation = ptninfequation.matcher(mtrcommentstructure.group(3));\r
+ while (mtrinfequation.find()) {\r
+ newcomment.append("@retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");\r
+ //System.out.println("@retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2));\r
+ }\r
+ System.out.println(newcomment);\r
+} else {\r
+ System.out.println("Error: Comment Style Incorrect");\r
+}*/
\ No newline at end of file