mirror of https://github.com/acidanthera/audk.git
REMODEL OF SourceFileReplacer.java
AT LAST git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1464 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
78b5fb8265
commit
16b7eeef54
|
@ -142,8 +142,15 @@ public final class Common {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final void toDoAll(Set<String> set, ForDoAll fda) throws Exception {
|
||||
Iterator<String> di = set.iterator();
|
||||
while (di.hasNext()) {
|
||||
fda.run(di.next());
|
||||
}
|
||||
}
|
||||
|
||||
public static void toDoAll(String path, ForDoAll fda, int type) throws Exception { // filter of file type can be done in toDo
|
||||
public static final void toDoAll(String path, ForDoAll fda, int type) throws Exception { // filter of file type can be done in toDo
|
||||
String[] list = new File(path).list();
|
||||
File test;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class MigrationTool {
|
|||
ModuleReader.ModuleScan(mi);
|
||||
|
||||
//MigrationTool.ui.yesOrNo("go on replace?");
|
||||
SourceFileReplacer.flush(mi); // some adding library actions are taken here,so it must be put before "MsaWriter"
|
||||
SourceFileReplacer.fireAt(mi); // some adding library actions are taken here,so it must be put before "MsaWriter"
|
||||
|
||||
//MigrationTool.ui.yesOrNo("go on show?");
|
||||
// show result
|
||||
|
|
|
@ -15,8 +15,6 @@ package org.tianocore.migration;
|
|||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.tianocore.ModuleTypeDef;
|
||||
|
||||
/*
|
||||
Class ModuleInfo is built for scanning the source files, it contains all the needed
|
||||
information and all the temporary data.
|
||||
|
|
|
@ -17,9 +17,10 @@ import java.util.*;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class SourceFileReplacer {
|
||||
private static ModuleInfo mi;
|
||||
private static boolean showdetails = false;
|
||||
public final class SourceFileReplacer implements Common.ForDoAll {
|
||||
private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();
|
||||
private ModuleInfo mi;
|
||||
private static boolean showdetails = true; // set this as default now, may be changed in the future
|
||||
|
||||
private static class r8tor9 {
|
||||
r8tor9(String r8, String r9) {
|
||||
|
@ -38,52 +39,11 @@ public final class SourceFileReplacer {
|
|||
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
||||
private static final Set<String> filer8only = new HashSet<String>();
|
||||
|
||||
public static final void flush(ModuleInfo moduleinfo) throws Exception {
|
||||
mi = moduleinfo;
|
||||
|
||||
String outname = null;
|
||||
String inname = null;
|
||||
|
||||
showdetails = true; // set this as default now, may be changed in the future
|
||||
|
||||
Iterator<String> di = mi.localmodulesources.iterator();
|
||||
String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;
|
||||
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;
|
||||
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(Common.file2string(tempinpath + inname)), tempoutpath + outname);
|
||||
} else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".uni")) {
|
||||
if (inname.contains(".H")) {
|
||||
outname = inname.replaceFirst(".H", ".h");
|
||||
} else {
|
||||
outname = inname;
|
||||
}
|
||||
MigrationTool.ui.println("\nCopying file: " + inname);
|
||||
Common.string2file(Common.file2string(tempinpath + inname), tempoutpath + outname);
|
||||
} else if (inname.contains(".dxs")) {
|
||||
outname = inname;
|
||||
MigrationTool.ui.println("\nModifying file: " + inname);
|
||||
Common.string2file(convertdxs(Common.file2string(tempinpath + inname)), tempoutpath + outname);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mi.hashr8only.isEmpty()) {
|
||||
addr8only();
|
||||
}
|
||||
}
|
||||
|
||||
private static final String addincludefile(String wholeline, String hfile) {
|
||||
return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n");
|
||||
}
|
||||
|
||||
private static final String convertdxs(String wholeline) {
|
||||
private final String convertdxs(String wholeline) {
|
||||
if (mi.getModuleType().equals("PEIM")) {
|
||||
return addincludefile(wholeline, "\\<PeimDepex.h\\>");
|
||||
} else {
|
||||
|
@ -91,7 +51,7 @@ public final class SourceFileReplacer {
|
|||
}
|
||||
}
|
||||
|
||||
private static final void addr8only() throws Exception {
|
||||
private final void addr8only() throws Exception {
|
||||
String paragraph = null;
|
||||
String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");
|
||||
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));
|
||||
|
@ -123,7 +83,7 @@ public final class SourceFileReplacer {
|
|||
}
|
||||
|
||||
// Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you!
|
||||
private static final String sourcefilereplace(String wholeline) throws Exception {
|
||||
private final String sourcefilereplace(String wholeline) throws Exception {
|
||||
boolean addr8 = false;
|
||||
|
||||
Pattern pat = Pattern.compile("g?(BS|RT)(\\s*->\\s*)([a-zA-Z_]\\w*)", Pattern.MULTILINE); // ! only two level () bracket allowed !
|
||||
|
@ -312,4 +272,60 @@ public final class SourceFileReplacer {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------ForDoAll-----------------------------------//
|
||||
public void run(String filepath) throws Exception {
|
||||
String outname = null;
|
||||
String inname = filepath.replace(mi.modulepath + File.separator, "");
|
||||
String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;
|
||||
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;
|
||||
|
||||
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(Common.file2string(tempinpath + inname)), tempoutpath + outname);
|
||||
} else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".uni")) {
|
||||
if (inname.contains(".H")) {
|
||||
outname = inname.replaceFirst(".H", ".h");
|
||||
} else {
|
||||
outname = inname;
|
||||
}
|
||||
MigrationTool.ui.println("\nCopying file: " + inname);
|
||||
Common.string2file(Common.file2string(tempinpath + inname), tempoutpath + outname);
|
||||
} else if (inname.contains(".dxs")) {
|
||||
outname = inname;
|
||||
MigrationTool.ui.println("\nModifying file: " + inname);
|
||||
Common.string2file(convertdxs(Common.file2string(tempinpath + inname)), tempoutpath + outname);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean dirFilter(String filepath) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean fileFilter(String filepath) {
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------ForDoAll-----------------------------------//
|
||||
|
||||
private final void setModuleInfo(ModuleInfo moduleinfo) {
|
||||
mi = moduleinfo;
|
||||
}
|
||||
|
||||
private final void start() throws Exception {
|
||||
Common.toDoAll(mi.localmodulesources, this);
|
||||
|
||||
if (!mi.hashr8only.isEmpty()) {
|
||||
addr8only();
|
||||
}
|
||||
}
|
||||
|
||||
public static final void fireAt(ModuleInfo moduleinfo) throws Exception {
|
||||
SFReplacer.setModuleInfo(moduleinfo);
|
||||
SFReplacer.start();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue