-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize.c
66 lines (61 loc) · 1.93 KB
/
initialize.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* initialize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ulyildiz <ulyildiz@student.42kocaeli.com.t +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 11:33:18 by ulyildiz #+# #+# */
/* Updated: 2024/05/23 11:33:18 by ulyildiz ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "functions.h"
#include "42-libft/libft.h"
#include <stdio.h>
static int prompt(t_main *shell)
{
shell->prompt = ft_strdup("ft_sh-> ");
if (!shell->prompt)
return (0);
return (1);
}
static int init_env(t_main *shell, char **env)
{
t_env *tmp;
char **s;
shell->envs = NULL;
while (*env)
{
tmp = (t_env *)malloc(sizeof(t_env));
if (!tmp)
return (free_env(shell->envs), 0);
s = ft_split(*env, '=');
if (!s)
return (free(tmp), free_env(shell->envs), 0);
tmp->name = s[0];
tmp->value = s[1];
tmp->next = NULL;
list_add_back(&(shell->envs), tmp);
free(s);
env++;
}
return (1);
}
int initialize(t_main *shell, char **env)
{
shell->cmd = NULL;
shell->token = NULL;
shell->paths = NULL;
shell->envs = NULL;
shell->cmd_line = NULL;
shell->prompt = NULL;
shell->paths = NULL;
if (!prompt(shell))
return (0);
if (!init_env(shell, env))
return (free(shell->prompt), 0);
shell->control = 1;
shell->env_for_execve_function = env;
return (1);
}