mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
pipeline: handle parsing of single-command pipelines
This commit is contained in:
parent
695596fde2
commit
256a8f5f9b
5 changed files with 138 additions and 0 deletions
47
src/parser/pipeline/pipeline.c
Normal file
47
src/parser/pipeline/pipeline.c
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pipeline.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 13:23:50 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 13:45:12 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "pipeline.h"
|
||||
#include "libft.h"
|
||||
|
||||
t_pipeline *pipeline_from_wordlist(t_wordlist *words)
|
||||
{
|
||||
t_pipeline *pipeline;
|
||||
|
||||
if (words == NULL)
|
||||
return (NULL);
|
||||
pipeline = ft_calloc(1, sizeof(t_pipeline));
|
||||
if (pipeline == NULL)
|
||||
return (NULL);
|
||||
pipeline->num_cmd = 1;
|
||||
pipeline->cmds = ft_calloc(1, sizeof(t_simple_cmd *));
|
||||
if (pipeline->cmds == NULL)
|
||||
return (NULL);
|
||||
pipeline->cmds[0] = simple_cmd_from_wordlist(words);
|
||||
return (pipeline);
|
||||
}
|
||||
|
||||
void pipeline_destroy(t_pipeline *pipeline)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (pipeline == NULL)
|
||||
return ;
|
||||
i = 0;
|
||||
while (i < pipeline->num_cmd)
|
||||
{
|
||||
simple_cmd_destroy(pipeline->cmds[i]);
|
||||
i++;
|
||||
}
|
||||
free(pipeline->cmds);
|
||||
free(pipeline);
|
||||
}
|
||||
27
src/parser/pipeline/pipeline.h
Normal file
27
src/parser/pipeline/pipeline.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pipeline.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 13:19:51 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 13:27:50 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PIPELINE_H
|
||||
# define PIPELINE_H
|
||||
|
||||
# include "../simple_cmd/simple_cmd.h"
|
||||
|
||||
typedef struct s_pipeline
|
||||
{
|
||||
t_simple_cmd **cmds;
|
||||
int num_cmd;
|
||||
} t_pipeline;
|
||||
|
||||
t_pipeline *pipeline_from_wordlist(t_wordlist *words);
|
||||
void pipeline_destroy(t_pipeline *pipeline);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue