<commit_before>
// Copyright (C) 2009-2015 <NAME>
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
// USA

// Macro utility for logging platform-relared function calls
#undef PLATFORM_LOG_ENABLED

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace OpenGL
{
	/// <summary>
	/// Abtract an interface for interoperating with dynamically loaded libraries.
	/// </summary>
	public static class GetProcAddress
	{
		#region Static Constructor

		/// <summary>
		/// Static constructor.
		/// </summary>
		static GetProcAddress()
		{
			PlatformID pId = Environment.OSVersion.Platform;

			// Determine GetOpenGLProcAddress implementation
			if ((pId == PlatformID.Win32NT) || (pId == PlatformID.Win32S) || (pId == PlatformID.Win32Windows) || (pId == PlatformID.WinCE)) {
				_GetProcAddress = new GetProcAddressWindows();
			} else if ((pId == PlatformID.Unix) || (pId == (PlatformID)4)) {
				string pIdString = DetectUnixKernel();

				// Distinguish between Unix and Mac OS X kernels.
				switch (pIdString) {
					case "Unix":
					case "Linux":
						_GetProcAddress = new GetProcAddressX11();
						break;
					case "Darwin":
						_GetProcAddress = new GetProcAddressOSX();
						break;
				}
			}
		}

		#endregion

		#region Static Implementation of IGetProcAddress

		/// <summary>
		/// Add a path of a directory as additional path for searching libraries.
		/// </summary>
		/// <param name="libraryDirPath">
		/// A <see cref="String"/> that specify the absolute path of the directory where the libraries are loaded using
		/// <see cref="GetProcAddress(string, string)"/> method.
		/// </param>
		public static void AddLibraryDirectory(string libraryDirPath)
		{
			if (_GetProcAddress == null)
				throw new PlatformNotSupportedException();
			_GetProcAddress.AddLibraryDirectory(libraryDirPath);
		}

		/// <summary>
		/// Retrieves the entry point for a dynamically exported function from any valid assembly.
		/// </summary>
		/// <param name="path">
		/// A <see cref="String"/> that specifies the path of the assembly file.
		/// </param>
		/// <param name="function">
		/// The function string for the OpenGL function (i.e. "GetProcAddress")
		/// </param>
		/// <returns>
		/// An IntPtr contaning the address for the entry point, or IntPtr.Zero if the specified
		/// function is not dynamically exported.
		/// </returns>
		public static IntPtr GetAddress(string path, string function)
		{
			if (_GetProcAddress == null)
				throw new PlatformNotSupportedException();
			return (_GetProcAddress.GetProcAddress(path, function));
		}


		/// <summary>
		/// Retrieves the entry point for a dynamically exported OpenGL function.
		/// </summary>
		/// <param name="function">The function string for the OpenGL function (eg. "glNewList")</param>
		/// <returns>
		/// An IntPtr contaning the address for the entry point, or IntPtr.Zero if the specified
		/// OpenGL function is not dynamically exported.
		/// </returns>
		public static IntPtr GetOpenGLAddress(string function)
		{
			if (_GetProcAddress == null)
				throw new PlatformNotSupportedException();
			return (_GetProcAddress.GetOpenGLProcAddress(function));
		}

		/// <summary>
		/// Executes "uname" which returns a string representing the name of the
		/// underlying Unix kernel.
		/// </summary>
		/// <returns>
		/// "Unix", "Linux", "Darwin" or null.
		/// </returns>
		/// <remarks>
		/// Source code from "Mono: A Developer's Notebook"
		/// </remarks>
		private static string DetectUnixKernel()
		{
			ProcessStartInfo startInfo = new ProcessStartInfo();

			startInfo.Arguments = "-s";
			startInfo.RedirectStandardOutput = true;
			startInfo.RedirectStandardError = true;
			startInfo.UseShellExecute = false;

			foreach (string unameprog in new string[] { "/usr/bin/uname", "/bin/uname", "uname" }) {
				try {

					startInfo.FileName = unameprog;

					using (Process uname = Process.Start(startInfo)) {
						return uname.StandardOutput.ReadLine().Trim();
					}
				} catch (System.IO.FileNotFoundException) {
					// The requested executable doesn't exist, try next one.
					continue;
				} catch (System.ComponentModel.Win32Exception) {
					continue;
				}
			}

			return (null);
		}

		/// <summary>
		/// Interface for loading external symbols.
		/// </summary>
		/// <remarks>
		/// 
		/// </remarks>
		private static IGetProcAddress _GetProcAddress;

		#endregion
	}<commit_msg>Better platform support exception handling.<commit_after>
// Copyright (C) 2009-2015 <NAME>
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
// USA

// Macro utility for logging platform-relared function calls
#undef PLATFORM_LOG_ENABLED

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;

namespace OpenGL
{
	/// <summary>
	/// Abtract an interface for interoperating with dynamically loaded libraries.
	/// </summary>
	public static class GetProcAddress
	{
		#region Static Constructor

		/// <summary>
		/// Static constructor.
		/// </summary>
		static GetProcAddress()
		{
			switch (Environment.OSVersion.Platform) {
				case PlatformID.Win32NT:
				case PlatformID.Win32Windows:
				case PlatformID.Win32S:
				case PlatformID.WinCE:
					_GetProcAddress = new GetProcAddressWindows();
					break;
				case PlatformID.Unix:
					string unixName = DetectUnixKernel();

					// Distinguish between Unix and Mac OS X kernels.
					switch (unixName) {
						case "Unix":
						case "Linux":
							_GetProcAddress = new GetProcAddressX11();
							break;
						case "Darwin":
							_GetProcAddress = new GetProcAddressOSX();
							break;
						case null:
							throw new NotSupportedException(String.Format("Unix platform not detected"));
						default:
							throw new NotSupportedException(String.Format("Unix platform {0} not supported", unixName));
					}
					break;
				default:
					throw new NotSupportedException(String.Format("platform {0} not supported", Environment.OSVersion.Platform));
			}
		}

		#endregion

		#region Static Implementation of IGetProcAddress

		/// <summary>
		/// Add a path of a directory as additional path for searching libraries.
		/// </summary>
		/// <param name="libraryDirPath">
		/// A <see cref="String"/> that specify the absolute path of the directory where the libraries are loaded using
		/// <see cref="GetProcAddress(string, string)"/> method.
		/// </param>
		public static void AddLibraryDirectory(string libraryDirPath)
		{
			if (_GetProcAddress == null)
				throw new PlatformNotSupportedException();
			_GetProcAddress.AddLibraryDirectory(libraryDirPath);
		}

		/// <summary>
		/// Retrieves the entry point for a dynamically exported function from any valid assembly.
		/// </summary>
		/// <param name="path">
		/// A <see cref="String"/> that specifies the path of the assembly file.
		/// </param>
		/// <param name="function">
		/// The function string for the OpenGL function (i.e. "GetProcAddress")
		/// </param>
		/// <returns>
		/// An IntPtr contaning the address for the entry point, or IntPtr.Zero if the specified
		/// function is not dynamically exported.
		/// </returns>
		public static IntPtr GetAddress(string path, string function)
		{
			if (_GetProcAddress == null)
				throw new PlatformNotSupportedException();
			return (_GetProcAddress.GetProcAddress(path, function));
		}


		/// <summary>
		/// Retrieves the entry point for a dynamically exported OpenGL function.
		/// </summary>
		/// <param name="function">The function string for the OpenGL function (eg. "glNewList")</param>
		/// <returns>
		/// An IntPtr contaning the address for the entry point, or IntPtr.Zero if the specified
		/// OpenGL function is not dynamically exported.
		/// </returns>
		public static IntPtr GetOpenGLAddress(string function)
		{
			if (_GetProcAddress == null)
				throw new PlatformNotSupportedException();
			return (_GetProcAddress.GetOpenGLProcAddress(function));
		}

		/// <summary>
		/// Executes "uname" which returns a string representing the name of the
		/// underlying Unix kernel.
		/// </summary>
		/// <returns>
		/// "Unix", "Linux", "Darwin" or null.
		/// </returns>
		/// <remarks>
		/// Source code from "Mono: A Developer's Notebook"
		/// </remarks>
		private static string DetectUnixKernel()
		{
			ProcessStartInfo startInfo = new ProcessStartInfo();

			startInfo.Arguments = "-s";
			startInfo.RedirectStandardOutput = true;
			startInfo.RedirectStandardError = true;
			startInfo.UseShellExecute = false;

			foreach (string unameprog in new string[] { "/usr/bin/uname", "/bin/uname", "uname" }) {
				// Avoid exception handling
				if (File.Exists(unameprog) == false)
					continue;

				try {
					startInfo.FileName = unameprog;
					using (Process uname = Process.Start(startInfo)) {
						return uname.StandardOutput.ReadLine().Trim();
					}
				} catch (FileNotFoundException) {
					// The requested executable doesn't exist, try next one.
					continue;
				} catch (System.ComponentModel.Win32Exception) {
					continue;
				}
			}

			return (null);
		}

		/// <summary>
		/// Interface for loading external symbols.
		/// </summary>
		private static IGetProcAddress _GetProcAddress;

		#endregion
	}
{'fraction_non_alphanumeric': 0.11531954887218045, 'fraction_numerical': 0.006109022556390977, 'mean_word_length': 3.1388564760793467, 'pattern_counts': {'":': 6, '<': 73, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4910402', 'n_tokens_mistral': 3519, 'n_tokens_neox': 2930, 'n_words': 1033}