]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java
24adfb70f1f21f88a5f448a4d235a8a04374d29b
[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 System.out.printf("%s\n", curpstr);
82 return 1;
83 }
84 //
85 //argstr is "-p ? ", display possible setting
86 //
87 if(argstr.length() < 6 && argstr.charAt(3) == '?'){
88 String workspacePath = System.getenv("WORKSPACE");
89 System.out.printf( "%s\n", "Assign a platform FPD file with relative path to " + workspacePath);
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", "There should be none or only one ACTIVE_PLATFORM. Please check the number of value which follow \"-p\".");
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 String workspacePath = System.getenv("WORKSPACE");
146 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" );
147 return 2;
148 }
149 if(argstr.length() < 6 && argstr.charAt(3) == '0'){
150 curcstr = cstr;
151 ncflag = true;
152 continue;
153 }
154 String[] S = argstr.split(" ");
155 if(S.length > 2){
156 System.out.printf( "%s\n", "There should be one and only one TOOL_CHAIN_CONF. Please check the number of value which follow \"-c\".");
157 return 3;
158 }
159 curcstr = cstr.concat(argstr.substring(2));
160 ncflag = true;
161 } else if (argstr.charAt(1) == 'n') {
162 if(argstr.length() < 4 && argstr.charAt(2) == ' '){
163 System.out.printf("%s\n", curnstr);
164 return 1;
165 }
166 if(argstr.length() < 6 && argstr.charAt(3) == '?'){
167 System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT." );
168 return 2;
169 }
170 if(argstr.length() < 6 && argstr.charAt(3) == '0'){
171 curnstr = nstr;
172 nnflag = true;
173 continue;
174 }
175 curnstr = nstr.concat(argstr.substring(2));
176 nnflag = true;
177 } else if (argstr.charAt(1) == 'm') {
178 if(argstr.length() < 4 && argstr.charAt(2) == ' '){
179 System.out.printf("%s\n", curmstr);
180 return 1;
181 }
182 if(argstr.length() < 6 && argstr.charAt(3) == '?'){
183 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." );
184 return 2;
185 }
186 String[] S = argstr.split(" ");
187 if(S.length > 2){
188 System.out.printf( "%s\n", "There should be one and only one integer, which doesn't include space.");
189 return 3;
190 }
191 mstr += argstr.substring(2);
192 curmstr = mstr;
193 nmflag = true;
194 if (argstr.charAt(3) == '0'){
195 mestr += " Disable";
196 } else {
197 mestr += " Enable";
198 }
199 curmestr = mestr;
200 nmeflag = true;
201 }
202
203 }
204 return 0;
205 }
206
207
208 public static boolean outputCurSetting(){
209
210 System.out.printf( "%s\n", "The current setting is:" );
211 String[] A = { pstr, tstr, astr, cstr, nstr, mstr, mestr };
212 String[] B = { curpstr, curtstr, curastr, curcstr, curnstr, curmstr, curmestr };
213
214 for(int i=0; i<A.length; i++){
215 if(B[i] != null){
216 System.out.printf( "%s\n", B[i] );
217 }
218 else{
219 System.out.printf( "%s\n", A[i] );
220 }
221
222 }
223
224 return true;
225 }
226
227
228 public static String pstr = new String("ACTIVE_PLATFORM = ");
229 public static String tstr = new String("TARGET = ");
230 public static String astr = new String("TARGET_ARCH = ");
231 public static String cstr = new String("TOOL_CHAIN_CONF = ");
232 public static String nstr = new String("TOOL_CHAIN_TAG = ");
233 public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");
234 public static String mestr = new String("MULTIPLE_THREAD = ");
235
236 public static String curpstr = null;
237 public static String curtstr = null;
238 public static String curastr = null;
239 public static String curcstr = null;
240 public static String curnstr = null;
241 public static String curmstr = null;
242 public static String curmestr = null;
243
244 public static boolean npflag = false;
245 public static boolean ntflag = false;
246 public static boolean naflag = false;
247 public static boolean ncflag = false;
248 public static boolean nnflag = false;
249 public static boolean nmflag = false;
250 public static boolean nmeflag = false;
251
252 }