maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
exit_status.h File Reference
#include "shell.h"
#include <errno.h>
Include dependency graph for exit_status.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define EXIT_SUCCESS   0
 
#define EXIT_FAILURE   1
 
#define EXIT_MISUSE   2
 
#define IS_DIRECTORY   256
 
#define NUMERIC_REQUIRED   257
 
#define TOO_MANY_ARGS   258
 
#define UNKNOWN_COMMAND   259
 
#define INVALID_ARGUMENT   260
 
#define PERMISSION_DENIED   261
 
#define ERROR_EXIT   262
 
#define NOT_VALID_IDENTIFIER   263
 
#define INVALID_OPTION   264
 

Functions

void exit_status_handler (t_ms_data *data, int status_code, char *err_arg)
 
void set_exit_status (int *exit_status, int status_code)
 
void set_shell_var_handler (t_ms_data *data)
 
int ft_perror (char *str)
 
int ft_isnumber (char *str)
 
void free_shell_var_list (t_env *shell_var)
 

Macro Definition Documentation

◆ ERROR_EXIT

#define ERROR_EXIT   262

Definition at line 26 of file exit_status.h.

◆ EXIT_FAILURE

#define EXIT_FAILURE   1

Definition at line 17 of file exit_status.h.

◆ EXIT_MISUSE

#define EXIT_MISUSE   2

Definition at line 18 of file exit_status.h.

◆ EXIT_SUCCESS

#define EXIT_SUCCESS   0

Definition at line 16 of file exit_status.h.

◆ INVALID_ARGUMENT

#define INVALID_ARGUMENT   260

Definition at line 24 of file exit_status.h.

◆ INVALID_OPTION

#define INVALID_OPTION   264

Definition at line 28 of file exit_status.h.

◆ IS_DIRECTORY

#define IS_DIRECTORY   256

Definition at line 20 of file exit_status.h.

◆ NOT_VALID_IDENTIFIER

#define NOT_VALID_IDENTIFIER   263

Definition at line 27 of file exit_status.h.

◆ NUMERIC_REQUIRED

#define NUMERIC_REQUIRED   257

Definition at line 21 of file exit_status.h.

◆ PERMISSION_DENIED

#define PERMISSION_DENIED   261

Definition at line 25 of file exit_status.h.

◆ TOO_MANY_ARGS

#define TOO_MANY_ARGS   258

Definition at line 22 of file exit_status.h.

◆ UNKNOWN_COMMAND

#define UNKNOWN_COMMAND   259

Definition at line 23 of file exit_status.h.

Function Documentation

◆ exit_status_handler()

void exit_status_handler ( t_ms_data data,
int  status_code,
char *  err_arg 
)

Definition at line 25 of file exit_status.c.

26{
27 char *error_message;
28
29 error_message = NULL;
30 if (status_code == IS_DIRECTORY)
31 error_message = "No such file or directory";
32 else if (status_code == NUMERIC_REQUIRED)
33 error_message = "numeric argument required";
34 else if (status_code == TOO_MANY_ARGS)
35 error_message = "too many arguments";
36 else if (status_code == UNKNOWN_COMMAND)
37 error_message = "command not found";
38 else if (status_code == INVALID_ARGUMENT)
39 error_message = "invalid argument";
40 else if (status_code == PERMISSION_DENIED)
41 error_message = "permission denied";
42 else if (status_code == NOT_VALID_IDENTIFIER)
43 error_message = "unset: not a valid identifier";
44 else if (status_code == INVALID_OPTION)
45 error_message = "invalid option";
46 else
47 error_message = "error";
48 ft_puterror(err_arg, error_message);
49 set_exit_status(&data->exit_status, status_code);
51}
void ft_puterror(char *err_arg, char *error_message)
Definition exit_status.c:62
void set_shell_var_handler(t_ms_data *data)
Definition exit_status.c:53
void set_exit_status(int *exit_status, int status_code)
Definition exit_status.c:78
#define NUMERIC_REQUIRED
Definition exit_status.h:21
#define TOO_MANY_ARGS
Definition exit_status.h:22
#define NOT_VALID_IDENTIFIER
Definition exit_status.h:27
#define INVALID_OPTION
Definition exit_status.h:28
#define PERMISSION_DENIED
Definition exit_status.h:25
#define UNKNOWN_COMMAND
Definition exit_status.h:23
#define INVALID_ARGUMENT
Definition exit_status.h:24
#define IS_DIRECTORY
Definition exit_status.h:20
int exit_status
Definition shell.h:30

References s_ms_data::exit_status, ft_puterror(), INVALID_ARGUMENT, INVALID_OPTION, IS_DIRECTORY, NOT_VALID_IDENTIFIER, NUMERIC_REQUIRED, PERMISSION_DENIED, set_exit_status(), set_shell_var_handler(), TOO_MANY_ARGS, and UNKNOWN_COMMAND.

Referenced by builtin_cd(), builtin_export(), 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:

◆ free_shell_var_list()

void free_shell_var_list ( t_env shell_var)

Definition at line 90 of file shell_variables_utils.c.

91{
92 t_env *curr_node;
93 t_env *next_node;
94
95 curr_node = shell_var;
96 while (curr_node)
97 {
98 next_node = curr_node->next;
99 free(curr_node->key);
100 free(curr_node->value);
101 free(curr_node);
102 curr_node = next_node;
103 }
104}
Definition env.h:17
struct s_env * next
Definition env.h:20
char * key
Definition env.h:18
char * value
Definition env.h:19

References s_env::key, s_env::next, and s_env::value.

Referenced by free_ms_data().

Here is the caller graph for this function:

◆ ft_isnumber()

int ft_isnumber ( char *  str)

Definition at line 24 of file exit_status_utils.c.

25{
26 int i;
27
28 i = 0;
29 while (str[i])
30 {
31 if (!ft_isdigit(str[i]))
32 return (0);
33 i++;
34 }
35 return (1);
36}
int ft_isdigit(int c)
Definition ft_isdigit.c:13

References ft_isdigit().

Referenced by builtin_exit().

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

◆ ft_perror()

int ft_perror ( char *  str)

Definition at line 18 of file exit_status_utils.c.

19{
20 perror (str);
21 exit(EXIT_FAILURE);
22}
#define EXIT_FAILURE
Definition exit_status.h:17

◆ set_exit_status()

void set_exit_status ( int *  exit_status,
int  status_code 
)

Definition at line 78 of file exit_status.c.

79{
80 *exit_status = status_code;
81}

Referenced by builtin_env(), and exit_status_handler().

Here is the caller graph for this function:

◆ set_shell_var_handler()

void set_shell_var_handler ( t_ms_data data)

Definition at line 53 of file exit_status.c.

54{
55 char *tmp_var;
56
57 tmp_var = ft_itoa(data->exit_status);
58 set_shell_var(&data->shell_variables, "?", tmp_var);
59 free(tmp_var);
60}
void set_shell_var(t_env **shell_var, const char *key, const char *value)
char * ft_itoa(int n)
Definition ft_itoa.c:40
t_env * shell_variables
Definition shell.h:25

References s_ms_data::exit_status, ft_itoa(), set_shell_var(), and s_ms_data::shell_variables.

Referenced by exit_status_handler(), and new_process().

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