-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminishell.c
executable file
·65 lines (61 loc) · 2.05 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mthiry <mthiry@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 09:38:28 by abuzdin #+# #+# */
/* Updated: 2022/08/11 14:24:48 by mthiry ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
// read from input, check whether it is correct or not; if correct,
// create tokens, simplify them, build commands and execute;
// then free what is not needed anymore and repeat;
// check for ctrl+c all the time
void prompt(t_input *data)
{
while (1)
{
if (signal(SIGINT, signal_main) == SIG_ERR
|| signal(SIGQUIT, SIG_IGN) == SIG_ERR)
error_check(-1, "", data);
data->buf = readline(data->prompt);
if (!data->buf)
yo_exit(data);
else if (is_right_buf(data->buf) != 1)
{
if (!check_closed(data, data->buf))
add_history(data->buf);
if (!check_field(data, data->buf))
{
data_init(data);
token_simplification(data);
if (!parsing(data))
execute(data);
ms_free_token(data->args);
ms_free_cmd(data->cmds);
}
}
free(data->buf);
}
}
// create welcome message; initialize envp variable
// create prompt's name and then call it
int main(int argc, char *argv[], char *envp[])
{
t_input data;
(void)argv;
if (argc != 1)
{
invalid_argv();
exit(EXIT_FAILURE);
}
welcome();
g_status = 0;
envp_init(&data, envp);
data.prompt = ms_strdup("YAMSP-1.6$ ", &data);
prompt(&data);
return ((g_status >> 8) & 0xff);
}