From 90503bad37fea5edf22531754c203f77268dfa36 Mon Sep 17 00:00:00 2001 From: alfred Date: Tue, 15 Aug 2006 12:35:00 +0000 Subject: [PATCH] Turn to Regex in ModuleReader.java 1st edition of MsaTreeEditor.java Some edit on ia32 x64... in .inf-read and MsaWriter.java git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1278 6f19259b-4bc3-4df7-8a09-765794883524 --- .../org/tianocore/migration/Common.java | 32 +++++++ .../org/tianocore/migration/FirstPanel.java | 33 +++++--- .../org/tianocore/migration/ModuleInfo.java | 17 +--- .../org/tianocore/migration/ModuleReader.java | 70 +++++++++------- .../tianocore/migration/MsaTreeEditor.java | 84 +++++++++++++++++++ .../org/tianocore/migration/MsaWriter.java | 12 ++- .../migration/SourceFileReplacer.java | 20 ++--- .../org/tianocore/migration/UI.java | 2 + 8 files changed, 197 insertions(+), 73 deletions(-) create mode 100644 Tools/Source/MigrationTools/org/tianocore/migration/Common.java create mode 100644 Tools/Source/MigrationTools/org/tianocore/migration/MsaTreeEditor.java diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/Common.java b/Tools/Source/MigrationTools/org/tianocore/migration/Common.java new file mode 100644 index 0000000000..10bc2836d9 --- /dev/null +++ b/Tools/Source/MigrationTools/org/tianocore/migration/Common.java @@ -0,0 +1,32 @@ +package org.tianocore.migration; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Common { + public static String sourcefiletostring(String filename) throws Exception { + BufferedReader rd = new BufferedReader(new FileReader(filename)); + StringBuffer wholefile = new StringBuffer(); + String line; + while ((line = rd.readLine()) != null) { + wholefile.append(line + "\n"); + } + return wholefile.toString(); + } + + public static void ensureDir(String objFileWhole) { + Pattern ptnseparate = Pattern.compile("(.*)\\\\[^\\\\]*"); + Matcher mtrseparate; + File tempdir; + + mtrseparate = ptnseparate.matcher(objFileWhole); + if (mtrseparate.find()) { + tempdir = new File(mtrseparate.group(1)); + if (!tempdir.exists()) tempdir.mkdirs(); + } + + } +} diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java b/Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java index 30085d449e..9f853e42f2 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java @@ -25,8 +25,9 @@ public class FirstPanel extends JPanel implements ActionListener, UI { private static final long serialVersionUID = 207759413522910399L; private String modulepath; + private ModuleInfo mi; - private JButton moduleButton , goButton; + private JButton moduleButton, goButton, msaEditorButton; private JTextField moduletext; private JTextArea log; private JFileChooser fc; @@ -43,6 +44,9 @@ public class FirstPanel extends JPanel implements ActionListener, UI { moduleButton = new JButton("Choose ModulePath"); moduleButton.addActionListener(this); + msaEditorButton = new JButton("MsaEditor"); + msaEditorButton.addActionListener(this); + moduletext = new JTextField(30); filebox = new JCheckBox("Output to logfile", true); @@ -54,9 +58,10 @@ public class FirstPanel extends JPanel implements ActionListener, UI { modulePanel.add(filebox); modulePanel.add(screenbox); modulePanel.add(goButton); + modulePanel.add(msaEditorButton); add(modulePanel); - log = new JTextArea(50,25); + log = new JTextArea(20,25); log.setMargin(new Insets(5,5,5,5)); log.setEditable(false); JScrollPane logScrollPane = new JScrollPane(log); @@ -99,16 +104,13 @@ public class FirstPanel extends JPanel implements ActionListener, UI { public String choose(String message, Object[] choicelist) { return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]); } - - //---------------------------------------------------------------------------------------// - /* - public boolean getOption(String item) { - if (item.matches("file")) { - } + public String getInput(String message) { + return (String)JOptionPane.showInputDialog(message); } - */ - + + //---------------------------------------------------------------------------------------// + public void actionPerformed(ActionEvent e) { if ( e.getSource() == moduleButton ) { int ret = fc.showOpenDialog(this); @@ -123,12 +125,19 @@ public class FirstPanel extends JPanel implements ActionListener, UI { logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log"))); println("Project MsaGen"); println("Copyright (c) 2006, Intel Corporation"); - new ModuleInfo(modulepath, this, new Database()); + mi = new ModuleInfo(modulepath, this, new Database()); logfile.flush(); } catch (Exception en) { println(en.getMessage()); } } + if ( e.getSource() == msaEditorButton) { + try { + MsaTreeEditor.init(mi, this); + } catch (Exception en) { + println(en.getMessage()); + } + } } public void itemStateChanged(ItemEvent e) { @@ -156,7 +165,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI { fp.setOpaque(true); frame.setContentPane(fp); - frame.setSize(800,600); + frame.pack(); frame.setVisible(true); } } \ No newline at end of file diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java index 220b3e8d40..5e3bbb50d0 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java @@ -86,7 +86,7 @@ public class ModuleInfo { } else { filename = ui.choose("Found .inf or .msa file in the module\nChoose one Please", msaorinf.toArray()); } - ModuleReader mr = new ModuleReader(modulepath, this, db); + ModuleReader mr = new ModuleReader(modulepath, this, db, ui); if (filename.contains(".inf")) { mr.readInf(filename); } else if (filename.contains(".msa")) { @@ -130,19 +130,6 @@ public class ModuleInfo { ui.println(show + hash.size()); ui.println(hash); } - - public void ensureDir(String objFileWhole) { - Pattern ptnseparate = Pattern.compile("(.*)\\\\[^\\\\]*"); - Matcher mtrseparate; - File tempdir; - - mtrseparate = ptnseparate.matcher(objFileWhole); - if (mtrseparate.find()) { - tempdir = new File(mtrseparate.group(1)); - if (!tempdir.exists()) tempdir.mkdirs(); - } - - } // add '//' to all non-local include lines private void CommentOutNonLocalHFile() throws IOException { @@ -158,7 +145,7 @@ public class ModuleInfo { while ( ii.hasNext() ) { curFile = ii.next(); rd = new BufferedReader(new FileReader(modulepath + File.separator + curFile)); - ensureDir(modulepath + File.separator + "temp" + File.separator + curFile); + Common.ensureDir(modulepath + File.separator + "temp" + File.separator + curFile); outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "temp" + File.separator + curFile))); while ((line = rd.readLine()) != null) { if (line.contains("#include")) { diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java index 3f379b7256..46fb4994bb 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java @@ -18,16 +18,20 @@ import java.util.regex.*; import org.tianocore.*; public class ModuleReader { - ModuleReader(String path, ModuleInfo moduleinfo, Database database) { + ModuleReader(String path, ModuleInfo moduleinfo, Database database, UI u) { modulepath = path; mi = moduleinfo; db = database; + ui = u; } private String modulepath; private ModuleInfo mi; private Database db; + private UI ui; - private static Pattern ptninfequation = Pattern.compile("([^ ]*) *= *([^ ]*)"); + private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)"); + private static Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE); + private static Pattern ptnfilename = Pattern.compile("[^\\s]+"); public void readMsa(String name) throws Exception { ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(modulepath + File.separator + name)); @@ -53,40 +57,48 @@ public class ModuleReader { System.out.println("Parsing INF file: " + name); BufferedReader rd = new BufferedReader(new FileReader(modulepath + File.separator + name)); String line; + String wholeline; String[] linecontext; boolean inSrc = false; Matcher mtrinfequation; + Matcher mtrsection; + Matcher mtrfilename; - while ((line = rd.readLine()) != null) { - if (line.length() != 0) { - if (inSrc) { - if (line.contains("[")) { - inSrc = false; - } else { - linecontext = line.split(" "); - if (linecontext[2].length() != 0) { - if (!mi.localmodulesources.contains(linecontext[2])) { - System.out.println("Source File Missing! : " + linecontext[2]); - } - } + wholeline = Common.sourcefiletostring(modulepath + File.separator + name); + mtrsection = ptnsection.matcher(wholeline); + while (mtrsection.find()) { + if (mtrsection.group(1).matches("defines")) { + mtrinfequation = ptninfequation.matcher(mtrsection.group(2)); + while (mtrinfequation.find()) { + if (mtrinfequation.group(1).matches("BASE_NAME")) { + mi.modulename = mtrinfequation.group(2); } - } else { - if ((mtrinfequation = ptninfequation.matcher(line)).find()) { - if (mtrinfequation.group(1).matches("BASE_NAME")) { - mi.modulename = mtrinfequation.group(2); - } - if (mtrinfequation.group(1).matches("FILE_GUID")) { - mi.guidvalue = mtrinfequation.group(2); - } - if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) { - mi.moduletype = mtrinfequation.group(2); - } - if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) { - mi.entrypoint = mtrinfequation.group(2); + if (mtrinfequation.group(1).matches("FILE_GUID")) { + mi.guidvalue = mtrinfequation.group(2); + } + if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) { + mi.moduletype = mtrinfequation.group(2); + } + } + } + if (mtrsection.group(1).matches("nmake.common")) { + mtrinfequation = ptninfequation.matcher(mtrsection.group(2)); + while (mtrinfequation.find()) { + if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) { + mi.entrypoint = mtrinfequation.group(2); + } + if (mtrinfequation.group(1).matches("DPX_SOURCE")) { + if (!mi.localmodulesources.contains(mtrinfequation.group(2))) { + ui.println("DPX File Missing! : " + mtrinfequation.group(2)); } } - if (line.contains("sources")) { - inSrc = true; + } + } + if (mtrsection.group(1).contains("sources.")) { + mtrfilename = ptnfilename.matcher(mtrsection.group(2)); + while (mtrfilename.find()) { + if (!mi.localmodulesources.contains(mtrfilename.group())) { + ui.println("Source File Missing! : " + mtrfilename.group()); } } } diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/MsaTreeEditor.java b/Tools/Source/MigrationTools/org/tianocore/migration/MsaTreeEditor.java new file mode 100644 index 0000000000..a324e81953 --- /dev/null +++ b/Tools/Source/MigrationTools/org/tianocore/migration/MsaTreeEditor.java @@ -0,0 +1,84 @@ +package org.tianocore.migration; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.tree.*; + +public class MsaTreeEditor extends JPanel { + MsaTreeEditor(ModuleInfo m, UI u) { + mi = m; + ui = u; + + rootNode = new DefaultMutableTreeNode("Root Node"); + treeModel = new DefaultTreeModel(rootNode); + + tree = new JTree(treeModel); + tree.setEditable(true); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + tree.setShowsRootHandles(false); + tree.addMouseListener(mouseadapter); + + JScrollPane scrollPane = new JScrollPane(tree); + add(scrollPane); + + popupmenu = new JPopupMenu(); + JMenuItem menuitemadd = new JMenuItem("addNode"); + JMenuItem menuitemdel = new JMenuItem("deleteNode"); + popupmenu.add(menuitemadd); + popupmenu.add(menuitemdel); + menuitemadd.addActionListener(actionListener); + menuitemdel.addActionListener(actionListener); + + addNode(rootNode, "1st"); + addNode(rootNode, "2nd"); + } + + private ModuleInfo mi; + private UI ui; + + private JTree tree; + private DefaultMutableTreeNode rootNode; + private DefaultTreeModel treeModel; + + private JPopupMenu popupmenu; + private MouseAdapter mouseadapter = new MouseAdapter() { + public void mouseReleased(MouseEvent me) { + if (me.getClickCount() == 1 && SwingUtilities.isRightMouseButton(me)) { + tree.setSelectionPath(tree.getPathForLocation(me.getX(), me.getY())); + popupmenu.show(tree, me.getX(), me.getY()); + } + } + }; + private ActionListener actionListener = new ActionListener() { + public void actionPerformed(ActionEvent ae) { + addNode(); + } + }; + + public void addNode() { + addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), ui.getInput("Input Node Name")); + System.out.println(); + } + + public void addNode(DefaultMutableTreeNode parentNode, Object child) { + DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child); + treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount()); + tree.scrollPathToVisible(new TreePath(childNode.getPath())); + } + + public static void init(ModuleInfo mi, UI ui) throws Exception { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + + JFrame frame = new JFrame("MsaTreeEditor"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + MsaTreeEditor mte = new MsaTreeEditor(mi, ui); + mte.setLayout(new GridBagLayout()); + mte.setOpaque(true); + frame.setContentPane(mte); + + frame.pack(); + frame.setVisible(true); + } +} \ No newline at end of file diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java b/Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java index 7d907690e9..2c3c97274e 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java @@ -78,7 +78,7 @@ public class MsaWriter { msaheader.setCopyright("Copyright (c) 2006, Intel Corporation"); msaheader.setVersion("1.0"); msaheader.setAbstract("Component name for module " + mi.modulename); - msaheader.setDescription("FIX ME!"); //??? + msaheader.setDescription("FIX ME!"); msaheader.addNewLicense().setStringValue("All rights reserved.\n" + " This software and associated documentation (if any) is furnished\n" + " under a license and may only be used or copied in accordance\n" + @@ -103,9 +103,17 @@ public class MsaWriter { externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000"); externs.addNewExtern().setModuleEntryPoint(mi.entrypoint); + FilenameDocument.Filename filename; it = mi.localmodulesources.iterator(); + //System.out.println(mi.localmodulesources); while (it.hasNext()) { - sourcefiles.addNewFilename().setStringValue(it.next()); + temp = it.next(); + filename = sourcefiles.addNewFilename(); + filename.setStringValue(temp); + //if (temp.contains("x64" + File.separator)) { + //System.out.println("find"); + //filename.setSupArchList(); + //} } if (!mi.protocol.isEmpty()) { protocols = msa.addNewProtocols(); diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java b/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java index dbe981ef94..03617ab716 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java @@ -85,7 +85,7 @@ public class SourceFileReplacer { outname = inname; } ui.println("\nModifying file: " + inname); - mi.ensureDir(modulepath + File.separator + "result" + File.separator + outname); + Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname); outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname))); outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname)); outfile.flush(); @@ -97,9 +97,9 @@ public class SourceFileReplacer { outname = inname; } ui.println("\nCopying file: " + inname); - mi.ensureDir(modulepath + File.separator + "result" + File.separator + outname); + Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname); outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname))); - outfile.append(sourcefiletostring(modulepath + File.separator + "temp" + File.separator + inname)); + outfile.append(Common.sourcefiletostring(modulepath + File.separator + "temp" + File.separator + inname)); outfile.flush(); outfile.close(); } @@ -112,8 +112,8 @@ public class SourceFileReplacer { private void addr8only() throws Exception { String paragraph = null; - String line = sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c"); - mi.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c"); + String line = Common.sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c"); + Common.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c"); PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.c"))); PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.h"))); Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL); @@ -142,16 +142,6 @@ public class SourceFileReplacer { mi.localmodulesources.add("R8Lib.c"); } - private String sourcefiletostring(String filename) throws Exception { - BufferedReader rd = new BufferedReader(new FileReader(filename)); - StringBuffer wholefile = new StringBuffer(); - String line; - while ((line = rd.readLine()) != null) { - wholefile.append(line + "\n"); - } - return wholefile.toString(); - } - // Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you! private String sourcefilereplace(String filename) throws Exception { BufferedReader rd = new BufferedReader(new FileReader(filename)); diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/UI.java b/Tools/Source/MigrationTools/org/tianocore/migration/UI.java index 7f91ebe461..170a2488bd 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/UI.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/UI.java @@ -25,4 +25,6 @@ public interface UI { public void println(Set hash); public String choose(String message, Object[] choicelist); + + public String getInput(String message); } -- 2.39.2