aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-08-31 08:23:26 +0000
committer_ov4 <ov4@ov4.org>2026-08-31 08:23:26 +0000
commit097165066c0f83c57e4f4cce02225c601deb2f02 (patch)
tree9f3b007eaf136a69b83a2bd7c716b5b5f2c46814 /src
parent0e460c391c093f1eb074d3192c60d37fa425d48d (diff)
path
Diffstat (limited to 'src')
-rw-r--r--src/eval.cc3
-rw-r--r--src/main.cc8
-rw-r--r--src/path.cc42
3 files changed, 51 insertions, 2 deletions
diff --git a/src/eval.cc b/src/eval.cc
index 369e032..4350367 100644
--- a/src/eval.cc
+++ b/src/eval.cc
@@ -43,12 +43,13 @@ void eval(char *cmdline)
block_all(&prev);
pid_t pid = fork();
+ const char* cmd = find_cmd(argv[0]).c_str();
if (pid == 0) // child
{
sigprocmask(SIG_SETMASK, &prev, nullptr);
setpgid(0, 0);
- execve(argv[0], argv, environ);
+ execve(cmd, argv, environ);
atomic_print(cmdline, true);
atomic_print(": Command not found\n");
diff --git a/src/main.cc b/src/main.cc
index 5a2bd71..1042cf8 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -22,6 +22,7 @@
#include "handler.h"
#include "ground.h"
#include "eval.h"
+#include "path.h"
using namespace std;
using namespace ov4;
@@ -47,13 +48,18 @@ handler_t *Signal(int signum, handler_t *handler);
// built-in commands
void builtin_command_quit();
-
+void test()
+{
+ cout << find_cmd("ls") << endl;
+ exit(0);
+}
/*
* main - The shell's main routine
*/
int main(int argc, char **argv)
{
+ //test();
init();
char c;
char cmdline[MAXLINE];
diff --git a/src/path.cc b/src/path.cc
new file mode 100644
index 0000000..519fd20
--- /dev/null
+++ b/src/path.cc
@@ -0,0 +1,42 @@
+#include "path.h"
+
+namespace ov4
+{
+
+using namespace std;
+
+string find_cmd(char* s)
+{
+ string tmp = s;
+ return find_cmd(tmp);
+}
+
+string find_cmd(string s)
+{
+ if (s.size() == 0) return "/";
+ if (s[0] == '/') return s;
+
+ string path = getenv("PATH");
+ size_t i = 0, j = 0, l = path.size();
+ while (true)
+ {
+ for (; j < l; j++)
+ if (path[j] == ':')
+ break;
+
+ string cmd = path.substr(i, j-i) + '/' +s;
+ cout << cmd << endl;
+ if (access(cmd.c_str(), F_OK) == 0)
+ return cmd;
+
+ if (j == l)
+ return "/";
+
+ j++;
+ i=j;
+
+ }
+}
+
+
+}