aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristopher Uhlig2025-01-20 17:34:02 +0100
committerChristopher Uhlig2025-01-20 17:34:02 +0100
commit634a3b84b31cbcc5c0c665338e1ef1eb49f25e5d (patch)
treea30f4d0c47a636c822e97efc2678b61d3e2c3dad /src
parent8f5abcdb257393a2e576fe382835e8e060662834 (diff)
downloadminishell-634a3b84b31cbcc5c0c665338e1ef1eb49f25e5d.tar.gz
minishell-634a3b84b31cbcc5c0c665338e1ef1eb49f25e5d.zip
fixed a bunch of stuff
Diffstat (limited to 'src')
-rw-r--r--src/builtins_part_one.c17
-rw-r--r--src/builtins_part_three.c13
-rw-r--r--src/env.c4
-rw-r--r--src/execute_cmd.c4
-rw-r--r--src/handle_redir.c8
5 files changed, 32 insertions, 14 deletions
diff --git a/src/builtins_part_one.c b/src/builtins_part_one.c
index 7cbcdeb..629cc87 100644
--- a/src/builtins_part_one.c
+++ b/src/builtins_part_one.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */
-/* Updated: 2025/01/18 18:33:33 by chuhlig ### ########.fr */
+/* Updated: 2025/01/20 17:05:19 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,7 +26,15 @@ int unset(char **av, t_env **env)
prev = NULL;
while (current)
{
- if (ft_strcmp(current->name, av[i]) == 0)
+ if ((!ft_strcmp(current->name, av[i])) && (!ft_strcmp("?", av[1])))
+ {
+ if (prev)
+ prev->next = current->next;
+ else
+ *env = current->next;
+ free_env_node(current);
+ break ;
+ }
{
if (prev)
prev->next = current->next;
@@ -91,7 +99,7 @@ int is_valid_identifier(char *str)
return (1);
}
-int export(char **av, t_env **env)
+int export(char **av, t_env **env, int f)
{
char *equal_sign;
int i;
@@ -107,6 +115,7 @@ int export(char **av, t_env **env)
write(1, "Minishell $ export: not a valid identifier\n", 43);
if (equal_sign)
*equal_sign = '=';
+ f++;
continue ;
}
if (equal_sign)
@@ -115,5 +124,5 @@ int export(char **av, t_env **env)
export_export(av[i], env);
}
}
- return (0);
+ return (check_flag(f));
}
diff --git a/src/builtins_part_three.c b/src/builtins_part_three.c
index 7c73e95..5f6fa31 100644
--- a/src/builtins_part_three.c
+++ b/src/builtins_part_three.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/18 18:29:24 by chuhlig #+# #+# */
-/* Updated: 2025/01/18 18:34:29 by chuhlig ### ########.fr */
+/* Updated: 2025/01/20 17:08:17 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,8 +22,10 @@ int builtin_exit(char **av, t_env **env)
{
int exit_status;
- if (av[1])
+ if (av[1] && !av[2])
exit_status = ft_atoi(av[1]);
+ else if (av[2])
+ exit_status = 1;
else
exit_status = 0;
exit_shell(env, exit_status);
@@ -74,3 +76,10 @@ int echo(char **av)
write(1, "\n", 1);
return (0);
}
+
+int check_flag(int f)
+{
+ if (f)
+ return (1);
+ return (0);
+}
diff --git a/src/env.c b/src/env.c
index 1972909..cc9cfae 100644
--- a/src/env.c
+++ b/src/env.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 14:31:07 by chuhlig #+# #+# */
-/* Updated: 2025/01/14 14:44:34 by chuhlig ### ########.fr */
+/* Updated: 2025/01/20 15:05:49 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -55,7 +55,7 @@ char *env_get(t_env *env, char *name)
{
while (env != NULL)
{
- if (!ft_strncmp(env->name, name, ft_strlen(name)))
+ if (!ft_strncmp(env->name, name, ft_strlen(env->name)))
return (env->value);
env = env->next;
}
diff --git a/src/execute_cmd.c b/src/execute_cmd.c
index e2b9d66..4b84e12 100644
--- a/src/execute_cmd.c
+++ b/src/execute_cmd.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 19:21:35 by chuhlig #+# #+# */
-/* Updated: 2025/01/19 19:15:46 by chuhlig ### ########.fr */
+/* Updated: 2025/01/20 15:43:41 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,7 +28,7 @@ int is_builtin(char *cmd)
int execute_builtin(char **args, t_env **env)
{
if (ft_strcmp(args[0], "export") == 0)
- return (export(args, env));
+ return (export(args, env, ft_atoi("0")));
else if (ft_strcmp(args[0], "unset") == 0)
return (unset(args, env));
else if (ft_strcmp(args[0], "cd") == 0)
diff --git a/src/handle_redir.c b/src/handle_redir.c
index 29bba92..e8a1010 100644
--- a/src/handle_redir.c
+++ b/src/handle_redir.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/18 18:34:51 by chuhlig #+# #+# */
-/* Updated: 2025/01/18 18:47:31 by chuhlig ### ########.fr */
+/* Updated: 2025/01/20 14:59:38 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,7 +26,7 @@ int handle_input_redirection(t_redirection *redir)
}
else if (redir->type == INPUT_LIMITER)
{
- fd = open_file("/tmp/heredoc_tmp", O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ fd = open_file("/tmp/heredoc_tmp", O_WRONLY | O_TRUNC, 0644);
if (fd < 0)
return (-1);
write(fd, redir->specifier, ft_strlen(redir->specifier));
@@ -46,7 +46,7 @@ int handle_output_redirection(t_redirection *redir)
if (redir->type == OUTPUT_OVERRIDE)
{
- fd = open_file(redir->specifier, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ fd = open_file(redir->specifier, O_WRONLY | O_TRUNC, 0644);
if (fd < 0)
return (-1);
dup2(fd, STDOUT_FILENO);
@@ -54,7 +54,7 @@ int handle_output_redirection(t_redirection *redir)
}
else if (redir->type == OUTPUT_APPEND)
{
- fd = open_file(redir->specifier, O_WRONLY | O_CREAT | O_APPEND, 0644);
+ fd = open_file(redir->specifier, O_WRONLY | O_APPEND, 0644);
if (fd < 0)
return (-1);
dup2(fd, STDOUT_FILENO);