diff --git a/.vscode/settings.json b/.vscode/settings.json index ab25e7a..ab16a65 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "sstream": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index d00eafa..3b3c1c0 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ LIBFT = lib/libft.a CC = gcc +# CFLAGS = -fsanitize=address CFLAGS = -Werror -Wall -Wextra -g -I $(HEADER) -fsanitize=address SRCS = $(wildcard ./srcs/*.c) diff --git a/include/minishell.h b/include/minishell.h index d90828c..7bd5dd0 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -198,10 +198,10 @@ char **line_to_matrix(char *line); //parse2.c void ft_do_quote(char **output, char c); +void ft_do_pipe(char **output); int readline_check(char **p2line); //parse_clean.c -//for late to remove quotes- but we will do this at the very end char *parse_clean(char **p2str); //parse_envp.c diff --git a/lib/libft.a b/lib/libft.a index ac02f7c..5a7e96c 100644 Binary files a/lib/libft.a and b/lib/libft.a differ diff --git "a/lol.c\342\200\235" "b/lol.c\342\200\235" new file mode 100644 index 0000000..f686800 --- /dev/null +++ "b/lol.c\342\200\235" @@ -0,0 +1 @@ +“cat lol.c diff --git a/minishell b/minishell index 8897fbc..7b97132 100755 Binary files a/minishell and b/minishell differ diff --git a/srcs/builtins.o b/srcs/builtins.o index 417e181..a18de46 100644 Binary files a/srcs/builtins.o and b/srcs/builtins.o differ diff --git a/srcs/builtins_background.o b/srcs/builtins_background.o index 21fbb95..4662f1f 100644 Binary files a/srcs/builtins_background.o and b/srcs/builtins_background.o differ diff --git a/srcs/builtins_background2.o b/srcs/builtins_background2.o index d5a6ce7..a74cbbc 100644 Binary files a/srcs/builtins_background2.o and b/srcs/builtins_background2.o differ diff --git a/srcs/builtins_checkers.o b/srcs/builtins_checkers.o index 85dfd02..b516345 100644 Binary files a/srcs/builtins_checkers.o and b/srcs/builtins_checkers.o differ diff --git a/srcs/builtins_runners.o b/srcs/builtins_runners.o index cb4d602..07174c5 100644 Binary files a/srcs/builtins_runners.o and b/srcs/builtins_runners.o differ diff --git a/srcs/cmd_build.c b/srcs/cmd_build.c index 3e893d8..8871c10 100755 --- a/srcs/cmd_build.c +++ b/srcs/cmd_build.c @@ -77,7 +77,7 @@ bool add_cmds(char **matrix) validate_rl(matrix); if (_shell()->valid_input == false) { - printf("SYNTAX ERROR: unexpected token ...\n"); + printf("\033[0;31msyntax error near unexpected token `newline'\033[0m\n"); return (false); } else diff --git a/srcs/cmd_build.o b/srcs/cmd_build.o index cc2a1c7..09c370d 100644 Binary files a/srcs/cmd_build.o and b/srcs/cmd_build.o differ diff --git a/srcs/cmd_build2.o b/srcs/cmd_build2.o index eecaf19..7d57aa2 100644 Binary files a/srcs/cmd_build2.o and b/srcs/cmd_build2.o differ diff --git a/srcs/concat.o b/srcs/concat.o index 6b85181..61b1888 100644 Binary files a/srcs/concat.o and b/srcs/concat.o differ diff --git a/srcs/create_files.o b/srcs/create_files.o index 37e039c..e7b655a 100644 Binary files a/srcs/create_files.o and b/srcs/create_files.o differ diff --git a/srcs/error.o b/srcs/error.o index 649c435..43b4a02 100644 Binary files a/srcs/error.o and b/srcs/error.o differ diff --git a/srcs/exec.o b/srcs/exec.o index 69ea30e..6cf75c1 100644 Binary files a/srcs/exec.o and b/srcs/exec.o differ diff --git a/srcs/free.o b/srcs/free.o index 6b60fab..e5cc75f 100644 Binary files a/srcs/free.o and b/srcs/free.o differ diff --git a/srcs/heredoc.o b/srcs/heredoc.o index b30ef4f..1d2da34 100644 Binary files a/srcs/heredoc.o and b/srcs/heredoc.o differ diff --git a/srcs/initializers.o b/srcs/initializers.o index a3794e0..85c7b88 100644 Binary files a/srcs/initializers.o and b/srcs/initializers.o differ diff --git a/srcs/loop.o b/srcs/loop.o index a98a49d..8d1707d 100644 Binary files a/srcs/loop.o and b/srcs/loop.o differ diff --git a/srcs/loop_new.o b/srcs/loop_new.o index 444b402..772e501 100644 Binary files a/srcs/loop_new.o and b/srcs/loop_new.o differ diff --git a/srcs/loop_utils.o b/srcs/loop_utils.o index 6a42b42..7cd696e 100644 Binary files a/srcs/loop_utils.o and b/srcs/loop_utils.o differ diff --git a/srcs/main.c b/srcs/main.c index 6fd75d7..1f07057 100755 --- a/srcs/main.c +++ b/srcs/main.c @@ -93,7 +93,7 @@ void minishell(void) matrix = line_to_matrix(line); if (add_cmds(matrix) && init_remove_qt()) { - // print_tcmd(_shell()->head); + print_tcmd(_shell()->head); pipe_commands(_shell()->head); } else diff --git a/srcs/main.o b/srcs/main.o index fe6b4e3..e7353d8 100644 Binary files a/srcs/main.o and b/srcs/main.o differ diff --git a/srcs/matrix_fts.o b/srcs/matrix_fts.o index 0fd7458..2bdf526 100644 Binary files a/srcs/matrix_fts.o and b/srcs/matrix_fts.o differ diff --git a/srcs/matrix_utils.o b/srcs/matrix_utils.o index 0ef5277..8dc9f11 100644 Binary files a/srcs/matrix_utils.o and b/srcs/matrix_utils.o differ diff --git a/srcs/parse.c b/srcs/parse.c index 316cfa0..ea4e5c2 100755 --- a/srcs/parse.c +++ b/srcs/parse.c @@ -1,17 +1,4 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* parse.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: vrubio < vrubio@student.42lisboa.com > +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/12/22 15:20:00 by vrubio #+# #+# */ -/* Updated: 2022/12/22 15:20:01 by vrubio ### ########.fr */ -/* */ -/* ************************************************************************** */ - #include "../include/minishell.h" -//parsing of quotes static char *buffer_quotes(char **buff, char c, char *str, int i) { @@ -33,7 +20,6 @@ static char *buffer_scan_for_quotes(char *str) f = 0; k = 0; i = -1; - c = 0; while (str[++i]) { if ((str[i] == '\'' || str[i] == '"')) @@ -49,25 +35,19 @@ static char *buffer_scan_for_quotes(char *str) return (str); } -static void buffer2string_quotes(char **buff, char **str, int *i) +int check_last_char_if_its_pipe(char *str) { - if (ft_strexist("'\"\2", **buff) && *(*buff) != '\0' && *(*buff - + 1) == **buff) - (*buff) += 2; - if (ft_strexist("'\"\2", **buff) && *(*buff) != '\0' && (**buff - + 1 != **buff)) - (*str) = buffer_quotes(&(*buff), **buff, (*str), *i); - else if (**buff) - (*str)[(*i)++] = *(*buff)++; + int i; + + i = ft_strlen(str); + if (str[i - 1] == '|') + return (1); + return (0); } -static char *buffer_to_string(char **buff) +static char *buffer_to_string(char **buff, int i, char *str) { - char *str; - int i; - - str = ft_calloc(sizeof(char), (ft_strlen(*buff) + 1)); - i = 0; + str = calloc(sizeof(char), (ft_strlen(*buff) + 1)); while (**buff) { i = ft_strlen(str); @@ -82,7 +62,12 @@ static char *buffer_to_string(char **buff) str[i++] = *(*buff)++; return (str); } - buffer2string_quotes(buff, &str, &i); + if ((**buff == '\'' || **buff == '"') && *(*buff + 1) == **buff) + (*buff) += 2; + if ((**buff == '\'' || **buff == '"') && (**buff + 1 != **buff)) + str = buffer_quotes(&(*buff), **buff, str, i); + else if (**buff) + str[i++] = *(*buff)++; } return (buffer_scan_for_quotes(str)); } @@ -91,8 +76,10 @@ char **line_to_matrix(char *line) { char **matrix; int i; + char *buff; - matrix = malloc(sizeof(char *) * (r_size(line) + 1)); + buff = NULL; + matrix = malloc(sizeof(char *) * (r_size(line) + 4)); i = 0; while (*line) { @@ -100,8 +87,17 @@ char **line_to_matrix(char *line) line++; if (!line || ft_strlen(line) == 0) break ; - matrix[i++] = buffer_to_string(&line); + matrix[i++] = buffer_to_string(&line, 0, NULL); + } + if (matrix[i - 1] && check_last_char_if_its_pipe(matrix[i - 1])) + { + while (!buff || ft_strlen(buff) == 0) + buff = readline("pipe> "); + add_history(buff); + matrix[i++] = ft_strdup(buff); + free (buff); } matrix[i] = 0; + print_arrays(matrix); return (matrix); } diff --git a/srcs/parse.o b/srcs/parse.o index 9375989..463ac34 100644 Binary files a/srcs/parse.o and b/srcs/parse.o differ diff --git a/srcs/parse2.c b/srcs/parse2.c index 5de2328..3830a56 100755 --- a/srcs/parse2.c +++ b/srcs/parse2.c @@ -30,6 +30,25 @@ void ft_do_quote(char **output, char c) ft_do_quote(output, c); } +void ft_do_pipe(char **output) +{ + char *buff; + char *tmp; + + buff = readline("pipe> "); + if (ft_strlen(buff) == 0) + ft_do_pipe(output); + else + { + add_history(buff); + tmp = ft_strdup(buff); + ft_stradd(&(*output), tmp); + free(buff); + free(tmp); + } +} + + int readline_check(char **p2line) { char *line; diff --git a/srcs/parse2.o b/srcs/parse2.o index 3a79272..47f554a 100644 Binary files a/srcs/parse2.o and b/srcs/parse2.o differ diff --git a/srcs/parse_clean.c b/srcs/parse_clean.c index cb10aac..f93509d 100755 --- a/srcs/parse_clean.c +++ b/srcs/parse_clean.c @@ -24,6 +24,7 @@ char *parse_clean(char **p2str) i = 0; while (*str) { + // printf("EVAL----%s\n", str); if (*str == 2 || *str == '\'' || *str == '"') { c = *str++; diff --git a/srcs/parse_clean.o b/srcs/parse_clean.o index 45baec4..67bdfd7 100644 Binary files a/srcs/parse_clean.o and b/srcs/parse_clean.o differ diff --git a/srcs/parse_env.o b/srcs/parse_env.o index 6f728fe..569e2cd 100644 Binary files a/srcs/parse_env.o and b/srcs/parse_env.o differ diff --git a/srcs/path.o b/srcs/path.o index 0561702..4134f5b 100644 Binary files a/srcs/path.o and b/srcs/path.o differ diff --git a/srcs/piping.o b/srcs/piping.o index 2900f94..538b920 100644 Binary files a/srcs/piping.o and b/srcs/piping.o differ diff --git a/srcs/piping2.o b/srcs/piping2.o index 66a15c6..0c15feb 100644 Binary files a/srcs/piping2.o and b/srcs/piping2.o differ diff --git a/srcs/piping_redir.o b/srcs/piping_redir.o index 9fa0a54..008b551 100644 Binary files a/srcs/piping_redir.o and b/srcs/piping_redir.o differ diff --git a/srcs/prompt.o b/srcs/prompt.o index 39fe36b..2ec4b6e 100644 Binary files a/srcs/prompt.o and b/srcs/prompt.o differ diff --git a/srcs/shell.o b/srcs/shell.o index 158c240..d5a1e1c 100644 Binary files a/srcs/shell.o and b/srcs/shell.o differ diff --git a/srcs/tester.o b/srcs/tester.o index 4080a2c..8a675ea 100644 Binary files a/srcs/tester.o and b/srcs/tester.o differ diff --git a/srcs/utils2.o b/srcs/utils2.o index 1e6548f..20d451d 100644 Binary files a/srcs/utils2.o and b/srcs/utils2.o differ diff --git a/srcs/utils_array.o b/srcs/utils_array.o index 26b1ef1..881a9cc 100644 Binary files a/srcs/utils_array.o and b/srcs/utils_array.o differ diff --git a/srcs/utils_fd.o b/srcs/utils_fd.o index 7a946a4..7b73316 100644 Binary files a/srcs/utils_fd.o and b/srcs/utils_fd.o differ diff --git a/srcs/utils_parsing.o b/srcs/utils_parsing.o index 4307180..d220cbe 100644 Binary files a/srcs/utils_parsing.o and b/srcs/utils_parsing.o differ diff --git a/srcs/validation.c b/srcs/validation.c index 63c390b..4773836 100755 --- a/srcs/validation.c +++ b/srcs/validation.c @@ -26,8 +26,6 @@ static void ft_validate_pipe_matrix(char **line, int i, int j) _shell()->valid_input = false; } } - if (line[i + 1] == NULL) - _shell()->valid_input = false; } static void ft_validate_redir_output_matrix(char **line, int i) @@ -64,9 +62,10 @@ void validate_rl(char **matrix) j = -1; while (matrix[i][++j]) { - if (matrix[i][j] == '\"' || matrix[i][j] == '\'') + + if (matrix[i][j] == '"' || matrix[i][j] == '\'') { - c = matrix[i][j]; + c = matrix[i][j++]; while (matrix[i][j] && matrix[i][j] != c) j++; } diff --git a/srcs/validation.o b/srcs/validation.o index ba999d5..afcc884 100644 Binary files a/srcs/validation.o and b/srcs/validation.o differ diff --git a/srcs/var_expansion.o b/srcs/var_expansion.o index 688fb57..1d4535c 100644 Binary files a/srcs/var_expansion.o and b/srcs/var_expansion.o differ