From 817a255f93b4d734acabd7a8c0d12bad95815609 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 25 Feb 2024 00:23:42 -0700 Subject: [PATCH] Implement search_path, find_path with std::filesystem --- CMakeLists.txt | 11 ++- common/cmdfiles.cpp | 1 + common/find_path.cpp | 94 +++++++++++++++++++++++++ common/help.cpp | 1 + common/loadmap.cpp | 1 + common/miscovl.cpp | 1 + common/prompts2.cpp | 10 +-- common/realdos.cpp | 1 + common/search_path.cpp | 36 ++++++++++ headers/find_path.h | 14 ++++ headers/miscres.h | 1 - headers/search_path.h | 18 +++++ tests/CMakeLists.txt | 10 ++- tests/test_data.h.in | 7 +- tests/test_find_path.cpp | 140 +++++++++++++++++++++++++++++++++++++ tests/test_make_path.cpp | 9 ++- tests/test_search_path.cpp | 61 ++++++++++++++++ unix/general.cpp | 73 ------------------- vcpkg.json | 1 + win32/os_win32.cpp | 76 -------------------- 20 files changed, 407 insertions(+), 159 deletions(-) create mode 100644 common/find_path.cpp create mode 100644 common/search_path.cpp create mode 100644 headers/find_path.h create mode 100644 headers/search_path.h create mode 100644 tests/test_find_path.cpp create mode 100644 tests/test_search_path.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 26a38b8ae..28ac85e11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ project("${ID_PROJECT_NAME}" include(CTest) include(TestBigEndian) +find_package(Boost REQUIRED) + set(home_dir "${CMAKE_SOURCE_DIR}/home") set(ID_DIR ${CMAKE_CURRENT_SOURCE_DIR}) @@ -123,6 +125,7 @@ add_library(libid common/drivers.cpp common/memory.cpp headers/memory.h + common/find_path.cpp headers/find_path.h common/fractint.cpp common/framain2.cpp headers/framain2.h headers/get_ifs_token.h @@ -135,6 +138,7 @@ add_library(libid common/prompts1.cpp headers/prompts1.h common/prompts2.cpp headers/prompts2.h common/realdos.cpp headers/realdos.h + common/search_path.cpp headers/search_path.h common/update_save_name.cpp headers/update_save_name.h common/zoom.cpp headers/zoom.h @@ -272,6 +276,7 @@ source_group("Source Files/common/plumbing" FILES common/memory.cpp ) source_group("Header Files/common/ui" FILES + headers/find_path.h headers/fractint.h headers/framain2.h headers/get_ifs_token.h @@ -285,10 +290,12 @@ source_group("Header Files/common/ui" FILES headers/prompts1.h headers/prompts2.h headers/realdos.h + headers/search_path.h headers/update_save_name.h headers/zoom.h ) source_group("Source Files/common/ui" FILES + common/find_path.cpp common/fractint.cpp common/framain2.cpp common/help.cpp @@ -299,6 +306,7 @@ source_group("Source Files/common/ui" FILES common/prompts1.cpp common/prompts2.cpp common/realdos.cpp + common/search_path.cpp common/update_save_name.cpp common/zoom.cpp ) @@ -309,7 +317,8 @@ set_src_dir(common/fractint.cpp) target_compile_definitions(libid PUBLIC ${ID_TARGET_DEFINITIONS} $<$:${ID_TARGET_DEFINITIONS_DEBUG}>) target_compile_options(libid PUBLIC ${ID_TARGET_OPTIONS}) target_include_directories(libid PUBLIC headers) -target_link_libraries(libid PRIVATE helpcom os config) +target_link_libraries(libid PRIVATE helpcom os config Boost::boost) +target_link_libraries(libid PUBLIC config) add_dependencies(libid native_help) add_executable(id ${ID_EXECUTABLE_TYPE} diff --git a/common/cmdfiles.cpp b/common/cmdfiles.cpp index a3adf0798..4a1c6160f 100644 --- a/common/cmdfiles.cpp +++ b/common/cmdfiles.cpp @@ -7,6 +7,7 @@ #include "calcfrac.h" #include "cmdfiles.h" #include "drivers.h" +#include "find_path.h" #include "fracsuba.h" #include "fracsubr.h" #include "fractalb.h" diff --git a/common/find_path.cpp b/common/find_path.cpp new file mode 100644 index 000000000..3e67967bf --- /dev/null +++ b/common/find_path.cpp @@ -0,0 +1,94 @@ +#include "find_path.h" + +#include "port.h" +#include "prototyp.h" + +#include "cmdfiles.h" +#include "fractint.h" +#include "id_data.h" +#include "make_path.h" +#include "prompts2.h" +#include "search_path.h" + +#ifdef WIN32 +#include +#else +#include +#endif + +#include + +namespace fs = std::filesystem; + +/* + *---------------------------------------------------------------------- + * + * findpath -- + * + * Find where a file is. + * We return filename if it is an absolute path. + * Otherwise, we first try FRACTDIR/filename, SRCDIR/filename, + * and then ./filename. + * + * Results: + * Returns full pathname in fullpathname. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ +std::string find_path(const char *filename, + const std::function &get_env) // return full pathnames +{ + char fullpathname[FILE_MAX_PATH]; + fullpathname[0] = 0; // indicate none found + + char fname[FILE_MAX_FNAME]; + char ext[FILE_MAX_EXT]; + char temp_path[FILE_MAX_PATH]; + + // check current directory if curdir= parameter set + split_fname_ext(filename, fname, ext); + make_path(temp_path, "", "", fname, ext); + if (g_check_cur_dir && fs::exists(temp_path)) // file exists + { + return (fs::current_path() / filename).make_preferred().string(); + } + + // check for absolute path + //if (fs::path{filename}.is_absolute() && ) + //{ + //} + std::strcpy(temp_path, filename); // avoid side effect changes to filename + if (temp_path[0] == SLASHC || (temp_path[0] && temp_path[1] == ':')) + { + if (access(temp_path, 0) == 0) // file exists + { + std::strcpy(fullpathname, temp_path); + return fullpathname; + } + + split_fname_ext(temp_path, fname, ext); + make_path(temp_path, "", "", fname, ext); + } + + // check FRACTDIR + make_path(temp_path, "", g_fractal_search_dir1.c_str(), fname, ext); + if (access(temp_path, 0) == 0) + { + std::strcpy(fullpathname, temp_path); + return fullpathname; + } + + // check SRCDIR + make_path(temp_path, "", g_fractal_search_dir2.c_str(), fname, ext); + if (access(temp_path, 0) == 0) + { + std::strcpy(fullpathname, temp_path); + return fullpathname; + } + + // check PATH + return search_path(temp_path, "PATH", get_env); +} diff --git a/common/help.cpp b/common/help.cpp index 684f9e51e..cbdcefdeb 100644 --- a/common/help.cpp +++ b/common/help.cpp @@ -3,6 +3,7 @@ #include "cmdfiles.h" #include "drivers.h" +#include "find_path.h" #include "helpcom.h" #include "helpdefs.h" #include "id_data.h" diff --git a/common/loadmap.cpp b/common/loadmap.cpp index 94f610649..df77c8032 100644 --- a/common/loadmap.cpp +++ b/common/loadmap.cpp @@ -2,6 +2,7 @@ #include "prototyp.h" #include "cmdfiles.h" +#include "find_path.h" #include "miscres.h" #include "prompts1.h" #include "prompts2.h" diff --git a/common/miscovl.cpp b/common/miscovl.cpp index 68230eb81..7686d40f3 100644 --- a/common/miscovl.cpp +++ b/common/miscovl.cpp @@ -8,6 +8,7 @@ #include "calcfrac.h" #include "cmdfiles.h" #include "drivers.h" +#include "find_path.h" #include "fractalp.h" #include "fractype.h" #include "framain2.h" diff --git a/common/prompts2.cpp b/common/prompts2.cpp index c894b6733..fd511be69 100644 --- a/common/prompts2.cpp +++ b/common/prompts2.cpp @@ -10,6 +10,7 @@ #include "diskvid.h" #include "drivers.h" #include "evolve.h" +#include "find_path.h" #include "fracsubr.h" #include "fractalp.h" #include "fractype.h" @@ -1939,22 +1940,23 @@ void make_path(char *template_str, char const *drive, char const *dir, char cons } fs::path result; + auto not_empty = [](const char *ptr) { return ptr != nullptr && ptr[0] != 0; }; #ifndef XFRACT - if (drive) + if (not_empty(drive)) { result = drive; } #endif - if (dir) + if (not_empty(dir)) { result /= dir; result += '/'; } - if (fname) + if (not_empty(fname)) { result /= fname; } - if (ext) + if (not_empty(ext)) { result.replace_extension(ext); } diff --git a/common/realdos.cpp b/common/realdos.cpp index 254b2714a..de3262c05 100644 --- a/common/realdos.cpp +++ b/common/realdos.cpp @@ -5,6 +5,7 @@ #include "diskvid.h" #include "drivers.h" #include "editpal.h" +#include "find_path.h" #include "fractalp.h" #include "fractype.h" #include "helpcom.h" diff --git a/common/search_path.cpp b/common/search_path.cpp new file mode 100644 index 000000000..5cc5f97a0 --- /dev/null +++ b/common/search_path.cpp @@ -0,0 +1,36 @@ +#include "search_path.h" + +#include +#include + +#include +#include + +namespace fs = std::filesystem; + +std::string search_path(const char *filename, const char *path_var, std::function get_env) +{ + if (filename == nullptr || path_var == nullptr) + { + return {}; + } + + const char *path = get_env(path_var); + if (path == nullptr) + { + return {}; + } + + std::vector parts; + split(parts, path, boost::algorithm::is_any_of(PATH_SEPARATOR)); + for (const fs::path dir : parts) + { + fs::path candidate{dir / filename}; + if (exists(candidate)) + { + return candidate.make_preferred().string(); + } + } + + return {}; +} diff --git a/headers/find_path.h b/headers/find_path.h new file mode 100644 index 000000000..b8f38ebb0 --- /dev/null +++ b/headers/find_path.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include +#include + +std::string find_path(const char *filename, const std::function &get_env); + +inline void findpath(char const *filename, char *fullpathname) +{ + const std::string result = find_path(filename, [](const char *var) -> const char * { return std::getenv(var); }); + std::strcpy(fullpathname, result.c_str()); +} diff --git a/headers/miscres.h b/headers/miscres.h index c7a32169d..1a6fc6ab4 100644 --- a/headers/miscres.h +++ b/headers/miscres.h @@ -19,7 +19,6 @@ extern void (*mtrig2)(); extern void (*mtrig3)(); extern void restore_active_ovly(); -extern void findpath(char const *filename, char *fullpathname); extern void notdiskmsg(); extern void cvtcentermag(double *, double *, LDBL *, double *, double *, double *); extern void cvtcorners(double, double, LDBL, double, double, double); diff --git a/headers/search_path.h b/headers/search_path.h new file mode 100644 index 000000000..9a99f11a5 --- /dev/null +++ b/headers/search_path.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +#ifdef WIN32 +constexpr const char *const PATH_SEPARATOR{";"}; +#else +constexpr const char *const PATH_SEPARATOR{":"}; +#endif + +std::string search_path(const char *filename, const char *path_var, std::function get_env); + +inline std::string search_path(const char * filename, const char *path_var) +{ + return search_path(filename, path_var, [](const char *var) -> const char * { return std::getenv(var); }); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 78dc35c1a..fc3375889 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,16 +6,24 @@ set(ID_TEST_DATA_DIR "${CMAKE_CURRENT_BINARY_DIR}/test_data") SET(ID_TEST_FIRST_IFS_NAME "binary") set(ID_TEST_FIRST_IFS_PARAM1 ".5") set(ID_TEST_SECOND_IFS_NAME "3dfern") +set(ID_TEST_IFS_FILE "test.ifs") +configure_file(test.ifs.in "${ID_TEST_DATA_DIR}/${ID_TEST_IFS_FILE}") + +set(ID_TEST_DATA_SUBDIR "${ID_TEST_DATA_DIR}/subdir") +set(ID_TEST_IFS_FILE2 "test2.ifs") +configure_file(test.ifs.in "${ID_TEST_DATA_SUBDIR}/${ID_TEST_IFS_FILE2}") + configure_file(test_data.h.in include/test_data.h @ONLY) -configure_file(test.ifs.in "${ID_TEST_DATA_DIR}/test.ifs") add_executable(test-id test.ifs.in "${ID_TEST_DATA_DIR}/test.ifs" "${CMAKE_CURRENT_BINARY_DIR}/include/test_data.h" test_data.h.in + test_find_path.cpp test_get_ifs_token.cpp test_make_path.cpp + test_search_path.cpp test_update_save_name.cpp ) source_group("CMake Templates" REGULAR_EXPRESSION ".*\\.in$") diff --git a/tests/test_data.h.in b/tests/test_data.h.in index 8f71de27c..6752b9615 100644 --- a/tests/test_data.h.in +++ b/tests/test_data.h.in @@ -1,9 +1,12 @@ #pragma once -#define ID_TEST_DATA_DIR "@ID_TEST_DATA_DIR@" +#define ID_TEST_DATA_DIR "@ID_TEST_DATA_DIR@" +#define ID_TEST_DATA_SUBDIR "@ID_TEST_DATA_SUBDIR@" // IFS test data -#define ID_TEST_IFS_FILE "test.ifs" +#define ID_TEST_IFS_FILE "@ID_TEST_IFS_FILE@" #define ID_TEST_FIRST_IFS_NAME "@ID_TEST_FIRST_IFS_NAME@" #define ID_TEST_FIRST_IFS_PARAM1 "@ID_TEST_FIRST_IFS_PARAM1@" #define ID_TEST_SECOND_IFS_NAME "@ID_TEST_SECOND_IFS_NAME@" + +#define ID_TEST_IFS_FILE2 "@ID_TEST_IFS_FILE2@" diff --git a/tests/test_find_path.cpp b/tests/test_find_path.cpp new file mode 100644 index 000000000..899d30361 --- /dev/null +++ b/tests/test_find_path.cpp @@ -0,0 +1,140 @@ +#include + +#include +#include + +#include +#include +#include + +#include "test_data.h" + +#include + +#include + +namespace fs = std::filesystem; + +namespace +{ + +class current_path_saver +{ +public: + current_path_saver(const fs::path &new_path) : + m_old_path(fs::current_path()) + { + current_path(new_path); + } + ~current_path_saver() + { + current_path(m_old_path); + } + +private: + fs::path m_old_path; +}; + +using GetEnv = std::function; + +class TestFindPath : public ::testing::Test +{ +public: + ~TestFindPath() override = default; + +protected: + void SetUp() override; + + const char *m_non_existent{"goink.goink"}; + GetEnv m_empty_env{[](const char *) -> const char * { return nullptr; }}; + std::string m_path{std::string{ID_TEST_DATA_DIR} + PATH_SEPARATOR + ID_TEST_DATA_SUBDIR}; + GetEnv m_env_path{[&](const char *var) { return (std::string{var} == "PATH") ? m_path.c_str() : nullptr; }}; +}; + +void TestFindPath::SetUp() +{ + Test::SetUp(); + g_check_cur_dir = false; + g_fractal_search_dir1.clear(); + g_fractal_search_dir2.clear(); +} + +} // namespace + +TEST_F(TestFindPath, foundInCurrentDirectory) +{ + current_path_saver cd(ID_TEST_DATA_DIR); + g_check_cur_dir = true; + + const std::string result = find_path(ID_TEST_IFS_FILE, m_empty_env); + + ASSERT_EQ((fs::path{ID_TEST_DATA_DIR} / ID_TEST_IFS_FILE).make_preferred(), fs::path{result}); +} + +TEST_F(TestFindPath, notFoundInCurrentDirectory) +{ + current_path_saver cd(ID_TEST_DATA_DIR); + g_check_cur_dir = true; + + const std::string result = find_path(m_non_existent, m_empty_env); + + ASSERT_TRUE(result.empty()); +} + +TEST_F(TestFindPath, foundInSearchDir1) +{ + g_fractal_search_dir1 = ID_TEST_DATA_DIR; + + const std::string result = find_path(ID_TEST_IFS_FILE, m_empty_env); + + ASSERT_EQ((fs::path{ID_TEST_DATA_DIR} / ID_TEST_IFS_FILE).make_preferred(), fs::path{result}); +} + +TEST_F(TestFindPath, notFoundInSearchDir1) +{ + g_fractal_search_dir1 = ID_TEST_DATA_DIR; + + const std::string result = find_path(m_non_existent, m_empty_env); + + ASSERT_TRUE(result.empty()); +} + +TEST_F(TestFindPath, foundInSearchDir2) +{ + g_fractal_search_dir2 = ID_TEST_DATA_DIR; + + const std::string result = find_path(ID_TEST_IFS_FILE, m_empty_env); + + ASSERT_EQ((fs::path{ID_TEST_DATA_DIR} / ID_TEST_IFS_FILE).make_preferred(), fs::path{result}); +} + +TEST_F(TestFindPath, notFoundInSearchDir2) +{ + g_fractal_search_dir2 = ID_TEST_DATA_DIR; + + const std::string result = find_path(m_non_existent, m_empty_env); + + ASSERT_TRUE(result.empty()); +} + +TEST_F(TestFindPath, foundInPath) +{ + const std::string result = find_path(ID_TEST_IFS_FILE, m_env_path); + + ASSERT_EQ((fs::path{ID_TEST_DATA_DIR} / ID_TEST_IFS_FILE).make_preferred(), fs::path{result}); +} + +TEST_F(TestFindPath, foundInPathSubDir) +{ + const std::string result = find_path(ID_TEST_IFS_FILE2, m_env_path); + + ASSERT_EQ((fs::path{ID_TEST_DATA_SUBDIR} / ID_TEST_IFS_FILE2).make_preferred(), fs::path{result}); +} + +TEST_F(TestFindPath, notFoundInPath) +{ + + const std::string result = find_path(m_non_existent, m_env_path); + + ASSERT_TRUE(result.empty()); +} diff --git a/tests/test_make_path.cpp b/tests/test_make_path.cpp index 2b77ef87f..d10b6220f 100644 --- a/tests/test_make_path.cpp +++ b/tests/test_make_path.cpp @@ -52,13 +52,20 @@ TEST_F(TestMakePath, directory) ASSERT_EQ(fs::path{"foo/"}.make_preferred().string(), std::string{buffer}); } -TEST_F(TestMakePath, filename) +TEST_F(TestMakePath, filenameNullDirectory) { make_path(buffer, nullptr, nullptr, "foo", nullptr); ASSERT_STREQ("foo", buffer); } +TEST_F(TestMakePath, filenameEmptyDirectory) +{ + make_path(buffer, nullptr, "", "foo", nullptr); + + ASSERT_STREQ("foo", buffer); +} + TEST_F(TestMakePath, extension) { make_path(buffer, nullptr, nullptr, nullptr, ".gif"); diff --git a/tests/test_search_path.cpp b/tests/test_search_path.cpp new file mode 100644 index 000000000..33ee88851 --- /dev/null +++ b/tests/test_search_path.cpp @@ -0,0 +1,61 @@ +#include + +#include "test_data.h" + +#include + +#include + +namespace fs = std::filesystem; + +TEST(TestSearchPath, pathVarNotDefined) +{ + const std::string result = search_path(ID_TEST_IFS_FILE, "PATH", [](const char *) { return nullptr; }); + + ASSERT_TRUE(result.empty()); +} + +TEST(TestSearchPath, fileNotInPath) +{ + const std::string path{ID_TEST_DATA_DIR}; + + const std::string result = search_path("goink.goink", "PATH", [&](const char *) { return path.c_str(); }); + + ASSERT_TRUE(result.empty()); +} + +TEST(TestSearchPath, fileInSinglePath) +{ + const std::string path{ID_TEST_DATA_DIR}; + + const std::string result = search_path(ID_TEST_IFS_FILE, "PATH", [&](const char *) { return path.c_str(); }); + + ASSERT_EQ((fs::path{ID_TEST_DATA_DIR} / ID_TEST_IFS_FILE).make_preferred().string(), result); +} + +TEST(TestSearchPath, fileNotInSinglePath) +{ + const std::string path{ID_TEST_DATA_DIR}; + + const std::string result = search_path("goink.goink", "PATH", [&](const char *) { return path.c_str(); }); + + ASSERT_TRUE(result.empty()); +} + +TEST(TestSearchPath, fileInMultiplePath) +{ + const std::string path{std::string{ID_TEST_DATA_DIR} + PATH_SEPARATOR + ID_TEST_DATA_SUBDIR}; + + const std::string result = search_path(ID_TEST_IFS_FILE2, "PATH", [&](const char *) { return path.c_str(); }); + + ASSERT_EQ((fs::path{ID_TEST_DATA_SUBDIR} / ID_TEST_IFS_FILE2).make_preferred().string(), result); +} + +TEST(TestSearchPath, fileNotInMultiplePath) +{ + const std::string path{std::string{ID_TEST_DATA_DIR} + PATH_SEPARATOR + ID_TEST_DATA_SUBDIR}; + + const std::string result = search_path("goink.goink", "PATH", [&](const char *) { return path.c_str(); }); + + ASSERT_TRUE(result.empty()); +} diff --git a/unix/general.cpp b/unix/general.cpp index 4c36a79a0..ebefe8c61 100644 --- a/unix/general.cpp +++ b/unix/general.cpp @@ -818,76 +818,3 @@ decode_orbits_info(ORBITS_INFO *info, int dir) std::memcpy((char *)info, (char *)buf, ORBITS_INFO_SIZE); } } - -static bool path_exists(const char *path) -{ - int fd = open(path, O_RDONLY); - if (fd != -1) - { - close(fd); - } - return fd != -1; -} - -/* - *---------------------------------------------------------------------- - * - * findpath -- - * - * Find where a file is. - * We return filename if it is an absolute path. - * Otherwise we first try FRACTDIR/filename, SRCDIR/filename, - * and then ./filename. - * - * Results: - * Returns full pathname in fullpathname. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ -void findpath(char const *filename, char *fullpathname) -{ - // check current directory if curdir= parameter set - if (g_check_cur_dir) - { - // check for current dir - std::strcpy(fullpathname, "./"); - std::strcat(fullpathname, filename); - if (path_exists(fullpathname)) - { - return; - } - } - - // check for absolute path - if (filename[0] == '/') - { - std::strcpy(fullpathname, filename); - if (path_exists(fullpathname)) - { - return; - } - } - - // check for FRACTDIR - std::strcpy(fullpathname, g_fractal_search_dir1.c_str()); - std::strcat(fullpathname, "/"); - std::strcat(fullpathname, filename); - if (path_exists(fullpathname)) - { - return; - } - - // check for SRCDIR - std::strcpy(fullpathname, g_fractal_search_dir2.c_str()); - std::strcat(fullpathname, "/"); - std::strcat(fullpathname, filename); - if (path_exists(fullpathname)) - { - return; - } - - fullpathname[0] = 0; -} diff --git a/vcpkg.json b/vcpkg.json index 693017d7a..5b7dc6d67 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -3,6 +3,7 @@ "name": "iterated-dynamics", "version": "1.0.0", "dependencies": [ + "boost-algorithm", "gtest", { "name": "libx11", diff --git a/win32/os_win32.cpp b/win32/os_win32.cpp index d2acdca50..0d295adc2 100644 --- a/win32/os_win32.cpp +++ b/win32/os_win32.cpp @@ -817,82 +817,6 @@ void init_failure(char const *message) MessageBox(nullptr, message, "FractInt: Fatal Error", MB_OK); } -/* - *---------------------------------------------------------------------- - * - * findpath -- - * - * Find where a file is. - * We return filename if it is an absolute path. - * Otherwise, we first try FRACTDIR/filename, SRCDIR/filename, - * and then ./filename. - * - * Results: - * Returns full pathname in fullpathname. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ -void findpath(char const *filename, char *fullpathname) // return full pathnames -{ - fullpathname[0] = 0; // indicate none found - - char fname[FILE_MAX_FNAME]; - char ext[FILE_MAX_EXT]; - char temp_path[FILE_MAX_PATH]; - - // check current directory if curdir= parameter set - split_fname_ext(filename, fname, ext); - make_path(temp_path, "", "", fname, ext); - if (g_check_cur_dir && access(temp_path, 0) == 0) // file exists - { - std::strcpy(fullpathname, temp_path); - return; - } - - // check for absolute path - std::strcpy(temp_path, filename); // avoid side effect changes to filename - if (temp_path[0] == SLASHC || (temp_path[0] && temp_path[1] == ':')) - { - if (access(temp_path, 0) == 0) // file exists - { - std::strcpy(fullpathname, temp_path); - return; - } - - split_fname_ext(temp_path, fname, ext); - make_path(temp_path, "", "", fname, ext); - } - - // check FRACTDIR - make_path(temp_path, "", g_fractal_search_dir1.c_str(), fname, ext); - if (access(temp_path, 0) == 0) - { - std::strcpy(fullpathname, temp_path); - return; - } - - // check SRCDIR - make_path(temp_path, "", g_fractal_search_dir2.c_str(), fname, ext); - if (access(temp_path, 0) == 0) - { - std::strcpy(fullpathname, temp_path); - return; - } - - // check PATH - _searchenv(temp_path, "PATH", fullpathname); - if (fullpathname[0] != 0) // found it! - { - if (std::strncmp(&fullpathname[2], SLASHSLASH, 2) == 0) // stupid klooge! - { - std::strcpy(&fullpathname[3], temp_path); - } - } -} - // case independent version of std::strncmp int strncasecmp(char const *s, char const *t, int ct) {