-
Notifications
You must be signed in to change notification settings - Fork 0
/
minishell.c
93 lines (85 loc) · 2.46 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jrainpre <jrainpre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 08:06:40 by mkoller #+# #+# */
/* Updated: 2023/02/13 13:53:09 by jrainpre ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include <fcntl.h>
#include <readline/history.h>
#include <readline/readline.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
t_global g_global;
int main(int argc, char **argv, char **envp)
{
t_prompt struc;
t_env_list *env_lst;
(void)argc;
(void)argv;
(void)envp;
fill_env_lst(&env_lst, envp);
init_prompt(&struc, env_lst);
shell_level_plus_one(&struc);
minishell(&struc, env_lst);
return (0);
}
int read_line_take_input(t_env_list *env_lst,
t_input *input, t_prompt *struc)
{
run_signals(1);
input->str = readline(PROMPT);
if (!input->str)
{
clean_interrupt(env_lst, input, struc);
run_signals(3);
}
if (!ft_is_str_whitespace(input->str))
{
free(input->str);
input->str = NULL;
return (1);
}
input->str = prepare_input_string(input->str);
add_history(input->str);
ft_split_input(input);
return (0);
}
int process_intput(t_prompt *struc, t_env_list *env_lst,
t_input *input)
{
put_to_table(input->output, struc);
set_env_lst(env_lst, struc->cmds, struc);
include_env_struc(struc);
expand_tilde_struc(struc);
if (!get_all_fd_out(struc) || !get_all_fd_in(struc))
return (1);
delete_closed_quotes_struc(struc);
trim_nodes(struc);
struc->input = input;
return (0);
}
int minishell(t_prompt *struc, t_env_list *env_lst)
{
t_input input;
while (1)
{
if (read_line_take_input(env_lst, &input, struc))
continue ;
if (process_intput(struc, env_lst, &input))
{
clean_loop(struc, &input);
continue ;
}
executer(struc->cmds, struc);
check_exit_flag(struc, &input);
clean_loop(struc, &input);
}
}