diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-19 13:31:08 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-19 13:31:08 +0200 |
| commit | 35434a76eaab34e4d639f5bd0a3b7ba610001c5e (patch) | |
| tree | cf30a93445da19b38392c0c5e8303038164de906 /src/parse/parse_error.c | |
| parent | a2ebd4ad078d7056a4c28ea697cfd3ebbf09d0f6 (diff) | |
| parent | c8091831c4ce1c4cf8703b18de22441aff191f44 (diff) | |
| download | minishell-35434a76eaab34e4d639f5bd0a3b7ba610001c5e.tar.gz minishell-35434a76eaab34e4d639f5bd0a3b7ba610001c5e.tar.bz2 minishell-35434a76eaab34e4d639f5bd0a3b7ba610001c5e.zip | |
Merge branch 'parse_cmd'
Diffstat (limited to 'src/parse/parse_error.c')
| -rw-r--r-- | src/parse/parse_error.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/parse/parse_error.c b/src/parse/parse_error.c new file mode 100644 index 0000000..b721c28 --- /dev/null +++ b/src/parse/parse_error.c @@ -0,0 +1,106 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_error.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/06/18 15:09:48 by nahaddac #+# #+# */ +/* Updated: 2020/06/19 12:46:56 by nahaddac ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser.h" + +t_token *error_syntax_parent(t_ftlst *in) +{ + int op; + int cl; + t_token *tk; + + op = 0; + cl = 0; + while(in != NULL) + { + tk = in->data; + if (tk->tag & TAG_PARENT_OPEN) + op++; + if(tk->tag & TAG_PARENT_CLOSE) + cl++; + if (cl && op == 0) + { + tk->content = ft_strjoin3( + "minishell: syntax error near unexpected token `", + tk->content, "'"); + return tk; + } + in = in->next; + } + return NULL; +} + +int out_error_first(t_token *tk) +{ + int i; + + i = 0; + if(tk->tag & TAG_IS_SEP) + return(1); + if (tk->tag & TAG_IS_REDIR) + { + while(tk->content[i]) + i++; + if (tk->tag & TAG_REDIR_APPEND && i <= 2) + return (0); + else + return(1); + } + return(0); +} + +t_token *error_syntax_simple(t_ftlst *in) +{ + t_token *tk; + size_t i; + t_ftlst *first; + + tk = in->data; + first = in; + if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR)) + { + if (out_error_first(tk)) + { + i = ft_strlen(tk->content); + if (i >= 2) + tk->content[2] = '\0'; + tk->content = + ft_strjoin3("minishell: syntax error near unexpected token `", + tk->content, "'"); + return(tk); + } + } + while(in != NULL) + { + i = 0; + tk = in->data; + if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR)) + { + if (((t_token *)in->next->data)->tag & + ((t_token*)in->next->data)->tag & TAG_IS_SEP || + (((t_token*)in->next->data)->tag & TAG_IS_REDIR)) + { + tk = in->next->data; + i = ft_strlen(tk->content); + if (i >= 3) + tk->content[3] = '\0'; + tk->content = + ft_strjoin3("minishell: syntax error near unexpected token `", + tk->content, "'"); + return(tk); + } + } + in = in->next; + } + return error_syntax_parent(first); + +} |
