norme on data_init

This commit is contained in:
wescande 2017-03-24 17:13:11 +01:00
parent bf093784d3
commit 1c213a5f11
4 changed files with 14 additions and 22 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/03/24 13:35:44 by wescande ### ########.fr */ /* Updated: 2017/03/24 17:11:16 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -57,9 +57,9 @@ struct s_data
}; };
t_data *data_singleton(); t_data *data_singleton();
int shell_init(int ac, char **av); int shell_init(int ac, char **av, char **env);
void shell_exit(void); void shell_exit(void);
int data_init(int ac, char **av); int data_init(int ac, char **av, char **env);
void data_exit(void); void data_exit(void);
int get_c_arg(char ***av, t_data *data); int get_c_arg(char ***av, t_data *data);

View file

@ -6,14 +6,12 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/24 16:27:51 by gwojda ### ########.fr */ /* Updated: 2017/03/24 17:12:51 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
extern char **environ;
static int path_binary_save(char *binary) static int path_binary_save(char *binary)
{ {
char *directory; char *directory;
@ -68,7 +66,7 @@ static int shlvl_inc(void)
return (0); return (0);
} }
int data_init(int ac, char **av) int data_init(int ac, char **av, char **env)
{ {
t_data *data; t_data *data;
char *term_name; char *term_name;
@ -76,7 +74,7 @@ int data_init(int ac, char **av)
data = data_singleton(); data = data_singleton();
data->argc = ac; data->argc = ac;
data->argv = ft_sstrdup(av); data->argv = ft_sstrdup(av);
data->env = ft_sstrdup(environ); data->env = ft_sstrdup(env);
data->c_arg = NULL; data->c_arg = NULL;
set_exitstatus(0, 1); set_exitstatus(0, 1);
localenv_init(); localenv_init();
@ -91,14 +89,8 @@ int data_init(int ac, char **av)
if ((term_name = ft_getenv(data->env, "TERM")) == NULL) if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
term_name = "dumb"; term_name = "dumb";
if (tgetent(NULL, term_name) != 1) if (tgetent(NULL, term_name) != 1)
{ return (SH_ERR("TERM name is not a tty") ? -1 : -1);
SH_ERR("TERM name is not a tty");
return (-1);
}
if (path_binary_save(av[0])) if (path_binary_save(av[0]))
{ return (SH_ERR("Failed to resolve binary name") ? -1 : -1);
SH_ERR("Failed to resolve binary name");
return (-1);
}
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
/* Updated: 2017/03/24 15:30:51 by jhalford ### ########.fr */ /* Updated: 2017/03/24 17:11:37 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -58,7 +58,7 @@ static int handle_instruction(t_list **token, t_btree **ast)
return (0); return (0);
} }
int main(int ac, char **av) int main(int ac, char **av, char **env)
{ {
int ret; int ret;
t_data *data; t_data *data;
@ -67,7 +67,7 @@ int main(int ac, char **av)
g_argv = av; g_argv = av;
DG("----------------"); DG("----------------");
if (shell_init(ac, av) != 0) if (shell_init(ac, av, env) != 0)
return (1); return (1);
token = NULL; token = NULL;
ast = NULL; ast = NULL;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2017/03/24 17:05:29 by wescande ### ########.fr */ /* Updated: 2017/03/24 17:11:20 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -79,12 +79,12 @@ static int interactive_settings(void)
return (0); return (0);
} }
int shell_init(int ac, char **av) int shell_init(int ac, char **av, char **env)
{ {
t_data *data; t_data *data;
data = data_singleton(); data = data_singleton();
if (data_init(ac, av) < 0) if (data_init(ac, av, env) < 0)
return (-1); return (-1);
if (cliopts_get(av, g_opts, data)) if (cliopts_get(av, g_opts, data))
{ {