]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add subdirectory support
authoralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Aug 2006 04:27:45 +0000 (04:27 +0000)
committeralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Aug 2006 04:27:45 +0000 (04:27 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1261 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java
Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java
Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java
Tools/Source/MigrationTools/org/tianocore/migration/UI.java

index 5bd9cf1ce4f1c078544110cf5b168f45a5f56bba..30085d449edd0770bc1fd7c5ab4712334da39fa5 100644 (file)
@@ -96,6 +96,10 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
                }\r
        }\r
 \r
+       public String choose(String message, Object[] choicelist) {\r
+               return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);\r
+       }\r
+\r
        //---------------------------------------------------------------------------------------//\r
        \r
        /*\r
index b238551cac84ca18dc6e7af3094358c61bb515a1..fa1843f15ea2bea95a6cdb4c6f4261ae4832bc48 100644 (file)
@@ -39,6 +39,7 @@ public class ModuleInfo {
        \r
        public Set<String> localmodulesources = new HashSet<String>();          //contains both .c and .h\r
        public Set<String> preprocessedccodes = new HashSet<String>();\r
+       public Set<String> msaorinf = new HashSet<String>();                            //only a little, hash may be too big for this\r
        \r
        public Set<String> hashfuncc = new HashSet<String>();\r
        public Set<String> hashfuncd = new HashSet<String>();\r
@@ -54,50 +55,42 @@ public class ModuleInfo {
        \r
        private static String migrationcomment = "//%$//";\r
        \r
-       private void moduleScan() throws Exception {\r
-               String[] list = new File(modulepath).list();\r
-               boolean hasInf = false;\r
-               String infname = null;\r
-               boolean hasMsa = false;\r
-               String msaname = null;\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
-                       if (new File(list[i]).isDirectory()) {\r
-                               ;\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")) {\r
-                                       localmodulesources.add(list[i]);\r
-                               } else if (list[i].contains(".h") || list[i].contains(".H")) {\r
-                                       localmodulesources.add(list[i]);        //the case that several .inf or .msa found is not concerned\r
-                               } else if (list[i].contains(".dxs")) {\r
-                                       localmodulesources.add(list[i]);\r
-                               } else if (list[i].contains(".uni")) {\r
-                                       localmodulesources.add(list[i]);\r
-                               } else if (list[i].contains(".inf")) {\r
-                                       if (ui.yesOrNo("Found .inf file : " + list[i] + "\nDo you want to use this file as this module's .inf?")) {\r
-                                               hasInf = true;\r
-                                               infname = list[i];\r
-                                       } else {\r
-                                               continue;\r
-                                       }\r
-                               } else if (list[i].contains(".msa")) {\r
-                                       if (ui.yesOrNo("Found .msa file : " + list[i] + "\nDo you want to use this file as this module's .msa?")) {\r
-                                               hasMsa = true;\r
-                                               msaname = list[i];\r
-                                       } else {\r
-                                               continue;\r
-                                       }\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
-               ModuleReader mr = new ModuleReader(modulepath, this, db);\r
-               if (hasInf) {                                                   // this sequence shows using .inf as default\r
-                       mr.readInf(infname);\r
-               } else if (hasMsa) {\r
-                       mr.readMsa(msaname);\r
+       }\r
+       \r
+       private void moduleScan() throws Exception {\r
+               dirScan("");\r
+               String filename = null;\r
+               if (msaorinf.isEmpty()) {\r
+                       ui.println("No .inf nor .msa file found! Tool Halt!");\r
+                       System.exit(0);\r
                } else {\r
-                       ui.println("No INF nor MSA file found!");\r
+                       filename = ui.choose("Found .inf or .msa file in the module\nChoose one Please", msaorinf.toArray());\r
+               }\r
+               ModuleReader mr = new ModuleReader(modulepath, this, db);\r
+               if (filename.contains(".inf")) {\r
+                       mr.readInf(filename);\r
+               } else if (filename.contains(".msa")) {\r
+                       mr.readMsa(filename);\r
                }\r
                \r
                CommentOutNonLocalHFile();\r
@@ -106,7 +99,7 @@ public class ModuleInfo {
                new SourceFileReplacer(modulepath, 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
+               if (ui.yesOrNo("Parse Module Information Complete . See details ?")) {\r
                        ui.println("\nModule Information : ");\r
                        ui.println("Entrypoint : " + entrypoint);\r
                        show(protocol, "Protocol : ");\r
@@ -129,8 +122,8 @@ public class ModuleInfo {
                \r
                ui.println("Errors Left : " + db.error);\r
                ui.println("Complete!");\r
-               ui.println("Your R9 module was placed here: " + modulepath + File.separator + "result");\r
-               ui.println("Your logfile was placed here: " + modulepath);\r
+               ui.println("Your R9 module is placed at " + modulepath + File.separator + "result");\r
+               ui.println("Your logfile is placed at " + modulepath);\r
        }\r
        \r
        private void show(Set<String> hash, String show) {\r
@@ -138,6 +131,19 @@ public class ModuleInfo {
                ui.println(hash);\r
        }\r
 \r
+       public void ensureDir(String objFileWhole) {\r
+               Pattern ptnseparate = Pattern.compile("(.*)\\\\[^\\\\]*");\r
+               Matcher mtrseparate;\r
+               File tempdir;\r
+\r
+               mtrseparate = ptnseparate.matcher(objFileWhole);\r
+               if (mtrseparate.find()) {\r
+                       tempdir = new File(mtrseparate.group(1));\r
+                       if (!tempdir.exists()) tempdir.mkdirs();\r
+               }\r
+               \r
+       }\r
+       \r
        // add '//' to all non-local include lines\r
        private void CommentOutNonLocalHFile() throws IOException {\r
                BufferedReader rd;\r
@@ -146,20 +152,18 @@ public class ModuleInfo {
                PrintWriter outfile;\r
 \r
                Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");\r
-               Matcher mtcinclude;\r
-               \r
-               File tempdir = new File(modulepath + File.separator + "temp" + File.separator);\r
-               if (!tempdir.exists()) tempdir.mkdir();\r
+               Matcher mtrinclude;\r
                \r
                Iterator<String> ii = localmodulesources.iterator();\r
                while ( ii.hasNext() ) {\r
                        curFile = ii.next();\r
                        rd = new BufferedReader(new FileReader(modulepath + File.separator + curFile));\r
+                       ensureDir(modulepath + File.separator + "temp" + File.separator + curFile);\r
                        outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "temp" + File.separator + curFile)));\r
                        while ((line = rd.readLine()) != null) {\r
                                if (line.contains("#include")) {\r
-                                       mtcinclude = ptninclude.matcher(line);\r
-                                       if (mtcinclude.find() && localmodulesources.contains(mtcinclude.group(1))) {\r
+                                       mtrinclude = ptninclude.matcher(line);\r
+                                       if (mtrinclude.find() && localmodulesources.contains(mtrinclude.group(1))) {\r
                                        } else {\r
                                                line = migrationcomment + line;\r
                                        }\r
@@ -170,15 +174,7 @@ public class ModuleInfo {
                        outfile.close();\r
                }\r
        }\r
-       /*\r
-       private void search(String line, Pattern ptn, Method md) {\r
-               matmacro = Func.ptntmacro.matcher(line);\r
-               while (matmacro.find()) {\r
-                       if ((temp = Func.registerMacro(matmacro, this, db)) != null) {\r
-                       }\r
-               }\r
-       }\r
-       */\r
+\r
        private void parsePreProcessedSourceCode() throws Exception {\r
                //Cl cl = new Cl(modulepath);\r
                //cl.execute("Fat.c");\r
@@ -187,19 +183,20 @@ public class ModuleInfo {
                //System.out.println("Note!!!! The CL is not implemented now , pls do it manually!!! RUN :");\r
                //System.out.println("cl " + modulepath + "\\temp\\*.c" + " -P");\r
                //String[] list = new File(modulepath + File.separator + "temp").list();        // without CL , add\r
-               String[] list = new File(modulepath).list();\r
-               for (int i = 0 ; i < list.length ; i++) {\r
-                       if (list[i].contains(".c")) {                                                                                   // without CL , change to .i\r
-                               preprocessedccodes.add(list[i]);\r
-                       }\r
-               }\r
-               //\r
-               Iterator<String> ii = preprocessedccodes.iterator();\r
                BufferedReader rd = null;\r
                String ifile = null;\r
                String line = null;\r
                String temp = null;\r
-               //StringBuffer result = new StringBuffer();\r
+               \r
+               Iterator<String> ii = localmodulesources.iterator();\r
+               while (ii.hasNext()) {\r
+                       temp = ii.next();\r
+                       if (temp.contains(".c")) {\r
+                               preprocessedccodes.add(temp);\r
+                       }\r
+               }\r
+               \r
+               ii = preprocessedccodes.iterator();\r
                \r
                Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE);\r
                Pattern patentrypoint = Pattern.compile("EFI_([A-Z]*)_ENTRY_POINT\\s*\\(([^\\(\\)]*)\\)",Pattern.MULTILINE);\r
@@ -291,4 +288,4 @@ public class ModuleInfo {
        public static void main(String[] args) throws Exception {\r
                FirstPanel.init();\r
        }\r
-}\r
+}
\ No newline at end of file
index 2df0ffd104b4d9be5788873ffeb8c443875ae9b3..34eb6be45478750a83e6d5523c772cf4854bbba7 100644 (file)
@@ -51,7 +51,7 @@ public class SourceFileReplacer {
                        "EfiLibInstallAllDriverProtocols " +\r
                        "EfiLibCompareLanguage " +\r
                        "BufToHexString " +\r
-                       "EfiStrTrim " +\r
+                       "EfiStrTrim " +                                                 //is the r8only lib going to be enlarged????  Caution !!!!\r
                        "EfiValueToHexStr " +\r
                        "HexStringToBuf " +\r
                        "IsHexDigit " +\r
@@ -69,33 +69,37 @@ public class SourceFileReplacer {
        \r
        public void flush() throws Exception {\r
                PrintWriter outfile;\r
-               String temp = null;\r
-               if (ui.yesOrNo("Changes will be made to the Source Code.  View details?")) {\r
+               String outname = null;\r
+               String inname = null;\r
+               if (ui.yesOrNo("Change Source Code is to be doing . See details ?")) {\r
                        showdetails = true;\r
                }\r
-               File tempdir = new File(modulepath + File.separator + "result" + File.separator);\r
-               if (!tempdir.exists()) tempdir.mkdir();\r
-               String[] list = new File(modulepath + File.separator + "temp").list();  //what I change is the non-local .h commented-out files\r
-               for (int i = 0 ; i < list.length ; i++) {\r
-                       if (list[i].contains(".c")) {\r
-                               ui.println("\nModifying file: " + list[i]);\r
-                               outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + list[i])));\r
-                               outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + list[i]));\r
+               \r
+               Iterator<String> di = mi.localmodulesources.iterator();\r
+               while (di.hasNext()) {\r
+                       inname = di.next();\r
+                       if (inname.contains(".c") || inname.contains(".C")) {\r
+                               if (inname.contains(".C")) {\r
+                                       outname = inname.replaceFirst(".C", ".c");\r
+                               } else {\r
+                                       outname = inname;\r
+                               }\r
+                               ui.println("\nModifying file : " + inname);\r
+                               mi.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
-                       } else {\r
-                               if (list[i].contains(".h")) {\r
-                                       temp = list[i];\r
-                               } else if (list[i].contains(".C")) {\r
-                                       temp = list[i].replaceFirst(".C", ".c");\r
-                               } else if (list[i].contains(".H")) {\r
-                                       temp = list[i].replaceFirst(".H", ".h");\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
                                } else {\r
-                                       continue;\r
+                                       outname = inname;\r
                                }\r
-                               ui.println("\nCopying file: " + temp);\r
-                               outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + temp)));\r
-                               outfile.append(sourcefiletostring(modulepath + File.separator + "temp" + File.separator + list[i]));\r
+                               ui.println("\nCopying file : " + inname);\r
+                               mi.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(sourcefiletostring(modulepath + File.separator + "temp" + File.separator + inname));\r
                                outfile.flush();\r
                                outfile.close();\r
                        }\r
@@ -109,10 +113,9 @@ public class SourceFileReplacer {
        private void addr8only() throws Exception {\r
                String paragraph = null;\r
                String line = sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c");\r
+               mi.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
-               //outfile1.append("#include \"R8Lib.h\"\n\n");\r
-               //outfile2.append("#include \"R8Lib.h\"\n\n");\r
                Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL);\r
                Matcher mtrr8only = ptnr8only.matcher(line);\r
                Matcher mtrr8onlyhead;\r
@@ -134,6 +137,9 @@ public class SourceFileReplacer {
                outfile1.close();\r
                outfile2.flush();\r
                outfile2.close();\r
+               \r
+               mi.localmodulesources.add("R8Lib.h");\r
+               mi.localmodulesources.add("R8Lib.c");\r
        }\r
        \r
        private String sourcefiletostring(String filename) throws Exception {\r
@@ -167,7 +173,7 @@ public class SourceFileReplacer {
                // replace BS -> gBS , RT -> gRT\r
                Matcher mat = pat.matcher(line);\r
                if (mat.find()) {                                                                                               // add a library here\r
-                       ui.println("Converting all BS->gBS, RT->gRT");\r
+                       ui.println("Converting all BS->gBS,RT->gRT");\r
                        line = mat.replaceAll("g$1$2$3");                                                       //unknown correctiveness\r
                }\r
                mat.reset();\r
@@ -214,8 +220,6 @@ public class SourceFileReplacer {
                                                while (rt.hasNext()) {\r
                                                        temp = rt.next();\r
                                                        if (r8only.contains(temp.r8thing)) {\r
-                                                               mi.localmodulesources.add("R8Lib.h");\r
-                                                               mi.localmodulesources.add("R8Lib.c");\r
                                                                filer8only.add(r8thing);\r
                                                                mi.hashr8only.add(r8thing);\r
                                                                addr8 = true;\r
@@ -310,7 +314,7 @@ public class SourceFileReplacer {
                fileppi.clear();\r
                fileprotocol.clear();\r
                filer8only.clear();\r
-               \r
+\r
                return line;\r
        }\r
        \r
index 755237930003c937d76d6dc442b3e9b016813bed..7f91ebe46170546ea04c3fa318ef053018c5aa4a 100644 (file)
@@ -23,4 +23,6 @@ public interface UI {
        public void println(String message);\r
        \r
        public void println(Set<String> hash);\r
+       \r
+       public String choose(String message, Object[] choicelist);\r
 }\r