-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
94 lines (85 loc) · 2.17 KB
/
Copy pathmain.c
File metadata and controls
94 lines (85 loc) · 2.17 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
84
85
86
87
88
89
90
91
92
93
94
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: moabed <moabed@student.42amman.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/20 08:50:13 by moabed #+# #+# */
/* Updated: 2026/05/18 13:35:39 by moabed ### ########.fr */
/* */
/* ************************************************************************** */
#include "headers/executionpart.h"
#include "headers/parsingpart.h"
t_cmd *prepare_for_execution(char *input, t_env *env, int last_status)
{
t_token *tokens;
t_cmd *cmds;
tokens = tokenization(input);
if (!tokens)
return (NULL);
if (check_if_var(&tokens) == FAILURE)
{
tokenlistclear(&tokens);
return (NULL);
}
if (!expand_tokens(&tokens, env, last_status))
{
tokenlistclear(&tokens);
return (NULL);
}
cmds = parsing(tokens);
tokenlistclear(&tokens);
return (cmds);
}
int check_line(char *input)
{
int i;
int option;
option = 0;
i = 0;
while (input[i])
{
if (!((input[i] >= 9 && input[i] <= 13)))
option = 1;
i++;
}
return (option);
}
void main2(t_exec *shell)
{
char *input;
while (1)
{
interactive_signals();
input = readline("minishell> ");
if (g_sig != 0)
{
shell->last_status = g_sig;
g_sig = 0;
}
if (!input)
break ;
if (check_line(input))
add_history(input);
shell->cmds = prepare_for_execution(input, shell->first_env_node,
shell->last_status);
if (shell->cmds)
{
execution(shell);
free_cmds_list(&shell->cmds);
}
free(input);
}
}
int main(int ac, char **av, char **envp)
{
t_exec shell;
(void)ac;
(void)av;
if (shell_init(envp, &shell))
return (1);
main2(&shell);
ruin_everything(&shell);
return (shell.last_status);
}