-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
83 lines (75 loc) · 2.04 KB
/
main.c
File metadata and controls
83 lines (75 loc) · 2.04 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ochouati <ochouati@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 20:58:15 by ochouati #+# #+# */
/* Updated: 2024/08/05 19:38:46 by ochouati ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void export___(t_data *data, char *str)
{
char **split;
split = ft_split(str, ' ');
if (!split || !split[0])
return ;
if (split[0] && !split[1])
{
ft_export_no_args(data->env);
ft_free_strs(split);
return ;
}
ft_export(&data->env, split[1]);
ft_free_strs(split);
}
void handle_sigint(int sig)
{
if (sig == SIGINT)
{
g_status = 1;
ft_printf("\n");
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}
}
static int minishell(t_data *data)
{
char *line;
char *trimmed_line;
while (1)
{
line = readline(M_NAME);
if (!line)
return (data_cleanup(&data, true), exit(g_status), 0);
trimmed_line = ft_strtrim(line, " \t\n\v\f\r");
free(line);
if (!ft_strlen(trimmed_line))
{
free(trimmed_line);
continue ;
}
add_history(trimmed_line);
if (parsing(data, trimmed_line))
exec_handler(data);
free(trimmed_line);
data_cleanup(&data, false);
}
}
int main(int ac, char **av, char **env)
{
t_data *data;
(void)ac;
(void)av;
signal(SIGINT, handle_sigint);
signal(SIGQUIT, SIG_IGN);
data = ft_calloc(1, sizeof(t_data));
if (!data)
return (1);
data->env = dup_env(env);
minishell(data);
return (0);
}