static int path_func_test() { char *p; test_ffp (fp_dir (""), "."); test_ffp (fp_dir ("gtest.h"), "."); test_ffp (fp_base ("gtest.h"), "gtest.h"); test_ffp (fp_dir ("./gtest.h"), "."); test_ffp (fp_base ("./gtest.h"), "gtest.h"); test_ffp (fp_dir ("/tmp/gtest/gtest.h"), "/tmp/gtest"); test_ffp (fp_base ("/tmp/gtest/gtest.h"), "gtest.h"); test_ffp (fp_abs ("/tmp/gtest/gtest.h"), "/tmp/gtest/gtest.h"); BUG_ON (!fp_hasprefix ("/tmp/gtest", "/tmp") ); BUG_ON (!fp_hasprefix ("/tmp/gtest", "") ); BUG_ON (!fp_hasprefix ("/tmp/gtest", "/tmp/gtest") ); BUG_ON (fp_hasprefix ("/tmp/gtest", "/tmp/gtest/") ); BUG_ON (!fp_hassuffix ("/tmp/gtest", "gtest") ); BUG_ON (!fp_hassuffix ("/tmp/gtest", "") ); BUG_ON (!fp_hassuffix ("/tmp/gtest", "/tmp/gtest") ); BUG_ON (fp_hassuffix ("/tmp/gtest", "/tmp/gtest/") ); return 0; }
int set_dir(PluginInstance* plugin, const wchar_t* dir, bool show_error) { FilePath fp_dir(dir); FilePath current_dir(plugin->current_dir); bool parent_dir = wcscmp(dir, L"..") == 0; if (current_dir.is_root_path() && parent_dir) { if (g_plugin_options.exit_on_dot_dot) far_control_ptr(plugin, FCTL_CLOSEPANEL, nullptr); return TRUE; } else if (parent_dir) { current_dir = current_dir.get_partial_path(current_dir.size() - 1); } else { current_dir.combine(fp_dir); } UnicodeString cd = current_dir.get_full_path(); if (!current_dir.is_root_path()) { plugin->last_object = cd; if (!dir_exists(cd, plugin->session)) FAIL(SystemError(ERROR_PATH_NOT_FOUND)); } plugin->current_dir = cd; return TRUE; }