-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_0.c
75 lines (67 loc) · 2.14 KB
/
init_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_0.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ngasco <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/14 11:21:09 by ngasco #+# #+# */
/* Updated: 2022/03/14 11:21:11 by ngasco ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/* Init and reset data required at beginning of every loop */
void ft_init_reset_loop_data(t_cdata *t_cdata)
{
t_cdata->syntax_error = 0;
t_cdata->tokens_list = NULL;
t_cdata->found_here_doc = 0;
ft_init_quotes_data(t_cdata);
}
// Structure with global data
void ft_init_general_data(t_cdata *c_data, char **envp)
{
memset(c_data, 0, sizeof(t_cdata));
init_envp(envp, c_data);
ft_init_prompt_data(c_data);
init_export(c_data);
}
/* Structure containing information on quotes */
void ft_init_quotes_data(t_cdata *t_cdata)
{
t_cdata->t_qdata = (t_qdata *)malloc(sizeof(t_qdata));
memset(t_cdata->t_qdata, 0, sizeof(t_qdata));
}
void init_envp(char **envp, t_cdata *t_cdata)
{
int i;
i = 0;
while (envp[i])
i++;
t_cdata->envp = (char **)malloc(sizeof(char *) * (i + 1));
i = -1;
while (envp[++i])
t_cdata->envp[i] = ft_strdup(envp[i]);
t_cdata->envp[i] = NULL;
}
void init_export(t_cdata *t_cdata)
{
int i;
char *string;
i = 0;
while (t_cdata->envp[i])
i++;
t_cdata->envp_export = malloc(sizeof(char *) * (i));
i = 0;
if (t_cdata->envp[i])
{
while (t_cdata->envp[i + 1])
{
string = ms_make_string(t_cdata->envp[i]);
t_cdata->envp_export[i] = ft_strdup(string);
free(string);
i++;
}
}
t_cdata->envp_export[i] = NULL;
}