aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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.c2
5 files changed, 29 insertions, 11 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 ac0d5b1..ab43032 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/20 15:54:43 by dkaiser ### ########.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 03fa453..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/20 15:24:49 by dkaiser ### ########.fr */
+/* Updated: 2025/01/20 14:59:38 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */