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 |
27 | HelpInfo.outputUsageInfo();\r |
28 | return false;\r |
29 | } else {\r |
30 | if( args[0].charAt(0) != '-' ){\r |
31 | HelpInfo.outputUsageInfo();\r |
32 | return false;\r |
33 | }\r |
34 | for(int i=0; i<args.length; i++){\r |
35 | if( (args[i].compareToIgnoreCase("-h") == 0) || \r |
36 | (args[i].startsWith("-") && ((args[i].charAt(1) != 'a') && (args[i].charAt(1) != 'c') \r |
2c71f6e5 |
37 | && (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't') && (args[i].charAt(1) != 'm')))){\r |
c74c7a43 |
38 | HelpInfo.outputUsageInfo();\r |
39 | return false;\r |
40 | }\r |
41 | }\r |
42 | }\r |
43 | \r |
44 | standardizeParameter(args);\r |
45 | return true; \r |
46 | }\r |
47 | \r |
48 | /** \r |
49 | * standardize user's input args\r |
50 | * @param args -- user's input\r |
51 | * @return no return value\r |
52 | **/\r |
53 | private static void standardizeParameter(String[] args) {\r |
54 | \r |
2c71f6e5 |
55 | //\r |
56 | // the parameters's length are same.\r |
57 | //\r |
c74c7a43 |
58 | length = pstr.length();\r |
59 | \r |
60 | StringBuffer InputData = new StringBuffer();\r |
61 | for (int i = 0; i < args.length; i++) {\r |
62 | InputData.append(args[i]);\r |
63 | InputData.append(" ");\r |
64 | }\r |
65 | \r |
66 | int i = 0;\r |
67 | while (i < InputData.length()) {\r |
68 | int j = InputData.indexOf("-", i + 1);\r |
69 | if (j == -1)\r |
70 | j = InputData.length();\r |
71 | \r |
72 | String argstr = InputData.substring(i, j);\r |
73 | \r |
74 | if (argstr.charAt(1) == 'p') {\r |
75 | pstr += argstr.substring(2);\r |
76 | // pstr += "\n";\r |
77 | } else if (argstr.charAt(1) == 't') {\r |
78 | tstr += argstr.substring(2);\r |
79 | // tstr += "\n";\r |
80 | } else if (argstr.charAt(1) == 'a') {\r |
81 | astr += argstr.substring(2);\r |
82 | // astr += "\n";\r |
83 | } else if (argstr.charAt(1) == 'c') {\r |
84 | cstr += argstr.substring(2);\r |
85 | // cstr += "\n";\r |
86 | } else if (argstr.charAt(1) == 'n') {\r |
87 | nstr += argstr.substring(2);\r |
88 | // nstr += "\n";\r |
2c71f6e5 |
89 | } else if (argstr.charAt(1) == 'm') {\r |
90 | mstr += argstr.substring(2);\r |
91 | // mstr += "\n";\r |
92 | if (argstr.charAt(3) == '0'){\r |
93 | mestr += " Disable";\r |
94 | } else {\r |
95 | mestr += " Enable";\r |
96 | }\r |
97 | }\r |
c74c7a43 |
98 | i = j;\r |
99 | }\r |
100 | \r |
101 | }\r |
102 | \r |
103 | public static int length = 0;\r |
2c71f6e5 |
104 | public static String pstr = new String("ACTIVE_PLATFORM = ");\r |
105 | public static String tstr = new String("TARGET = ");\r |
106 | public static String astr = new String("TARGET_ARCH = ");\r |
107 | public static String cstr = new String("TOOL_CHAIN_CONF = ");\r |
108 | public static String nstr = new String("TOOL_CHAIN_TAG = ");\r |
109 | public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");\r |
110 | public static String mestr = new String("MULTIPLE_THREAD = ");\r |
c74c7a43 |
111 | \r |
112 | }\r |