mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
pipeline: reject repetitions of '|' token
This commit is contained in:
parent
68e923c09e
commit
c9f8c5a4f9
4 changed files with 27 additions and 6 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 12:40:46 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 12:40:51 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/21 15:38:54 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -50,6 +50,7 @@ char *ft_strerror(t_errno errno)
|
|||
[FT_ESUCCESS] = "Success",
|
||||
[FT_EINVAL] = "Invalid argument",
|
||||
[FT_EBADID] = "Bad identifier",
|
||||
[FT_EUNEXPECTED_PIPE] = "minishell: syntax error near unexpected token `|'",
|
||||
};
|
||||
|
||||
if (errno >= 0 && errno < FT_EMAXERRNO)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 12:40:58 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 12:41:02 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/21 15:37:56 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ typedef enum e_errno
|
|||
FT_ESUCCESS = 0,
|
||||
FT_EINVAL,
|
||||
FT_EBADID,
|
||||
FT_EUNEXPECTED_PIPE,
|
||||
FT_EMAXERRNO,
|
||||
} t_errno;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 13:23:50 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 15:23:12 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/21 15:42:34 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "pipeline.h"
|
||||
#include "libft.h"
|
||||
#include "unistd.h"
|
||||
#include "../../ft_errno.h"
|
||||
#include "../matchers/pipe.h"
|
||||
|
||||
static int pipeline_count_cmds(t_wordlist *words)
|
||||
|
|
@ -53,9 +53,11 @@ static t_pipeline *pipeline_parse_wordlist(t_pipeline *pipeline,
|
|||
{
|
||||
pipeline->cmds[idx] = simple_cmd_from_wordlist(current_wordlist);
|
||||
if (pipeline->cmds[idx] == NULL)
|
||||
return (pipeline_destroy(pipeline), NULL);
|
||||
return (pipeline_destroy(pipeline), wordlist_destroy(words), NULL);
|
||||
current_wordlist = NULL;
|
||||
current_word = ignore_word(current_word, &words);
|
||||
if (is_pipe(current_word))
|
||||
return (pipeline_destroy(pipeline), wordlist_destroy(words), worddesc_destroy(current_word), ft_errno(FT_EUNEXPECTED_PIPE), NULL);
|
||||
idx++;
|
||||
}
|
||||
current_wordlist = wordlist_push(current_wordlist, current_word);
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 13:13:58 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 15:29:48 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/21 16:03:39 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../src/parser/pipeline/pipeline.h"
|
||||
#include "../src/parser/wordsplit/wordsplit.h"
|
||||
#include "../src/ft_errno.h"
|
||||
#include <assert.h>
|
||||
#include "ft_printf.h"
|
||||
#include "libft.h"
|
||||
|
|
@ -95,6 +96,20 @@ static void test_parse_pipeline_four_cmd(void)
|
|||
pipeline_destroy(pipeline);
|
||||
}
|
||||
|
||||
static void test_parse_pipeline_double_pipe_rejected(void)
|
||||
{
|
||||
ft_errno(FT_ESUCCESS);
|
||||
assert(parse_pipeline("echo hello | | tee output.txt") == NULL);
|
||||
assert(ft_errno_get() == FT_EUNEXPECTED_PIPE);
|
||||
}
|
||||
|
||||
static void test_parse_pipeline_triple_pipe_rejected(void)
|
||||
{
|
||||
ft_errno(FT_ESUCCESS);
|
||||
assert(parse_pipeline("echo hello | | | tee output.txt") == NULL);
|
||||
assert(ft_errno_get() == FT_EUNEXPECTED_PIPE);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_parse_empty_pipeline();
|
||||
|
|
@ -102,5 +117,7 @@ int main(void)
|
|||
test_parse_pipeline_two_cmd();
|
||||
test_parse_pipeline_three_cmd();
|
||||
test_parse_pipeline_four_cmd();
|
||||
test_parse_pipeline_double_pipe_rejected();
|
||||
test_parse_pipeline_triple_pipe_rejected();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue