\t 2 \ \ \ \
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1499 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -18,191 +18,191 @@ import java.util.*;
|
|||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
|
|
||||||
public final class Common {
|
public final class Common {
|
||||||
public static final int BOTH = 0;
|
public static final int BOTH = 0;
|
||||||
public static final int FILE = 1;
|
public static final int FILE = 1;
|
||||||
public static final int DIR = 2;
|
public static final int DIR = 2;
|
||||||
|
|
||||||
public static final String strseparate = "(.*)\\\\([^\\\\]*)";
|
public static final String strseparate = "(.*)\\\\([^\\\\]*)";
|
||||||
public static final Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)");
|
public static final Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)");
|
||||||
|
|
||||||
//-------------------------------------regex------------------------------------------//
|
//-------------------------------------regex------------------------------------------//
|
||||||
|
|
||||||
public static final String replaceAll(String line, Pattern ptn, String des) {
|
public static final String replaceAll(String line, Pattern ptn, String des) {
|
||||||
Matcher mtr = ptn.matcher(line);
|
Matcher mtr = ptn.matcher(line);
|
||||||
|
|
||||||
if (mtr.find()) {
|
if (mtr.find()) {
|
||||||
return mtr.replaceAll(des);
|
return mtr.replaceAll(des);
|
||||||
}
|
}
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------regex------------------------------------------//
|
//-------------------------------------regex------------------------------------------//
|
||||||
|
|
||||||
//-----------------------------------file&string---------------------------------------//
|
//-----------------------------------file&string---------------------------------------//
|
||||||
|
|
||||||
public static final String file2string(String filename) throws Exception {
|
public static final String file2string(String filename) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(filename));
|
BufferedReader rd = new BufferedReader(new FileReader(filename));
|
||||||
StringBuffer wholefile = new StringBuffer();
|
StringBuffer wholefile = new StringBuffer();
|
||||||
String line;
|
String line;
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
wholefile.append(line + "\n");
|
wholefile.append(line + "\n");
|
||||||
}
|
}
|
||||||
return wholefile.toString();
|
return wholefile.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void string2file(String content, String filename) throws Exception {
|
public static final void string2file(String content, String filename) throws Exception {
|
||||||
ensureDir(filename);
|
ensureDir(filename);
|
||||||
PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
|
PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
|
||||||
outfile.append(content);
|
outfile.append(content);
|
||||||
outfile.flush();
|
outfile.flush();
|
||||||
outfile.close();
|
outfile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------file&string---------------------------------------//
|
//-----------------------------------file&string---------------------------------------//
|
||||||
|
|
||||||
//--------------------------------------dir--------------------------------------------//
|
//--------------------------------------dir--------------------------------------------//
|
||||||
/*
|
/*
|
||||||
public static final HashSet<String> walkDir(String path, int mode) throws Exception {
|
public static final HashSet<String> walkDir(String path, int mode) throws Exception {
|
||||||
HashSet<String> pathlist = new HashSet<String>();
|
HashSet<String> pathlist = new HashSet<String>();
|
||||||
Common.toDoAll(path, Common.class.getMethod("walkDir", String.class), null, null, mode);
|
Common.toDoAll(path, Common.class.getMethod("walkDir", String.class), null, null, mode);
|
||||||
return pathlist;
|
return pathlist;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
public static final void ensureDir(String objFileWhole) {
|
public static final void ensureDir(String objFileWhole) {
|
||||||
File tempdir;
|
File tempdir;
|
||||||
Matcher mtrseparate = ptnseparate.matcher(objFileWhole);
|
Matcher mtrseparate = ptnseparate.matcher(objFileWhole);
|
||||||
if (mtrseparate.find()) {
|
if (mtrseparate.find()) {
|
||||||
tempdir = new File(mtrseparate.group(1));
|
tempdir = new File(mtrseparate.group(1));
|
||||||
if (!tempdir.exists()) tempdir.mkdirs();
|
if (!tempdir.exists()) tempdir.mkdirs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void deleteDir(String objFileWhole) {
|
public static final void deleteDir(String objFileWhole) {
|
||||||
String[] list = new File(objFileWhole).list();
|
String[] list = new File(objFileWhole).list();
|
||||||
File temp;
|
File temp;
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0 ; i < list.length ; i++) {
|
||||||
temp = new File(objFileWhole + File.separator + list[i]);
|
temp = new File(objFileWhole + File.separator + list[i]);
|
||||||
if (temp.isDirectory()) {
|
if (temp.isDirectory()) {
|
||||||
deleteDir(objFileWhole + File.separator + list[i]);
|
deleteDir(objFileWhole + File.separator + list[i]);
|
||||||
} else {
|
} else {
|
||||||
temp.delete();
|
temp.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new File(objFileWhole).delete();
|
new File(objFileWhole).delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String dirCopy_(String src) throws Exception {
|
public static final String dirCopy_(String src) throws Exception {
|
||||||
Matcher mtrseparate = Common.ptnseparate.matcher(src);
|
Matcher mtrseparate = Common.ptnseparate.matcher(src);
|
||||||
if (mtrseparate.find()) {
|
if (mtrseparate.find()) {
|
||||||
dirCopy(src, mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2));
|
dirCopy(src, mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2));
|
||||||
}
|
}
|
||||||
return mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2);
|
return mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final 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();
|
String[] list = new File(src).list();
|
||||||
File test;
|
File test;
|
||||||
|
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0 ; i < list.length ; i++) {
|
||||||
test = new File(src + File.separator + list[i]);
|
test = new File(src + File.separator + list[i]);
|
||||||
if (test.isDirectory()) {
|
if (test.isDirectory()) {
|
||||||
dirCopy(src + File.separator + list[i], des + File.separator + list[i]);
|
dirCopy(src + File.separator + list[i], des + File.separator + list[i]);
|
||||||
} else {
|
} 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]);
|
string2file(file2string(src + File.separator + list[i]), des + File.separator + list[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------dir--------------------------------------------//
|
//--------------------------------------dir--------------------------------------------//
|
||||||
|
|
||||||
//-------------------------------like python walk-----------------------------------------//
|
//-------------------------------like python walk-----------------------------------------//
|
||||||
|
|
||||||
public static final void toDoAll(String path, Method md, Object obj, Object[] args, int type) throws Exception {
|
public static final void toDoAll(String path, Method md, Object obj, Object[] args, int type) throws Exception {
|
||||||
String[] list = new File(path).list();
|
String[] list = new File(path).list();
|
||||||
ArrayList<Object> _args = new ArrayList<Object>();
|
ArrayList<Object> _args = new ArrayList<Object>();
|
||||||
|
|
||||||
_args.add(path);
|
_args.add(path);
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
_args.add(args[i]);
|
_args.add(args[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == DIR || type == BOTH) {
|
if (type == DIR || type == BOTH) {
|
||||||
md.invoke(obj, _args.toArray());
|
md.invoke(obj, _args.toArray());
|
||||||
}
|
}
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0 ; i < list.length ; i++) {
|
||||||
if (new File(path + File.separator + list[i]).isDirectory()) {
|
if (new File(path + File.separator + list[i]).isDirectory()) {
|
||||||
toDoAll(path + File.separator + list[i], md, obj, args, type);
|
toDoAll(path + File.separator + list[i], md, obj, args, type);
|
||||||
} else {
|
} else {
|
||||||
if (type == FILE || type == BOTH) {
|
if (type == FILE || type == BOTH) {
|
||||||
_args.set(0, path + File.separator + list[i]);
|
_args.set(0, path + File.separator + list[i]);
|
||||||
md.invoke(obj, _args.toArray());
|
md.invoke(obj, _args.toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void toDoAll(Set<String> set, ForDoAll fda) throws Exception {
|
public static final void toDoAll(Set<String> set, ForDoAll fda) throws Exception {
|
||||||
Iterator<String> di = set.iterator();
|
Iterator<String> di = set.iterator();
|
||||||
while (di.hasNext()) {
|
while (di.hasNext()) {
|
||||||
fda.run(di.next());
|
fda.run(di.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void toDoAll(String path, ForDoAll fda, int type) throws Exception { // filter of file type can be done in toDo
|
public static final void toDoAll(String path, ForDoAll fda, int type) throws Exception { // filter of file type can be done in toDo
|
||||||
String[] list = new File(path).list();
|
String[] list = new File(path).list();
|
||||||
File test;
|
File test;
|
||||||
|
|
||||||
if (type == DIR || type == BOTH) {
|
if (type == DIR || type == BOTH) {
|
||||||
fda.run(path);
|
fda.run(path);
|
||||||
}
|
}
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0 ; i < list.length ; i++) {
|
||||||
test = new File(path + File.separator + list[i]);
|
test = new File(path + File.separator + list[i]);
|
||||||
if (test.isDirectory()) {
|
if (test.isDirectory()) {
|
||||||
if (fda.filter(test)) {
|
if (fda.filter(test)) {
|
||||||
toDoAll(path + File.separator + list[i], fda, type);
|
toDoAll(path + File.separator + list[i], fda, type);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (type == FILE || type == BOTH) {
|
if (type == FILE || type == BOTH) {
|
||||||
fda.run(path + File.separator + list[i]);
|
fda.run(path + File.separator + list[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface ForDoAll {
|
public static interface ForDoAll {
|
||||||
public void run(String filepath) throws Exception;
|
public void run(String filepath) throws Exception;
|
||||||
|
|
||||||
public boolean filter(File dir);
|
public boolean filter(File dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static abstract class Laplace {
|
public static abstract class Laplace {
|
||||||
public void transform(String src, String des) throws Exception {
|
public void transform(String src, String des) throws Exception {
|
||||||
Common.string2file(operation(Common.file2string(src)), des);
|
Common.string2file(operation(Common.file2string(src)), des);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String operation(String wholeline);
|
public abstract String operation(String wholeline);
|
||||||
|
|
||||||
public abstract boolean recognize(String filename);
|
public abstract boolean recognize(String filename);
|
||||||
|
|
||||||
public abstract String namechange(String oldname);
|
public abstract String namechange(String oldname);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface Element {
|
public static interface Element {
|
||||||
|
|
||||||
// public int replace = 0;
|
// public int replace = 0;
|
||||||
// public int type = 1;
|
// public int type = 1;
|
||||||
|
|
||||||
public String getReplace(String key);
|
public String getReplace(String key);
|
||||||
|
|
||||||
// public void getType(String key);
|
// public void getType(String key);
|
||||||
//
|
//
|
||||||
// public void setReplace(int num);
|
// public void setReplace(int num);
|
||||||
//
|
//
|
||||||
// public void setType(int num);
|
// public void setType(int num);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,192 +16,192 @@ import java.util.regex.*;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public final class Critic {
|
public final class Critic {
|
||||||
public static final Pattern PTN_NEW_HEAD_COMMENT = Pattern.compile("^\\/\\*\\*.*?\\*\\*\\/",Pattern.DOTALL);
|
public static final Pattern PTN_NEW_HEAD_COMMENT = Pattern.compile("^\\/\\*\\*.*?\\*\\*\\/",Pattern.DOTALL);
|
||||||
private static final Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);
|
private static final Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);
|
||||||
private static final Pattern ptnfunccomment = Pattern.compile("([\\};\\/\">]\\s*)([\\w\\s\\*]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/(\\s*.*?)(?=[\\{;])",Pattern.DOTALL); // find function with {;">/ , may be unsafe
|
private static final Pattern ptnfunccomment = Pattern.compile("([\\};\\/\">]\\s*)([\\w\\s\\*]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/(\\s*.*?)(?=[\\{;])",Pattern.DOTALL); // find function with {;">/ , may be unsafe
|
||||||
//private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\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 final Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");
|
private static final Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");
|
||||||
private static Matcher mtrcommentequation;
|
private static Matcher mtrcommentequation;
|
||||||
private static final Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");
|
private static final Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");
|
||||||
private static Matcher mtrnewcomment;
|
private static Matcher mtrnewcomment;
|
||||||
|
|
||||||
private static final int totallinelength = 82;
|
private static final int totallinelength = 82;
|
||||||
|
|
||||||
public static final void run(String filepath) throws Exception {
|
public static final void run(String filepath) throws Exception {
|
||||||
if (MigrationTool.doCritic) { // this is left here to set an example for future structure
|
if (MigrationTool.doCritic) { // this is left here to set an example for future structure
|
||||||
critic(filepath);
|
critic(filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void critic(String filepath) throws Exception {
|
private static final void critic(String filepath) throws Exception {
|
||||||
if (filepath.contains(".c") || filepath.contains(".h")) {
|
if (filepath.contains(".c") || filepath.contains(".h")) {
|
||||||
BufferedReader rd = null;
|
BufferedReader rd = null;
|
||||||
String line = null;
|
String line = null;
|
||||||
StringBuffer templine = new StringBuffer();
|
StringBuffer templine = new StringBuffer();
|
||||||
boolean incomment = false;
|
boolean incomment = false;
|
||||||
|
|
||||||
System.out.println("Criticing " + filepath);
|
System.out.println("Criticing " + filepath);
|
||||||
String wholeline = Common.file2string(filepath);
|
String wholeline = Common.file2string(filepath);
|
||||||
|
|
||||||
wholeline = wholeline.replaceAll("\t", " ");
|
wholeline = wholeline.replaceAll("\t", " ");
|
||||||
wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");
|
wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");
|
||||||
wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1/**$3**/$4$2");
|
wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1/**$3**/$4$2");
|
||||||
//wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
|
//wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
|
||||||
|
|
||||||
// first scan
|
// first scan
|
||||||
boolean description = false;
|
boolean description = false;
|
||||||
boolean arguments = false;
|
boolean arguments = false;
|
||||||
boolean returns = false;
|
boolean returns = false;
|
||||||
boolean inequation = false;
|
boolean inequation = false;
|
||||||
rd = new BufferedReader(new StringReader(wholeline));
|
rd = new BufferedReader(new StringReader(wholeline));
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.matches("\\/\\*\\*")) {
|
if (line.matches("\\/\\*\\*")) {
|
||||||
incomment = true;
|
incomment = true;
|
||||||
description = false;
|
description = false;
|
||||||
arguments = false;
|
arguments = false;
|
||||||
returns = false;
|
returns = false;
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
} else if (line.matches("\\*\\*\\/")) {
|
} else if (line.matches("\\*\\*\\/")) {
|
||||||
incomment = false;
|
incomment = false;
|
||||||
templine.append("\n" + line + "\n");
|
templine.append("\n" + line + "\n");
|
||||||
} else if (incomment) {
|
} else if (incomment) {
|
||||||
if (line.contains("Routine Description:")) {
|
if (line.contains("Routine Description:")) {
|
||||||
description = true;
|
description = true;
|
||||||
arguments = false;
|
arguments = false;
|
||||||
returns = false;
|
returns = false;
|
||||||
} else if (line.contains("Arguments:")) {
|
} else if (line.contains("Arguments:")) {
|
||||||
description = false;
|
description = false;
|
||||||
arguments = true;
|
arguments = true;
|
||||||
returns = false;
|
returns = false;
|
||||||
templine.append("\n");
|
templine.append("\n");
|
||||||
} else if (line.contains("Returns:")) {
|
} else if (line.contains("Returns:")) {
|
||||||
description = false;
|
description = false;
|
||||||
arguments = false;
|
arguments = false;
|
||||||
returns = true;
|
returns = true;
|
||||||
templine.append("\n");
|
templine.append("\n");
|
||||||
} else if (description) {
|
} else if (description) {
|
||||||
if (line.trim().length() != 0) {
|
if (line.trim().length() != 0) {
|
||||||
templine.append(" " + line.trim() + "\n");
|
templine.append(" " + line.trim() + "\n");
|
||||||
}
|
}
|
||||||
} else if (arguments) {
|
} else if (arguments) {
|
||||||
mtrcommentequation = ptncommentequation.matcher(line);
|
mtrcommentequation = ptncommentequation.matcher(line);
|
||||||
if (mtrcommentequation.find()) {
|
if (mtrcommentequation.find()) {
|
||||||
inequation = true;
|
inequation = true;
|
||||||
templine.append(" @param " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
|
templine.append(" @param " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
|
||||||
} else if (inequation && line.trim().length() == 0) {
|
} else if (inequation && line.trim().length() == 0) {
|
||||||
inequation = false;
|
inequation = false;
|
||||||
} else if (inequation && line.trim().length() != 0) {
|
} else if (inequation && line.trim().length() != 0) {
|
||||||
templine.append("#%#%" + line + "\n");
|
templine.append("#%#%" + line + "\n");
|
||||||
} else {
|
} else {
|
||||||
if (line.trim().length() != 0) {
|
if (line.trim().length() != 0) {
|
||||||
templine.append(" " + line.trim() + "\n");
|
templine.append(" " + line.trim() + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (returns) {
|
} else if (returns) {
|
||||||
mtrcommentequation = ptncommentequation.matcher(line);
|
mtrcommentequation = ptncommentequation.matcher(line);
|
||||||
if (mtrcommentequation.find()) {
|
if (mtrcommentequation.find()) {
|
||||||
inequation = true;
|
inequation = true;
|
||||||
templine.append(" @retval " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
|
templine.append(" @retval " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
|
||||||
} else if (inequation && line.trim().length() == 0) {
|
} else if (inequation && line.trim().length() == 0) {
|
||||||
inequation = false;
|
inequation = false;
|
||||||
} else if (inequation && line.trim().length() != 0) {
|
} else if (inequation && line.trim().length() != 0) {
|
||||||
templine.append("#%#%" + line + "\n");
|
templine.append("#%#%" + line + "\n");
|
||||||
} else {
|
} else {
|
||||||
if (line.trim().length() != 0) {
|
if (line.trim().length() != 0) {
|
||||||
templine.append(" @return " + line.trim() + "\n");
|
templine.append(" @return " + line.trim() + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wholeline = templine.toString();
|
wholeline = templine.toString();
|
||||||
wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");
|
wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");
|
||||||
//
|
//
|
||||||
|
|
||||||
// secend scan
|
// secend scan
|
||||||
int startmax = 0;
|
int startmax = 0;
|
||||||
rd = new BufferedReader(new StringReader(wholeline));
|
rd = new BufferedReader(new StringReader(wholeline));
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.matches("\\/\\*\\*")) {
|
if (line.matches("\\/\\*\\*")) {
|
||||||
incomment = true;
|
incomment = true;
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
} else if (line.matches("\\*\\*\\/")) {
|
} else if (line.matches("\\*\\*\\/")) {
|
||||||
incomment = false;
|
incomment = false;
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
} else if (incomment) {
|
} else if (incomment) {
|
||||||
mtrnewcomment = ptnnewcomment.matcher(line);
|
mtrnewcomment = ptnnewcomment.matcher(line);
|
||||||
if (mtrnewcomment.find()) {
|
if (mtrnewcomment.find()) {
|
||||||
startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment.group(1).length() : startmax;
|
startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment.group(1).length() : startmax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
startmax++;
|
startmax++;
|
||||||
//
|
//
|
||||||
|
|
||||||
// third scan
|
// third scan
|
||||||
int n = 0;
|
int n = 0;
|
||||||
String temp = null;
|
String temp = null;
|
||||||
String[] tempcont = null;
|
String[] tempcont = null;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
templine = new StringBuffer();
|
templine = new StringBuffer();
|
||||||
rd = new BufferedReader(new StringReader(wholeline));
|
rd = new BufferedReader(new StringReader(wholeline));
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.matches("\\/\\*\\*")) {
|
if (line.matches("\\/\\*\\*")) {
|
||||||
incomment = true;
|
incomment = true;
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
} else if (line.matches("\\*\\*\\/")) {
|
} else if (line.matches("\\*\\*\\/")) {
|
||||||
incomment = false;
|
incomment = false;
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
} else if (incomment) {
|
} else if (incomment) {
|
||||||
mtrnewcomment = ptnnewcomment.matcher(line);
|
mtrnewcomment = ptnnewcomment.matcher(line);
|
||||||
if (mtrnewcomment.find()) {
|
if (mtrnewcomment.find()) {
|
||||||
n = startmax - mtrnewcomment.group(1).length();
|
n = startmax - mtrnewcomment.group(1).length();
|
||||||
templine.append(mtrnewcomment.group(1));
|
templine.append(mtrnewcomment.group(1));
|
||||||
while (n-- >= 0) {
|
while (n-- >= 0) {
|
||||||
templine.append(" ");
|
templine.append(" ");
|
||||||
}
|
}
|
||||||
temp = mtrnewcomment.group(3);
|
temp = mtrnewcomment.group(3);
|
||||||
tempcont = temp.split(" "); // use \\s+ ?
|
tempcont = temp.split(" "); // use \\s+ ?
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
for (int i = 0; i < tempcont.length; i++) {
|
for (int i = 0; i < tempcont.length; i++) {
|
||||||
count += tempcont[i].length();
|
count += tempcont[i].length();
|
||||||
if (count <= (totallinelength - startmax)) {
|
if (count <= (totallinelength - startmax)) {
|
||||||
templine.append(tempcont[i] + " ");
|
templine.append(tempcont[i] + " ");
|
||||||
count += 1;
|
count += 1;
|
||||||
} else {
|
} else {
|
||||||
templine.append("\n");
|
templine.append("\n");
|
||||||
n = startmax;
|
n = startmax;
|
||||||
while (n-- >= 0) {
|
while (n-- >= 0) {
|
||||||
templine.append(" ");
|
templine.append(" ");
|
||||||
}
|
}
|
||||||
templine.append(tempcont[i] + " ");
|
templine.append(tempcont[i] + " ");
|
||||||
count = tempcont[i].length() + 1;
|
count = tempcont[i].length() + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templine.append("\n");
|
templine.append("\n");
|
||||||
} else {
|
} else {
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wholeline = templine.toString();
|
wholeline = templine.toString();
|
||||||
//
|
//
|
||||||
// Remove trailing blanks.
|
// Remove trailing blanks.
|
||||||
//
|
//
|
||||||
wholeline = wholeline.replaceAll (" +\n", "\n");
|
wholeline = wholeline.replaceAll (" +\n", "\n");
|
||||||
Common.string2file(wholeline, filepath);
|
Common.string2file(wholeline, filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void fireAt(String path) throws Exception {
|
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.class.getMethod("critic", String.class), null, null, Common.FILE);
|
||||||
Common.toDoAll(path, Critic.class.getMethod("run", String.class), null, null, Common.FILE);
|
Common.toDoAll(path, Critic.class.getMethod("run", String.class), null, null, Common.FILE);
|
||||||
//Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);
|
//Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);
|
||||||
System.out.println("Critic Done");
|
System.out.println("Critic Done");
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -17,170 +17,170 @@ import java.util.*;
|
|||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
|
|
||||||
public final class Database {
|
public final class Database {
|
||||||
private static final Database INSTANCE = Database.init();
|
private static final Database INSTANCE = Database.init();
|
||||||
|
|
||||||
Database(String path) {
|
Database(String path) {
|
||||||
DatabasePath = path;
|
DatabasePath = path;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
importDBLib("Library.csv");
|
importDBLib("Library.csv");
|
||||||
importDBGuid("Guid.csv", "Guid");
|
importDBGuid("Guid.csv", "Guid");
|
||||||
importDBGuid("Ppi.csv", "Ppi");
|
importDBGuid("Ppi.csv", "Ppi");
|
||||||
importDBGuid("Protocol.csv", "Protocol");
|
importDBGuid("Protocol.csv", "Protocol");
|
||||||
importDBMacro("Macro.csv");
|
importDBMacro("Macro.csv");
|
||||||
importListR8Only();
|
importListR8Only();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String DatabasePath;
|
public String DatabasePath;
|
||||||
public Set<String> error = new HashSet<String>();
|
public Set<String> error = new HashSet<String>();
|
||||||
public Set<String> r8only = new HashSet<String>();
|
public Set<String> r8only = new HashSet<String>();
|
||||||
|
|
||||||
private Map<String,Guid> hashguid = new HashMap<String,Guid>();
|
private Map<String,Guid> hashguid = new HashMap<String,Guid>();
|
||||||
private Map<String,Func> hashfunc = new HashMap<String,Func>();
|
private Map<String,Func> hashfunc = new HashMap<String,Func>();
|
||||||
private Map<String,Macro> hashmacro = new HashMap<String,Macro>();
|
private Map<String,Macro> hashmacro = new HashMap<String,Macro>();
|
||||||
|
|
||||||
//-------------------------------------import------------------------------------------//
|
//-------------------------------------import------------------------------------------//
|
||||||
|
|
||||||
private void importDBLib(String filename) throws Exception {
|
private void importDBLib(String filename) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
||||||
String line;
|
String line;
|
||||||
String[] linecontext;
|
String[] linecontext;
|
||||||
Func lf;
|
Func lf;
|
||||||
|
|
||||||
if (rd.ready()) {
|
if (rd.ready()) {
|
||||||
System.out.println("Found " + filename + ", Importing Library Database.");
|
System.out.println("Found " + filename + ", Importing Library Database.");
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.length() != 0) {
|
if (line.length() != 0) {
|
||||||
linecontext = line.split(",");
|
linecontext = line.split(",");
|
||||||
lf = new Func(linecontext);
|
lf = new Func(linecontext);
|
||||||
hashfunc.put(lf.r8funcname,lf);
|
hashfunc.put(lf.r8funcname,lf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importDBGuid(String filename, String type) throws Exception {
|
private void importDBGuid(String filename, String type) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
||||||
String line;
|
String line;
|
||||||
String[] linecontext;
|
String[] linecontext;
|
||||||
Guid gu;
|
Guid gu;
|
||||||
|
|
||||||
if (rd.ready()) {
|
if (rd.ready()) {
|
||||||
System.out.println("Found " + filename + ", Importing " + type + " Database.");
|
System.out.println("Found " + filename + ", Importing " + type + " Database.");
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.length() != 0) {
|
if (line.length() != 0) {
|
||||||
linecontext = line.split(",");
|
linecontext = line.split(",");
|
||||||
gu = new Guid(linecontext, type);
|
gu = new Guid(linecontext, type);
|
||||||
hashguid.put(gu.r8name,gu);
|
hashguid.put(gu.r8name,gu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importDBMacro(String filename) throws Exception {
|
private void importDBMacro(String filename) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
||||||
String line;
|
String line;
|
||||||
String[] linecontext;
|
String[] linecontext;
|
||||||
Macro mc;
|
Macro mc;
|
||||||
|
|
||||||
if (rd.ready()) {
|
if (rd.ready()) {
|
||||||
System.out.println("Found " + filename + ", Importing Macro Database.");
|
System.out.println("Found " + filename + ", Importing Macro Database.");
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.length() != 0) {
|
if (line.length() != 0) {
|
||||||
linecontext = line.split(",");
|
linecontext = line.split(",");
|
||||||
mc = new Macro(linecontext);
|
mc = new Macro(linecontext);
|
||||||
hashmacro.put(mc.r8name,mc);
|
hashmacro.put(mc.r8name,mc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importListR8Only() throws Exception {
|
private void importListR8Only() throws Exception {
|
||||||
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);
|
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);
|
||||||
String wholeline = Common.file2string(DatabasePath + File.separator + "R8Lib.c");
|
String wholeline = Common.file2string(DatabasePath + File.separator + "R8Lib.c");
|
||||||
System.out.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");
|
System.out.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");
|
||||||
Matcher mtrr8only = ptnr8only.matcher(wholeline);
|
Matcher mtrr8only = ptnr8only.matcher(wholeline);
|
||||||
while (mtrr8only.find()) {
|
while (mtrr8only.find()) {
|
||||||
r8only.add(mtrr8only.group(2));
|
r8only.add(mtrr8only.group(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------import------------------------------------------//
|
//-------------------------------------import------------------------------------------//
|
||||||
|
|
||||||
//-------------------------------------get------------------------------------------//
|
//-------------------------------------get------------------------------------------//
|
||||||
|
|
||||||
public String getR9Lib(String r8funcname) {
|
public String getR9Lib(String r8funcname) {
|
||||||
String temp = null;
|
String temp = null;
|
||||||
if (hashfunc.containsKey(r8funcname)) {
|
if (hashfunc.containsKey(r8funcname)) {
|
||||||
temp = hashfunc.get(r8funcname).r9libname;
|
temp = hashfunc.get(r8funcname).r9libname;
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getR9Func(String r8funcname) {
|
public String getR9Func(String r8funcname) {
|
||||||
String temp = null;
|
String temp = null;
|
||||||
if (hashfunc.containsKey(r8funcname)) {
|
if (hashfunc.containsKey(r8funcname)) {
|
||||||
temp = hashfunc.get(r8funcname).r9funcname;
|
temp = hashfunc.get(r8funcname).r9funcname;
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getR9Macro(String r8macro) {
|
public String getR9Macro(String r8macro) {
|
||||||
return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it
|
return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getR9Guidname(String r8Guid) {
|
public String getR9Guidname(String r8Guid) {
|
||||||
String temp = null;
|
String temp = null;
|
||||||
try {
|
try {
|
||||||
temp = hashguid.get(r8Guid).r9name;
|
temp = hashguid.get(r8Guid).r9name;
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
error.add("getR9Guidname :" + r8Guid);
|
error.add("getR9Guidname :" + r8Guid);
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGuidType(String r8Guid) {
|
public String getGuidType(String r8Guid) {
|
||||||
String temp = null;
|
String temp = null;
|
||||||
try {
|
try {
|
||||||
temp = hashguid.get(r8Guid).type;
|
temp = hashguid.get(r8Guid).type;
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
error.add("getR9Guidname :" + r8Guid);
|
error.add("getR9Guidname :" + r8Guid);
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------get------------------------------------------//
|
//-------------------------------------get------------------------------------------//
|
||||||
|
|
||||||
//-------------------------------------has------------------------------------------//
|
//-------------------------------------has------------------------------------------//
|
||||||
|
|
||||||
public boolean hasFunc(String r8lib) {
|
public boolean hasFunc(String r8lib) {
|
||||||
return hashfunc.containsKey(r8lib);
|
return hashfunc.containsKey(r8lib);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasGuid(String r8guid) {
|
public boolean hasGuid(String r8guid) {
|
||||||
return hashguid.containsKey(r8guid);
|
return hashguid.containsKey(r8guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMacro(String r8macro) {
|
public boolean hasMacro(String r8macro) {
|
||||||
return hashmacro.containsKey(r8macro);
|
return hashmacro.containsKey(r8macro);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------has------------------------------------------//
|
//-------------------------------------has------------------------------------------//
|
||||||
|
|
||||||
//-------------------------------------init------------------------------------------//
|
//-------------------------------------init------------------------------------------//
|
||||||
|
|
||||||
private static final Database init() {
|
private static final Database init() {
|
||||||
if (System.getenv("WORKSPACE") == null) {
|
if (System.getenv("WORKSPACE") == null) {
|
||||||
return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
|
return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
|
||||||
} else {
|
} else {
|
||||||
return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
|
return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Database getInstance() {
|
public static final Database getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,65 +19,65 @@ import java.util.*;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public final class FirstPanel extends JPanel implements ActionListener, ItemListener, UI {
|
public final class FirstPanel extends JPanel implements ActionListener, ItemListener, UI {
|
||||||
/**
|
/**
|
||||||
* Define class Serial Version UID
|
* Define class Serial Version UID
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 207759413522910399L;
|
private static final long serialVersionUID = 207759413522910399L;
|
||||||
|
|
||||||
private static final FirstPanel INSTANCE = FirstPanel.init();
|
private static final FirstPanel INSTANCE = FirstPanel.init();
|
||||||
|
|
||||||
private String startpath;
|
private String startpath;
|
||||||
|
|
||||||
private JButton moduleButton, goButton, msaEditorButton, criticButton, specifyCommentButton;
|
private JButton moduleButton, goButton, msaEditorButton, criticButton, specifyCommentButton;
|
||||||
private JTextField moduletext;
|
private JTextField moduletext;
|
||||||
private JTextArea log;
|
private JTextArea log;
|
||||||
private JFileChooser fc = new JFileChooser();
|
private JFileChooser fc = new JFileChooser();
|
||||||
private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;
|
private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;
|
||||||
|
|
||||||
private boolean tofile = true, toscreen = true;
|
private boolean tofile = true, toscreen = true;
|
||||||
private PrintWriter logfile;
|
private PrintWriter logfile;
|
||||||
|
|
||||||
FirstPanel() {
|
FirstPanel() {
|
||||||
GridBagLayout gridbag = new GridBagLayout();
|
GridBagLayout gridbag = new GridBagLayout();
|
||||||
setLayout(gridbag);
|
setLayout(gridbag);
|
||||||
|
|
||||||
GridBagConstraints cst = new GridBagConstraints();
|
GridBagConstraints cst = new GridBagConstraints();
|
||||||
|
|
||||||
goButton = new JButton("Go");
|
goButton = new JButton("Go");
|
||||||
goButton.addActionListener(this);
|
goButton.addActionListener(this);
|
||||||
goButton.setActionCommand("go");
|
goButton.setActionCommand("go");
|
||||||
|
|
||||||
moduleButton = new JButton("Choose ModulePath");
|
moduleButton = new JButton("Choose ModulePath");
|
||||||
moduleButton.addActionListener(this);
|
moduleButton.addActionListener(this);
|
||||||
|
|
||||||
msaEditorButton = new JButton("MsaEditor");
|
msaEditorButton = new JButton("MsaEditor");
|
||||||
msaEditorButton.addActionListener(this);
|
msaEditorButton.addActionListener(this);
|
||||||
|
|
||||||
criticButton = new JButton("Critic");
|
criticButton = new JButton("Critic");
|
||||||
criticButton.addActionListener(this);
|
criticButton.addActionListener(this);
|
||||||
|
|
||||||
specifyCommentButton = new JButton("Comment Style");
|
specifyCommentButton = new JButton("Comment Style");
|
||||||
specifyCommentButton.addActionListener(this);
|
specifyCommentButton.addActionListener(this);
|
||||||
|
|
||||||
moduletext = new JTextField(30);
|
moduletext = new JTextField(30);
|
||||||
|
|
||||||
filebox = new JCheckBox("Output to logfile", true);
|
filebox = new JCheckBox("Output to logfile", true);
|
||||||
filebox.addItemListener(this);
|
filebox.addItemListener(this);
|
||||||
|
|
||||||
screenbox = new JCheckBox("Specify logfile", false);
|
screenbox = new JCheckBox("Specify logfile", false);
|
||||||
screenbox.addItemListener(this);
|
screenbox.addItemListener(this);
|
||||||
|
|
||||||
mibox = new JCheckBox("Print ModuleInfo", false);
|
mibox = new JCheckBox("Print ModuleInfo", false);
|
||||||
mibox.addItemListener(this);
|
mibox.addItemListener(this);
|
||||||
MigrationTool.printModuleInfo = false;
|
MigrationTool.printModuleInfo = false;
|
||||||
|
|
||||||
criticbox = new JCheckBox("Run Critic", true);
|
criticbox = new JCheckBox("Run Critic", true);
|
||||||
criticbox.addItemListener(this);
|
criticbox.addItemListener(this);
|
||||||
MigrationTool.doCritic = true;
|
MigrationTool.doCritic = true;
|
||||||
|
|
||||||
defaultpathbox = new JCheckBox("Use Default Output Path", true);
|
defaultpathbox = new JCheckBox("Use Default Output Path", true);
|
||||||
defaultpathbox.addItemListener(this);
|
defaultpathbox.addItemListener(this);
|
||||||
MigrationTool.defaultoutput = true;
|
MigrationTool.defaultoutput = true;
|
||||||
|
|
||||||
JPanel modulePanel = new JPanel();
|
JPanel modulePanel = new JPanel();
|
||||||
modulePanel.add(moduleButton);
|
modulePanel.add(moduleButton);
|
||||||
@@ -119,163 +119,163 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
|
|||||||
cst.fill = GridBagConstraints.BOTH;
|
cst.fill = GridBagConstraints.BOTH;
|
||||||
gridbag.setConstraints(logScrollPane, cst);
|
gridbag.setConstraints(logScrollPane, cst);
|
||||||
add(logScrollPane);
|
add(logScrollPane);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
public boolean yesOrNo(String question) {
|
public boolean yesOrNo(String question) {
|
||||||
return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
|
return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void print(String message) {
|
public void print(String message) {
|
||||||
if (toscreen == true) {
|
if (toscreen == true) {
|
||||||
log.append(message);
|
log.append(message);
|
||||||
System.out.print(message);
|
System.out.print(message);
|
||||||
}
|
}
|
||||||
if (tofile == true) {
|
if (tofile == true) {
|
||||||
logfile.append(message);
|
logfile.append(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void println(String message) {
|
public void println(String message) {
|
||||||
print(message + "\n");
|
print(message + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void println(Set<String> hash) {
|
public void println(Set<String> hash) {
|
||||||
if (toscreen == true) {
|
if (toscreen == true) {
|
||||||
log.append(hash + "\n");
|
log.append(hash + "\n");
|
||||||
System.out.println(hash);
|
System.out.println(hash);
|
||||||
}
|
}
|
||||||
if (tofile == true) {
|
if (tofile == true) {
|
||||||
logfile.append(hash + "\n");
|
logfile.append(hash + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String choose(String message, Object[] choicelist) {
|
public String choose(String message, Object[] choicelist) {
|
||||||
return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);
|
return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInput(String message) {
|
public String getInput(String message) {
|
||||||
return (String)JOptionPane.showInputDialog(message);
|
return (String)JOptionPane.showInputDialog(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
public String getFilepath(String title, int mode) {
|
public String getFilepath(String title, int mode) {
|
||||||
fc.setDialogTitle(title);
|
fc.setDialogTitle(title);
|
||||||
fc.setFileSelectionMode(mode);
|
fc.setFileSelectionMode(mode);
|
||||||
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||||
log.append(fc.getSelectedFile().getAbsolutePath() + "\n");
|
log.append(fc.getSelectedFile().getAbsolutePath() + "\n");
|
||||||
return fc.getSelectedFile().getAbsolutePath();
|
return fc.getSelectedFile().getAbsolutePath();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if ( e.getSource() == moduleButton ) {
|
if ( e.getSource() == moduleButton ) {
|
||||||
startpath = getFilepath("Please choose a starting path", JFileChooser.DIRECTORIES_ONLY);
|
startpath = getFilepath("Please choose a starting path", JFileChooser.DIRECTORIES_ONLY);
|
||||||
moduletext.setText(startpath);
|
moduletext.setText(startpath);
|
||||||
}
|
}
|
||||||
if ( e.getSource() == goButton ) {
|
if ( e.getSource() == goButton ) {
|
||||||
try {
|
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.strseparate, "$1") + File.separator + "migration.log")));
|
||||||
MigrationTool.startMigrateAll(startpath);
|
MigrationTool.startMigrateAll(startpath);
|
||||||
logfile.flush();
|
logfile.flush();
|
||||||
logfile.close();
|
logfile.close();
|
||||||
} catch (Exception en) {
|
} catch (Exception en) {
|
||||||
println(en.getMessage());
|
println(en.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( e.getSource() == msaEditorButton) {
|
if ( e.getSource() == msaEditorButton) {
|
||||||
try {
|
try {
|
||||||
MsaTreeEditor.init();
|
MsaTreeEditor.init();
|
||||||
} catch (Exception en) {
|
} catch (Exception en) {
|
||||||
println(en.getMessage());
|
println(en.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( e.getSource() == criticButton) {
|
if ( e.getSource() == criticButton) {
|
||||||
try {
|
try {
|
||||||
Critic.fireAt(startpath);
|
Critic.fireAt(startpath);
|
||||||
} catch (Exception en) {
|
} catch (Exception en) {
|
||||||
println(en.getMessage());
|
println(en.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( e.getSource() == specifyCommentButton) {
|
if ( e.getSource() == specifyCommentButton) {
|
||||||
try { // input examine is not imposed but should be added
|
try { // input examine is not imposed but should be added
|
||||||
MigrationTool.MIGRATIONCOMMENT = getInput("Please type in wanted comment style used by the tool\nbe sure to start with '//', or you won't enjoy the result");
|
MigrationTool.MIGRATIONCOMMENT = getInput("Please type in wanted comment style used by the tool\nbe sure to start with '//', or you won't enjoy the result");
|
||||||
//MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");
|
//MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");
|
||||||
} catch (Exception en) {
|
} catch (Exception en) {
|
||||||
println(en.getMessage());
|
println(en.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void itemStateChanged(ItemEvent e) {
|
public void itemStateChanged(ItemEvent e) {
|
||||||
if (e.getSource() == filebox) {
|
if (e.getSource() == filebox) {
|
||||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
System.out.println("filebox DESELECTED");
|
System.out.println("filebox DESELECTED");
|
||||||
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
System.out.println("filebox SELECTED");
|
System.out.println("filebox SELECTED");
|
||||||
}
|
}
|
||||||
} else if (e.getSource() == screenbox) {
|
} else if (e.getSource() == screenbox) {
|
||||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
System.out.println("screenbox DESELECTED");
|
System.out.println("screenbox DESELECTED");
|
||||||
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
System.out.println("screenbox SELECTED");
|
System.out.println("screenbox SELECTED");
|
||||||
}
|
}
|
||||||
} else if (e.getSource() == mibox) {
|
} else if (e.getSource() == mibox) {
|
||||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
MigrationTool.printModuleInfo = false;
|
MigrationTool.printModuleInfo = false;
|
||||||
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
MigrationTool.printModuleInfo = true;
|
MigrationTool.printModuleInfo = true;
|
||||||
}
|
}
|
||||||
} else if (e.getSource() == criticbox) {
|
} else if (e.getSource() == criticbox) {
|
||||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
MigrationTool.doCritic = false;
|
MigrationTool.doCritic = false;
|
||||||
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
MigrationTool.doCritic = true;
|
MigrationTool.doCritic = true;
|
||||||
}
|
}
|
||||||
} else if (e.getSource() == defaultpathbox) {
|
} else if (e.getSource() == defaultpathbox) {
|
||||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
MigrationTool.defaultoutput = false;
|
MigrationTool.defaultoutput = false;
|
||||||
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
MigrationTool.defaultoutput = true;
|
MigrationTool.defaultoutput = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
private static final FirstPanel init() {
|
private static final FirstPanel init() {
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
||||||
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
|
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
|
||||||
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
|
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
|
||||||
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
|
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
|
||||||
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
|
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
JFrame frame = new JFrame("MigrationTools");
|
JFrame frame = new JFrame("MigrationTools");
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
FirstPanel fp = new FirstPanel();
|
FirstPanel fp = new FirstPanel();
|
||||||
//fp.setLayout(new GridBagLayout());
|
//fp.setLayout(new GridBagLayout());
|
||||||
//fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
|
//fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
|
||||||
fp.setOpaque(true);
|
fp.setOpaque(true);
|
||||||
frame.setContentPane(fp);
|
frame.setContentPane(fp);
|
||||||
|
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final FirstPanel getInstance() {
|
public static final FirstPanel getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -15,50 +15,50 @@ package org.tianocore.migration;
|
|||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
|
|
||||||
public class Func {
|
public class Func {
|
||||||
Func(String r8func,String r8lib,String r9func,String r9lib) {
|
Func(String r8func,String r8lib,String r9func,String r9lib) {
|
||||||
r8funcname = r8func;
|
r8funcname = r8func;
|
||||||
r8libname = r8lib;
|
r8libname = r8lib;
|
||||||
r9funcname = r9func;
|
r9funcname = r9func;
|
||||||
r9libname = r9lib;
|
r9libname = r9lib;
|
||||||
}
|
}
|
||||||
Func(String[] linecontext) {
|
Func(String[] linecontext) {
|
||||||
r8funcname = linecontext[1];
|
r8funcname = linecontext[1];
|
||||||
r8libname = linecontext[0];
|
r8libname = linecontext[0];
|
||||||
r9funcname = linecontext[2];
|
r9funcname = linecontext[2];
|
||||||
r9libname = linecontext[3];
|
r9libname = linecontext[3];
|
||||||
}
|
}
|
||||||
public String r8funcname;
|
public String r8funcname;
|
||||||
public String r8libname;
|
public String r8libname;
|
||||||
public String r9funcname;
|
public String r9funcname;
|
||||||
public String r9libname;
|
public String r9libname;
|
||||||
|
|
||||||
public static Pattern ptnbrace = Pattern.compile("\\{[^\\{\\}]*\\}",Pattern.MULTILINE);
|
public static Pattern ptnbrace = Pattern.compile("\\{[^\\{\\}]*\\}",Pattern.MULTILINE);
|
||||||
//public static Pattern ptnfuncc = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)",Pattern.MULTILINE);
|
//public static Pattern ptnfuncc = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)",Pattern.MULTILINE);
|
||||||
public static Pattern ptnfuncc = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\(",Pattern.MULTILINE);
|
public static Pattern ptnfuncc = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\(",Pattern.MULTILINE);
|
||||||
public static Pattern ptnfuncd = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)\\s*@",Pattern.MULTILINE);
|
public static Pattern ptnfuncd = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)\\s*@",Pattern.MULTILINE);
|
||||||
public static Pattern ptnlowcase = Pattern.compile("[a-z]"); // must be removed
|
public static Pattern ptnlowcase = Pattern.compile("[a-z]"); // must be removed
|
||||||
|
|
||||||
private static String reservedwords = "if for pack while switch return sizeof";
|
private static String reservedwords = "if for pack while switch return sizeof";
|
||||||
|
|
||||||
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
||||||
String temp = null;
|
String temp = null;
|
||||||
|
|
||||||
temp = mtr.group(1); // both changed and not changed funcc are registered , for finding all the non-local function calls
|
temp = mtr.group(1); // both changed and not changed funcc are registered , for finding all the non-local function calls
|
||||||
Matcher mtrlowcase = ptnlowcase.matcher(temp); // must be removed , so the two funcs can be merged
|
Matcher mtrlowcase = ptnlowcase.matcher(temp); // must be removed , so the two funcs can be merged
|
||||||
if (!reservedwords.contains(temp) && mtrlowcase.find()) {
|
if (!reservedwords.contains(temp) && mtrlowcase.find()) {
|
||||||
mi.hashfuncc.add(temp);
|
mi.hashfuncc.add(temp);
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
public static String registerFuncD(Matcher mtr, ModuleInfo mi, Database db) {
|
public static String registerFuncD(Matcher mtr, ModuleInfo mi, Database db) {
|
||||||
String temp = null;
|
String temp = null;
|
||||||
|
|
||||||
temp = mtr.group(1); // both changed and not changed funcd are registered , for finding all the non-local function calls
|
temp = mtr.group(1); // both changed and not changed funcd are registered , for finding all the non-local function calls
|
||||||
if (!reservedwords.contains(temp)) {
|
if (!reservedwords.contains(temp)) {
|
||||||
mi.hashfuncd.add(temp);
|
mi.hashfuncd.add(temp);
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@@ -15,47 +15,47 @@ package org.tianocore.migration;
|
|||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
|
|
||||||
public class Guid {
|
public class Guid {
|
||||||
Guid (String r8, String t, String n, String r9, String gv, String p) {
|
Guid (String r8, String t, String n, String r9, String gv, String p) {
|
||||||
r8name = r8;
|
r8name = r8;
|
||||||
type = t;
|
type = t;
|
||||||
name = n;
|
name = n;
|
||||||
r9name = r9;
|
r9name = r9;
|
||||||
guidvalue = gv;
|
guidvalue = gv;
|
||||||
pack = p;
|
pack = p;
|
||||||
}
|
}
|
||||||
Guid (String[] linecontext, String t) {
|
Guid (String[] linecontext, String t) {
|
||||||
r8name = linecontext[1];
|
r8name = linecontext[1];
|
||||||
type = t;
|
type = t;
|
||||||
name = linecontext[0];
|
name = linecontext[0];
|
||||||
r9name = linecontext[2];
|
r9name = linecontext[2];
|
||||||
guidvalue = linecontext[3];
|
guidvalue = linecontext[3];
|
||||||
pack = linecontext[4];
|
pack = linecontext[4];
|
||||||
}
|
}
|
||||||
public String r8name;
|
public String r8name;
|
||||||
public String type;
|
public String type;
|
||||||
public String name;
|
public String name;
|
||||||
public String r9name;
|
public String r9name;
|
||||||
public String guidvalue;
|
public String guidvalue;
|
||||||
public String pack;
|
public String pack;
|
||||||
|
|
||||||
public static Pattern ptnguid = Pattern.compile("g\\w*Guid");
|
public static Pattern ptnguid = Pattern.compile("g\\w*Guid");
|
||||||
|
|
||||||
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
||||||
String type = null;
|
String type = null;
|
||||||
String temp = null;
|
String temp = null;
|
||||||
|
|
||||||
temp = mtr.group();
|
temp = mtr.group();
|
||||||
if (MigrationTool.db.hasGuid(temp)) { // only changed guids registered, because both changed and not changed guids are included in database
|
if (MigrationTool.db.hasGuid(temp)) { // only changed guids registered, because both changed and not changed guids are included in database
|
||||||
type = MigrationTool.db.getGuidType(temp);
|
type = MigrationTool.db.getGuidType(temp);
|
||||||
if (type.matches("Protocol")) {
|
if (type.matches("Protocol")) {
|
||||||
mi.protocol.add(temp);
|
mi.protocol.add(temp);
|
||||||
} else if (type.matches("Ppi")) {
|
} else if (type.matches("Ppi")) {
|
||||||
mi.ppi.add(temp);
|
mi.ppi.add(temp);
|
||||||
} else if (type.matches("Guid")) {
|
} else if (type.matches("Guid")) {
|
||||||
mi.guid.add(temp);
|
mi.guid.add(temp);
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -15,32 +15,32 @@ package org.tianocore.migration;
|
|||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
|
|
||||||
public class Macro {
|
public class Macro {
|
||||||
Macro(String r8, String r9) {
|
Macro(String r8, String r9) {
|
||||||
r8name = r8;
|
r8name = r8;
|
||||||
r9name = r9;
|
r9name = r9;
|
||||||
}
|
}
|
||||||
Macro(String[] linecontext) {
|
Macro(String[] linecontext) {
|
||||||
r8name = linecontext[0];
|
r8name = linecontext[0];
|
||||||
r9name = linecontext[1];
|
r9name = linecontext[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public String r8name;
|
public String r8name;
|
||||||
public String r9name;
|
public String r9name;
|
||||||
|
|
||||||
public static Pattern ptntmacro = Pattern.compile("\\b[A-Z_]+\\s*?\\(?\\b",Pattern.MULTILINE);
|
public static Pattern ptntmacro = Pattern.compile("\\b[A-Z_]+\\s*?\\(?\\b",Pattern.MULTILINE);
|
||||||
|
|
||||||
private static String unmacro = "VOID UINTN BOOLEAN ASSERT OPTIONAL STATIC NULL TRUE IN OUT FALSE";
|
private static String unmacro = "VOID UINTN BOOLEAN ASSERT OPTIONAL STATIC NULL TRUE IN OUT FALSE";
|
||||||
|
|
||||||
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
||||||
String temp = null;
|
String temp = null;
|
||||||
|
|
||||||
temp = mtr.group();
|
temp = mtr.group();
|
||||||
if (MigrationTool.db.hasMacro(temp)) { // only changed macros registered, because the database of macro has only changed ones
|
if (MigrationTool.db.hasMacro(temp)) { // only changed macros registered, because the database of macro has only changed ones
|
||||||
if (!unmacro.contains(temp)) {
|
if (!unmacro.contains(temp)) {
|
||||||
mi.hashnonlocalmacro.add(temp);
|
mi.hashnonlocalmacro.add(temp);
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -18,91 +18,91 @@ import java.util.*;
|
|||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
|
|
||||||
public class MigrationTool {
|
public class MigrationTool {
|
||||||
public static UI ui = null;
|
public static UI ui = null;
|
||||||
public static Database db = null;
|
public static Database db = null;
|
||||||
|
|
||||||
public static String MIGRATIONCOMMENT = "//%@//";
|
public static String MIGRATIONCOMMENT = "//%@//";
|
||||||
|
|
||||||
public static boolean printModuleInfo = false;
|
public static boolean printModuleInfo = false;
|
||||||
public static boolean doCritic = false;
|
public static boolean doCritic = false;
|
||||||
public static boolean defaultoutput = false;
|
public static boolean defaultoutput = false;
|
||||||
|
|
||||||
public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();
|
public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();
|
||||||
|
|
||||||
private static final void mainFlow(ModuleInfo mi) throws Exception {
|
private static final void mainFlow(ModuleInfo mi) throws Exception {
|
||||||
|
|
||||||
ModuleReader.ModuleScan(mi);
|
ModuleReader.ModuleScan(mi);
|
||||||
|
|
||||||
//MigrationTool.ui.yesOrNo("go on replace?");
|
//MigrationTool.ui.yesOrNo("go on replace?");
|
||||||
SourceFileReplacer.fireAt(mi); // some adding library actions are taken here,so it must be put before "MsaWriter"
|
SourceFileReplacer.fireAt(mi); // some adding library actions are taken here,so it must be put before "MsaWriter"
|
||||||
|
|
||||||
//MigrationTool.ui.yesOrNo("go on show?");
|
//MigrationTool.ui.yesOrNo("go on show?");
|
||||||
// show result
|
// show result
|
||||||
if (MigrationTool.printModuleInfo) {
|
if (MigrationTool.printModuleInfo) {
|
||||||
MigrationTool.ui.println("\nModule Information : ");
|
MigrationTool.ui.println("\nModule Information : ");
|
||||||
MigrationTool.ui.println("Entrypoint : " + mi.entrypoint);
|
MigrationTool.ui.println("Entrypoint : " + mi.entrypoint);
|
||||||
show(mi.protocol, "Protocol : ");
|
show(mi.protocol, "Protocol : ");
|
||||||
show(mi.ppi, "Ppi : ");
|
show(mi.ppi, "Ppi : ");
|
||||||
show(mi.guid, "Guid : ");
|
show(mi.guid, "Guid : ");
|
||||||
show(mi.hashfuncc, "call : ");
|
show(mi.hashfuncc, "call : ");
|
||||||
show(mi.hashfuncd, "def : ");
|
show(mi.hashfuncd, "def : ");
|
||||||
show(mi.hashEFIcall, "EFIcall : ");
|
show(mi.hashEFIcall, "EFIcall : ");
|
||||||
show(mi.hashnonlocalmacro, "macro : ");
|
show(mi.hashnonlocalmacro, "macro : ");
|
||||||
show(mi.hashnonlocalfunc, "nonlocal : ");
|
show(mi.hashnonlocalfunc, "nonlocal : ");
|
||||||
show(mi.hashr8only, "hashr8only : ");
|
show(mi.hashr8only, "hashr8only : ");
|
||||||
}
|
}
|
||||||
|
|
||||||
//MigrationTool.ui.yesOrNo("go on msawrite?");
|
//MigrationTool.ui.yesOrNo("go on msawrite?");
|
||||||
new MsaWriter(mi).flush();
|
new MsaWriter(mi).flush();
|
||||||
//MigrationTool.ui.yesOrNo("go on critic?");
|
//MigrationTool.ui.yesOrNo("go on critic?");
|
||||||
|
|
||||||
if (MigrationTool.doCritic) {
|
if (MigrationTool.doCritic) {
|
||||||
Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename);
|
Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename);
|
||||||
}
|
}
|
||||||
|
|
||||||
//MigrationTool.ui.yesOrNo("go on delete?");
|
//MigrationTool.ui.yesOrNo("go on delete?");
|
||||||
Common.deleteDir(mi.modulepath + File.separator + "temp");
|
Common.deleteDir(mi.modulepath + File.separator + "temp");
|
||||||
|
|
||||||
MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);
|
MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);
|
||||||
MigrationTool.ui.println("Complete!");
|
MigrationTool.ui.println("Complete!");
|
||||||
//MigrationTool.ui.println("Your R9 module was placed here: " + mi.modulepath + File.separator + "result");
|
//MigrationTool.ui.println("Your R9 module was placed here: " + mi.modulepath + File.separator + "result");
|
||||||
//MigrationTool.ui.println("Your logfile was placed here: " + mi.modulepath);
|
//MigrationTool.ui.println("Your logfile was placed here: " + mi.modulepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void show(Set<String> hash, String show) {
|
private static final void show(Set<String> hash, String show) {
|
||||||
MigrationTool.ui.println(show + hash.size());
|
MigrationTool.ui.println(show + hash.size());
|
||||||
MigrationTool.ui.println(hash);
|
MigrationTool.ui.println(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String assignOutPutPath(String inputpath) {
|
private static final String assignOutPutPath(String inputpath) {
|
||||||
if (MigrationTool.defaultoutput) {
|
if (MigrationTool.defaultoutput) {
|
||||||
return inputpath.replaceAll(Common.strseparate, "$1");
|
return inputpath.replaceAll(Common.strseparate, "$1");
|
||||||
} else {
|
} else {
|
||||||
return MigrationTool.ui.getFilepath("Please choose where to place the output module", JFileChooser.DIRECTORIES_ONLY);
|
return MigrationTool.ui.getFilepath("Please choose where to place the output module", JFileChooser.DIRECTORIES_ONLY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void seekModule(String filepath) throws Exception {
|
public static final void seekModule(String filepath) throws Exception {
|
||||||
if (ModuleInfo.isModule(filepath)) {
|
if (ModuleInfo.isModule(filepath)) {
|
||||||
ModuleInfoMap.put(new ModuleInfo(filepath), assignOutPutPath(filepath));
|
ModuleInfoMap.put(new ModuleInfo(filepath), assignOutPutPath(filepath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void startMigrateAll(String path) throws Exception {
|
public static final void startMigrateAll(String path) throws Exception {
|
||||||
MigrationTool.ui.println("Project Migration");
|
MigrationTool.ui.println("Project Migration");
|
||||||
MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");
|
MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");
|
||||||
Common.toDoAll(path, MigrationTool.class.getMethod("seekModule", String.class), null, null, Common.DIR);
|
Common.toDoAll(path, MigrationTool.class.getMethod("seekModule", String.class), null, null, Common.DIR);
|
||||||
|
|
||||||
Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();
|
Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();
|
||||||
while (miit.hasNext()) {
|
while (miit.hasNext()) {
|
||||||
mainFlow(miit.next());
|
mainFlow(miit.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleInfoMap.clear();
|
ModuleInfoMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
ui = FirstPanel.getInstance();
|
ui = FirstPanel.getInstance();
|
||||||
db = Database.getInstance();
|
db = Database.getInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,67 +16,67 @@ import java.io.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Class ModuleInfo is built for scanning the source files, it contains all the needed
|
Class ModuleInfo is built for scanning the source files, it contains all the needed
|
||||||
information and all the temporary data.
|
information and all the temporary data.
|
||||||
*/
|
*/
|
||||||
public final class ModuleInfo {
|
public final class ModuleInfo {
|
||||||
ModuleInfo(String modulepath) throws Exception {
|
ModuleInfo(String modulepath) throws Exception {
|
||||||
this.modulepath = modulepath;
|
this.modulepath = modulepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String modulepath;
|
public final String modulepath;
|
||||||
|
|
||||||
public String modulename = null;
|
public String modulename = null;
|
||||||
public String guidvalue = null;
|
public String guidvalue = null;
|
||||||
public String moduletype = null;
|
public String moduletype = null;
|
||||||
public String entrypoint = null;
|
public String entrypoint = null;
|
||||||
|
|
||||||
public final Set<String> localmodulesources = new HashSet<String>(); //contains both .c and .h
|
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> 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> msaorinf = new HashSet<String>(); //only a little, hash may be too big for this
|
||||||
|
|
||||||
public final Set<String> hashfuncc = new HashSet<String>();
|
public final Set<String> hashfuncc = new HashSet<String>();
|
||||||
public final Set<String> hashfuncd = new HashSet<String>();
|
public final Set<String> hashfuncd = new HashSet<String>();
|
||||||
public final Set<String> hashnonlocalfunc = new HashSet<String>();
|
public final Set<String> hashnonlocalfunc = new HashSet<String>();
|
||||||
public final Set<String> hashnonlocalmacro = new HashSet<String>();
|
public final Set<String> hashnonlocalmacro = new HashSet<String>();
|
||||||
public final Set<String> hashEFIcall = new HashSet<String>();
|
public final Set<String> hashEFIcall = new HashSet<String>();
|
||||||
public final Set<String> hashr8only = new HashSet<String>();
|
public final Set<String> hashr8only = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> hashrequiredr9libs = new HashSet<String>(); // hashrequiredr9libs is now all added in SourceFileReplacer
|
public final Set<String> hashrequiredr9libs = new HashSet<String>(); // hashrequiredr9libs is now all added in SourceFileReplacer
|
||||||
public final Set<String> guid = new HashSet<String>();
|
public final Set<String> guid = new HashSet<String>();
|
||||||
public final Set<String> protocol = new HashSet<String>();
|
public final Set<String> protocol = new HashSet<String>();
|
||||||
public final Set<String> ppi = new HashSet<String>();
|
public final Set<String> ppi = new HashSet<String>();
|
||||||
|
|
||||||
public final String getModuleType() {
|
public final String getModuleType() {
|
||||||
if (moduletype.contains("PEI")) {
|
if (moduletype.contains("PEI")) {
|
||||||
return "PEIM";
|
return "PEIM";
|
||||||
} else {
|
} else {
|
||||||
return "DXE_DRIVER";
|
return "DXE_DRIVER";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void enroll(String filepath) throws Exception {
|
public final void enroll(String filepath) throws Exception {
|
||||||
String temp = null;
|
String temp = null;
|
||||||
if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") ||
|
if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") ||
|
||||||
filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) {
|
filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) {
|
||||||
localmodulesources.add(filepath.replace(modulepath + File.separator, ""));
|
localmodulesources.add(filepath.replace(modulepath + File.separator, ""));
|
||||||
} else if (filepath.contains(".inf") || filepath.contains(".msa")) {
|
} else if (filepath.contains(".inf") || filepath.contains(".msa")) {
|
||||||
temp = filepath.replace(modulepath + File.separator, "");
|
temp = filepath.replace(modulepath + File.separator, "");
|
||||||
if (!temp.contains(File.separator)) { // .inf in subdirectory is not regarded
|
if (!temp.contains(File.separator)) { // .inf in subdirectory is not regarded
|
||||||
msaorinf.add(temp);
|
msaorinf.add(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final boolean isModule(String path) {
|
public static final boolean isModule(String path) {
|
||||||
String[] list = new File(path).list();
|
String[] list = new File(path).list();
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0 ; i < list.length ; i++) {
|
||||||
if (!new File(list[i]).isDirectory()) {
|
if (!new File(list[i]).isDirectory()) {
|
||||||
if (list[i].contains(".inf") || list[i].contains(".msa")) {
|
if (list[i].contains(".inf") || list[i].contains(".msa")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -19,257 +19,257 @@ import java.util.regex.*;
|
|||||||
import org.tianocore.*;
|
import org.tianocore.*;
|
||||||
|
|
||||||
public final class ModuleReader {
|
public final class ModuleReader {
|
||||||
private static ModuleInfo mi;
|
private static ModuleInfo mi;
|
||||||
|
|
||||||
private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\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 ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
|
||||||
private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");
|
private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");
|
||||||
|
|
||||||
public static final void ModuleScan(ModuleInfo m) throws Exception {
|
public static final void ModuleScan(ModuleInfo m) throws Exception {
|
||||||
mi = m;
|
mi = m;
|
||||||
|
|
||||||
Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll", String.class), mi, null, Common.FILE);
|
Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll", String.class), mi, null, Common.FILE);
|
||||||
|
|
||||||
String filename = null;
|
String filename = null;
|
||||||
if (mi.msaorinf.isEmpty()) {
|
if (mi.msaorinf.isEmpty()) {
|
||||||
MigrationTool.ui.println("No INF nor MSA file found!");
|
MigrationTool.ui.println("No INF nor MSA file found!");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
} else {
|
} else {
|
||||||
if (mi.msaorinf.size() == 1) {
|
if (mi.msaorinf.size() == 1) {
|
||||||
filename = (String)mi.msaorinf.toArray()[0];
|
filename = (String)mi.msaorinf.toArray()[0];
|
||||||
} else {
|
} else {
|
||||||
filename = MigrationTool.ui.choose("Found .inf or .msa file for module\n" + mi.modulepath + "\nChoose one Please", mi.msaorinf.toArray());
|
filename = MigrationTool.ui.choose("Found .inf or .msa file for module\n" + mi.modulepath + "\nChoose one Please", mi.msaorinf.toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename.contains(".inf")) {
|
if (filename.contains(".inf")) {
|
||||||
readInf(filename);
|
readInf(filename);
|
||||||
} else if (filename.contains(".msa")) {
|
} else if (filename.contains(".msa")) {
|
||||||
readMsa(filename);
|
readMsa(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommentOutNonLocalHFile();
|
CommentOutNonLocalHFile();
|
||||||
parsePreProcessedSourceCode();
|
parsePreProcessedSourceCode();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void readMsa(String name) throws Exception {
|
private static final void readMsa(String name) throws Exception {
|
||||||
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));
|
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));
|
||||||
ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();
|
ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();
|
||||||
MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
|
MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
|
||||||
|
|
||||||
mi.modulename = msaheader.getModuleName();
|
mi.modulename = msaheader.getModuleName();
|
||||||
mi.guidvalue = msaheader.getGuidValue();
|
mi.guidvalue = msaheader.getGuidValue();
|
||||||
mi.moduletype = msaheader.getModuleType().toString(); // ???
|
mi.moduletype = msaheader.getModuleType().toString(); // ???
|
||||||
|
|
||||||
SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();
|
SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();
|
||||||
|
|
||||||
String temp;
|
String temp;
|
||||||
Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();
|
Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();
|
||||||
while (li.hasNext()) {
|
while (li.hasNext()) {
|
||||||
if (!mi.localmodulesources.contains(temp = li.next().toString())) {
|
if (!mi.localmodulesources.contains(temp = li.next().toString())) {
|
||||||
System.out.println("Source File Missing! : " + temp);
|
System.out.println("Source File Missing! : " + temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void readInf(String name) throws Exception {
|
private static final void readInf(String name) throws Exception {
|
||||||
System.out.println("\nParsing INF file: " + name);
|
System.out.println("\nParsing INF file: " + name);
|
||||||
String wholeline;
|
String wholeline;
|
||||||
Matcher mtrinfequation;
|
Matcher mtrinfequation;
|
||||||
Matcher mtrsection;
|
Matcher mtrsection;
|
||||||
Matcher mtrfilename;
|
Matcher mtrfilename;
|
||||||
|
|
||||||
wholeline = Common.file2string(mi.modulepath + File.separator + name);
|
wholeline = Common.file2string(mi.modulepath + File.separator + name);
|
||||||
mtrsection = ptnsection.matcher(wholeline);
|
mtrsection = ptnsection.matcher(wholeline);
|
||||||
while (mtrsection.find()) {
|
while (mtrsection.find()) {
|
||||||
if (mtrsection.group(1).matches("defines")) {
|
if (mtrsection.group(1).matches("defines")) {
|
||||||
mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
|
mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
|
||||||
while (mtrinfequation.find()) {
|
while (mtrinfequation.find()) {
|
||||||
if (mtrinfequation.group(1).matches("BASE_NAME")) {
|
if (mtrinfequation.group(1).matches("BASE_NAME")) {
|
||||||
mi.modulename = mtrinfequation.group(2);
|
mi.modulename = mtrinfequation.group(2);
|
||||||
}
|
}
|
||||||
if (mtrinfequation.group(1).matches("FILE_GUID")) {
|
if (mtrinfequation.group(1).matches("FILE_GUID")) {
|
||||||
mi.guidvalue = mtrinfequation.group(2);
|
mi.guidvalue = mtrinfequation.group(2);
|
||||||
}
|
}
|
||||||
if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {
|
if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {
|
||||||
mi.moduletype = mtrinfequation.group(2);
|
mi.moduletype = mtrinfequation.group(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mtrsection.group(1).matches("nmake.common")) {
|
if (mtrsection.group(1).matches("nmake.common")) {
|
||||||
mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
|
mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
|
||||||
while (mtrinfequation.find()) {
|
while (mtrinfequation.find()) {
|
||||||
if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {
|
if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {
|
||||||
mi.entrypoint = mtrinfequation.group(2);
|
mi.entrypoint = mtrinfequation.group(2);
|
||||||
}
|
}
|
||||||
if (mtrinfequation.group(1).matches("DPX_SOURCE")) {
|
if (mtrinfequation.group(1).matches("DPX_SOURCE")) {
|
||||||
if (!mi.localmodulesources.contains(mtrinfequation.group(2))) {
|
if (!mi.localmodulesources.contains(mtrinfequation.group(2))) {
|
||||||
MigrationTool.ui.println("DPX File Missing! : " + mtrinfequation.group(2));
|
MigrationTool.ui.println("DPX File Missing! : " + mtrinfequation.group(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mtrsection.group(1).contains("sources.")) {
|
if (mtrsection.group(1).contains("sources.")) {
|
||||||
mtrfilename = ptnfilename.matcher(mtrsection.group(2));
|
mtrfilename = ptnfilename.matcher(mtrsection.group(2));
|
||||||
while (mtrfilename.find()) {
|
while (mtrfilename.find()) {
|
||||||
if (!mi.localmodulesources.contains(mtrfilename.group())) {
|
if (!mi.localmodulesources.contains(mtrfilename.group())) {
|
||||||
MigrationTool.ui.println("Source File Missing! : " + mtrfilename.group());
|
MigrationTool.ui.println("Source File Missing! : " + mtrfilename.group());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add '//' to all non-local include lines
|
// add '//' to all non-local include lines
|
||||||
private static final void CommentOutNonLocalHFile() throws IOException {
|
private static final void CommentOutNonLocalHFile() throws IOException {
|
||||||
BufferedReader rd;
|
BufferedReader rd;
|
||||||
String line;
|
String line;
|
||||||
String curFile;
|
String curFile;
|
||||||
PrintWriter outfile;
|
PrintWriter outfile;
|
||||||
|
|
||||||
Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");
|
Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");
|
||||||
Matcher mtrinclude;
|
Matcher mtrinclude;
|
||||||
|
|
||||||
Iterator<String> ii = mi.localmodulesources.iterator();
|
Iterator<String> ii = mi.localmodulesources.iterator();
|
||||||
while ( ii.hasNext() ) {
|
while ( ii.hasNext() ) {
|
||||||
curFile = ii.next();
|
curFile = ii.next();
|
||||||
rd = new BufferedReader(new FileReader(mi.modulepath + File.separator + curFile));
|
rd = new BufferedReader(new FileReader(mi.modulepath + File.separator + curFile));
|
||||||
Common.ensureDir(mi.modulepath + File.separator + "temp" + 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)));
|
outfile = new PrintWriter(new BufferedWriter(new FileWriter(mi.modulepath + File.separator + "temp" + File.separator + curFile)));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (curFile.contains(".dxs")) {
|
if (curFile.contains(".dxs")) {
|
||||||
if (mi.moduletype.contains("PEI")) {
|
if (mi.moduletype.contains("PEI")) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.contains("#include")) {
|
if (line.contains("#include")) {
|
||||||
mtrinclude = ptninclude.matcher(line);
|
mtrinclude = ptninclude.matcher(line);
|
||||||
if (mtrinclude.find() && mi.localmodulesources.contains(mtrinclude.group(1))) {
|
if (mtrinclude.find() && mi.localmodulesources.contains(mtrinclude.group(1))) {
|
||||||
} else {
|
} else {
|
||||||
line = MigrationTool.MIGRATIONCOMMENT + line;
|
line = MigrationTool.MIGRATIONCOMMENT + line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outfile.append(line + '\n');
|
outfile.append(line + '\n');
|
||||||
}
|
}
|
||||||
outfile.flush();
|
outfile.flush();
|
||||||
outfile.close();
|
outfile.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void parsePreProcessedSourceCode() throws Exception {
|
private static final void parsePreProcessedSourceCode() throws Exception {
|
||||||
//Cl cl = new Cl(modulepath);
|
//Cl cl = new Cl(modulepath);
|
||||||
//cl.execute("Fat.c");
|
//cl.execute("Fat.c");
|
||||||
//cl.generateAll(preprocessedccodes);
|
//cl.generateAll(preprocessedccodes);
|
||||||
//
|
//
|
||||||
//System.out.println("Note!!!! The CL is not implemented now , pls do it manually!!! RUN :");
|
//System.out.println("Note!!!! The CL is not implemented now , pls do it manually!!! RUN :");
|
||||||
//System.out.println("cl " + modulepath + "\\temp\\*.c" + " -P");
|
//System.out.println("cl " + modulepath + "\\temp\\*.c" + " -P");
|
||||||
//String[] list = new File(modulepath + File.separator + "temp").list(); // without CL , add
|
//String[] list = new File(modulepath + File.separator + "temp").list(); // without CL , add
|
||||||
BufferedReader rd = null;
|
BufferedReader rd = null;
|
||||||
String ifile = null;
|
String ifile = null;
|
||||||
String line = null;
|
String line = null;
|
||||||
String temp = null;
|
String temp = null;
|
||||||
|
|
||||||
Iterator<String> ii = mi.localmodulesources.iterator();
|
Iterator<String> ii = mi.localmodulesources.iterator();
|
||||||
while (ii.hasNext()) {
|
while (ii.hasNext()) {
|
||||||
temp = ii.next();
|
temp = ii.next();
|
||||||
if (temp.contains(".c")) {
|
if (temp.contains(".c")) {
|
||||||
mi.preprocessedccodes.add(temp);
|
mi.preprocessedccodes.add(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ii = mi.preprocessedccodes.iterator();
|
ii = mi.preprocessedccodes.iterator();
|
||||||
|
|
||||||
Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE);
|
Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE);
|
||||||
Pattern patentrypoint = Pattern.compile("EFI_([A-Z]*)_ENTRY_POINT\\s*\\(([^\\(\\)]*)\\)",Pattern.MULTILINE);
|
Pattern patentrypoint = Pattern.compile("EFI_([A-Z]*)_ENTRY_POINT\\s*\\(([^\\(\\)]*)\\)",Pattern.MULTILINE);
|
||||||
Matcher matguid;
|
Matcher matguid;
|
||||||
Matcher matfuncc;
|
Matcher matfuncc;
|
||||||
Matcher matfuncd;
|
Matcher matfuncd;
|
||||||
Matcher matenclosereplace;
|
Matcher matenclosereplace;
|
||||||
Matcher matefifuncc;
|
Matcher matefifuncc;
|
||||||
Matcher matentrypoint;
|
Matcher matentrypoint;
|
||||||
Matcher matmacro;
|
Matcher matmacro;
|
||||||
|
|
||||||
while (ii.hasNext()) {
|
while (ii.hasNext()) {
|
||||||
StringBuffer wholefile = new StringBuffer();
|
StringBuffer wholefile = new StringBuffer();
|
||||||
ifile = ii.next();
|
ifile = ii.next();
|
||||||
rd = new BufferedReader(new FileReader(mi.modulepath + File.separator + "temp" + File.separator + ifile));
|
rd = new BufferedReader(new FileReader(mi.modulepath + File.separator + "temp" + File.separator + ifile));
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
wholefile.append(line + '\n');
|
wholefile.append(line + '\n');
|
||||||
}
|
}
|
||||||
line = wholefile.toString();
|
line = wholefile.toString();
|
||||||
|
|
||||||
// if this is a Pei phase module , add these library class to .msa
|
// if this is a Pei phase module , add these library class to .msa
|
||||||
matentrypoint = patentrypoint.matcher(line);
|
matentrypoint = patentrypoint.matcher(line);
|
||||||
if (matentrypoint.find()) {
|
if (matentrypoint.find()) {
|
||||||
mi.entrypoint = matentrypoint.group(2);
|
mi.entrypoint = matentrypoint.group(2);
|
||||||
if (matentrypoint.group(1).matches("PEIM")) {
|
if (matentrypoint.group(1).matches("PEIM")) {
|
||||||
mi.hashrequiredr9libs.add("PeimEntryPoint");
|
mi.hashrequiredr9libs.add("PeimEntryPoint");
|
||||||
} else {
|
} else {
|
||||||
mi.hashrequiredr9libs.add("UefiDriverEntryPoint");
|
mi.hashrequiredr9libs.add("UefiDriverEntryPoint");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find guid
|
// find guid
|
||||||
matguid = Guid.ptnguid.matcher(line); // several ways to implement this , which one is faster ? :
|
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
|
while (matguid.find()) { // 1.currently , find once , then call to identify which is it
|
||||||
if ((temp = Guid.register(matguid, mi, MigrationTool.db)) != null) { // 2.use 3 different matchers , search 3 times to find each
|
if ((temp = Guid.register(matguid, mi, MigrationTool.db)) != null) { // 2.use 3 different matchers , search 3 times to find each
|
||||||
//matguid.appendReplacement(result, MigrationTool.db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost
|
//matguid.appendReplacement(result, MigrationTool.db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//matguid.appendTail(result);
|
//matguid.appendTail(result);
|
||||||
//line = result.toString();
|
//line = result.toString();
|
||||||
|
|
||||||
// find EFI call in form of '->' , many 'gUnicodeCollationInterface->' like things are not changed
|
// find EFI call in form of '->' , many 'gUnicodeCollationInterface->' like things are not changed
|
||||||
// This item is not simply replaced , special operation is required.
|
// This item is not simply replaced , special operation is required.
|
||||||
matefifuncc = patefifuncc.matcher(line);
|
matefifuncc = patefifuncc.matcher(line);
|
||||||
while (matefifuncc.find()) {
|
while (matefifuncc.find()) {
|
||||||
mi.hashEFIcall.add(matefifuncc.group(2));
|
mi.hashEFIcall.add(matefifuncc.group(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// find function call
|
// find function call
|
||||||
matfuncc = Func.ptnfuncc.matcher(line);
|
matfuncc = Func.ptnfuncc.matcher(line);
|
||||||
while (matfuncc.find()) {
|
while (matfuncc.find()) {
|
||||||
if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) {
|
if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) {
|
||||||
//MigrationTool.ui.println(ifile + " dofunc " + temp);
|
//MigrationTool.ui.println(ifile + " dofunc " + temp);
|
||||||
//matfuncc.appendReplacement(result, MigrationTool.db.getR9Func(temp));
|
//matfuncc.appendReplacement(result, MigrationTool.db.getR9Func(temp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//matfuncc.appendTail(result);
|
//matfuncc.appendTail(result);
|
||||||
//line = result.toString();
|
//line = result.toString();
|
||||||
|
|
||||||
// find macro
|
// find macro
|
||||||
matmacro = Macro.ptntmacro.matcher(line);
|
matmacro = Macro.ptntmacro.matcher(line);
|
||||||
while (matmacro.find()) {
|
while (matmacro.find()) {
|
||||||
if ((temp = Macro.register(matmacro, mi, MigrationTool.db)) != null) {
|
if ((temp = Macro.register(matmacro, mi, MigrationTool.db)) != null) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find function definition
|
// find function definition
|
||||||
// replace all {} to @
|
// replace all {} to @
|
||||||
while ((matenclosereplace = Func.ptnbrace.matcher(line)).find()) {
|
while ((matenclosereplace = Func.ptnbrace.matcher(line)).find()) {
|
||||||
line = matenclosereplace.replaceAll("@");
|
line = matenclosereplace.replaceAll("@");
|
||||||
}
|
}
|
||||||
|
|
||||||
matfuncd = Func.ptnfuncd.matcher(line);
|
matfuncd = Func.ptnfuncd.matcher(line);
|
||||||
while (matfuncd.find()) {
|
while (matfuncd.find()) {
|
||||||
if ((temp = Func.register(matfuncd, mi, MigrationTool.db)) != null) {
|
if ((temp = Func.register(matfuncd, mi, MigrationTool.db)) != null) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// op on hash
|
// op on hash
|
||||||
Iterator<String> funcci = mi.hashfuncc.iterator();
|
Iterator<String> funcci = mi.hashfuncc.iterator();
|
||||||
while (funcci.hasNext()) {
|
while (funcci.hasNext()) {
|
||||||
if (!mi.hashfuncd.contains(temp = funcci.next()) && !mi.hashEFIcall.contains(temp)) {
|
if (!mi.hashfuncd.contains(temp = funcci.next()) && !mi.hashEFIcall.contains(temp)) {
|
||||||
mi.hashnonlocalfunc.add(temp); // this set contains both changed and not changed items
|
mi.hashnonlocalfunc.add(temp); // this set contains both changed and not changed items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,19 +8,19 @@ import javax.xml.parsers.*;
|
|||||||
import org.w3c.dom.*;
|
import org.w3c.dom.*;
|
||||||
|
|
||||||
public class MsaTreeEditor extends JPanel {
|
public class MsaTreeEditor extends JPanel {
|
||||||
/**
|
/**
|
||||||
* Define class Serial Version UID
|
* Define class Serial Version UID
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 3169905938472150649L;
|
private static final long serialVersionUID = 3169905938472150649L;
|
||||||
|
|
||||||
private
|
private
|
||||||
/*
|
/*
|
||||||
MsaTreeEditor(ModuleInfo m, UI u, ModuleSurfaceAreaDocument md) {
|
MsaTreeEditor(ModuleInfo m, UI u, ModuleSurfaceAreaDocument md) {
|
||||||
mi = m;
|
mi = m;
|
||||||
ui = u;
|
ui = u;
|
||||||
msadoc = md;
|
msadoc = md;
|
||||||
|
|
||||||
//rootNode = msadoc.getDomNode();
|
//rootNode = msadoc.getDomNode();
|
||||||
rootNode = new DefaultMutableTreeNode("Root Node");
|
rootNode = new DefaultMutableTreeNode("Root Node");
|
||||||
treeModel = new DefaultTreeModel(rootNode);
|
treeModel = new DefaultTreeModel(rootNode);
|
||||||
|
|
||||||
@@ -43,9 +43,9 @@ public class MsaTreeEditor extends JPanel {
|
|||||||
|
|
||||||
addNode(rootNode, "1st");
|
addNode(rootNode, "1st");
|
||||||
addNode(rootNode, "2nd");
|
addNode(rootNode, "2nd");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
MsaTreeEditor() throws Exception {
|
MsaTreeEditor() throws Exception {
|
||||||
rootNode = new DefaultMutableTreeNode("Root Node");
|
rootNode = new DefaultMutableTreeNode("Root Node");
|
||||||
treeModel = new DefaultTreeModel(rootNode);
|
treeModel = new DefaultTreeModel(rootNode);
|
||||||
|
|
||||||
@@ -70,92 +70,92 @@ public class MsaTreeEditor extends JPanel {
|
|||||||
menuitemdel.addActionListener(actionListener);
|
menuitemdel.addActionListener(actionListener);
|
||||||
menuitemedit.addActionListener(actionListener);
|
menuitemedit.addActionListener(actionListener);
|
||||||
|
|
||||||
genDomTree(MigrationTool.ui.getFilepath("Select a msa file", JFileChooser.FILES_AND_DIRECTORIES));
|
genDomTree(MigrationTool.ui.getFilepath("Select a msa file", JFileChooser.FILES_AND_DIRECTORIES));
|
||||||
}
|
}
|
||||||
|
|
||||||
//private ModuleSurfaceAreaDocument msadoc;
|
//private ModuleSurfaceAreaDocument msadoc;
|
||||||
|
|
||||||
private JTree tree;
|
private JTree tree;
|
||||||
private DefaultMutableTreeNode rootNode;
|
private DefaultMutableTreeNode rootNode;
|
||||||
private DefaultTreeModel treeModel;
|
private DefaultTreeModel treeModel;
|
||||||
private JMenuItem menuitemadd, menuitemdel, menuitemedit;
|
private JMenuItem menuitemadd, menuitemdel, menuitemedit;
|
||||||
|
|
||||||
private JPopupMenu popupmenu;
|
private JPopupMenu popupmenu;
|
||||||
private MouseAdapter mouseadapter = new MouseAdapter() {
|
private MouseAdapter mouseadapter = new MouseAdapter() {
|
||||||
public void mouseReleased(MouseEvent me) {
|
public void mouseReleased(MouseEvent me) {
|
||||||
if (me.getClickCount() == 1 && SwingUtilities.isRightMouseButton(me)) {
|
if (me.getClickCount() == 1 && SwingUtilities.isRightMouseButton(me)) {
|
||||||
tree.setSelectionPath(tree.getPathForLocation(me.getX(), me.getY()));
|
tree.setSelectionPath(tree.getPathForLocation(me.getX(), me.getY()));
|
||||||
popupmenu.show(tree, me.getX(), me.getY());
|
popupmenu.show(tree, me.getX(), me.getY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private ActionListener actionListener = new ActionListener() {
|
private ActionListener actionListener = new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ae) {
|
public void actionPerformed(ActionEvent ae) {
|
||||||
if (ae.getSource() == menuitemadd) {
|
if (ae.getSource() == menuitemadd) {
|
||||||
addNode();
|
addNode();
|
||||||
} else if (ae.getSource() == menuitemdel) {
|
} else if (ae.getSource() == menuitemdel) {
|
||||||
delNode();
|
delNode();
|
||||||
} else if (ae.getSource() == menuitemedit) {
|
} else if (ae.getSource() == menuitemedit) {
|
||||||
editNode();
|
editNode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void editNode() {
|
private void editNode() {
|
||||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent());
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent());
|
||||||
Element element = (Element)node.getUserObject();
|
Element element = (Element)node.getUserObject();
|
||||||
System.out.println(element.getTextContent());
|
System.out.println(element.getTextContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void delNode() {
|
private void delNode() {
|
||||||
treeModel.removeNodeFromParent((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()));
|
treeModel.removeNodeFromParent((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNode() {
|
private void addNode() {
|
||||||
addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), MigrationTool.ui.getInput("Input Node Name"));
|
addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), MigrationTool.ui.getInput("Input Node Name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, Object child) {
|
private DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, Object child) {
|
||||||
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
|
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
|
||||||
treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());
|
treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());
|
||||||
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
|
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
|
||||||
return childNode;
|
return childNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void handleNode(Node node, DefaultMutableTreeNode parentNode) {
|
private final void handleNode(Node node, DefaultMutableTreeNode parentNode) {
|
||||||
DefaultMutableTreeNode curNode = null;
|
DefaultMutableTreeNode curNode = null;
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
System.out.println("elem");
|
System.out.println("elem");
|
||||||
curNode = addNode(parentNode, node);
|
curNode = addNode(parentNode, node);
|
||||||
} else if (node.getNodeType() == Node.DOCUMENT_NODE){
|
} else if (node.getNodeType() == Node.DOCUMENT_NODE){
|
||||||
System.out.println("doc");
|
System.out.println("doc");
|
||||||
curNode = addNode(parentNode, "MsaDocum"); // can Docum be with Root Node?
|
curNode = addNode(parentNode, "MsaDocum"); // can Docum be with Root Node?
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeList nodelist = node.getChildNodes();
|
NodeList nodelist = node.getChildNodes();
|
||||||
for (int i = 0; i < nodelist.getLength(); i++) {
|
for (int i = 0; i < nodelist.getLength(); i++) {
|
||||||
handleNode(nodelist.item(i), curNode);
|
handleNode(nodelist.item(i), curNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void genDomTree(String filename) throws Exception {
|
private final void genDomTree(String filename) throws Exception {
|
||||||
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
Document document = builder.parse(filename);
|
Document document = builder.parse(filename);
|
||||||
handleNode(document, rootNode);
|
handleNode(document, rootNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void init() throws Exception {
|
public static final void init() throws Exception {
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
|
||||||
JFrame frame = new JFrame("MsaTreeEditor");
|
JFrame frame = new JFrame("MsaTreeEditor");
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
MsaTreeEditor mte = new MsaTreeEditor();
|
MsaTreeEditor mte = new MsaTreeEditor();
|
||||||
mte.setLayout(new GridBagLayout());
|
mte.setLayout(new GridBagLayout());
|
||||||
mte.setOpaque(true);
|
mte.setOpaque(true);
|
||||||
frame.setContentPane(mte);
|
frame.setContentPane(mte);
|
||||||
|
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -20,163 +20,163 @@ import org.tianocore.SupportedArchitectures.Enum;
|
|||||||
import org.apache.xmlbeans.*;
|
import org.apache.xmlbeans.*;
|
||||||
|
|
||||||
public class MsaWriter {
|
public class MsaWriter {
|
||||||
MsaWriter(ModuleInfo moduleinfo) {
|
MsaWriter(ModuleInfo moduleinfo) {
|
||||||
mi = moduleinfo;
|
mi = moduleinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();
|
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();
|
private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();
|
||||||
private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();
|
private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();
|
||||||
private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();
|
private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();
|
||||||
private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles(); //found local .h files are not written
|
private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles(); //found local .h files are not written
|
||||||
private GuidsDocument.Guids guids;
|
private GuidsDocument.Guids guids;
|
||||||
private ProtocolsDocument.Protocols protocols;
|
private ProtocolsDocument.Protocols protocols;
|
||||||
private PPIsDocument.PPIs ppis;
|
private PPIsDocument.PPIs ppis;
|
||||||
private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();
|
private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();
|
||||||
private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();
|
private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();
|
||||||
private ExternsDocument.Externs externs = msa.addNewExterns();
|
private ExternsDocument.Externs externs = msa.addNewExterns();
|
||||||
|
|
||||||
private String Query (String requirement) throws Exception {
|
private String Query (String requirement) throws Exception {
|
||||||
String answer;
|
String answer;
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
|
||||||
System.out.println(requirement);
|
System.out.println(requirement);
|
||||||
while ((answer = rd.readLine()).length() == 0) ;
|
while ((answer = rd.readLine()).length() == 0) ;
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSourceFiles (String name) { // furthur modification needed
|
private void addSourceFiles (String name) { // furthur modification needed
|
||||||
List<Enum> arch = new ArrayList<Enum>();
|
List<Enum> arch = new ArrayList<Enum>();
|
||||||
FilenameDocument.Filename filename;
|
FilenameDocument.Filename filename;
|
||||||
filename = sourcefiles.addNewFilename();
|
filename = sourcefiles.addNewFilename();
|
||||||
filename.setStringValue(name);
|
filename.setStringValue(name);
|
||||||
|
|
||||||
if (name.contains("x64" + File.separator)) { // filename ???
|
if (name.contains("x64" + File.separator)) { // filename ???
|
||||||
arch.add(SupportedArchitectures.X_64);
|
arch.add(SupportedArchitectures.X_64);
|
||||||
System.out.println("x64" + File.separator);
|
System.out.println("x64" + File.separator);
|
||||||
filename.setSupArchList(arch);
|
filename.setSupArchList(arch);
|
||||||
} else if (name.contains("Ia32" + File.separator)) { // filename ???
|
} else if (name.contains("Ia32" + File.separator)) { // filename ???
|
||||||
arch.add(SupportedArchitectures.IA_32);
|
arch.add(SupportedArchitectures.IA_32);
|
||||||
System.out.println("Ia32" + File.separator);
|
System.out.println("Ia32" + File.separator);
|
||||||
filename.setSupArchList(arch);
|
filename.setSupArchList(arch);
|
||||||
} else if (name.contains("Ipf" + File.separator)) { // filename ???
|
} else if (name.contains("Ipf" + File.separator)) { // filename ???
|
||||||
arch.add(SupportedArchitectures.IPF);
|
arch.add(SupportedArchitectures.IPF);
|
||||||
System.out.println("Ipf" + File.separator);
|
System.out.println("Ipf" + File.separator);
|
||||||
filename.setSupArchList(arch);
|
filename.setSupArchList(arch);
|
||||||
} else if (name.contains("Ebc" + File.separator)) { // filename ???
|
} else if (name.contains("Ebc" + File.separator)) { // filename ???
|
||||||
arch.add(SupportedArchitectures.EBC);
|
arch.add(SupportedArchitectures.EBC);
|
||||||
System.out.println("Ebc" + File.separator);
|
System.out.println("Ebc" + File.separator);
|
||||||
filename.setSupArchList(arch);
|
filename.setSupArchList(arch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {
|
private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {
|
||||||
Iterator<String> it;
|
Iterator<String> it;
|
||||||
String temp;
|
String temp;
|
||||||
|
|
||||||
if (mi.modulename != null) {
|
if (mi.modulename != null) {
|
||||||
msaheader.setModuleName(mi.modulename);
|
msaheader.setModuleName(mi.modulename);
|
||||||
} else {
|
} else {
|
||||||
msaheader.setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));
|
msaheader.setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));
|
||||||
}
|
}
|
||||||
if (mi.guidvalue == null) {
|
if (mi.guidvalue == null) {
|
||||||
mi.guidvalue = UUID.randomUUID().toString();
|
mi.guidvalue = UUID.randomUUID().toString();
|
||||||
MigrationTool.ui.println ("Guid value can not be retrieved from inf file. Generate " + mi.guidvalue + " at random!");
|
MigrationTool.ui.println ("Guid value can not be retrieved from inf file. Generate " + mi.guidvalue + " at random!");
|
||||||
}
|
}
|
||||||
msaheader.setGuidValue(mi.guidvalue);
|
msaheader.setGuidValue(mi.guidvalue);
|
||||||
if (mi.moduletype != null) {
|
if (mi.moduletype != null) {
|
||||||
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));
|
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));
|
||||||
/*
|
/*
|
||||||
if (mi.moduletype.contains("PEI")) {
|
if (mi.moduletype.contains("PEI")) {
|
||||||
msaheader.setModuleType(ModuleTypeDef.Enum.forString("PEIM"));
|
msaheader.setModuleType(ModuleTypeDef.Enum.forString("PEIM"));
|
||||||
} else {
|
} else {
|
||||||
msaheader.setModuleType(ModuleTypeDef.Enum.forString("DXE_DRIVER"));
|
msaheader.setModuleType(ModuleTypeDef.Enum.forString("DXE_DRIVER"));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));
|
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));
|
||||||
}
|
}
|
||||||
|
|
||||||
msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");
|
msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");
|
||||||
msaheader.setVersion("1.0");
|
msaheader.setVersion("1.0");
|
||||||
msaheader.setAbstract("Component name for module " + mi.modulename);
|
msaheader.setAbstract("Component name for module " + mi.modulename);
|
||||||
msaheader.setDescription("FIX ME!");
|
msaheader.setDescription("FIX ME!");
|
||||||
msaheader.addNewLicense().setStringValue("All rights reserved.\n" +
|
msaheader.addNewLicense().setStringValue("All rights reserved.\n" +
|
||||||
" This software and associated documentation (if any) is furnished\n" +
|
" This software and associated documentation (if any) is furnished\n" +
|
||||||
" under a license and may only be used or copied in accordance\n" +
|
" under a license and may only be used or copied in accordance\n" +
|
||||||
" with the terms of the license. Except as permitted by such\n" +
|
" with the terms of the license. Except as permitted by such\n" +
|
||||||
" license, no part of this software or documentation may be\n" +
|
" license, no part of this software or documentation may be\n" +
|
||||||
" reproduced, stored in a retrieval system, or transmitted in any\n" +
|
" reproduced, stored in a retrieval system, or transmitted in any\n" +
|
||||||
" form or by any means without the express written consent of\n" +
|
" form or by any means without the express written consent of\n" +
|
||||||
" Intel Corporation.");
|
" Intel Corporation.");
|
||||||
msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
|
msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
|
||||||
|
|
||||||
List<Enum> arch = new ArrayList<Enum>();
|
List<Enum> arch = new ArrayList<Enum>();
|
||||||
arch.add(SupportedArchitectures.IA_32);
|
arch.add(SupportedArchitectures.IA_32);
|
||||||
arch.add(SupportedArchitectures.X_64);
|
arch.add(SupportedArchitectures.X_64);
|
||||||
arch.add(SupportedArchitectures.IPF);
|
arch.add(SupportedArchitectures.IPF);
|
||||||
arch.add(SupportedArchitectures.EBC);
|
arch.add(SupportedArchitectures.EBC);
|
||||||
md.setSupportedArchitectures(arch);
|
md.setSupportedArchitectures(arch);
|
||||||
md.setBinaryModule(false);
|
md.setBinaryModule(false);
|
||||||
md.setOutputFileBasename(mi.modulename);
|
md.setOutputFileBasename(mi.modulename);
|
||||||
|
|
||||||
pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");
|
pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");
|
||||||
externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");
|
externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");
|
||||||
externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");
|
externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");
|
||||||
externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);
|
externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);
|
||||||
|
|
||||||
it = mi.localmodulesources.iterator();
|
it = mi.localmodulesources.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
addSourceFiles(it.next());
|
addSourceFiles(it.next());
|
||||||
}
|
}
|
||||||
if (!mi.protocol.isEmpty()) {
|
if (!mi.protocol.isEmpty()) {
|
||||||
protocols = msa.addNewProtocols();
|
protocols = msa.addNewProtocols();
|
||||||
it = mi.protocol.iterator();
|
it = mi.protocol.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if ((temp = it.next()) != null) {
|
if ((temp = it.next()) != null) {
|
||||||
ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();
|
ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();
|
||||||
pr.setProtocolCName(temp);
|
pr.setProtocolCName(temp);
|
||||||
pr.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
pr.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!mi.ppi.isEmpty()) {
|
if (!mi.ppi.isEmpty()) {
|
||||||
ppis = msa.addNewPPIs();
|
ppis = msa.addNewPPIs();
|
||||||
it = mi.ppi.iterator();
|
it = mi.ppi.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if ((temp = it.next()) != null) {
|
if ((temp = it.next()) != null) {
|
||||||
PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();
|
PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();
|
||||||
pp.setPpiCName(temp);
|
pp.setPpiCName(temp);
|
||||||
pp.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
pp.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!mi.guid.isEmpty()) {
|
if (!mi.guid.isEmpty()) {
|
||||||
guids = msa.addNewGuids();
|
guids = msa.addNewGuids();
|
||||||
it = mi.guid.iterator();
|
it = mi.guid.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if ((temp = it.next()) != null) {
|
if ((temp = it.next()) != null) {
|
||||||
GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();
|
GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();
|
||||||
gcn.setGuidCName(temp);
|
gcn.setGuidCName(temp);
|
||||||
gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
it = mi.hashrequiredr9libs.iterator();
|
it = mi.hashrequiredr9libs.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if ((temp = it.next()) != null && !temp.matches("%")) {
|
if ((temp = it.next()) != null && !temp.matches("%")) {
|
||||||
LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();
|
LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();
|
||||||
lc.setKeyword(temp);
|
lc.setKeyword(temp);
|
||||||
lc.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
lc.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return msadoc;
|
return msadoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws Exception {
|
public void flush() throws Exception {
|
||||||
XmlOptions options = new XmlOptions();
|
XmlOptions options = new XmlOptions();
|
||||||
|
|
||||||
options.setCharacterEncoding("UTF-8");
|
options.setCharacterEncoding("UTF-8");
|
||||||
@@ -184,14 +184,14 @@ public class MsaWriter {
|
|||||||
options.setSavePrettyPrintIndent(2);
|
options.setSavePrettyPrintIndent(2);
|
||||||
options.setUseDefaultNamespace();
|
options.setUseDefaultNamespace();
|
||||||
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));
|
||||||
fulfillMsadoc().save(bw, options);
|
fulfillMsadoc().save(bw, options);
|
||||||
//MsaTreeEditor.init(mi, ui, msadoc);
|
//MsaTreeEditor.init(mi, ui, msadoc);
|
||||||
bw.flush();
|
bw.flush();
|
||||||
bw.close();
|
bw.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void flush(String path, ModuleSurfaceAreaDocument msadoc) throws Exception {
|
private static void flush(String path, ModuleSurfaceAreaDocument msadoc) throws Exception {
|
||||||
XmlOptions options = new XmlOptions();
|
XmlOptions options = new XmlOptions();
|
||||||
|
|
||||||
options.setCharacterEncoding("UTF-8");
|
options.setCharacterEncoding("UTF-8");
|
||||||
@@ -199,14 +199,14 @@ public class MsaWriter {
|
|||||||
options.setSavePrettyPrintIndent(2);
|
options.setSavePrettyPrintIndent(2);
|
||||||
options.setUseDefaultNamespace();
|
options.setUseDefaultNamespace();
|
||||||
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(path));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(path));
|
||||||
msadoc.save(bw, options);
|
msadoc.save(bw, options);
|
||||||
bw.flush();
|
bw.flush();
|
||||||
bw.close();
|
bw.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void parse(String msafile) throws Exception {
|
public static final void parse(String msafile) throws Exception {
|
||||||
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(msafile);
|
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(msafile);
|
||||||
flush("c:\\temp.msa", msadoc);
|
flush("c:\\temp.msa", msadoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,35 +16,35 @@ import java.io.File;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public final class PathIterator implements Common.ForDoAll {
|
public final class PathIterator implements Common.ForDoAll {
|
||||||
// this PathIterator is based on HashSet, an thread implementation is required.
|
// this PathIterator is based on HashSet, an thread implementation is required.
|
||||||
PathIterator(String path, int md) throws Exception {
|
PathIterator(String path, int md) throws Exception {
|
||||||
startpath = path;
|
startpath = path;
|
||||||
mode = md;
|
mode = md;
|
||||||
Common.toDoAll(startpath, this, mode);
|
Common.toDoAll(startpath, this, mode);
|
||||||
it = pathlist.iterator();
|
it = pathlist.iterator();
|
||||||
}
|
}
|
||||||
private String startpath = null;
|
private String startpath = null;
|
||||||
private int mode;
|
private int mode;
|
||||||
private HashSet<String> pathlist = new HashSet<String>();
|
private HashSet<String> pathlist = new HashSet<String>();
|
||||||
private Iterator<String> it = null;
|
private Iterator<String> it = null;
|
||||||
|
|
||||||
public final void run(String path) throws Exception {
|
public final void run(String path) throws Exception {
|
||||||
pathlist.add(path);
|
pathlist.add(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean filter(File dir) {
|
public boolean filter(File dir) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String next() {
|
public final String next() {
|
||||||
return it.next();
|
return it.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean hasNext() {
|
public final boolean hasNext() {
|
||||||
return it.hasNext();
|
return it.hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String toString() {
|
public final String toString() {
|
||||||
return pathlist.toString();
|
return pathlist.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,374 +18,374 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class SourceFileReplacer implements Common.ForDoAll {
|
public final class SourceFileReplacer implements Common.ForDoAll {
|
||||||
private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();
|
private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
private static final Set<Common.Laplace> Laplaces = new HashSet<Common.Laplace>();
|
private static final Set<Common.Laplace> Laplaces = new HashSet<Common.Laplace>();
|
||||||
|
|
||||||
// these sets are used only for printing log of the changes in current file
|
// these sets are used only for printing log of the changes in current file
|
||||||
private static final Set<r8tor9> filefunc = new HashSet<r8tor9>();
|
private static final Set<r8tor9> filefunc = new HashSet<r8tor9>();
|
||||||
private static final Set<r8tor9> filemacro = new HashSet<r8tor9>();
|
private static final Set<r8tor9> filemacro = new HashSet<r8tor9>();
|
||||||
private static final Set<r8tor9> fileguid = new HashSet<r8tor9>();
|
private static final Set<r8tor9> fileguid = new HashSet<r8tor9>();
|
||||||
private static final Set<r8tor9> fileppi = new HashSet<r8tor9>();
|
private static final Set<r8tor9> fileppi = new HashSet<r8tor9>();
|
||||||
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
||||||
private static final Set<String> filer8only = new HashSet<String>();
|
private static final Set<String> filer8only = new HashSet<String>();
|
||||||
|
|
||||||
private static final String[] specialhoblibfunc = {
|
private static final String[] specialhoblibfunc = {
|
||||||
"BuildModuleHob",
|
"BuildModuleHob",
|
||||||
"BuildResourceDescriptorHob",
|
"BuildResourceDescriptorHob",
|
||||||
"BuildFvHob",
|
"BuildFvHob",
|
||||||
"BuildCpuHob",
|
"BuildCpuHob",
|
||||||
"BuildStackHob",
|
"BuildStackHob",
|
||||||
"BuildBspStoreHob",
|
"BuildBspStoreHob",
|
||||||
"BuildMemoryAllocationHob"
|
"BuildMemoryAllocationHob"
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------inner classes---------------------------------------//
|
//---------------------------------------inner classes---------------------------------------//
|
||||||
private static class r8tor9 {
|
private static class r8tor9 {
|
||||||
r8tor9(String r8, String r9) {
|
r8tor9(String r8, String r9) {
|
||||||
r8thing = r8;
|
r8thing = r8;
|
||||||
r9thing = r9;
|
r9thing = r9;
|
||||||
}
|
}
|
||||||
public String r8thing;
|
public String r8thing;
|
||||||
public String r9thing;
|
public String r9thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class IdleLaplace extends Common.Laplace {
|
private class IdleLaplace extends Common.Laplace {
|
||||||
public String operation(String wholeline) {
|
public String operation(String wholeline) {
|
||||||
return wholeline;
|
return wholeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean recognize(String filename) {
|
public boolean recognize(String filename) {
|
||||||
return filename.contains(".h") || filename.contains(".H") || filename.contains(".uni");
|
return filename.contains(".h") || filename.contains(".H") || filename.contains(".uni");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String namechange(String oldname) {
|
public String namechange(String oldname) {
|
||||||
if (oldname.contains(".H")) {
|
if (oldname.contains(".H")) {
|
||||||
return oldname.replaceFirst(".H", ".h");
|
return oldname.replaceFirst(".H", ".h");
|
||||||
} else {
|
} else {
|
||||||
return oldname;
|
return oldname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private class DxsLaplace extends Common.Laplace {
|
private class DxsLaplace extends Common.Laplace {
|
||||||
public String operation(String wholeline) {
|
public String operation(String wholeline) {
|
||||||
if (mi.getModuleType().equals("PEIM")) {
|
if (mi.getModuleType().equals("PEIM")) {
|
||||||
return addincludefile(wholeline, "\\<PeimDepex.h\\>");
|
return addincludefile(wholeline, "\\<PeimDepex.h\\>");
|
||||||
} else {
|
} else {
|
||||||
return addincludefile(wholeline, "\\<DxeDepex.h\\>");
|
return addincludefile(wholeline, "\\<DxeDepex.h\\>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean recognize(String filename) {
|
public boolean recognize(String filename) {
|
||||||
return filename.contains(".dxs");
|
return filename.contains(".dxs");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String namechange(String oldname) {
|
public String namechange(String oldname) {
|
||||||
return oldname;
|
return oldname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CLaplace extends Common.Laplace {
|
private class CLaplace extends Common.Laplace {
|
||||||
public String operation(String wholeline) {
|
public String operation(String wholeline) {
|
||||||
boolean addr8 = false;
|
boolean addr8 = false;
|
||||||
|
|
||||||
Pattern pat = Pattern.compile("g?(BS|RT)(\\s*->\\s*)([a-zA-Z_]\\w*)", Pattern.MULTILINE); // ! only two level () bracket allowed !
|
Pattern pat = Pattern.compile("g?(BS|RT)(\\s*->\\s*)([a-zA-Z_]\\w*)", Pattern.MULTILINE); // ! only two level () bracket allowed !
|
||||||
//Pattern ptnpei = Pattern.compile("\\(\\*\\*?PeiServices\\)[.-][>]?\\s*(\\w*[#$]*)(\\s*\\(([^\\(\\)]*(\\([^\\(\\)]*\\))?[^\\(\\)]*)*\\))", Pattern.MULTILINE);
|
//Pattern ptnpei = Pattern.compile("\\(\\*\\*?PeiServices\\)[.-][>]?\\s*(\\w*[#$]*)(\\s*\\(([^\\(\\)]*(\\([^\\(\\)]*\\))?[^\\(\\)]*)*\\))", Pattern.MULTILINE);
|
||||||
|
|
||||||
// replace BS -> gBS , RT -> gRT
|
// replace BS -> gBS , RT -> gRT
|
||||||
Matcher mat = pat.matcher(wholeline);
|
Matcher mat = pat.matcher(wholeline);
|
||||||
if (mat.find()) { // add a library here
|
if (mat.find()) { // add a library here
|
||||||
MigrationTool.ui.println("Converting all BS->gBS, RT->gRT");
|
MigrationTool.ui.println("Converting all BS->gBS, RT->gRT");
|
||||||
wholeline = mat.replaceAll("g$1$2$3"); //unknown correctiveness
|
wholeline = mat.replaceAll("g$1$2$3"); //unknown correctiveness
|
||||||
}
|
}
|
||||||
mat.reset();
|
mat.reset();
|
||||||
while (mat.find()) {
|
while (mat.find()) {
|
||||||
if (mat.group(1).matches("BS")) {
|
if (mat.group(1).matches("BS")) {
|
||||||
mi.hashrequiredr9libs.add("UefiBootServicesTableLib");
|
mi.hashrequiredr9libs.add("UefiBootServicesTableLib");
|
||||||
}
|
}
|
||||||
if (mat.group(1).matches("RT")) {
|
if (mat.group(1).matches("RT")) {
|
||||||
mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib");
|
mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// remove EFI_DRIVER_ENTRY_POINT
|
// remove EFI_DRIVER_ENTRY_POINT
|
||||||
wholeline = wholeline.replaceAll("(EFI_\\w+_ENTRY_POINT)", MigrationTool.MIGRATIONCOMMENT + " $1");
|
wholeline = wholeline.replaceAll("(EFI_\\w+_ENTRY_POINT)", MigrationTool.MIGRATIONCOMMENT + " $1");
|
||||||
|
|
||||||
// start replacing names
|
// start replacing names
|
||||||
String r8thing;
|
String r8thing;
|
||||||
String r9thing;
|
String r9thing;
|
||||||
Iterator<String> it;
|
Iterator<String> it;
|
||||||
// Converting non-locla function
|
// Converting non-locla function
|
||||||
it = mi.hashnonlocalfunc.iterator();
|
it = mi.hashnonlocalfunc.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
r8thing = it.next();
|
r8thing = it.next();
|
||||||
if (r8thing.matches("EfiInitializeDriverLib")) { //s
|
if (r8thing.matches("EfiInitializeDriverLib")) { //s
|
||||||
mi.hashrequiredr9libs.add("UefiBootServicesTableLib"); //p
|
mi.hashrequiredr9libs.add("UefiBootServicesTableLib"); //p
|
||||||
mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib"); //e
|
mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib"); //e
|
||||||
} else if (r8thing.matches("DxeInitializeDriverLib")) { //c
|
} else if (r8thing.matches("DxeInitializeDriverLib")) { //c
|
||||||
mi.hashrequiredr9libs.add("UefiBootServicesTableLib"); //i
|
mi.hashrequiredr9libs.add("UefiBootServicesTableLib"); //i
|
||||||
mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib"); //a
|
mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib"); //a
|
||||||
mi.hashrequiredr9libs.add("DxeServicesTableLib"); //l
|
mi.hashrequiredr9libs.add("DxeServicesTableLib"); //l
|
||||||
} else { //
|
} else { //
|
||||||
mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); // add a library here
|
mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); // add a library here
|
||||||
}
|
}
|
||||||
|
|
||||||
r8tor9 temp;
|
r8tor9 temp;
|
||||||
if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {
|
if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {
|
||||||
if (!r8thing.equals(r9thing)) {
|
if (!r8thing.equals(r9thing)) {
|
||||||
if (wholeline.contains(r8thing)) {
|
if (wholeline.contains(r8thing)) {
|
||||||
wholeline = wholeline.replaceAll(r8thing, r9thing);
|
wholeline = wholeline.replaceAll(r8thing, r9thing);
|
||||||
filefunc.add(new r8tor9(r8thing, r9thing));
|
filefunc.add(new r8tor9(r8thing, r9thing));
|
||||||
Iterator<r8tor9> rt = filefunc.iterator();
|
Iterator<r8tor9> rt = filefunc.iterator();
|
||||||
while (rt.hasNext()) {
|
while (rt.hasNext()) {
|
||||||
temp = rt.next();
|
temp = rt.next();
|
||||||
if (MigrationTool.db.r8only.contains(temp.r8thing)) {
|
if (MigrationTool.db.r8only.contains(temp.r8thing)) {
|
||||||
filer8only.add(r8thing);
|
filer8only.add(r8thing);
|
||||||
mi.hashr8only.add(r8thing);
|
mi.hashr8only.add(r8thing);
|
||||||
addr8 = true;
|
addr8 = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} //is any of the guids changed?
|
} //is any of the guids changed?
|
||||||
if (addr8 == true) {
|
if (addr8 == true) {
|
||||||
wholeline = addincludefile(wholeline, "\"R8Lib.h\"");
|
wholeline = addincludefile(wholeline, "\"R8Lib.h\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converting macro
|
// Converting macro
|
||||||
it = mi.hashnonlocalmacro.iterator();
|
it = mi.hashnonlocalmacro.iterator();
|
||||||
while (it.hasNext()) { //macros are all assumed MdePkg currently
|
while (it.hasNext()) { //macros are all assumed MdePkg currently
|
||||||
r8thing = it.next();
|
r8thing = it.next();
|
||||||
//mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing));
|
//mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing));
|
||||||
if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {
|
if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {
|
||||||
if (wholeline.contains(r8thing)) {
|
if (wholeline.contains(r8thing)) {
|
||||||
wholeline = wholeline.replaceAll(r8thing, r9thing);
|
wholeline = wholeline.replaceAll(r8thing, r9thing);
|
||||||
filemacro.add(new r8tor9(r8thing, r9thing));
|
filemacro.add(new r8tor9(r8thing, r9thing));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converting guid
|
// Converting guid
|
||||||
replaceGuid(wholeline, mi.guid, "guid", fileguid);
|
replaceGuid(wholeline, mi.guid, "guid", fileguid);
|
||||||
replaceGuid(wholeline, mi.ppi, "ppi", fileppi);
|
replaceGuid(wholeline, mi.ppi, "ppi", fileppi);
|
||||||
replaceGuid(wholeline, mi.protocol, "protocol", fileprotocol);
|
replaceGuid(wholeline, mi.protocol, "protocol", fileprotocol);
|
||||||
|
|
||||||
// Converting Pei
|
// Converting Pei
|
||||||
// First , find all (**PeiServices)-> or (*PeiServices). with arg "PeiServices" , change name and add #%
|
// First , find all (**PeiServices)-> or (*PeiServices). with arg "PeiServices" , change name and add #%
|
||||||
Pattern ptnpei = Pattern.compile("\\(\\*\\*?PeiServices\\)[.-][>]?\\s*(\\w*)(\\s*\\(\\s*PeiServices\\s*,\\s*)", Pattern.MULTILINE);
|
Pattern ptnpei = Pattern.compile("\\(\\*\\*?PeiServices\\)[.-][>]?\\s*(\\w*)(\\s*\\(\\s*PeiServices\\s*,\\s*)", Pattern.MULTILINE);
|
||||||
if (mi.getModuleType().matches("PEIM")) {
|
if (mi.getModuleType().matches("PEIM")) {
|
||||||
//if (mi.moduletype.contains("PEIM")) {
|
//if (mi.moduletype.contains("PEIM")) {
|
||||||
Matcher mtrpei = ptnpei.matcher(wholeline);
|
Matcher mtrpei = ptnpei.matcher(wholeline);
|
||||||
while (mtrpei.find()) { // ! add a library here !
|
while (mtrpei.find()) { // ! add a library here !
|
||||||
wholeline = mtrpei.replaceAll("PeiServices$1#%$2");
|
wholeline = mtrpei.replaceAll("PeiServices$1#%$2");
|
||||||
mi.hashrequiredr9libs.add("PeiServicesLib");
|
mi.hashrequiredr9libs.add("PeiServicesLib");
|
||||||
}
|
}
|
||||||
mtrpei.reset();
|
mtrpei.reset();
|
||||||
if (wholeline.contains("PeiServicesCopyMem")) {
|
if (wholeline.contains("PeiServicesCopyMem")) {
|
||||||
wholeline = wholeline.replaceAll("PeiServicesCopyMem#%", "CopyMem");
|
wholeline = wholeline.replaceAll("PeiServicesCopyMem#%", "CopyMem");
|
||||||
mi.hashrequiredr9libs.add("BaseMemoryLib");
|
mi.hashrequiredr9libs.add("BaseMemoryLib");
|
||||||
}
|
}
|
||||||
if (wholeline.contains("PeiServicesSetMem")) {
|
if (wholeline.contains("PeiServicesSetMem")) {
|
||||||
wholeline = wholeline.replaceAll("PeiServicesSetMem#%", "SetMem");
|
wholeline = wholeline.replaceAll("PeiServicesSetMem#%", "SetMem");
|
||||||
mi.hashrequiredr9libs.add("BaseMemoryLib");
|
mi.hashrequiredr9libs.add("BaseMemoryLib");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second , find all #% to drop the arg "PeiServices"
|
// Second , find all #% to drop the arg "PeiServices"
|
||||||
Pattern ptnpeiarg = Pattern.compile("#%+(\\s*\\(+\\s*)PeiServices\\s*,\\s*", Pattern.MULTILINE);
|
Pattern ptnpeiarg = Pattern.compile("#%+(\\s*\\(+\\s*)PeiServices\\s*,\\s*", Pattern.MULTILINE);
|
||||||
Matcher mtrpeiarg = ptnpeiarg.matcher(wholeline);
|
Matcher mtrpeiarg = ptnpeiarg.matcher(wholeline);
|
||||||
while (mtrpeiarg.find()) {
|
while (mtrpeiarg.find()) {
|
||||||
wholeline = mtrpeiarg.replaceAll("$1");
|
wholeline = mtrpeiarg.replaceAll("$1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wholeline = hobLibFuncDropStatus(wholeline);
|
wholeline = hobLibFuncDropStatus(wholeline);
|
||||||
|
|
||||||
Matcher mtrmac;
|
Matcher mtrmac;
|
||||||
mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(wholeline);
|
mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(wholeline);
|
||||||
if (mtrmac.find()) {
|
if (mtrmac.find()) {
|
||||||
wholeline = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");
|
wholeline = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");
|
||||||
}
|
}
|
||||||
mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline);
|
mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline);
|
||||||
if (mtrmac.find()) {
|
if (mtrmac.find()) {
|
||||||
wholeline = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");
|
wholeline = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");
|
||||||
}
|
}
|
||||||
mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline);
|
mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline);
|
||||||
if (mtrmac.find()) {
|
if (mtrmac.find()) {
|
||||||
wholeline = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");
|
wholeline = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");
|
||||||
}
|
}
|
||||||
mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(wholeline);
|
mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(wholeline);
|
||||||
if (mtrmac.find()) {
|
if (mtrmac.find()) {
|
||||||
wholeline = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");
|
wholeline = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");
|
||||||
}
|
}
|
||||||
if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) {
|
if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) {
|
||||||
wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)");
|
wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
show(filefunc, "function");
|
show(filefunc, "function");
|
||||||
show(filemacro, "macro");
|
show(filemacro, "macro");
|
||||||
show(fileguid, "guid");
|
show(fileguid, "guid");
|
||||||
show(fileppi, "ppi");
|
show(fileppi, "ppi");
|
||||||
show(fileprotocol, "protocol");
|
show(fileprotocol, "protocol");
|
||||||
if (!filer8only.isEmpty()) {
|
if (!filer8only.isEmpty()) {
|
||||||
MigrationTool.ui.println("Converting r8only : " + filer8only);
|
MigrationTool.ui.println("Converting r8only : " + filer8only);
|
||||||
}
|
}
|
||||||
|
|
||||||
filefunc.clear();
|
filefunc.clear();
|
||||||
filemacro.clear();
|
filemacro.clear();
|
||||||
fileguid.clear();
|
fileguid.clear();
|
||||||
fileppi.clear();
|
fileppi.clear();
|
||||||
fileprotocol.clear();
|
fileprotocol.clear();
|
||||||
filer8only.clear();
|
filer8only.clear();
|
||||||
|
|
||||||
return wholeline;
|
return wholeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean recognize(String filename) {
|
public boolean recognize(String filename) {
|
||||||
return filename.contains(".c") || filename.contains(".C");
|
return filename.contains(".c") || filename.contains(".C");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String namechange(String oldname) {
|
public String namechange(String oldname) {
|
||||||
if (oldname.contains(".C")) {
|
if (oldname.contains(".C")) {
|
||||||
return oldname.replaceFirst(".C", ".c");
|
return oldname.replaceFirst(".C", ".c");
|
||||||
} else {
|
} else {
|
||||||
return oldname;
|
return oldname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//---------------------------------------inner classes---------------------------------------//
|
//---------------------------------------inner classes---------------------------------------//
|
||||||
|
|
||||||
//-------------------------------------process functions-------------------------------------//
|
//-------------------------------------process functions-------------------------------------//
|
||||||
private static final String addincludefile(String wholeline, String hfile) {
|
private static final String addincludefile(String wholeline, String hfile) {
|
||||||
return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n");
|
return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void show(Set<r8tor9> hash, String sh) {
|
private static final void show(Set<r8tor9> hash, String sh) {
|
||||||
Iterator<r8tor9> it = hash.iterator();
|
Iterator<r8tor9> it = hash.iterator();
|
||||||
r8tor9 temp;
|
r8tor9 temp;
|
||||||
if (!hash.isEmpty()) {
|
if (!hash.isEmpty()) {
|
||||||
MigrationTool.ui.print("Converting " + sh + " : ");
|
MigrationTool.ui.print("Converting " + sh + " : ");
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
temp = it.next();
|
temp = it.next();
|
||||||
MigrationTool.ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] ");
|
MigrationTool.ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] ");
|
||||||
}
|
}
|
||||||
MigrationTool.ui.println("");
|
MigrationTool.ui.println("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void replaceGuid(String line, Set<String> hash, String kind, Set<r8tor9> filehash) {
|
private static final void replaceGuid(String line, Set<String> hash, String kind, Set<r8tor9> filehash) {
|
||||||
Iterator<String> it;
|
Iterator<String> it;
|
||||||
String r8thing;
|
String r8thing;
|
||||||
String r9thing;
|
String r9thing;
|
||||||
it = hash.iterator();
|
it = hash.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
r8thing = it.next();
|
r8thing = it.next();
|
||||||
if ((r9thing = MigrationTool.db.getR9Guidname(r8thing)) != null) {
|
if ((r9thing = MigrationTool.db.getR9Guidname(r8thing)) != null) {
|
||||||
if (!r8thing.equals(r9thing)) {
|
if (!r8thing.equals(r9thing)) {
|
||||||
if (line.contains(r8thing)) {
|
if (line.contains(r8thing)) {
|
||||||
line = line.replaceAll(r8thing, r9thing);
|
line = line.replaceAll(r8thing, r9thing);
|
||||||
filehash.add(new r8tor9(r8thing, r9thing));
|
filehash.add(new r8tor9(r8thing, r9thing));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String hobLibFuncDropStatus(String wholeline) { // or use regex to find pattern "Status = ..."
|
private final String hobLibFuncDropStatus(String wholeline) { // or use regex to find pattern "Status = ..."
|
||||||
Pattern ptnhobstatus;
|
Pattern ptnhobstatus;
|
||||||
Matcher mtrhobstatus;
|
Matcher mtrhobstatus;
|
||||||
String templine = wholeline;
|
String templine = wholeline;
|
||||||
for (int i = 0; i < specialhoblibfunc.length; i++) {
|
for (int i = 0; i < specialhoblibfunc.length; i++) {
|
||||||
ptnhobstatus = Pattern.compile("(Status\\s*=\\s*)?" + specialhoblibfunc[i] + "(.*?\\)\\s*;)", Pattern.DOTALL);
|
ptnhobstatus = Pattern.compile("(Status\\s*=\\s*)?" + specialhoblibfunc[i] + "(.*?\\)\\s*;)", Pattern.DOTALL);
|
||||||
mtrhobstatus = ptnhobstatus.matcher(templine);
|
mtrhobstatus = ptnhobstatus.matcher(templine);
|
||||||
if (mtrhobstatus.find()) {
|
if (mtrhobstatus.find()) {
|
||||||
templine = mtrhobstatus.replaceAll(specialhoblibfunc[i] + mtrhobstatus.group(2) + "\n //Migration comments: R9 Hob-building library functions will assert if build failure.\n Status = EFI_SUCCESS;");
|
templine = mtrhobstatus.replaceAll(specialhoblibfunc[i] + mtrhobstatus.group(2) + "\n //Migration comments: R9 Hob-building library functions will assert if build failure.\n Status = EFI_SUCCESS;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return templine;
|
return templine;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void addr8only() throws Exception {
|
private final void addr8only() throws Exception {
|
||||||
String paragraph = null;
|
String paragraph = null;
|
||||||
String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");
|
String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");
|
||||||
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));
|
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));
|
||||||
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.h")));
|
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.h")));
|
||||||
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?(.*?R8_(\\w*).*?)////~", Pattern.DOTALL);
|
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?(.*?R8_(\\w*).*?)////~", Pattern.DOTALL);
|
||||||
Matcher mtrr8only = ptnr8only.matcher(line);
|
Matcher mtrr8only = ptnr8only.matcher(line);
|
||||||
Matcher mtrr8onlyhead;
|
Matcher mtrr8onlyhead;
|
||||||
|
|
||||||
//add head comment
|
//add head comment
|
||||||
Matcher mtrr8onlyheadcomment = Critic.PTN_NEW_HEAD_COMMENT.matcher(line);
|
Matcher mtrr8onlyheadcomment = Critic.PTN_NEW_HEAD_COMMENT.matcher(line);
|
||||||
if (mtrr8onlyheadcomment.find()) {
|
if (mtrr8onlyheadcomment.find()) {
|
||||||
outfile1.append(mtrr8onlyheadcomment.group() + "\n\n");
|
outfile1.append(mtrr8onlyheadcomment.group() + "\n\n");
|
||||||
outfile2.append(mtrr8onlyheadcomment.group() + "\n\n");
|
outfile2.append(mtrr8onlyheadcomment.group() + "\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//add functions body
|
//add functions body
|
||||||
while (mtrr8only.find()) {
|
while (mtrr8only.find()) {
|
||||||
if (mi.hashr8only.contains(mtrr8only.group(3))) {
|
if (mi.hashr8only.contains(mtrr8only.group(3))) {
|
||||||
paragraph = mtrr8only.group(2);
|
paragraph = mtrr8only.group(2);
|
||||||
outfile1.append(paragraph + "\n\n");
|
outfile1.append(paragraph + "\n\n");
|
||||||
if (mtrr8only.group(1).length() != 0) {
|
if (mtrr8only.group(1).length() != 0) {
|
||||||
mi.hashrequiredr9libs.add(mtrr8only.group(1));
|
mi.hashrequiredr9libs.add(mtrr8only.group(1));
|
||||||
}
|
}
|
||||||
//generate R8lib.h
|
//generate R8lib.h
|
||||||
while ((mtrr8onlyhead = Func.ptnbrace.matcher(paragraph)).find()) {
|
while ((mtrr8onlyhead = Func.ptnbrace.matcher(paragraph)).find()) {
|
||||||
paragraph = mtrr8onlyhead.replaceAll(";");
|
paragraph = mtrr8onlyhead.replaceAll(";");
|
||||||
}
|
}
|
||||||
outfile2.append(paragraph + "\n\n");
|
outfile2.append(paragraph + "\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outfile1.flush();
|
outfile1.flush();
|
||||||
outfile1.close();
|
outfile1.close();
|
||||||
outfile2.flush();
|
outfile2.flush();
|
||||||
outfile2.close();
|
outfile2.close();
|
||||||
|
|
||||||
mi.localmodulesources.add("R8Lib.h");
|
mi.localmodulesources.add("R8Lib.h");
|
||||||
mi.localmodulesources.add("R8Lib.c");
|
mi.localmodulesources.add("R8Lib.c");
|
||||||
}
|
}
|
||||||
//-------------------------------------process functions-------------------------------------//
|
//-------------------------------------process functions-------------------------------------//
|
||||||
|
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
//-----------------------------------ForDoAll-----------------------------------//
|
||||||
public void run(String filepath) throws Exception {
|
public void run(String filepath) throws Exception {
|
||||||
String inname = filepath.replace(mi.modulepath + File.separator, "");
|
String inname = filepath.replace(mi.modulepath + File.separator, "");
|
||||||
String tempinpath = 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;
|
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;
|
||||||
|
|
||||||
Iterator<Common.Laplace> itLaplace = Laplaces.iterator();
|
Iterator<Common.Laplace> itLaplace = Laplaces.iterator();
|
||||||
while (itLaplace.hasNext()) {
|
while (itLaplace.hasNext()) {
|
||||||
Common.Laplace lap = itLaplace.next();
|
Common.Laplace lap = itLaplace.next();
|
||||||
if (lap.recognize(inname)) {
|
if (lap.recognize(inname)) {
|
||||||
MigrationTool.ui.println("\nHandling file: " + inname);
|
MigrationTool.ui.println("\nHandling file: " + inname);
|
||||||
lap.transform(tempinpath + inname, tempoutpath + lap.namechange(inname));
|
lap.transform(tempinpath + inname, tempoutpath + lap.namechange(inname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean filter(File dir) {
|
public boolean filter(File dir) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
//-----------------------------------ForDoAll-----------------------------------//
|
||||||
|
|
||||||
private final void setModuleInfo(ModuleInfo moduleinfo) {
|
private final void setModuleInfo(ModuleInfo moduleinfo) {
|
||||||
mi = moduleinfo;
|
mi = moduleinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void start() throws Exception {
|
private final void start() throws Exception {
|
||||||
Laplaces.add(new DxsLaplace());
|
Laplaces.add(new DxsLaplace());
|
||||||
Laplaces.add(new CLaplace());
|
Laplaces.add(new CLaplace());
|
||||||
Laplaces.add(new IdleLaplace());
|
Laplaces.add(new IdleLaplace());
|
||||||
|
|
||||||
Common.toDoAll(mi.localmodulesources, this);
|
Common.toDoAll(mi.localmodulesources, this);
|
||||||
|
|
||||||
if (!mi.hashr8only.isEmpty()) {
|
if (!mi.hashr8only.isEmpty()) {
|
||||||
addr8only();
|
addr8only();
|
||||||
}
|
}
|
||||||
|
|
||||||
Laplaces.clear();
|
Laplaces.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void fireAt(ModuleInfo moduleinfo) throws Exception {
|
public static final void fireAt(ModuleInfo moduleinfo) throws Exception {
|
||||||
SFReplacer.setModuleInfo(moduleinfo);
|
SFReplacer.setModuleInfo(moduleinfo);
|
||||||
SFReplacer.start();
|
SFReplacer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,17 +16,17 @@ import java.util.*;
|
|||||||
|
|
||||||
public interface UI {
|
public interface UI {
|
||||||
|
|
||||||
public boolean yesOrNo(String question);
|
public boolean yesOrNo(String question);
|
||||||
|
|
||||||
public void print(String message);
|
public void print(String message);
|
||||||
|
|
||||||
public void println(String message);
|
public void println(String message);
|
||||||
|
|
||||||
public void println(Set<String> hash);
|
public void println(Set<String> hash);
|
||||||
|
|
||||||
public String choose(String message, Object[] choicelist);
|
public String choose(String message, Object[] choicelist);
|
||||||
|
|
||||||
public String getInput(String message);
|
public String getInput(String message);
|
||||||
|
|
||||||
public String getFilepath(String title, int mode); // necessary ?
|
public String getFilepath(String title, int mode); // necessary ?
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user