+++ /dev/null
-/** @file\r
- File is ParseParameter class which is used to parse the validity of user's input args\r
- and standardize them. \r
- \r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-**/\r
-package org.tianocore.context;\r
-\r
-public class ParseParameter {\r
-\r
- \r
- /** \r
- * check the validity of user's input args\r
- * @param args -- user's input\r
- * @return true or false\r
- **/\r
- public static boolean checkParameter(String[] args) {\r
- \r
- if(args.length == 0){\r
- TargetFile.readFile();\r
- outputCurSetting();\r
- return false;\r
- } else {\r
- if( (args[0].compareToIgnoreCase("-h") == 0) || (args[0].compareToIgnoreCase("/h") == 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 Parameters! Please type \"ContextTool -h\" for helpinfo.");\r
- return false;\r
- }\r
- for(int i=0; i<args.length; i++){\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 Parameters! Please type \"ContextTool -h\" for helpinfo."); \r
- return false;\r
- }\r
- }\r
- }\r
- \r
- return true; \r
- }\r
- \r
- /** \r
- * standardize user's input args\r
- * @param args -- user's input\r
- * @return no return value\r
- **/\r
- public static int standardizeParameter(String[] args) {\r
- \r
- \r
- StringBuffer InputData = new StringBuffer();\r
- for (int i = 0; i < args.length; i++) {\r
- InputData.append(args[i]);\r
- InputData.append(" ");\r
- }\r
-\r
- int i = 0;\r
- while (i < InputData.length()) {\r
- int j = InputData.indexOf("-", i + 1);\r
- if (j == -1)\r
- j = InputData.length();\r
-\r
- String argstr = InputData.substring(i, j);\r
- i = j;\r
- if (argstr.charAt(1) == 'p') {\r
- //\r
- // argstr is "-p ", display current setting\r
- //\r
- if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
- if (curpstr != null) {\r
- System.out.printf("%s\n", curpstr);\r
- } else {\r
- System.out.printf("No ACTIVE_PLATFORM defined \n");\r
- }\r
- return 1;\r
- }\r
- //\r
- //argstr is "-p ? ", display possible setting\r
- //\r
- if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
- String workspacePath = System.getenv("WORKSPACE");\r
- System.out.printf( "%s\n", "Assign a platform FPD file with relative path to " + workspacePath);\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
- npflag = true;\r
- continue;\r
- }\r
- String[] S = argstr.split(" ");\r
- if(S.length > 2){\r
- System.out.printf( "%s\n", "There should be none or only one ACTIVE_PLATFORM. Please check the number of value which follow \"-p\".");\r
- return 3;\r
- }\r
- curpstr = pstr.concat(argstr.substring(2));\r
- npflag = true;\r
- } else if (argstr.charAt(1) == 't') {\r
- if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
- if (curtstr != null) {\r
- System.out.printf("%s\n", curtstr);\r
- } else {\r
- System.out.printf("No TARGET defined\n");\r
- }\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
- ntflag = true;\r
- continue;\r
- }\r
- curtstr = tstr.concat(argstr.substring(2));\r
- ntflag = true;\r
- } else if (argstr.charAt(1) == 'a') {\r
- if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
- if (curastr != null) {\r
- System.out.printf("%s\n", curastr);\r
- } else {\r
- System.out.printf("No TARGET_ARCH defined\n");\r
- }\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
- naflag = true;\r
- continue;\r
- }\r
- curastr = astr.concat(argstr.substring(2));\r
- naflag = true;\r
- } else if (argstr.charAt(1) == 'c') {\r
- if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
- if (curcstr != null) {\r
- System.out.printf("%s\n", curcstr);\r
- } else {\r
- System.out.printf("No TOOL_CHAIN_CONF defined\n");\r
- }\r
- return 1;\r
- }\r
- if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
- String workspacePath = System.getenv("WORKSPACE");\r
- System.out.printf( "%s\n", "Assign a txt file with relative path to " + workspacePath + ", which specify the tools to use for the build and must be located in the path:" + workspacePath + "\\Tools\\Conf" );\r
- return 2;\r
- }\r
- if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
- curcstr = cstr;\r
- ncflag = true;\r
- continue;\r
- }\r
- String[] S = argstr.split(" ");\r
- if(S.length > 2){\r
- System.out.printf( "%s\n", "There should be one and only one TOOL_CHAIN_CONF. Please check the number of value which follow \"-c\".");\r
- return 3;\r
- }\r
- curcstr = cstr.concat(argstr.substring(2));\r
- ncflag = true;\r
- } else if (argstr.charAt(1) == 'n') {\r
- if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
- if (curnstr != null) {\r
- System.out.printf("%s\n", curnstr);\r
- } else {\r
- System.out.printf("No TOOL_CHAIN_TAG defined\n");\r
- }\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
- nnflag = true;\r
- continue;\r
- }\r
- curnstr = nstr.concat(argstr.substring(2));\r
- nnflag = true;\r
- } else if (argstr.charAt(1) == 'm') {\r
- if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
- if (curmstr != null) {\r
- System.out.printf("%s\n", curmstr);\r
- } else {\r
- System.out.printf("No MAX_CONCURRENT_THREAD_NUMBER defined\n");\r
- }\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
- String[] S = argstr.split(" ");\r
- if(S.length > 2){\r
- System.out.printf( "%s\n", "There should be one and only one integer, which doesn't include space.");\r
- return 3;\r
- }\r
- mstr += argstr.substring(2);\r
- curmstr = mstr;\r
- nmflag = true;\r
- if (argstr.charAt(3) == '0'){\r
- mestr += " Disable";\r
- } else {\r
- mestr += " Enable";\r
- }\r
- curmestr = mestr;\r
- nmeflag = true;\r
- }\r
- \r
- }\r
- return 0;\r
- }\r
-\r
- \r
- public static boolean outputCurSetting(){\r
- \r
- System.out.printf( "%s\n", "The current setting is:" );\r
- String[] A = { pstr, tstr, astr, cstr, nstr, mstr, mestr };\r
- String[] B = { curpstr, curtstr, curastr, curcstr, curnstr, curmstr, curmestr };\r
- \r
- for(int i=0; i<A.length; i++){\r
- if(B[i] != null){\r
- System.out.printf( "%s\n", B[i] );\r
- }\r
- else{\r
- System.out.printf( "%s\n", A[i] );\r
- }\r
- \r
- }\r
- \r
- return true;\r
- }\r
-\r
- \r
- public static String pstr = new String("ACTIVE_PLATFORM = ");\r
- public static String tstr = new String("TARGET = ");\r
- public static String astr = new String("TARGET_ARCH = ");\r
- public static String cstr = new String("TOOL_CHAIN_CONF = ");\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 boolean npflag = false;\r
- public static boolean ntflag = false;\r
- public static boolean naflag = false;\r
- public static boolean ncflag = false;\r
- public static boolean nnflag = false;\r
- public static boolean nmflag = false;\r
- public static boolean nmeflag = false;\r
-\r
-}\r