public static boolean checkParameter(String[] args) {\r
\r
if(args.length == 0){\r
- HelpInfo.outputUsageInfo();\r
+ TargetFile.readFile();\r
+ outputCurSetting();\r
return false;\r
} else {\r
- if( args[0].charAt(0) != '-' ){\r
+ if( (args[0].compareToIgnoreCase("-h") == 0) || (args[0].compareToIgnoreCase("/h") == 0) || \r
+ (args[0].compareToIgnoreCase("-?") == 0) || (args[0].compareToIgnoreCase("/?") == 0) || \r
+ (args[0].compareToIgnoreCase("-help") == 0) || (args[0].compareToIgnoreCase("/help") == 0) ){\r
HelpInfo.outputUsageInfo();\r
return false;\r
}\r
+ if( args[0].charAt(0) != '-' ){\r
+ System.out.printf("%s\n", "Error arguments! Please type \"ContextTool -h\" for helpinfo.");\r
+ return false;\r
+ }\r
for(int i=0; i<args.length; i++){\r
- if( (args[i].compareToIgnoreCase("-h") == 0) || \r
- (args[i].startsWith("-") && ((args[i].charAt(1) != 'a') && (args[i].charAt(1) != 'c') \r
- && (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't') && (args[i].charAt(1) != 'm')))){\r
- HelpInfo.outputUsageInfo();\r
+ if( (args[i].startsWith("-") && \r
+ ((args[i].compareTo("-a") != 0) && (args[i].compareTo("-c") != 0) && \r
+ (args[i].compareTo("-n") != 0) && (args[i].compareTo("-p") != 0) && \r
+ (args[i].compareTo("-t") != 0) && (args[i].compareTo("-m") != 0)))){\r
+ System.out.printf("%s\n", "Error arguments! Please type \"ContextTool -h\" for helpinfo."); \r
return false;\r
}\r
}\r
}\r
\r
- standardizeParameter(args);\r
return true; \r
}\r
\r
* @param args -- user's input\r
* @return no return value\r
**/\r
- private static void standardizeParameter(String[] args) {\r
+ public static int standardizeParameter(String[] args) {\r
\r
- //\r
- // the parameters's length are same.\r
- //\r
- length = pstr.length();\r
\r
StringBuffer InputData = new StringBuffer();\r
for (int i = 0; i < args.length; i++) {\r
j = InputData.length();\r
\r
String argstr = InputData.substring(i, j);\r
-\r
+ i = j;\r
if (argstr.charAt(1) == 'p') {\r
- pstr += argstr.substring(2);\r
- // pstr += "\n";\r
+ //\r
+ // argstr is "-p ", display current setting\r
+ //\r
+ if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
+ System.out.printf("%s\n", curpstr);\r
+ return 1;\r
+ }\r
+ //\r
+ //argstr is "-p ?", display possible setting\r
+ //\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
+ System.out.printf( "%s\n", "assign the platform FPD file's relative path to WORKSPACE" );\r
+ return 2;\r
+ }\r
+ //\r
+ //argstr is "-p 0", clean current setting\r
+ //\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
+ curpstr = pstr;\r
+ continue;\r
+ }\r
+ curpstr = mergeSetting(curpstr, argstr);\r
} else if (argstr.charAt(1) == 't') {\r
- tstr += argstr.substring(2);\r
- // tstr += "\n";\r
+ if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
+ System.out.printf("%s\n", curtstr);\r
+ return 1;\r
+ }\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
+ System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE" );\r
+ return 2;\r
+ }\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
+ curtstr = tstr;\r
+ continue;\r
+ }\r
+ curtstr = mergeSetting(curtstr, argstr);\r
} else if (argstr.charAt(1) == 'a') {\r
- astr += argstr.substring(2);\r
-// astr += "\n";\r
+ if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
+ System.out.printf("%s\n", curastr);\r
+ return 1;\r
+ }\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
+ System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM" );\r
+ return 2;\r
+ }\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
+ curastr = astr;\r
+ continue;\r
+ }\r
+ curastr = mergeSetting(curastr, argstr);\r
} else if (argstr.charAt(1) == 'c') {\r
- cstr += argstr.substring(2);\r
-// cstr += "\n";\r
+ if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
+ System.out.printf("%s\n", curcstr);\r
+ return 1;\r
+ }\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
+ System.out.printf( "%s\n", "Assign a txt file with the relative path to WORKSPACE, which specify the tools to use for the build and must be located in the path: WORKSPACE/Tools/Conf/" );\r
+ return 2;\r
+ }\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
+ curcstr = cstr;\r
+ continue;\r
+ }\r
+ curcstr = mergeSetting(curcstr, argstr);\r
} else if (argstr.charAt(1) == 'n') {\r
- nstr += argstr.substring(2);\r
-// nstr += "\n";\r
+ if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
+ System.out.printf("%s\n", curnstr);\r
+ return 1;\r
+ }\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
+ System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT" );\r
+ return 2;\r
+ }\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
+ curnstr = nstr;\r
+ continue;\r
+ }\r
+ curnstr = mergeSetting(curnstr, argstr);\r
} else if (argstr.charAt(1) == 'm') {\r
+ if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
+ System.out.printf("%s\n", curmstr);\r
+ return 1;\r
+ }\r
+ if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
+ System.out.printf( "%s\n", "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." );\r
+ return 2;\r
+ }\r
mstr += argstr.substring(2);\r
-// mstr += "\n";\r
+ curmstr = mstr;\r
if (argstr.charAt(3) == '0'){\r
mestr += " Disable";\r
} else {\r
mestr += " Enable";\r
}\r
- }\r
- i = j;\r
+ curmestr = mestr;\r
+ }\r
+ \r
}\r
-\r
+ return 0;\r
+ }\r
+ \r
+ \r
+ public static String mergeSetting( String S1, String S2){\r
+ \r
+ String[] S = S2.split(" ");\r
+ if(S1 == null){\r
+ S1 = tstr.concat(S2.substring(2));\r
+ }else{\r
+ for(int i = 1; i < S.length; i++){\r
+ if( S1.contains(S[i]) == false ){\r
+ S1 = S1.concat(S[i]).concat(" ");\r
+ }\r
+ }\r
+ }\r
+ \r
+ return S1;\r
+ }\r
+ \r
+ public static boolean outputCurSetting(){\r
+ \r
+ System.out.printf( "%s\n", "The current setting is:" );\r
+ System.out.printf( "%s\n", curpstr );\r
+ System.out.printf( "%s\n", curtstr );\r
+ System.out.printf( "%s\n", curastr );\r
+ System.out.printf( "%s\n", curcstr );\r
+ System.out.printf( "%s\n", curnstr );\r
+ System.out.printf( "%s\n", curmstr );\r
+ System.out.printf( "%s\n", curmestr );\r
+ \r
+ return true;\r
}\r
\r
public static int length = 0;\r
public static String nstr = new String("TOOL_CHAIN_TAG = ");\r
public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");\r
public static String mestr = new String("MULTIPLE_THREAD = ");\r
+ \r
+ public static String curpstr = null;\r
+ public static String curtstr = null;\r
+ public static String curastr = null;\r
+ public static String curcstr = null;\r
+ public static String curnstr = null;\r
+ public static String curmstr = null;\r
+ public static String curmestr = null;\r
+ \r
+ public static int plength = 0;\r
+ public static int tlength = 0;\r
+ public static int alength = 0;\r
+ public static int clength = 0;\r
+ public static int nlength = 0;\r
+ public static int mlength = 0;\r
+ public static int melength = 0;\r
\r
}\r
* @param String filename : the name of target file\r
* @return true or false\r
**/\r
- public static boolean parsePath(String filename) {\r
+ public static boolean setFile(String filename) {\r
\r
String workspacePath = System.getenv("WORKSPACE");\r
\r
TargetFile.writeFile(Fd);\r
return true;\r
}\r
+ \r
+ \r
+ /** \r
+ * validate the filename\r
+ * @param String filename : the name of target file\r
+ * \r
+ * @return true or false\r
+ **/\r
+ public static boolean validateFilename(String filename) {\r
+ \r
+ String workspacePath = System.getenv("WORKSPACE");\r
+ \r
+ Fd = new File(workspacePath + File.separator + "Tools" + File.separator + "Conf" + File.separator + filename);\r
+ \r
+ if (Fd.exists() == true && Fd.canRead() == true)\r
+ return true;\r
+ else\r
+ return false;\r
+ }\r
+ \r
\r
/**\r
* create a empty temp file, which is located at the same directory with target file\r
* @param String filename : the name of target temp file\r
* @return true or false\r
**/\r
- private static boolean createTempFile(String filename) {\r
+ public static boolean createTempFile(String filename) {\r
\r
String workspacePath = System.getenv("WORKSPACE");\r
\r
- TempFd = new File(workspacePath + File.separator + "Tools" + File.separator + "Conf" + File.separator + filename);\r
+ TempFd = new File(workspacePath + File.separator + "Tools" + File.separator + "Conf" + File.separator + filename + "tmp");\r
\r
if (TempFd.exists() == true) {\r
if (TempFd.delete() == false) {\r
* @param no paremeter\r
* @return true or false\r
**/\r
- private static boolean readwriteFile() {\r
+ public static boolean readwriteFile() {\r
\r
if (Fd.canRead() != true)\r
return false;\r
if (textLine.indexOf("ACTIVE_PLATFORM") != -1) {\r
if(pflag == true){\r
if(textLine.trim().charAt(0) == '#'){\r
- if(ParseParameter.pstr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.pstr);\r
+ if(ParseParameter.curpstr.length() >= ParseParameter.plength) {\r
+ bw.write(ParseParameter.curpstr);\r
bw.newLine();\r
pflag = false;\r
}\r
continue;\r
}\r
- if(ParseParameter.pstr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.pstr);\r
+ if(ParseParameter.curpstr.length() >= ParseParameter.plength) {\r
+ bw.write(ParseParameter.curpstr);\r
} else {\r
bw.write(textLine);\r
}\r
} else if (textLine.indexOf("TARGET_ARCH") != -1) {\r
if(aflag == true){\r
if(textLine.trim().charAt(0) == '#'){\r
- if(ParseParameter.astr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.astr);\r
+ if(ParseParameter.curastr.length() >= ParseParameter.alength) {\r
+ bw.write(ParseParameter.curastr);\r
bw.newLine();\r
aflag = false;\r
}\r
continue;\r
}\r
- if(ParseParameter.astr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.astr);\r
+ if(ParseParameter.curastr.length() >= ParseParameter.alength) {\r
+ bw.write(ParseParameter.curastr);\r
} else {\r
bw.write(textLine);\r
}\r
} else if (textLine.indexOf("TARGET") != -1) {\r
if(tflag == true){\r
if(textLine.trim().charAt(0) == '#'){\r
- if(ParseParameter.tstr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.tstr);\r
+ if(ParseParameter.curtstr.length() >= ParseParameter.tlength) {\r
+ bw.write(ParseParameter.curtstr);\r
bw.newLine();\r
tflag = false;\r
}\r
continue;\r
}\r
- if(ParseParameter.tstr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.tstr);\r
+ if(ParseParameter.curtstr.length() >= ParseParameter.tlength) {\r
+ bw.write(ParseParameter.curtstr);\r
} else {\r
bw.write(textLine);\r
}\r
} else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) {\r
if(cflag == true){\r
if(textLine.trim().charAt(0) == '#'){\r
- if(ParseParameter.cstr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.cstr);\r
+ if(ParseParameter.curcstr.length() >= ParseParameter.clength) {\r
+ bw.write(ParseParameter.curcstr);\r
bw.newLine();\r
cflag = false;\r
}\r
continue;\r
}\r
- if(ParseParameter.cstr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.cstr);\r
+ if(ParseParameter.curcstr.length() >= ParseParameter.clength) {\r
+ bw.write(ParseParameter.curcstr);\r
} else {\r
bw.write(textLine);\r
}\r
} else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) {\r
if(nflag == true){\r
if(textLine.trim().charAt(0) == '#'){\r
- if(ParseParameter.nstr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.nstr);\r
+ if(ParseParameter.curnstr.length() >= ParseParameter.nlength) {\r
+ bw.write(ParseParameter.curnstr);\r
bw.newLine();\r
nflag = false;\r
}\r
continue;\r
}\r
- if(ParseParameter.nstr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.nstr);\r
+ if(ParseParameter.curnstr.length() >= ParseParameter.nlength) {\r
+ bw.write(ParseParameter.curnstr);\r
} else {\r
bw.write(textLine);\r
}\r
} else if (textLine.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) {\r
if(mflag == true){\r
if(textLine.trim().charAt(0) == '#'){\r
- if(ParseParameter.mstr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.mstr);\r
+ if(ParseParameter.curmstr.length() >= ParseParameter.mlength) {\r
+ bw.write(ParseParameter.curmstr);\r
bw.newLine();\r
mflag = false;\r
}\r
continue;\r
}\r
- if(ParseParameter.mstr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.mstr);\r
+ if(ParseParameter.curmstr.length() >= ParseParameter.mlength) {\r
+ bw.write(ParseParameter.curmstr);\r
} else {\r
bw.write(textLine);\r
}\r
}else if (textLine.indexOf("MULTIPLE_THREAD") != -1) {\r
if(meflag == true){\r
if(textLine.trim().charAt(0) == '#'){\r
- if(ParseParameter.mestr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.mestr);\r
+ if(ParseParameter.curmestr.length() >= ParseParameter.melength) {\r
+ bw.write(ParseParameter.curmestr);\r
bw.newLine();\r
meflag = false;\r
}\r
continue;\r
}\r
- if(ParseParameter.mestr.length() > ParseParameter.length) {\r
- bw.write(ParseParameter.mestr);\r
+ if(ParseParameter.curmestr.length() >= ParseParameter.melength) {\r
+ bw.write(ParseParameter.curmestr);\r
} else {\r
bw.write(textLine);\r
}\r
//\r
//user maybe delete the line *ACTIVE_PLATFORM*=*\r
//\r
- if( (pflag == true) && (ParseParameter.pstr.length() > ParseParameter.length) ){\r
- bw.write(ParseParameter.pstr);\r
+ if( (pflag == true) && (ParseParameter.curpstr.length() >= ParseParameter.plength) ){\r
+ bw.write(ParseParameter.curpstr);\r
bw.newLine();\r
- } else if ( (tflag == true) && (ParseParameter.tstr.length() > ParseParameter.length) ){\r
- bw.write(ParseParameter.tstr);\r
+ } else if ( (tflag == true) && (ParseParameter.curtstr.length() >= ParseParameter.tlength) ){\r
+ bw.write(ParseParameter.curtstr);\r
bw.newLine();\r
- } else if ( (aflag == true) && (ParseParameter.astr.length() > ParseParameter.length) ){\r
- bw.write(ParseParameter.astr);\r
+ } else if ( (aflag == true) && (ParseParameter.curastr.length() >= ParseParameter.alength) ){\r
+ bw.write(ParseParameter.curastr);\r
bw.newLine();\r
- } else if ( (cflag == true) && (ParseParameter.cstr.length() > ParseParameter.length) ){\r
- bw.write(ParseParameter.cstr);\r
+ } else if ( (cflag == true) && (ParseParameter.curcstr.length() >= ParseParameter.clength) ){\r
+ bw.write(ParseParameter.curcstr);\r
bw.newLine();\r
- } else if ( (nflag == true) && (ParseParameter.nstr.length() > ParseParameter.length) ){\r
- bw.write(ParseParameter.nstr);\r
+ } else if ( (nflag == true) && (ParseParameter.curnstr.length() >= ParseParameter.nlength) ){\r
+ bw.write(ParseParameter.curnstr);\r
bw.newLine();\r
- } else if ( (meflag == true) && (ParseParameter.mestr.length() > ParseParameter.length) ){\r
- bw.write(ParseParameter.mestr);\r
+ } else if ( (meflag == true) && (ParseParameter.curmestr.length() >= ParseParameter.melength) ){\r
+ bw.write(ParseParameter.curmestr);\r
bw.newLine();\r
- } else if ( (mflag == true) && (ParseParameter.mstr.length() > ParseParameter.length) ){\r
- bw.write(ParseParameter.mstr);\r
+ } else if ( (mflag == true) && (ParseParameter.curmstr.length() >= ParseParameter.mlength) ){\r
+ bw.write(ParseParameter.curmstr);\r
bw.newLine();\r
}\r
} catch (IOException e) {\r
\r
return true;\r
}\r
+ \r
+ /**\r
+ * read the file and output the lines which include setting\r
+ * @param File fd : the File of the target file\r
+ * @return String: the current setting\r
+ **/\r
+ public static boolean readFile() {\r
+ \r
+ BufferedReader br = null;\r
+ String textLine = null;\r
+\r
+ try {\r
+ br = new BufferedReader(new FileReader(Fd));\r
+ } catch (FileNotFoundException e) {\r
+ System.out\r
+ .println("\n# create the BufferedReader failed, because can't find the file:target.txt!");\r
+ return false;\r
+ }\r
+ try {\r
+ while ((textLine = br.readLine()) != null) {\r
+ //\r
+ // the line is composed of Space\r
+ //\r
+ if (textLine.trim().compareToIgnoreCase("") == 0) {\r
+ continue;\r
+ } \r
+ //\r
+ // the line starts with "#"\r
+ //\r
+ else if ((textLine.trim().charAt(0) == '#')){\r
+ continue;\r
+ } else {\r
+ if (textLine.indexOf("ACTIVE_PLATFORM") != -1) {\r
+ ParseParameter.curpstr = textLine;\r
+ ParseParameter.plength = textLine.indexOf('=');\r
+ } else if (textLine.indexOf("TARGET_ARCH") != -1) {\r
+ ParseParameter.curastr = textLine;\r
+ ParseParameter.alength = textLine.indexOf('=');\r
+ } else if (textLine.indexOf("TARGET") != -1) {\r
+ ParseParameter.curtstr = textLine;\r
+ ParseParameter.tlength = textLine.indexOf('=');\r
+ } else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) {\r
+ ParseParameter.curcstr = textLine;\r
+ ParseParameter.clength = textLine.indexOf('=');\r
+ } else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) {\r
+ ParseParameter.curnstr = textLine;\r
+ ParseParameter.nlength = textLine.indexOf('=');\r
+ } else if (textLine.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) {\r
+ ParseParameter.curmstr = textLine;\r
+ ParseParameter.mlength = textLine.indexOf('=');\r
+ } else if (textLine.indexOf("MULTIPLE_THREAD") != -1) {\r
+ ParseParameter.curmestr = textLine;\r
+ ParseParameter.melength = textLine.indexOf('=');\r
+ }\r
+ }\r
+ }\r
+ } catch (IOException e) {\r
+ System.out.println("\n# read file error!");\r
+ return false;\r
+ }\r
+\r
+ try {\r
+ br.close();\r
+ } catch (IOException e) {\r
+ System.out\r
+ .println("\n# close BufferedReader error");\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+ \r
+ private static String convertStr(String str){\r
+ String convertStr = null;\r
+ \r
+ if( str.compareTo("-p") == 0 ){\r
+ convertStr = "ACTIVE_PLATFORM";\r
+ }else if( str.compareTo("-a") == 0){\r
+ convertStr = "TARGET_ARCH";\r
+ }else if( str.compareTo("-t") == 0){\r
+ convertStr = "TARGET";\r
+ }else if( str.compareTo("-c") == 0){\r
+ convertStr = "TOOL_CHAIN_CONF";\r
+ }else if( str.compareTo("-n") == 0){\r
+ convertStr = "TOOL_CHAIN_TAG";\r
+ }else if( str.compareTo("-m") == 0){\r
+ convertStr = "MAX_CONCURRENT_THREAD_NUMBER";\r
+ }\r
+ \r
+ return convertStr;\r
+ }\r
+ \r
\r
/**\r
* according to user's input args, write the file directly\r