import java.util.regex.Matcher;\r
import java.util.regex.Pattern;\r
\r
-public final class SourceFileReplacer {\r
- private static ModuleInfo mi;\r
- private static boolean showdetails = false;\r
+public final class SourceFileReplacer implements Common.ForDoAll {\r
+ private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();\r
+ private ModuleInfo mi;\r
+ private static boolean showdetails = true; // set this as default now, may be changed in the future\r
\r
private static class r8tor9 {\r
r8tor9(String r8, String r9) {\r
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();\r
private static final Set<String> filer8only = new HashSet<String>();\r
\r
- public static final void flush(ModuleInfo moduleinfo) throws Exception {\r
- mi = moduleinfo;\r
- \r
- String outname = null;\r
- String inname = null;\r
-\r
- showdetails = true; // set this as default now, may be changed in the future\r
- \r
- Iterator<String> di = mi.localmodulesources.iterator();\r
- String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;\r
- String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;\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
- MigrationTool.ui.println("\nModifying file: " + inname);\r
- Common.string2file(sourcefilereplace(Common.file2string(tempinpath + inname)), tempoutpath + outname);\r
- } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".uni")) {\r
- if (inname.contains(".H")) {\r
- outname = inname.replaceFirst(".H", ".h");\r
- } else {\r
- outname = inname;\r
- }\r
- MigrationTool.ui.println("\nCopying file: " + inname);\r
- Common.string2file(Common.file2string(tempinpath + inname), tempoutpath + outname);\r
- } else if (inname.contains(".dxs")) {\r
- outname = inname;\r
- MigrationTool.ui.println("\nModifying file: " + inname);\r
- Common.string2file(convertdxs(Common.file2string(tempinpath + inname)), tempoutpath + outname);\r
- }\r
- }\r
-\r
- if (!mi.hashr8only.isEmpty()) {\r
- addr8only();\r
- }\r
- }\r
- \r
private static final String addincludefile(String wholeline, String hfile) {\r
return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n");\r
}\r
\r
- private static final String convertdxs(String wholeline) {\r
+ private final String convertdxs(String wholeline) {\r
if (mi.getModuleType().equals("PEIM")) {\r
return addincludefile(wholeline, "\\<PeimDepex.h\\>");\r
} else {\r
}\r
}\r
\r
- private static final void addr8only() throws Exception {\r
+ private final void addr8only() throws Exception {\r
String paragraph = null;\r
String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");\r
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));\r
}\r
\r
// Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you!\r
- private static final String sourcefilereplace(String wholeline) throws Exception {\r
+ private final String sourcefilereplace(String wholeline) throws Exception {\r
boolean addr8 = false;\r
\r
Pattern pat = Pattern.compile("g?(BS|RT)(\\s*->\\s*)([a-zA-Z_]\\w*)", Pattern.MULTILINE); // ! only two level () bracket allowed !\r
}\r
}\r
}\r
+ \r
+ //-----------------------------------ForDoAll-----------------------------------//\r
+ public void run(String filepath) throws Exception {\r
+ String outname = null;\r
+ String inname = filepath.replace(mi.modulepath + File.separator, "");\r
+ String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;\r
+ String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;\r
+\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
+ MigrationTool.ui.println("\nModifying file: " + inname);\r
+ Common.string2file(sourcefilereplace(Common.file2string(tempinpath + inname)), tempoutpath + outname);\r
+ } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".uni")) {\r
+ if (inname.contains(".H")) {\r
+ outname = inname.replaceFirst(".H", ".h");\r
+ } else {\r
+ outname = inname;\r
+ }\r
+ MigrationTool.ui.println("\nCopying file: " + inname);\r
+ Common.string2file(Common.file2string(tempinpath + inname), tempoutpath + outname);\r
+ } else if (inname.contains(".dxs")) {\r
+ outname = inname;\r
+ MigrationTool.ui.println("\nModifying file: " + inname);\r
+ Common.string2file(convertdxs(Common.file2string(tempinpath + inname)), tempoutpath + outname);\r
+ }\r
+ }\r
+ \r
+ public boolean dirFilter(String filepath) {\r
+ return true;\r
+ }\r
+ \r
+ public boolean fileFilter(String filepath) {\r
+ return true;\r
+ }\r
+ //-----------------------------------ForDoAll-----------------------------------//\r
+ \r
+ private final void setModuleInfo(ModuleInfo moduleinfo) {\r
+ mi = moduleinfo;\r
+ }\r
+ \r
+ private final void start() throws Exception {\r
+ Common.toDoAll(mi.localmodulesources, this);\r
+ \r
+ if (!mi.hashr8only.isEmpty()) {\r
+ addr8only();\r
+ }\r
+ }\r
+ \r
+ public static final void fireAt(ModuleInfo moduleinfo) throws Exception {\r
+ SFReplacer.setModuleInfo(moduleinfo);\r
+ SFReplacer.start();\r
+ }\r
}\r