From 0109c12fa69873d6f8d01eaff0f50185be003c06 Mon Sep 17 00:00:00 2001 From: Leo-Paul Cottet Date: Thu, 11 Apr 2024 17:22:14 +0200 Subject: [PATCH] Fix KOs from tester Co-authored-by: Bastien Wisniewski --- .github/workflows/main.yaml | 5 +++++ srcs/builtins/cd.c | 8 ++++---- srcs/builtins/pwd.c | 10 +++++----- srcs/exec/here_doc.c | 23 +++++++++++++++-------- srcs/expander/expander.c | 12 +++++++----- srcs/expander/expander_file.c | 8 +++++--- srcs/main.c | 8 ++++---- tester | 2 +- 8 files changed, 46 insertions(+), 30 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0e538b5..1e3cf9c 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -46,5 +46,10 @@ jobs: pip3 install norminette norminette + - name: Test + run: + export TERM=default + make test + - name: Build run: make diff --git a/srcs/builtins/cd.c b/srcs/builtins/cd.c index 564efa5..18e184e 100644 --- a/srcs/builtins/cd.c +++ b/srcs/builtins/cd.c @@ -3,19 +3,19 @@ /* ::: :::::::: */ /* cd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: bwisniew +#+ +:+ +#+ */ +/* By: lcottet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/14 13:57:43 by bwisniew #+# #+# */ -/* Updated: 2024/04/10 15:35:37 by bwisniew ### ########.fr */ +/* Updated: 2024/04/11 15:55:42 by lcottet ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #include "libft.h" +#include "ft_printf.h" #include #include #include -#include int cd_getcwd_err(t_mshell *sh, char *argv) { @@ -99,7 +99,7 @@ int cd_oldpwd(t_mshell *sh) error("cd"); return (1); } - printf("%s\n", oldpwd->value); + ft_printf("%s\n", oldpwd->value); return (cd_change_env(sh, NULL)); } diff --git a/srcs/builtins/pwd.c b/srcs/builtins/pwd.c index 3d099da..33c83de 100644 --- a/srcs/builtins/pwd.c +++ b/srcs/builtins/pwd.c @@ -3,15 +3,15 @@ /* ::: :::::::: */ /* pwd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: bwisniew +#+ +:+ +#+ */ +/* By: lcottet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/14 13:57:34 by bwisniew #+# #+# */ -/* Updated: 2024/04/08 15:49:06 by bwisniew ### ########.fr */ +/* Updated: 2024/04/11 15:54:25 by lcottet ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -#include +#include "ft_printf.h" #include #include @@ -24,7 +24,7 @@ int pwd(t_mshell *sh, t_execute *exec) env = env_get(sh, "PWD", false); if (env) { - printf("%s\n", env->value); + ft_printf("%s\n", env->value); return (0); } pwd = getcwd(NULL, 0); @@ -33,7 +33,7 @@ int pwd(t_mshell *sh, t_execute *exec) error("pwd"); return (1); } - printf("%s\n", pwd); + ft_printf("%s\n", pwd); free(pwd); return (0); } diff --git a/srcs/exec/here_doc.c b/srcs/exec/here_doc.c index 0b1dc4e..37649cd 100644 --- a/srcs/exec/here_doc.c +++ b/srcs/exec/here_doc.c @@ -3,16 +3,17 @@ /* ::: :::::::: */ /* here_doc.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: bwisniew +#+ +:+ +#+ */ +/* By: lcottet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/10 20:41:37 by lcottet #+# #+# */ -/* Updated: 2024/04/08 18:58:18 by lcottet ### ########.fr */ +/* Updated: 2024/04/11 17:02:05 by lcottet ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #include "expander.h" #include "libft.h" +#include "ft_printf.h" #include "get_next_line.h" #include #include @@ -23,11 +24,15 @@ int here_doc_line(int file, char *line) { - if (write(file, line, ft_strlen(line)) == -1) - return (free(line), 1); + size_t i; + + i = 0; + while (line[i] && line[i] != '\n') + i++; + if (write(file, line, i) == -1) + return (1); if (write(file, "\n", 1) == -1) - return (free(line), 1); - free(line); + return (1); return (0); } @@ -67,8 +72,10 @@ char *here_doc_getline(t_mshell *sh, size_t i, t_fd fd, int *err) free_token(&line); return (free(tmp), NULL); } - *err = here_doc_line(fd, line.txt); - return (tmp); + if (!hd_cmp(((t_token *)sh->tokens.tab)[i].txt, tmp, + ((t_token *)sh->tokens.tab)[i].txt_size)) + *err = here_doc_line(fd, line.txt); + return (free_token(&line), tmp); } int get_final_heredoc_fd(t_execute *exec, t_fd old, int err) diff --git a/srcs/expander/expander.c b/srcs/expander/expander.c index c841b7f..77fca71 100644 --- a/srcs/expander/expander.c +++ b/srcs/expander/expander.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* expander.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: bwisniew +#+ +:+ +#+ */ +/* By: lcottet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/21 19:13:27 by bwisniew #+# #+# */ -/* Updated: 2024/04/03 18:11:59 by bwisniew ### ########.fr */ +/* Updated: 2024/04/11 16:44:42 by lcottet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,9 +18,12 @@ int expander(t_mshell *sh, size_t start, size_t end) size_t token_i; int ret; - token_i = expander_skip_file(&sh->tokens, start, end); + token_i = start; while (token_i < end) { + token_i = expander_skip_file(&sh->tokens, token_i, end); + if (token_i >= end) + break ; if (!is_special(((t_token *)sh->tokens.tab)[token_i].type)) { ret = tokens_expand(sh, token_i); @@ -29,9 +32,8 @@ int expander(t_mshell *sh, size_t start, size_t end) token_i += ret; end += ret - 1; } - else + else if (!is_type_arrow(((t_token *)sh->tokens.tab)[token_i].type)) token_i++; - token_i = expander_skip_file(&sh->tokens, token_i, end); } return (expander_unseparated(&sh->tokens, start, token_i)); } diff --git a/srcs/expander/expander_file.c b/srcs/expander/expander_file.c index e58cf96..ab781fa 100644 --- a/srcs/expander/expander_file.c +++ b/srcs/expander/expander_file.c @@ -3,16 +3,17 @@ /* ::: :::::::: */ /* expander_file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: bwisniew +#+ +:+ +#+ */ +/* By: lcottet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/03 13:50:42 by bwisniew #+# #+# */ -/* Updated: 2024/04/03 19:17:15 by bwisniew ### ########.fr */ +/* Updated: 2024/04/11 17:14:12 by lcottet ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #include "expander.h" #include "libft.h" +#include size_t expander_skip_file(t_vector *lex, size_t i, size_t n) { @@ -64,7 +65,8 @@ int expand_file(t_mshell *sh, size_t token_i) i_cp = token_i; token_i++; while (token_i < sh->tokens.len - && ((t_token *)sh->tokens.tab)[token_i].is_file == 1) + && (((t_token *)sh->tokens.tab)[token_i].is_file == 1 + && !is_type_arrow(((t_token *)sh->tokens.tab)[token_i].type))) { if (expand_ambi_file(&((t_token *)sh->tokens.tab)[token_i], sh) != 0) return (1); diff --git a/srcs/main.c b/srcs/main.c index 2f2b1a6..39203c2 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -3,17 +3,17 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: bwisniew +#+ +:+ +#+ */ +/* By: lcottet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/14 13:11:23 by lcottet #+# #+# */ -/* Updated: 2024/04/09 16:35:22 by lcottet ### ########.fr */ +/* Updated: 2024/04/11 17:13:51 by lcottet ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #include "lexer.h" +#include "ft_printf.h" #include "get_next_line.h" -#include #include #include #include @@ -99,7 +99,7 @@ int main(int argc, char **argv, char **env) minishell(&mshell, input); } if (isatty(STDIN_FILENO)) - printf("exit\n"); + ft_printf("exit\n"); errno = 0; finish_mshell(&mshell); return ((char)mshell.exit); diff --git a/tester b/tester index dc8eb2b..3ce8130 160000 --- a/tester +++ b/tester @@ -1 +1 @@ -Subproject commit dc8eb2bdb743b977c43380eac36aa8652059029a +Subproject commit 3ce8130fc12276029c22345008ae332d48288e49