X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FMigrationTools%2Forg%2Ftianocore%2Fmigration%2FSourceFileReplacer.java;h=42a220f6809b007596ea231fa47ef96b2e3cc90c;hb=482407d3d6faaa8eba7975d425c1e386b75dae6d;hp=2df0ffd104b4d9be5788873ffeb8c443875ae9b3;hpb=719cebfea79fc6a8cdf06e1694a6596b4db69d1b;p=mirror_edk2.git diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java b/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java index 2df0ffd104..42a220f680 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java @@ -17,20 +17,11 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class SourceFileReplacer { - SourceFileReplacer(String path, ModuleInfo moduleinfo, Database database, UI fp) { - modulepath = path; - mi = moduleinfo; - db = database; - ui = fp; - } - private String modulepath; - private ModuleInfo mi; - private Database db; - private UI ui; - private boolean showdetails = false; +public final class SourceFileReplacer { + private static ModuleInfo mi; + private static boolean showdetails = false; - private class r8tor9 { + private static class r8tor9 { r8tor9(String r8, String r9) { r8thing = r8; r9thing = r9; @@ -40,64 +31,45 @@ public class SourceFileReplacer { } // these sets are used only for printing log of the changes in current file - private Set filefunc = new HashSet(); - private Set filemacro = new HashSet(); - private Set fileguid = new HashSet(); - private Set fileppi = new HashSet(); - private Set fileprotocol = new HashSet(); - private Set filer8only = new HashSet(); - - private String r8only = "EfiLibInstallDriverBinding " + - "EfiLibInstallAllDriverProtocols " + - "EfiLibCompareLanguage " + - "BufToHexString " + - "EfiStrTrim " + - "EfiValueToHexStr " + - "HexStringToBuf " + - "IsHexDigit " + - "NibbleToHexChar " + - "GetHob " + - "GetHobListSize " + - "GetHobVersion " + - "GetHobBootMode " + - "GetCpuHobInfo " + - "GetDxeCoreHobInfo " + - "GetNextFirmwareVolumeHob " + - "GetNextGuidHob " + - "GetPalEntryHobInfo " + - "GetIoPortSpaceAddressHobInfo "; + private static final Set filefunc = new HashSet(); + private static final Set filemacro = new HashSet(); + private static final Set fileguid = new HashSet(); + private static final Set fileppi = new HashSet(); + private static final Set fileprotocol = new HashSet(); + private static final Set filer8only = new HashSet(); - public void flush() throws Exception { - PrintWriter outfile; - String temp = null; - if (ui.yesOrNo("Changes will be made to the Source Code. View details?")) { + public static final void flush(ModuleInfo moduleinfo) throws Exception { + + mi = moduleinfo; + + String outname = null; + String inname = null; + /* + if (MigrationTool.ui.yesOrNo("Changes will be made to the Source Code. View details?")) { showdetails = true; } - File tempdir = new File(modulepath + File.separator + "result" + File.separator); - if (!tempdir.exists()) tempdir.mkdir(); - String[] list = new File(modulepath + File.separator + "temp").list(); //what I change is the non-local .h commented-out files - for (int i = 0 ; i < list.length ; i++) { - if (list[i].contains(".c")) { - ui.println("\nModifying file: " + list[i]); - outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + list[i]))); - outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + list[i])); - outfile.flush(); - outfile.close(); - } else { - if (list[i].contains(".h")) { - temp = list[i]; - } else if (list[i].contains(".C")) { - temp = list[i].replaceFirst(".C", ".c"); - } else if (list[i].contains(".H")) { - temp = list[i].replaceFirst(".H", ".h"); + */ + showdetails = true; // set this as default now, may be changed in the future + + Iterator di = mi.localmodulesources.iterator(); + while (di.hasNext()) { + inname = di.next(); + if (inname.contains(".c") || inname.contains(".C")) { + if (inname.contains(".C")) { + outname = inname.replaceFirst(".C", ".c"); + } else { + outname = inname; + } + MigrationTool.ui.println("\nModifying file: " + inname); + Common.string2file(sourcefilereplace(mi.modulepath + File.separator + "temp" + File.separator + inname), mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname); + } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) { + if (inname.contains(".H")) { + outname = inname.replaceFirst(".H", ".h"); } else { - continue; + outname = inname; } - ui.println("\nCopying file: " + temp); - outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + temp))); - outfile.append(sourcefiletostring(modulepath + File.separator + "temp" + File.separator + list[i])); - outfile.flush(); - outfile.close(); + MigrationTool.ui.println("\nCopying file: " + inname); + Common.string2file(Common.file2string(mi.modulepath + File.separator + "temp" + File.separator + inname), mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname); } } @@ -106,13 +78,12 @@ public class SourceFileReplacer { } } - private void addr8only() throws Exception { + private static final void addr8only() throws Exception { String paragraph = null; - String line = sourcefiletostring(Database.defaultpath + 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"))); - //outfile1.append("#include \"R8Lib.h\"\n\n"); - //outfile2.append("#include \"R8Lib.h\"\n\n"); + String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c"); + //Common.ensureDir(mi.modulepath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c"); + PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c"))); + PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.h"))); Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL); Matcher mtrr8only = ptnr8only.matcher(line); Matcher mtrr8onlyhead; @@ -134,20 +105,13 @@ public class SourceFileReplacer { outfile1.close(); outfile2.flush(); outfile2.close(); - } - - 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(); + + mi.localmodulesources.add("R8Lib.h"); + mi.localmodulesources.add("R8Lib.c"); } // 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 { + private static final String sourcefilereplace(String filename) throws Exception { BufferedReader rd = new BufferedReader(new FileReader(filename)); StringBuffer wholefile = new StringBuffer(); String line; @@ -167,7 +131,7 @@ public class SourceFileReplacer { // replace BS -> gBS , RT -> gRT Matcher mat = pat.matcher(line); if (mat.find()) { // add a library here - ui.println("Converting all BS->gBS, RT->gRT"); + MigrationTool.ui.println("Converting all BS->gBS, RT->gRT"); line = mat.replaceAll("g$1$2$3"); //unknown correctiveness } mat.reset(); @@ -184,7 +148,7 @@ public class SourceFileReplacer { Pattern patentrypoint = Pattern.compile("EFI_DRIVER_ENTRY_POINT[^\\}]*\\}"); Matcher matentrypoint = patentrypoint.matcher(line); if (matentrypoint.find()) { - ui.println("Deleting Entry_Point"); + MigrationTool.ui.println("Deleting Entry_Point"); line = matentrypoint.replaceAll(""); } */ @@ -202,10 +166,10 @@ public class SourceFileReplacer { mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib"); //a mi.hashrequiredr9libs.add("DxeServicesTableLib"); //l } else { // - mi.hashrequiredr9libs.add(db.getR9Lib(r8thing)); // add a library here + mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); // add a library here } - if ((r9thing = db.getR9Func(r8thing)) != null) { + if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) { if (!r8thing.equals(r9thing)) { if (line.contains(r8thing)) { line = line.replaceAll(r8thing, r9thing); @@ -213,9 +177,7 @@ public class SourceFileReplacer { Iterator rt = filefunc.iterator(); while (rt.hasNext()) { temp = rt.next(); - if (r8only.contains(temp.r8thing)) { - mi.localmodulesources.add("R8Lib.h"); - mi.localmodulesources.add("R8Lib.c"); + if (MigrationTool.db.r8only.contains(temp.r8thing)) { filer8only.add(r8thing); mi.hashr8only.add(r8thing); addr8 = true; @@ -233,8 +195,8 @@ public class SourceFileReplacer { it = mi.hashnonlocalmacro.iterator(); while (it.hasNext()) { //macros are all assumed MdePkg currently r8thing = it.next(); - //mi.hashrequiredr9libs.add(db.getR9Lib(r8thing)); - if ((r9thing = db.getR9Macro(r8thing)) != null) { + //mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); + if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) { if (line.contains(r8thing)) { line = line.replaceAll(r8thing, r9thing); filemacro.add(new r8tor9(r8thing, r9thing)); @@ -301,7 +263,7 @@ public class SourceFileReplacer { show(fileppi, "ppi"); show(fileprotocol, "protocol"); if (!filer8only.isEmpty()) { - ui.println("Converting r8only : " + filer8only); + MigrationTool.ui.println("Converting r8only : " + filer8only); } filefunc.clear(); @@ -310,33 +272,33 @@ public class SourceFileReplacer { fileppi.clear(); fileprotocol.clear(); filer8only.clear(); - + return line; } - private void show(Set hash, String sh) { + private static final void show(Set hash, String sh) { Iterator it = hash.iterator(); r8tor9 temp; if (showdetails) { if (!hash.isEmpty()) { - ui.print("Converting " + sh + " : "); + MigrationTool.ui.print("Converting " + sh + " : "); while (it.hasNext()) { temp = it.next(); - ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] "); + MigrationTool.ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] "); } - ui.println(""); + MigrationTool.ui.println(""); } } } - private void replaceGuid(String line, Set hash, String kind, Set filehash) { + private static final void replaceGuid(String line, Set hash, String kind, Set filehash) { Iterator it; String r8thing; String r9thing; it = hash.iterator(); while (it.hasNext()) { r8thing = it.next(); - if ((r9thing = db.getR9Guidname(r8thing)) != null) { + if ((r9thing = MigrationTool.db.getR9Guidname(r8thing)) != null) { if (!r8thing.equals(r9thing)) { if (line.contains(r8thing)) { line = line.replaceAll(r8thing, r9thing);