-
Notifications
You must be signed in to change notification settings - Fork 0
/
int_minishell.c
66 lines (59 loc) · 1.81 KB
/
int_minishell.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* int_minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hel-hich <hel-hich@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/26 01:46:40 by hel-hich #+# #+# */
/* Updated: 2022/11/26 20:50:28 by hel-hich ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "env/env.h"
t_sh g_sh;
int creat_env(char **env)
{
char *name;
t_envir *t_envir;
t_lst *lst;
while (*env)
{
name = ft_strsep(&*env, "=");
t_envir = envr_init(name, *env);
lst = ft_lstnew(t_envir);
if (!t_envir || !lst)
return (env_free(t_envir), free(lst), -1);
lst_put_orderly_new(&g_sh.lst_env, lst, (t_cmpfn)comp_env);
env++;
}
return (0);
}
int shlvl_env(void)
{
char *val;
val = ft_env("SHLVL");
if (val)
{
val = ft_itoa(ft_atoi(val) + 1);
if (!val || envr_set("SHLVL", val))
return (free(val), -1);
free(val);
}
else
if (envr_set("SHLVL", "1"))
return (-1);
return (0);
}
int int_minishell(int ac, char **av, char **env)
{
g_sh.ac = ac;
g_sh.av = av;
g_sh.exec = 0;
g_sh.exit_s = 0;
g_sh.lst_env = NULL;
if (creat_env(env) || shlvl_env() || envr_set("SHELL", av[0]))
return (perror("minishell"),
ft_lstclear(&g_sh.lst_env, (t_delfn)env_free), -1);
return (0);
}