Merge remote-tracking branch 'origin/quinten' into willem

This commit is contained in:
whaffman 2025-03-07 13:40:03 +01:00
commit 199db17d31
4 changed files with 39 additions and 21 deletions

View File

@ -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)

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* lexer_read_word.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* 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 <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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));

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* error_msg.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* 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 <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);