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