Adding the *NIX equivalent to fw.bat
[mirror_edk2.git] / Tools / Source / ContextTool / org / tianocore / context / ParseParameter.java
CommitLineData
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
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
c74c7a43 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 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
37 && (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't')))){\r
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
55 length = pstr.length();\r
56 \r
57 StringBuffer InputData = new StringBuffer();\r
58 for (int i = 0; i < args.length; i++) {\r
59 InputData.append(args[i]);\r
60 InputData.append(" ");\r
61 }\r
62\r
63 int i = 0;\r
64 while (i < InputData.length()) {\r
65 int j = InputData.indexOf("-", i + 1);\r
66 if (j == -1)\r
67 j = InputData.length();\r
68\r
69 String argstr = InputData.substring(i, j);\r
70\r
71 if (argstr.charAt(1) == 'p') {\r
72 pstr += argstr.substring(2);\r
73 // pstr += "\n";\r
74 } else if (argstr.charAt(1) == 't') {\r
75 tstr += argstr.substring(2);\r
76 // tstr += "\n";\r
77 } else if (argstr.charAt(1) == 'a') {\r
78 astr += argstr.substring(2);\r
79// astr += "\n";\r
80 } else if (argstr.charAt(1) == 'c') {\r
81 cstr += argstr.substring(2);\r
82// cstr += "\n";\r
83 } else if (argstr.charAt(1) == 'n') {\r
84 nstr += argstr.substring(2);\r
85// nstr += "\n";\r
86 }\r
87 i = j;\r
88 }\r
89\r
90 }\r
91 \r
92 public static int length = 0;\r
93 public static String pstr = new String("ACTIVE_PLATFORM = ");\r
94 public static String tstr = new String("TARGET = ");\r
95 public static String astr = new String("TARGET_ARCH = ");\r
96 public static String cstr = new String("TOOL_CHAIN_CONF = ");\r
97 public static String nstr = new String("TOOL_CHAIN_TAG = ");\r
98\r
99}\r