-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
78 lines (70 loc) · 2 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: itulgar < [email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 17:25:29 by zayaz #+# #+# */
/* Updated: 2024/11/08 17:27:51 by itulgar ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static char *get_user_input(t_program *program)
{
char *tmp;
program->finish_check = 0;
g_global_signal = 0;
program->input = readline("minishell 🐥 ");
if (g_global_signal == 13)
{
program->status = 1;
g_global_signal = 0;
}
tmp = ft_strtrim(program->input, " ");
free(program->input);
program->input = tmp;
if (program->input)
add_history(program->input);
if (program->input == NULL)
exit(1);
return (tmp);
}
static void free_main_program(t_program *program, char *tmp)
{
free_parser_input(program);
free(tmp);
free(program->process);
}
static void run_minishell(t_program *program)
{
char *tmp;
while (1)
{
tmp = get_user_input(program);
if (!ft_parser(program, program->input))
{
free(tmp);
continue ;
}
zi_exec(program);
free_main_program(program, tmp);
}
}
int main(int argc, char **argv, char **envp)
{
t_program *program;
program = NULL;
(void)argv;
if (argc != 1)
{
error_message("Unvalid argument");
exit(0);
}
program = malloc(sizeof(t_program));
if (!program)
return (0);
ft_init_program(program, envp);
run_minishell(program);
free_program(program);
}