aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-09-01 06:35:52 +0000
committer_ov4 <ov4@ov4.org>2026-09-01 06:35:52 +0000
commitc1733952f1bbb567b335109f51fb66a73abfedd3 (patch)
treed299d08a55d146e5c8cc21f5e68b689e15bdff08
parentc9c3b2f4357e30dd078075b3259d86adca6958e3 (diff)
path .
-rw-r--r--include/path.h5
-rw-r--r--src/init.cc2
-rw-r--r--src/path.cc24
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 <string>
#include <unistd.h>
#include <iterator>
+#include <iostream>
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;
+}
+
}