Many Many Modifies

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1331 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
alfred 2006-08-21 06:45:23 +00:00
parent 4436ffdcd9
commit 5ea254f612
8 changed files with 277 additions and 134 deletions

View File

@ -15,11 +15,30 @@ package org.tianocore.migration;
import java.io.*;
import java.util.regex.*;
import java.util.*;
import java.lang.reflect.*;
public class Common {
public static Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)");
public final class Common {
public static final int BOTH = 0;
public static final int FILE = 1;
public static final int DIR = 2;
public static String file2string(String filename) throws Exception {
public static final Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)");
//-------------------------------------regex------------------------------------------//
public static final String replaceAll(String line, Pattern ptn, String des) {
Matcher mtr = ptn.matcher(line);
if (mtr.find()) {
return mtr.replaceAll(des);
}
return line;
}
//-------------------------------------regex------------------------------------------//
//-----------------------------------file&string---------------------------------------//
public static final String file2string(String filename) throws Exception {
BufferedReader rd = new BufferedReader(new FileReader(filename));
StringBuffer wholefile = new StringBuffer();
String line;
@ -29,7 +48,7 @@ public class Common {
return wholefile.toString();
}
public static void string2file(String content, String filename) throws Exception {
public static final void string2file(String content, String filename) throws Exception {
ensureDir(filename);
PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
outfile.append(content);
@ -37,7 +56,11 @@ public class Common {
outfile.close();
}
public static void ensureDir(String objFileWhole) {
//-----------------------------------file&string---------------------------------------//
//--------------------------------------dir--------------------------------------------//
public static final void ensureDir(String objFileWhole) {
File tempdir;
Matcher mtrseparate = ptnseparate.matcher(objFileWhole);
if (mtrseparate.find()) {
@ -46,32 +69,21 @@ public class Common {
}
}
public static HashSet<String> dirScan(String path) { // use HashSet, persue speed rather than space
HashSet<String> filelist = new HashSet<String>();
String[] list = new File(path).list();
File test;
public static final void deleteDir(String objFileWhole) {
String[] list = new File(objFileWhole).list();
File temp;
for (int i = 0 ; i < list.length ; i++) {
test = new File(path + File.separator + list[i]);
if (test.isDirectory()) {
dirScan(path + File.separator + list[i]);
temp = new File(objFileWhole + File.separator + list[i]);
if (temp.isDirectory()) {
deleteDir(objFileWhole + File.separator + list[i]);
} else {
filelist.add(path + File.separator + list[i]);
temp.delete();
}
}
return filelist;
}
public static String replaceAll(String line, Pattern ptn, String des) {
Matcher mtr = ptn.matcher(line);
if (mtr.find()) {
return mtr.replaceAll(des);
}
return line;
new File(objFileWhole).delete();
}
public static String dirCopy_(String src) throws Exception {
public static final String dirCopy_(String src) throws Exception {
Matcher mtrseparate = Common.ptnseparate.matcher(src);
if (mtrseparate.find()) {
dirCopy(src, mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2));
@ -79,7 +91,7 @@ public class Common {
return mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2);
}
public static void dirCopy(String src, String des) throws Exception {
public static final void dirCopy(String src, String des) throws Exception {
String[] list = new File(src).list();
File test;
@ -93,6 +105,36 @@ public class Common {
}
}
}
//--------------------------------------dir--------------------------------------------//
//-------------------------------like python walk-----------------------------------------//
public static final void toDoAll(String path, Method md, Object obj, Object[] args, int type) throws Exception {
String[] list = new File(path).list();
ArrayList<Object> _args = new ArrayList<Object>();
_args.add(path);
if (args != null) {
for (int i = 0; i < args.length; i++) {
_args.add(args[i]);
}
}
if (type == DIR || type == BOTH) {
md.invoke(obj, _args.toArray());
}
for (int i = 0 ; i < list.length ; i++) {
if (new File(path + File.separator + list[i]).isDirectory()) {
toDoAll(path + File.separator + list[i], md, obj, args, type);
} else {
if (type == FILE || type == BOTH) {
_args.set(0, path + File.separator + list[i]);
md.invoke(obj, _args.toArray());
}
}
}
}
public static void toDoAll(String path, ForDoAll fda) throws Exception { // filter of file type can be done in toDo
String[] list = new File(path).list();

View File

@ -15,23 +15,23 @@ package org.tianocore.migration;
import java.util.regex.*;
import java.io.*;
public class Critic implements Common.ForDoAll {
public class Critic {
private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);
private static Pattern ptnfunccomment = Pattern.compile("([\\};\\/]\\s*)([\\w\\s]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/(\\s*.*?)([\\{;])",Pattern.DOTALL);
//private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);
private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*-\\s*(.*)\\s*");
private static Matcher mtrinfequation;
private static Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");
private static Matcher mtrcommentequation;
private static Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");
private static Matcher mtrnewcomment;
public void toDo(String filepath) throws Exception {
private static final int totallinelength = 82;
public static final void critic(String filepath) throws Exception {
if (filepath.contains(".c") || filepath.contains(".h")) {
BufferedReader rd = null;
String line = null;
StringBuffer templine = new StringBuffer();
boolean incomment = false;
boolean description = false;
boolean arguments = false;
boolean returns = false;
boolean inequation = false;
System.out.println("Criticing " + filepath);
String wholeline = Common.file2string(filepath);
@ -40,7 +40,12 @@ public class Critic implements Common.ForDoAll {
wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");
wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1/**$3**/$4$2$5");
//wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
// first scan
boolean description = false;
boolean arguments = false;
boolean returns = false;
boolean inequation = false;
rd = new BufferedReader(new StringReader(wholeline));
while ((line = rd.readLine()) != null) {
if (line.matches("\\/\\*\\*")) {
@ -62,30 +67,103 @@ public class Critic implements Common.ForDoAll {
arguments = false;
returns = true;
} else if (incomment && description) {
templine.append(line + "\n");
templine.append(" " + line.trim() + "\n");
} else if (incomment && arguments) {
mtrinfequation = ptninfequation.matcher(line);
if (mtrinfequation.find()) {
mtrcommentequation = ptncommentequation.matcher(line);
if (mtrcommentequation.find()) {
inequation = true;
templine.append(" @param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");
templine.append(" @param " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
} else if (inequation && line.trim().length() == 0) {
inequation = false;
templine.append(line + "\n");
} else if (inequation && line.trim().length() != 0) {
templine.append("#%#%" + line + "\n");
} else {
templine.append(line + "\n");
templine.append(" " + line.trim() + "\n");
}
} else if (incomment && returns) {
mtrinfequation = ptninfequation.matcher(line);
if (mtrinfequation.find()) {
mtrcommentequation = ptncommentequation.matcher(line);
if (mtrcommentequation.find()) {
inequation = true;
templine.append(" @retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");
templine.append(" @retval " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
} else if (inequation && line.trim().length() == 0) {
inequation = false;
templine.append(line + "\n");
} else if (inequation && line.trim().length() != 0) {
templine.append("#%#%" + line + "\n");
} else {
templine.append(" " + line.trim() + "\n");
}
} else {
templine.append(line + "\n");
}
}
wholeline = templine.toString();
wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");
//
// secend scan
int startmax = 0;
rd = new BufferedReader(new StringReader(wholeline));
while ((line = rd.readLine()) != null) {
if (line.matches("\\/\\*\\*")) {
incomment = true;
templine.append(line + "\n");
} else if (line.matches("\\*\\*\\/")) {
incomment = false;
templine.append(line + "\n");
} else if (incomment) {
mtrnewcomment = ptnnewcomment.matcher(line);
if (mtrnewcomment.find()) {
startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment.group(1).length() : startmax;
}
}
}
startmax++;
//
// third scan
int n = 0;
String temp = null;
String[] tempcont = null;
int count = 0;
templine = new StringBuffer();
rd = new BufferedReader(new StringReader(wholeline));
while ((line = rd.readLine()) != null) {
if (line.matches("\\/\\*\\*")) {
incomment = true;
templine.append(line + "\n");
} else if (line.matches("\\*\\*\\/")) {
incomment = false;
templine.append(line + "\n");
} else if (incomment) {
mtrnewcomment = ptnnewcomment.matcher(line);
if (mtrnewcomment.find()) {
n = startmax - mtrnewcomment.group(1).length();
templine.append(mtrnewcomment.group(1));
while (n-- >= 0) {
templine.append(" ");
}
temp = mtrnewcomment.group(3);
tempcont = temp.split(" "); // use \\s+ ?
count = 0;
for (int i = 0; i < tempcont.length; i++) {
count += tempcont[i].length();
if (count <= (totallinelength - startmax)) {
templine.append(tempcont[i] + " ");
count += 1;
} else {
templine.append("\n");
n = startmax;
while (n-- >= 0) {
templine.append(" ");
}
templine.append(tempcont[i] + " ");
count = tempcont[i].length() + 1;
}
}
templine.append("\n");
} else {
templine.append(line + "\n");
}
@ -94,7 +172,7 @@ public class Critic implements Common.ForDoAll {
}
}
wholeline = templine.toString();
wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");
//
/* -----slow edition of replacefirst with stringbuffer-----
line.append(wholeline);
@ -123,9 +201,9 @@ public class Critic implements Common.ForDoAll {
}
}
public static void fireAt(String path) throws Exception {
Critic critic = new Critic();
Common.toDoAll(Common.dirCopy_(path), critic);
public static final void fireAt(String path) throws Exception {
Common.toDoAll(Common.dirCopy_(path), Critic.class.getMethod("critic", String.class), null, null, Common.FILE);
//Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);
System.out.println("Critic Done");
}
}

View File

@ -18,7 +18,7 @@ import java.io.*;
import java.util.*;
import javax.swing.*;
public class FirstPanel extends JPanel implements ActionListener, UI {
public final class FirstPanel extends JPanel implements ActionListener, UI {
/**
* Define class Serial Version UID
*/
@ -61,7 +61,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
modulePanel.add(filebox);
modulePanel.add(screenbox);
modulePanel.add(goButton);
modulePanel.add(msaEditorButton);
//modulePanel.add(msaEditorButton);
modulePanel.add(criticButton);
add(modulePanel);
@ -115,21 +115,34 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
//---------------------------------------------------------------------------------------//
public String getFilepath() {
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
log.append(fc.getSelectedFile().getAbsolutePath() + "\n");
return fc.getSelectedFile().getAbsolutePath();
}
return null;
}
//---------------------------------------------------------------------------------------//
public void actionPerformed(ActionEvent e) {
if ( e.getSource() == moduleButton ) {
modulepath = getFilepath();
/*
int ret = fc.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
modulepath = fc.getSelectedFile().getAbsolutePath();
moduletext.setText(modulepath);
log.append("ModulePath: " + modulepath + "\n");
}
*/
}
if ( e.getSource() == goButton ) {
try {
logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));
println("Project MsaGen");
println("Copyright (c) 2006, Intel Corporation");
mi = new ModuleInfo(modulepath, this, new Database());
Common.toDoAll(modulepath, ModuleInfo.class.getMethod("seekModule", String.class), null, null, Common.DIR);
logfile.flush();
} catch (Exception en) {
println(en.getMessage());
@ -159,7 +172,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
//---------------------------------------------------------------------------------------//
public static void init() throws Exception {
public static FirstPanel init() throws Exception {
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
@ -178,5 +191,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
frame.pack();
frame.setVisible(true);
return fp;
}
}

View File

@ -21,16 +21,24 @@ import java.util.regex.*;
information and all the temporary data.
*/
public class ModuleInfo {
ModuleInfo(String modulepath, UI ui, Database db) throws Exception {
ModuleInfo(String modulepath) throws Exception {
this.modulepath = modulepath;
this.ui = ui;
this.db = db;
ui.println("Choose where to place the result");
if ((outputpath = ui.getFilepath()) == null) {
outputpath = modulepath;
}
ui.println(outputpath);
moduleScan();
}
private static UI ui = null; //if MIM is still usefull, this can be given to it
private static Database db = null; //if MIM is still usefull, this can be given to it
private String modulepath = null;
private Database db = null;
private UI ui = null;
public String modulepath = null;
public String outputpath = null;
public String modulename = null;
public String guidvalue = null;
@ -55,48 +63,27 @@ public class ModuleInfo {
private static String migrationcomment = "//%$//";
private void dirScan(String subpath) throws Exception {
String[] list = new File(modulepath + File.separator + subpath).list(); // if no sub , separator need?
File test;
for (int i = 0 ; i < list.length ; i++) {
test = new File(modulepath + File.separator + subpath + list[i]);
if (test.isDirectory()) {
if (list[i].contains("result") || list[i].contains("temp")) {
} else {
dirScan(subpath + list[i] + File.separator);
}
} else {
if (list[i].contains(".c") || list[i].contains(".C") || list[i].contains(".h") ||
list[i].contains(".H") || list[i].contains(".dxs") || list[i].contains(".uni")) {
localmodulesources.add(subpath + list[i]);
} else if (list[i].contains(".inf") || list[i].contains(".msa")) {
msaorinf.add(subpath + list[i]);
}
}
}
}
private void moduleScan() throws Exception {
dirScan("");
Common.toDoAll(modulepath, ModuleInfo.class.getMethod("enroll", String.class), this, null, Common.FILE);
String filename = null;
if (msaorinf.isEmpty()) {
ui.println("No INF nor MSA file found!");
System.exit(0);
} else {
filename = ui.choose("Found .inf or .msa file in the module\nChoose one Please", msaorinf.toArray());
filename = ui.choose("Found .inf or .msa file for module\n" + modulepath + "\nChoose one Please", msaorinf.toArray());
}
ModuleReader mr = new ModuleReader(modulepath, this, db, ui);
//ModuleReader mr = new ModuleReader(modulepath, this, db, ui);
if (filename.contains(".inf")) {
mr.readInf(filename);
ModuleReader.readInf(filename, this);
} else if (filename.contains(".msa")) {
mr.readMsa(filename);
ModuleReader.readMsa(filename, this);
}
CommentOutNonLocalHFile();
parsePreProcessedSourceCode();
new SourceFileReplacer(modulepath, this, db, ui).flush(); // some adding library actions are taken here,so it must be put before "MsaWriter"
new SourceFileReplacer(modulepath, outputpath, this, db, ui).flush(); // some adding library actions are taken here,so it must be put before "MsaWriter"
// show result
if (ui.yesOrNo("Parse of the Module Information has completed. View details?")) {
@ -113,12 +100,10 @@ public class ModuleInfo {
show(hashr8only, "hashr8only : ");
}
new MsaWriter(modulepath, this, db, ui).flush();
// remove temp directory
//File tempdir = new File(modulepath + File.separator + "temp");
//System.out.println("Deleting Dir");
//if (tempdir.exists()) tempdir.d;
new MsaWriter(modulepath, outputpath, this, db, ui).flush();
Common.deleteDir(modulepath + File.separator + "temp");
//Common.toDoAll(modulepath + File.separator + "temp", Common.class.getMethod("deleteDir", String.class), null, null, Common.DIR);
ui.println("Errors Left : " + db.error);
ui.println("Complete!");
@ -140,7 +125,7 @@ public class ModuleInfo {
Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");
Matcher mtrinclude;
Iterator<String> ii = localmodulesources.iterator();
while ( ii.hasNext() ) {
curFile = ii.next();
@ -218,7 +203,7 @@ public class ModuleInfo {
// find guid
matguid = Guid.ptnguid.matcher(line); // several ways to implement this , which one is faster ? :
while (matguid.find()) { // 1.currently , find once , then call to identify which is it
if ((temp = Guid.register(matguid, this, db)) != null) { // 2.use 3 different matchers , search 3 times to find each
if ((temp = Guid.register(matguid, this, db)) != null) { // 2.use 3 different matchers , search 3 times to find each
//matguid.appendReplacement(result, db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost
}
}
@ -272,7 +257,39 @@ public class ModuleInfo {
}
}
public static void main(String[] args) throws Exception {
FirstPanel.init();
public final void enroll(String filepath) throws Exception {
String[] temp;
if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") ||
filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) {
temp = filepath.split("\\\\");
localmodulesources.add(temp[temp.length - 1]);
} else if (filepath.contains(".inf") || filepath.contains(".msa")) {
temp = filepath.split("\\\\");
msaorinf.add(temp[temp.length - 1]);
}
}
public static final void seekModule(String filepath) throws Exception {
if (isModule(filepath)) {
//System.out.println("I'm in");
new ModuleInfo(filepath);
}
}
private static final boolean isModule(String path) {
String[] list = new File(path).list();
for (int i = 0 ; i < list.length ; i++) {
if (!new File(list[i]).isDirectory()) {
if (list[i].contains(".inf") || list[i].contains(".msa")) {
return true;
}
}
}
return false;
}
public static final void main(String[] args) throws Exception {
ui = FirstPanel.init();
db = new Database();
}
}

View File

@ -17,24 +17,24 @@ import java.util.*;
import java.util.regex.*;
import org.tianocore.*;
public class ModuleReader {
public final class ModuleReader {
ModuleReader(String path, ModuleInfo moduleinfo, Database database, UI u) {
modulepath = path;
mi = moduleinfo;
//modulepath = path;
//mi = moduleinfo;
db = database;
ui = u;
}
private String modulepath;
private ModuleInfo mi;
private Database db;
private UI ui;
//private static String modulepath;
//private static ModuleInfo mi;
private static Database db;
private static UI ui;
private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
private static Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
private static Pattern ptnfilename = Pattern.compile("[^\\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 ptnfilename = Pattern.compile("[^\\s]+");
public void readMsa(String name) throws Exception {
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(modulepath + File.separator + name));
public static final void readMsa(String name, ModuleInfo mi) throws Exception {
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));
ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();
MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
@ -53,14 +53,14 @@ public class ModuleReader {
}
}
public void readInf(String name) throws Exception {
public static final void readInf(String name, ModuleInfo mi) throws Exception {
System.out.println("\nParsing INF file: " + name);
String wholeline;
Matcher mtrinfequation;
Matcher mtrsection;
Matcher mtrfilename;
wholeline = Common.file2string(modulepath + File.separator + name);
wholeline = Common.file2string(mi.modulepath + File.separator + name);
mtrsection = ptnsection.matcher(wholeline);
while (mtrsection.find()) {
if (mtrsection.group(1).matches("defines")) {

View File

@ -20,14 +20,16 @@ import org.tianocore.SupportedArchitectures.Enum;
import org.apache.xmlbeans.*;
public class MsaWriter {
MsaWriter(String path, ModuleInfo moduleinfo, Database database, UI u) {
MsaWriter(String path, String outpath, ModuleInfo moduleinfo, Database database, UI u) {
modulepath = path;
outputpath = outpath;
mi = moduleinfo;
db = database;
ui = u;
}
private String modulepath;
private String outputpath;
private ModuleInfo mi;
private Database db;
private UI ui;
@ -187,7 +189,7 @@ public class MsaWriter {
options.setSavePrettyPrintIndent(2);
options.setUseDefaultNamespace();
BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));
BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));
fulfillMsadoc().save(bw, options);
//MsaTreeEditor.init(mi, ui, msadoc);
bw.flush();

View File

@ -17,14 +17,16 @@ import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SourceFileReplacer {
SourceFileReplacer(String path, ModuleInfo moduleinfo, Database database, UI fp) {
public final class SourceFileReplacer {
SourceFileReplacer(String path, String outpath, ModuleInfo moduleinfo, Database database, UI fp) {
modulepath = path;
outputpath = outpath;
mi = moduleinfo;
db = database;
ui = fp;
}
private String modulepath;
private String outputpath;
private ModuleInfo mi;
private Database db;
private UI ui;
@ -47,7 +49,7 @@ public class SourceFileReplacer {
private Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
private Set<String> filer8only = new HashSet<String>();
private String r8only = "EfiLibInstallDriverBinding " +
private static final String r8only = "EfiLibInstallDriverBinding " +
"EfiLibInstallAllDriverProtocols " +
"EfiLibCompareLanguage " +
"BufToHexString " +
@ -68,7 +70,6 @@ public class SourceFileReplacer {
"GetIoPortSpaceAddressHobInfo ";
public void flush() throws Exception {
PrintWriter outfile;
String outname = null;
String inname = null;
if (ui.yesOrNo("Changes will be made to the Source Code. View details?")) {
@ -85,14 +86,7 @@ public class SourceFileReplacer {
outname = inname;
}
ui.println("\nModifying file: " + inname);
Common.string2file(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname), modulepath + File.separator + "result" + File.separator + outname);
/*
Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));
outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname));
outfile.flush();
outfile.close();
*/
Common.string2file(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname), outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);
} else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {
if (inname.contains(".H")) {
outname = inname.replaceFirst(".H", ".h");
@ -100,14 +94,7 @@ public class SourceFileReplacer {
outname = inname;
}
ui.println("\nCopying file: " + inname);
Common.string2file(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname), modulepath + File.separator + "result" + File.separator + outname);
/*
Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));
outfile.append(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname));
outfile.flush();
outfile.close();
*/
Common.string2file(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname), outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);
}
}
@ -120,8 +107,8 @@ public class SourceFileReplacer {
String paragraph = null;
String line = Common.file2string(Database.defaultpath + File.separator + "R8Lib.c");
Common.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.c")));
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.h")));
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.h")));
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL);
Matcher mtrr8only = ptnr8only.matcher(line);
Matcher mtrr8onlyhead;

View File

@ -27,4 +27,6 @@ public interface UI {
public String choose(String message, Object[] choicelist);
public String getInput(String message);
public String getFilepath(); // necessary ?
}