heredoc and builtins fix

This commit is contained in:
marcnava-42cursus
2026-02-14 14:26:58 +01:00
parent ba40670ace
commit 73ed56aa16
29 changed files with 1107 additions and 155 deletions

View File

@@ -14,6 +14,7 @@
static uint8_t is_valid_identifier(const char *arg);
static uint8_t unset_one(char *arg, t_minishell *msh);
static bool is_option(const char *arg);
uint8_t builtin_unset(
t_command cmd,
@@ -21,13 +22,19 @@ uint8_t builtin_unset(
)
{
uint8_t status;
uint8_t result;
size_t i;
status = EXIT_SUCCESS;
i = 0;
while (cmd.argv[++i] != NULL)
if (unset_one(cmd.argv[i], msh) != EXIT_SUCCESS)
{
result = unset_one(cmd.argv[i], msh);
if (result == 2)
return (2);
if (result != EXIT_SUCCESS)
status = EXIT_FAILURE;
}
return (status);
}
@@ -53,9 +60,21 @@ static uint8_t unset_one(
t_minishell *msh
)
{
if (is_option(arg))
{
ft_eprintf("minishell: unset: %s: invalid option\n", arg);
ft_eputendl("unset: usage: unset [name ...]");
return (2);
}
if (!is_valid_identifier(arg))
return (ft_eprintf("minishell: unset: `%s': not a valid identifier\n",
arg), EXIT_FAILURE);
return (EXIT_SUCCESS);
unset_env(arg, msh);
return (EXIT_SUCCESS);
}
static bool is_option(
const char *arg
)
{
return (arg != NULL && arg[0] == '-' && arg[1] != '\0');
}