|
|
@ -6,16 +6,59 @@ |
|
|
|
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ |
|
|
|
/* +#+#+#+#+#+ +#+ */ |
|
|
|
/* Created: 2022/05/02 12:14:09 by narnaud #+# #+# */ |
|
|
|
/* Updated: 2022/05/06 11:23:19 by narnaud ### ########.fr */ |
|
|
|
/* Updated: 2022/05/06 12:03:13 by narnaud ### ########.fr */ |
|
|
|
/* */ |
|
|
|
/* ************************************************************************** */ |
|
|
|
|
|
|
|
# include "minishell.h" |
|
|
|
int main(int argc, char **argv, char **envp) |
|
|
|
|
|
|
|
void termios(int ctl) |
|
|
|
{ |
|
|
|
struct termios termios_p; |
|
|
|
int tty; |
|
|
|
|
|
|
|
tty = ttyslot(); |
|
|
|
if (tcgetattr(tty, &termios_p) < 0) |
|
|
|
exit ((perror("stdin"), EXIT_FAILURE)); |
|
|
|
if (ctl) |
|
|
|
{ |
|
|
|
termios_p.c_lflag |= ECHOCTL; |
|
|
|
signal(SIGINT, nothing); |
|
|
|
signal(SIGQUIT, nothing); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
termios_p.c_lflag &= ~(ECHOCTL); |
|
|
|
signal(SIGINT, sigs_handler); |
|
|
|
signal(SIGQUIT, sigs_handler); |
|
|
|
} |
|
|
|
termios_p.c_cc[VQUIT] = ctl * 28; |
|
|
|
tcsetattr(tty, TCSANOW, &termios_p); |
|
|
|
} |
|
|
|
|
|
|
|
void prompt(t_datas *datas) |
|
|
|
{ |
|
|
|
char *line; |
|
|
|
t_command *cmd; |
|
|
|
|
|
|
|
termios(0); |
|
|
|
line = readline("$ "); |
|
|
|
termios(1); |
|
|
|
if (line == NULL) |
|
|
|
halt(EXIT_FAILURE); |
|
|
|
if (is_empty(line)) |
|
|
|
return ; |
|
|
|
cmd = parser(datas, lexer(datas, line), NULL); |
|
|
|
if (!cmd->prev && !cmd->next && is_builtin(cmd->argv[0])) |
|
|
|
builtin_call(datas, cmd); |
|
|
|
else |
|
|
|
piper(datas, cmd); |
|
|
|
add_history(line); |
|
|
|
} |
|
|
|
|
|
|
|
int main(int argc, char **argv, char **envp) |
|
|
|
{ |
|
|
|
t_datas datas; |
|
|
|
char *line; |
|
|
|
int i; |
|
|
|
|
|
|
|
i = 0; |
|
|
@ -26,21 +69,7 @@ int main(int argc, char **argv, char **envp) |
|
|
|
if (argc < 2) |
|
|
|
(void)argv; |
|
|
|
while (1) |
|
|
|
{ |
|
|
|
termios(0); |
|
|
|
line = readline("$ "); |
|
|
|
termios(1); |
|
|
|
if (line == NULL) |
|
|
|
halt(EXIT_FAILURE); |
|
|
|
if (is_empty(line)) |
|
|
|
continue ; |
|
|
|
cmd = parser(&datas, lexer(&datas, line), NULL); |
|
|
|
if (!cmd->prev && !cmd->next && is_builtin(cmd->argv[0])) |
|
|
|
builtin_call(&datas, cmd); |
|
|
|
else |
|
|
|
piper(&datas, cmd); |
|
|
|
add_history(line); |
|
|
|
} |
|
|
|
prompt(&datas); |
|
|
|
clear_history(); |
|
|
|
return (EXIT_SUCCESS); |
|
|
|
} |
|
|
|