maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
exit.c File Reference
#include "shell.h"
#include "libft.h"
#include <stdlib.h>
#include <stdio.h>
#include "env.h"
#include "exit_status.h"
#include "tokens.h"
#include "signals.h"
#include "builtins.h"
Include dependency graph for exit.c:

Go to the source code of this file.

Functions

void cleanup_exit_resources (t_ms_data *data)
 
void handle_numeric_error (t_ms_data *data, const char *arg)
 
void handle_too_many_args_error (t_ms_data *data)
 
void handle_exit (t_ms_data *data, int status)
 
int builtin_exit (t_ms_data *data)
 

Function Documentation

◆ builtin_exit()

int builtin_exit ( t_ms_data data)

Definition at line 61 of file exit.c.

62{
63 int number;
64
65 number = 0;
66 if (!data->args || !data->args[1])
67 {
68 ft_free_2d_arr(data->args);
69 data->args = NULL;
70 ft_putendl_fd("exit", STDOUT_FILENO);
71 handle_exit(data, 0);
72 return (0);
73 }
74 if (ft_isnumber(data->args[1]) == 0)
75 handle_numeric_error(data, data->args[1]);
76 else if (data->args[2])
78 else
79 {
80 number = ft_atoi(data->args[1]);
81 ft_free_2d_arr(data->args);
82 data->args = NULL;
83 handle_exit(data, number);
84 }
85 return (EXIT_SUCCESS);
86}
void ft_free_2d_arr(char **arr)
void handle_exit(t_ms_data *data, int status)
Definition exit.c:53
void handle_too_many_args_error(t_ms_data *data)
Definition exit.c:47
void handle_numeric_error(t_ms_data *data, const char *arg)
Definition exit.c:37
#define EXIT_SUCCESS
Definition exit_status.h:16
int ft_isnumber(char *str)
void ft_putendl_fd(char *s, int fd)
int ft_atoi(const char *str)
char ** args
Definition shell.h:23

References s_ms_data::args, EXIT_SUCCESS, ft_atoi(), ft_free_2d_arr(), ft_isnumber(), ft_putendl_fd(), handle_exit(), handle_numeric_error(), and handle_too_many_args_error().

Referenced by execute(), and main_loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup_exit_resources()

void cleanup_exit_resources ( t_ms_data data)

Definition at line 30 of file exit.c.

31{
33 free_ms_data(data);
35}
void free_signal_context(void)
void clear_history_file(void)
void free_ms_data(t_ms_data *data)
Definition clean.c:51

References clear_history_file(), free_ms_data(), and free_signal_context().

Referenced by handle_exit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_exit()

void handle_exit ( t_ms_data data,
int  status 
)

Definition at line 53 of file exit.c.

54{
55 if (status != 0 && status != TOO_MANY_ARGS)
56 ft_putendl_fd("exit", STDOUT_FILENO);
58 exit(status);
59}
void cleanup_exit_resources(t_ms_data *data)
Definition exit.c:30
#define TOO_MANY_ARGS
Definition exit_status.h:22

References cleanup_exit_resources(), ft_putendl_fd(), and TOO_MANY_ARGS.

Referenced by builtin_exit(), handle_numeric_error(), and handle_too_many_args_error().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_numeric_error()

void handle_numeric_error ( t_ms_data data,
const char *  arg 
)

Definition at line 37 of file exit.c.

38{
39 char *temp_str;
40
41 temp_str = ft_strjoin("exit: ", arg);
43 free(temp_str);
44 handle_exit(data, 0);
45}
#define NUMERIC_REQUIRED
Definition exit_status.h:21
void exit_status_handler(t_ms_data *data, int status_code, char *err_arg)
Definition exit_status.c:25
char * ft_strjoin(char const *s1, char const *s2)
Definition ft_strjoin.c:23

References exit_status_handler(), ft_strjoin(), handle_exit(), and NUMERIC_REQUIRED.

Referenced by builtin_exit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_too_many_args_error()

void handle_too_many_args_error ( t_ms_data data)

Definition at line 47 of file exit.c.

48{
51}

References exit_status_handler(), handle_exit(), and TOO_MANY_ARGS.

Referenced by builtin_exit().

Here is the call graph for this function:
Here is the caller graph for this function: