add ContextTool to workspace/Tools
[mirror_edk2.git] / Tools / Source / ContextTool / org / tianocore / context / ParseParameter.java
CommitLineData
c74c7a43 1package org.tianocore.context;\r
2\r
3public class ParseParameter {\r
4\r
5 \r
6 /** \r
7 * check the validity of user's input args\r
8 * @param args -- user's input\r
9 * @return true or false\r
10 **/\r
11 public static boolean checkParameter(String[] args) {\r
12 \r
13 if(args.length == 0){\r
14 HelpInfo.outputUsageInfo();\r
15 return false;\r
16 } else {\r
17 if( args[0].charAt(0) != '-' ){\r
18 HelpInfo.outputUsageInfo();\r
19 return false;\r
20 }\r
21 for(int i=0; i<args.length; i++){\r
22 if( (args[i].compareToIgnoreCase("-h") == 0) || \r
23 (args[i].startsWith("-") && ((args[i].charAt(1) != 'a') && (args[i].charAt(1) != 'c') \r
24 && (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't')))){\r
25 HelpInfo.outputUsageInfo();\r
26 return false;\r
27 }\r
28 }\r
29 }\r
30 \r
31 standardizeParameter(args);\r
32 return true; \r
33 }\r
34 \r
35 /** \r
36 * standardize user's input args\r
37 * @param args -- user's input\r
38 * @return no return value\r
39 **/\r
40 private static void standardizeParameter(String[] args) {\r
41 \r
42 length = pstr.length();\r
43 \r
44 StringBuffer InputData = new StringBuffer();\r
45 for (int i = 0; i < args.length; i++) {\r
46 InputData.append(args[i]);\r
47 InputData.append(" ");\r
48 }\r
49\r
50 int i = 0;\r
51 while (i < InputData.length()) {\r
52 int j = InputData.indexOf("-", i + 1);\r
53 if (j == -1)\r
54 j = InputData.length();\r
55\r
56 String argstr = InputData.substring(i, j);\r
57\r
58 if (argstr.charAt(1) == 'p') {\r
59 pstr += argstr.substring(2);\r
60 // pstr += "\n";\r
61 } else if (argstr.charAt(1) == 't') {\r
62 tstr += argstr.substring(2);\r
63 // tstr += "\n";\r
64 } else if (argstr.charAt(1) == 'a') {\r
65 astr += argstr.substring(2);\r
66// astr += "\n";\r
67 } else if (argstr.charAt(1) == 'c') {\r
68 cstr += argstr.substring(2);\r
69// cstr += "\n";\r
70 } else if (argstr.charAt(1) == 'n') {\r
71 nstr += argstr.substring(2);\r
72// nstr += "\n";\r
73 }\r
74 i = j;\r
75 }\r
76\r
77 }\r
78 \r
79 public static int length = 0;\r
80 public static String pstr = new String("ACTIVE_PLATFORM = ");\r
81 public static String tstr = new String("TARGET = ");\r
82 public static String astr = new String("TARGET_ARCH = ");\r
83 public static String cstr = new String("TOOL_CHAIN_CONF = ");\r
84 public static String nstr = new String("TOOL_CHAIN_TAG = ");\r
85\r
86}\r