]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/toolchain/ConfigReader.java
f48735966e80c609ad8bf848cf6c4b5636ff5fcc
4 ConfigReader is used to read tool chain config file with flat format.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 package org
.tianocore
.build
.toolchain
;
17 import java
.io
.BufferedReader
;
19 import java
.io
.FileReader
;
20 import java
.util
.HashMap
;
21 import java
.util
.Iterator
;
24 import java
.util
.Vector
;
26 import org
.apache
.tools
.ant
.BuildException
;
30 ConfigReader is used to read tool chain config file with flat format. Comments
31 is line starting with character '#'.
35 public class ConfigReader
{
37 private static String confPath
= ".";
40 Public construct method.
42 public ConfigReader () {
46 Default filepath is ".".
48 @param filename the config file name like "target.txt"
49 @return the variables defined in file
51 public static synchronized String
[][] parse(String filename
) {
52 return parse(confPath
, filename
);
56 Get all variables defined in config file. the config file format is flat
57 with "A=B". If line started with '#' looks as comments.
59 @param confPath the path of config file
60 @param filename the file name of the config file
61 @return the variables defined in the config file
62 @throws BuildException
63 Config file's format is not valid
65 public static synchronized String
[][] parse(String confPath
, String filename
) throws BuildException
{
67 Map
<String
, String
> map
= new HashMap
<String
, String
>(20);
68 File file
= new File(confPath
+ File
.separatorChar
+ filename
);
69 FileReader reader
= new FileReader(file
);
70 BufferedReader in
= new BufferedReader(reader
);
72 while ((str
= in
.readLine()) != null) {
75 // if str is empty line or comments (start with '#')
77 if (str
.equalsIgnoreCase("") || str
.startsWith("#")) {
81 // if str without '=' or start with '='
83 if (str
.indexOf('=') <= 0) {
87 // look as line "A = B"
89 int index
= str
.indexOf('=');
90 String key
= str
.substring(0, index
).trim();
91 String value
= str
.substring(index
+ 1).trim();
93 // if key is existed, then update
95 if (map
.containsKey(key
)) {
100 Set keyset
= map
.keySet();
101 Iterator iter
= keyset
.iterator();
102 String
[][] result
= new String
[map
.size()][2];
104 while (iter
.hasNext()) {
105 String key
= (String
) iter
.next();
107 result
[i
++][1] = (String
) map
.get(key
);
110 } catch (Exception e
) {
111 throw new BuildException("Processor file [" + filename
+ "] error. \n" + e
.getMessage());
116 Parse global flags table. The format is like such(global flag name, value,
117 vendor_arch_cmd, [add flags], [sub flags]):
121 EFI_DEBUG YES MSFT_IA32_ASM ADD.["/Zi", "/DEBUG"]
122 EFI_DEBUG YES MSFT_IA32_CC ADD.["/Zi", "/Gm", "/D EFI_DEBUG"] SUB.["/nologo", "/WX"]
123 EFI_DEBUG YES MSFT_IA32_LINK ADD.["/DEBUG"]
124 EFI_DEBUG YES MSFT_NT32_CC ADD.["/DEBUG"]
127 @param confPath the file path of config file
128 @param filename the file name of config file
129 @return the value list
130 @throws BuildException
131 Config file is not valid
133 public static synchronized String
[][] parseTable(String confPath
,
134 String filename
) throws BuildException
{
136 Vector
<String
[]> vector
= new Vector
<String
[]>(20);
137 File file
= new File(confPath
+ File
.separatorChar
+ filename
);
138 FileReader reader
= new FileReader(file
);
139 BufferedReader in
= new BufferedReader(reader
);
141 while ((str
= in
.readLine()) != null) {
144 // if str is empty line or comments (start with '#')
146 if (str
.equalsIgnoreCase("") || str
.startsWith("#")) {
149 String
[] item
= new String
[5];
150 for(int i
=0; i
< item
.length
; i
++){
154 // EFI_DEBUG YES MSFT_IA32_ASM ADD.["/Zi", "/DEBUG"]
157 int index
= str
.indexOf(" ");
158 item
[0] = str
.substring(0, index
);
159 str
= str
.substring(index
+ 1).trim();
163 index
= str
.indexOf(" ");
164 item
[1] = str
.substring(0, index
);
165 str
= str
.substring(index
+ 1).trim();
167 // Vendor_Arch_Commandtype: MSFT_IA32_ASM
169 index
= str
.indexOf(" ");
170 item
[2] = str
.substring(0, index
);
171 str
= str
.substring(index
+ 1).trim();
175 if (str
.startsWith("ADD.")) {
176 index
= str
.indexOf("]");
178 item
[3] = str
.substring(5, index
);
179 str
= str
.substring(index
+ 1).trim();
182 else if(str
.startsWith("SUB.")){
183 index
= str
.indexOf("]");
185 item
[4] = str
.substring(5, index
);
186 str
= str
.substring(index
+ 1).trim();
190 throw new BuildException("File [" + filename
+ "] never conform to Global Flags Table format.");
193 if (str
.startsWith("ADD.")) {
194 index
= str
.indexOf("]");
196 item
[3] = str
.substring(5, index
);
197 str
= str
.substring(index
+ 1).trim();
200 else if(str
.startsWith("SUB.")){
201 index
= str
.indexOf("]");
203 item
[4] = str
.substring(5, index
);
204 str
= str
.substring(index
+ 1).trim();
207 vector
.addElement(item
);
209 String
[][] result
= new String
[vector
.size()][5];
210 for(int i
=0; i
< vector
.size(); i
++){
211 result
[i
] = (String
[])vector
.get(i
);
214 } catch (Exception e
) {
215 throw new BuildException("Processor file [" + filename
+ "] error. \n" + e
.getMessage());