<commit_before>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 RC 1        *
*                (c) 2006-2011 INRIA, USTL, UJF, CNRS, MGH                    *
*                                                                             *
* 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.          *
*******************************************************************************
*                              SOFA :: Framework                              *
*                                                                             *
* Authors: The SOFA Team (see Authors.txt)                                    *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/
#include <sofa/helper/system/FileRepository.h>
#include <sofa/helper/system/SetDirectory.h>
#include <sofa/config.h>

#include <sys/types.h>
#include <sys/stat.h>
#if defined(WIN32)
#include <windows.h>
#include <direct.h>
#elif defined(_XBOX)
#include <xtl.h>
#else
#include <unistd.h>
#endif

#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>

namespace sofa
{

namespace helper
{

namespace system
{

std::string AddSofaSrcDir (const std::string & path = std::string())
{
    std::string result = sofa_tostring(SOFA_SRC_DIR);
    result = result.substr(1,result.size()-2);
    result += path;
    return result;
}

std::string AddSofaBuildDir (const std::string & path = std::string())
{
    std::string result = sofa_tostring(SOFA_BUILD_DIR);
    result = result.substr(1,result.size()-2);
    result += path;
    return result;
}

// replacing every occurences of "//"  by "/"
std::string cleanPath( const std::string& path )
{
    std::string p = path;
    size_t pos = p.find("//");
	size_t len = p.length();
    while( pos != std::string::npos )
    {
		if ( pos == (len-1))
			p.replace( pos, 2, "");
		else
			p.replace(pos,2,"/");
        pos = p.find("//");
    }
    return p;
}

#if defined (WIN32) || defined (_XBOX)
#define SOFA_PLUGIN_SUBDIR /bin
#else
#define SOFA_PLUGIN_SUBDIR /lib
#endif

FileRepository PluginRepository("SOFA_PLUGIN_PATH", AddSofaBuildDir("SOFA_PLUGIN_SUBDIR").c_str());

#undef SOFA_PLUGIN_SUBDIR



static FileRepository createSofaDataPath()
{
    FileRepository repository("SOFA_DATA_PATH");

    repository.addLastPath(std::string(SOFA_BUILD_DIR));
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/share");
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/examples");

#if defined (WIN32) || defined (_XBOX) || defined(PS3)
#elif defined (__APPLE__)
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/Resources/examples");
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/Resources");
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/../../../examples");
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/../../../share");
#else // LINUX
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/../Verification/data");<commit_msg>r10657/sofa : push b79ab8e..7ca3015<commit_after>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 RC 1        *
*                (c) 2006-2011 INRIA, USTL, UJF, CNRS, MGH                    *
*                                                                             *
* 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.          *
*******************************************************************************
*                              SOFA :: Framework                              *
*                                                                             *
* Authors: The SOFA Team (see Authors.txt)                                    *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/
#include <sofa/helper/system/FileRepository.h>
#include <sofa/helper/system/SetDirectory.h>
#include <sofa/config.h>

#include <sys/types.h>
#include <sys/stat.h>
#if defined(WIN32)
#include <windows.h>
#include <direct.h>
#elif defined(_XBOX)
#include <xtl.h>
#else
#include <unistd.h>
#endif

#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>

namespace sofa
{

namespace helper
{

namespace system
{

std::string AddSofaSrcDir (const std::string & path = std::string())
{
    std::string result = sofa_tostring(SOFA_SRC_DIR);
    result = result.substr(1,result.size()-2);
    result += path;
    return result;
}

std::string AddSofaBuildDir (const std::string & path = std::string())
{
    std::string result = sofa_tostring(SOFA_BUILD_DIR);
    result = result.substr(1,result.size()-2);
    result += path;
    return result;
}

// replacing every occurences of "//"  by "/"
std::string cleanPath( const std::string& path )
{
    std::string p = path;
    size_t pos = p.find("//");
	size_t len = p.length();
    while( pos != std::string::npos )
    {
		if ( pos == (len-1))
			p.replace( pos, 2, "");
		else
			p.replace(pos,2,"/");
        pos = p.find("//");
    }
    return p;
}

#if defined (WIN32) || defined (_XBOX)
static std::string pluginSubdir("/bin");
#else
static std::string pluginSubdir("/lib");
#endif

FileRepository PluginRepository("SOFA_PLUGIN_PATH", AddSofaBuildDir(pluginSubdir).c_str());


static FileRepository createSofaDataPath()
{
    FileRepository repository("SOFA_DATA_PATH");

    repository.addLastPath(std::string(SOFA_BUILD_DIR));
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/share");
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/examples");

#if defined (WIN32) || defined (_XBOX) || defined(PS3)
#elif defined (__APPLE__)
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/Resources/examples");
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/Resources");
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/../../../examples");
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/../../../share");
#else // LINUX
    repository.addLastPath(std::string(SOFA_SRC_DIR) + "/../Verification/data");
{'fraction_non_alphanumeric': 0.1717062634989201, 'fraction_numerical': 0.010679145668346532, 'mean_word_length': 2.214423447743926, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5317500', 'n_tokens_mistral': 2328, 'n_tokens_neox': 2220, 'n_words': 587}