\r
public Set<String> localmodulesources = new HashSet<String>(); //contains both .c and .h\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]); //the case that several .inf or .msa found is not concerned\r
- } else if (list[i].contains(".dxs")) {\r
- localmodulesources.add(list[i]);\r
- } else if (list[i].contains(".uni")) {\r
- localmodulesources.add(list[i]);\r
- } else if (list[i].contains(".inf")) {\r
- if (ui.yesOrNo("Found .inf file : " + list[i] + "\nDo you want to use 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] + "\nDo you want to use 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! Tool Halt!");\r
+ System.exit(0);\r
} else {\r
- ui.println("No INF nor MSA file 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);\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 of the Module Information has completed. View details?")) {\r
+ if (ui.yesOrNo("Parse Module Information Complete . See 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 was placed here: " + modulepath + File.separator + "result");\r
- ui.println("Your logfile was placed here: " + modulepath);\r
+ ui.println("Your R9 module is placed at " + modulepath + File.separator + "result");\r
+ ui.println("Your logfile is placed at " + modulepath);\r
}\r
\r
private void show(Set<String> hash, String show) {\r
ui.println(hash);\r
}\r
\r
+ public void ensureDir(String objFileWhole) {\r
+ Pattern ptnseparate = Pattern.compile("(.*)\\\\[^\\\\]*");\r
+ Matcher mtrseparate;\r
+ File tempdir;\r
+\r
+ mtrseparate = ptnseparate.matcher(objFileWhole);\r
+ if (mtrseparate.find()) {\r
+ tempdir = new File(mtrseparate.group(1));\r
+ if (!tempdir.exists()) tempdir.mkdirs();\r
+ }\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
+ 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() && localmodulesources.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
public static void main(String[] args) throws Exception {\r
FirstPanel.init();\r
}\r
-}\r
+}
\ No newline at end of file
"EfiLibInstallAllDriverProtocols " +\r
"EfiLibCompareLanguage " +\r
"BufToHexString " +\r
- "EfiStrTrim " +\r
+ "EfiStrTrim " + //is the r8only lib going to be enlarged???? Caution !!!!\r
"EfiValueToHexStr " +\r
"HexStringToBuf " +\r
"IsHexDigit " +\r
\r
public void flush() throws Exception {\r
PrintWriter outfile;\r
- String temp = null;\r
- if (ui.yesOrNo("Changes will be made to the Source Code. View details?")) {\r
+ String outname = null;\r
+ String inname = null;\r
+ if (ui.yesOrNo("Change Source Code is to be doing . See details ?")) {\r
showdetails = true;\r
}\r
- File tempdir = new File(modulepath + File.separator + "result" + File.separator);\r
- if (!tempdir.exists()) tempdir.mkdir();\r
- String[] list = new File(modulepath + File.separator + "temp").list(); //what I change is the non-local .h commented-out files\r
- for (int i = 0 ; i < list.length ; i++) {\r
- if (list[i].contains(".c")) {\r
- ui.println("\nModifying file: " + list[i]);\r
- outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + list[i])));\r
- outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + list[i]));\r
+ \r
+ Iterator<String> di = mi.localmodulesources.iterator();\r
+ while (di.hasNext()) {\r
+ inname = di.next();\r
+ if (inname.contains(".c") || inname.contains(".C")) {\r
+ if (inname.contains(".C")) {\r
+ outname = inname.replaceFirst(".C", ".c");\r
+ } else {\r
+ outname = inname;\r
+ }\r
+ ui.println("\nModifying file : " + inname);\r
+ mi.ensureDir(modulepath + File.separator + "result" + File.separator + outname);\r
+ outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));\r
+ outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname));\r
outfile.flush();\r
outfile.close();\r
- } else {\r
- if (list[i].contains(".h")) {\r
- temp = list[i];\r
- } else if (list[i].contains(".C")) {\r
- temp = list[i].replaceFirst(".C", ".c");\r
- } else if (list[i].contains(".H")) {\r
- temp = list[i].replaceFirst(".H", ".h");\r
+ } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {\r
+ if (inname.contains(".H")) {\r
+ outname = inname.replaceFirst(".H", ".h");\r
} else {\r
- continue;\r
+ outname = inname;\r
}\r
- ui.println("\nCopying file: " + temp);\r
- outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + temp)));\r
- outfile.append(sourcefiletostring(modulepath + File.separator + "temp" + File.separator + list[i]));\r
+ ui.println("\nCopying file : " + inname);\r
+ mi.ensureDir(modulepath + File.separator + "result" + File.separator + outname);\r
+ outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));\r
+ outfile.append(sourcefiletostring(modulepath + File.separator + "temp" + File.separator + inname));\r
outfile.flush();\r
outfile.close();\r
}\r
private void addr8only() throws Exception {\r
String paragraph = null;\r
String line = sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c");\r
+ mi.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");\r
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.c")));\r
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.h")));\r
- //outfile1.append("#include \"R8Lib.h\"\n\n");\r
- //outfile2.append("#include \"R8Lib.h\"\n\n");\r
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL);\r
Matcher mtrr8only = ptnr8only.matcher(line);\r
Matcher mtrr8onlyhead;\r
outfile1.close();\r
outfile2.flush();\r
outfile2.close();\r
+ \r
+ mi.localmodulesources.add("R8Lib.h");\r
+ mi.localmodulesources.add("R8Lib.c");\r
}\r
\r
private String sourcefiletostring(String filename) throws Exception {\r
// replace BS -> gBS , RT -> gRT\r
Matcher mat = pat.matcher(line);\r
if (mat.find()) { // add a library here\r
- ui.println("Converting all BS->gBS, RT->gRT");\r
+ ui.println("Converting all BS->gBS,RT->gRT");\r
line = mat.replaceAll("g$1$2$3"); //unknown correctiveness\r
}\r
mat.reset();\r
while (rt.hasNext()) {\r
temp = rt.next();\r
if (r8only.contains(temp.r8thing)) {\r
- mi.localmodulesources.add("R8Lib.h");\r
- mi.localmodulesources.add("R8Lib.c");\r
filer8only.add(r8thing);\r
mi.hashr8only.add(r8thing);\r
addr8 = true;\r
fileppi.clear();\r
fileprotocol.clear();\r
filer8only.clear();\r
- \r
+\r
return line;\r
}\r
\r