]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/ContextTool/org/tianocore/context/ParseParameter.java
1.add code to support friendly output message.
[mirror_edk2.git] / Tools / Java / Source / ContextTool / org / tianocore / context / ParseParameter.java
index 8b818059d5a4dfaea33f173540ac5af15f4d367f..d58d28b01087103bf5961c638df294766dd91aef 100644 (file)
@@ -35,7 +35,7 @@ public class ParseParameter {
                 return false;\r
             }\r
             if( args[0].charAt(0) != '-' ){\r
-                System.out.printf("%s\n", "Error arguments! Please type \"ContextTool -h\" for helpinfo.");\r
+                System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo.");\r
                 return false;\r
             }\r
             for(int i=0; i<args.length; i++){\r
@@ -43,7 +43,7 @@ public class ParseParameter {
                     ((args[i].compareTo("-a") != 0) && (args[i].compareTo("-c") != 0) && \r
                     (args[i].compareTo("-n") != 0) && (args[i].compareTo("-p") != 0) && \r
                     (args[i].compareTo("-t") != 0) && (args[i].compareTo("-m") != 0)))){\r
-                    System.out.printf("%s\n", "Error arguments! Please type \"ContextTool -h\" for helpinfo.");                                                                                                                                                            \r
+                    System.out.printf("%s\n", "Error Parameters! Please type \"ContextTool -h\" for helpinfo.");                                                                                                                                                            \r
                     return false;\r
                 }\r
             }\r
@@ -83,76 +83,98 @@ public class ParseParameter {
                     return 1;\r
                 }\r
                 //\r
-                //argstr is "-p ?", display possible setting\r
+                //argstr is "-p ? ", display possible setting\r
                 //\r
                 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
-                    System.out.printf( "%s\n", "assign the platform FPD file's relative path to WORKSPACE" );\r
+                    String workspacePath = System.getenv("WORKSPACE");\r
+                    System.out.printf( "%s\n", "Assign a platform FPD file with relative path to " + workspacePath);\r
                     return 2;\r
                 }\r
                 //\r
-                //argstr is "-p 0", clean current setting\r
+                //argstr is "-p 0 ", clean current setting\r
                 //\r
                 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
                     curpstr = pstr;\r
+                    npflag = true;\r
                     continue;\r
                 }\r
-                curpstr = mergeSetting(curpstr, argstr);\r
+                String[] S = argstr.split(" ");\r
+                if(S.length > 2){\r
+                    System.out.printf( "%s\n", "There should be none or only one ACTIVE_PLATFORM. Please check the number of value which follow \"-p\".");\r
+                    return 3;\r
+                }\r
+                curpstr = pstr.concat(argstr.substring(2));\r
+                npflag = true;\r
             } else if (argstr.charAt(1) == 't') {\r
                 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
                     System.out.printf("%s\n", curtstr);\r
                     return 1;\r
                 }\r
                 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
-                    System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE" );\r
+                    System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE." );\r
                     return 2;\r
                 }\r
                 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
                     curtstr = tstr;\r
+                    ntflag = true;\r
                     continue;\r
                 }\r
-                curtstr = mergeSetting(curtstr, argstr);\r
+                curtstr = tstr.concat(argstr.substring(2));\r
+                ntflag = true;\r
             } else if (argstr.charAt(1) == 'a') {\r
                 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
                     System.out.printf("%s\n", curastr);\r
                     return 1;\r
                 }\r
                 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
-                    System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM" );\r
+                    System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM." );\r
                     return 2;\r
                 }\r
                 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
                     curastr = astr;\r
+                    naflag = true;\r
                     continue;\r
                 }\r
-                curastr = mergeSetting(curastr, argstr);\r
+                curastr = astr.concat(argstr.substring(2));\r
+                naflag = true;\r
             } else if (argstr.charAt(1) == 'c') {\r
                 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
                     System.out.printf("%s\n", curcstr);\r
                     return 1;\r
                 }\r
                 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
-                    System.out.printf( "%s\n", "Assign a txt file with the relative path to WORKSPACE, which specify the tools to use for the build and must be located in the path: WORKSPACE/Tools/Conf/" );\r
+                    String workspacePath = System.getenv("WORKSPACE");\r
+                    System.out.printf( "%s\n", "Assign a txt file with relative path to " + workspacePath + ", which specify the tools to use for the build and must be located in the path:" + workspacePath + "\\Tools\\Conf" );\r
                     return 2;\r
                 }\r
                 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
                     curcstr = cstr;\r
+                    ncflag = true;\r
                     continue;\r
                 }\r
-                curcstr = mergeSetting(curcstr, argstr);\r
+                String[] S = argstr.split(" ");\r
+                if(S.length > 2){\r
+                    System.out.printf( "%s\n", "There should be one and only one TOOL_CHAIN_CONF. Please check the number of value which follow \"-c\".");\r
+                    return 3;\r
+                }\r
+                curcstr = cstr.concat(argstr.substring(2));\r
+                ncflag = true;\r
             } else if (argstr.charAt(1) == 'n') {\r
                 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
                     System.out.printf("%s\n", curnstr);\r
                     return 1;\r
                 }\r
                 if(argstr.length() < 6 && argstr.charAt(3) == '?'){\r
-                    System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT" );\r
+                    System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT." );\r
                     return 2;\r
                 }\r
                 if(argstr.length() < 6 && argstr.charAt(3) == '0'){\r
                     curnstr = nstr;\r
+                    nnflag = true;\r
                     continue;\r
                 }\r
-                curnstr = mergeSetting(curnstr, argstr);\r
+                curnstr = nstr.concat(argstr.substring(2));\r
+                nnflag = true;\r
             } else if (argstr.charAt(1) == 'm') {\r
                 if(argstr.length() < 4 && argstr.charAt(2) == ' '){\r
                     System.out.printf("%s\n", curmstr);\r
@@ -162,52 +184,84 @@ public class ParseParameter {
                     System.out.printf( "%s\n", "The number of concurrent threads. Default is 2. Recommend to set this value to one more than the number of your compurter cores or CPUs." );\r
                     return 2;\r
                 }\r
+                String[] S = argstr.split(" ");\r
+                if(S.length > 2){\r
+                    System.out.printf( "%s\n", "There should be one and only one integer, which doesn't include space.");\r
+                    return 3;\r
+                }\r
                 mstr += argstr.substring(2);\r
                 curmstr = mstr;\r
+                nmflag = true;\r
                 if (argstr.charAt(3) == '0'){\r
                     mestr += " Disable";\r
                 } else {\r
                     mestr += " Enable";\r
                 }\r
                 curmestr = mestr;\r
+                nmeflag = true;\r
             }\r
             \r
         }\r
         return 0;\r
     }\r
+\r
     \r
-    \r
-    public static String mergeSetting( String S1, String S2){\r
+    public static boolean outputCurSetting(){\r
         \r
-        String[] S = S2.split(" ");\r
-        if(S1 == null){\r
-            S1 = tstr.concat(S2.substring(2));\r
-        }else{\r
-            for(int i = 1; i < S.length; i++){\r
-                if( S1.contains(S[i]) == false ){\r
-                    S1 = S1.concat(S[i]).concat(" ");\r
-                }\r
-            }\r
+        System.out.printf( "%s\n", "The current setting is:" );\r
+        \r
+        if(curpstr != null){\r
+            System.out.printf( "%s\n", curpstr );\r
+        }\r
+        else{\r
+            System.out.printf( "%s\n", pstr );\r
         }\r
         \r
-        return S1;\r
-    }\r
-    \r
-    public static boolean outputCurSetting(){\r
+        if(curtstr != null){\r
+            System.out.printf( "%s\n", curtstr );\r
+        }\r
+        else{\r
+            System.out.printf( "%s\n", tstr );\r
+        }\r
         \r
-        System.out.printf( "%s\n", "The current setting is:" );\r
-        System.out.printf( "%s\n", curpstr );\r
-        System.out.printf( "%s\n", curtstr );\r
-        System.out.printf( "%s\n", curastr );\r
-        System.out.printf( "%s\n", curcstr );\r
-        System.out.printf( "%s\n", curnstr );\r
-        System.out.printf( "%s\n", curmstr );\r
-        System.out.printf( "%s\n", curmestr );\r
+        if(curastr != null){\r
+            System.out.printf( "%s\n", curastr );\r
+        }\r
+        else{\r
+            System.out.printf( "%s\n", astr );\r
+        }\r
+        \r
+        if(curcstr != null){\r
+            System.out.printf( "%s\n", curcstr );\r
+        }\r
+        else{\r
+            System.out.printf( "%s\n", cstr );\r
+        }\r
+        \r
+        if(curnstr != null){\r
+            System.out.printf( "%s\n", curnstr );\r
+        }\r
+        else{\r
+            System.out.printf( "%s\n", nstr );\r
+        }\r
+        \r
+        if(curmstr != null){\r
+            System.out.printf( "%s\n", curmstr );\r
+        }\r
+        else{\r
+            System.out.printf( "%s\n", mstr );\r
+        }\r
+        \r
+        if(curmstr != null){\r
+            System.out.printf( "%s\n", curmestr );\r
+        }\r
+        else{\r
+            System.out.printf( "%s\n", mestr );\r
+        }\r
         \r
         return true;\r
     }\r
-     \r
-    public static int length  = 0;\r
+    \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
@@ -224,12 +278,12 @@ public class ParseParameter {
     public static String curmstr = null;\r
     public static String curmestr = null;\r
     \r
-    public static int plength = 0;\r
-    public static int tlength = 0;\r
-    public static int alength = 0;\r
-    public static int clength = 0;\r
-    public static int nlength = 0;\r
-    public static int mlength = 0;\r
-    public static int melength = 0;\r
+    public static boolean npflag = false;\r
+    public static boolean ntflag = false;\r
+    public static boolean naflag = false;\r
+    public static boolean ncflag = false;\r
+    public static boolean nnflag = false;\r
+    public static boolean nmflag = false;\r
+    public static boolean nmeflag = false;\r
 \r
 }\r