]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java
1.add code to support friendly output message.
[mirror_edk2.git] / Tools / Java / Source / ContextTool / org / tianocore / context / ParseParameter.java
CommitLineData
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
5Copyright (c) 2006, Intel Corporation\r
6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10 \r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13**/\r
c74c7a43 14package org.tianocore.context;\r
15\r
16public 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
c81f5d44 38 System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo.");\r
f337986f 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
c81f5d44 46 System.out.printf("%s\n", "Error Parameters! 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
c81f5d44 89 String workspacePath = System.getenv("WORKSPACE");\r
90 System.out.printf( "%s\n", "Assign a platform FPD file with relative path to " + workspacePath);\r
f337986f 91 return 2;\r
92 }\r
93 //\r
d3f45848 94 //argstr is "-p 0 ", clean current setting\r
f337986f 95 //\r
96 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
97 curpstr = pstr;\r
f15e1359 98 npflag = true;\r
f337986f 99 continue;\r
100 }\r
d3f45848 101 String[] S = argstr.split(" ");\r
102 if(S.length > 2){\r
c81f5d44 103 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 104 return 3;\r
f15e1359 105 }\r
d3f45848 106 curpstr = pstr.concat(argstr.substring(2));\r
f15e1359 107 npflag = true;\r
c74c7a43 108 } else if (argstr.charAt(1) == 't') {\r
f337986f 109 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
110 System.out.printf("%s\n", curtstr);\r
111 return 1;\r
112 }\r
113 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
c81f5d44 114 System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE." );\r
f337986f 115 return 2;\r
116 }\r
117 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
118 curtstr = tstr;\r
f15e1359 119 ntflag = true;\r
f337986f 120 continue;\r
121 }\r
d3f45848 122 curtstr = tstr.concat(argstr.substring(2));\r
f15e1359 123 ntflag = true;\r
c74c7a43 124 } else if (argstr.charAt(1) == 'a') {\r
f337986f 125 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
126 System.out.printf("%s\n", curastr);\r
127 return 1;\r
128 }\r
129 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
c81f5d44 130 System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM." );\r
f337986f 131 return 2;\r
132 }\r
133 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
134 curastr = astr;\r
f15e1359 135 naflag = true;\r
f337986f 136 continue;\r
137 }\r
d3f45848 138 curastr = astr.concat(argstr.substring(2));\r
f15e1359 139 naflag = true;\r
c74c7a43 140 } else if (argstr.charAt(1) == 'c') {\r
f337986f 141 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
142 System.out.printf("%s\n", curcstr);\r
143 return 1;\r
144 }\r
145 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
c81f5d44 146 String workspacePath = System.getenv("WORKSPACE");\r
147 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 148 return 2;\r
149 }\r
150 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
151 curcstr = cstr;\r
f15e1359 152 ncflag = true;\r
f337986f 153 continue;\r
154 }\r
d3f45848 155 String[] S = argstr.split(" ");\r
156 if(S.length > 2){\r
c81f5d44 157 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 158 return 3;\r
f15e1359 159 }\r
d3f45848 160 curcstr = cstr.concat(argstr.substring(2));\r
f15e1359 161 ncflag = true;\r
c74c7a43 162 } else if (argstr.charAt(1) == 'n') {\r
f337986f 163 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
164 System.out.printf("%s\n", curnstr);\r
165 return 1;\r
166 }\r
167 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
c81f5d44 168 System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT." );\r
f337986f 169 return 2;\r
170 }\r
171 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
172 curnstr = nstr;\r
f15e1359 173 nnflag = true;\r
f337986f 174 continue;\r
175 }\r
d3f45848 176 curnstr = nstr.concat(argstr.substring(2));\r
f15e1359 177 nnflag = true;\r
2c71f6e5 178 } else if (argstr.charAt(1) == 'm') {\r
f337986f 179 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
180 System.out.printf("%s\n", curmstr);\r
181 return 1;\r
182 }\r
183 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
184 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
185 return 2;\r
186 }\r
d3f45848 187 String[] S = argstr.split(" ");\r
188 if(S.length > 2){\r
c81f5d44 189 System.out.printf( "%s\n", "There should be one and only one integer, which doesn't include space.");\r
d3f45848 190 return 3;\r
191 }\r
2c71f6e5 192 mstr += argstr.substring(2);\r
f337986f 193 curmstr = mstr;\r
f15e1359 194 nmflag = true;\r
2c71f6e5 195 if (argstr.charAt(3) == '0'){\r
196 mestr += " Disable";\r
197 } else {\r
198 mestr += " Enable";\r
199 }\r
f337986f 200 curmestr = mestr;\r
f15e1359 201 nmeflag = true;\r
f337986f 202 }\r
203 \r
c74c7a43 204 }\r
f337986f 205 return 0;\r
206 }\r
f15e1359 207\r
f337986f 208 \r
209 public static boolean outputCurSetting(){\r
210 \r
211 System.out.printf( "%s\n", "The current setting is:" );\r
d3f45848 212 \r
213 if(curpstr != null){\r
214 System.out.printf( "%s\n", curpstr );\r
215 }\r
216 else{\r
217 System.out.printf( "%s\n", pstr );\r
218 }\r
219 \r
220 if(curtstr != null){\r
221 System.out.printf( "%s\n", curtstr );\r
222 }\r
223 else{\r
224 System.out.printf( "%s\n", tstr );\r
225 }\r
226 \r
227 if(curastr != null){\r
228 System.out.printf( "%s\n", curastr );\r
229 }\r
230 else{\r
231 System.out.printf( "%s\n", astr );\r
232 }\r
233 \r
234 if(curcstr != null){\r
235 System.out.printf( "%s\n", curcstr );\r
236 }\r
237 else{\r
238 System.out.printf( "%s\n", cstr );\r
239 }\r
240 \r
241 if(curnstr != null){\r
242 System.out.printf( "%s\n", curnstr );\r
243 }\r
244 else{\r
245 System.out.printf( "%s\n", nstr );\r
246 }\r
247 \r
248 if(curmstr != null){\r
249 System.out.printf( "%s\n", curmstr );\r
250 }\r
251 else{\r
252 System.out.printf( "%s\n", mstr );\r
253 }\r
254 \r
255 if(curmstr != null){\r
256 System.out.printf( "%s\n", curmestr );\r
257 }\r
258 else{\r
259 System.out.printf( "%s\n", mestr );\r
260 }\r
f337986f 261 \r
262 return true;\r
c74c7a43 263 }\r
c81f5d44 264 \r
2c71f6e5 265 public static String pstr = new String("ACTIVE_PLATFORM = ");\r
266 public static String tstr = new String("TARGET = ");\r
267 public static String astr = new String("TARGET_ARCH = ");\r
268 public static String cstr = new String("TOOL_CHAIN_CONF = ");\r
269 public static String nstr = new String("TOOL_CHAIN_TAG = ");\r
270 public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");\r
271 public static String mestr = new String("MULTIPLE_THREAD = ");\r
f337986f 272 \r
273 public static String curpstr = null;\r
274 public static String curtstr = null;\r
275 public static String curastr = null;\r
276 public static String curcstr = null;\r
277 public static String curnstr = null;\r
278 public static String curmstr = null;\r
279 public static String curmestr = null;\r
280 \r
f15e1359 281 public static boolean npflag = false;\r
282 public static boolean ntflag = false;\r
283 public static boolean naflag = false;\r
284 public static boolean ncflag = false;\r
285 public static boolean nnflag = false;\r
286 public static boolean nmflag = false;\r
287 public static boolean nmeflag = false;\r
c74c7a43 288\r
289}\r