-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshell_split_utils.c
46 lines (40 loc) · 1.76 KB
/
shell_split_utils.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* shell_split_utils.c :+: :+: */
/* +:+ */
/* By: daniel <[email protected]> +#+ */
/* +#+ */
/* Created: 2021/12/23 15:05:47 by daniel #+# #+# */
/* Updated: 2022/01/18 10:04:14 by sde-rijk ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "Libft/libft.h"
int new_part_required(int i, t_part *parts)
{
return (i == 0 || (parts[i - 1].type == SPACES || \
(parts[i - 1].type == NORMAL && parts[i].type == NORMAL) || \
parts[i - 1].type == SPECIAL));
}
void add_special_outpart(t_part part, t_part *outparts, int *j,
int **wild_quoted)
{
outparts[++(*j)].part = ft_calloc(1, 1);
wild_quoted[(*j)] = ft_calloc(ft_strlen(part.part), sizeof(int));
ft_strjoin_free(&(outparts[(*j)].part), part.part);
outparts[(*j)].type = SPECIAL;
}
void set_quotes(t_part part, int j, int length, int **wild_quoted)
{
int k;
k = 0;
while (k < (int)ft_strlen(part.part))
*(wild_quoted[j] + length + k++) = (part.type == SINGLE_QUOTED
|| part.type == DOUBLE_QUOTED);
}
void calloc_2(t_part *outparts, int **wild_quoted, int *j)
{
outparts[++(*j)].part = ft_calloc(1, 1);
wild_quoted[(*j)] = ft_calloc(1, sizeof(int));
}