]>
Commit | Line | Data |
---|---|---|
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 | |
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 | |
27 | TargetFile.readFile();\r | |
28 | outputCurSetting();\r | |
29 | return false;\r | |
30 | } else {\r | |
31 | if( (args[0].compareToIgnoreCase("-h") == 0) || (args[0].compareToIgnoreCase("/h") == 0) || \r | |
32 | (args[0].compareToIgnoreCase("--help") == 0) || (args[0].compareToIgnoreCase("/help") == 0) ){\r | |
33 | HelpInfo.outputUsageInfo();\r | |
34 | return false;\r | |
35 | }\r | |
36 | if( args[0].charAt(0) != '-' ){\r | |
37 | System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo.");\r | |
38 | return false;\r | |
39 | }\r | |
40 | for(int i=0; i<args.length; i++){\r | |
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 | |
45 | System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo."); \r | |
46 | return false;\r | |
47 | }\r | |
48 | }\r | |
49 | }\r | |
50 | \r | |
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 | |
59 | public static int standardizeParameter(String[] args) {\r | |
60 | \r | |
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 | |
75 | i = j;\r | |
76 | if (argstr.charAt(1) == 'p') {\r | |
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 | |
85 | //argstr is "-p ? ", display possible setting\r | |
86 | //\r | |
87 | if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r | |
88 | String workspacePath = System.getenv("WORKSPACE");\r | |
89 | System.out.printf( "%s\n", "Assign a platform FPD file with relative path to " + workspacePath);\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 | |
97 | npflag = true;\r | |
98 | continue;\r | |
99 | }\r | |
100 | String[] S = argstr.split(" ");\r | |
101 | if(S.length > 2){\r | |
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 | |
103 | return 3;\r | |
104 | }\r | |
105 | curpstr = pstr.concat(argstr.substring(2));\r | |
106 | npflag = true;\r | |
107 | } else if (argstr.charAt(1) == 't') {\r | |
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 | |
113 | System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE." );\r | |
114 | return 2;\r | |
115 | }\r | |
116 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
117 | curtstr = tstr;\r | |
118 | ntflag = true;\r | |
119 | continue;\r | |
120 | }\r | |
121 | curtstr = tstr.concat(argstr.substring(2));\r | |
122 | ntflag = true;\r | |
123 | } else if (argstr.charAt(1) == 'a') {\r | |
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 | |
129 | System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM." );\r | |
130 | return 2;\r | |
131 | }\r | |
132 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
133 | curastr = astr;\r | |
134 | naflag = true;\r | |
135 | continue;\r | |
136 | }\r | |
137 | curastr = astr.concat(argstr.substring(2));\r | |
138 | naflag = true;\r | |
139 | } else if (argstr.charAt(1) == 'c') {\r | |
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 | |
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 | |
147 | return 2;\r | |
148 | }\r | |
149 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
150 | curcstr = cstr;\r | |
151 | ncflag = true;\r | |
152 | continue;\r | |
153 | }\r | |
154 | String[] S = argstr.split(" ");\r | |
155 | if(S.length > 2){\r | |
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 | |
157 | return 3;\r | |
158 | }\r | |
159 | curcstr = cstr.concat(argstr.substring(2));\r | |
160 | ncflag = true;\r | |
161 | } else if (argstr.charAt(1) == 'n') {\r | |
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 | |
167 | System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT." );\r | |
168 | return 2;\r | |
169 | }\r | |
170 | if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r | |
171 | curnstr = nstr;\r | |
172 | nnflag = true;\r | |
173 | continue;\r | |
174 | }\r | |
175 | curnstr = nstr.concat(argstr.substring(2));\r | |
176 | nnflag = true;\r | |
177 | } else if (argstr.charAt(1) == 'm') {\r | |
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 | |
186 | String[] S = argstr.split(" ");\r | |
187 | if(S.length > 2){\r | |
188 | System.out.printf( "%s\n", "There should be one and only one integer, which doesn't include space.");\r | |
189 | return 3;\r | |
190 | }\r | |
191 | mstr += argstr.substring(2);\r | |
192 | curmstr = mstr;\r | |
193 | nmflag = true;\r | |
194 | if (argstr.charAt(3) == '0'){\r | |
195 | mestr += " Disable";\r | |
196 | } else {\r | |
197 | mestr += " Enable";\r | |
198 | }\r | |
199 | curmestr = mestr;\r | |
200 | nmeflag = true;\r | |
201 | }\r | |
202 | \r | |
203 | }\r | |
204 | return 0;\r | |
205 | }\r | |
206 | \r | |
207 | \r | |
208 | public static boolean outputCurSetting(){\r | |
209 | \r | |
210 | System.out.printf( "%s\n", "The current setting is:" );\r | |
211 | String[] A = { pstr, tstr, astr, cstr, nstr, mstr, mestr };\r | |
212 | String[] B = { curpstr, curtstr, curastr, curcstr, curnstr, curmstr, curmestr };\r | |
213 | \r | |
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 | |
222 | }\r | |
223 | \r | |
224 | return true;\r | |
225 | }\r | |
226 | \r | |
227 | \r | |
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 | |
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 | |
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 | |
251 | \r | |
252 | }\r |