+/** @file\r
+ \r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+ \r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ \r
+ **/\r
package org.tianocore.migration;\r
\r
import java.io.*;\r
public String entrypoint = null;\r
\r
public Set<String> localmodulesources = new HashSet<String>(); //contains both .c and .h\r
- public Set<String> localmoduleheaders = new HashSet<String>();\r
public Set<String> preprocessedccodes = new HashSet<String>();\r
+ public Set<String> msaorinf = new HashSet<String>(); //only a little, hash may be too big for this\r
\r
public Set<String> hashfuncc = new HashSet<String>();\r
public Set<String> hashfuncd = new HashSet<String>();\r
\r
private static String migrationcomment = "//%$//";\r
\r
- private void moduleScan() throws Exception {\r
- String[] list = new File(modulepath).list();\r
- boolean hasInf = false;\r
- String infname = null;\r
- boolean hasMsa = false;\r
- String msaname = null;\r
+ private void dirScan(String subpath) throws Exception {\r
+ String[] list = new File(modulepath + File.separator + subpath).list(); // if no sub , separator need?\r
+ File test;\r
\r
for (int i = 0 ; i < list.length ; i++) {\r
- if (new File(list[i]).isDirectory()) {\r
- ;\r
+ test = new File(modulepath + File.separator + subpath + list[i]);\r
+ if (test.isDirectory()) {\r
+ if (list[i].contains("result") || list[i].contains("temp")) {\r
+ } else {\r
+ dirScan(subpath + list[i] + File.separator);\r
+ }\r
} else {\r
- if (list[i].contains(".c") || list[i].contains(".C")) {\r
- localmodulesources.add(list[i]);\r
- } else if (list[i].contains(".h") || list[i].contains(".H")) {\r
- localmodulesources.add(list[i]);\r
- localmoduleheaders.add(list[i]); //the case that several .inf or .msa found is not concerned\r
- } else if (list[i].contains(".inf")) {\r
- if (ui.yesOrNo("Found .inf file : " + list[i] + "\nUse this file as this module's .inf ?")) {\r
- hasInf = true;\r
- infname = list[i];\r
- } else {\r
- continue;\r
- }\r
- } else if (list[i].contains(".msa")) {\r
- if (ui.yesOrNo("Found .msa file : " + list[i] + "\nUse this file as this module's .msa ?")) {\r
- hasMsa = true;\r
- msaname = list[i];\r
- } else {\r
- continue;\r
- }\r
+ if (list[i].contains(".c") || list[i].contains(".C") || list[i].contains(".h") || \r
+ list[i].contains(".H") || list[i].contains(".dxs") || list[i].contains(".uni")) {\r
+ localmodulesources.add(subpath + list[i]);\r
+ } else if (list[i].contains(".inf") || list[i].contains(".msa")) {\r
+ msaorinf.add(subpath + list[i]);\r
}\r
}\r
}\r
- \r
- ModuleReader mr = new ModuleReader(modulepath, this, db);\r
- if (hasInf) { // this sequence shows using .inf as default\r
- mr.readInf(infname);\r
- } else if (hasMsa) {\r
- mr.readMsa(msaname);\r
+ }\r
+ \r
+ private void moduleScan() throws Exception {\r
+ dirScan("");\r
+ String filename = null;\r
+ if (msaorinf.isEmpty()) {\r
+ ui.println("No INF nor MSA file found!");\r
+ System.exit(0);\r
} else {\r
- ui.println("No Inf Nor Msa Found");\r
+ filename = ui.choose("Found .inf or .msa file in the module\nChoose one Please", msaorinf.toArray());\r
+ }\r
+ ModuleReader mr = new ModuleReader(modulepath, this, db, ui);\r
+ if (filename.contains(".inf")) {\r
+ mr.readInf(filename);\r
+ } else if (filename.contains(".msa")) {\r
+ mr.readMsa(filename);\r
}\r
\r
CommentOutNonLocalHFile();\r
new SourceFileReplacer(modulepath, this, db, ui).flush(); // some adding library actions are taken here,so it must be put before "MsaWriter"\r
\r
// show result\r
- if (ui.yesOrNo("Parse Module Information Complete . See details ?")) {\r
+ if (ui.yesOrNo("Parse of the Module Information has completed. View details?")) {\r
ui.println("\nModule Information : ");\r
ui.println("Entrypoint : " + entrypoint);\r
show(protocol, "Protocol : ");\r
\r
ui.println("Errors Left : " + db.error);\r
ui.println("Complete!");\r
- ui.println("Your R9 module is placed at " + modulepath + File.separator + "result");\r
- ui.println("Your logfile is placed at " + modulepath);\r
+ ui.println("Your R9 module was placed here: " + modulepath + File.separator + "result");\r
+ ui.println("Your logfile was placed here: " + modulepath);\r
}\r
\r
private void show(Set<String> hash, String show) {\r
ui.println(show + hash.size());\r
ui.println(hash);\r
}\r
-\r
+ \r
// add '//' to all non-local include lines\r
private void CommentOutNonLocalHFile() throws IOException {\r
BufferedReader rd;\r
PrintWriter outfile;\r
\r
Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");\r
- Matcher mtcinclude;\r
- \r
- File tempdir = new File(modulepath + File.separator + "temp" + File.separator);\r
- if (!tempdir.exists()) tempdir.mkdir();\r
+ Matcher mtrinclude;\r
\r
Iterator<String> ii = localmodulesources.iterator();\r
while ( ii.hasNext() ) {\r
curFile = ii.next();\r
rd = new BufferedReader(new FileReader(modulepath + File.separator + curFile));\r
+ Common.ensureDir(modulepath + File.separator + "temp" + File.separator + curFile);\r
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "temp" + File.separator + curFile)));\r
while ((line = rd.readLine()) != null) {\r
if (line.contains("#include")) {\r
- mtcinclude = ptninclude.matcher(line);\r
- if (mtcinclude.find() && localmoduleheaders.contains(mtcinclude.group(1))) {\r
+ mtrinclude = ptninclude.matcher(line);\r
+ if (mtrinclude.find() && localmodulesources.contains(mtrinclude.group(1))) {\r
} else {\r
line = migrationcomment + line;\r
}\r
outfile.close();\r
}\r
}\r
- /*\r
- private void search(String line, Pattern ptn, Method md) {\r
- matmacro = Func.ptntmacro.matcher(line);\r
- while (matmacro.find()) {\r
- if ((temp = Func.registerMacro(matmacro, this, db)) != null) {\r
- }\r
- }\r
- }\r
- */\r
+\r
private void parsePreProcessedSourceCode() throws Exception {\r
//Cl cl = new Cl(modulepath);\r
//cl.execute("Fat.c");\r
//System.out.println("Note!!!! The CL is not implemented now , pls do it manually!!! RUN :");\r
//System.out.println("cl " + modulepath + "\\temp\\*.c" + " -P");\r
//String[] list = new File(modulepath + File.separator + "temp").list(); // without CL , add\r
- String[] list = new File(modulepath).list();\r
- for (int i = 0 ; i < list.length ; i++) {\r
- if (list[i].contains(".c")) { // without CL , change to .i\r
- preprocessedccodes.add(list[i]);\r
- }\r
- }\r
- //\r
- Iterator<String> ii = preprocessedccodes.iterator();\r
BufferedReader rd = null;\r
String ifile = null;\r
String line = null;\r
String temp = null;\r
- //StringBuffer result = new StringBuffer();\r
+ \r
+ Iterator<String> ii = localmodulesources.iterator();\r
+ while (ii.hasNext()) {\r
+ temp = ii.next();\r
+ if (temp.contains(".c")) {\r
+ preprocessedccodes.add(temp);\r
+ }\r
+ }\r
+ \r
+ ii = preprocessedccodes.iterator();\r
\r
Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE);\r
Pattern patentrypoint = Pattern.compile("EFI_([A-Z]*)_ENTRY_POINT\\s*\\(([^\\(\\)]*)\\)",Pattern.MULTILINE);\r