From de23176011fa4b78a5770ffb10688416342dabb4 Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 21 Jun 2024 12:44:51 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=E2=9C=A8=E3=80=8D=20feat:=20Check=20f?= =?UTF-8?q?or=20unclosed=20quote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/parsing.h | 3 +- src/parsing/check_error/check_quote.c | 48 +++++++++++++++++++++++++++ src/parsing/is_inquote.c | 2 +- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/parsing/check_error/check_quote.c diff --git a/include/parsing.h b/include/parsing.h index 4b0d799..e9bf5a0 100644 --- a/include/parsing.h +++ b/include/parsing.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */ -/* Updated: 2024/06/18 12:58:53 by adjoly ### ########.fr */ +/* Updated: 2024/06/21 12:41:11 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,6 +42,7 @@ char **split_argv(char *readline); char *env_var_replace(char *readline, t_env *env); size_t get_size_with_env(char *readline, t_env *env); size_t strlen_till_char(char *s, int c); +void check_quote(char *readline); /** * @brief Take the argv of a command a split the argv and the * command it self diff --git a/src/parsing/check_error/check_quote.c b/src/parsing/check_error/check_quote.c new file mode 100644 index 0000000..91d098a --- /dev/null +++ b/src/parsing/check_error/check_quote.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* check_quote.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/21 11:59:34 by adjoly #+# #+# */ +/* Updated: 2024/06/21 12:40:56 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parsing.h" +#include "tokenizer.h" + +size_t count_quote(char *readline, t_quote type) +{ + char *tmp; + size_t count; + + tmp = readline; + count = 0; + while (*tmp) + { + if (*tmp == type) + count++; + tmp++; + } + return (count); +} + +void check_quote(char *readline) +{ + size_t count; + + count = count_quote(readline, DOUBLE); + if (count % 2) + { + ft_putendl_fd("double quote error", STDERR_FILENO); + exit (EXIT_FAILURE); + } + count = count_quote(readline, SINGLE); + if (count % 2) + { + ft_putendl_fd("single quote error", STDERR_FILENO); + exit (EXIT_FAILURE); + } +} diff --git a/src/parsing/is_inquote.c b/src/parsing/is_inquote.c index 8c246bd..ffe3255 100644 --- a/src/parsing/is_inquote.c +++ b/src/parsing/is_inquote.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/20 20:06:13 by adjoly #+# #+# */ -/* Updated: 2024/06/20 14:35:26 by adjoly ### ########.fr */ +/* Updated: 2024/06/20 17:41:33 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */