mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
pipeline parse: reject hanging pipe at end
This rejects commands such as echo hello | cat -e | I also updated the doc this time
This commit is contained in:
parent
8606774781
commit
4b403c4bf3
2 changed files with 28 additions and 9 deletions
|
|
@ -6,14 +6,17 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/24 14:36:43 by khais #+# #+# */
|
||||
/* Updated: 2025/02/24 15:53:04 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/28 13:13:38 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "pipeline_parse.h"
|
||||
#include "pipeline.h"
|
||||
#include "pipeline_parse_baseops.h"
|
||||
#include "../../ft_errno.h"
|
||||
#include "../matchers/pipe.h"
|
||||
#include "unistd.h"
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
|
|
@ -82,8 +85,11 @@ static void pipeline_delimit(t_pipeline_builder *builder)
|
|||
** - While there are still words remaining in the input stream
|
||||
** - If we have a pipe character
|
||||
** - Delimit the current command
|
||||
** - If there was an error
|
||||
** - Return NULL
|
||||
** - If there was an error
|
||||
** - Return NULL
|
||||
** - If we reached the end of input stream
|
||||
** - This means that there is a hanging pipe at the end of the pipeline.
|
||||
** Destroy the pipeline, set ft_errno, and return NULL.
|
||||
** - Push the current word to the accumulator for the next command
|
||||
** - Advance the state to the next word
|
||||
** - Since there is no pipe token at the end to delimit the last command,
|
||||
|
|
@ -92,9 +98,6 @@ static void pipeline_delimit(t_pipeline_builder *builder)
|
|||
** additional memory freeing is required.
|
||||
** in case of error in pipeline_delimit, it will call destroy, which will set
|
||||
** builder->pipeline to NULL
|
||||
**
|
||||
** Note: if there is a | token at the end of the input stream, the results are
|
||||
** undefined.
|
||||
*/
|
||||
t_pipeline *pipeline_parse_wordlist(t_pipeline_builder *builder)
|
||||
{
|
||||
|
|
@ -104,9 +107,17 @@ t_pipeline *pipeline_parse_wordlist(t_pipeline_builder *builder)
|
|||
while (!eof(builder))
|
||||
{
|
||||
if (current_is_pipe(builder))
|
||||
{
|
||||
pipeline_delimit(builder);
|
||||
if (builder->error)
|
||||
return (NULL);
|
||||
if (builder->error)
|
||||
return (NULL);
|
||||
if (eof(builder))
|
||||
{
|
||||
builder_destroy(builder);
|
||||
ft_errno(FT_EUNEXPECTED_PIPE);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
push_word(builder);
|
||||
next_word(builder);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue