-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmin_remove_quotes.c
executable file
·90 lines (81 loc) · 2 KB
/
min_remove_quotes.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* min_remove_quotes.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pmoreno- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/06 13:01:20 by potero #+# #+# */
/* Updated: 2022/08/11 10:09:33 by pmoreno- ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void aux_strings(char **str, int i)
{
char *aux;
char *aux2;
aux = ft_substr(*str, 0, i);
aux2 = ft_substr(*str, i + 1, ft_strlen(*str) - i);
free(*str);
*str = ft_strjoin(aux, aux2);
free(aux);
free(aux2);
}
char *quotes(char *arg)
{
int i;
char c;
char *ret;
char *str;
str = ft_strdup(arg);
i = 0;
while (str[i])
{
if ((str[i] == 34) || (str[i] == 39))
{
c = str[i];
aux_strings(&str, i);
while (str[i] && str[i] != c)
i++;
aux_strings(&str, i);
}
i++;
}
free(str);
ret = ft_strdup(str);
return (ret);
}
static void aux_split(char **split)
{
char *str;
str = quotes(*split);
free(*split);
*split = ft_strdup(str);
free(str);
}
void remove_quotes(t_argv **argv)
{
int i;
char *str;
t_argv *aux;
aux = *argv;
while (aux)
{
i = 0;
if (ft_strchr(aux->arg, 34) != 0
|| ft_strchr(aux->arg, 39) != 0)
{
str = quotes(aux->arg);
free(aux->arg);
aux->arg = str;
}
while (aux->split[i])
{
if (ft_strchr(aux->split[i], 34) != 0
|| ft_strchr(aux->split[i], 39) != 0)
aux_split(&aux->split[i]);
i++;
}
aux = aux->next;
}
}