a0723b6528481081c1b4fe4575bf978382077f2d
[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')))){
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 length = pstr.length();
56
57 StringBuffer InputData = new StringBuffer();
58 for (int i = 0; i < args.length; i++) {
59 InputData.append(args[i]);
60 InputData.append(" ");
61 }
62
63 int i = 0;
64 while (i < InputData.length()) {
65 int j = InputData.indexOf("-", i + 1);
66 if (j == -1)
67 j = InputData.length();
68
69 String argstr = InputData.substring(i, j);
70
71 if (argstr.charAt(1) == 'p') {
72 pstr += argstr.substring(2);
73 // pstr += "\n";
74 } else if (argstr.charAt(1) == 't') {
75 tstr += argstr.substring(2);
76 // tstr += "\n";
77 } else if (argstr.charAt(1) == 'a') {
78 astr += argstr.substring(2);
79 // astr += "\n";
80 } else if (argstr.charAt(1) == 'c') {
81 cstr += argstr.substring(2);
82 // cstr += "\n";
83 } else if (argstr.charAt(1) == 'n') {
84 nstr += argstr.substring(2);
85 // nstr += "\n";
86 }
87 i = j;
88 }
89
90 }
91
92 public static int length = 0;
93 public static String pstr = new String("ACTIVE_PLATFORM = ");
94 public static String tstr = new String("TARGET = ");
95 public static String astr = new String("TARGET_ARCH = ");
96 public static String cstr = new String("TOOL_CHAIN_CONF = ");
97 public static String nstr = new String("TOOL_CHAIN_TAG = ");
98
99 }