-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_joinargs.c
More file actions
61 lines (56 loc) · 1.78 KB
/
ft_joinargs.c
File metadata and controls
61 lines (56 loc) · 1.78 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_joinargs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sid-bell <sid-bell@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/04 00:33:37 by sid-bell #+# #+# */
/* Updated: 2019/02/23 05:31:59 by sid-bell ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static int ft_helper1(char *str, int r)
{
while (r >= 0)
{
if (str[r] == '\"' || str[r] == '\'' || ft_isspace(str[r]))
break ;
r--;
}
return (r);
}
static void ft_helper2(char c, t_bool *qoute)
{
if (c == '\'')
qoute[0] = !qoute[0];
else if (c == '\"')
qoute[1] = !qoute[1];
}
char *ft_joinargs(char **str, char *result)
{
int i[2];
t_bool qoute[2];
char c;
qoute[0] = 0;
qoute[1] = 0;
i[0] = -1;
result = ft_strdup(*str);
free(*str);
while (result[++i[0]])
{
if (!qoute[0] && !qoute[1] && !ft_isspace(result[i[0]]) &&
(result[i[0] + 1] == '\"' || result[i[0] + 1] == '\''))
{
i[1] = ft_helper1(result, i[0]);
c = result[i[0] + 1];
result = ft_delchar(&result, i[0] + 1);
result = ft_insertchar(&result, c, i[1] + 1);
qoute[0] = c == '\'' ? 1 : 0;
qoute[1] = c == '\"' ? 1 : 0;
i[0]++;
}
ft_helper2(result[i[0]], qoute);
}
return (result);
}