-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpansions_special_chars_errors.c
93 lines (83 loc) · 2.42 KB
/
expansions_special_chars_errors.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
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* expansions_special_chars_errors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ngasco <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/29 15:26:03 by ngasco #+# #+# */
/* Updated: 2022/03/29 15:26:04 by ngasco ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/* Check if two adjacent nodes are both special chars */
int ft_found_adjacent_special_chars(t_cdata *t_cdata)
{
struct s_qnode *curr;
curr = t_cdata->t_qdata->quotes_list;
while (1)
{
if (curr->next)
{
if ((ft_is_special_str(curr->str)
&& ft_is_special_str(curr->next->str)
&& !curr->next->q_type)
|| ft_found_adjecent_pipes(curr->str))
return (1);
}
if (curr->next == NULL || curr->next->next == NULL)
break ;
else
curr = curr->next;
}
return (0);
}
/* Check if node contains special char */
int ft_is_special_str(char *str)
{
if (!ft_strcmp(str, ">") || !ft_strcmp(str, "<") || !ft_strcmp(str, ">>")
|| !ft_strcmp(str, "<<") || !ft_strcmp(str, "|"))
return (1);
return (0);
}
/* Check if string contains two pipes */
int ft_found_adjecent_pipes(char *str)
{
int i;
i = 0;
if (!ft_strlen(str))
return (0);
while (str[i + 1] != '\0')
{
if (str[i] == '|' && str[i + 1] == '|')
return (1);
i++;
}
return (0);
}
/* Check if list has only one node and it's a special char */
int ft_last_node_is_special_char(t_cdata *t_cdata)
{
struct s_qnode *curr;
curr = t_cdata->t_qdata->quotes_list;
while (1)
{
if (curr->next == NULL && ft_is_special_str(curr->str)
&& !curr->q_type)
return (1);
if (curr->next == NULL)
break ;
else
curr = curr->next;
}
return (0);
}
/* Check if first node is a pipe */
int ft_first_node_is_pipe(t_cdata *t_cdata)
{
struct s_qnode *curr;
curr = t_cdata->t_qdata->quotes_list;
if (!strncmp(curr->str, "|", 1))
return (1);
return (0);
}