From b0c34f36efb9c8f2dbf2286c9c17c97e2af324d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Fri, 7 Mar 2025 13:34:47 +0100 Subject: [PATCH] redirection parsing: add utility function for t_redirection --- Makefile | 1 + src/postprocess/redirections/redirection.c | 43 ++++++++++++++++++++++ src/postprocess/redirections/redirection.h | 6 ++- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/postprocess/redirections/redirection.c diff --git a/Makefile b/Makefile index 3798aa8..b0ba41d 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,7 @@ srcs = \ src/parser/wordsplit/tokenizing_6_10.c \ src/parser/wordsplit/wordsplit.c \ src/parser/wordsplit/wordsplit_utils.c \ + src/postprocess/redirections/redirection.c \ src/postprocess/redirections/redirection_parsing.c \ objs = $(srcs:.c=.o) diff --git a/src/postprocess/redirections/redirection.c b/src/postprocess/redirections/redirection.c new file mode 100644 index 0000000..7a5771e --- /dev/null +++ b/src/postprocess/redirections/redirection.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* redirection.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/07 14:26:26 by khais #+# #+# */ +/* Updated: 2025/03/07 14:34:28 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "redirection.h" +#include "libft.h" + +/* +** create a new redirection, with the given data +** +** In case of allocation error, marker is not freed +*/ +t_redirection *redirection_create(t_redir_type type, + t_worddesc *marker) +{ + t_redirection *outvalue; + + outvalue = ft_calloc(1, sizeof(t_redirection)); + if (outvalue == NULL) + return (NULL); + outvalue->marker = marker; + outvalue->type = type; + return (outvalue); +} + +/* +** free all the memory associated with the given redirection +*/ +void redirection_destroy(t_redirection *redirection) +{ + if (redirection == NULL) + return ; + worddesc_destroy(redirection->marker); + free(redirection); +} diff --git a/src/postprocess/redirections/redirection.h b/src/postprocess/redirections/redirection.h index 8a9bfa6..fea537a 100644 --- a/src/postprocess/redirections/redirection.h +++ b/src/postprocess/redirections/redirection.h @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/07 14:26:06 by khais #+# #+# */ -/* Updated: 2025/03/07 14:44:12 by khais ### ########.fr */ +/* Updated: 2025/03/07 14:49:24 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,4 +25,8 @@ typedef struct s_redirection t_worddesc *marker; } t_redirection; +t_redirection *redirection_create(t_redir_type type, + t_worddesc *marker); +void redirection_destroy(t_redirection *redirection); + #endif // REDIRECTION_BASICS_H