-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
70 lines (64 loc) · 1.67 KB
/
Copy pathmain.c
File metadata and controls
70 lines (64 loc) · 1.67 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: agunes <agunes@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/02 16:33:50 by agunes #+# #+# */
/* Updated: 2022/08/27 12:44:46 by agunes ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void prompt(void)
{
g_shell->prompt = ft_prompt();
g_shell->command = readline(g_shell->prompt);
free(g_shell->prompt);
}
int is_valid(char *arr)
{
int i;
i = -1;
while (arr[++i])
{
if (ft_isprint(arr[i]))
return (1);
}
return (0);
}
void start(void)
{
ft_signal();
prompt();
if (g_shell->command != NULL)
{
if (is_valid(g_shell->command))
{
add_history(g_shell->command);
ft_free();
parser();
dolar();
if (g_shell->commandlist[0])
runcommand(g_shell->commandlist[0]);
free(g_shell->command);
}
else
free(g_shell->command);
}
else
{
printf("exit\n");
exit(0);
}
}
int main(int argc, char **argv, char **env)
{
(void)argc;
(void)argv;
g_shell = ft_calloc(sizeof(t_shell), 1);
exportenvcpy(env);
while (1)
start();
return (0);
}