-
Notifications
You must be signed in to change notification settings - Fork 0
/
minishell.c
59 lines (54 loc) · 1.7 KB
/
minishell.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
54
55
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chanwoki <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/09 23:29:54 by dkham #+# #+# */
/* Updated: 2023/06/10 00:52:43 by chanwoki ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void parse_and_exe(t_shell *my_shell, char **env)
{
if (check_quotation(my_shell->line) && check_whitespace(my_shell->line))
{
parsing_start(my_shell->line, my_shell);
if (my_shell->error != 1)
execute(my_shell, env);
free_all(my_shell);
}
}
static void wrong_argc(void)
{
printf("Wrong ARGCS Error\n");
exit(1);
}
int main(int argc, char **argv, char **env)
{
t_shell my_shell;
if (argc != 1)
wrong_argc();
(void)argv;
init_shell(&my_shell, env);
while (1)
{
my_shell.line = readline("minishell $ ");
if (ft_strcmp("", my_shell.line) == 0)
{
free(my_shell.line);
continue ;
}
if (my_shell.line == NULL)
{
printf("exit\n");
free_env(my_shell.env);
return (0);
}
parse_and_exe(&my_shell, env);
add_history(my_shell.line);
free(my_shell.line);
}
return (0);
}