]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java
Turn to Regex in ModuleReader.java
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / SourceFileReplacer.java
index 6f56e51969c0706a00c870046316be2306b8a2e5..03617ab7167cc61e51d0031b20be09fced2b994a 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("Change Source Code is to be doing . See details ?")) {\r
+               String outname = null;\r
+               String inname = null;\r
+               if (ui.yesOrNo("Changes will be made to the Source Code.  View 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
+                               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
-                       } 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
+                               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.flush();\r
                                outfile.close();\r
                        }\r
@@ -108,11 +112,10 @@ public class SourceFileReplacer {
        \r
        private void addr8only() throws Exception {\r
                String paragraph = null;\r
-               String line = sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c");\r
+               String line = Common.sourcefiletostring(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
-               //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,16 +137,9 @@ public class SourceFileReplacer {
                outfile1.close();\r
                outfile2.flush();\r
                outfile2.close();\r
-       }\r
-       \r
-       private String sourcefiletostring(String filename) throws Exception {\r
-               BufferedReader rd = new BufferedReader(new FileReader(filename));\r
-               StringBuffer wholefile = new StringBuffer();\r
-               String line;\r
-               while ((line = rd.readLine()) != null) {\r
-                       wholefile.append(line + "\n");\r
-               }\r
-               return wholefile.toString();\r
+               \r
+               mi.localmodulesources.add("R8Lib.h");\r
+               mi.localmodulesources.add("R8Lib.c");\r
        }\r
        \r
        // Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you!\r
@@ -167,7 +163,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 +210,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 +304,7 @@ public class SourceFileReplacer {
                fileppi.clear();\r
                fileprotocol.clear();\r
                filer8only.clear();\r
-               \r
+\r
                return line;\r
        }\r
        \r