forked from xhelp00/minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminishell.c
89 lines (79 loc) · 2.1 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: phelebra <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/30 15:56:26 by x230 #+# #+# */
/* Updated: 2023/08/07 13:55:11 by phelebra ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#define LINE_SIZE 1024
#define PATH_SEP ":"
extern int g_status;
void process_line(char *line, char **environ, t_env *env)
{
char **ebloid;
t_parsed *head;
add_history(line);
ebloid = lexer(line, env);
if (ebloid != NULL)
{
head = fill_list(ebloid);
execute_commands(head, environ, env);
free_array(ebloid);
}
}
void shell_loop(t_env *env)
{
char *line;
extern char **environ;
int save_fd;
g_status = 0;
signal(SIGINT, sigint_handler);
signal(SIGQUIT, SIG_IGN);
while (1)
{
save_fd = dup(STDIN_FILENO);
line = readline("\033[31;5m⛧ minihell ⛧\033[0m > ");
if (!line)
{
close(save_fd);
break ;
}
if (*line)
process_line(line, environ, env);
free(line);
dup2(save_fd, STDIN_FILENO);
close(save_fd);
}
}
void sigint_handler(int sig)
{
if (sig == SIGINT)
{
rl_replace_line("", 0);
rl_on_new_line();
printf("\n");
rl_redisplay();
}
}
void execute_commands(t_parsed *head, char **envp, t_env *env)
{
t_parsed *current;
t_parsed *next;
current = head;
while (current != NULL)
{
next = current->next;
if (current->op == PIPE)
pipex2(current, envp, env);
else
execute(current, envp, env);
free(current->args);
free(current);
current = next;
}
}