-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplitermux_utils_0.c
81 lines (75 loc) · 1.97 KB
/
splitermux_utils_0.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* splitermux_utils_0.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggiannit <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/23 17:32:41 by ggiannit #+# #+# */
/* Updated: 2023/04/13 17:38:36 by ggiannit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_iscut(char c)
{
if (!c || c == 32 || c == '|' || c == '<' || c == '>')
return (1);
return (0);
}
static int ft_count_word_skip(char *str, int *i)
{
while (str[*i] && str[*i] != 32)
{
if (str[*i] && str[*i] == SQUT)
{
*i += 1;
while (str[*i] && str[*i] != SQUT)
*i += 1;
}
if (str[*i] && str[*i] == DQUT)
{
*i += 1;
while (str[*i] && str[*i] != DQUT)
*i += 1;
}
if (str[*i] == '|')
return (0);
*i += 1;
}
return (1);
}
static void ft_count_word_iter(char *str, int *i)
{
while ((str[*i] && str[*i] == '>') || (str[*i] && str[*i] == '<'))
{
if (str[*i] == '>' && str[*i + 1] == '>')
*i += 2;
else if (str[*i] == '<' && str[*i + 1] == '<')
*i += 2;
else
*i += 1;
while (str[*i] == 32)
*i += 1;
while (!ft_iscut(str[*i]))
*i += 1;
}
}
int ft_count_word_mux(char *str)
{
int i;
int word;
i = 0;
word = 1;
if (!str)
return (1);
while (str && str[i])
{
while (str[i] && str[i] == 32)
i++;
ft_count_word_iter(str, &i);
if (!ft_count_word_skip(str, &i))
return (word);
word++;
}
return (word);
}