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

View File

@ -180,7 +180,7 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
}
if ( e.getSource() == goButton ) {
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);
logfile.flush();
logfile.close();

View File

@ -31,7 +31,7 @@ public class MigrationTool {
private static final void mainFlow(ModuleInfo mi) throws Exception {
ModuleReader.ModuleScan(mi);
ModuleReader.aimAt(mi);
//MigrationTool.ui.yesOrNo("go on replace?");
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) {
if (MigrationTool.defaultoutput) {
return inputpath.replaceAll(Common.strseparate, "$1");
return inputpath.replaceAll(Common.STRSEPARATER, "$1");
} else {
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> 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> infincludes = new HashSet<String>();
public final Set<String> infsources = new HashSet<String>();
public final Set<String> hashfuncc = new HashSet<String>();
public final Set<String> hashfuncd = new HashSet<String>();

View File

@ -18,18 +18,19 @@ import java.util.regex.*;
import org.tianocore.*;
public final class ModuleReader {
private static ModuleInfo mi;
public final class ModuleReader implements Common.ForDoAll {
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 ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");
public static final void ModuleScan(ModuleInfo m) throws Exception {
mi = m;
public final void ModuleScan() throws Exception {
Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll", String.class), mi, null, Common.FILE);
// inf&msa
String filename = null;
if (mi.msaorinf.isEmpty()) {
MigrationTool.ui.println("No INF nor MSA file found!");
@ -47,13 +48,12 @@ public final class ModuleReader {
} else if (filename.contains(".msa")) {
readMsa(filename);
}
// inf&msa
CommentOutNonLocalHFile();
parsePreProcessedSourceCode();
preProcessModule();
}
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.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();
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);
String wholeline;
Matcher mtrinfequation;
@ -113,48 +113,63 @@ public final class ModuleReader {
if (mtrsection.group(1).contains("sources.")) {
mtrfilename = ptnfilename.matcher(mtrsection.group(2));
while (mtrfilename.find()) {
mi.infsources.add(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 static final void CommentOutNonLocalHFile() throws IOException {
BufferedReader rd;
String line;
String curFile;
PrintWriter outfile;
Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");
Matcher mtrinclude;
Iterator<String> ii = mi.localmodulesources.iterator();
while ( ii.hasNext() ) {
curFile = ii.next();
rd = new BufferedReader(new FileReader(mi.modulepath + File.separator + curFile));
Common.ensureDir(mi.modulepath + File.separator + "temp" + File.separator + curFile);
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 (mtrinclude.find() && mi.localmodulesources.contains(mtrinclude.group(1))) {
} else {
line = MigrationTool.MIGRATIONCOMMENT + line;
}
}
outfile.append(line + '\n');
private final void preProcessModule() throws Exception {
// according to .inf file, add extraordinary includes and sourcefiles
Common.dirCopy(mi.modulepath, mi.modulepath + File.separator + "temp");
if (!mi.infincludes.isEmpty()) {
Iterator<String> it = mi.infincludes.iterator();
String tempincludename = null;
while (it.hasNext()) {
tempincludename = it.next();
if (tempincludename.contains("..")) {
Matcher mtr = Common.PTNSEPARATER.matcher(tempincludename);
if (mtr.find() && !mtr.group(2).matches(".")) {
Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + mtr.group(2), mi.modulepath + File.separator + "temp", ".h");
} else {
Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1"), mi.modulepath + File.separator + "temp", ".h");
}
}
}
}
if (!mi.infsources.isEmpty()) {
Iterator<String> it = mi.infsources.iterator();
String tempsourcename = null;
while (it.hasNext()) {
tempsourcename = it.next();
if (tempsourcename.contains("..")) {
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.execute("Fat.c");
//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 {
public String operation(String wholeline) {
boolean addr8 = false;
// remove EFI_DRIVER_ENTRY_POINT
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
@ -390,7 +389,7 @@ public final class SourceFileReplacer implements Common.ForDoAll {
//-----------------------------------ForDoAll-----------------------------------//
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 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 IdleLaplace());
Common.toDoAll(mi.localmodulesources, this);
Common.toDoAll(mi.modulepath + File.separator + "temp", this, Common.FILE);
if (!mi.hashr8only.isEmpty()) {
addr8only();