]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java
Output more descriptive information when there's no TARGET, TARGET_ARCH, etc defined...
[mirror_edk2.git] / Tools / Java / Source / ContextTool / org / tianocore / context / ParseParameter.java
... / ...
CommitLineData
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
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
27 TargetFile.readFile();\r
28 outputCurSetting();\r
29 return false;\r
30 } else {\r
31 if( (args[0].compareToIgnoreCase("-h") == 0) || (args[0].compareToIgnoreCase("/h") == 0) || \r
32 (args[0].compareToIgnoreCase("--help") == 0) || (args[0].compareToIgnoreCase("/help") == 0) ){\r
33 HelpInfo.outputUsageInfo();\r
34 return false;\r
35 }\r
36 if( args[0].charAt(0) != '-' ){\r
37 System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo.");\r
38 return false;\r
39 }\r
40 for(int i=0; i<args.length; i++){\r
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
45 System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo."); \r
46 return false;\r
47 }\r
48 }\r
49 }\r
50 \r
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
59 public static int standardizeParameter(String[] args) {\r
60 \r
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
75 i = j;\r
76 if (argstr.charAt(1) == 'p') {\r
77 //\r
78 // argstr is "-p ", display current setting\r
79 //\r
80 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
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
86 return 1;\r
87 }\r
88 //\r
89 //argstr is "-p ? ", display possible setting\r
90 //\r
91 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
92 String workspacePath = System.getenv("WORKSPACE");\r
93 System.out.printf( "%s\n", "Assign a platform FPD file with relative path to " + workspacePath);\r
94 return 2;\r
95 }\r
96 //\r
97 //argstr is "-p 0 ", clean current setting\r
98 //\r
99 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
100 curpstr = pstr;\r
101 npflag = true;\r
102 continue;\r
103 }\r
104 String[] S = argstr.split(" ");\r
105 if(S.length > 2){\r
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
107 return 3;\r
108 }\r
109 curpstr = pstr.concat(argstr.substring(2));\r
110 npflag = true;\r
111 } else if (argstr.charAt(1) == 't') {\r
112 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
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
118 return 1;\r
119 }\r
120 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
121 System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE." );\r
122 return 2;\r
123 }\r
124 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
125 curtstr = tstr;\r
126 ntflag = true;\r
127 continue;\r
128 }\r
129 curtstr = tstr.concat(argstr.substring(2));\r
130 ntflag = true;\r
131 } else if (argstr.charAt(1) == 'a') {\r
132 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
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
138 return 1;\r
139 }\r
140 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
141 System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM." );\r
142 return 2;\r
143 }\r
144 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
145 curastr = astr;\r
146 naflag = true;\r
147 continue;\r
148 }\r
149 curastr = astr.concat(argstr.substring(2));\r
150 naflag = true;\r
151 } else if (argstr.charAt(1) == 'c') {\r
152 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
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
158 return 1;\r
159 }\r
160 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
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
163 return 2;\r
164 }\r
165 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
166 curcstr = cstr;\r
167 ncflag = true;\r
168 continue;\r
169 }\r
170 String[] S = argstr.split(" ");\r
171 if(S.length > 2){\r
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
173 return 3;\r
174 }\r
175 curcstr = cstr.concat(argstr.substring(2));\r
176 ncflag = true;\r
177 } else if (argstr.charAt(1) == 'n') {\r
178 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
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
184 return 1;\r
185 }\r
186 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
187 System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT." );\r
188 return 2;\r
189 }\r
190 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
191 curnstr = nstr;\r
192 nnflag = true;\r
193 continue;\r
194 }\r
195 curnstr = nstr.concat(argstr.substring(2));\r
196 nnflag = true;\r
197 } else if (argstr.charAt(1) == 'm') {\r
198 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
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
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
210 String[] S = argstr.split(" ");\r
211 if(S.length > 2){\r
212 System.out.printf( "%s\n", "There should be one and only one integer, which doesn't include space.");\r
213 return 3;\r
214 }\r
215 mstr += argstr.substring(2);\r
216 curmstr = mstr;\r
217 nmflag = true;\r
218 if (argstr.charAt(3) == '0'){\r
219 mestr += " Disable";\r
220 } else {\r
221 mestr += " Enable";\r
222 }\r
223 curmestr = mestr;\r
224 nmeflag = true;\r
225 }\r
226 \r
227 }\r
228 return 0;\r
229 }\r
230\r
231 \r
232 public static boolean outputCurSetting(){\r
233 \r
234 System.out.printf( "%s\n", "The current setting is:" );\r
235 String[] A = { pstr, tstr, astr, cstr, nstr, mstr, mestr };\r
236 String[] B = { curpstr, curtstr, curastr, curcstr, curnstr, curmstr, curmestr };\r
237 \r
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
246 }\r
247 \r
248 return true;\r
249 }\r
250\r
251 \r
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
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
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
275\r
276}\r