From 5e89605f63f6a207c6cbf9e5b257176118380873 Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Thu, 6 Mar 2025 17:59:22 +0100 Subject: [PATCH 1/2] now it works --- src/builtin/builtin_echo.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/builtin/builtin_echo.c b/src/builtin/builtin_echo.c index c79860b..c8b07fe 100644 --- a/src/builtin/builtin_echo.c +++ b/src/builtin/builtin_echo.c @@ -12,6 +12,22 @@ #include "minishell.h" +static int is_n_flag(char *cmd) +{ + int i; + + if (cmd[0] != '-') + return (0); + i = 1; + while (cmd[i]) + { + if (cmd[i] != 'n') + return (0); + i++; + } + return (1); +} + int builtin_echo(t_minishell *msh, t_command *cmd) { int i; @@ -20,14 +36,14 @@ int builtin_echo(t_minishell *msh, t_command *cmd) (void)msh; i = 1; n_flag = 0; - if (cmd->args[i] != NULL && ft_strncmp(cmd->args[i], "-n", 2) == 0) + if (cmd->args[i] != NULL && is_n_flag(cmd->args[i])) { n_flag = 1; i++; } while (cmd->args[i] != NULL) { - while (ft_strncmp(cmd->args[i], "-n", 2) == 0 && n_flag > 0) + while (is_n_flag(cmd->args[i]) && n_flag > 0) i++; printf("%s", cmd->args[i]); if (cmd->args[i + 1] != NULL) From f6b4ab4f12149e31d5e9be4828ff7158a4ea4ede Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Thu, 6 Mar 2025 18:10:59 +0100 Subject: [PATCH 2/2] fixing some parsing and error messages --- src/lexer/lexer_read_word.c | 16 +++++++++------- src/redirect/redirect_valid_type.c | 4 ++-- src/utils/error_msg.c | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/lexer/lexer_read_word.c b/src/lexer/lexer_read_word.c index d60e43b..d20ba9e 100644 --- a/src/lexer/lexer_read_word.c +++ b/src/lexer/lexer_read_word.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* lexer_read_word.c :+: :+: */ -/* +:+ */ -/* By: qmennen +#+ */ -/* +#+ */ -/* Created: 2025/02/05 19:03:47 by qmennen #+# #+# */ -/* Updated: 2025/02/28 14:06:32 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* lexer_read_word.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/05 19:03:47 by qmennen #+# #+# */ +/* Updated: 2025/03/06 18:02:51 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,8 @@ static int is_word_char(char c) { if (c == '<' || c == '>' || c == '|' || c == '\0') return (0); + else if (c == '\'' || c == '"') + return (0); else if (ft_isspace(c)) return (0); return (ft_isprint(c)); diff --git a/src/redirect/redirect_valid_type.c b/src/redirect/redirect_valid_type.c index 8d232d0..a9a8414 100644 --- a/src/redirect/redirect_valid_type.c +++ b/src/redirect/redirect_valid_type.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/23 12:30:18 by Quinten #+# #+# */ -/* Updated: 2025/02/26 17:40:44 by qmennen ### ########.fr */ +/* Updated: 2025/03/06 18:07:28 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ int redirect_is_valid(t_list *lst, t_token *token, int mode) } if (mode >= 0 && access(next->value, mode) != 0) { - error_msg("minishell", "unable to write to temp file"); + error_msg(next->value, NULL); return (0); } return (redirect_token_type(token) && next->type < 3); diff --git a/src/utils/error_msg.c b/src/utils/error_msg.c index 879e116..7c23632 100644 --- a/src/utils/error_msg.c +++ b/src/utils/error_msg.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* error_msg.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/02/20 17:03:13 by whaffman #+# #+# */ -/* Updated: 2025/03/06 15:36:30 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* error_msg.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/20 17:03:13 by whaffman #+# #+# */ +/* Updated: 2025/03/06 18:08:53 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,12 +23,12 @@ void error_msg(char *func, char *msg) { ft_putstr_fd(RED BOLD SHELL_NAME RESET ": ", STDERR_FILENO); if (func != NULL) - { ft_putstr_fd(func, STDERR_FILENO); - ft_putstr_fd(": ", STDERR_FILENO); - } if (msg != NULL) + { + ft_putstr_fd(": ", STDERR_FILENO); ft_putstr_fd(msg, STDERR_FILENO); + } if (errno) { ft_putstr_fd(": ", STDERR_FILENO);