aboutsummaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-09-14 20:48:50 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-09-14 20:48:50 +0200
commit8e40323db9715621d8ab45ff6d943c2eeba46ea0 (patch)
tree010828d6a75dfaaf94535035dc50b6a2a55aa12e /src/eval
parent3693acaff9fbf3f34dc2907e95dd221d5a8bc9e4 (diff)
downloadminishell-8e40323db9715621d8ab45ff6d943c2eeba46ea0.tar.gz
minishell-8e40323db9715621d8ab45ff6d943c2eeba46ea0.tar.bz2
minishell-8e40323db9715621d8ab45ff6d943c2eeba46ea0.zip
Removing path hash table, replacing it by brute force searchpath
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/cmd.c13
-rw-r--r--src/eval/eval.c10
-rw-r--r--src/eval/exec.c39
-rw-r--r--src/eval/operation.c12
-rw-r--r--src/eval/parenthesis.c7
5 files changed, 40 insertions, 41 deletions
diff --git a/src/eval/cmd.c b/src/eval/cmd.c
index 455ff77..2f90378 100644
--- a/src/eval/cmd.c
+++ b/src/eval/cmd.c
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/14 10:41:31 by charles #+# #+# */
-/* Updated: 2020/09/14 17:18:05 by charles ### ########.fr */
+/* Updated: 2020/09/14 19:50:55 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -36,7 +36,7 @@ int wrapped_cmd(void *void_param)
}
}
-int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast, pid_t *child_pid)
+int eval_cmd(int fds[2], t_env env, t_ast *ast, pid_t *child_pid)
{
t_fork_param_cmd param;
char **argv;
@@ -54,13 +54,12 @@ int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast, pid_t *child_pid)
if (param.builtin == NULL)
{
- status = exec_search_path(path, env_search(env, "PATH"), argv[0], &param.exec_path);
- if (status != 0)
+
+ if (!path_search(env, argv[0], param.exec_path))
{
- if (status == 127)
- errorf("%s: command not found\n", argv[0]);
+ errorf("%s: command not found\n", argv[0]);
ft_split_destroy(argv);
- return (status);
+ return (127);
}
if ((status = exec_path_check(param.exec_path)) != 0)
return (status);
diff --git a/src/eval/eval.c b/src/eval/eval.c
index 351c870..ee5c009 100644
--- a/src/eval/eval.c
+++ b/src/eval/eval.c
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/13 20:38:06 by charles #+# #+# */
-/* Updated: 2020/09/14 16:49:31 by charles ### ########.fr */
+/* Updated: 2020/09/14 19:39:33 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -62,13 +62,13 @@ int fork_wrap(
** \return The last command status or EVAL_FATAL on error
*/
-int eval(int fds[2], t_env env, t_path path, t_ast *ast, pid_t *child_pid)
+int eval(int fds[2], t_env env, t_ast *ast, pid_t *child_pid)
{
if (ast->tag == AST_PARENT)
- return (eval_parenthesis(fds, env, path, ast));
+ return (eval_parenthesis(fds, env, ast));
if (ast->tag == AST_OP)
- return (eval_operation(fds, env, path, ast));
+ return (eval_operation(fds, env, ast));
if (ast->tag == AST_CMD)
- return (eval_cmd(fds, env, path, ast, child_pid));
+ return (eval_cmd(fds, env, ast, child_pid));
return (EVAL_FATAL);
}
diff --git a/src/eval/exec.c b/src/eval/exec.c
index e8e13e1..f733c34 100644
--- a/src/eval/exec.c
+++ b/src/eval/exec.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:06:11 by charles #+# #+# */
-/* Updated: 2020/09/14 17:20:50 by charles ### ########.fr */
+/* Updated: 2020/09/14 19:48:49 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,7 +31,6 @@ int exec_path_check(char *exec_path)
return (errorf_ret(127, "%s: %s\n", exec_path, strerror(errno)));
if (S_ISDIR(statbuf.st_mode))
return (errorf_ret(126, "%s: Is a directory\n", exec_path));
- //
if (!(statbuf.st_mode & 0444))
return (errorf_ret(126, "%s: %s\n", exec_path, strerror(EACCES)));
return (0);
@@ -45,20 +44,22 @@ int exec_path_check(char *exec_path)
** \return Executable path or NULL if not found or path update error
*/
-int exec_search_path(t_path path, char *path_var, char *exec_name, char **exec_path)
-{
- if (ft_strchr(exec_name, '/') != NULL) // TODO test recursive link
- {
- *exec_path = exec_name;
- return (0);
- }
- // TODO if PATH contain empty path, consider current directory files as cmd
- if ((*exec_path = ft_htget(path, exec_name)) == NULL)
- {
- if (path_update(path, path_var) == NULL) // optimise by not updating not changed path in ht
- return (EVAL_FATAL); // FIXME need to distiguish between malloc error and cmd not found error
- if ((*exec_path = ft_htget(path, exec_name)) == NULL)
- return (127);
- }
- return (0);
-}
+/* int exec_search_path(t_path path, char *path_var, char *exec_name, char **exec_path) */
+/* { */
+/* if (ft_strchr(exec_name, '/') != NULL) // TODO test recursive link */
+/* { */
+/* *exec_path = exec_name; */
+/* return (0); */
+/* } */
+/* if (path_var == NULL) */
+/* return (127); */
+/* // TODO if PATH contain empty path, consider current directory files as cmd */
+/* if ((*exec_path = ft_htget(path, exec_name)) == NULL) */
+/* { */
+/* if (path_update(path, path_var) == NULL) */
+/* return (EVAL_FATAL); */
+/* if ((*exec_path = ft_htget(path, exec_name)) == NULL) */
+/* return (127); */
+/* } */
+/* return (0); */
+/* } */
diff --git a/src/eval/operation.c b/src/eval/operation.c
index eaafcf8..8c80033 100644
--- a/src/eval/operation.c
+++ b/src/eval/operation.c
@@ -6,13 +6,13 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/17 15:27:22 by charles #+# #+# */
-/* Updated: 2020/09/13 20:38:26 by charles ### ########.fr */
+/* Updated: 2020/09/14 19:39:16 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "eval.h"
-int eval_operation(int fds[2], t_env env, t_path path, t_ast *ast)
+int eval_operation(int fds[2], t_env env, t_ast *ast)
{
int status;
int left_fds[2];
@@ -31,9 +31,9 @@ int eval_operation(int fds[2], t_env env, t_path path, t_ast *ast)
pid_t left_pid;
pid_t right_pid;
- eval(left_fds, env, path, ast->op.left, &left_pid);
+ eval(left_fds, env, ast->op.left, &left_pid);
close(p[FD_WRITE]);
- eval(right_fds, env, path, ast->op.right, &right_pid);
+ eval(right_fds, env, ast->op.right, &right_pid);
close(p[FD_READ]);
pid_t finished;
@@ -49,12 +49,12 @@ int eval_operation(int fds[2], t_env env, t_path path, t_ast *ast)
}
return (0);
}
- if ((status = eval(left_fds, env, path, ast->op.left, NULL)) == EVAL_FATAL)
+ if ((status = eval(left_fds, env, ast->op.left, NULL)) == EVAL_FATAL)
return (EVAL_FATAL);
g_last_status = status;
if ((ast->op.sep == TAG_AND && status != 0) ||
(ast->op.sep == TAG_PIPE && status != 0) ||
(ast->op.sep == TAG_OR && status == 0))
return (status);
- return (eval(right_fds, env, path, ast->op.right, NULL));
+ return (eval(right_fds, env, ast->op.right, NULL));
}
diff --git a/src/eval/parenthesis.c b/src/eval/parenthesis.c
index 8983378..610218b 100644
--- a/src/eval/parenthesis.c
+++ b/src/eval/parenthesis.c
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/13 20:38:29 by charles #+# #+# */
-/* Updated: 2020/09/13 20:40:19 by charles ### ########.fr */
+/* Updated: 2020/09/14 19:40:12 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,10 +17,10 @@ int wrapped_eval(void *void_param)
t_fork_param_args *param;
param = void_param;
- return (eval(param->fds, param->env, param->path, param->ast, NULL));
+ return (eval(param->fds, param->env, param->ast, NULL));
}
-int eval_parenthesis(int fds[2], t_env env, t_path path, t_ast *ast)
+int eval_parenthesis(int fds[2], t_env env, t_ast *ast)
{
int status;
t_fork_param_args param;
@@ -31,7 +31,6 @@ int eval_parenthesis(int fds[2], t_env env, t_path path, t_ast *ast)
param.fds[0] = fds[0];
param.fds[1] = fds[1];
param.env = env;
- param.path = path;
param.ast = ast->parent_ast;
return (fork_wrap(fds, &param, wrapped_eval, NULL));
}