diff options
author | Oliver Wolff <oliver.wolff@theqtcompany.com> | 2016-02-19 08:32:58 +0100 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@theqtcompany.com> | 2016-02-19 11:50:18 +0000 |
commit | 79c3ff01ac7040ab7817c0eb36941269b9e31cbd (patch) | |
tree | 2c92666d3f3fed058100523027f1dff7074574ac | |
parent | 2f1fa954dfbd58033eabf160f1e89785cbaf1bd4 (diff) |
Fixed qmake.conf parser for included configurations
Instead of adding the values that are read in included configurations
the operators have to be taken into account there as well. So use one
Parse function, that edits the configuration entries directly and can
be called for included configurations.
Task-number: QTVSADDINBUG-418
Change-Id: I7e8033c02de2170ad0211c7ea86c63bff4e623a2
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
-rw-r--r-- | Qt4VS2003/QtProjectLib/QMakeConf.cs | 131 |
1 files changed, 61 insertions, 70 deletions
diff --git a/Qt4VS2003/QtProjectLib/QMakeConf.cs b/Qt4VS2003/QtProjectLib/QMakeConf.cs index f3399f35..5c3931c4 100644 --- a/Qt4VS2003/QtProjectLib/QMakeConf.cs +++ b/Qt4VS2003/QtProjectLib/QMakeConf.cs @@ -35,7 +35,7 @@ namespace Digia.Qt5ProjectLib { public class QMakeConf { - protected Hashtable entries = new Hashtable(); + protected Hashtable mEntries = new Hashtable(); private FileInfo fileInfo = null; private string qmakespecFolder = ""; @@ -99,82 +99,73 @@ namespace Digia.Qt5ProjectLib protected void Init(string filename) { - fileInfo = new FileInfo(filename); - if (fileInfo.Exists) - { - StreamReader streamReader = new StreamReader(filename); - string line = streamReader.ReadLine(); - while (line != null) - { - ParseLine(line); - line = streamReader.ReadLine(); - } - streamReader.Close(); - } + ParseFile(filename, ref mEntries); } public string Get(string key) { - return (string)entries[key]; + return (string)mEntries[key]; } - private void ParseLine(string line) + private void ParseFile(string filename, ref Hashtable entries) { - line = line.Trim(); - int commentStartIndex = line.IndexOf('#'); - if (commentStartIndex >= 0) - line = line.Remove(commentStartIndex); - int pos = line.IndexOf('='); - if (pos > 0) + fileInfo = new FileInfo(filename); + if (fileInfo.Exists) { - string op = "="; - if (line[pos - 1] == '+' || line[pos - 1] == '-') - op = line[pos - 1] + "="; + StreamReader streamReader = new StreamReader(filename); + string line = streamReader.ReadLine(); + while (line != null) + { + line = line.Trim(); + int commentStartIndex = line.IndexOf('#'); + if (commentStartIndex >= 0) + line = line.Remove(commentStartIndex); + int pos = line.IndexOf('='); + if (pos > 0) + { + string op = "="; + if (line[pos - 1] == '+' || line[pos - 1] == '-') + op = line[pos - 1] + "="; - string lineKey; - string lineValue; - lineKey = line.Substring(0, pos - op.Length + 1).Trim(); - lineValue = ExpandVariables(line.Substring(pos + 1).Trim()); + string lineKey; + string lineValue; + lineKey = line.Substring(0, pos - op.Length + 1).Trim(); + lineValue = ExpandVariables(line.Substring(pos + 1).Trim(), entries); - if (op == "+=") - { - entries[lineKey] += " " + lineValue; - } - else if (op == "-=") - { - foreach (string remval in lineValue.Split(new char[] { ' ', '\t' })) - RemoveValue(lineKey, remval); - } - else - entries[lineKey] = lineValue; - } - else if (line.StartsWith("include")) - { - pos = line.IndexOf('('); - int posEnd = line.LastIndexOf(')'); - if (pos > 0 && pos < posEnd) - { - string filenameToInclude = line.Substring(pos + 1, posEnd - pos - 1); - string saveCurrentDir = Environment.CurrentDirectory; - Environment.CurrentDirectory = fileInfo.Directory.FullName; - FileInfo fileInfoToInclude = new FileInfo(filenameToInclude); - if (fileInfoToInclude.Exists) + if (op == "+=") + { + entries[lineKey] += " " + lineValue; + } + else if (op == "-=") + { + foreach (string remval in lineValue.Split(new char[] { ' ', '\t' })) + RemoveValue(lineKey, remval, entries); + } + else + entries[lineKey] = lineValue; + } + else if (line.StartsWith("include")) { - QMakeConf includeConf = new QMakeConf(fileInfoToInclude.FullName, InitType.InitQMakeConf); - foreach (string key in includeConf.entries.Keys) + pos = line.IndexOf('('); + int posEnd = line.LastIndexOf(')'); + if (pos > 0 && pos < posEnd) { - if (entries.ContainsKey(key)) - entries[key] += includeConf.entries[key].ToString(); - else - entries[key] = includeConf.entries[key].ToString(); + string filenameToInclude = line.Substring(pos + 1, posEnd - pos - 1); + string saveCurrentDir = Environment.CurrentDirectory; + Environment.CurrentDirectory = fileInfo.Directory.FullName; + FileInfo fileInfoToInclude = new FileInfo(filenameToInclude); + if (fileInfoToInclude.Exists) + ParseFile(fileInfoToInclude.FullName, ref entries); + Environment.CurrentDirectory = saveCurrentDir; } } - Environment.CurrentDirectory = saveCurrentDir; + line = streamReader.ReadLine(); } + streamReader.Close(); } } - private string ExpandVariables(string value) + private string ExpandVariables(string value, Hashtable entries) { int pos = value.IndexOf("$$"); while (pos != -1) @@ -208,20 +199,20 @@ namespace Digia.Qt5ProjectLib return value; } - private void RemoveValue(string key, string valueToRemove) + private void RemoveValue(string key, string valueToRemove, Hashtable entries) { int pos; - if (entries.Contains(key)) + if (!entries.Contains(key)) + return; + + string value = entries[key].ToString(); + do { - string value = entries[key].ToString(); - do - { - pos = value.IndexOf(valueToRemove); - if (pos >= 0) - value = value.Remove(pos, valueToRemove.Length); - } while (pos >= 0); - entries[key] = value; - } + pos = value.IndexOf(valueToRemove); + if (pos >= 0) + value = value.Remove(pos, valueToRemove.Length); + } while (pos >= 0); + entries[key] = value; } } } |