]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java
d58d28b01087103bf5961c638df294766dd91aef
[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 Parameters! 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 Parameters! 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 String workspacePath = System.getenv("WORKSPACE");
90 System.out.printf( "%s\n", "Assign a platform FPD file with relative path to " + workspacePath);
91 return 2;
92 }
93 //
94 //argstr is "-p 0 ", clean current setting
95 //
96 if(argstr.length() < 6 && argstr.charAt(3) == '0'){
97 curpstr = pstr;
98 npflag = true;
99 continue;
100 }
101 String[] S = argstr.split(" ");
102 if(S.length > 2){
103 System.out.printf( "%s\n", "There should be none or only one ACTIVE_PLATFORM. Please check the number of value which follow \"-p\".");
104 return 3;
105 }
106 curpstr = pstr.concat(argstr.substring(2));
107 npflag = true;
108 } else if (argstr.charAt(1) == 't') {
109 if(argstr.length() < 4 && argstr.charAt(2) == ' '){
110 System.out.printf("%s\n", curtstr);
111 return 1;
112 }
113 if(argstr.length() < 6 && argstr.charAt(3) == '?'){
114 System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE." );
115 return 2;
116 }
117 if(argstr.length() < 6 && argstr.charAt(3) == '0'){
118 curtstr = tstr;
119 ntflag = true;
120 continue;
121 }
122 curtstr = tstr.concat(argstr.substring(2));
123 ntflag = true;
124 } else if (argstr.charAt(1) == 'a') {
125 if(argstr.length() < 4 && argstr.charAt(2) == ' '){
126 System.out.printf("%s\n", curastr);
127 return 1;
128 }
129 if(argstr.length() < 6 && argstr.charAt(3) == '?'){
130 System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM." );
131 return 2;
132 }
133 if(argstr.length() < 6 && argstr.charAt(3) == '0'){
134 curastr = astr;
135 naflag = true;
136 continue;
137 }
138 curastr = astr.concat(argstr.substring(2));
139 naflag = true;
140 } else if (argstr.charAt(1) == 'c') {
141 if(argstr.length() < 4 && argstr.charAt(2) == ' '){
142 System.out.printf("%s\n", curcstr);
143 return 1;
144 }
145 if(argstr.length() < 6 && argstr.charAt(3) == '?'){
146 String workspacePath = System.getenv("WORKSPACE");
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" );
148 return 2;
149 }
150 if(argstr.length() < 6 && argstr.charAt(3) == '0'){
151 curcstr = cstr;
152 ncflag = true;
153 continue;
154 }
155 String[] S = argstr.split(" ");
156 if(S.length > 2){
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\".");
158 return 3;
159 }
160 curcstr = cstr.concat(argstr.substring(2));
161 ncflag = true;
162 } else if (argstr.charAt(1) == 'n') {
163 if(argstr.length() < 4 && argstr.charAt(2) == ' '){
164 System.out.printf("%s\n", curnstr);
165 return 1;
166 }
167 if(argstr.length() < 6 && argstr.charAt(3) == '?'){
168 System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT." );
169 return 2;
170 }
171 if(argstr.length() < 6 && argstr.charAt(3) == '0'){
172 curnstr = nstr;
173 nnflag = true;
174 continue;
175 }
176 curnstr = nstr.concat(argstr.substring(2));
177 nnflag = true;
178 } else if (argstr.charAt(1) == 'm') {
179 if(argstr.length() < 4 && argstr.charAt(2) == ' '){
180 System.out.printf("%s\n", curmstr);
181 return 1;
182 }
183 if(argstr.length() < 6 && argstr.charAt(3) == '?'){
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." );
185 return 2;
186 }
187 String[] S = argstr.split(" ");
188 if(S.length > 2){
189 System.out.printf( "%s\n", "There should be one and only one integer, which doesn't include space.");
190 return 3;
191 }
192 mstr += argstr.substring(2);
193 curmstr = mstr;
194 nmflag = true;
195 if (argstr.charAt(3) == '0'){
196 mestr += " Disable";
197 } else {
198 mestr += " Enable";
199 }
200 curmestr = mestr;
201 nmeflag = true;
202 }
203
204 }
205 return 0;
206 }
207
208
209 public static boolean outputCurSetting(){
210
211 System.out.printf( "%s\n", "The current setting is:" );
212
213 if(curpstr != null){
214 System.out.printf( "%s\n", curpstr );
215 }
216 else{
217 System.out.printf( "%s\n", pstr );
218 }
219
220 if(curtstr != null){
221 System.out.printf( "%s\n", curtstr );
222 }
223 else{
224 System.out.printf( "%s\n", tstr );
225 }
226
227 if(curastr != null){
228 System.out.printf( "%s\n", curastr );
229 }
230 else{
231 System.out.printf( "%s\n", astr );
232 }
233
234 if(curcstr != null){
235 System.out.printf( "%s\n", curcstr );
236 }
237 else{
238 System.out.printf( "%s\n", cstr );
239 }
240
241 if(curnstr != null){
242 System.out.printf( "%s\n", curnstr );
243 }
244 else{
245 System.out.printf( "%s\n", nstr );
246 }
247
248 if(curmstr != null){
249 System.out.printf( "%s\n", curmstr );
250 }
251 else{
252 System.out.printf( "%s\n", mstr );
253 }
254
255 if(curmstr != null){
256 System.out.printf( "%s\n", curmestr );
257 }
258 else{
259 System.out.printf( "%s\n", mestr );
260 }
261
262 return true;
263 }
264
265 public static String pstr = new String("ACTIVE_PLATFORM = ");
266 public static String tstr = new String("TARGET = ");
267 public static String astr = new String("TARGET_ARCH = ");
268 public static String cstr = new String("TOOL_CHAIN_CONF = ");
269 public static String nstr = new String("TOOL_CHAIN_TAG = ");
270 public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");
271 public static String mestr = new String("MULTIPLE_THREAD = ");
272
273 public static String curpstr = null;
274 public static String curtstr = null;
275 public static String curastr = null;
276 public static String curcstr = null;
277 public static String curnstr = null;
278 public static String curmstr = null;
279 public static String curmestr = null;
280
281 public static boolean npflag = false;
282 public static boolean ntflag = false;
283 public static boolean naflag = false;
284 public static boolean ncflag = false;
285 public static boolean nnflag = false;
286 public static boolean nmflag = false;
287 public static boolean nmeflag = false;
288
289 }