package org.tianocore.migration;\r
\r
-import java.io.BufferedReader;\r
-import java.io.File;\r
-import java.io.FileReader;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
+import java.io.*;\r
+import java.util.regex.*;\r
+import java.util.*;\r
\r
public class Common {\r
- public static String sourcefiletostring(String filename) throws Exception {\r
+ public static String file2string(String filename) throws Exception {\r
BufferedReader rd = new BufferedReader(new FileReader(filename));\r
StringBuffer wholefile = new StringBuffer();\r
String line;\r
tempdir = new File(mtrseparate.group(1));\r
if (!tempdir.exists()) tempdir.mkdirs();\r
}\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
+ File test;\r
+\r
+ for (int i = 0 ; i < list.length ; i++) {\r
+ test = new File(path + File.separator + list[i]);\r
+ if (test.isDirectory()) {\r
+ dirScan(path + File.separator + list[i]);\r
+ } else {\r
+ filelist.add(path + File.separator + list[i]);\r
+ }\r
+ }\r
\r
+ return filelist;\r
+ }\r
+ \r
+ public static void toDoAll(String path, ForDoAll fda) throws Exception { // filter of file type can be done in toDo\r
+ String[] list = new File(path).list();\r
+ File test;\r
+\r
+ for (int i = 0 ; i < list.length ; i++) {\r
+ test = new File(path + File.separator + list[i]);\r
+ if (test.isDirectory()) {\r
+ toDoAll(path + File.separator + list[i], fda);\r
+ } else {\r
+ fda.toDo(path + File.separator + list[i]);\r
+ }\r
+ }\r
+ }\r
+ \r
+ public static interface ForDoAll {\r
+ public void toDo(String filepath) throws Exception;\r
}\r
}\r
--- /dev/null
+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
+ \r
+ public void toDo(String filepath) throws Exception {\r
+ if (filepath.contains(".c") || filepath.contains(".h")) {\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
+ }\r
+ }\r
+ \r
+ public static void fireAt(String path) throws Exception {\r
+ Common.toDoAll(path, new Critic());\r
+ System.out.println("Critic Done");\r
+ }\r
+}\r
private String modulepath;\r
private ModuleInfo mi;\r
\r
- private JButton moduleButton, goButton, msaEditorButton;\r
+ private JButton moduleButton, goButton, msaEditorButton, criticButton;\r
private JTextField moduletext;\r
private JTextArea log;\r
private JFileChooser fc;\r
msaEditorButton = new JButton("MsaEditor");\r
msaEditorButton.addActionListener(this);\r
\r
+ criticButton = new JButton("Critic");\r
+ criticButton.addActionListener(this);\r
+ \r
moduletext = new JTextField(30);\r
\r
filebox = new JCheckBox("Output to logfile", true);\r
modulePanel.add(screenbox);\r
modulePanel.add(goButton);\r
modulePanel.add(msaEditorButton);\r
+ modulePanel.add(criticButton);\r
add(modulePanel);\r
\r
log = new JTextArea(20,25);\r
println(en.getMessage());\r
}\r
}\r
+ if ( e.getSource() == criticButton) {\r
+ try {\r
+ Critic.fireAt(modulepath);\r
+ } catch (Exception en) {\r
+ println(en.getMessage());\r
+ }\r
+ }\r
}\r
\r
public void itemStateChanged(ItemEvent e) {\r
show(hashr8only, "hashr8only : ");\r
}\r
\r
- new MsaWriter(modulepath, this, db).flush();\r
+ new MsaWriter(modulepath, this, db, ui).flush();\r
\r
// remove temp directory\r
//File tempdir = new File(modulepath + File.separator + "temp");\r
}\r
\r
public void readInf(String name) throws Exception {\r
- System.out.println("Parsing INF file: " + name);\r
- BufferedReader rd = new BufferedReader(new FileReader(modulepath + File.separator + name));\r
- String line;\r
+ System.out.println("\nParsing INF file: " + name);\r
String wholeline;\r
- String[] linecontext;\r
- boolean inSrc = false;\r
Matcher mtrinfequation;\r
Matcher mtrsection;\r
Matcher mtrfilename;\r
\r
- wholeline = Common.sourcefiletostring(modulepath + File.separator + name);\r
+ wholeline = Common.file2string(modulepath + File.separator + name);\r
mtrsection = ptnsection.matcher(wholeline);\r
while (mtrsection.find()) {\r
if (mtrsection.group(1).matches("defines")) {\r
import javax.swing.*;\r
import javax.swing.tree.*;\r
\r
+import org.tianocore.ModuleSurfaceAreaDocument;\r
+\r
public class MsaTreeEditor extends JPanel {\r
/**\r
* Define class Serial Version UID\r
*/\r
private static final long serialVersionUID = 3169905938472150649L;\r
+/*\r
+ MsaTreeEditor(ModuleInfo m, UI u, ModuleSurfaceAreaDocument md) {\r
+ mi = m;\r
+ ui = u;\r
+ msadoc = md;\r
+ \r
+ //rootNode = msadoc.getDomNode();\r
+ rootNode = new DefaultMutableTreeNode("Root Node");\r
+ treeModel = new DefaultTreeModel(rootNode);\r
\r
+ tree = new JTree(treeModel);\r
+ tree.setEditable(true);\r
+ tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);\r
+ tree.setShowsRootHandles(false);\r
+ tree.addMouseListener(mouseadapter);\r
+\r
+ JScrollPane scrollPane = new JScrollPane(tree);\r
+ add(scrollPane);\r
+ \r
+ popupmenu = new JPopupMenu();\r
+ menuitemadd = new JMenuItem("addNode");\r
+ menuitemdel = new JMenuItem("deleteNode");\r
+ popupmenu.add(menuitemadd);\r
+ popupmenu.add(menuitemdel);\r
+ menuitemadd.addActionListener(actionListener);\r
+ menuitemdel.addActionListener(actionListener);\r
+ \r
+ addNode(rootNode, "1st");\r
+ addNode(rootNode, "2nd");\r
+ }\r
+*/\r
MsaTreeEditor(ModuleInfo m, UI u) {\r
mi = m;\r
ui = u;\r
add(scrollPane);\r
\r
popupmenu = new JPopupMenu();\r
- JMenuItem menuitemadd = new JMenuItem("addNode");\r
- JMenuItem menuitemdel = new JMenuItem("deleteNode");\r
+ menuitemadd = new JMenuItem("addNode");\r
+ menuitemdel = new JMenuItem("deleteNode");\r
popupmenu.add(menuitemadd);\r
popupmenu.add(menuitemdel);\r
menuitemadd.addActionListener(actionListener);\r
\r
private ModuleInfo mi;\r
private UI ui;\r
+ //private ModuleSurfaceAreaDocument msadoc;\r
\r
private JTree tree;\r
private DefaultMutableTreeNode rootNode;\r
private DefaultTreeModel treeModel;\r
+ private JMenuItem menuitemadd, menuitemdel;\r
\r
private JPopupMenu popupmenu;\r
private MouseAdapter mouseadapter = new MouseAdapter() {\r
};\r
private ActionListener actionListener = new ActionListener() {\r
public void actionPerformed(ActionEvent ae) {\r
- addNode();\r
+ if (ae.getSource() == menuitemadd) {\r
+ addNode();\r
+ } else if (ae.getSource() == menuitemdel) {\r
+ delNode();\r
+ }\r
}\r
};\r
\r
- public void addNode() {\r
+ private void delNode() {\r
+ treeModel.removeNodeFromParent((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()));\r
+ }\r
+ \r
+ private void addNode() {\r
addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), ui.getInput("Input Node Name"));\r
- System.out.println();\r
}\r
\r
- public void addNode(DefaultMutableTreeNode parentNode, Object child) {\r
+ private void addNode(DefaultMutableTreeNode parentNode, Object child) {\r
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);\r
treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());\r
tree.scrollPathToVisible(new TreePath(childNode.getPath()));\r
}\r
-\r
+ /*\r
+ public static void init(ModuleInfo mi, UI ui, ModuleSurfaceAreaDocument msadoc) throws Exception {\r
+ init(mi, ui);\r
+ }\r
+ */\r
public static void init(ModuleInfo mi, UI ui) throws Exception {\r
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
\r
import org.apache.xmlbeans.*;\r
\r
public class MsaWriter {\r
- MsaWriter(String path, ModuleInfo moduleinfo, Database database) {\r
+ MsaWriter(String path, ModuleInfo moduleinfo, Database database, UI u) {\r
modulepath = path;\r
mi = moduleinfo;\r
db = database;\r
+ ui = u;\r
}\r
\r
private String modulepath;\r
private ModuleInfo mi;\r
private Database db;\r
+ private UI ui;\r
\r
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
\r
\r
BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));\r
fulfillMsadoc().save(bw, options);\r
+ //MsaTreeEditor.init(mi, ui, msadoc);\r
bw.flush();\r
bw.close();\r
}\r
outname = inname;\r
}\r
ui.println("\nModifying file: " + inname);\r
+ Common.string2file(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname), modulepath + File.separator + "result" + File.separator + outname);\r
+ /*\r
Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);\r
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));\r
outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname));\r
outfile.flush();\r
outfile.close();\r
+ */\r
} else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {\r
if (inname.contains(".H")) {\r
outname = inname.replaceFirst(".H", ".h");\r
outname = inname;\r
}\r
ui.println("\nCopying file: " + inname);\r
+ Common.string2file(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname), modulepath + File.separator + "result" + File.separator + outname);\r
+ /*\r
Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);\r
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));\r
- outfile.append(Common.sourcefiletostring(modulepath + File.separator + "temp" + File.separator + inname));\r
+ outfile.append(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname));\r
outfile.flush();\r
outfile.close();\r
+ */\r
}\r
}\r
\r
\r
private void addr8only() throws Exception {\r
String paragraph = null;\r
- String line = Common.sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c");\r
+ String line = Common.file2string(Database.defaultpath + File.separator + "R8Lib.c");\r
Common.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");\r
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.c")));\r
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.h")));\r