From 10a8ecaae866db7ff151f141aaeb77b9a9dfa7bd Mon Sep 17 00:00:00 2001 From: hugogogo Date: Sun, 5 Dec 2021 14:16:11 +0100 Subject: [PATCH] recherche du pbm dans heredoc --- srcs/exec/exec_cmd_line.c | 3 +-- srcs/parsing/parsing.c | 2 +- srcs/parsing/redirections/here_doc.c | 30 +--------------------- srcs/parsing/redirections/redirections.c | 2 +- srcs/shell_loop.c | 5 +--- tests/unit_tests/wip/main.c | 32 +++++++++++------------- 6 files changed, 20 insertions(+), 54 deletions(-) diff --git a/srcs/exec/exec_cmd_line.c b/srcs/exec/exec_cmd_line.c index 1c91c93..8a35d73 100644 --- a/srcs/exec/exec_cmd_line.c +++ b/srcs/exec/exec_cmd_line.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */ -/* Updated: 2021/12/05 09:28:00 by hulamy ### ########.fr */ +/* Updated: 2021/12/05 14:09:43 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,6 @@ int exec_cmd_line(t_all *c) free_pipeline(&c->pipeline); return (0); } -//write(1, "here\n", 5); return (1); } diff --git a/srcs/parsing/parsing.c b/srcs/parsing/parsing.c index 6ee4969..5adbe76 100644 --- a/srcs/parsing/parsing.c +++ b/srcs/parsing/parsing.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */ -/* Updated: 2021/12/04 16:06:48 by hulamy ### ########.fr */ +/* Updated: 2021/12/05 14:02:10 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/parsing/redirections/here_doc.c b/srcs/parsing/redirections/here_doc.c index 0684da2..22e6931 100644 --- a/srcs/parsing/redirections/here_doc.c +++ b/srcs/parsing/redirections/here_doc.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */ -/* Updated: 2021/12/05 10:58:56 by hulamy ### ########.fr */ +/* Updated: 2021/12/05 14:15:09 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -117,31 +117,3 @@ static int here_doc_write(char *delimiter, int doc_fd) sigaction(SIGINT, &signal_action, NULL); return (0); } - -/* -static int here_doc_write(char *delimiter, int doc_fd) -{ - char *line; - int ret; - - line = NULL; - ret = 1; - while (ret) - { - ret = gnl(STDIN_FILENO, &line, 0); - if (ret == -1) - return (ft_reti_perror_free(0, line, free, "gnl() STDIN")); - if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0) // Ou ft_strlen(delimiter) + 1 ? Ça devrais être identique et ça peux se calculer une seul fois. - break ; - if (write(doc_fd, line, ft_strlen(line)) == -1) - return (ft_reti_perror_free(0, line, free, "write() "TMP_HERE_DOC)); - if (write(doc_fd, "\n", 1) == -1) - return (ft_reti_perror_free(0, line, free, "write() "TMP_HERE_DOC)); - free(line); - line = NULL; - } - free(line); - gnl(STDIN_FILENO, NULL, 1); - return (1); -} - */ diff --git a/srcs/parsing/redirections/redirections.c b/srcs/parsing/redirections/redirections.c index 1b6e9bf..210900a 100644 --- a/srcs/parsing/redirections/redirections.c +++ b/srcs/parsing/redirections/redirections.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */ -/* Updated: 2021/12/04 16:05:46 by hulamy ### ########.fr */ +/* Updated: 2021/12/05 14:00:22 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/shell_loop.c b/srcs/shell_loop.c index c19bcca..77b902a 100644 --- a/srcs/shell_loop.c +++ b/srcs/shell_loop.c @@ -6,7 +6,7 @@ /* By: lperrey +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */ -/* Updated: 2021/12/04 16:08:48 by hulamy ### ########.fr */ +/* Updated: 2021/12/05 14:15:18 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,9 +23,6 @@ void shell_loop(t_all *c) { if (line_input) free(line_input); - write(2, c->prompt, ft_strlen(c->prompt)); - rl_already_prompted = 1; -// line_input = read_input(NULL, c); line_input = read_input(c->prompt, c); if (line_input && *line_input) { diff --git a/tests/unit_tests/wip/main.c b/tests/unit_tests/wip/main.c index f3dfc34..886091d 100644 --- a/tests/unit_tests/wip/main.c +++ b/tests/unit_tests/wip/main.c @@ -4,40 +4,38 @@ #include #include +#define CYAN "\001\e[1;36m\002" #define WHITE "\001\e[1;37m\002" #define RESET "\001\e[0m\002" int main(void) { - char *prompt; char *line_input; + char *heredoc; + char *delimiter; + char *here_line; - //prompt = WHITE"mybash a very long prompt to test the output in case of a redirection in a file> "RESET; - prompt = WHITE"mybash> "RESET; line_input = NULL; while (1) { - if (line_input) - free(line_input); - line_input = readline(prompt); + line_input = readline(WHITE"mybash> "RESET); if (line_input) { - if (!strncmp(line_input, "echo ", 5)) + heredoc = strstr(line_input, " << "); + if (heredoc) { - write(1, line_input + 5, strlen(line_input) - 5); - write(1, "\n", 1); + delimiter = heredoc + strlen(" << "); + while(1) + { + here_line = NULL; + here_line = readline(CYAN"> "RESET); + if (!strncmp(here_line, delimiter, strlen(here_line) + 1)) + break ; + } } } if (!line_input) - { - write(2, "exit\n", 5); exit(0); - } } -/* - prompt = WHITE"mybash a very long prompt to test the output in case of a redirection in a file, style longer than that even> "RESET; - write(1, prompt, strlen(prompt)); - write(1, "\n", 1); -*/ return (0); }