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