add .. support

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1534 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
alfred 2006-09-14 08:09:54 +00:00
parent ce32083fca
commit 39e5e412f9
6 changed files with 136 additions and 53 deletions

View File

@ -22,8 +22,8 @@ public final class Common {
public static final int FILE = 1; public static final int FILE = 1;
public static final int DIR = 2; public static final int DIR = 2;
public static final String strseparate = "(.*)\\\\([^\\\\]*)"; public static final String STRSEPARATER = "(.*)\\\\([^\\\\]*)";
public static final Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)"); public static final Pattern PTNSEPARATER = Pattern.compile("(.*)\\\\([^\\\\]*)");
//-------------------------------------regex------------------------------------------// //-------------------------------------regex------------------------------------------//
@ -53,6 +53,7 @@ public final class Common {
while ((line = rd.readLine()) != null) { while ((line = rd.readLine()) != null) {
wholefile.append(line + "\n"); wholefile.append(line + "\n");
} }
rd.close();
return wholefile.toString(); return wholefile.toString();
} }
@ -64,6 +65,10 @@ public final class Common {
outfile.close(); outfile.close();
} }
public static final void fileCopy(String src, String des) throws Exception {
string2file(file2string(src), des);
}
//-----------------------------------file&string---------------------------------------// //-----------------------------------file&string---------------------------------------//
//--------------------------------------dir--------------------------------------------// //--------------------------------------dir--------------------------------------------//
@ -76,7 +81,7 @@ public final class Common {
*/ */
public static final void ensureDir(String objFileWhole) { public static final void ensureDir(String objFileWhole) {
File tempdir; File tempdir;
Matcher mtrseparate = ptnseparate.matcher(objFileWhole); Matcher mtrseparate = PTNSEPARATER.matcher(objFileWhole);
if (mtrseparate.find()) { if (mtrseparate.find()) {
tempdir = new File(mtrseparate.group(1)); tempdir = new File(mtrseparate.group(1));
if (!tempdir.exists()) tempdir.mkdirs(); if (!tempdir.exists()) tempdir.mkdirs();
@ -98,7 +103,7 @@ public final class Common {
} }
public static final String dirCopy_(String src) throws Exception { public static final String dirCopy_(String src) throws Exception {
Matcher mtrseparate = Common.ptnseparate.matcher(src); Matcher mtrseparate = Common.PTNSEPARATER.matcher(src);
if (mtrseparate.find()) { if (mtrseparate.find()) {
dirCopy(src, mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2)); dirCopy(src, mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2));
} }
@ -109,16 +114,28 @@ public final class Common {
String[] list = new File(src).list(); String[] list = new File(src).list();
File test; File test;
ensureDir(des);
for (int i = 0 ; i < list.length ; i++) { for (int i = 0 ; i < list.length ; i++) {
test = new File(src + File.separator + list[i]); test = new File(src + File.separator + list[i]);
if (test.isDirectory()) { if (test.isDirectory()) {
dirCopy(src + File.separator + list[i], des + File.separator + list[i]); dirCopy(src + File.separator + list[i], des + File.separator + list[i]);
} else { } else {
ensureDir(des + File.separator + list[i]); //ensureDir(des + File.separator + list[i]);
string2file(file2string(src + File.separator + list[i]), des + File.separator + list[i]); string2file(file2string(src + File.separator + list[i]), des + File.separator + list[i]);
} }
} }
} }
public static final void oneLevelDirCopy(String src, String des, String type) throws Exception {
String[] list = new File(src).list();
ensureDir(des);
for (int i = 0; i < list.length; i++) {
if (list[i].contains(type)) {
string2file(file2string(src + File.separator + list[i]), des + File.separator + list[i]);
}
}
}
//--------------------------------------dir--------------------------------------------// //--------------------------------------dir--------------------------------------------//

View File

@ -180,7 +180,7 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
} }
if ( e.getSource() == goButton ) { if ( e.getSource() == goButton ) {
try { try {
logfile = new PrintWriter(new BufferedWriter(new FileWriter(startpath.replaceAll(Common.strseparate, "$1") + File.separator + "migration.log"))); logfile = new PrintWriter(new BufferedWriter(new FileWriter(startpath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + "migration.log")));
MigrationTool.startMigrateAll(startpath); MigrationTool.startMigrateAll(startpath);
logfile.flush(); logfile.flush();
logfile.close(); logfile.close();

View File

@ -31,7 +31,7 @@ public class MigrationTool {
private static final void mainFlow(ModuleInfo mi) throws Exception { private static final void mainFlow(ModuleInfo mi) throws Exception {
ModuleReader.ModuleScan(mi); ModuleReader.aimAt(mi);
//MigrationTool.ui.yesOrNo("go on replace?"); //MigrationTool.ui.yesOrNo("go on replace?");
SourceFileReplacer.fireAt(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"
@ -76,7 +76,7 @@ public class MigrationTool {
private static final String assignOutPutPath(String inputpath) { private static final String assignOutPutPath(String inputpath) {
if (MigrationTool.defaultoutput) { if (MigrationTool.defaultoutput) {
return inputpath.replaceAll(Common.strseparate, "$1"); return inputpath.replaceAll(Common.STRSEPARATER, "$1");
} else { } else {
return MigrationTool.ui.getFilepath("Please choose where to place the output module", JFileChooser.DIRECTORIES_ONLY); return MigrationTool.ui.getFilepath("Please choose where to place the output module", JFileChooser.DIRECTORIES_ONLY);
} }

View File

@ -34,6 +34,8 @@ public final class ModuleInfo {
public final Set<String> localmodulesources = new HashSet<String>(); //contains both .c and .h public final Set<String> localmodulesources = new HashSet<String>(); //contains both .c and .h
public final Set<String> preprocessedccodes = new HashSet<String>(); public final Set<String> preprocessedccodes = new HashSet<String>();
public final Set<String> msaorinf = new HashSet<String>(); //only a little, hash may be too big for this public final Set<String> msaorinf = new HashSet<String>(); //only a little, hash may be too big for this
public final Set<String> infincludes = new HashSet<String>();
public final Set<String> infsources = new HashSet<String>();
public final Set<String> hashfuncc = new HashSet<String>(); public final Set<String> hashfuncc = new HashSet<String>();
public final Set<String> hashfuncd = new HashSet<String>(); public final Set<String> hashfuncd = new HashSet<String>();

View File

@ -18,18 +18,19 @@ import java.util.regex.*;
import org.tianocore.*; import org.tianocore.*;
public final class ModuleReader { public final class ModuleReader implements Common.ForDoAll {
private static ModuleInfo mi; private static final ModuleReader modulereader = new ModuleReader();
private ModuleInfo mi;
private final CommentLaplace commentlaplace = new CommentLaplace();
private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)"); private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE); private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
private static final Pattern ptnfilename = Pattern.compile("[^\\s]+"); private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");
public static final void ModuleScan(ModuleInfo m) throws Exception { public final void ModuleScan() throws Exception {
mi = m;
Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll", String.class), mi, null, Common.FILE); Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll", String.class), mi, null, Common.FILE);
// inf&msa
String filename = null; String filename = null;
if (mi.msaorinf.isEmpty()) { if (mi.msaorinf.isEmpty()) {
MigrationTool.ui.println("No INF nor MSA file found!"); MigrationTool.ui.println("No INF nor MSA file found!");
@ -47,13 +48,12 @@ public final class ModuleReader {
} else if (filename.contains(".msa")) { } else if (filename.contains(".msa")) {
readMsa(filename); readMsa(filename);
} }
// inf&msa
CommentOutNonLocalHFile(); preProcessModule();
parsePreProcessedSourceCode();
} }
private static final void readMsa(String name) throws Exception { private final void readMsa(String name) throws Exception {
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name)); ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));
ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea(); ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();
MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader(); MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
@ -73,7 +73,7 @@ public final class ModuleReader {
} }
} }
private static final void readInf(String name) throws Exception { private final void readInf(String name) throws Exception {
System.out.println("\nParsing INF file: " + name); System.out.println("\nParsing INF file: " + name);
String wholeline; String wholeline;
Matcher mtrinfequation; Matcher mtrinfequation;
@ -113,48 +113,63 @@ public final class ModuleReader {
if (mtrsection.group(1).contains("sources.")) { if (mtrsection.group(1).contains("sources.")) {
mtrfilename = ptnfilename.matcher(mtrsection.group(2)); mtrfilename = ptnfilename.matcher(mtrsection.group(2));
while (mtrfilename.find()) { while (mtrfilename.find()) {
mi.infsources.add(mtrfilename.group());
if (!mi.localmodulesources.contains(mtrfilename.group())) { if (!mi.localmodulesources.contains(mtrfilename.group())) {
MigrationTool.ui.println("Source File Missing! : " + mtrfilename.group()); MigrationTool.ui.println("Warn: Source File Missing! : " + mtrfilename.group());
} }
} }
} }
if (mtrsection.group(1).matches("includes.common")) {
mtrfilename = ptnfilename.matcher(mtrsection.group(2));
while (mtrfilename.find()) {
mi.infincludes.add(mtrfilename.group());
}
}
} }
} }
// add '//' to all non-local include lines private final void preProcessModule() throws Exception {
private static final void CommentOutNonLocalHFile() throws IOException { // according to .inf file, add extraordinary includes and sourcefiles
BufferedReader rd; Common.dirCopy(mi.modulepath, mi.modulepath + File.separator + "temp");
String line;
String curFile; if (!mi.infincludes.isEmpty()) {
PrintWriter outfile; Iterator<String> it = mi.infincludes.iterator();
String tempincludename = null;
Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]"); while (it.hasNext()) {
Matcher mtrinclude; tempincludename = it.next();
if (tempincludename.contains("..")) {
Iterator<String> ii = mi.localmodulesources.iterator(); Matcher mtr = Common.PTNSEPARATER.matcher(tempincludename);
while ( ii.hasNext() ) { if (mtr.find() && !mtr.group(2).matches(".")) {
curFile = ii.next(); Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + mtr.group(2), mi.modulepath + File.separator + "temp", ".h");
rd = new BufferedReader(new FileReader(mi.modulepath + File.separator + curFile)); } else {
Common.ensureDir(mi.modulepath + File.separator + "temp" + File.separator + curFile); Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1"), mi.modulepath + File.separator + "temp", ".h");
outfile = new PrintWriter(new BufferedWriter(new FileWriter(mi.modulepath + File.separator + "temp" + File.separator + curFile))); }
}
while ((line = rd.readLine()) != null) { }
if (line.contains("#include")) { }
mtrinclude = ptninclude.matcher(line); if (!mi.infsources.isEmpty()) {
if (mtrinclude.find() && mi.localmodulesources.contains(mtrinclude.group(1))) { Iterator<String> it = mi.infsources.iterator();
} else { String tempsourcename = null;
line = MigrationTool.MIGRATIONCOMMENT + line; while (it.hasNext()) {
} tempsourcename = it.next();
} if (tempsourcename.contains("..")) {
outfile.append(line + '\n'); Common.ensureDir(mi.modulepath + File.separator + "temp" + File.separator + "MT_Parent_Sources");
Matcher mtr = Common.PTNSEPARATER.matcher(tempsourcename);
if (mtr.find()) {
Common.fileCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + mtr.group(2), mi.modulepath + File.separator + "temp" + File.separator + "MT_Parent_Sources" + File.separator + mtr.group(2));
}
}
} }
outfile.flush(); }
outfile.close();
//CommentOutNonLocalHFile();
} Common.toDoAll(mi.modulepath + File.separator + "temp", this, Common.FILE);
parsePreProcessedSourceCode();
} }
private static final void parsePreProcessedSourceCode() throws Exception { private final void parsePreProcessedSourceCode() throws Exception {
//Cl cl = new Cl(modulepath); //Cl cl = new Cl(modulepath);
//cl.execute("Fat.c"); //cl.execute("Fat.c");
//cl.generateAll(preprocessedccodes); //cl.generateAll(preprocessedccodes);
@ -263,4 +278,54 @@ public final class ModuleReader {
} }
} }
} }
public class CommentLaplace extends Common.Laplace {
public String operation(String wholeline) {
StringBuffer wholebuffer = new StringBuffer();
String templine = null;
Pattern ptnincludefile = Pattern.compile("[\"<](.*[.]h)[\">]");
Pattern ptninclude = Pattern.compile("#include\\s*(.*)");
Matcher mtrinclude = ptninclude.matcher(wholeline);
Matcher mtrincludefile = null;
while (mtrinclude.find()) {
mtrincludefile = ptnincludefile.matcher(mtrinclude.group(1));
if (mtrincludefile.find() && mi.localmodulesources.contains(mtrincludefile.group(1))) {
templine = mtrinclude.group();
} else {
templine = MigrationTool.MIGRATIONCOMMENT + mtrinclude.group();
}
mtrinclude.appendReplacement(wholebuffer, templine);
}
mtrinclude.appendTail(wholebuffer);
return wholebuffer.toString();
}
public boolean recognize(String filename) {
return filename.contains(".c") || filename.contains(".h");
}
public String namechange(String oldname) {
return oldname;
}
}
//-----------------------------------ForDoAll-----------------------------------//
public void run(String filepath) throws Exception {
String name = mi.modulepath + File.separator + "temp" + File.separator + filepath.replace(mi.modulepath + File.separator + "temp" + File.separator, "");
commentlaplace.transform(name, name);
}
public boolean filter(File dir) {
return true;
}
//-----------------------------------ForDoAll-----------------------------------//
public final void setModuleInfo(ModuleInfo m) {
mi = m;
}
public static final void aimAt(ModuleInfo mi) throws Exception {
modulereader.setModuleInfo(mi);
modulereader.ModuleScan();
}
} }

View File

@ -104,7 +104,6 @@ public final class SourceFileReplacer implements Common.ForDoAll {
private class CLaplace extends Common.Laplace { private class CLaplace extends Common.Laplace {
public String operation(String wholeline) { public String operation(String wholeline) {
boolean addr8 = false;
// remove EFI_DRIVER_ENTRY_POINT // remove EFI_DRIVER_ENTRY_POINT
wholeline = wholeline.replaceAll("(EFI_[A-Z]+_ENTRY_POINT\\s*\\(\\s*" + mi.entrypoint + "\\s*\\)\\s*;)", MigrationTool.MIGRATIONCOMMENT + " $1"); wholeline = wholeline.replaceAll("(EFI_[A-Z]+_ENTRY_POINT\\s*\\(\\s*" + mi.entrypoint + "\\s*\\)\\s*;)", MigrationTool.MIGRATIONCOMMENT + " $1");
// redefine module entry point for some self-relocated modules // redefine module entry point for some self-relocated modules
@ -390,7 +389,7 @@ public final class SourceFileReplacer implements Common.ForDoAll {
//-----------------------------------ForDoAll-----------------------------------// //-----------------------------------ForDoAll-----------------------------------//
public void run(String filepath) throws Exception { public void run(String filepath) throws Exception {
String inname = filepath.replace(mi.modulepath + File.separator, ""); String inname = filepath.replace(mi.modulepath + File.separator + "temp" + File.separator, "");
String tempinpath = mi.modulepath + File.separator + "temp" + File.separator; String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator; String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;
@ -418,7 +417,7 @@ public final class SourceFileReplacer implements Common.ForDoAll {
Laplaces.add(new CLaplace()); Laplaces.add(new CLaplace());
Laplaces.add(new IdleLaplace()); Laplaces.add(new IdleLaplace());
Common.toDoAll(mi.localmodulesources, this); Common.toDoAll(mi.modulepath + File.separator + "temp", this, Common.FILE);
if (!mi.hashr8only.isEmpty()) { if (!mi.hashr8only.isEmpty()) {
addr8only(); addr8only();