+ fix error handle in redirections() + rename ft_free_cmd_arr() to free_pipeline() + "char **path" added to "struct t_all" + misc
84 lines
2.6 KiB
C
84 lines
2.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* shell_loop.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
|
/* Updated: 2021/11/16 03:52:37 by lperrey ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "minishell.h"
|
|
|
|
//static char **tokens_list_to_argv(t_token *t); // temp test
|
|
void sigint_handler(int signum); //tmp
|
|
void sigquit_aka_eof_handler(int signum); //tmp
|
|
|
|
void close_fd(t_cmd *cmd);
|
|
void execute_cmd(char **envp, t_cmd **cmd_arr);
|
|
|
|
void shell_loop(t_all *c)
|
|
{
|
|
char *line_input;
|
|
|
|
line_input = NULL;
|
|
while (1)
|
|
{
|
|
if (line_input)
|
|
free(line_input);
|
|
line_input = readline(c->prompt);
|
|
if (line_input && *line_input)
|
|
{
|
|
add_history(line_input);
|
|
// Lexing
|
|
c->token_list = input_to_tokens(line_input);
|
|
if (!c->token_list)
|
|
continue ;
|
|
// Parsing
|
|
c->cmd_arr = parsing(c->token_list);
|
|
ft_lstclear((t_list **)&c->token_list, free);
|
|
if (!c->cmd_arr)
|
|
continue ;
|
|
// Exec Pipeline
|
|
exec_cmd_line(c);
|
|
}
|
|
else if (!line_input)
|
|
write(1, "\n", 1);
|
|
}
|
|
}
|
|
|
|
void test_signal(t_all *c)
|
|
{
|
|
// TEMP
|
|
// A faire aprés être sortie du mode interactif
|
|
// - Ignorer tout les signaux
|
|
// - Remettre ori_termios
|
|
c->signal_behaviour.sa_handler = SIG_IGN;
|
|
sigaction(SIGINT, &c->signal_behaviour, NULL);
|
|
sigaction(SIGQUIT, &c->signal_behaviour, NULL);
|
|
tcsetattr(STDIN_FILENO, TCSANOW, &c->ori_termios);
|
|
if (!fork())
|
|
{
|
|
char *arg_test[3];
|
|
|
|
arg_test[0] = ft_strdup("sleep");
|
|
arg_test[1] = ft_strdup("3");
|
|
arg_test[2] = NULL;
|
|
sigaction(SIGQUIT, &c->ori_signal_behaviour, NULL);
|
|
sigaction(SIGINT, &c->ori_signal_behaviour, NULL);
|
|
execve("/bin/sleep", arg_test, c->envp);
|
|
}
|
|
else
|
|
{
|
|
int wait_test;
|
|
wait(&wait_test);
|
|
c->signal_behaviour.sa_handler = sigint_handler;
|
|
sigaction(SIGINT, &c->signal_behaviour, NULL);
|
|
c->signal_behaviour.sa_handler = SIG_IGN;
|
|
sigaction(SIGQUIT, &c->signal_behaviour, NULL);
|
|
tcsetattr(STDIN_FILENO, TCSANOW, &c->interactive_termios);
|
|
}
|
|
}
|