]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java
add some features:
[mirror_edk2.git] / Tools / Java / Source / ContextTool / org / tianocore / context / ParseParameter.java
... / ...
CommitLineData
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
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
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("-?") == 0) || (args[0].compareToIgnoreCase("/?") == 0) || \r
33 (args[0].compareToIgnoreCase("-help") == 0) || (args[0].compareToIgnoreCase("/help") == 0) ){\r
34 HelpInfo.outputUsageInfo();\r
35 return false;\r
36 }\r
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
41 for(int i=0; i<args.length; i++){\r
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
47 return false;\r
48 }\r
49 }\r
50 }\r
51 \r
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
60 public static int standardizeParameter(String[] args) {\r
61 \r
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
76 i = j;\r
77 if (argstr.charAt(1) == 'p') {\r
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
97 continue;\r
98 }\r
99 curpstr = mergeSetting(curpstr, argstr);\r
100 } else if (argstr.charAt(1) == 't') {\r
101 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
102 System.out.printf("%s\n", curtstr);\r
103 return 1;\r
104 }\r
105 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
106 System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE" );\r
107 return 2;\r
108 }\r
109 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
110 curtstr = tstr;\r
111 continue;\r
112 }\r
113 curtstr = mergeSetting(curtstr, argstr);\r
114 } else if (argstr.charAt(1) == 'a') {\r
115 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
116 System.out.printf("%s\n", curastr);\r
117 return 1;\r
118 }\r
119 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
120 System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM" );\r
121 return 2;\r
122 }\r
123 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
124 curastr = astr;\r
125 continue;\r
126 }\r
127 curastr = mergeSetting(curastr, argstr);\r
128 } else if (argstr.charAt(1) == 'c') {\r
129 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
130 System.out.printf("%s\n", curcstr);\r
131 return 1;\r
132 }\r
133 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
134 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
135 return 2;\r
136 }\r
137 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
138 curcstr = cstr;\r
139 continue;\r
140 }\r
141 curcstr = mergeSetting(curcstr, argstr);\r
142 } else if (argstr.charAt(1) == 'n') {\r
143 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
144 System.out.printf("%s\n", curnstr);\r
145 return 1;\r
146 }\r
147 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
148 System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT" );\r
149 return 2;\r
150 }\r
151 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
152 curnstr = nstr;\r
153 continue;\r
154 }\r
155 curnstr = mergeSetting(curnstr, argstr);\r
156 } else if (argstr.charAt(1) == 'm') {\r
157 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
158 System.out.printf("%s\n", curmstr);\r
159 return 1;\r
160 }\r
161 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
162 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
163 return 2;\r
164 }\r
165 mstr += argstr.substring(2);\r
166 curmstr = mstr;\r
167 if (argstr.charAt(3) == '0'){\r
168 mestr += " Disable";\r
169 } else {\r
170 mestr += " Enable";\r
171 }\r
172 curmestr = mestr;\r
173 }\r
174 \r
175 }\r
176 return 0;\r
177 }\r
178 \r
179 \r
180 public static String mergeSetting( String S1, String S2){\r
181 \r
182 String[] S = S2.split(" ");\r
183 if(S1 == null){\r
184 S1 = tstr.concat(S2.substring(2));\r
185 }else{\r
186 for(int i = 1; i < S.length; i++){\r
187 if( S1.contains(S[i]) == false ){\r
188 S1 = S1.concat(S[i]).concat(" ");\r
189 }\r
190 }\r
191 }\r
192 \r
193 return S1;\r
194 }\r
195 \r
196 public static boolean outputCurSetting(){\r
197 \r
198 System.out.printf( "%s\n", "The current setting is:" );\r
199 System.out.printf( "%s\n", curpstr );\r
200 System.out.printf( "%s\n", curtstr );\r
201 System.out.printf( "%s\n", curastr );\r
202 System.out.printf( "%s\n", curcstr );\r
203 System.out.printf( "%s\n", curnstr );\r
204 System.out.printf( "%s\n", curmstr );\r
205 System.out.printf( "%s\n", curmestr );\r
206 \r
207 return true;\r
208 }\r
209 \r
210 public static int length = 0;\r
211 public static String pstr = new String("ACTIVE_PLATFORM = ");\r
212 public static String tstr = new String("TARGET = ");\r
213 public static String astr = new String("TARGET_ARCH = ");\r
214 public static String cstr = new String("TOOL_CHAIN_CONF = ");\r
215 public static String nstr = new String("TOOL_CHAIN_TAG = ");\r
216 public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");\r
217 public static String mestr = new String("MULTIPLE_THREAD = ");\r
218 \r
219 public static String curpstr = null;\r
220 public static String curtstr = null;\r
221 public static String curastr = null;\r
222 public static String curcstr = null;\r
223 public static String curnstr = null;\r
224 public static String curmstr = null;\r
225 public static String curmestr = null;\r
226 \r
227 public static int plength = 0;\r
228 public static int tlength = 0;\r
229 public static int alength = 0;\r
230 public static int clength = 0;\r
231 public static int nlength = 0;\r
232 public static int mlength = 0;\r
233 public static int melength = 0;\r
234\r
235}\r