]>
Commit | Line | Data |
---|---|---|
987912ad | 1 | /** @file\r |
2 | File is ParseParameter class which is used to parse the validity of user's input args\r | |
3 | and standardize them. \r | |
4 | \r | |
5 | Copyright (c) 2006, Intel Corporation\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | **/\r | |
c74c7a43 | 14 | package org.tianocore.context;\r |
15 | \r | |
16 | public class ParseParameter {\r | |
17 | \r | |
18 | \r | |
19 | /** \r | |
20 | * check the validity of user's input args\r | |
21 | * @param args -- user's input\r | |
22 | * @return true or false\r | |
23 | **/\r | |
24 | public static boolean checkParameter(String[] args) {\r | |
25 | \r | |
26 | if(args.length == 0){\r | |
f337986f | 27 | TargetFile.readFile();\r |
28 | outputCurSetting();\r | |
c74c7a43 | 29 | return false;\r |
30 | } else {\r | |
f337986f | 31 | if( (args[0].compareToIgnoreCase("-h") == 0) || (args[0].compareToIgnoreCase("/h") == 0) || \r |
bd236895 | 32 | (args[0].compareToIgnoreCase("--help") == 0) || (args[0].compareToIgnoreCase("/help") == 0) ){\r |
c74c7a43 | 33 | HelpInfo.outputUsageInfo();\r |
34 | return false;\r | |
35 | }\r | |
f337986f | 36 | if( args[0].charAt(0) != '-' ){\r |
c81f5d44 | 37 | System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo.");\r |
f337986f | 38 | return false;\r |
39 | }\r | |
c74c7a43 | 40 | for(int i=0; i<args.length; i++){\r |
f337986f | 41 | if( (args[i].startsWith("-") && \r |
42 | ((args[i].compareTo("-a") != 0) && (args[i].compareTo("-c") != 0) && \r | |
43 | (args[i].compareTo("-n") != 0) && (args[i].compareTo("-p") != 0) && \r | |
44 | (args[i].compareTo("-t") != 0) && (args[i].compareTo("-m") != 0)))){\r | |
c81f5d44 | 45 | System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo."); \r |
c74c7a43 | 46 | return false;\r |
47 | }\r | |
48 | }\r | |
49 | }\r | |
50 | \r | |
c74c7a43 | 51 | return true; \r |
52 | }\r | |
53 | \r | |
54 | /** \r | |
55 | * standardize user's input args\r | |
56 | * @param args -- user's input\r | |
57 | * @return no return value\r | |
58 | **/\r | |
f337986f | 59 | public static int standardizeParameter(String[] args) {\r |
c74c7a43 | 60 | \r |
c74c7a43 | 61 | \r |
62 | StringBuffer InputData = new StringBuffer();\r | |
63 | for (int i = 0; i < args.length; i++) {\r | |
64 | InputData.append(args[i]);\r | |
65 | InputData.append(" ");\r | |
66 | }\r | |
67 | \r | |
68 | int i = 0;\r | |
69 | while (i < InputData.length()) {\r | |
70 | int j = InputData.indexOf("-", i + 1);\r | |
71 | if (j == -1)\r | |
72 | j = InputData.length();\r | |
73 | \r | |
74 | String argstr = InputData.substring(i, j);\r | |
f337986f | 75 | i = j;\r |
c74c7a43 | 76 | if (argstr.charAt(1) == 'p') {\r |
f337986f | 77 | //\r |
78 | // argstr is "-p ", display current setting\r | |
79 | //\r | |
80 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r | |
2f96bdd1 | 81 | if (curpstr != null) {\r |
82 | System.out.printf("%s\n", curpstr);\r | |
83 | } else {\r | |
84 | System.out.printf("No ACTIVE_PLATFORM defined \n");\r | |
85 | }\r | |
f337986f | 86 | return 1;\r |
87 | }\r | |
88 | //\r | |
d3f45848 | 89 | //argstr is "-p ? ", display possible setting\r |
f337986f | 90 | //\r |
91 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
c81f5d44 | 92 | String workspacePath = System.getenv("WORKSPACE");\r |
93 | System.out.printf( "%s\n", "Assign a platform FPD file with relative path to " + workspacePath);\r | |
f337986f | 94 | return 2;\r |
95 | }\r | |
96 | //\r | |
d3f45848 | 97 | //argstr is "-p 0 ", clean current setting\r |
f337986f | 98 | //\r |
99 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
100 | curpstr = pstr;\r | |
f15e1359 | 101 | npflag = true;\r |
f337986f | 102 | continue;\r |
103 | }\r | |
d3f45848 | 104 | String[] S = argstr.split(" ");\r |
105 | if(S.length > 2){\r | |
c81f5d44 | 106 | System.out.printf( "%s\n", "There should be none or only one ACTIVE_PLATFORM. Please check the number of value which follow \"-p\".");\r |
d3f45848 | 107 | return 3;\r |
f15e1359 | 108 | }\r |
d3f45848 | 109 | curpstr = pstr.concat(argstr.substring(2));\r |
f15e1359 | 110 | npflag = true;\r |
c74c7a43 | 111 | } else if (argstr.charAt(1) == 't') {\r |
f337986f | 112 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r |
2f96bdd1 | 113 | if (curtstr != null) {\r |
114 | System.out.printf("%s\n", curtstr);\r | |
115 | } else {\r | |
116 | System.out.printf("No TARGET defined\n");\r | |
117 | }\r | |
f337986f | 118 | return 1;\r |
119 | }\r | |
120 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
c81f5d44 | 121 | System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE." );\r |
f337986f | 122 | return 2;\r |
123 | }\r | |
124 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
125 | curtstr = tstr;\r | |
f15e1359 | 126 | ntflag = true;\r |
f337986f | 127 | continue;\r |
128 | }\r | |
d3f45848 | 129 | curtstr = tstr.concat(argstr.substring(2));\r |
f15e1359 | 130 | ntflag = true;\r |
c74c7a43 | 131 | } else if (argstr.charAt(1) == 'a') {\r |
f337986f | 132 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r |
2f96bdd1 | 133 | if (curastr != null) {\r |
134 | System.out.printf("%s\n", curastr);\r | |
135 | } else {\r | |
136 | System.out.printf("No TARGET_ARCH defined\n");\r | |
137 | }\r | |
f337986f | 138 | return 1;\r |
139 | }\r | |
140 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
c81f5d44 | 141 | System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM." );\r |
f337986f | 142 | return 2;\r |
143 | }\r | |
144 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
145 | curastr = astr;\r | |
f15e1359 | 146 | naflag = true;\r |
f337986f | 147 | continue;\r |
148 | }\r | |
d3f45848 | 149 | curastr = astr.concat(argstr.substring(2));\r |
f15e1359 | 150 | naflag = true;\r |
c74c7a43 | 151 | } else if (argstr.charAt(1) == 'c') {\r |
f337986f | 152 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r |
2f96bdd1 | 153 | if (curcstr != null) {\r |
154 | System.out.printf("%s\n", curcstr);\r | |
155 | } else {\r | |
156 | System.out.printf("No TOOL_CHAIN_CONF defined\n");\r | |
157 | }\r | |
f337986f | 158 | return 1;\r |
159 | }\r | |
160 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
c81f5d44 | 161 | String workspacePath = System.getenv("WORKSPACE");\r |
162 | 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 | |
f337986f | 163 | return 2;\r |
164 | }\r | |
165 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
166 | curcstr = cstr;\r | |
f15e1359 | 167 | ncflag = true;\r |
f337986f | 168 | continue;\r |
169 | }\r | |
d3f45848 | 170 | String[] S = argstr.split(" ");\r |
171 | if(S.length > 2){\r | |
c81f5d44 | 172 | 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 |
d3f45848 | 173 | return 3;\r |
f15e1359 | 174 | }\r |
d3f45848 | 175 | curcstr = cstr.concat(argstr.substring(2));\r |
f15e1359 | 176 | ncflag = true;\r |
c74c7a43 | 177 | } else if (argstr.charAt(1) == 'n') {\r |
f337986f | 178 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r |
2f96bdd1 | 179 | if (curnstr != null) {\r |
180 | System.out.printf("%s\n", curnstr);\r | |
181 | } else {\r | |
182 | System.out.printf("No TOOL_CHAIN_TAG defined\n");\r | |
183 | }\r | |
f337986f | 184 | return 1;\r |
185 | }\r | |
186 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
c81f5d44 | 187 | System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT." );\r |
f337986f | 188 | return 2;\r |
189 | }\r | |
190 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
191 | curnstr = nstr;\r | |
f15e1359 | 192 | nnflag = true;\r |
f337986f | 193 | continue;\r |
194 | }\r | |
d3f45848 | 195 | curnstr = nstr.concat(argstr.substring(2));\r |
f15e1359 | 196 | nnflag = true;\r |
2c71f6e5 | 197 | } else if (argstr.charAt(1) == 'm') {\r |
f337986f | 198 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r |
2f96bdd1 | 199 | if (curmstr != null) {\r |
200 | System.out.printf("%s\n", curmstr);\r | |
201 | } else {\r | |
202 | System.out.printf("No MAX_CONCURRENT_THREAD_NUMBER defined\n");\r | |
203 | }\r | |
f337986f | 204 | return 1;\r |
205 | }\r | |
206 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
207 | 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 | |
208 | return 2;\r | |
209 | }\r | |
d3f45848 | 210 | String[] S = argstr.split(" ");\r |
211 | if(S.length > 2){\r | |
c81f5d44 | 212 | System.out.printf( "%s\n", "There should be one and only one integer, which doesn't include space.");\r |
d3f45848 | 213 | return 3;\r |
214 | }\r | |
2c71f6e5 | 215 | mstr += argstr.substring(2);\r |
f337986f | 216 | curmstr = mstr;\r |
f15e1359 | 217 | nmflag = true;\r |
2c71f6e5 | 218 | if (argstr.charAt(3) == '0'){\r |
219 | mestr += " Disable";\r | |
220 | } else {\r | |
221 | mestr += " Enable";\r | |
222 | }\r | |
f337986f | 223 | curmestr = mestr;\r |
f15e1359 | 224 | nmeflag = true;\r |
f337986f | 225 | }\r |
226 | \r | |
c74c7a43 | 227 | }\r |
f337986f | 228 | return 0;\r |
229 | }\r | |
f15e1359 | 230 | \r |
f337986f | 231 | \r |
232 | public static boolean outputCurSetting(){\r | |
233 | \r | |
234 | System.out.printf( "%s\n", "The current setting is:" );\r | |
bd236895 | 235 | String[] A = { pstr, tstr, astr, cstr, nstr, mstr, mestr };\r |
236 | String[] B = { curpstr, curtstr, curastr, curcstr, curnstr, curmstr, curmestr };\r | |
d3f45848 | 237 | \r |
bd236895 | 238 | for(int i=0; i<A.length; i++){\r |
239 | if(B[i] != null){\r | |
240 | System.out.printf( "%s\n", B[i] );\r | |
241 | }\r | |
242 | else{\r | |
243 | System.out.printf( "%s\n", A[i] );\r | |
244 | }\r | |
245 | \r | |
d3f45848 | 246 | }\r |
f337986f | 247 | \r |
248 | return true;\r | |
c74c7a43 | 249 | }\r |
bd236895 | 250 | \r |
c81f5d44 | 251 | \r |
2c71f6e5 | 252 | public static String pstr = new String("ACTIVE_PLATFORM = ");\r |
253 | public static String tstr = new String("TARGET = ");\r | |
254 | public static String astr = new String("TARGET_ARCH = ");\r | |
255 | public static String cstr = new String("TOOL_CHAIN_CONF = ");\r | |
256 | public static String nstr = new String("TOOL_CHAIN_TAG = ");\r | |
257 | public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");\r | |
258 | public static String mestr = new String("MULTIPLE_THREAD = ");\r | |
f337986f | 259 | \r |
260 | public static String curpstr = null;\r | |
261 | public static String curtstr = null;\r | |
262 | public static String curastr = null;\r | |
263 | public static String curcstr = null;\r | |
264 | public static String curnstr = null;\r | |
265 | public static String curmstr = null;\r | |
266 | public static String curmestr = null;\r | |
267 | \r | |
f15e1359 | 268 | public static boolean npflag = false;\r |
269 | public static boolean ntflag = false;\r | |
270 | public static boolean naflag = false;\r | |
271 | public static boolean ncflag = false;\r | |
272 | public static boolean nnflag = false;\r | |
273 | public static boolean nmflag = false;\r | |
274 | public static boolean nmeflag = false;\r | |
c74c7a43 | 275 | \r |
276 | }\r |