This commit is contained in:
2024-03-25 20:41:05 +01:00
parent 50dd393b36
commit c5b6f8f53e
4 changed files with 43 additions and 17 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */ /* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */
/* Updated: 2024/03/25 19:14:46 by tomoron ### ########.fr */ /* Updated: 2024/03/25 20:38:21 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -85,7 +85,6 @@ void get_here_doc_input(t_msh *msh, char *eof)
line = NULL; line = NULL;
signal(SIGINT, signal_handler_here_doc); signal(SIGINT, signal_handler_here_doc);
signal(SIGQUIT, signal_handler_here_doc);
while (1) while (1)
{ {
free(line); free(line);
@ -131,10 +130,10 @@ void handle_here_doc(t_msh *msh, char *eof)
else else
{ {
signal(SIGINT, signal_handler_command); signal(SIGINT, signal_handler_command);
signal(SIGQUIT, signal_handler_command); signal(SIGQUIT, signal_handler_here_doc);
waitpid(pid, &status , 0); waitpid(pid, &status , 0);
signal(SIGINT, signal_handler_interactive); signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive);
close(msh->in_fd); close(msh->in_fd);
if(WIFEXITED(status) && WEXITSTATUS(status)) if(WIFEXITED(status) && WEXITSTATUS(status))
unlink(here_doc_file); unlink(here_doc_file);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
/* Updated: 2024/03/25 13:19:26 by tomoron ### ########.fr */ /* Updated: 2024/03/25 20:04:03 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -71,8 +71,31 @@ t_env *get_env(char **envp)
return (env); return (env);
} }
void print_binary(unsigned int num)
{
if (num == 0) {
printf("0");
return;
}
// Taille d'un unsigned int en bits
int size = sizeof(unsigned int) * 8;
int i;
// Parcours de chaque bit de droite à gauche
for (i = size - 1; i >= 0; i--) {
// Vérifie si le bit est 1 ou 0
if (num & (1u << i))
printf("1");
else
printf("0");
}
}
int init_minishell(t_msh **msh, int argc, char **argv, char **envp) int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
{ {
struct termios t_p;
*msh = ft_calloc(1, sizeof(t_msh)); *msh = ft_calloc(1, sizeof(t_msh));
if (!*msh) if (!*msh)
ft_exit(*msh, 1); ft_exit(*msh, 1);
@ -81,6 +104,11 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
(*msh)->env = get_env(envp); (*msh)->env = get_env(envp);
signal(SIGINT, signal_handler_interactive); signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive);
if(tcgetattr(1, &t_p))
ft_printf_fd(2, "an error occured while setting the flags");
t_p.c_lflag = t_p.c_lflag & (~ECHOCTL);
if(tcsetattr(1, TCSANOW, &t_p))
ft_printf_fd(2, "an error occured while setting the flags");
return (0); return (0);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
/* Updated: 2024/03/25 18:42:00 by tomoron ### ########.fr */ /* Updated: 2024/03/25 19:37:11 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,6 +23,7 @@
# include <sys/stat.h> # include <sys/stat.h>
# include <signal.h> # include <signal.h>
# include <stdint.h> # include <stdint.h>
# include <termios.h>
typedef enum e_token_type typedef enum e_token_type
{ {

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */ /* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
/* Updated: 2024/03/25 19:10:39 by tomoron ### ########.fr */ /* Updated: 2024/03/25 20:39:21 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,19 +14,16 @@
void signal_handler_interactive(int signum) void signal_handler_interactive(int signum)
{ {
if (signum == 2) if (signum == SIGINT)
{ {
g_return_code = 130; g_return_code = 130;
ft_putstr_fd("\n", 1); printf("%s%s^C\n",rl_prompt, rl_line_buffer);
rl_replace_line("", 0); rl_replace_line("", 0);
rl_on_new_line(); rl_on_new_line();
rl_redisplay(); rl_redisplay();
} }
if (signum == 3) else if (signum == SIGQUIT)
{ printf("%s%s", rl_prompt, rl_line_buffer);
rl_redisplay();
ft_putstr_fd("filsdeup", 1);
}
} }
void *here_doc_variables(int write, int index, void *data) void *here_doc_variables(int write, int index, void *data)
@ -45,9 +42,9 @@ void signal_handler_here_doc(int signum)
t_msh *msh; t_msh *msh;
char *here_doc_file; char *here_doc_file;
if(signum == 2) if(signum == SIGINT)
{ {
write(1,"\n",1); printf("%s%s^C\n",rl_prompt, rl_line_buffer);
msh = here_doc_variables(0, 0, 0); msh = here_doc_variables(0, 0, 0);
here_doc_file = here_doc_variables(0, 1, 0); here_doc_file = here_doc_variables(0, 1, 0);
close(msh->in_fd); close(msh->in_fd);
@ -59,5 +56,6 @@ void signal_handler_here_doc(int signum)
void signal_handler_command(int signum) void signal_handler_command(int signum)
{ {
(void)signum; if(signum == SIGQUIT)
printf("^\\Quit (core dumped)\n");
} }