Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2024 | ||
3 | ** 42sh | ||
4 | ** File description: | ||
5 | ** The file containing the redirections functions | ||
6 | */ | ||
7 | /** | ||
8 | * @file redirections.c | ||
9 | * @brief The file containing the redirections functions | ||
10 | */ | ||
11 | |||
12 | #include "../../include/myshell.h" | ||
13 | |||
14 | /** | ||
15 | * @brief Browse the command line to get the redirection path | ||
16 | * @param line The command line | ||
17 | * @return <b>char *</b> The redirection path | ||
18 | */ | ||
19 | ✗ | char *get_redirection_path(char *line) | |
20 | { | ||
21 | ✗ | char *path = CALLOC(my_strlen(line), sizeof(char)); | |
22 | ✗ | int start = 0; | |
23 | |||
24 | ✗ | for (int index = 0; line[index] != '\0'; index++) { | |
25 | ✗ | if (line[index] == '<' || line[index] == '>' || line[index] == '|') | |
26 | ✗ | return path; | |
27 | ✗ | if (start > 0 && (line[index] == ' ' || line[index] == '\t' || | |
28 | ✗ | line[index] == '\n')) | |
29 | ✗ | return path; | |
30 | ✗ | if (line[index] != ' ' && line[index] != '\t' && line[index] != '\n') { | |
31 | ✗ | path[start] = line[index]; | |
32 | ✗ | start++; | |
33 | } | ||
34 | } | ||
35 | ✗ | return path; | |
36 | } | ||
37 | |||
38 | /** | ||
39 | * @brief Display the error message when the name is missing | ||
40 | * @param mysh The shell structure | ||
41 | * @param commands The command line | ||
42 | * @return <b>int</b> Always <u>1</u> | ||
43 | */ | ||
44 | ✗ | int missing_name(mysh_t *mysh, char **commands) | |
45 | { | ||
46 | ✗ | mysh->exit_status = 1; | |
47 | ✗ | my_putstr_error("Missing name for redirect.\n"); | |
48 | ✗ | FREE_WORD_ARRAY(commands); | |
49 | ✗ | return 1; | |
50 | } | ||
51 | |||
52 | /** | ||
53 | * @brief Analyse and execute the good redirection | ||
54 | * @param mysh The shell structure | ||
55 | * @param input The input command | ||
56 | * @return <b>void</b> | ||
57 | */ | ||
58 | 1128 | void select_redirections(mysh_t *mysh, input_command_t *input) | |
59 | { | ||
60 |
2/2✓ Branch 0 taken 83 times.
✓ Branch 1 taken 1045 times.
|
1128 | if (input->right_type != 0) |
61 | 83 | return exec_right_redirection(mysh, input); | |
62 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1030 times.
|
1045 | if (input->left_type == 1) |
63 | 15 | return exec_left_simple_redirection(mysh, input); | |
64 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1025 times.
|
1030 | if (input->left_type == 2) |
65 | 5 | return exec_left_double_redirection(mysh, input); | |
66 | 1025 | return analyse_parentheses(mysh, input); | |
67 | } | ||
68 |