diff --git a/src/ft_errno.c b/src/ft_errno.c index 0f7317b..2242832 100644 --- a/src/ft_errno.c +++ b/src/ft_errno.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_errno.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: khais +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/21 12:40:46 by khais #+# #+# */ -/* Updated: 2025/04/17 11:39:56 by khais ### ########.fr */ +/* Updated: 2025/04/24 16:49:17 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,7 +56,10 @@ char *ft_strerror(t_errno errno) [FT_ENOMEM] = "Cannot allocate memory", [FT_STATFAIL] = "minishell: stat: internal failure", [FT_ISDIR] = "Is a directory", - [FT_EHEREDOC_FAILED] = "Failed to aquire here-document", + [FT_EHEREDOC_FAILED] = "Failed to acquire here-document", + [FT_EUNCLOSED_DBLE_QUOTE] + = "unexpected EOF while looking for matching `\"'", + [FT_EUNCLOSED_SMPL_QUOTE] = "unexpected EOF while looking for matching `''", }; if (errno >= 0 && errno < FT_EMAXERRNO) diff --git a/src/ft_errno.h b/src/ft_errno.h index 25acfef..f319a01 100644 --- a/src/ft_errno.h +++ b/src/ft_errno.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_errno.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: khais +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/17 11:40/12 by khais #+# #+# */ -/* Updated: 2025/04/17 11:40:12 by khais ### ########.fr */ +/* Created: 2025/04/17 11:40:12 by khais #+# #+# */ +/* Updated: 2025/04/24 16:45:56 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,8 @@ typedef enum e_errno FT_STATFAIL, FT_ISDIR, FT_EHEREDOC_FAILED, + FT_EUNCLOSED_DBLE_QUOTE, + FT_EUNCLOSED_SMPL_QUOTE, FT_EMAXERRNO, } t_errno; diff --git a/src/parser/cmd_parsing.c b/src/parser/cmd_parsing.c index 204e077..6d324f9 100644 --- a/src/parser/cmd_parsing.c +++ b/src/parser/cmd_parsing.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* cmd_parsing.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: khais +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */ -/* Updated: 2025/04/17 11:55:27 by khais ### ########.fr */ +/* Updated: 2025/04/24 16:39:14 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,6 +40,16 @@ static void parse_error_newline(t_minishell *app) worddesc_destroy(token); } +static t_cmd *expecting_quote_error(t_minishell *app) +{ + if (ft_errno_get() != FT_ESUCCESS) + { + app->last_return_value = 2; + ft_perror("minishell"); + } + return (NULL); +} + /* ** TODO check if we need to differentiate the cause of a NULL return. */ @@ -53,7 +63,7 @@ t_cmd *minishell_parse(t_minishell *app, char *command_line) return (NULL); tokens = minishell_wordsplit(command_line); if (!tokens) - return (NULL); + return (expecting_quote_error(app)); root_cmd = minishell_cmds_parse(app, &tokens); if (root_cmd == NULL && ft_errno_get() != FT_ESUCCESS) { diff --git a/src/parser/wordsplit/wordsplit.c b/src/parser/wordsplit/wordsplit.c index 36d5a19..99b59c3 100644 --- a/src/parser/wordsplit/wordsplit.c +++ b/src/parser/wordsplit/wordsplit.c @@ -3,16 +3,25 @@ /* ::: :::::::: */ /* wordsplit.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: khais +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/21 12:29:36 by khais #+# #+# */ -/* Updated: 2025/02/21 12:42:46 by khais ### ########.fr */ +/* Updated: 2025/04/24 16:48:19 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ +#include "../../ft_errno.h" #include "wordsplit.h" #include "libft.h" +static void set_quote_error(char quote) +{ + if (quote == '"') + ft_errno(FT_EUNCLOSED_DBLE_QUOTE); + else if (quote == '\'') + ft_errno(FT_EUNCLOSED_SMPL_QUOTE); +} + /* ** split a string into words, respecting quotes etc. ** @@ -47,6 +56,7 @@ t_wordlist *minishell_wordsplit(char *original) rule_new_word(&token_build, original); } if (token_build.quote != '\0') - return (wordlist_destroy(token_build.wordlist), NULL); + return (wordlist_destroy(token_build.wordlist), + set_quote_error(token_build.quote), NULL); return (token_build.wordlist); } diff --git a/test.sh b/test.sh index e7708ef..ce79110 100755 --- a/test.sh +++ b/test.sh @@ -977,4 +977,37 @@ minishell: /root/outfile: Permission denied 1 EOF +when_run <<"EOF" "print error when unclosed quotes" +echo " kjlhgsaf +echo $? +echo ' HGIFUY +echo $? +echo '"HGIFUY" +echo $? +echo '"HGIFUY +echo $? +echo "'HGIFUY +echo $? +echo "' HGI'FUY +echo $? +echo boubou +echo $? +EOF +expecting <<"EOF" +minishell: unexpected EOF while looking for matching `"' +2 +minishell: unexpected EOF while looking for matching `'' +2 +minishell: unexpected EOF while looking for matching `'' +2 +minishell: unexpected EOF while looking for matching `'' +2 +minishell: unexpected EOF while looking for matching `"' +2 +minishell: unexpected EOF while looking for matching `"' +2 +boubou +0 +EOF + finalize