]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java
Fix the bug EDKT464. ? and * are regarded as wildcard char by OS. so we have to remov...
[mirror_edk2.git] / Tools / Java / Source / ContextTool / org / tianocore / context / ParseParameter.java
CommitLineData
987912ad 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
c74c7a43 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
f337986f 27 TargetFile.readFile();\r
28 outputCurSetting();\r
c74c7a43 29 return false;\r
30 } else {\r
f337986f 31 if( (args[0].compareToIgnoreCase("-h") == 0) || (args[0].compareToIgnoreCase("/h") == 0) || \r
bd236895 32 (args[0].compareToIgnoreCase("--help") == 0) || (args[0].compareToIgnoreCase("/help") == 0) ){\r
c74c7a43 33 HelpInfo.outputUsageInfo();\r
34 return false;\r
35 }\r
f337986f 36 if( args[0].charAt(0) != '-' ){\r
c81f5d44 37 System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo.");\r
f337986f 38 return false;\r
39 }\r
c74c7a43 40 for(int i=0; i<args.length; i++){\r
f337986f 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
c81f5d44 45 System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo."); \r
c74c7a43 46 return false;\r
47 }\r
48 }\r
49 }\r
50 \r
c74c7a43 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
f337986f 59 public static int standardizeParameter(String[] args) {\r
c74c7a43 60 \r
c74c7a43 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
f337986f 75 i = j;\r
c74c7a43 76 if (argstr.charAt(1) == 'p') {\r
f337986f 77 //\r
78 // argstr is "-p ", display current setting\r
79 //\r
80 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
81 System.out.printf("%s\n", curpstr);\r
82 return 1;\r
83 }\r
84 //\r
d3f45848 85 //argstr is "-p ? ", display possible setting\r
f337986f 86 //\r
87 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
c81f5d44 88 String workspacePath = System.getenv("WORKSPACE");\r
89 System.out.printf( "%s\n", "Assign a platform FPD file with relative path to " + workspacePath);\r
f337986f 90 return 2;\r
91 }\r
92 //\r
d3f45848 93 //argstr is "-p 0 ", clean current setting\r
f337986f 94 //\r
95 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
96 curpstr = pstr;\r
f15e1359 97 npflag = true;\r
f337986f 98 continue;\r
99 }\r
d3f45848 100 String[] S = argstr.split(" ");\r
101 if(S.length > 2){\r
c81f5d44 102 System.out.printf( "%s\n", "There should be none or only one ACTIVE_PLATFORM. Please check the number of value which follow \"-p\".");\r
d3f45848 103 return 3;\r
f15e1359 104 }\r
d3f45848 105 curpstr = pstr.concat(argstr.substring(2));\r
f15e1359 106 npflag = true;\r
c74c7a43 107 } else if (argstr.charAt(1) == 't') {\r
f337986f 108 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
109 System.out.printf("%s\n", curtstr);\r
110 return 1;\r
111 }\r
112 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
c81f5d44 113 System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE." );\r
f337986f 114 return 2;\r
115 }\r
116 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
117 curtstr = tstr;\r
f15e1359 118 ntflag = true;\r
f337986f 119 continue;\r
120 }\r
d3f45848 121 curtstr = tstr.concat(argstr.substring(2));\r
f15e1359 122 ntflag = true;\r
c74c7a43 123 } else if (argstr.charAt(1) == 'a') {\r
f337986f 124 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
125 System.out.printf("%s\n", curastr);\r
126 return 1;\r
127 }\r
128 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
c81f5d44 129 System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM." );\r
f337986f 130 return 2;\r
131 }\r
132 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
133 curastr = astr;\r
f15e1359 134 naflag = true;\r
f337986f 135 continue;\r
136 }\r
d3f45848 137 curastr = astr.concat(argstr.substring(2));\r
f15e1359 138 naflag = true;\r
c74c7a43 139 } else if (argstr.charAt(1) == 'c') {\r
f337986f 140 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
141 System.out.printf("%s\n", curcstr);\r
142 return 1;\r
143 }\r
144 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
c81f5d44 145 String workspacePath = System.getenv("WORKSPACE");\r
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" );\r
f337986f 147 return 2;\r
148 }\r
149 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
150 curcstr = cstr;\r
f15e1359 151 ncflag = true;\r
f337986f 152 continue;\r
153 }\r
d3f45848 154 String[] S = argstr.split(" ");\r
155 if(S.length > 2){\r
c81f5d44 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\".");\r
d3f45848 157 return 3;\r
f15e1359 158 }\r
d3f45848 159 curcstr = cstr.concat(argstr.substring(2));\r
f15e1359 160 ncflag = true;\r
c74c7a43 161 } else if (argstr.charAt(1) == 'n') {\r
f337986f 162 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
163 System.out.printf("%s\n", curnstr);\r
164 return 1;\r
165 }\r
166 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
c81f5d44 167 System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT." );\r
f337986f 168 return 2;\r
169 }\r
170 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
171 curnstr = nstr;\r
f15e1359 172 nnflag = true;\r
f337986f 173 continue;\r
174 }\r
d3f45848 175 curnstr = nstr.concat(argstr.substring(2));\r
f15e1359 176 nnflag = true;\r
2c71f6e5 177 } else if (argstr.charAt(1) == 'm') {\r
f337986f 178 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
179 System.out.printf("%s\n", curmstr);\r
180 return 1;\r
181 }\r
182 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
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." );\r
184 return 2;\r
185 }\r
d3f45848 186 String[] S = argstr.split(" ");\r
187 if(S.length > 2){\r
c81f5d44 188 System.out.printf( "%s\n", "There should be one and only one integer, which doesn't include space.");\r
d3f45848 189 return 3;\r
190 }\r
2c71f6e5 191 mstr += argstr.substring(2);\r
f337986f 192 curmstr = mstr;\r
f15e1359 193 nmflag = true;\r
2c71f6e5 194 if (argstr.charAt(3) == '0'){\r
195 mestr += " Disable";\r
196 } else {\r
197 mestr += " Enable";\r
198 }\r
f337986f 199 curmestr = mestr;\r
f15e1359 200 nmeflag = true;\r
f337986f 201 }\r
202 \r
c74c7a43 203 }\r
f337986f 204 return 0;\r
205 }\r
f15e1359 206\r
f337986f 207 \r
208 public static boolean outputCurSetting(){\r
209 \r
210 System.out.printf( "%s\n", "The current setting is:" );\r
bd236895 211 String[] A = { pstr, tstr, astr, cstr, nstr, mstr, mestr };\r
212 String[] B = { curpstr, curtstr, curastr, curcstr, curnstr, curmstr, curmestr };\r
d3f45848 213 \r
bd236895 214 for(int i=0; i<A.length; i++){\r
215 if(B[i] != null){\r
216 System.out.printf( "%s\n", B[i] );\r
217 }\r
218 else{\r
219 System.out.printf( "%s\n", A[i] );\r
220 }\r
221 \r
d3f45848 222 }\r
f337986f 223 \r
224 return true;\r
c74c7a43 225 }\r
bd236895 226\r
c81f5d44 227 \r
2c71f6e5 228 public static String pstr = new String("ACTIVE_PLATFORM = ");\r
229 public static String tstr = new String("TARGET = ");\r
230 public static String astr = new String("TARGET_ARCH = ");\r
231 public static String cstr = new String("TOOL_CHAIN_CONF = ");\r
232 public static String nstr = new String("TOOL_CHAIN_TAG = ");\r
233 public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");\r
234 public static String mestr = new String("MULTIPLE_THREAD = ");\r
f337986f 235 \r
236 public static String curpstr = null;\r
237 public static String curtstr = null;\r
238 public static String curastr = null;\r
239 public static String curcstr = null;\r
240 public static String curnstr = null;\r
241 public static String curmstr = null;\r
242 public static String curmestr = null;\r
243 \r
f15e1359 244 public static boolean npflag = false;\r
245 public static boolean ntflag = false;\r
246 public static boolean naflag = false;\r
247 public static boolean ncflag = false;\r
248 public static boolean nnflag = false;\r
249 public static boolean nmflag = false;\r
250 public static boolean nmeflag = false;\r
c74c7a43 251\r
252}\r