fixes + norm
This commit is contained in:
60
srcs/main.c
60
srcs/main.c
@@ -3,30 +3,30 @@
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/27 14:16:52 by lderidde #+# #+# */
|
||||
/* Updated: 2025/02/11 13:22:49 by lderidde ### ########.fr */
|
||||
/* Updated: 2025/02/11 16:44:10 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/minishell.h"
|
||||
#include "../includes/minishell.h"
|
||||
#include <readline/history.h>
|
||||
#include <readline/readline.h>
|
||||
|
||||
int g_sig = 0;
|
||||
int g_sig = 0;
|
||||
|
||||
void handle_sigint(int sig)
|
||||
void handle_sigint(int sig)
|
||||
{
|
||||
(void)sig;
|
||||
g_sig = SIGINT;
|
||||
rl_replace_line("", 0);
|
||||
// rl_on_new_line();
|
||||
rl_done = 1;
|
||||
rl_done = 1;
|
||||
rl_redisplay();
|
||||
}
|
||||
|
||||
void handle_sigquit(int sig)
|
||||
void handle_sigquit(int sig)
|
||||
{
|
||||
(void)sig;
|
||||
// ft_printf("\b\b");
|
||||
@@ -48,23 +48,23 @@ static void add_prevhistory(t_msh *msh)
|
||||
}
|
||||
}
|
||||
|
||||
static void interpret_cmd(char **input, t_msh *msh)
|
||||
int interactive_mode(t_msh *msh)
|
||||
{
|
||||
msh->head = parser(*input, msh);
|
||||
if (!msh->head)
|
||||
msh->input = malloc(1);
|
||||
msh->input[0] = 0;
|
||||
while (!msh->input[0] || is_only_space(msh->input) || g_sig == SIGINT)
|
||||
{
|
||||
ft_free(input);
|
||||
return ;
|
||||
g_sig = 0;
|
||||
free(msh->input);
|
||||
msh->input = powerline(msh);
|
||||
if (!msh->input)
|
||||
return (0);
|
||||
}
|
||||
msh->here_fd = open(".heredoc", O_RDONLY);
|
||||
msh->ex_code = execute_command(msh->head);
|
||||
get_next_line(msh->here_fd, 1);
|
||||
if (msh->here_fd != -1)
|
||||
close(msh->here_fd);
|
||||
unlink(".heredoc");
|
||||
free_ast(msh->head);
|
||||
msh->head = NULL;
|
||||
ft_free(input);
|
||||
if (!msh->input)
|
||||
return (1);
|
||||
if (g_sig != SIGINT)
|
||||
interpret_cmd(&msh->input, msh);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int main(int ac, char **av, char **envp)
|
||||
@@ -79,22 +79,8 @@ int main(int ac, char **av, char **envp)
|
||||
if (ac == 1)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
msh->input = malloc (1);
|
||||
msh->input[0] = 0;
|
||||
while (!msh->input[0] || is_only_space(msh->input) || g_sig == SIGINT)
|
||||
{
|
||||
g_sig = 0;
|
||||
free(msh->input);
|
||||
msh->input = powerline(msh);
|
||||
if (!msh->input)
|
||||
break;
|
||||
}
|
||||
if (!msh->input)
|
||||
break;
|
||||
if (g_sig != SIGINT)
|
||||
interpret_cmd(&msh->input, msh);
|
||||
}
|
||||
if (!interactive_mode(msh))
|
||||
break ;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user