| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2024 | ||
| 3 | ** 42sh | ||
| 4 | ** File description: | ||
| 5 | ** The file containing the echo builtin | ||
| 6 | */ | ||
| 7 | /** | ||
| 8 | * @file echo.c | ||
| 9 | * @brief The file containing the echo builtin | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include "../../include/myshell.h" | ||
| 13 | |||
| 14 | /** | ||
| 15 | * @brief The echo builtin | ||
| 16 | * @param mysh The shell structure | ||
| 17 | * @return <b>int</b> The exit status of the echo command | ||
| 18 | */ | ||
| 19 | 23 | int exec_echo(mysh_t *mysh) | |
| 20 | { | ||
| 21 | 23 | char **tmp = globbing(mysh->args); | |
| 22 | 23 | int index = 1; | |
| 23 | |||
| 24 |
2/4✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
|
23 | if (tmp == NULL || tmp[0] == NULL) |
| 25 | ✗ | return 1; | |
| 26 | 23 | mysh->args = my_malloc_strdup_word_array(tmp); | |
| 27 | 23 | FREE(tmp); | |
| 28 |
3/4✓ Branch 0 taken 20 times.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
|
23 | if (mysh->args[1] != NULL && my_strcmp(mysh->args[1], "-n") == 0) |
| 29 | ✗ | index = 2; | |
| 30 |
2/2✓ Branch 0 taken 5674 times.
✓ Branch 1 taken 23 times.
|
5697 | for (; mysh->args[index] != NULL; index++) { |
| 31 | 5674 | my_putstr(mysh->args[index]); | |
| 32 |
2/2✓ Branch 0 taken 5654 times.
✓ Branch 1 taken 20 times.
|
5674 | if (mysh->args[index + 1] != NULL) |
| 33 | 5654 | my_putchar(' '); | |
| 34 | } | ||
| 35 |
3/4✓ Branch 0 taken 20 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
|
23 | if (mysh->args[1] == NULL || my_strcmp(mysh->args[1], "-n") != 0) |
| 36 | 23 | my_putchar('\n'); | |
| 37 | 23 | return 0; | |
| 38 | } | ||
| 39 |