From c1733952f1bbb567b335109f51fb66a73abfedd3 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 1 Sep 2026 06:35:52 +0000 Subject: path . --- include/path.h | 5 +++++ src/init.cc | 2 +- src/path.cc | 24 ++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/path.h b/include/path.h index ca0e052..c4ea85c 100644 --- a/include/path.h +++ b/include/path.h @@ -5,12 +5,17 @@ #include #include #include +#include namespace ov4 { +extern std::string current_dir; + std::string find_cmd(char* s); std::string find_cmd(std::string s); +std::string set_current_dir(std::string s); +std::string path_unifier(const std::string &s); } diff --git a/src/init.cc b/src/init.cc index 06b66e1..9fdd5b7 100644 --- a/src/init.cc +++ b/src/init.cc @@ -14,7 +14,7 @@ There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR P Published under GNU AFFERO GENERAL PUBLIC LICENSE (AGPL) Version 3." << endl; signal_init(); - + set_current_dir(get_current_dir_name()); } diff --git a/src/path.cc b/src/path.cc index 620c464..e9d1892 100644 --- a/src/path.cc +++ b/src/path.cc @@ -5,6 +5,8 @@ namespace ov4 using namespace std; +string current_dir; + string find_cmd(char* s) { string tmp = s; @@ -13,8 +15,11 @@ string find_cmd(char* s) string find_cmd(string s) { - if (s.size() == 0) return "/"; - if (s[0] == '/') return s; + if (s.size() == 0) return ""; + string unified_s = path_unifier(s); + cout << unified_s << endl; + if (access(unified_s.c_str(), F_OK) == 0) + return unified_s; string path = getenv("PATH"); size_t i = 0, j = 0, l = path.size(); @@ -37,5 +42,20 @@ string find_cmd(string s) } } +string path_unifier(const string &s) +{ + if (s.size() == 0) return ""; + if (s[0] == '/') return s; + if (s[0] == '.') + { + return current_dir + s.substr(1); + } +} + +string set_current_dir(string s) +{ + return current_dir = s; +} + } -- cgit v1.3.1-4-g156e