summaryrefslogtreecommitdiffstats
path: root/src/m_minishell.c
blob: c5901dbaf8ace8cf42545cc9fa33a41070b8b6dc (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   m_minishell.c                                      :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:19:27 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/14 17:19:29 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include "f_fail.h"
#include "m_argv.h"
#include "s_struct.h"
#include "s_init.h"
#include "s_destroy.h"
#include "u_vars.h"
#include "u_vars_next.h"

int
	main(int argc,
		char *const argv[],
		char *const envp[])
{
	int32_t	ret;
	char	*str;
	t_msh	*msh;

	/* TODO: also set $SHELL | maybe not bash does not set $SHELL */
	/* only zsh does */
	/* TODO: handle general variables | $var */
	if (!(msh = init_msh(argv, envp)))
	{
		ft_dprintf(2, "%s\n", strerror(errno));
		return (FT_RET_ALLOC);
	}
	u_subst_var_value("$SHLVL", str = ft_itoa(ft_atoi(u_get_var_value("$SHLVL", msh)) + 1), msh);
	ft_memdel((void*)&str);
	ret = m_argv(argc, argv, msh);
	s_destroy(msh);
	return (ret);
}

/*
** ====== INFO ======
** Files prefixes info
** -------------------
** b_  -> builtins related
** d_  -> defines related
** e_  -> exec related
** f_  -> failure related
** m_  -> core minishell related
** p_  -> parse related
** s_  -> structs related
** u_  -> utils related
** v_  -> general purpose variables related
*/