-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexport_utils.c
More file actions
65 lines (60 loc) · 1.73 KB
/
export_utils.c
File metadata and controls
65 lines (60 loc) · 1.73 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* export_utils.c :+: :+: */
/* +:+ */
/* By: sde-rijk <sde-rijk@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/01/25 10:47:39 by sde-rijk #+# #+# */
/* Updated: 2022/01/25 10:48:11 by sde-rijk ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "Libft/libft.h"
#include <termios.h>
#include <stdio.h>
int check_identifier(char *str, int unset)
{
int i;
i = 0;
if (ft_isdigit(str[0]) || str[0] == '=' || str[0] == '+')
return (1);
while (str[i])
{
if (str[i] == '+' && str[i + 1] == '=')
i++;
if (str[i] == '=')
{
if (unset)
return (1);
else
return (0);
}
if (!ft_isalnum(str[i]) && str[i] != '_')
return (1);
i++;
}
return (0);
}
void expand_env(t_env *s_env)
{
int i;
char **copy;
i = 0;
while (s_env->env[i])
i++;
if (i == s_env->size)
{
copy = ft_calloc((s_env->size + 11) * sizeof(char *), 1);
i = 0;
while (s_env->env[i])
{
copy[i] = ft_calloc(ft_strlen(s_env->env[i]) + 1, 1);
ft_memcpy(copy[i], s_env->env[i], ft_strlen(s_env->env[i]));
i++;
}
ft_free_env(s_env);
s_env->env = copy;
s_env->size += 10;
}
}