redirection parsing: add utility function for t_redirection

This commit is contained in:
Khaïs COLIN 2025-03-07 13:34:47 +01:00
parent cf517bb7f8
commit b0c34f36ef
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
3 changed files with 49 additions and 1 deletions

View file

@ -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)

View file

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirection.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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