<commit_before>﻿// -----------------------------------------------------------------------------
//  <copyright file="ConfigReader.cs" company="<NAME>">
//      Copyright (c) <NAME>.  All rights reserved.
//  </copyright>
// -----------------------------------------------------------------------------

#pragma warning disable 642

namespace Lantea.Common.IO
{
	using System;
	using System.Collections.Generic;
	using System.IO;
	using System.Reflection;
	using System.Text;
	using Atlantis.Linq;
	using Extensibility;
	using Linq;

    // ReSharper disable InconsistentNaming

	public class Configuration : Block
	{
		private readonly Stack<Block> block_stack = new Stack<Block>();
		private readonly StringBuilder buffer     = new StringBuilder();
		private String currentFileName;
		private String itemname;
		private Int32 currentLine;
		
		private bool in_word;
		private bool in_quote;
		private bool in_comment;

		private readonly Dictionary<String, Block> modules = new Dictionary<String, Block>(StringComparer.OrdinalIgnoreCase);
		private String root;

		public Configuration() : base("")
		{
			buffer      = new StringBuilder();
			block_stack = new Stack<Block>();
		}

		#region Events

		public event EventHandler<ConfigurationLoadEventArgs> ConfigurationLoadEvent;

		#endregion
		
		#region Methods

		public Block GetModule(IModule module)
		{
			return module == null ? null : GetModule(module.Name);
		}

		public Block GetModule(String name)
		{
			Block block;

			return modules.TryGetValue(name, out block) ? block : null;
		}

		/// <summary>
		/// Loads the specified config file into memory according to the Anope configuration standard.
		/// </summary>
		/// <param name="path">The path of the file to be loaded.</param>
		/// <exception cref="T:System.IO.FileNotFoundException" />
		/// <exception cref="T:Lantea.Common.IO.MalformedConfigException" />
		public void Load(String path)
		{
		    if (path == null) throw new ArgumentNullException("path");

		    try
			{
				currentFileName = Path.GetFileName(path);
                root            = Path.GetDirectoryName(path.GetAbsolutePath());

				Load(new FileStream(path, FileMode.Open, FileAccess.Read));

				for (Int32 i = 0; i < CountBlock("include"); ++i)
				{
					Block include = GetBlock("include", i);
					String file = include.Get<String>("name");

                    ValidateNotEmpty("include", "name", file);

                    file = Path.GetFullPath(Path.Combine(root, "config", file));

                    ValidateFilePath("include", "name", file);

					Load(new FileStream(file, FileMode.Open, FileAccess.Read));
				}
			}
			catch (FileNotFoundException e)
			{
				ConfigurationLoadEvent.Raise(this, new ConfigurationLoadEventArgs(false, e));
			}
#if !DEBUG
			catch (MalformedConfigException e)
			{
				ConfigurationLoadEvent.Raise(this, new ConfigurationLoadEventArgs(false, e));
			}
#endif
			finally
			{
				for (Int32 i = 0; i < CountBlock("module"); ++i)
				{
					Block module = GetBlock("module", i);
					if (module != null)
					{
						String name = module.Get<String>("name");

						ValidateNotEmpty("module", "name", name);<commit_msg>Fix another bug relating to the bug I just fixed (caused this one) where I was making the path append a "config" too.<commit_after>﻿// -----------------------------------------------------------------------------
//  <copyright file="ConfigReader.cs" company="Zack Loveless">
//      Copyright (c) <NAME>.  All rights reserved.
//  </copyright>
// -----------------------------------------------------------------------------

#pragma warning disable 642

namespace Lantea.Common.IO
{
	using System;
	using System.Collections.Generic;
	using System.IO;
	using System.Reflection;
	using System.Text;
	using Atlantis.Linq;
	using Extensibility;
	using Linq;

    // ReSharper disable InconsistentNaming

	public class Configuration : Block
	{
		private readonly Stack<Block> block_stack = new Stack<Block>();
		private readonly StringBuilder buffer     = new StringBuilder();
		private String currentFileName;
		private String itemname;
		private Int32 currentLine;
		
		private bool in_word;
		private bool in_quote;
		private bool in_comment;

		private readonly Dictionary<String, Block> modules = new Dictionary<String, Block>(StringComparer.OrdinalIgnoreCase);
		private String root;

		public Configuration() : base("")
		{
			buffer      = new StringBuilder();
			block_stack = new Stack<Block>();
		}

		#region Events

		public event EventHandler<ConfigurationLoadEventArgs> ConfigurationLoadEvent;

		#endregion
		
		#region Methods

		public Block GetModule(IModule module)
		{
			return module == null ? null : GetModule(module.Name);
		}

		public Block GetModule(String name)
		{
			Block block;

			return modules.TryGetValue(name, out block) ? block : null;
		}

		/// <summary>
		/// Loads the specified config file into memory according to the Anope configuration standard.
		/// </summary>
		/// <param name="path">The path of the file to be loaded.</param>
		/// <exception cref="T:System.IO.FileNotFoundException" />
		/// <exception cref="T:Lantea.Common.IO.MalformedConfigException" />
		public void Load(String path)
		{
		    if (path == null) throw new ArgumentNullException("path");

		    try
			{
				currentFileName = Path.GetFileName(path);
                root            = Path.GetDirectoryName(path.GetAbsolutePath());

				Load(new FileStream(path, FileMode.Open, FileAccess.Read));

				for (Int32 i = 0; i < CountBlock("include"); ++i)
				{
					Block include = GetBlock("include", i);
					String file = include.Get<String>("name");

                    ValidateNotEmpty("include", "name", file);

                    file = Path.GetFullPath(Path.Combine(root, file));

                    ValidateFilePath("include", "name", file);

					Load(new FileStream(file, FileMode.Open, FileAccess.Read));
				}
			}
			catch (FileNotFoundException e)
			{
				ConfigurationLoadEvent.Raise(this, new ConfigurationLoadEventArgs(false, e));
			}
#if !DEBUG
			catch (MalformedConfigException e)
			{
				ConfigurationLoadEvent.Raise(this, new ConfigurationLoadEventArgs(false, e));
			}
#endif
			finally
			{
				for (Int32 i = 0; i < CountBlock("module"); ++i)
				{
					Block module = GetBlock("module", i);
					if (module != null)
					{
						String name = module.Get<String>("name");

						ValidateNotEmpty("module", "name", name);
{'fraction_non_alphanumeric': 0.1606837606837607, 'fraction_numerical': 0.003418803418803419, 'mean_word_length': 2.7031070195627156, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '659278', 'n_tokens_mistral': 2055, 'n_tokens_neox': 1742, 'n_words': 487}