small fixes
This commit is contained in:
@@ -27,7 +27,10 @@ int exec_cd(char *path, t_ast_n *head)
|
|||||||
|
|
||||||
src = getcwd(NULL, 0);
|
src = getcwd(NULL, 0);
|
||||||
if (chdir(path) == -1)
|
if (chdir(path) == -1)
|
||||||
|
{
|
||||||
|
ft_free(&src);
|
||||||
return (err_msg_cmd("cd", path, strerror(errno), EXIT_FAILURE));
|
return (err_msg_cmd("cd", path, strerror(errno), EXIT_FAILURE));
|
||||||
|
}
|
||||||
dest = getcwd(NULL, 0);
|
dest = getcwd(NULL, 0);
|
||||||
pwd_update(head, src, dest);
|
pwd_update(head, src, dest);
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@@ -46,16 +46,6 @@ char *ft_getenv(char *str, char **envp)
|
|||||||
return (&envp[j][len]);
|
return (&envp[j][len]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int print_exit(char **arg, t_ast_n *node)
|
|
||||||
{
|
|
||||||
if (*arg && ft_strncmp(*arg, "$?", 2) == 0)
|
|
||||||
{
|
|
||||||
ft_fprintf(1, "%d", node->msh->ex_code);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void echo_print(t_ast_n *node, int j, char **envp)
|
static void echo_print(t_ast_n *node, int j, char **envp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -66,9 +56,6 @@ static void echo_print(t_ast_n *node, int j, char **envp)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (node->args[j][i])
|
while (node->args[j][i])
|
||||||
{
|
{
|
||||||
if (print_exit(&node->args[j], node))
|
|
||||||
i += 2;
|
|
||||||
else
|
|
||||||
ft_put_c(node->args[j][i++]);
|
ft_put_c(node->args[j][i++]);
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/12 10:00:08 by lderidde #+# #+# */
|
/* Created: 2025/02/12 10:00:08 by lderidde #+# #+# */
|
||||||
/* Updated: 2025/02/12 13:31:03 by lderidde ### ########.fr */
|
/* Updated: 2025/02/19 10:07:55 by lderidde ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -84,8 +84,8 @@ int exec(t_ast_n *node)
|
|||||||
if (execve(path, node->args, node->msh->env) == -1)
|
if (execve(path, node->args, node->msh->env) == -1)
|
||||||
{
|
{
|
||||||
free_child(node->msh);
|
free_child(node->msh);
|
||||||
|
ft_fprintf(2, "minishell: failed to execute %s\n", path);
|
||||||
ft_free(&path);
|
ft_free(&path);
|
||||||
perror("execve");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@@ -27,6 +27,23 @@ static char **ft_setnewenv(void)
|
|||||||
return (envp);
|
return (envp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_shellenv(t_msh *msh)
|
||||||
|
{
|
||||||
|
char *src;
|
||||||
|
char *tmp;
|
||||||
|
int sh;
|
||||||
|
|
||||||
|
src = getcwd(NULL, 0);
|
||||||
|
tmp = ft_strjoin(src, "/minishell");
|
||||||
|
set_var_env("SHELL", tmp, msh);
|
||||||
|
ft_free(&src);
|
||||||
|
ft_free(&tmp);
|
||||||
|
sh = ft_atoi(get_var_value("SHLVL", msh->env));
|
||||||
|
tmp = ft_itoa(sh + 1);
|
||||||
|
set_var_env("SHLVL", tmp, msh);
|
||||||
|
ft_free(&tmp);
|
||||||
|
}
|
||||||
|
|
||||||
t_msh *init_msh(char **envp)
|
t_msh *init_msh(char **envp)
|
||||||
{
|
{
|
||||||
t_msh *msh;
|
t_msh *msh;
|
||||||
@@ -46,6 +63,7 @@ t_msh *init_msh(char **envp)
|
|||||||
msh->env = ft_setnewenv();
|
msh->env = ft_setnewenv();
|
||||||
else
|
else
|
||||||
msh->env = init_env(envp);
|
msh->env = init_env(envp);
|
||||||
|
set_shellenv(msh);
|
||||||
return (msh);
|
return (msh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user