]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / ContextTool / org / tianocore / context / ParseParameter.java
diff --git a/Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java b/Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java
new file mode 100644 (file)
index 0000000..2285f21
--- /dev/null
@@ -0,0 +1,112 @@
+/** @file\r
+  File is ParseParameter class which is used to parse the validity of user's input args\r
+  and standardize them. \r
\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+package org.tianocore.context;\r
+\r
+public class ParseParameter {\r
+\r
+    \r
+    /** \r
+     * check the validity of user's input args\r
+     * @param args -- user's input\r
+     * @return true or false\r
+     **/\r
+    public static boolean checkParameter(String[] args) {\r
+        \r
+        if(args.length == 0){\r
+            HelpInfo.outputUsageInfo();\r
+            return false;\r
+        } else {\r
+            if( args[0].charAt(0) != '-' ){\r
+                HelpInfo.outputUsageInfo();\r
+                return false;\r
+            }\r
+            for(int i=0; i<args.length; i++){\r
+                if( (args[i].compareToIgnoreCase("-h") == 0) || \r
+                    (args[i].startsWith("-") && ((args[i].charAt(1) != 'a') && (args[i].charAt(1) != 'c') \r
+                    && (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't') && (args[i].charAt(1) != 'm')))){\r
+                    HelpInfo.outputUsageInfo();\r
+                    return false;\r
+                }\r
+            }\r
+        }\r
+        \r
+        standardizeParameter(args);\r
+        return true; \r
+    }\r
+    \r
+    /** \r
+     * standardize user's input args\r
+     * @param args -- user's input\r
+     * @return no return value\r
+     **/\r
+    private static void standardizeParameter(String[] args) {\r
+        \r
+        //\r
+        // the parameters's length are same.\r
+        //\r
+        length  = pstr.length();\r
+        \r
+        StringBuffer InputData = new StringBuffer();\r
+        for (int i = 0; i < args.length; i++) {\r
+            InputData.append(args[i]);\r
+            InputData.append(" ");\r
+        }\r
+\r
+        int i = 0;\r
+        while (i < InputData.length()) {\r
+            int j = InputData.indexOf("-", i + 1);\r
+            if (j == -1)\r
+                j = InputData.length();\r
+\r
+            String argstr = InputData.substring(i, j);\r
+\r
+            if (argstr.charAt(1) == 'p') {\r
+                pstr += argstr.substring(2);\r
+ //               pstr += "\n";\r
+            } else if (argstr.charAt(1) == 't') {\r
+                tstr += argstr.substring(2);\r
+ //               tstr += "\n";\r
+            } else if (argstr.charAt(1) == 'a') {\r
+                astr += argstr.substring(2);\r
+//                astr += "\n";\r
+            } else if (argstr.charAt(1) == 'c') {\r
+                cstr += argstr.substring(2);\r
+//                cstr += "\n";\r
+            } else if (argstr.charAt(1) == 'n') {\r
+                nstr += argstr.substring(2);\r
+//                nstr += "\n";\r
+            } else if (argstr.charAt(1) == 'm') {\r
+                mstr += argstr.substring(2);\r
+//              mstr += "\n";\r
+                if (argstr.charAt(3) == '0'){\r
+                    mestr += " Disable";\r
+                } else {\r
+                    mestr += " Enable";\r
+                }\r
+          }\r
+            i = j;\r
+        }\r
+\r
+    }\r
+     \r
+    public static int length  = 0;\r
+    public static String pstr = new String("ACTIVE_PLATFORM                     = ");\r
+    public static String tstr = new String("TARGET                              = ");\r
+    public static String astr = new String("TARGET_ARCH                         = ");\r
+    public static String cstr = new String("TOOL_CHAIN_CONF                     = ");\r
+    public static String nstr = new String("TOOL_CHAIN_TAG                      = ");\r
+    public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER        = ");\r
+    public static String mestr = new String("MULTIPLE_THREAD                     = ");\r
+\r
+}\r