heredoc and builtins fix
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user