1
0
mirror of https://github.com/KeyZox71/ft_minipowershell.git synced 2025-05-13 16:08:45 +02:00

」 feat: Added ctrl c to heredoc

This commit is contained in:
2024-07-13 14:16:31 +02:00
parent 310f26ef80
commit d7c5e9611b
18 changed files with 183 additions and 521 deletions

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
/* Updated: 2024/07/10 01:18:17 by adjoly ### ########.fr */
/* Updated: 2024/07/10 14:11:59 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 10:50:52 by mmoussou #+# #+# */
/* Updated: 2024/07/09 21:21:16 by adjoly ### ########.fr */
/* Updated: 2024/07/13 13:19:34 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,8 @@
char *format_quotes_string(char *cmd)
{
if (!cmd)
return (NULL);
if (*cmd == DOUBLE || *cmd == SINGLE)
ft_strlcpy(cmd, cmd + 1, ft_strlen(cmd) - 1);
return (cmd);
@ -23,7 +25,9 @@ int format_quotes_cmd(t_cmd *cmd, t_env *env)
{
uint i;
format_quotes_string(cmd->cmd);
if (!cmd)
return (-1);
cmd->cmd = format_quotes_string(cmd->cmd);
i = 0;
while (cmd->argv[i])
{
@ -40,7 +44,8 @@ int format_quotes(t_list *list_cmd, t_env *env)
return (0);
while (list_cmd)
{
format_quotes_cmd(list_cmd->content, env);
if (format_quotes_cmd(list_cmd->content, env))
return (-1);
list_cmd = list_cmd->next;
}
return (0);

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 09:19:39 by mmoussou #+# #+# */
/* Updated: 2024/07/10 01:14:41 by adjoly ### ########.fr */
/* Updated: 2024/07/13 14:02:22 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -73,11 +73,13 @@ static int get_input(char *delimiter, int fd)
void __forked(char *delimiter, int fd, t_cmd *cmd)
{
get_input(delimiter, fd);
signal(SIGINT, &__heredoc_sig);
free(cmd);
get_input(delimiter, fd);
ft_envclear(get_env(NULL), free);
ft_lstclear_till_nxt(get_list2(NULL), &free_cmd);
ft_lstclear(get_list(NULL), &free_token);
rl_clear_history();
close(fd);
}
@ -85,6 +87,7 @@ int __heredoc(char *delimiter, t_cmd *cmd)
{
int fork_pid;
int fd;
int heredoc_ret;
fd = fd_manager(0);
if (fd == -1)
@ -105,9 +108,8 @@ int __heredoc(char *delimiter, t_cmd *cmd)
exit(0);
}
else
waitpid(fork_pid, NULL, 0);
close(fd);
return (fd_manager(1));
waitpid(fork_pid, &heredoc_ret, 0);
return (check_error(heredoc_ret, fd));
}
int ft_heredoc(char *delimiter, t_cmd *cmd)

View File

@ -6,13 +6,14 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/10 01:14:10 by adjoly #+# #+# */
/* Updated: 2024/07/10 01:16:48 by adjoly ### ########.fr */
/* Updated: 2024/07/13 14:03:00 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
#include <fcntl.h>
#include "minishell.h"
int __open_fd_here(char *path, int mode)
{
@ -23,6 +24,7 @@ int __open_fd_here(char *path, int mode)
else
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644);
free(path);
get_fd_heredoc(fd);
return (fd);
}
@ -46,3 +48,27 @@ void ft_lstclear_till_nxt(t_list **lst, void (*del)(void *))
}
free(*lst);
}
int check_error(int heredoc_ret, int fd)
{
heredoc_ret = WEXITSTATUS(heredoc_ret);
if (heredoc_ret != 0)
{
close(fd);
get_exit_code(heredoc_ret);
return (-2);
}
close(fd);
return (fd_manager(1));
}
void __heredoc_sig(int code)
{
(void)code;
ft_envclear(get_env(NULL), free);
ft_lstclear_till_nxt(get_list2(NULL), &free_cmd);
ft_lstclear(get_list(NULL), &free_token);
close(get_fd_heredoc(-1));
rl_clear_history();
exit(130);
}