Skip to content

Commit

Permalink
adding pipe error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
qfeuilla committed Jul 19, 2020
1 parent d778c06 commit aff00f3
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion working/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SRCS= srcs/parsing/prompt_loop.c\
srcs/parsing/parsingUtils.c\
srcs/parsing/tokenLen.c\
srcs/parsing/tokenize.c\
srcs/parsing/tokens_syntax_check.c\
srcs/parsing/syntax_check.c\
srcs/commands/search_path.c\
srcs/token_expansion/get_env.c\
srcs/token_expansion/expand_tokens.c\
Expand Down
9 changes: 8 additions & 1 deletion working/srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/24 13:39:32 by frthierr #+# #+# */
/* Updated: 2020/07/19 02:11:46 by qfeuilla ### ########.fr */
/* Updated: 2020/07/19 18:11:47 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -24,6 +24,12 @@ void minishell_start()
ft_lstclear(&token_list, free);
ft_perror(ERR_UNFINISHED_QUOTE);
}
else if (!pipes_syntax_check(token_list) || pipe_error)
{
pipe_error = 0;
ft_lstclear(&token_list, free);
ft_perror(ERR_PIPE);
}
else
{
command_list = get_command_list(token_list);
Expand All @@ -39,6 +45,7 @@ void minishell_start()
int main(int argc, char **argv, char **env)
{
open_pipe = 0;
pipe_error = 0;
if (argc > 1 || argv[1])
{
ft_perror(ERR_TOO_MANY_ARGS);
Expand Down
15 changes: 10 additions & 5 deletions working/srcs/parsing/prompt_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/02 14:48:38 by frthierr #+# #+# */
/* Updated: 2020/07/19 02:22:53 by qfeuilla ### ########.fr */
/* Updated: 2020/07/19 18:15:41 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -65,12 +65,17 @@ t_list *prompt_loop(int depth)
return (NULL);
}
tokenList = tokenize(line);
if (!ft_strncmp(last_token(tokenList), "|", 2) || (depth >= 1 && !last_token(tokenList))) {
if ((!ft_strncmp(last_token(tokenList), "|", 2)) || (depth >= 1 && !last_token(tokenList))) {
if (depth == 0)
open_pipe = 1;
print_prompt();
tmp = prompt_loop(depth + 1);
ft_lstadd_back(&tokenList, tmp);
if (!ft_strncmp(last_token(tokenList), "|", 2) && ft_lstlen(tokenList) == 1)
pipe_error = 1;
else
{
print_prompt();
tmp = prompt_loop(depth + 1);
ft_lstadd_back(&tokenList, tmp);
}
if (depth == 0)
open_pipe = 0;
return (tokenList);
Expand Down
Binary file modified working/srcs/parsing/prompt_loop.o
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tokens_syntax_check.c :+: :+: :+: */
/* syntax_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/01 18:43:38 by frthierr #+# #+# */
/* Updated: 2020/07/18 19:02:59 by qfeuilla ### ########.fr */
/* Updated: 2020/07/19 18:04:34 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -45,3 +45,11 @@ int tokens_syntax_check(t_list *token_list)
}
return (1);
}

int pipes_syntax_check(t_list *token_list)
{
if (ft_lstlen(token_list) == 1 && !ft_strncmp(last_token(token_list), "|", 2))
return (0);
return (1);
}

Binary file added working/srcs/parsing/syntax_check.o
Binary file not shown.
Binary file removed working/srcs/parsing/tokens_syntax_check.o
Binary file not shown.

0 comments on commit aff00f3

Please sign in to comment.