add: exit cmd
This commit is contained in:
parent
3d66fbe9a9
commit
9f0b0f5422
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
|||||||
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c utils/ft_atoi_check.c
|
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c utils/ft_atoi_check.c
|
||||||
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c env2.c env3.c execution.c spacer.c env_fill.c builtins/echo.c builtins/pwd.c builtins/export.c builtins/env.c builtins/cd.c builtins/exit.c
|
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c env2.c env3.c execution.c spacer.c env_fill.c builtins/echo.c builtins/pwd.c builtins/export.c builtins/env.c builtins/cd.c builtins/exit.c builtins/unset.c
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
static int error(int err, char *reason, char *problem, int fd)
|
static int error(int err, char *reason, char *problem, int fd)
|
||||||
{
|
{
|
||||||
write(fd, "bash: exit: ", 12);
|
ft_putstr_fd("minishell: exit ", fd);
|
||||||
if (problem != NULL)
|
if (problem != NULL)
|
||||||
{
|
{
|
||||||
ft_putstr_fd(problem, fd);
|
ft_putstr_fd(problem, fd);
|
||||||
@ -36,11 +36,11 @@ int ft_exit(char **args, int fd)
|
|||||||
return (error(2, "numeric argument required", args[0], fd));
|
return (error(2, "numeric argument required", args[0], fd));
|
||||||
if (args[1] != NULL)
|
if (args[1] != NULL)
|
||||||
return (error(-1, "too many arguments", NULL, fd));
|
return (error(-1, "too many arguments", NULL, fd));
|
||||||
return (0);
|
return (ft_atoi(args[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
/* int main(int argc, char *argv[]) */
|
||||||
{
|
/* { */
|
||||||
(void)argc;
|
/* (void)argc; */
|
||||||
return(ft_exit(argv + 1, 1));
|
/* return(ft_exit(argv + 1, 1)); */
|
||||||
}
|
/* } */
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../minishell.h"
|
||||||
|
|
||||||
int error(char *str, int fd)
|
int error(char *str, int fd)
|
||||||
{
|
{
|
||||||
write(fd, "bash: unset: `", 14);
|
write(fd, "bash: unset: `", 14);
|
||||||
|
20
execution.c
20
execution.c
@ -95,25 +95,33 @@ static int ft_excutor(t_cmd *cmd, t_list **env)
|
|||||||
return (return_value);
|
return (return_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ft_own_cmd(t_list **env, t_cmd *cmd)
|
static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
||||||
{
|
{
|
||||||
int return_code;
|
int return_code;
|
||||||
|
int exit_code;
|
||||||
|
|
||||||
return_code = -1;
|
return_code = -1;
|
||||||
if (ft_strcmp(cmd->executable, "pwd") == 0)
|
if (ft_strcmp(cmd->executable, "pwd") == 0)
|
||||||
return_code = pwd(cmd->fd_out);
|
return_code = pwd(cmd->fd_out);
|
||||||
else if (ft_strcmp(cmd->executable, "env") == 0)
|
else if (ft_strcmp(cmd->executable, "env") == 0)
|
||||||
return_code = print_env(env, cmd->fd_out);
|
return_code = print_env(data->env, cmd->fd_out);
|
||||||
else if (ft_strcmp(cmd->executable, "export") == 0)
|
else if (ft_strcmp(cmd->executable, "export") == 0)
|
||||||
return_code = (export(env,cmd->args + 1, cmd->fd_out));
|
return_code = (export(data->env,cmd->args + 1, cmd->fd_out));
|
||||||
else if (ft_strcmp(cmd->executable, "cd") == 0)
|
else if (ft_strcmp(cmd->executable, "cd") == 0)
|
||||||
return_code = (move_folder(cmd->args[1], cmd->fd_out));
|
return_code = (move_folder(cmd->args[1], cmd->fd_out));
|
||||||
/* if (ft_strcmp(cmd->executable, "unset") == 0) */
|
if (ft_strcmp(cmd->executable, "unset") == 0)
|
||||||
/* return_code = (unset(env, cmd->args, cmd->fd_out)); */
|
return_code = (unset(data->env, cmd->args, cmd->fd_out));
|
||||||
else if (ft_strcmp(cmd->executable, "echo") == 0)
|
else if (ft_strcmp(cmd->executable, "echo") == 0)
|
||||||
return_code = (echo(cmd->fd_out, cmd->args + 1));
|
return_code = (echo(cmd->fd_out, cmd->args + 1));
|
||||||
else if (ft_strcmp(cmd->executable, "exit") == 0)
|
else if (ft_strcmp(cmd->executable, "exit") == 0)
|
||||||
|
{
|
||||||
|
exit_code = ft_exit(cmd->args + 1, cmd->fd_out);
|
||||||
|
if (exit_code != -1)
|
||||||
|
{
|
||||||
|
data->exit_code = exit_code;
|
||||||
return_code = -2;
|
return_code = -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (return_code != -1)
|
if (return_code != -1)
|
||||||
cmd->executable = NULL;
|
cmd->executable = NULL;
|
||||||
return (return_code);
|
return (return_code);
|
||||||
@ -141,7 +149,7 @@ int ft_cmds_executor(t_data *data, t_list **cmds)
|
|||||||
content->fd_out = fds[1];
|
content->fd_out = fds[1];
|
||||||
((t_cmd *) current->next->content)->fd_in = fds[0];
|
((t_cmd *) current->next->content)->fd_in = fds[0];
|
||||||
}
|
}
|
||||||
cmd_return = ft_own_cmd(data->env, content);
|
cmd_return = ft_own_cmd(data, content);
|
||||||
if (cmd_return == -1)
|
if (cmd_return == -1)
|
||||||
{
|
{
|
||||||
content->executable = ft_get_executable_path(
|
content->executable = ft_get_executable_path(
|
||||||
|
Loading…
Reference in New Issue
Block a user