]>
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 |
32 | (args[0].compareToIgnoreCase("-?") == 0) || (args[0].compareToIgnoreCase("/?") == 0) || \r | |
33 | (args[0].compareToIgnoreCase("-help") == 0) || (args[0].compareToIgnoreCase("/help") == 0) ){\r | |
c74c7a43 | 34 | HelpInfo.outputUsageInfo();\r |
35 | return false;\r | |
36 | }\r | |
f337986f | 37 | if( args[0].charAt(0) != '-' ){\r |
38 | System.out.printf("%s\n", "Error arguments! Please type \"ContextTool -h\" for helpinfo.");\r | |
39 | return false;\r | |
40 | }\r | |
c74c7a43 | 41 | for(int i=0; i<args.length; i++){\r |
f337986f | 42 | if( (args[i].startsWith("-") && \r |
43 | ((args[i].compareTo("-a") != 0) && (args[i].compareTo("-c") != 0) && \r | |
44 | (args[i].compareTo("-n") != 0) && (args[i].compareTo("-p") != 0) && \r | |
45 | (args[i].compareTo("-t") != 0) && (args[i].compareTo("-m") != 0)))){\r | |
46 | System.out.printf("%s\n", "Error arguments! Please type \"ContextTool -h\" for helpinfo."); \r | |
c74c7a43 | 47 | return false;\r |
48 | }\r | |
49 | }\r | |
50 | }\r | |
51 | \r | |
c74c7a43 | 52 | return true; \r |
53 | }\r | |
54 | \r | |
55 | /** \r | |
56 | * standardize user's input args\r | |
57 | * @param args -- user's input\r | |
58 | * @return no return value\r | |
59 | **/\r | |
f337986f | 60 | public static int standardizeParameter(String[] args) {\r |
c74c7a43 | 61 | \r |
c74c7a43 | 62 | \r |
63 | StringBuffer InputData = new StringBuffer();\r | |
64 | for (int i = 0; i < args.length; i++) {\r | |
65 | InputData.append(args[i]);\r | |
66 | InputData.append(" ");\r | |
67 | }\r | |
68 | \r | |
69 | int i = 0;\r | |
70 | while (i < InputData.length()) {\r | |
71 | int j = InputData.indexOf("-", i + 1);\r | |
72 | if (j == -1)\r | |
73 | j = InputData.length();\r | |
74 | \r | |
75 | String argstr = InputData.substring(i, j);\r | |
f337986f | 76 | i = j;\r |
c74c7a43 | 77 | if (argstr.charAt(1) == 'p') {\r |
f337986f | 78 | //\r |
79 | // argstr is "-p ", display current setting\r | |
80 | //\r | |
81 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r | |
82 | System.out.printf("%s\n", curpstr);\r | |
83 | return 1;\r | |
84 | }\r | |
85 | //\r | |
d3f45848 | 86 | //argstr is "-p ? ", display possible setting\r |
f337986f | 87 | //\r |
88 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
89 | System.out.printf( "%s\n", "assign the platform FPD file's relative path to WORKSPACE" );\r | |
90 | return 2;\r | |
91 | }\r | |
92 | //\r | |
d3f45848 | 93 | //argstr is "-p 0 ", clean current setting\r |
f337986f | 94 | //\r |
95 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
96 | curpstr = pstr;\r | |
f15e1359 | 97 | npflag = true;\r |
f337986f | 98 | continue;\r |
99 | }\r | |
d3f45848 | 100 | String[] S = argstr.split(" ");\r |
101 | if(S.length > 2){\r | |
102 | System.out.printf( "%s\n", "The number of ACTIVE_PLATFORM can not more than 1.");\r | |
103 | return 3;\r | |
f15e1359 | 104 | }\r |
d3f45848 | 105 | curpstr = pstr.concat(argstr.substring(2));\r |
f15e1359 | 106 | npflag = true;\r |
c74c7a43 | 107 | } else if (argstr.charAt(1) == 't') {\r |
f337986f | 108 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r |
109 | System.out.printf("%s\n", curtstr);\r | |
110 | return 1;\r | |
111 | }\r | |
112 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
113 | System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE" );\r | |
114 | return 2;\r | |
115 | }\r | |
116 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
117 | curtstr = tstr;\r | |
f15e1359 | 118 | ntflag = true;\r |
f337986f | 119 | continue;\r |
120 | }\r | |
d3f45848 | 121 | curtstr = tstr.concat(argstr.substring(2));\r |
f15e1359 | 122 | ntflag = true;\r |
c74c7a43 | 123 | } else if (argstr.charAt(1) == 'a') {\r |
f337986f | 124 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r |
125 | System.out.printf("%s\n", curastr);\r | |
126 | return 1;\r | |
127 | }\r | |
128 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
129 | System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM" );\r | |
130 | return 2;\r | |
131 | }\r | |
132 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
133 | curastr = astr;\r | |
f15e1359 | 134 | naflag = true;\r |
f337986f | 135 | continue;\r |
136 | }\r | |
d3f45848 | 137 | curastr = astr.concat(argstr.substring(2));\r |
f15e1359 | 138 | naflag = true;\r |
c74c7a43 | 139 | } else if (argstr.charAt(1) == 'c') {\r |
f337986f | 140 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r |
141 | System.out.printf("%s\n", curcstr);\r | |
142 | return 1;\r | |
143 | }\r | |
144 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
145 | 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 | |
146 | return 2;\r | |
147 | }\r | |
148 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
149 | curcstr = cstr;\r | |
f15e1359 | 150 | ncflag = true;\r |
f337986f | 151 | continue;\r |
152 | }\r | |
d3f45848 | 153 | String[] S = argstr.split(" ");\r |
154 | if(S.length > 2){\r | |
155 | System.out.printf( "%s\n", "The number of TOOL_CHAIN_CONF can not more than 1.");\r | |
156 | return 3;\r | |
f15e1359 | 157 | }\r |
d3f45848 | 158 | curcstr = cstr.concat(argstr.substring(2));\r |
f15e1359 | 159 | ncflag = true;\r |
c74c7a43 | 160 | } else if (argstr.charAt(1) == 'n') {\r |
f337986f | 161 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r |
162 | System.out.printf("%s\n", curnstr);\r | |
163 | return 1;\r | |
164 | }\r | |
165 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
166 | System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT" );\r | |
167 | return 2;\r | |
168 | }\r | |
169 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
170 | curnstr = nstr;\r | |
f15e1359 | 171 | nnflag = true;\r |
f337986f | 172 | continue;\r |
173 | }\r | |
d3f45848 | 174 | curnstr = nstr.concat(argstr.substring(2));\r |
f15e1359 | 175 | nnflag = true;\r |
2c71f6e5 | 176 | } else if (argstr.charAt(1) == 'm') {\r |
f337986f | 177 | if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r |
178 | System.out.printf("%s\n", curmstr);\r | |
179 | return 1;\r | |
180 | }\r | |
181 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
182 | 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 | |
183 | return 2;\r | |
184 | }\r | |
d3f45848 | 185 | String[] S = argstr.split(" ");\r |
186 | if(S.length > 2){\r | |
187 | System.out.printf( "%s\n", "The format of number is wrong.");\r | |
188 | return 3;\r | |
189 | }\r | |
2c71f6e5 | 190 | mstr += argstr.substring(2);\r |
f337986f | 191 | curmstr = mstr;\r |
f15e1359 | 192 | nmflag = true;\r |
2c71f6e5 | 193 | if (argstr.charAt(3) == '0'){\r |
194 | mestr += " Disable";\r | |
195 | } else {\r | |
196 | mestr += " Enable";\r | |
197 | }\r | |
f337986f | 198 | curmestr = mestr;\r |
f15e1359 | 199 | nmeflag = true;\r |
f337986f | 200 | }\r |
201 | \r | |
c74c7a43 | 202 | }\r |
f337986f | 203 | return 0;\r |
204 | }\r | |
f15e1359 | 205 | \r |
f337986f | 206 | \r |
207 | public static boolean outputCurSetting(){\r | |
208 | \r | |
209 | System.out.printf( "%s\n", "The current setting is:" );\r | |
d3f45848 | 210 | \r |
211 | if(curpstr != null){\r | |
212 | System.out.printf( "%s\n", curpstr );\r | |
213 | }\r | |
214 | else{\r | |
215 | System.out.printf( "%s\n", pstr );\r | |
216 | }\r | |
217 | \r | |
218 | if(curtstr != null){\r | |
219 | System.out.printf( "%s\n", curtstr );\r | |
220 | }\r | |
221 | else{\r | |
222 | System.out.printf( "%s\n", tstr );\r | |
223 | }\r | |
224 | \r | |
225 | if(curastr != null){\r | |
226 | System.out.printf( "%s\n", curastr );\r | |
227 | }\r | |
228 | else{\r | |
229 | System.out.printf( "%s\n", astr );\r | |
230 | }\r | |
231 | \r | |
232 | if(curcstr != null){\r | |
233 | System.out.printf( "%s\n", curcstr );\r | |
234 | }\r | |
235 | else{\r | |
236 | System.out.printf( "%s\n", cstr );\r | |
237 | }\r | |
238 | \r | |
239 | if(curnstr != null){\r | |
240 | System.out.printf( "%s\n", curnstr );\r | |
241 | }\r | |
242 | else{\r | |
243 | System.out.printf( "%s\n", nstr );\r | |
244 | }\r | |
245 | \r | |
246 | if(curmstr != null){\r | |
247 | System.out.printf( "%s\n", curmstr );\r | |
248 | }\r | |
249 | else{\r | |
250 | System.out.printf( "%s\n", mstr );\r | |
251 | }\r | |
252 | \r | |
253 | if(curmstr != null){\r | |
254 | System.out.printf( "%s\n", curmestr );\r | |
255 | }\r | |
256 | else{\r | |
257 | System.out.printf( "%s\n", mestr );\r | |
258 | }\r | |
f337986f | 259 | \r |
260 | return true;\r | |
c74c7a43 | 261 | }\r |
262 | \r | |
263 | public static int length = 0;\r | |
2c71f6e5 | 264 | public static String pstr = new String("ACTIVE_PLATFORM = ");\r |
265 | public static String tstr = new String("TARGET = ");\r | |
266 | public static String astr = new String("TARGET_ARCH = ");\r | |
267 | public static String cstr = new String("TOOL_CHAIN_CONF = ");\r | |
268 | public static String nstr = new String("TOOL_CHAIN_TAG = ");\r | |
269 | public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");\r | |
270 | public static String mestr = new String("MULTIPLE_THREAD = ");\r | |
f337986f | 271 | \r |
272 | public static String curpstr = null;\r | |
273 | public static String curtstr = null;\r | |
274 | public static String curastr = null;\r | |
275 | public static String curcstr = null;\r | |
276 | public static String curnstr = null;\r | |
277 | public static String curmstr = null;\r | |
278 | public static String curmestr = null;\r | |
279 | \r | |
280 | public static int plength = 0;\r | |
281 | public static int tlength = 0;\r | |
282 | public static int alength = 0;\r | |
283 | public static int clength = 0;\r | |
284 | public static int nlength = 0;\r | |
285 | public static int mlength = 0;\r | |
286 | public static int melength = 0;\r | |
f15e1359 | 287 | \r |
288 | public static boolean npflag = false;\r | |
289 | public static boolean ntflag = false;\r | |
290 | public static boolean naflag = false;\r | |
291 | public static boolean ncflag = false;\r | |
292 | public static boolean nnflag = false;\r | |
293 | public static boolean nmflag = false;\r | |
294 | public static boolean nmeflag = false;\r | |
c74c7a43 | 295 | \r |
296 | }\r |