mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-24 22:24:37 +02:00
Many Many Modifies
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1331 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
4436ffdcd9
commit
5ea254f612
@ -15,11 +15,30 @@ package org.tianocore.migration;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
|
||||||
public class Common {
|
public final class Common {
|
||||||
public static Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)");
|
public static final int BOTH = 0;
|
||||||
|
public static final int FILE = 1;
|
||||||
|
public static final int DIR = 2;
|
||||||
|
|
||||||
public static String file2string(String filename) throws Exception {
|
public static final Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)");
|
||||||
|
|
||||||
|
//-------------------------------------regex------------------------------------------//
|
||||||
|
|
||||||
|
public static final String replaceAll(String line, Pattern ptn, String des) {
|
||||||
|
Matcher mtr = ptn.matcher(line);
|
||||||
|
if (mtr.find()) {
|
||||||
|
return mtr.replaceAll(des);
|
||||||
|
}
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------regex------------------------------------------//
|
||||||
|
|
||||||
|
//-----------------------------------file&string---------------------------------------//
|
||||||
|
|
||||||
|
public static final String file2string(String filename) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(filename));
|
BufferedReader rd = new BufferedReader(new FileReader(filename));
|
||||||
StringBuffer wholefile = new StringBuffer();
|
StringBuffer wholefile = new StringBuffer();
|
||||||
String line;
|
String line;
|
||||||
@ -29,7 +48,7 @@ public class Common {
|
|||||||
return wholefile.toString();
|
return wholefile.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void string2file(String content, String filename) throws Exception {
|
public static final void string2file(String content, String filename) throws Exception {
|
||||||
ensureDir(filename);
|
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);
|
||||||
@ -37,7 +56,11 @@ public class Common {
|
|||||||
outfile.close();
|
outfile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ensureDir(String objFileWhole) {
|
//-----------------------------------file&string---------------------------------------//
|
||||||
|
|
||||||
|
//--------------------------------------dir--------------------------------------------//
|
||||||
|
|
||||||
|
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()) {
|
||||||
@ -46,32 +69,21 @@ public class Common {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashSet<String> dirScan(String path) { // use HashSet, persue speed rather than space
|
public static final void deleteDir(String objFileWhole) {
|
||||||
HashSet<String> filelist = new HashSet<String>();
|
String[] list = new File(objFileWhole).list();
|
||||||
String[] list = new File(path).list();
|
File temp;
|
||||||
File test;
|
|
||||||
|
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0 ; i < list.length ; i++) {
|
||||||
test = new File(path + File.separator + list[i]);
|
temp = new File(objFileWhole + File.separator + list[i]);
|
||||||
if (test.isDirectory()) {
|
if (temp.isDirectory()) {
|
||||||
dirScan(path + File.separator + list[i]);
|
deleteDir(objFileWhole + File.separator + list[i]);
|
||||||
} else {
|
} else {
|
||||||
filelist.add(path + File.separator + list[i]);
|
temp.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
new File(objFileWhole).delete();
|
||||||
return filelist;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String replaceAll(String line, Pattern ptn, String des) {
|
|
||||||
Matcher mtr = ptn.matcher(line);
|
|
||||||
if (mtr.find()) {
|
|
||||||
return mtr.replaceAll(des);
|
|
||||||
}
|
|
||||||
return line;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static 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));
|
||||||
@ -79,7 +91,7 @@ public class Common {
|
|||||||
return mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2);
|
return mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dirCopy(String src, String des) throws Exception {
|
public static final void dirCopy(String src, String des) throws Exception {
|
||||||
String[] list = new File(src).list();
|
String[] list = new File(src).list();
|
||||||
File test;
|
File test;
|
||||||
|
|
||||||
@ -93,6 +105,36 @@ public class Common {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------dir--------------------------------------------//
|
||||||
|
|
||||||
|
//-------------------------------like python walk-----------------------------------------//
|
||||||
|
|
||||||
|
public static final void toDoAll(String path, Method md, Object obj, Object[] args, int type) throws Exception {
|
||||||
|
String[] list = new File(path).list();
|
||||||
|
ArrayList<Object> _args = new ArrayList<Object>();
|
||||||
|
|
||||||
|
_args.add(path);
|
||||||
|
if (args != null) {
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
_args.add(args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == DIR || type == BOTH) {
|
||||||
|
md.invoke(obj, _args.toArray());
|
||||||
|
}
|
||||||
|
for (int i = 0 ; i < list.length ; i++) {
|
||||||
|
if (new File(path + File.separator + list[i]).isDirectory()) {
|
||||||
|
toDoAll(path + File.separator + list[i], md, obj, args, type);
|
||||||
|
} else {
|
||||||
|
if (type == FILE || type == BOTH) {
|
||||||
|
_args.set(0, path + File.separator + list[i]);
|
||||||
|
md.invoke(obj, _args.toArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void toDoAll(String path, ForDoAll fda) throws Exception { // filter of file type can be done in toDo
|
public static void toDoAll(String path, ForDoAll fda) throws Exception { // filter of file type can be done in toDo
|
||||||
String[] list = new File(path).list();
|
String[] list = new File(path).list();
|
||||||
|
@ -15,23 +15,23 @@ package org.tianocore.migration;
|
|||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class Critic implements Common.ForDoAll {
|
public class Critic {
|
||||||
private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);
|
private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);
|
||||||
private static Pattern ptnfunccomment = Pattern.compile("([\\};\\/]\\s*)([\\w\\s]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/(\\s*.*?)([\\{;])",Pattern.DOTALL);
|
private static Pattern ptnfunccomment = Pattern.compile("([\\};\\/]\\s*)([\\w\\s]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/(\\s*.*?)([\\{;])",Pattern.DOTALL);
|
||||||
//private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);
|
//private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);
|
||||||
private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*-\\s*(.*)\\s*");
|
private static Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");
|
||||||
private static Matcher mtrinfequation;
|
private static Matcher mtrcommentequation;
|
||||||
|
private static Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");
|
||||||
|
private static Matcher mtrnewcomment;
|
||||||
|
|
||||||
public void toDo(String filepath) throws Exception {
|
private static final int totallinelength = 82;
|
||||||
|
|
||||||
|
public static final void critic(String filepath) throws Exception {
|
||||||
if (filepath.contains(".c") || filepath.contains(".h")) {
|
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;
|
||||||
boolean description = false;
|
|
||||||
boolean arguments = false;
|
|
||||||
boolean returns = false;
|
|
||||||
boolean inequation = false;
|
|
||||||
|
|
||||||
System.out.println("Criticing " + filepath);
|
System.out.println("Criticing " + filepath);
|
||||||
String wholeline = Common.file2string(filepath);
|
String wholeline = Common.file2string(filepath);
|
||||||
@ -40,7 +40,12 @@ public class Critic implements Common.ForDoAll {
|
|||||||
wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");
|
wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");
|
||||||
wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1/**$3**/$4$2$5");
|
wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1/**$3**/$4$2$5");
|
||||||
//wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
|
//wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
|
||||||
|
|
||||||
|
// first scan
|
||||||
|
boolean description = false;
|
||||||
|
boolean arguments = false;
|
||||||
|
boolean returns = false;
|
||||||
|
boolean inequation = false;
|
||||||
rd = new BufferedReader(new StringReader(wholeline));
|
rd = new BufferedReader(new StringReader(wholeline));
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.matches("\\/\\*\\*")) {
|
if (line.matches("\\/\\*\\*")) {
|
||||||
@ -62,30 +67,103 @@ public class Critic implements Common.ForDoAll {
|
|||||||
arguments = false;
|
arguments = false;
|
||||||
returns = true;
|
returns = true;
|
||||||
} else if (incomment && description) {
|
} else if (incomment && description) {
|
||||||
templine.append(line + "\n");
|
templine.append(" " + line.trim() + "\n");
|
||||||
} else if (incomment && arguments) {
|
} else if (incomment && arguments) {
|
||||||
mtrinfequation = ptninfequation.matcher(line);
|
mtrcommentequation = ptncommentequation.matcher(line);
|
||||||
if (mtrinfequation.find()) {
|
if (mtrcommentequation.find()) {
|
||||||
inequation = true;
|
inequation = true;
|
||||||
templine.append(" @param " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");
|
templine.append(" @param " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
|
||||||
} else if (inequation && line.trim().length() == 0) {
|
} else if (inequation && line.trim().length() == 0) {
|
||||||
inequation = false;
|
inequation = false;
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
} else if (inequation && line.trim().length() != 0) {
|
} else if (inequation && line.trim().length() != 0) {
|
||||||
templine.append("#%#%" + line + "\n");
|
templine.append("#%#%" + line + "\n");
|
||||||
} else {
|
} else {
|
||||||
templine.append(line + "\n");
|
templine.append(" " + line.trim() + "\n");
|
||||||
}
|
}
|
||||||
} else if (incomment && returns) {
|
} else if (incomment && returns) {
|
||||||
mtrinfequation = ptninfequation.matcher(line);
|
mtrcommentequation = ptncommentequation.matcher(line);
|
||||||
if (mtrinfequation.find()) {
|
if (mtrcommentequation.find()) {
|
||||||
inequation = true;
|
inequation = true;
|
||||||
templine.append(" @retval " + mtrinfequation.group(1) + " " + mtrinfequation.group(2) + "\n");
|
templine.append(" @retval " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
|
||||||
} else if (inequation && line.trim().length() == 0) {
|
} else if (inequation && line.trim().length() == 0) {
|
||||||
inequation = false;
|
inequation = false;
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
} else if (inequation && line.trim().length() != 0) {
|
} else if (inequation && line.trim().length() != 0) {
|
||||||
templine.append("#%#%" + line + "\n");
|
templine.append("#%#%" + line + "\n");
|
||||||
|
} else {
|
||||||
|
templine.append(" " + line.trim() + "\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templine.append(line + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wholeline = templine.toString();
|
||||||
|
wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");
|
||||||
|
//
|
||||||
|
|
||||||
|
// secend scan
|
||||||
|
int startmax = 0;
|
||||||
|
rd = new BufferedReader(new StringReader(wholeline));
|
||||||
|
while ((line = rd.readLine()) != null) {
|
||||||
|
if (line.matches("\\/\\*\\*")) {
|
||||||
|
incomment = true;
|
||||||
|
templine.append(line + "\n");
|
||||||
|
} else if (line.matches("\\*\\*\\/")) {
|
||||||
|
incomment = false;
|
||||||
|
templine.append(line + "\n");
|
||||||
|
} else if (incomment) {
|
||||||
|
mtrnewcomment = ptnnewcomment.matcher(line);
|
||||||
|
if (mtrnewcomment.find()) {
|
||||||
|
startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment.group(1).length() : startmax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
startmax++;
|
||||||
|
//
|
||||||
|
|
||||||
|
// third scan
|
||||||
|
int n = 0;
|
||||||
|
String temp = null;
|
||||||
|
String[] tempcont = null;
|
||||||
|
int count = 0;
|
||||||
|
templine = new StringBuffer();
|
||||||
|
rd = new BufferedReader(new StringReader(wholeline));
|
||||||
|
while ((line = rd.readLine()) != null) {
|
||||||
|
if (line.matches("\\/\\*\\*")) {
|
||||||
|
incomment = true;
|
||||||
|
templine.append(line + "\n");
|
||||||
|
} else if (line.matches("\\*\\*\\/")) {
|
||||||
|
incomment = false;
|
||||||
|
templine.append(line + "\n");
|
||||||
|
} else if (incomment) {
|
||||||
|
mtrnewcomment = ptnnewcomment.matcher(line);
|
||||||
|
if (mtrnewcomment.find()) {
|
||||||
|
n = startmax - mtrnewcomment.group(1).length();
|
||||||
|
templine.append(mtrnewcomment.group(1));
|
||||||
|
while (n-- >= 0) {
|
||||||
|
templine.append(" ");
|
||||||
|
}
|
||||||
|
temp = mtrnewcomment.group(3);
|
||||||
|
tempcont = temp.split(" "); // use \\s+ ?
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
for (int i = 0; i < tempcont.length; i++) {
|
||||||
|
count += tempcont[i].length();
|
||||||
|
if (count <= (totallinelength - startmax)) {
|
||||||
|
templine.append(tempcont[i] + " ");
|
||||||
|
count += 1;
|
||||||
|
} else {
|
||||||
|
templine.append("\n");
|
||||||
|
n = startmax;
|
||||||
|
while (n-- >= 0) {
|
||||||
|
templine.append(" ");
|
||||||
|
}
|
||||||
|
templine.append(tempcont[i] + " ");
|
||||||
|
count = tempcont[i].length() + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templine.append("\n");
|
||||||
} else {
|
} else {
|
||||||
templine.append(line + "\n");
|
templine.append(line + "\n");
|
||||||
}
|
}
|
||||||
@ -94,7 +172,7 @@ public class Critic implements Common.ForDoAll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
wholeline = templine.toString();
|
wholeline = templine.toString();
|
||||||
wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");
|
//
|
||||||
|
|
||||||
/* -----slow edition of replacefirst with stringbuffer-----
|
/* -----slow edition of replacefirst with stringbuffer-----
|
||||||
line.append(wholeline);
|
line.append(wholeline);
|
||||||
@ -123,9 +201,9 @@ public class Critic implements Common.ForDoAll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fireAt(String path) throws Exception {
|
public static final void fireAt(String path) throws Exception {
|
||||||
Critic critic = new Critic();
|
Common.toDoAll(Common.dirCopy_(path), Critic.class.getMethod("critic", String.class), null, null, Common.FILE);
|
||||||
Common.toDoAll(Common.dirCopy_(path), critic);
|
//Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);
|
||||||
System.out.println("Critic Done");
|
System.out.println("Critic Done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import java.io.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class FirstPanel extends JPanel implements ActionListener, UI {
|
public final class FirstPanel extends JPanel implements ActionListener, UI {
|
||||||
/**
|
/**
|
||||||
* Define class Serial Version UID
|
* Define class Serial Version UID
|
||||||
*/
|
*/
|
||||||
@ -61,7 +61,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
|
|||||||
modulePanel.add(filebox);
|
modulePanel.add(filebox);
|
||||||
modulePanel.add(screenbox);
|
modulePanel.add(screenbox);
|
||||||
modulePanel.add(goButton);
|
modulePanel.add(goButton);
|
||||||
modulePanel.add(msaEditorButton);
|
//modulePanel.add(msaEditorButton);
|
||||||
modulePanel.add(criticButton);
|
modulePanel.add(criticButton);
|
||||||
add(modulePanel);
|
add(modulePanel);
|
||||||
|
|
||||||
@ -115,21 +115,34 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
|
|||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
public String getFilepath() {
|
||||||
|
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||||
|
log.append(fc.getSelectedFile().getAbsolutePath() + "\n");
|
||||||
|
return fc.getSelectedFile().getAbsolutePath();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if ( e.getSource() == moduleButton ) {
|
if ( e.getSource() == moduleButton ) {
|
||||||
|
modulepath = getFilepath();
|
||||||
|
/*
|
||||||
int ret = fc.showOpenDialog(this);
|
int ret = fc.showOpenDialog(this);
|
||||||
if (ret == JFileChooser.APPROVE_OPTION) {
|
if (ret == JFileChooser.APPROVE_OPTION) {
|
||||||
modulepath = fc.getSelectedFile().getAbsolutePath();
|
modulepath = fc.getSelectedFile().getAbsolutePath();
|
||||||
moduletext.setText(modulepath);
|
moduletext.setText(modulepath);
|
||||||
log.append("ModulePath: " + modulepath + "\n");
|
log.append("ModulePath: " + modulepath + "\n");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
if ( e.getSource() == goButton ) {
|
if ( e.getSource() == goButton ) {
|
||||||
try {
|
try {
|
||||||
logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));
|
logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));
|
||||||
println("Project MsaGen");
|
println("Project MsaGen");
|
||||||
println("Copyright (c) 2006, Intel Corporation");
|
println("Copyright (c) 2006, Intel Corporation");
|
||||||
mi = new ModuleInfo(modulepath, this, new Database());
|
Common.toDoAll(modulepath, ModuleInfo.class.getMethod("seekModule", String.class), null, null, Common.DIR);
|
||||||
logfile.flush();
|
logfile.flush();
|
||||||
} catch (Exception en) {
|
} catch (Exception en) {
|
||||||
println(en.getMessage());
|
println(en.getMessage());
|
||||||
@ -159,7 +172,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
|
|||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
public static void init() throws Exception {
|
public static FirstPanel init() throws Exception {
|
||||||
|
|
||||||
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
@ -178,5 +191,7 @@ public class FirstPanel extends JPanel implements ActionListener, UI {
|
|||||||
|
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
return fp;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,16 +21,24 @@ import java.util.regex.*;
|
|||||||
information and all the temporary data.
|
information and all the temporary data.
|
||||||
*/
|
*/
|
||||||
public class ModuleInfo {
|
public class ModuleInfo {
|
||||||
ModuleInfo(String modulepath, UI ui, Database db) throws Exception {
|
ModuleInfo(String modulepath) throws Exception {
|
||||||
this.modulepath = modulepath;
|
this.modulepath = modulepath;
|
||||||
this.ui = ui;
|
|
||||||
this.db = db;
|
ui.println("Choose where to place the result");
|
||||||
|
if ((outputpath = ui.getFilepath()) == null) {
|
||||||
|
outputpath = modulepath;
|
||||||
|
}
|
||||||
|
ui.println(outputpath);
|
||||||
|
|
||||||
moduleScan();
|
moduleScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static UI ui = null; //if MIM is still usefull, this can be given to it
|
||||||
|
private static Database db = null; //if MIM is still usefull, this can be given to it
|
||||||
|
|
||||||
private String modulepath = null;
|
public String modulepath = null;
|
||||||
private Database db = null;
|
|
||||||
private UI ui = null;
|
public String outputpath = null;
|
||||||
|
|
||||||
public String modulename = null;
|
public String modulename = null;
|
||||||
public String guidvalue = null;
|
public String guidvalue = null;
|
||||||
@ -55,48 +63,27 @@ public class ModuleInfo {
|
|||||||
|
|
||||||
private static String migrationcomment = "//%$//";
|
private static String migrationcomment = "//%$//";
|
||||||
|
|
||||||
private void dirScan(String subpath) throws Exception {
|
|
||||||
String[] list = new File(modulepath + File.separator + subpath).list(); // if no sub , separator need?
|
|
||||||
File test;
|
|
||||||
|
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
|
||||||
test = new File(modulepath + File.separator + subpath + list[i]);
|
|
||||||
if (test.isDirectory()) {
|
|
||||||
if (list[i].contains("result") || list[i].contains("temp")) {
|
|
||||||
} else {
|
|
||||||
dirScan(subpath + list[i] + File.separator);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (list[i].contains(".c") || list[i].contains(".C") || list[i].contains(".h") ||
|
|
||||||
list[i].contains(".H") || list[i].contains(".dxs") || list[i].contains(".uni")) {
|
|
||||||
localmodulesources.add(subpath + list[i]);
|
|
||||||
} else if (list[i].contains(".inf") || list[i].contains(".msa")) {
|
|
||||||
msaorinf.add(subpath + list[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void moduleScan() throws Exception {
|
private void moduleScan() throws Exception {
|
||||||
dirScan("");
|
Common.toDoAll(modulepath, ModuleInfo.class.getMethod("enroll", String.class), this, null, Common.FILE);
|
||||||
|
|
||||||
String filename = null;
|
String filename = null;
|
||||||
if (msaorinf.isEmpty()) {
|
if (msaorinf.isEmpty()) {
|
||||||
ui.println("No INF nor MSA file found!");
|
ui.println("No INF nor MSA file found!");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
} else {
|
} else {
|
||||||
filename = ui.choose("Found .inf or .msa file in the module\nChoose one Please", msaorinf.toArray());
|
filename = ui.choose("Found .inf or .msa file for module\n" + modulepath + "\nChoose one Please", msaorinf.toArray());
|
||||||
}
|
}
|
||||||
ModuleReader mr = new ModuleReader(modulepath, this, db, ui);
|
//ModuleReader mr = new ModuleReader(modulepath, this, db, ui);
|
||||||
if (filename.contains(".inf")) {
|
if (filename.contains(".inf")) {
|
||||||
mr.readInf(filename);
|
ModuleReader.readInf(filename, this);
|
||||||
} else if (filename.contains(".msa")) {
|
} else if (filename.contains(".msa")) {
|
||||||
mr.readMsa(filename);
|
ModuleReader.readMsa(filename, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommentOutNonLocalHFile();
|
CommentOutNonLocalHFile();
|
||||||
parsePreProcessedSourceCode();
|
parsePreProcessedSourceCode();
|
||||||
|
|
||||||
new SourceFileReplacer(modulepath, this, db, ui).flush(); // some adding library actions are taken here,so it must be put before "MsaWriter"
|
new SourceFileReplacer(modulepath, outputpath, this, db, ui).flush(); // some adding library actions are taken here,so it must be put before "MsaWriter"
|
||||||
|
|
||||||
// show result
|
// show result
|
||||||
if (ui.yesOrNo("Parse of the Module Information has completed. View details?")) {
|
if (ui.yesOrNo("Parse of the Module Information has completed. View details?")) {
|
||||||
@ -113,12 +100,10 @@ public class ModuleInfo {
|
|||||||
show(hashr8only, "hashr8only : ");
|
show(hashr8only, "hashr8only : ");
|
||||||
}
|
}
|
||||||
|
|
||||||
new MsaWriter(modulepath, this, db, ui).flush();
|
new MsaWriter(modulepath, outputpath, this, db, ui).flush();
|
||||||
|
|
||||||
// remove temp directory
|
Common.deleteDir(modulepath + File.separator + "temp");
|
||||||
//File tempdir = new File(modulepath + File.separator + "temp");
|
//Common.toDoAll(modulepath + File.separator + "temp", Common.class.getMethod("deleteDir", String.class), null, null, Common.DIR);
|
||||||
//System.out.println("Deleting Dir");
|
|
||||||
//if (tempdir.exists()) tempdir.d;
|
|
||||||
|
|
||||||
ui.println("Errors Left : " + db.error);
|
ui.println("Errors Left : " + db.error);
|
||||||
ui.println("Complete!");
|
ui.println("Complete!");
|
||||||
@ -140,7 +125,7 @@ public class ModuleInfo {
|
|||||||
|
|
||||||
Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");
|
Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");
|
||||||
Matcher mtrinclude;
|
Matcher mtrinclude;
|
||||||
|
|
||||||
Iterator<String> ii = localmodulesources.iterator();
|
Iterator<String> ii = localmodulesources.iterator();
|
||||||
while ( ii.hasNext() ) {
|
while ( ii.hasNext() ) {
|
||||||
curFile = ii.next();
|
curFile = ii.next();
|
||||||
@ -218,7 +203,7 @@ public class ModuleInfo {
|
|||||||
// 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, this, db)) != null) { // 2.use 3 different matchers , search 3 times to find each
|
if ((temp = Guid.register(matguid, this, db)) != null) { // 2.use 3 different matchers , search 3 times to find each
|
||||||
//matguid.appendReplacement(result, db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost
|
//matguid.appendReplacement(result, db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,7 +257,39 @@ public class ModuleInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public final void enroll(String filepath) throws Exception {
|
||||||
FirstPanel.init();
|
String[] temp;
|
||||||
|
if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") ||
|
||||||
|
filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) {
|
||||||
|
temp = filepath.split("\\\\");
|
||||||
|
localmodulesources.add(temp[temp.length - 1]);
|
||||||
|
} else if (filepath.contains(".inf") || filepath.contains(".msa")) {
|
||||||
|
temp = filepath.split("\\\\");
|
||||||
|
msaorinf.add(temp[temp.length - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void seekModule(String filepath) throws Exception {
|
||||||
|
if (isModule(filepath)) {
|
||||||
|
//System.out.println("I'm in");
|
||||||
|
new ModuleInfo(filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final boolean isModule(String path) {
|
||||||
|
String[] list = new File(path).list();
|
||||||
|
for (int i = 0 ; i < list.length ; i++) {
|
||||||
|
if (!new File(list[i]).isDirectory()) {
|
||||||
|
if (list[i].contains(".inf") || list[i].contains(".msa")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void main(String[] args) throws Exception {
|
||||||
|
ui = FirstPanel.init();
|
||||||
|
db = new Database();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,24 +17,24 @@ import java.util.*;
|
|||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
import org.tianocore.*;
|
import org.tianocore.*;
|
||||||
|
|
||||||
public class ModuleReader {
|
public final class ModuleReader {
|
||||||
ModuleReader(String path, ModuleInfo moduleinfo, Database database, UI u) {
|
ModuleReader(String path, ModuleInfo moduleinfo, Database database, UI u) {
|
||||||
modulepath = path;
|
//modulepath = path;
|
||||||
mi = moduleinfo;
|
//mi = moduleinfo;
|
||||||
db = database;
|
db = database;
|
||||||
ui = u;
|
ui = u;
|
||||||
}
|
}
|
||||||
private String modulepath;
|
//private static String modulepath;
|
||||||
private ModuleInfo mi;
|
//private static ModuleInfo mi;
|
||||||
private Database db;
|
private static Database db;
|
||||||
private UI ui;
|
private static UI ui;
|
||||||
|
|
||||||
private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
|
private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
|
||||||
private static Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
|
private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
|
||||||
private static Pattern ptnfilename = Pattern.compile("[^\\s]+");
|
private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");
|
||||||
|
|
||||||
public void readMsa(String name) throws Exception {
|
public static final void readMsa(String name, ModuleInfo mi) throws Exception {
|
||||||
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(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();
|
||||||
|
|
||||||
@ -53,14 +53,14 @@ public class ModuleReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readInf(String name) throws Exception {
|
public static final void readInf(String name, ModuleInfo mi) throws Exception {
|
||||||
System.out.println("\nParsing INF file: " + name);
|
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(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")) {
|
||||||
|
@ -20,14 +20,16 @@ import org.tianocore.SupportedArchitectures.Enum;
|
|||||||
import org.apache.xmlbeans.*;
|
import org.apache.xmlbeans.*;
|
||||||
|
|
||||||
public class MsaWriter {
|
public class MsaWriter {
|
||||||
MsaWriter(String path, ModuleInfo moduleinfo, Database database, UI u) {
|
MsaWriter(String path, String outpath, ModuleInfo moduleinfo, Database database, UI u) {
|
||||||
modulepath = path;
|
modulepath = path;
|
||||||
|
outputpath = outpath;
|
||||||
mi = moduleinfo;
|
mi = moduleinfo;
|
||||||
db = database;
|
db = database;
|
||||||
ui = u;
|
ui = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String modulepath;
|
private String modulepath;
|
||||||
|
private String outputpath;
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
private Database db;
|
private Database db;
|
||||||
private UI ui;
|
private UI ui;
|
||||||
@ -187,7 +189,7 @@ public class MsaWriter {
|
|||||||
options.setSavePrettyPrintIndent(2);
|
options.setSavePrettyPrintIndent(2);
|
||||||
options.setUseDefaultNamespace();
|
options.setUseDefaultNamespace();
|
||||||
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));
|
||||||
fulfillMsadoc().save(bw, options);
|
fulfillMsadoc().save(bw, options);
|
||||||
//MsaTreeEditor.init(mi, ui, msadoc);
|
//MsaTreeEditor.init(mi, ui, msadoc);
|
||||||
bw.flush();
|
bw.flush();
|
||||||
|
@ -17,14 +17,16 @@ import java.util.*;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class SourceFileReplacer {
|
public final class SourceFileReplacer {
|
||||||
SourceFileReplacer(String path, ModuleInfo moduleinfo, Database database, UI fp) {
|
SourceFileReplacer(String path, String outpath, ModuleInfo moduleinfo, Database database, UI fp) {
|
||||||
modulepath = path;
|
modulepath = path;
|
||||||
|
outputpath = outpath;
|
||||||
mi = moduleinfo;
|
mi = moduleinfo;
|
||||||
db = database;
|
db = database;
|
||||||
ui = fp;
|
ui = fp;
|
||||||
}
|
}
|
||||||
private String modulepath;
|
private String modulepath;
|
||||||
|
private String outputpath;
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
private Database db;
|
private Database db;
|
||||||
private UI ui;
|
private UI ui;
|
||||||
@ -47,7 +49,7 @@ public class SourceFileReplacer {
|
|||||||
private Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
private Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
||||||
private Set<String> filer8only = new HashSet<String>();
|
private Set<String> filer8only = new HashSet<String>();
|
||||||
|
|
||||||
private String r8only = "EfiLibInstallDriverBinding " +
|
private static final String r8only = "EfiLibInstallDriverBinding " +
|
||||||
"EfiLibInstallAllDriverProtocols " +
|
"EfiLibInstallAllDriverProtocols " +
|
||||||
"EfiLibCompareLanguage " +
|
"EfiLibCompareLanguage " +
|
||||||
"BufToHexString " +
|
"BufToHexString " +
|
||||||
@ -68,7 +70,6 @@ public class SourceFileReplacer {
|
|||||||
"GetIoPortSpaceAddressHobInfo ";
|
"GetIoPortSpaceAddressHobInfo ";
|
||||||
|
|
||||||
public void flush() throws Exception {
|
public void flush() throws Exception {
|
||||||
PrintWriter outfile;
|
|
||||||
String outname = null;
|
String outname = null;
|
||||||
String inname = null;
|
String inname = null;
|
||||||
if (ui.yesOrNo("Changes will be made to the Source Code. View details?")) {
|
if (ui.yesOrNo("Changes will be made to the Source Code. View details?")) {
|
||||||
@ -85,14 +86,7 @@ public class SourceFileReplacer {
|
|||||||
outname = inname;
|
outname = inname;
|
||||||
}
|
}
|
||||||
ui.println("\nModifying file: " + inname);
|
ui.println("\nModifying file: " + inname);
|
||||||
Common.string2file(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname), modulepath + File.separator + "result" + File.separator + outname);
|
Common.string2file(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname), outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);
|
||||||
/*
|
|
||||||
Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);
|
|
||||||
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));
|
|
||||||
outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname));
|
|
||||||
outfile.flush();
|
|
||||||
outfile.close();
|
|
||||||
*/
|
|
||||||
} else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {
|
} else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {
|
||||||
if (inname.contains(".H")) {
|
if (inname.contains(".H")) {
|
||||||
outname = inname.replaceFirst(".H", ".h");
|
outname = inname.replaceFirst(".H", ".h");
|
||||||
@ -100,14 +94,7 @@ public class SourceFileReplacer {
|
|||||||
outname = inname;
|
outname = inname;
|
||||||
}
|
}
|
||||||
ui.println("\nCopying file: " + inname);
|
ui.println("\nCopying file: " + inname);
|
||||||
Common.string2file(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname), modulepath + File.separator + "result" + File.separator + outname);
|
Common.string2file(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname), outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);
|
||||||
/*
|
|
||||||
Common.ensureDir(modulepath + File.separator + "result" + File.separator + outname);
|
|
||||||
outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + outname)));
|
|
||||||
outfile.append(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname));
|
|
||||||
outfile.flush();
|
|
||||||
outfile.close();
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,8 +107,8 @@ public class SourceFileReplacer {
|
|||||||
String paragraph = null;
|
String paragraph = null;
|
||||||
String line = Common.file2string(Database.defaultpath + File.separator + "R8Lib.c");
|
String line = Common.file2string(Database.defaultpath + File.separator + "R8Lib.c");
|
||||||
Common.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");
|
Common.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");
|
||||||
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.c")));
|
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));
|
||||||
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.h")));
|
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.h")));
|
||||||
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL);
|
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL);
|
||||||
Matcher mtrr8only = ptnr8only.matcher(line);
|
Matcher mtrr8only = ptnr8only.matcher(line);
|
||||||
Matcher mtrr8onlyhead;
|
Matcher mtrr8onlyhead;
|
||||||
|
@ -27,4 +27,6 @@ public interface UI {
|
|||||||
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(); // necessary ?
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user