From f337986f8e8a8bcf79cbac3a6dd2d9537e46d247 Mon Sep 17 00:00:00 2001 From: jjin9 Date: Sat, 14 Oct 2006 08:22:12 +0000 Subject: [PATCH] add some features: 1. display current settings in target.txt by ContextTool 2. display help information with arguments, such as: ContextTool -h, arguments include -h, /h, -?, /?, -help, /help 3. display current setting by ContextTool -x 4. display possible setting by ContextTool -x ? 5. clean current setting by ContextTool -x 0 6. merge new setting to current setting by ContextTool -x new x is the setting argument, such as p, a, n, m, t, c. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1746 6f19259b-4bc3-4df7-8a09-765794883524 --- .../org/tianocore/context/ContextMain.java | 21 +- .../org/tianocore/context/HelpInfo.java | 4 +- .../org/tianocore/context/ParseParameter.java | 177 ++++++++++++--- .../org/tianocore/context/TargetFile.java | 203 ++++++++++++++---- 4 files changed, 328 insertions(+), 77 deletions(-) diff --git a/Tools/Java/Source/ContextTool/org/tianocore/context/ContextMain.java b/Tools/Java/Source/ContextTool/org/tianocore/context/ContextMain.java index ec2e5b9996..7ee7d6c7c9 100644 --- a/Tools/Java/Source/ContextTool/org/tianocore/context/ContextMain.java +++ b/Tools/Java/Source/ContextTool/org/tianocore/context/ContextMain.java @@ -16,11 +16,28 @@ public class ContextMain { public static void main(String[] args) { + if (TargetFile.validateFilename("target.txt") == false) { + System.out.printf("%n%s", "Target.txt can't be found in WorkSpace. Please check it!"); + System.exit(0); + } + if(ParseParameter.checkParameter(args) == false){ System.exit(0); } - - if (TargetFile.parsePath("target.txt") == false) { + + if (TargetFile.readFile() == false){ + System.exit(0); + } + + if (ParseParameter.standardizeParameter(args) > 0){ + System.exit(0); + } + + if (TargetFile.createTempFile("target.txt") == false){ + System.exit(0); + } + + if (TargetFile.readwriteFile() == false){ System.exit(0); } diff --git a/Tools/Java/Source/ContextTool/org/tianocore/context/HelpInfo.java b/Tools/Java/Source/ContextTool/org/tianocore/context/HelpInfo.java index b65ee0a131..ca9b099883 100644 --- a/Tools/Java/Source/ContextTool/org/tianocore/context/HelpInfo.java +++ b/Tools/Java/Source/ContextTool/org/tianocore/context/HelpInfo.java @@ -102,7 +102,7 @@ public class HelpInfo { private static final String AString = "-a "; - private static final String AStringInfo = "what kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM. Multiple values can be specified on a single line, using space to separate the values."; + private static final String AStringInfo = "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM. Multiple values can be specified on a single line, using space to separate the values."; private static final String CString = "-c "; @@ -122,7 +122,7 @@ public class HelpInfo { private static final String MString = "-m "; - private static final String MStringInfo = "number should GE 0. 0 clears both MULTIPLE_THREAD and MAX_CONCURRENT_THREAD_NUMBER, others enable MULTIPLE_THREAD and set MAX_CONCURRENT_THREAD_NUMBER."; + private static final String MStringInfo = "The number of concurrent threads. Default is 2. Recommend to set this value to one more than the number of your compurter cores or CPUs. 0 will disable MULTIPLE_THREAD and clean MAX_CONCURRENT_THREAD_NUMBER."; private static final String[] UsageString = { HString, AString, CString, NString, PString, TString, MString }; diff --git a/Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java b/Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java index 2285f2142d..8b818059d5 100644 --- a/Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java +++ b/Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java @@ -24,24 +24,31 @@ public class ParseParameter { public static boolean checkParameter(String[] args) { if(args.length == 0){ - HelpInfo.outputUsageInfo(); + TargetFile.readFile(); + outputCurSetting(); return false; } else { - if( args[0].charAt(0) != '-' ){ + if( (args[0].compareToIgnoreCase("-h") == 0) || (args[0].compareToIgnoreCase("/h") == 0) || + (args[0].compareToIgnoreCase("-?") == 0) || (args[0].compareToIgnoreCase("/?") == 0) || + (args[0].compareToIgnoreCase("-help") == 0) || (args[0].compareToIgnoreCase("/help") == 0) ){ HelpInfo.outputUsageInfo(); return false; } + if( args[0].charAt(0) != '-' ){ + System.out.printf("%s\n", "Error arguments! Please type \"ContextTool -h\" for helpinfo."); + return false; + } for(int i=0; i ParseParameter.length) { - bw.write(ParseParameter.pstr); + if(ParseParameter.curpstr.length() >= ParseParameter.plength) { + bw.write(ParseParameter.curpstr); bw.newLine(); pflag = false; } continue; } - if(ParseParameter.pstr.length() > ParseParameter.length) { - bw.write(ParseParameter.pstr); + if(ParseParameter.curpstr.length() >= ParseParameter.plength) { + bw.write(ParseParameter.curpstr); } else { bw.write(textLine); } @@ -155,15 +175,15 @@ public class TargetFile { } else if (textLine.indexOf("TARGET_ARCH") != -1) { if(aflag == true){ if(textLine.trim().charAt(0) == '#'){ - if(ParseParameter.astr.length() > ParseParameter.length) { - bw.write(ParseParameter.astr); + if(ParseParameter.curastr.length() >= ParseParameter.alength) { + bw.write(ParseParameter.curastr); bw.newLine(); aflag = false; } continue; } - if(ParseParameter.astr.length() > ParseParameter.length) { - bw.write(ParseParameter.astr); + if(ParseParameter.curastr.length() >= ParseParameter.alength) { + bw.write(ParseParameter.curastr); } else { bw.write(textLine); } @@ -173,15 +193,15 @@ public class TargetFile { } else if (textLine.indexOf("TARGET") != -1) { if(tflag == true){ if(textLine.trim().charAt(0) == '#'){ - if(ParseParameter.tstr.length() > ParseParameter.length) { - bw.write(ParseParameter.tstr); + if(ParseParameter.curtstr.length() >= ParseParameter.tlength) { + bw.write(ParseParameter.curtstr); bw.newLine(); tflag = false; } continue; } - if(ParseParameter.tstr.length() > ParseParameter.length) { - bw.write(ParseParameter.tstr); + if(ParseParameter.curtstr.length() >= ParseParameter.tlength) { + bw.write(ParseParameter.curtstr); } else { bw.write(textLine); } @@ -191,15 +211,15 @@ public class TargetFile { } else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) { if(cflag == true){ if(textLine.trim().charAt(0) == '#'){ - if(ParseParameter.cstr.length() > ParseParameter.length) { - bw.write(ParseParameter.cstr); + if(ParseParameter.curcstr.length() >= ParseParameter.clength) { + bw.write(ParseParameter.curcstr); bw.newLine(); cflag = false; } continue; } - if(ParseParameter.cstr.length() > ParseParameter.length) { - bw.write(ParseParameter.cstr); + if(ParseParameter.curcstr.length() >= ParseParameter.clength) { + bw.write(ParseParameter.curcstr); } else { bw.write(textLine); } @@ -209,15 +229,15 @@ public class TargetFile { } else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) { if(nflag == true){ if(textLine.trim().charAt(0) == '#'){ - if(ParseParameter.nstr.length() > ParseParameter.length) { - bw.write(ParseParameter.nstr); + if(ParseParameter.curnstr.length() >= ParseParameter.nlength) { + bw.write(ParseParameter.curnstr); bw.newLine(); nflag = false; } continue; } - if(ParseParameter.nstr.length() > ParseParameter.length) { - bw.write(ParseParameter.nstr); + if(ParseParameter.curnstr.length() >= ParseParameter.nlength) { + bw.write(ParseParameter.curnstr); } else { bw.write(textLine); } @@ -227,15 +247,15 @@ public class TargetFile { } else if (textLine.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) { if(mflag == true){ if(textLine.trim().charAt(0) == '#'){ - if(ParseParameter.mstr.length() > ParseParameter.length) { - bw.write(ParseParameter.mstr); + if(ParseParameter.curmstr.length() >= ParseParameter.mlength) { + bw.write(ParseParameter.curmstr); bw.newLine(); mflag = false; } continue; } - if(ParseParameter.mstr.length() > ParseParameter.length) { - bw.write(ParseParameter.mstr); + if(ParseParameter.curmstr.length() >= ParseParameter.mlength) { + bw.write(ParseParameter.curmstr); } else { bw.write(textLine); } @@ -245,15 +265,15 @@ public class TargetFile { }else if (textLine.indexOf("MULTIPLE_THREAD") != -1) { if(meflag == true){ if(textLine.trim().charAt(0) == '#'){ - if(ParseParameter.mestr.length() > ParseParameter.length) { - bw.write(ParseParameter.mestr); + if(ParseParameter.curmestr.length() >= ParseParameter.melength) { + bw.write(ParseParameter.curmestr); bw.newLine(); meflag = false; } continue; } - if(ParseParameter.mestr.length() > ParseParameter.length) { - bw.write(ParseParameter.mestr); + if(ParseParameter.curmestr.length() >= ParseParameter.melength) { + bw.write(ParseParameter.curmestr); } else { bw.write(textLine); } @@ -266,26 +286,26 @@ public class TargetFile { // //user maybe delete the line *ACTIVE_PLATFORM*=* // - if( (pflag == true) && (ParseParameter.pstr.length() > ParseParameter.length) ){ - bw.write(ParseParameter.pstr); + if( (pflag == true) && (ParseParameter.curpstr.length() >= ParseParameter.plength) ){ + bw.write(ParseParameter.curpstr); bw.newLine(); - } else if ( (tflag == true) && (ParseParameter.tstr.length() > ParseParameter.length) ){ - bw.write(ParseParameter.tstr); + } else if ( (tflag == true) && (ParseParameter.curtstr.length() >= ParseParameter.tlength) ){ + bw.write(ParseParameter.curtstr); bw.newLine(); - } else if ( (aflag == true) && (ParseParameter.astr.length() > ParseParameter.length) ){ - bw.write(ParseParameter.astr); + } else if ( (aflag == true) && (ParseParameter.curastr.length() >= ParseParameter.alength) ){ + bw.write(ParseParameter.curastr); bw.newLine(); - } else if ( (cflag == true) && (ParseParameter.cstr.length() > ParseParameter.length) ){ - bw.write(ParseParameter.cstr); + } else if ( (cflag == true) && (ParseParameter.curcstr.length() >= ParseParameter.clength) ){ + bw.write(ParseParameter.curcstr); bw.newLine(); - } else if ( (nflag == true) && (ParseParameter.nstr.length() > ParseParameter.length) ){ - bw.write(ParseParameter.nstr); + } else if ( (nflag == true) && (ParseParameter.curnstr.length() >= ParseParameter.nlength) ){ + bw.write(ParseParameter.curnstr); bw.newLine(); - } else if ( (meflag == true) && (ParseParameter.mestr.length() > ParseParameter.length) ){ - bw.write(ParseParameter.mestr); + } else if ( (meflag == true) && (ParseParameter.curmestr.length() >= ParseParameter.melength) ){ + bw.write(ParseParameter.curmestr); bw.newLine(); - } else if ( (mflag == true) && (ParseParameter.mstr.length() > ParseParameter.length) ){ - bw.write(ParseParameter.mstr); + } else if ( (mflag == true) && (ParseParameter.curmstr.length() >= ParseParameter.mlength) ){ + bw.write(ParseParameter.curmstr); bw.newLine(); } } catch (IOException e) { @@ -313,6 +333,97 @@ public class TargetFile { return true; } + + /** + * read the file and output the lines which include setting + * @param File fd : the File of the target file + * @return String: the current setting + **/ + public static boolean readFile() { + + BufferedReader br = null; + String textLine = null; + + try { + br = new BufferedReader(new FileReader(Fd)); + } catch (FileNotFoundException e) { + System.out + .println("\n# create the BufferedReader failed, because can't find the file:target.txt!"); + return false; + } + try { + while ((textLine = br.readLine()) != null) { + // + // the line is composed of Space + // + if (textLine.trim().compareToIgnoreCase("") == 0) { + continue; + } + // + // the line starts with "#" + // + else if ((textLine.trim().charAt(0) == '#')){ + continue; + } else { + if (textLine.indexOf("ACTIVE_PLATFORM") != -1) { + ParseParameter.curpstr = textLine; + ParseParameter.plength = textLine.indexOf('='); + } else if (textLine.indexOf("TARGET_ARCH") != -1) { + ParseParameter.curastr = textLine; + ParseParameter.alength = textLine.indexOf('='); + } else if (textLine.indexOf("TARGET") != -1) { + ParseParameter.curtstr = textLine; + ParseParameter.tlength = textLine.indexOf('='); + } else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) { + ParseParameter.curcstr = textLine; + ParseParameter.clength = textLine.indexOf('='); + } else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) { + ParseParameter.curnstr = textLine; + ParseParameter.nlength = textLine.indexOf('='); + } else if (textLine.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) { + ParseParameter.curmstr = textLine; + ParseParameter.mlength = textLine.indexOf('='); + } else if (textLine.indexOf("MULTIPLE_THREAD") != -1) { + ParseParameter.curmestr = textLine; + ParseParameter.melength = textLine.indexOf('='); + } + } + } + } catch (IOException e) { + System.out.println("\n# read file error!"); + return false; + } + + try { + br.close(); + } catch (IOException e) { + System.out + .println("\n# close BufferedReader error"); + return false; + } + return true; + } + + private static String convertStr(String str){ + String convertStr = null; + + if( str.compareTo("-p") == 0 ){ + convertStr = "ACTIVE_PLATFORM"; + }else if( str.compareTo("-a") == 0){ + convertStr = "TARGET_ARCH"; + }else if( str.compareTo("-t") == 0){ + convertStr = "TARGET"; + }else if( str.compareTo("-c") == 0){ + convertStr = "TOOL_CHAIN_CONF"; + }else if( str.compareTo("-n") == 0){ + convertStr = "TOOL_CHAIN_TAG"; + }else if( str.compareTo("-m") == 0){ + convertStr = "MAX_CONCURRENT_THREAD_NUMBER"; + } + + return convertStr; + } + /** * according to user's input args, write the file directly