Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** 42sh | ||
4 | ** File description: | ||
5 | ** The file containing the unalias builtin | ||
6 | */ | ||
7 | /** | ||
8 | * @file unalias.c | ||
9 | * @brief The file containing the unalias builtin | ||
10 | */ | ||
11 | |||
12 | #include "../../include/myshell.h" | ||
13 | |||
14 | /** | ||
15 | * @brief Remove an alias from the alias list | ||
16 | * @param mysh The shell structure | ||
17 | * @param index The index of the alias to remove | ||
18 | * @return <b>void</b> | ||
19 | */ | ||
20 | 11 | static void unlink_alias(mysh_t *mysh, int index) | |
21 | { | ||
22 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | for (node_t *tmp = mysh->alias_list; tmp != NULL; tmp = tmp->next) { |
23 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | if (my_strcmp(((alias_t *)tmp->data)->name, mysh->args[index]) == 0) { |
24 | 11 | my_free_ptr(my_previous_to_next(&mysh->alias_list, tmp)); | |
25 | 11 | return; | |
26 | } | ||
27 | } | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * @brief The unalias builtin | ||
32 | * @param mysh The shell structure | ||
33 | * @return <b>int</b> <u>0</u> if the command succeed, <u>1</u> otherwise | ||
34 | */ | ||
35 | 11 | int exec_unalias(mysh_t *mysh) | |
36 | { | ||
37 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (mysh->args[1] == NULL) { |
38 | ✗ | my_putstr_error("unalias: Too few arguments.\n"); | |
39 | ✗ | return 1; | |
40 | } | ||
41 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 11 times.
|
22 | for (int index = 1; mysh->args[index] != NULL; index++) |
42 | 11 | unlink_alias(mysh, index); | |
43 | 11 | return 0; | |
44 | } | ||
45 |