From 71874f9369fbefdd1a64619bd9b4cc52946e430d Mon Sep 17 00:00:00 2001 From: alfred Date: Wed, 6 Sep 2006 02:14:52 +0000 Subject: [PATCH] Laplace, run git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1470 6f19259b-4bc3-4df7-8a09-765794883524 --- .../org/tianocore/migration/Common.java | 22 ++-- .../org/tianocore/migration/PathIterator.java | 13 +-- .../migration/SourceFileReplacer.java | 110 +++++++++--------- 3 files changed, 70 insertions(+), 75 deletions(-) diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/Common.java b/Tools/Source/MigrationTools/org/tianocore/migration/Common.java index fb89dcae4d..6b1208c7c6 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/Common.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/Common.java @@ -155,19 +155,17 @@ public final class Common { File test; if (type == DIR || type == BOTH) { - if (fda.dirFilter(path)) { - fda.run(path); - } + fda.run(path); } for (int i = 0 ; i < list.length ; i++) { test = new File(path + File.separator + list[i]); if (test.isDirectory()) { - toDoAll(path + File.separator + list[i], fda, type); + if (fda.filter(test)) { + toDoAll(path + File.separator + list[i], fda, type); + } } else { if (type == FILE || type == BOTH) { - if (fda.fileFilter(path + File.separator + list[i])) { - fda.run(path + File.separator + list[i]); - } + fda.run(path + File.separator + list[i]); } } } @@ -176,8 +174,14 @@ public final class Common { public static interface ForDoAll { public void run(String filepath) throws Exception; - public boolean dirFilter(String filepath); + public boolean filter(File dir); + } + + public static abstract class Laplace { + public final void transform(String src, String des) throws Exception { + Common.string2file(operation(Common.file2string(src)), des); + } - public boolean fileFilter(String filepath); + public abstract String operation(String wholeline); } } diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/PathIterator.java b/Tools/Source/MigrationTools/org/tianocore/migration/PathIterator.java index ffd1107067..40a9805cdb 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/PathIterator.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/PathIterator.java @@ -12,6 +12,7 @@ **/ package org.tianocore.migration; +import java.io.File; import java.util.*; public final class PathIterator implements Common.ForDoAll { @@ -31,6 +32,10 @@ public final class PathIterator implements Common.ForDoAll { pathlist.add(path); } + public boolean filter(File dir) { + return true; + } + public final String next() { return it.next(); } @@ -42,12 +47,4 @@ public final class PathIterator implements Common.ForDoAll { public final String toString() { return pathlist.toString(); } - - public boolean dirFilter(String filepath) { - return true; - } - - public boolean fileFilter(String filepath) { - return true; - } } diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java b/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java index 67e5bc2567..361036251e 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java @@ -20,7 +20,7 @@ import java.util.regex.Pattern; public final class SourceFileReplacer implements Common.ForDoAll { private static final SourceFileReplacer SFReplacer = new SourceFileReplacer(); private ModuleInfo mi; - private static boolean showdetails = true; // set this as default now, may be changed in the future + //private static boolean showdetails = true; // set this as default now, may be changed in the future private static class r8tor9 { r8tor9(String r8, String r9) { @@ -39,49 +39,6 @@ public final class SourceFileReplacer implements Common.ForDoAll { private static final Set fileprotocol = new HashSet(); private static final Set filer8only = new HashSet(); - private static final String addincludefile(String wholeline, String hfile) { - return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n"); - } - - private final String convertdxs(String wholeline) { - if (mi.getModuleType().equals("PEIM")) { - return addincludefile(wholeline, "\\"); - } else { - return addincludefile(wholeline, "\\"); - } - } - - private final void addr8only() throws Exception { - String paragraph = null; - 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 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); - Matcher mtrr8only = ptnr8only.matcher(line); - Matcher mtrr8onlyhead; - while (mtrr8only.find()) { - if (mi.hashr8only.contains(mtrr8only.group(2))) { - paragraph = mtrr8only.group(); - outfile1.append(paragraph + "\n\n"); - if (mtrr8only.group(1).length() != 0) { - mi.hashrequiredr9libs.add(mtrr8only.group(1)); - } - //generate R8lib.h - while ((mtrr8onlyhead = Func.ptnbrace.matcher(paragraph)).find()) { - paragraph = mtrr8onlyhead.replaceAll(";"); - } - outfile2.append(paragraph + "\n\n"); - } - } - outfile1.flush(); - outfile1.close(); - outfile2.flush(); - outfile2.close(); - - mi.localmodulesources.add("R8Lib.h"); - mi.localmodulesources.add("R8Lib.c"); - } - // Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you! private final String sourcefilereplace(String wholeline) throws Exception { boolean addr8 = false; @@ -233,22 +190,32 @@ public final class SourceFileReplacer implements Common.ForDoAll { return wholeline; } + + private static final String addincludefile(String wholeline, String hfile) { + return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n"); + } + private final String convertdxs(String wholeline) { + if (mi.getModuleType().equals("PEIM")) { + return addincludefile(wholeline, "\\"); + } else { + return addincludefile(wholeline, "\\"); + } + } + private static final void show(Set hash, String sh) { Iterator it = hash.iterator(); r8tor9 temp; - if (showdetails) { - if (!hash.isEmpty()) { - MigrationTool.ui.print("Converting " + sh + " : "); - while (it.hasNext()) { - temp = it.next(); - MigrationTool.ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] "); - } - MigrationTool.ui.println(""); + if (!hash.isEmpty()) { + MigrationTool.ui.print("Converting " + sh + " : "); + while (it.hasNext()) { + temp = it.next(); + MigrationTool.ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] "); } + MigrationTool.ui.println(""); } } - + private static final void replaceGuid(String line, Set hash, String kind, Set filehash) { Iterator it; String r8thing; @@ -266,6 +233,37 @@ public final class SourceFileReplacer implements Common.ForDoAll { } } } + + private final void addr8only() throws Exception { + String paragraph = null; + 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 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); + Matcher mtrr8only = ptnr8only.matcher(line); + Matcher mtrr8onlyhead; + while (mtrr8only.find()) { + if (mi.hashr8only.contains(mtrr8only.group(2))) { + paragraph = mtrr8only.group(); + outfile1.append(paragraph + "\n\n"); + if (mtrr8only.group(1).length() != 0) { + mi.hashrequiredr9libs.add(mtrr8only.group(1)); + } + //generate R8lib.h + while ((mtrr8onlyhead = Func.ptnbrace.matcher(paragraph)).find()) { + paragraph = mtrr8onlyhead.replaceAll(";"); + } + outfile2.append(paragraph + "\n\n"); + } + } + outfile1.flush(); + outfile1.close(); + outfile2.flush(); + outfile2.close(); + + mi.localmodulesources.add("R8Lib.h"); + mi.localmodulesources.add("R8Lib.c"); + } //-----------------------------------ForDoAll-----------------------------------// public void run(String filepath) throws Exception { @@ -297,11 +295,7 @@ public final class SourceFileReplacer implements Common.ForDoAll { } } - public boolean dirFilter(String filepath) { - return true; - } - - public boolean fileFilter(String filepath) { + public boolean filter(File dir) { return true; } //-----------------------------------ForDoAll-----------------------------------// -- 2.39.2