Repository navigation
Expand file tree
/
Copy pathutils3.c
More file actions
96 lines (86 loc) · 1.93 KB
/
Copy pathutils3.c
File metadata and controls
96 lines (86 loc) · 1.93 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
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
94
95
96
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: esekouni <esekouni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/12 19:00:24 by esekouni #+# #+# */
/* Updated: 2023/06/22 16:22:02 by esekouni ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_lstsize(t_environment_path *export)
{
int i;
t_environment_path *exp;
i = 0;
exp = export;
while (exp)
{
i++;
exp = exp->next;
}
return (i);
}
char *add_double_cotes(char *str)
{
int i;
int len;
char *ch;
i = 0;
len = ft_strlen(str);
ch = malloc(sizeof(char) * (len + 3));
if (!ch)
return (NULL);
ch[0] = '"';
while (str[i])
{
ch[i + 1] = str[i];
i++;
}
ch[i + 1] = '"';
i++;
ch[i + 1] = '\0';
return (ch);
}
int check_dollar(char *ch)
{
int i;
i = 0;
while (ch && ch[i] != '\0')
{
if (ch[i] == '$')
return (1);
i++;
}
return (0);
}
int check_valid_caractr(char c)
{
if (ft_isalnum(c) == 0)
{
if (c == '_')
return (0);
else
return (1);
}
return (0);
}
char *found_valeur_variable(t_environment_path *expo, char *variable)
{
t_environment_path *export;
char *valeur;
export = expo;
valeur = NULL;
while (export)
{
if (ft_strcmp(export->variable, variable) == 0)
{
valeur = ft_strdup(export->valeur);
break ;
}
export = export->next;
}
return (valeur);
}