]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ContextTool/org/tianocore/context/ParseParameter.java
d74801e279507a86f7a5296e664968e8bb8f51c1
[mirror_edk2.git] / Tools / Source / ContextTool / org / tianocore / context / ParseParameter.java
1 package org.tianocore.context;
2
3 public class ParseParameter {
4
5
6 /**
7 * check the validity of user's input args
8 * @param args -- user's input
9 * @return true or false
10 **/
11 public static boolean checkParameter(String[] args) {
12
13 if(args.length == 0){
14 HelpInfo.outputUsageInfo();
15 return false;
16 } else {
17 if( args[0].charAt(0) != '-' ){
18 HelpInfo.outputUsageInfo();
19 return false;
20 }
21 for(int i=0; i<args.length; i++){
22 if( (args[i].compareToIgnoreCase("-h") == 0) ||
23 (args[i].startsWith("-") && ((args[i].charAt(1) != 'a') && (args[i].charAt(1) != 'c')
24 && (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't')))){
25 HelpInfo.outputUsageInfo();
26 return false;
27 }
28 }
29 }
30
31 standardizeParameter(args);
32 return true;
33 }
34
35 /**
36 * standardize user's input args
37 * @param args -- user's input
38 * @return no return value
39 **/
40 private static void standardizeParameter(String[] args) {
41
42 length = pstr.length();
43
44 StringBuffer InputData = new StringBuffer();
45 for (int i = 0; i < args.length; i++) {
46 InputData.append(args[i]);
47 InputData.append(" ");
48 }
49
50 int i = 0;
51 while (i < InputData.length()) {
52 int j = InputData.indexOf("-", i + 1);
53 if (j == -1)
54 j = InputData.length();
55
56 String argstr = InputData.substring(i, j);
57
58 if (argstr.charAt(1) == 'p') {
59 pstr += argstr.substring(2);
60 // pstr += "\n";
61 } else if (argstr.charAt(1) == 't') {
62 tstr += argstr.substring(2);
63 // tstr += "\n";
64 } else if (argstr.charAt(1) == 'a') {
65 astr += argstr.substring(2);
66 // astr += "\n";
67 } else if (argstr.charAt(1) == 'c') {
68 cstr += argstr.substring(2);
69 // cstr += "\n";
70 } else if (argstr.charAt(1) == 'n') {
71 nstr += argstr.substring(2);
72 // nstr += "\n";
73 }
74 i = j;
75 }
76
77 }
78
79 public static int length = 0;
80 public static String pstr = new String("ACTIVE_PLATFORM = ");
81 public static String tstr = new String("TARGET = ");
82 public static String astr = new String("TARGET_ARCH = ");
83 public static String cstr = new String("TOOL_CHAIN_CONF = ");
84 public static String nstr = new String("TOOL_CHAIN_TAG = ");
85
86 }