X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Ftoolchain%2FConfigReader.java;h=b6f58ce5f2575421d141bbdee703876a905b92cc;hp=6e26adee0136c1d6b40998259d76998223c8c821;hb=d2059d0594816ba3a159554b2e720bc9a3985f4a;hpb=64ec22c0f1e8f4aca45b9391661510179ff362e8 diff --git a/Tools/Source/GenBuild/org/tianocore/build/toolchain/ConfigReader.java b/Tools/Source/GenBuild/org/tianocore/build/toolchain/ConfigReader.java index 6e26adee01..b6f58ce5f2 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/toolchain/ConfigReader.java +++ b/Tools/Source/GenBuild/org/tianocore/build/toolchain/ConfigReader.java @@ -1,8 +1,8 @@ /** @file ConfigReader class. - - ConfigReader is used to read tool chain config file with flat format. - + + ConfigReader is used to read tool chain config file with flat format. + Copyright (c) 2006, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -23,65 +23,65 @@ import java.util.ArrayList; import java.util.List; /** - + ConfigReader is used to read tool chain config file with flat format. Comments is line starting with character '#'. - + @since GenBuild 1.0 **/ public class ConfigReader { - private static String confPath = "."; - - - /** - Public construct method. - **/ - public ConfigReader () { - } - /** - Default filepath is ".". + Parse specified tool chain definition file. + + @param filename The config file name with full path - @param filename the config file name like "target.txt" - @return the variables defined in file + @return String[][] The definition array **/ public static synchronized String[][] parse(String filename) throws EdkException { - return parse(confPath, filename); + return parse(new File(filename)); } /** - Get all variables defined in config file. the config file format is flat - with "A=B". If line started with '#' looks as comments. - - @param confPath the path of config file - @param filename the file name of the config file - @return the variables defined in the config file - @throws BuildException - Config file's format is not valid + Get all definitions in config file. the config file format is flat + with "A=B". If line started with '#' looks as comments. + + @param configFile The config file + + @return String[][] The variables defined in the config file + + @throws EdkException + Config file's format is not valid **/ - public static synchronized String[][] parse(String confPath, String filename) throws EdkException { - //Map map = new TreeMap(comparator); + public static synchronized String[][] parse(File configFile) throws EdkException { List keyList = new ArrayList(256); List valueList = new ArrayList(256); + int lines = 0; try { - File file = new File(confPath + File.separatorChar + filename); - FileReader reader = new FileReader(file); + FileReader reader = new FileReader(configFile); BufferedReader in = new BufferedReader(reader); String str; while ((str = in.readLine()) != null) { + ++lines; str = str.trim(); // - // if str is empty line, comments (start with '#'), - // without '=', or start with '=' + // skip empty line, comment (start with '#') // - int index; - if (str.length() == 0 || str.startsWith("#") || - (index = str.indexOf('=')) <= 0) { + if (str.length() == 0 || str.startsWith("#")) { continue; } + + // + // stop if the definition line is not in "name=value" form + // + int index; + if ((index = str.indexOf('=')) <= 0) { + throw new EdkException("ERROR Processing file [" + configFile.getAbsolutePath() + + "] (line " + lines + ").\n"); + } + // // look as line "A = B" // @@ -89,7 +89,8 @@ public class ConfigReader { valueList.add(str.substring(index + 1).trim()); } } catch (Exception e) { - throw new EdkException("ERROR Processing file [" + filename + "].\n" + e.getMessage()); + throw new EdkException("ERROR Processing file [" + configFile.getAbsolutePath() + + "] (line " + lines + ").\n" + e.getMessage()); } String[][] definitions = new String[2][keyList.size()]; @@ -98,39 +99,6 @@ public class ConfigReader { return definitions; } - - public static synchronized ToolChainMap parseToolChainConfig(File ConfigFile) throws EdkException { - ToolChainMap map = new ToolChainMap(); - - try { - FileReader reader = new FileReader(ConfigFile); - BufferedReader in = new BufferedReader(reader); - String str; - - while ((str = in.readLine()) != null) { - str = str.trim(); - // - // if str is empty line, comments (start with '#'), - // without '=', or start with '=' - // - int index; - if (str.length() == 0 || str.startsWith("#") || - (index = str.indexOf('=')) <= 0) { - continue; - } - // - // look as line "A = B" - // - String key = str.substring(0, index).trim().toUpperCase(); - String value = str.substring(index + 1).trim(); - map.put(key, value); - } - } catch (Exception e) { - throw new EdkException("ERROR Processing file [" + ConfigFile.getAbsolutePath() + "].\n" + e.getMessage()); - } - - return map; - } }