pipeline: handle parsing of single-command pipelines

This commit is contained in:
Khaïs COLIN 2025-02-21 13:44:51 +01:00
parent 695596fde2
commit 256a8f5f9b
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
5 changed files with 138 additions and 0 deletions

View 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);
}

View 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