-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexpand_utils.c
84 lines (76 loc) · 1.91 KB
/
expand_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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* expand_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: csweetin <csweetin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/29 17:42:17 by csweetin #+# #+# */
/* Updated: 2024/05/03 18:26:31 by csweetin ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
int search_dollar(char **data)
{
size_t i;
size_t j;
i = 0;
if (!data)
return (0);
while (data[i])
{
j = 0;
while (data[i][j])
{
if (data[i][j] == '$')
return (1);
else if (data[i][j])
j++;
}
i++;
}
return (0);
}
static int ft_strcmp_env(char *data, char *env)
{
size_t i;
i = 0;
while (data[i] && env[i] && env[i] != '='
&& (ft_isalnum(data[i]) || data[i] == '_'))
{
if (data[i] != env[i])
return (1);
i++;
}
if (env[i] && env[i] != '=')
return (1);
if (data[i] && (ft_isalnum(data[i]) || data[i] == '_'))
return (1);
return (0);
}
char *search_env(char *data, t_env **env)
{
t_env *node;
size_t i;
i = 0;
node = *env;
while (node)
{
if (!ft_strcmp_env(data, node->env))
{
while (node->env[i] && node->env[i] != '=')
i++;
i++;
if (node->env[i] == '\0')
return (NULL);
return (node->env + i);
}
node = node->next;
}
return (NULL);
}
void nb_letter_status(size_t *letter, size_t *j, char *status)
{
*j += 1;
*letter += ft_strlen(status);
}