|
6 | 6 | /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ |
7 | 7 | /* +#+#+#+#+#+ +#+ */ |
8 | 8 | /* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */ |
9 | | -/* Updated: 2024/02/21 17:43:52 by marde-vr ### ########.fr */ |
| 9 | +/* Updated: 2024/03/06 09:10:11 by marde-vr ### ########.fr */ |
10 | 10 | /* */ |
11 | 11 | /* ************************************************************************** */ |
12 | 12 |
|
13 | 13 | #include "minishell.h" |
14 | 14 |
|
15 | | -void print_numeric_arg_err(char *arg) |
| 15 | +void numeric_arg_err(char *arg, int *exit_code) |
16 | 16 | { |
17 | 17 | ft_putstr_fd("minishell: exit: ", 2); |
18 | 18 | ft_putstr_fd(arg, 2); |
19 | 19 | ft_putstr_fd(": numeric argument required\n", 2); |
| 20 | + *exit_code = 2; |
20 | 21 | } |
21 | 22 |
|
22 | 23 | void exit_bt(t_msh *msh) |
23 | 24 | { |
24 | | - t_cmd *start; |
| 25 | + t_cmd *cur_cmd; |
25 | 26 | int exit_code; |
26 | 27 |
|
27 | | - start = msh->cmds; |
28 | | - msh->cmds = msh->cmds->next; |
| 28 | + cur_cmd = msh->cmds->next; |
29 | 29 | ft_printf("exit\n"); |
30 | | - if (msh->cmds && msh->cmds->next && msh->cmds->next->type == ARG |
31 | | - && ft_strisnbr(msh->cmds->token)) |
| 30 | + if (cur_cmd && cur_cmd->next && cur_cmd->next->type == ARG |
| 31 | + && ft_strisnbr(cur_cmd->token)) |
| 32 | + { |
32 | 33 | ft_putstr_fd("minishell: exit: too many arguments\n", 2); |
| 34 | + g_return_code = 1; |
| 35 | + } |
33 | 36 | else |
34 | 37 | { |
35 | | - if (msh->cmds && msh->cmds->type == ARG |
36 | | - && !ft_strisnbr(msh->cmds->token)) |
37 | | - print_numeric_arg_err(msh->cmds->token); |
38 | | - if (msh->cmds && msh->cmds->type == ARG) |
39 | | - exit_code = (unsigned char)ft_atoi(msh->cmds->token); |
40 | | - else if (msh->cmds && msh->cmds->type == ARG |
41 | | - && !ft_strisnbr(msh->cmds->token)) |
42 | | - exit_code = 2; |
| 38 | + if (cur_cmd && cur_cmd->type == ARG |
| 39 | + && !ft_strisnbr(cur_cmd->token)) |
| 40 | + numeric_arg_err(cur_cmd->token, &exit_code); |
| 41 | + else if (cur_cmd && cur_cmd->type == ARG) |
| 42 | + exit_code = (unsigned char)ft_atoi(cur_cmd->token); |
43 | 43 | else |
44 | 44 | exit_code = g_return_code; |
45 | | - free_cmd(start); |
46 | 45 | free_msh(msh); |
47 | 46 | exit(exit_code); |
48 | 47 | } |
|
0 commit comments