]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/ContextTool/org/tianocore/context/ParseParameter.java
add ContextTool to workspace/Tools
[mirror_edk2.git] / Tools / Source / ContextTool / org / tianocore / context / ParseParameter.java
diff --git a/Tools/Source/ContextTool/org/tianocore/context/ParseParameter.java b/Tools/Source/ContextTool/org/tianocore/context/ParseParameter.java
new file mode 100644 (file)
index 0000000..d74801e
--- /dev/null
@@ -0,0 +1,86 @@
+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')))){\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
+        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
+            }\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
+\r
+}\r