mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
redirection parsing: add utility functions for t_redir_list
This commit is contained in:
parent
b0c34f36ef
commit
541bad80c0
3 changed files with 71 additions and 1 deletions
1
Makefile
1
Makefile
|
|
@ -51,6 +51,7 @@ srcs = \
|
||||||
src/parser/wordsplit/wordsplit.c \
|
src/parser/wordsplit/wordsplit.c \
|
||||||
src/parser/wordsplit/wordsplit_utils.c \
|
src/parser/wordsplit/wordsplit_utils.c \
|
||||||
src/postprocess/redirections/redirection.c \
|
src/postprocess/redirections/redirection.c \
|
||||||
|
src/postprocess/redirections/redirection_list.c \
|
||||||
src/postprocess/redirections/redirection_parsing.c \
|
src/postprocess/redirections/redirection_parsing.c \
|
||||||
|
|
||||||
objs = $(srcs:.c=.o)
|
objs = $(srcs:.c=.o)
|
||||||
|
|
|
||||||
67
src/postprocess/redirections/redirection_list.c
Normal file
67
src/postprocess/redirections/redirection_list.c
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redirection_list.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/07 14:29:53 by khais #+# #+# */
|
||||||
|
/* Updated: 2025/03/07 14:48:20 by khais ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "redirection_list.h"
|
||||||
|
#include "redirection.h"
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a new redir list item, with the given item
|
||||||
|
**
|
||||||
|
** may return null in case of allocation failure
|
||||||
|
*/
|
||||||
|
static t_redir_list *redir_list_create(t_redirection *item)
|
||||||
|
{
|
||||||
|
t_redir_list *out;
|
||||||
|
|
||||||
|
out = ft_calloc(1, sizeof(t_redir_list));
|
||||||
|
if (out == NULL)
|
||||||
|
return (NULL);
|
||||||
|
out->redirection = item;
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** free all memory associated with this redir list
|
||||||
|
*/
|
||||||
|
static void redir_list_destroy(t_redir_list *lst)
|
||||||
|
{
|
||||||
|
t_redir_list *prev;
|
||||||
|
|
||||||
|
while (lst != NULL)
|
||||||
|
{
|
||||||
|
redirection_destroy(lst->redirection);
|
||||||
|
prev = lst;
|
||||||
|
lst = lst->next;
|
||||||
|
free(prev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Add the given item to the end of the given list.
|
||||||
|
**
|
||||||
|
** If allocation fails, return null.
|
||||||
|
*/
|
||||||
|
t_redir_list *redir_list_push(t_redir_list *lst, t_redirection *item)
|
||||||
|
{
|
||||||
|
t_redir_list *start;
|
||||||
|
|
||||||
|
if (lst == NULL)
|
||||||
|
return (redir_list_create(item));
|
||||||
|
start = lst;
|
||||||
|
while (lst->next != NULL)
|
||||||
|
lst = lst->next;
|
||||||
|
lst->next = redir_list_create(item);
|
||||||
|
if (lst->next == NULL)
|
||||||
|
return (redir_list_destroy(start), NULL);
|
||||||
|
return (start);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/07 14:29:32 by khais #+# #+# */
|
/* Created: 2025/03/07 14:29:32 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/07 14:43:50 by khais ### ########.fr */
|
/* Updated: 2025/03/07 14:48:41 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,4 +21,6 @@ typedef struct s_redirection_list
|
||||||
struct s_redirection_list *next;
|
struct s_redirection_list *next;
|
||||||
} t_redir_list;
|
} t_redir_list;
|
||||||
|
|
||||||
|
t_redir_list *redir_list_push(t_redir_list *lst, t_redirection *item);
|
||||||
|
|
||||||
#endif // REDIRECTION_LIST_H
|
#endif // REDIRECTION_LIST_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue