-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtins.c
53 lines (50 loc) · 1.96 KB
/
builtins.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtins.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: burkaya <burkaya@student.42istanbul.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/01 02:43:20 by egumus #+# #+# */
/* Updated: 2024/03/30 09:16:04 by burkaya ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_is_builtin(char *value)
{
if (ft_strcmp(value, "echo") == 0)
return (1);
if (ft_strcmp(value, "cd") == 0)
return (1);
if (ft_strcmp(value, "pwd") == 0)
return (1);
if (ft_strcmp(value, "export") == 0)
return (1);
if (ft_strcmp(value, "unset") == 0)
return (1);
if (ft_strcmp(value, "env") == 0)
return (1);
if (ft_strcmp(value, "exit") == 0)
return (1);
return (SUCCESS);
}
int ft_execute_builtin(t_state *s, t_exec *exec)
{
if (s->cmd_amount == 1 && ft_dup_redictions(exec, s))
return (1);
if (ft_strcmp(exec->cmd_args[0], "echo") == 0)
return (ft_echo(exec));
else if (ft_strcmp(exec->cmd_args[0], "cd") == 0)
return (ft_cd(exec, s));
else if (ft_strcmp(exec->cmd_args[0], "pwd") == 0)
return (ft_pwd(s));
else if (ft_strcmp(exec->cmd_args[0], "export") == 0)
return (ft_export(exec, s));
else if (ft_strcmp(exec->cmd_args[0], "unset") == 0)
return (ft_unset(exec, s));
else if (ft_strcmp(exec->cmd_args[0], "env") == 0)
return (ft_env(s));
else if (ft_strcmp(exec->cmd_args[0], "exit") == 0)
return (ft_exit(exec, s));
return (127);
}