-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredir_utils1.c
60 lines (56 loc) · 1.67 KB
/
redir_utils1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redir_utils1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bpisak-l <bpisak-l@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/20 11:49:03 by bpisak-l #+# #+# */
/* Updated: 2024/07/25 12:10:43 by bpisak-l ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *get_filename(char *filename, int index)
{
char *fn;
char *temp;
char **parts;
temp = expand_variables(filename, "\'\"");
parts = str_split(temp, " \t", "\"\'");
fn = remove_chars(temp, "\"\'");
free(temp);
replace_special_chars(fn);
if (ft_arr_len(parts) > 1)
{
set_mini_error(filename, 1, "ambiguous redirect");
state()->pipeline[index].redir.invalid = 1;
}
free_split_arr(parts);
return (fn);
}
void try_get_token(char *token, char *str, int *i)
{
ft_memset(token, 0, 8);
if (!str || !str[*i])
return ;
if (str[*i] == '>')
{
token[0] = '>';
*i = *i + 1;
if (str[*i] == '>')
{
token[1] = '>';
*i = *i + 1;
}
}
else if (str[*i] == '<')
{
token[0] = '<';
*i = *i + 1;
if (str[*i] == '<')
{
token[1] = '<';
*i = *i + 1;
}
}
}