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