<commit_before>/*
* FUEL(isp) is a fast usable embeddable lisp interpreter.
*
* Copyright (c) 2016 <NAME>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* */

//using System;
//using System.IO;
//using System.Linq;
//using System.Reflection;

#include "fuel.h"

#ifdef _WIN32
#include <windows.h>
#define FUEL_DEBUGGER_NAME "FuelDebugger.dll"
#endif

#if defined( __linux__ ) || defined( __APPLE__ )
#include <dlfcn.h>			// fuer: 
#endif

#if defined( __linux__ )
#define FUEL_DEBUGGER_NAME "libFuelDebugger.so"
#endif

#if defined( __APPLE__ )
#define FUEL_DEBUGGER_NAME "libFuelDebugger.dylib"
#endif

void * SimpleLoadLibrary(const char * sDllName)
{
#ifdef _WIN32
#ifdef UNICODE
	std::string s(sDllName);
	std::wstring stemp = std::wstring(s.begin(), s.end());
    return (void *)LoadLibrary( (LPCWSTR)stemp.c_str() );
#else
    return (void *)LoadLibrary( (LPCSTR)sDllName );
#endif
#endif
#if defined( __linux__ ) || defined( __APPLE__ )
    return (void *)dlopen( sDllName, RTLD_LAZY );
#endif
}

bool SimpleFreeLibrary(void * hDllModule)
{
#ifdef _WIN32
	return FreeLibrary((HMODULE)hDllModule) == TRUE;
#endif
#if defined( __linux__ ) || defined( __APPLE__ )
    return dlclose( (void *)hDllModule );
#endif
}

void * SimpleGetProcAddress(void * hDllModule, const char * sProcName)
{
#ifdef _WIN32
	return (void *)GetProcAddress((HMODULE)hDllModule, sProcName);
#endif
#if defined( __linux__ ) || defined( __APPLE__ )
	return (void *)dlsym( (void *)hDllModule, sProcName );
#endif
}

static void * g_hDebuggerDLL = 0;

#ifdef UNIT_TEST
extern "C" CppLisp::ILispDebugger * create_debugger();
#endif

static void DisconnectDebugger()
{
	if (g_hDebuggerDLL != 0)
	{
		SimpleFreeLibrary(g_hDebuggerDLL);
	}
}

namespace CppLisp
{
	extern string LispUtils_LibraryPath;

	uint64_t Environment_GetTickCount(void);

	bool Contains(const std::vector<string> & container, const string & search)
	{
		return std::find(container.begin(), container.end(), search) != container.end();
	}

	std::vector<string> GetScriptFilesFromProgramArgs(const std::vector<string> & args)
	{
		std::vector<string> result;
		std::copy_if(args.begin(), args.end(), back_inserter(result), [](const string & s) -> bool { return !s.StartsWith("-");  });
		return result;
	}

	void Fuel::Main(std::vector<string> args)<commit_msg>Fixed for fuel application without shared libraries<commit_after>/*
* FUEL(isp) is a fast usable embeddable lisp interpreter.
*
* Copyright (c) 2016 <NAME>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* */

//using System;
//using System.IO;
//using System.Linq;
//using System.Reflection;

#include "fuel.h"

#ifdef _WIN32
#include <windows.h>
#define FUEL_DEBUGGER_NAME "FuelDebugger.dll"
#endif

#if defined( __linux__ ) || defined( __APPLE__ )
#include <dlfcn.h>			// fuer: 
#endif

#if defined( __linux__ )
#define FUEL_DEBUGGER_NAME "libFuelDebugger.so"
#endif

#if defined( __APPLE__ )
#define FUEL_DEBUGGER_NAME "libFuelDebugger.dylib"
#endif

void * SimpleLoadLibrary(const char * sDllName)
{
#ifdef _WIN32
#ifdef UNICODE
	std::string s(sDllName);
	std::wstring stemp = std::wstring(s.begin(), s.end());
    return (void *)LoadLibrary( (LPCWSTR)stemp.c_str() );
#else
    return (void *)LoadLibrary( (LPCSTR)sDllName );
#endif
#endif
#if defined( __linux__ ) || defined( __APPLE__ )
    return (void *)dlopen( sDllName, RTLD_LAZY );
#endif
}

bool SimpleFreeLibrary(void * hDllModule)
{
#ifdef _WIN32
	return FreeLibrary((HMODULE)hDllModule) == TRUE;
#endif
#if defined( __linux__ ) || defined( __APPLE__ )
    return dlclose( (void *)hDllModule );
#endif
}

void * SimpleGetProcAddress(void * hDllModule, const char * sProcName)
{
#ifdef _WIN32
	return (void *)GetProcAddress((HMODULE)hDllModule, sProcName);
#endif
#if defined( __linux__ ) || defined( __APPLE__ )
	return (void *)dlsym( (void *)hDllModule, sProcName );
#endif
}

static void * g_hDebuggerDLL = 0;

#if !defined(UNIT_TEST) && !defined(WITH_STATIC_DEBUGGER)
extern "C" CppLisp::ILispDebugger * create_debugger();
#endif

static void DisconnectDebugger()
{
	if (g_hDebuggerDLL != 0)
	{
		SimpleFreeLibrary(g_hDebuggerDLL);
	}
}

namespace CppLisp
{
	extern string LispUtils_LibraryPath;

	uint64_t Environment_GetTickCount(void);

	bool Contains(const std::vector<string> & container, const string & search)
	{
		return std::find(container.begin(), container.end(), search) != container.end();
	}

	std::vector<string> GetScriptFilesFromProgramArgs(const std::vector<string> & args)
	{
		std::vector<string> result;
		std::copy_if(args.begin(), args.end(), back_inserter(result), [](const string & s) -> bool { return !s.StartsWith("-");  });
		return result;
	}

	void Fuel::Main(std::vector<string> args)
{'fraction_non_alphanumeric': 0.11443898077782745, 'fraction_numerical': 0.0047682908657428105, 'mean_word_length': 5.255358807082945, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '3204548', 'n_tokens_mistral': 2254, 'n_tokens_neox': 2189, 'n_words': 712}