fixe builtin exit to accept arguments
This commit is contained in:
parent
eda2954279
commit
a93185a45e
@ -11,6 +11,7 @@ A lot of amazing shell stuff
|
||||
-[x] Get environment array (export)
|
||||
-[x] Set environment variable (export)
|
||||
-[x] Simple builtin export
|
||||
-[x] builtins
|
||||
-[x] Preliminary signals
|
||||
-[x] Define struct for commands, something like (
|
||||
```c
|
||||
@ -49,7 +50,7 @@ A lot of amazing shell stuff
|
||||
- `ctrl - C` SIGINT to processs status 130
|
||||
- `ctrl - D`
|
||||
- `ctrl - \` SIGQUIT to process core dumped status 131
|
||||
-- Shows ^C
|
||||
-- Shows ^C
|
||||
|
||||
### During HEREDOC
|
||||
- `ctrl - C` redisplay prompt status 130
|
||||
|
||||
@ -6,16 +6,37 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/20 11:32:59 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/20 12:17:40 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/20 15:54:11 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
|
||||
int builtin_exit(t_minishell *minishell, t_command *cmd)
|
||||
{
|
||||
(void)cmd;
|
||||
int exit_status;
|
||||
|
||||
exit_status = 0; //TODO EXIT last exit status
|
||||
if (ft_count_arr(cmd->args) > 2)
|
||||
{
|
||||
ft_putstr_fd("exit\n", STDERR_FILENO);
|
||||
ft_putstr_fd("minishell: exit: too many arguments\n", STDERR_FILENO);
|
||||
return (FAILURE);
|
||||
}
|
||||
if (ft_count_arr(cmd->args) == 2 && cmd->args[1] != NULL)
|
||||
{
|
||||
if (ft_isdigit_str(cmd->args[1]) == FALSE)
|
||||
{
|
||||
ft_putstr_fd("exit\n", STDERR_FILENO);
|
||||
ft_putstr_fd("minishell: exit: ", STDERR_FILENO);
|
||||
ft_putstr_fd(cmd->args[1], STDERR_FILENO);
|
||||
ft_putstr_fd(": numeric argument required\n", STDERR_FILENO);
|
||||
return (FAILURE);
|
||||
}
|
||||
exit_status = ft_atoi(cmd->args[1]);
|
||||
}
|
||||
free_minishell(minishell);
|
||||
exit(EXIT_SUCCESS);
|
||||
return (SUCCESS);
|
||||
exit(exit_status);
|
||||
return (FAILURE);
|
||||
}
|
||||
|
||||
@ -6,12 +6,13 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/20 11:03:33 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/20 13:54:04 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/20 15:36:16 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
|
||||
int is_builtin(char *cmd)
|
||||
{
|
||||
const char *builtins[] = {"echo", "cd", "pwd", "export",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user