Many Many Modifies
authoralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 21 Aug 2006 06:45:23 +0000 (06:45 +0000)
committeralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 21 Aug 2006 06:45:23 +0000 (06:45 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1331 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/MigrationTools/org/tianocore/migration/Common.java
Tools/Source/MigrationTools/org/tianocore/migration/Critic.java
Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java
Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java
Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java
Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java
Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java
Tools/Source/MigrationTools/org/tianocore/migration/UI.java

index d3d781f32213b89d81c635c338ad874866a12a44..2fcd092315a43553c9d0f7bd0287b1eb6c1a62d1 100644 (file)
@@ -15,11 +15,30 @@ package org.tianocore.migration;
 import java.io.*;\r
 import java.util.regex.*;\r
 import java.util.*;\r
+import java.lang.reflect.*;\r
 \r
-public class Common {\r
-       public static Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)");\r
+public final class Common {\r
+       public static final int BOTH = 0;\r
+       public static final int FILE = 1;\r
+       public static final int DIR = 2;\r
        \r
-       public static String file2string(String filename) throws Exception {\r
+       public static final Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)");\r
+\r
+       //-------------------------------------regex------------------------------------------//\r
+       \r
+       public static final String replaceAll(String line, Pattern ptn, String des) {\r
+               Matcher mtr = ptn.matcher(line);\r
+               if (mtr.find()) {\r
+                        return mtr.replaceAll(des);\r
+               }\r
+               return line;\r
+       }\r
+\r
+       //-------------------------------------regex------------------------------------------//\r
+       \r
+       //-----------------------------------file&string---------------------------------------//\r
+       \r
+       public static final String file2string(String filename) throws Exception {\r
                BufferedReader rd = new BufferedReader(new FileReader(filename));\r
                StringBuffer wholefile = new StringBuffer();\r
                String line;\r
@@ -29,7 +48,7 @@ public class Common {
                return wholefile.toString();\r
        }\r
 \r
-       public static void string2file(String content, String filename) throws Exception {\r
+       public static final 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
@@ -37,7 +56,11 @@ public class Common {
                outfile.close();\r
        }\r
 \r
-       public static void ensureDir(String objFileWhole) {\r
+       //-----------------------------------file&string---------------------------------------//\r
+\r
+       //--------------------------------------dir--------------------------------------------//\r
+       \r
+       public static final void ensureDir(String objFileWhole) {\r
                File tempdir;\r
                Matcher mtrseparate = ptnseparate.matcher(objFileWhole);\r
                if (mtrseparate.find()) {\r
@@ -46,32 +69,21 @@ public class Common {
                }\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
+       public static final void deleteDir(String objFileWhole) {\r
+               String[] list = new File(objFileWhole).list();\r
+               File temp;\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
+                       temp = new File(objFileWhole + File.separator + list[i]);\r
+                       if (temp.isDirectory()) {\r
+                               deleteDir(objFileWhole + File.separator + list[i]);\r
                        } else {\r
-                               filelist.add(path + File.separator + list[i]);\r
+                               temp.delete();\r
                        }\r
                }\r
-               \r
-               return filelist;\r
-       }\r
-\r
-       public static String replaceAll(String line, Pattern ptn, String des) {\r
-               Matcher mtr = ptn.matcher(line);\r
-               if (mtr.find()) {\r
-                        return mtr.replaceAll(des);\r
-               }\r
-               return line;\r
+               new File(objFileWhole).delete();\r
        }\r
        \r
-       public static String dirCopy_(String src) throws Exception {\r
+       public static final String dirCopy_(String src) throws Exception {\r
                Matcher mtrseparate = Common.ptnseparate.matcher(src);\r
                if (mtrseparate.find()) {\r
                        dirCopy(src, mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2));\r
@@ -79,7 +91,7 @@ public class Common {
                return mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2);\r
        }\r
        \r
-       public static void dirCopy(String src, String des) throws Exception {\r
+       public static final void dirCopy(String src, String des) throws Exception {\r
                String[] list = new File(src).list();\r
                File test;\r
 \r
@@ -93,6 +105,36 @@ public class Common {
                        }\r
                }\r
        }\r
+\r
+       //--------------------------------------dir--------------------------------------------//\r
+\r
+       //-------------------------------like python walk-----------------------------------------//\r
+       \r
+       public static final void toDoAll(String path, Method md, Object obj, Object[] args, int type) throws Exception {\r
+               String[] list = new File(path).list();\r
+               ArrayList<Object> _args = new ArrayList<Object>();\r
+               \r
+               _args.add(path);\r
+               if (args != null) {\r
+                       for (int i = 0; i < args.length; i++) {\r
+                               _args.add(args[i]);\r
+                       }\r
+               }\r
+\r
+               if (type == DIR || type == BOTH) {\r
+                       md.invoke(obj, _args.toArray());\r
+               }\r
+               for (int i = 0 ; i < list.length ; i++) {\r
+                       if (new File(path + File.separator + list[i]).isDirectory()) {\r
+                               toDoAll(path + File.separator + list[i], md, obj, args, type);\r
+                       } else {\r
+                               if (type == FILE || type == BOTH) {\r
+                                       _args.set(0, path + File.separator + list[i]);\r
+                                       md.invoke(obj, _args.toArray());\r
+                               }\r
+                       }\r
+               }\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
index 23ad95abfcad28016368a0d3307a4faef2d63f02..962574645cfccc6ebb3407650b4819f1070899a8 100644 (file)
@@ -15,23 +15,23 @@ package org.tianocore.migration;
 import java.util.regex.*;\r
 import java.io.*;\r
 \r
-public class Critic implements Common.ForDoAll {\r
+public class Critic {\r
        private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
        private static Pattern ptnfunccomment = Pattern.compile("([\\};\\/]\\s*)([\\w\\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*");\r
-       private static Matcher mtrinfequation;\r
+       private static Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");\r
+       private static Matcher mtrcommentequation;\r
+       private static Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");\r
+       private static Matcher mtrnewcomment;\r
        \r
-       public void toDo(String filepath) throws Exception {\r
+       private static final int totallinelength = 82;\r
+       \r
+       public 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
-                       boolean description = false;\r
-                       boolean arguments = false;\r
-                       boolean returns = false;\r
-                       boolean inequation = false;\r
 \r
                        System.out.println("Criticing   " + filepath);\r
                        String wholeline = Common.file2string(filepath);\r
@@ -40,7 +40,12 @@ public class Critic implements Common.ForDoAll {
                        wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");\r
                        wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1/**$3**/$4$2$5");\r
                        //wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");\r
-                       \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
@@ -62,32 +67,32 @@ public class Critic implements Common.ForDoAll {
                                        arguments = false;\r
                                        returns = true;\r
                                } else if (incomment && description) {\r
-                                       templine.append(line + "\n");\r
+                                       templine.append("  " + line.trim() + "\n");\r
                                } else if (incomment && arguments) {\r
-                                       mtrinfequation = ptninfequation.matcher(line);\r
-                                       if (mtrinfequation.find()) {\r
+                                       mtrcommentequation = ptncommentequation.matcher(line);\r
+                                       if (mtrcommentequation.find()) {\r
                                                inequation = true;\r
-                                               templine.append("  @param " + mtrinfequation.group(1) + "     " + mtrinfequation.group(2) + "\n");\r
+                                               templine.append("  @param  " + mtrcommentequation.group(1) + "     " + mtrcommentequation.group(2) + "\n");\r
                                        } else if (inequation && line.trim().length() == 0) {\r
                                                inequation = false;\r
                                                templine.append(line + "\n");\r
                                        } else if (inequation && line.trim().length() != 0) {\r
                                                templine.append("#%#%" + line + "\n");\r
                                        } else {\r
-                                               templine.append(line + "\n");\r
+                                               templine.append("  " + line.trim() + "\n");\r
                                        }\r
                                } else if (incomment && returns) {\r
-                                       mtrinfequation = ptninfequation.matcher(line);\r
-                                       if (mtrinfequation.find()) {\r
+                                       mtrcommentequation = ptncommentequation.matcher(line);\r
+                                       if (mtrcommentequation.find()) {\r
                                                inequation = true;\r
-                                               templine.append("  @retval " + mtrinfequation.group(1) + "     " + mtrinfequation.group(2) + "\n");\r
+                                               templine.append("  @retval " + mtrcommentequation.group(1) + "     " + mtrcommentequation.group(2) + "\n");\r
                                        } else if (inequation && line.trim().length() == 0) {\r
                                                inequation = false;\r
                                                templine.append(line + "\n");\r
                                        } else if (inequation && line.trim().length() != 0) {\r
                                                templine.append("#%#%" + line + "\n");\r
                                        } else {\r
-                                               templine.append(line + "\n");\r
+                                               templine.append("  " + line.trim() + "\n");\r
                                        }\r
                                } else {\r
                                        templine.append(line + "\n");\r
@@ -95,6 +100,79 @@ public class Critic implements Common.ForDoAll {
                        }\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
                        \r
                        /* -----slow edition of replacefirst with stringbuffer-----\r
                        line.append(wholeline);\r
@@ -123,9 +201,9 @@ public class Critic implements Common.ForDoAll {
                }\r
        }\r
        \r
-       public static void fireAt(String path) throws Exception {\r
-               Critic critic = new Critic();\r
-               Common.toDoAll(Common.dirCopy_(path), critic);\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(Common.dirCopy_(path), critic, Common.FILE);\r
                System.out.println("Critic Done");\r
        }\r
 }\r
index d0a2fc2dd5f8e45ac9db398e20d87920eb880530..1d9cf64a618ac96ef5d70ef9a8194a3e3f2e58bd 100644 (file)
@@ -18,7 +18,7 @@ import java.io.*;
 import java.util.*;\r
 import javax.swing.*;\r
 \r
-public class FirstPanel extends JPanel implements ActionListener, UI {\r
+public final class FirstPanel extends JPanel implements ActionListener, UI {\r
        /**\r
         *  Define class Serial Version UID\r
         */\r
@@ -61,7 +61,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
         modulePanel.add(filebox);\r
         modulePanel.add(screenbox);\r
         modulePanel.add(goButton);\r
-        modulePanel.add(msaEditorButton);\r
+        //modulePanel.add(msaEditorButton);\r
         modulePanel.add(criticButton);\r
         add(modulePanel);\r
 \r
@@ -115,21 +115,34 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
 \r
        //---------------------------------------------------------------------------------------//\r
 \r
+       public String getFilepath() {\r
+               if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {\r
+                       log.append(fc.getSelectedFile().getAbsolutePath() + "\n");\r
+                       return fc.getSelectedFile().getAbsolutePath();\r
+               }\r
+               return null;\r
+       }\r
+\r
+       //---------------------------------------------------------------------------------------//\r
+\r
     public void actionPerformed(ActionEvent e) {\r
         if ( e.getSource() == moduleButton ) {\r
+               modulepath = getFilepath();\r
+               /*\r
                int ret = fc.showOpenDialog(this);\r
                if (ret == JFileChooser.APPROVE_OPTION) {\r
                        modulepath = fc.getSelectedFile().getAbsolutePath();\r
                        moduletext.setText(modulepath);\r
                 log.append("ModulePath: " + modulepath + "\n");\r
                }\r
+               */\r
         }\r
         if ( e.getSource() == goButton ) {\r
                try {\r
                        logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));\r
                        println("Project MsaGen");\r
                        println("Copyright (c) 2006, Intel Corporation");\r
-                       mi = new ModuleInfo(modulepath, this, new Database());\r
+                       Common.toDoAll(modulepath, ModuleInfo.class.getMethod("seekModule", String.class), null, null, Common.DIR);\r
                        logfile.flush();\r
                } catch (Exception en) {\r
                        println(en.getMessage());\r
@@ -159,7 +172,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
 \r
     //---------------------------------------------------------------------------------------//\r
     \r
-    public static void init() throws Exception {\r
+    public static FirstPanel init() throws Exception {\r
        \r
        //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());\r
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
@@ -178,5 +191,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
 \r
                frame.pack();\r
                frame.setVisible(true);\r
+               \r
+               return fp;\r
     }\r
 }
\ No newline at end of file
index 13d3436d959ed2c99c22a64b4fd58b21814f3633..af1259ed62774241ada1c1ef88bfe974a80a1c26 100644 (file)
@@ -21,16 +21,24 @@ import java.util.regex.*;
 information and all the temporary data.\r
 */\r
 public class ModuleInfo {\r
-       ModuleInfo(String modulepath, UI ui, Database db) throws Exception {\r
+       ModuleInfo(String modulepath) throws Exception {\r
                this.modulepath = modulepath;\r
-               this.ui = ui;\r
-               this.db = db;\r
+               \r
+               ui.println("Choose where to place the result");\r
+               if ((outputpath = ui.getFilepath()) == null) {\r
+                       outputpath = modulepath; \r
+               }\r
+               ui.println(outputpath);\r
+               \r
                moduleScan();\r
        }\r
+\r
+       private static UI ui = null;                            //if MIM is still usefull, this can be given to it\r
+       private static Database db = null;                      //if MIM is still usefull, this can be given to it\r
+       \r
+       public String modulepath = null;\r
        \r
-       private String modulepath = null;\r
-       private Database db = null;\r
-       private UI ui = null;\r
+       public String outputpath = null;\r
        \r
        public String modulename = null;\r
        public String guidvalue = null;\r
@@ -55,48 +63,27 @@ public class ModuleInfo {
        \r
        private static String migrationcomment = "//%$//";\r
        \r
-       private void dirScan(String subpath) throws Exception {\r
-               String[] list = new File(modulepath + File.separator + subpath).list();                 // if no sub , separator need?\r
-               File test;\r
-               \r
-               for (int i = 0 ; i < list.length ; i++) {\r
-                       test = new File(modulepath + File.separator + subpath + list[i]);\r
-                       if (test.isDirectory()) {\r
-                               if (list[i].contains("result") || list[i].contains("temp")) {\r
-                               } else {\r
-                                       dirScan(subpath + list[i] + File.separator);\r
-                               }\r
-                       } else {\r
-                               if (list[i].contains(".c") || list[i].contains(".C") || list[i].contains(".h") || \r
-                                       list[i].contains(".H") || list[i].contains(".dxs") || list[i].contains(".uni")) {\r
-                                       localmodulesources.add(subpath + list[i]);\r
-                               } else if (list[i].contains(".inf") || list[i].contains(".msa")) {\r
-                                       msaorinf.add(subpath + list[i]);\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       \r
        private void moduleScan() throws Exception {\r
-               dirScan("");\r
+               Common.toDoAll(modulepath, ModuleInfo.class.getMethod("enroll", String.class), this, null, Common.FILE);\r
+               \r
                String filename = null;\r
                if (msaorinf.isEmpty()) {\r
                        ui.println("No INF nor MSA file found!");\r
                        System.exit(0);\r
                } else {\r
-                       filename = ui.choose("Found .inf or .msa file in the module\nChoose one Please", msaorinf.toArray());\r
+                       filename = ui.choose("Found .inf or .msa file for module\n" + modulepath + "\nChoose one Please", msaorinf.toArray());\r
                }\r
-               ModuleReader mr = new ModuleReader(modulepath, this, db, ui);\r
+               //ModuleReader mr = new ModuleReader(modulepath, this, db, ui);\r
                if (filename.contains(".inf")) {\r
-                       mr.readInf(filename);\r
+                       ModuleReader.readInf(filename, this);\r
                } else if (filename.contains(".msa")) {\r
-                       mr.readMsa(filename);\r
+                       ModuleReader.readMsa(filename, this);\r
                }\r
                \r
                CommentOutNonLocalHFile();\r
                parsePreProcessedSourceCode();\r
-               \r
-               new SourceFileReplacer(modulepath, this, db, ui).flush();       // some adding library actions are taken here,so it must be put before "MsaWriter"\r
+\r
+               new SourceFileReplacer(modulepath, outputpath, this, db, ui).flush();   // some adding library actions are taken here,so it must be put before "MsaWriter"\r
                \r
                // show result\r
                if (ui.yesOrNo("Parse of the Module Information has completed. View details?")) {\r
@@ -113,12 +100,10 @@ public class ModuleInfo {
                        show(hashr8only, "hashr8only : ");\r
                }\r
                \r
-               new MsaWriter(modulepath, this, db, ui).flush();\r
-               \r
-               // remove temp directory\r
-               //File tempdir = new File(modulepath + File.separator + "temp");\r
-               //System.out.println("Deleting Dir");\r
-               //if (tempdir.exists()) tempdir.d;\r
+               new MsaWriter(modulepath, outputpath, this, db, ui).flush();\r
+\r
+               Common.deleteDir(modulepath + File.separator + "temp");\r
+               //Common.toDoAll(modulepath + File.separator + "temp", Common.class.getMethod("deleteDir", String.class), null, null, Common.DIR);\r
                \r
                ui.println("Errors Left : " + db.error);\r
                ui.println("Complete!");\r
@@ -140,7 +125,7 @@ public class ModuleInfo {
 \r
                Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");\r
                Matcher mtrinclude;\r
-               \r
+\r
                Iterator<String> ii = localmodulesources.iterator();\r
                while ( ii.hasNext() ) {\r
                        curFile = ii.next();\r
@@ -218,7 +203,7 @@ public class ModuleInfo {
                        // find guid\r
                        matguid = Guid.ptnguid.matcher(line);                                                                           // several ways to implement this , which one is faster ? :\r
                        while (matguid.find()) {                                                                                                        // 1.currently , find once , then call to identify which is it\r
-                               if ((temp = Guid.register(matguid, this, db)) != null) {                        // 2.use 3 different matchers , search 3 times to find each\r
+                               if ((temp = Guid.register(matguid, this, db)) != null) {                                // 2.use 3 different matchers , search 3 times to find each\r
                                        //matguid.appendReplacement(result, db.getR9Guidname(temp));            // search the database for all 3 kinds of guids , high cost\r
                                }\r
                        }\r
@@ -272,7 +257,39 @@ public class ModuleInfo {
                }\r
        }\r
        \r
-       public static void main(String[] args) throws Exception {\r
-               FirstPanel.init();\r
+       public final void enroll(String filepath) throws Exception {\r
+               String[] temp;\r
+               if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") || \r
+                               filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) {\r
+                       temp = filepath.split("\\\\");\r
+                       localmodulesources.add(temp[temp.length - 1]);\r
+               } else if (filepath.contains(".inf") || filepath.contains(".msa")) {\r
+                       temp = filepath.split("\\\\");\r
+                       msaorinf.add(temp[temp.length - 1]);\r
+               }\r
+       }\r
+       \r
+       public static final void seekModule(String filepath) throws Exception {\r
+               if (isModule(filepath)) {\r
+                       //System.out.println("I'm in");\r
+                       new ModuleInfo(filepath);\r
+               }\r
+       }\r
+\r
+       private static final boolean isModule(String path) {\r
+               String[] list = new File(path).list();\r
+               for (int i = 0 ; i < list.length ; i++) {\r
+                       if (!new File(list[i]).isDirectory()) {\r
+                               if (list[i].contains(".inf") || list[i].contains(".msa")) {\r
+                                       return true;\r
+                               }\r
+                       }\r
+               }\r
+               return false;\r
+       }\r
+\r
+       public static final void main(String[] args) throws Exception {\r
+               ui = FirstPanel.init();\r
+               db = new Database();\r
        }\r
 }
\ No newline at end of file
index 4eb32463311b1f94b16e347644684c6170be2e47..b8bde6fef0fc445d46636ba1dc7409749ede0057 100644 (file)
@@ -17,24 +17,24 @@ import java.util.*;
 import java.util.regex.*;\r
 import org.tianocore.*;\r
 \r
-public class ModuleReader {\r
+public final class ModuleReader {\r
        ModuleReader(String path, ModuleInfo moduleinfo, Database database, UI u) {\r
-               modulepath = path;\r
-               mi = moduleinfo;\r
+               //modulepath = path;\r
+               //mi = moduleinfo;\r
                db = database;\r
                ui = u;\r
        }\r
-       private String modulepath;\r
-       private ModuleInfo mi;\r
-       private Database db;\r
-       private UI ui;\r
+       //private static String modulepath;\r
+       //private static ModuleInfo mi;\r
+       private static Database db;\r
+       private static UI ui;\r
        \r
-       private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");\r
-       private static Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);\r
-       private static Pattern ptnfilename = Pattern.compile("[^\\s]+");\r
+       private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");\r
+       private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);\r
+       private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");\r
        \r
-       public void readMsa(String name) throws Exception {\r
-               ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(modulepath + File.separator + name));\r
+       public static final void readMsa(String name, ModuleInfo mi) throws Exception {\r
+               ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));\r
                ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();\r
                MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();\r
                \r
@@ -53,14 +53,14 @@ public class ModuleReader {
                }\r
        }\r
        \r
-       public void readInf(String name) throws Exception {\r
+       public static final void readInf(String name, ModuleInfo mi) throws Exception {\r
                System.out.println("\nParsing INF file: " + name);\r
                String wholeline;\r
                Matcher mtrinfequation;\r
                Matcher mtrsection;\r
                Matcher mtrfilename;\r
 \r
-               wholeline = Common.file2string(modulepath + File.separator + name);\r
+               wholeline = Common.file2string(mi.modulepath + File.separator + name);\r
                mtrsection = ptnsection.matcher(wholeline);\r
                while (mtrsection.find()) {\r
                        if (mtrsection.group(1).matches("defines")) {\r
index 06e18686f5a96a4947135bce8489ea558c11042d..caec997c922ac3c61e0c41b79f8f80e51a030090 100644 (file)
@@ -20,14 +20,16 @@ import org.tianocore.SupportedArchitectures.Enum;
 import org.apache.xmlbeans.*;\r
 \r
 public class MsaWriter {\r
-       MsaWriter(String path, ModuleInfo moduleinfo, Database database, UI u) {\r
+       MsaWriter(String path, String outpath, ModuleInfo moduleinfo, Database database, UI u) {\r
                modulepath = path;\r
+               outputpath = outpath;\r
                mi = moduleinfo;\r
                db = database;\r
                ui = u;\r
        }\r
 \r
        private String modulepath;\r
+       private String outputpath;\r
        private ModuleInfo mi;\r
        private Database db;\r
        private UI ui;\r
@@ -187,7 +189,7 @@ public class MsaWriter {
         options.setSavePrettyPrintIndent(2);\r
         options.setUseDefaultNamespace();\r
         \r
-               BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));\r
+               BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));\r
                fulfillMsadoc().save(bw, options);\r
                //MsaTreeEditor.init(mi, ui, msadoc);\r
                bw.flush();\r
index d213693c24a7dc7b6a3e4678e0c2270d4e759bc7..c1c36981d5d8ac78f86e1cadade3fa99e97d5937 100644 (file)
@@ -17,14 +17,16 @@ import java.util.*;
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
-public class SourceFileReplacer {\r
-       SourceFileReplacer(String path, ModuleInfo moduleinfo, Database database, UI fp) {\r
+public final class SourceFileReplacer {\r
+       SourceFileReplacer(String path, String outpath, ModuleInfo moduleinfo, Database database, UI fp) {\r
                modulepath = path;\r
+               outputpath = outpath;\r
                mi = moduleinfo;\r
                db = database;\r
                ui = fp;\r
        }\r
        private String modulepath;\r
+       private String outputpath;\r
        private ModuleInfo mi;\r
        private Database db;\r
        private UI ui;\r
@@ -47,7 +49,7 @@ public class SourceFileReplacer {
        private Set<r8tor9> fileprotocol = new HashSet<r8tor9>();\r
        private Set<String> filer8only = new HashSet<String>();\r
        \r
-       private String r8only = "EfiLibInstallDriverBinding " +\r
+       private static final String r8only = "EfiLibInstallDriverBinding " +\r
                        "EfiLibInstallAllDriverProtocols " +\r
                        "EfiLibCompareLanguage " +\r
                        "BufToHexString " +\r
@@ -68,7 +70,6 @@ public class SourceFileReplacer {
                        "GetIoPortSpaceAddressHobInfo ";\r
        \r
        public void flush() throws Exception {\r
-               PrintWriter outfile;\r
                String outname = null;\r
                String inname = null;\r
                if (ui.yesOrNo("Changes will be made to the Source Code.  View details?")) {\r
@@ -85,14 +86,7 @@ public class SourceFileReplacer {
                                        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
+                               Common.string2file(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname), outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);\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
@@ -100,14 +94,7 @@ public class SourceFileReplacer {
                                        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.file2string(modulepath + File.separator + "temp" + File.separator + inname));\r
-                               outfile.flush();\r
-                               outfile.close();\r
-                               */\r
+                               Common.string2file(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname), outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);\r
                        }\r
                }\r
 \r
@@ -120,8 +107,8 @@ public class SourceFileReplacer {
                String paragraph = null;\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
+               PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));\r
+               PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.h")));\r
                Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL);\r
                Matcher mtrr8only = ptnr8only.matcher(line);\r
                Matcher mtrr8onlyhead;\r
index 170a2488bd99573196720cb370df2cca2b029c36..c9a0deb0280fc02de7f3b6d7fab37c417d17eac6 100644 (file)
@@ -27,4 +27,6 @@ public interface UI {
        public String choose(String message, Object[] choicelist);\r
        \r
        public String getInput(String message);\r
+       \r
+       public String getFilepath();            // necessary ?\r
 }\r