Example #1
0
        private void ParseLine(string line)
        {
            line = line.Trim();
            line = RemoveComments(line);
            int pos = line.IndexOf('=');

            if (pos > 0)
            {
                var operation = "=";
                if (line[pos - 1] == '+' || line[pos - 1] == '-')
                {
                    operation = line[pos - 1] + "=";
                }

                var key   = line.Substring(0, pos - operation.Length + 1).Trim();
                var value = ExpandVariables(line.Substring(pos + 1).Trim());

                if (operation == "+=" && m_entries.ContainsKey(key))
                {
                    m_entries[key] += " " + value;
                }
                else if (operation == "-=")
                {
                    foreach (var removeValue in value.Split(new char[] { ' ', '\t' }))
                    {
                        RemoveValue(key, removeValue);
                    }
                }
                else
                {
                    m_entries[key] = value;
                }
            }
            else if (line.StartsWith("include"))
            {
                var start = line.IndexOf('(');
                var end   = line.LastIndexOf(')');
                if (start > 0 && start < end)
                {
                    var includeFile = line.Substring(start + 1, end - start - 1);
                    var temp        = Environment.CurrentDirectory;
                    Environment.CurrentDirectory = Path.GetDirectoryName(m_path);
                    if (File.Exists(includeFile))
                    {
                        var includeParser = new ConfigParser(Path.GetFullPath(includeFile));
                        foreach (var data in includeParser.m_entries)
                        {
                            if (m_entries.ContainsKey(data.Key))
                            {
                                m_entries[data.Key] += data.Value;
                            }
                            else
                            {
                                m_entries[data.Key] = data.Value;
                            }
                        }
                    }
                    Environment.CurrentDirectory = temp;
                }
            }
        }
Example #2
0
 protected void Init(string filename)
 {
     parser = new ConfigParser(filename);
 }