To fix EDKT284.
[mirror_edk2.git] / Tools / Source / ContextTool / org / tianocore / context / ParseParameter.java
1 /** @file
2 File is ParseParameter class which is used to parse the validity of user's input args
3 and standardize them.
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 **/
14 package org.tianocore.context;
15
16 public class ParseParameter {
17
18
19 /**
20 * check the validity of user's input args
21 * @param args -- user's input
22 * @return true or false
23 **/
24 public static boolean checkParameter(String[] args) {
25
26 if(args.length == 0){
27 HelpInfo.outputUsageInfo();
28 return false;
29 } else {
30 if( args[0].charAt(0) != '-' ){
31 HelpInfo.outputUsageInfo();
32 return false;
33 }
34 for(int i=0; i<args.length; i++){
35 if( (args[i].compareToIgnoreCase("-h") == 0) ||
36 (args[i].startsWith("-") && ((args[i].charAt(1) != 'a') && (args[i].charAt(1) != 'c')
37 && (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't') && (args[i].charAt(1) != 'm')))){
38 HelpInfo.outputUsageInfo();
39 return false;
40 }
41 }
42 }
43
44 standardizeParameter(args);
45 return true;
46 }
47
48 /**
49 * standardize user's input args
50 * @param args -- user's input
51 * @return no return value
52 **/
53 private static void standardizeParameter(String[] args) {
54
55 //
56 // the parameters's length are same.
57 //
58 length = pstr.length();
59
60 StringBuffer InputData = new StringBuffer();
61 for (int i = 0; i < args.length; i++) {
62 InputData.append(args[i]);
63 InputData.append(" ");
64 }
65
66 int i = 0;
67 while (i < InputData.length()) {
68 int j = InputData.indexOf("-", i + 1);
69 if (j == -1)
70 j = InputData.length();
71
72 String argstr = InputData.substring(i, j);
73
74 if (argstr.charAt(1) == 'p') {
75 pstr += argstr.substring(2);
76 // pstr += "\n";
77 } else if (argstr.charAt(1) == 't') {
78 tstr += argstr.substring(2);
79 // tstr += "\n";
80 } else if (argstr.charAt(1) == 'a') {
81 astr += argstr.substring(2);
82 // astr += "\n";
83 } else if (argstr.charAt(1) == 'c') {
84 cstr += argstr.substring(2);
85 // cstr += "\n";
86 } else if (argstr.charAt(1) == 'n') {
87 nstr += argstr.substring(2);
88 // nstr += "\n";
89 } else if (argstr.charAt(1) == 'm') {
90 mstr += argstr.substring(2);
91 // mstr += "\n";
92 if (argstr.charAt(3) == '0'){
93 mestr += " Disable";
94 } else {
95 mestr += " Enable";
96 }
97 }
98 i = j;
99 }
100
101 }
102
103 public static int length = 0;
104 public static String pstr = new String("ACTIVE_PLATFORM = ");
105 public static String tstr = new String("TARGET = ");
106 public static String astr = new String("TARGET_ARCH = ");
107 public static String cstr = new String("TOOL_CHAIN_CONF = ");
108 public static String nstr = new String("TOOL_CHAIN_TAG = ");
109 public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");
110 public static String mestr = new String("MULTIPLE_THREAD = ");
111
112 }