From a2545bb2e7458662a0a37a80e1ff106c78f4176f Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 27 Mar 2017 18:07:20 +0200 Subject: [PATCH] norme --- 42sh/libft/includes/cliopts.h | 9 ++++----- 42sh/src/builtin/builtin_cd.c | 4 ++-- 42sh/src/completion/completion.c | 4 ++-- 42sh/src/exec/redirect_dgreat.c | 5 ++--- 42sh/src/exec/redirect_less.c | 4 ++-- 42sh/src/history/history_parsing.c | 3 +-- 42sh/src/main/data_exit.c | 3 +-- 42sh/src/main/data_init.c | 16 +++++++++++----- 42sh/src/main/shell_fds.c | 6 +++--- 42sh/src/main/shell_init.c | 10 +++++----- 10 files changed, 33 insertions(+), 31 deletions(-) diff --git a/42sh/libft/includes/cliopts.h b/42sh/libft/includes/cliopts.h index 9ea82890..60ec9ec3 100644 --- a/42sh/libft/includes/cliopts.h +++ b/42sh/libft/includes/cliopts.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */ -/* Updated: 2017/03/25 14:59:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 17:59:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ typedef struct s_cliopts t_cliopts; typedef struct s_data_template t_data_template; typedef long long t_flag; -struct s_cliopts +struct s_cliopts { char c; char *str; @@ -30,15 +30,14 @@ struct s_cliopts int arg_required:1; }; -struct s_data_template +struct s_data_template { t_flag flag; char **av_data; }; -int cliopts_get(char **av, t_cliopts opt_map[], void *data); +int cliopts_get(char **av, t_cliopts opt_map[], void *data); t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg); t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg); -int cliopts_has(char **av, char c); #endif diff --git a/42sh/src/builtin/builtin_cd.c b/42sh/src/builtin/builtin_cd.c index af086139..99160c42 100644 --- a/42sh/src/builtin/builtin_cd.c +++ b/42sh/src/builtin/builtin_cd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 18:20:42 by ariard #+# #+# */ -/* Updated: 2017/03/25 21:23:11 by ariard ### ########.fr */ +/* Updated: 2017/03/27 18:00:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,7 @@ static t_cliopts g_cdopts[] = {0, NULL, 0, 0, NULL, 0}, }; -int cd_file_autorisations(char *target, int flag) +int cd_file_autorisations(char *target, int flag) { (void)flag; if (access(target, F_OK)) diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index 752ed3f5..74201f51 100644 --- a/42sh/src/completion/completion.c +++ b/42sh/src/completion/completion.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/09/20 14:50:33 by alao #+# #+# */ -/* Updated: 2017/03/27 09:30:40 by alao ### ########.fr */ +/* Updated: 2017/03/27 18:01:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ static void c_mv_tab(t_comp *c, int next) ptr->next->cursor = 1; else ptr->prev->cursor = 1; - } +} /* ** Once the completion has been processed, this is the return point. diff --git a/42sh/src/exec/redirect_dgreat.c b/42sh/src/exec/redirect_dgreat.c index a2d57f1c..62e79888 100644 --- a/42sh/src/exec/redirect_dgreat.c +++ b/42sh/src/exec/redirect_dgreat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:07:37 by jhalford #+# #+# */ -/* Updated: 2017/03/26 22:36:18 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:00:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,8 +22,7 @@ int redirect_dgreat(t_redir *redir) if ((try_access(redir->word, 0, W_OK))) return (ft_perror(NULL)); if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0) - exit (1); - + exit(1); fd_replace(fdold, fdnew); return (0); } diff --git a/42sh/src/exec/redirect_less.c b/42sh/src/exec/redirect_less.c index 0e24b2c7..bb5cc083 100644 --- a/42sh/src/exec/redirect_less.c +++ b/42sh/src/exec/redirect_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */ -/* Updated: 2017/03/27 01:02:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:00:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ int redirect_less(t_redir *redir) if ((try_access(redir->word, 1, R_OK)) != 0) return (ft_perror(NULL)); if ((fdold = open(redir->word, O_RDONLY, 0644)) < 0) - exit (1); + exit(1); fd_replace(fdold, fdnew); return (0); } diff --git a/42sh/src/history/history_parsing.c b/42sh/src/history/history_parsing.c index 2c7040f3..45e9eba7 100644 --- a/42sh/src/history/history_parsing.c +++ b/42sh/src/history/history_parsing.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */ -/* Updated: 2017/03/22 12:09:59 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 18:01:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,7 +41,6 @@ static int check_validity(char *str, int i) else if (!str[i + 1] || str[i + 1] == '"') return (0); return (1); - } static int history_parsing_nb_and_name(char *str, int *i) diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index bea98b57..1c5a6389 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ -/* Updated: 2017/03/27 16:04:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:02:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,6 @@ void data_exit(void) t_data *data; data = data_singleton(); - /* ft_strdel(&data->line.input); */ ft_strdel(&data->binary); ft_sstrfree(data->env); ft_sstrfree(data->local_var); diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 85205e8c..d8f7c41d 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/27 16:00:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:04:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,6 +66,15 @@ static int shlvl_inc(void) return (0); } +int modules_init(t_data *data) +{ + lexer_init(&data->lexer); + parser_init(&data->parser); + exec_init(&data->exec); + jobc_init(&data->jobc); + return (0); +} + int data_init(int ac, char **av, char **env) { t_data *data; @@ -80,13 +89,10 @@ int data_init(int ac, char **av, char **env) localenv_init(); if (shlvl_inc()) return (-1); + modules_init(data); data->comp = NULL; data->opts = SH_INTERACTIVE | SH_OPTS_JOBC; data->lst_func = NULL; - lexer_init(&data->lexer); - parser_init(&data->parser); - exec_init(&data->exec); - jobc_init(&data->jobc); if ((term_name = ft_getenv(data->env, "TERM")) == NULL) term_name = "dumb"; if (tgetent(NULL, term_name) != 1) diff --git a/42sh/src/main/shell_fds.c b/42sh/src/main/shell_fds.c index 8761e728..97487b80 100644 --- a/42sh/src/main/shell_fds.c +++ b/42sh/src/main/shell_fds.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/27 15:32:13 by jhalford #+# #+# */ -/* Updated: 2017/03/27 15:57:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:02:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,7 +56,7 @@ int shell_fds_pop(void) return (0); } -void shell_fds_reset(void) +void shell_fds_reset(void) { t_data *data; int i; @@ -72,7 +72,7 @@ void shell_fds_reset(void) } } -void shell_fds_destroy(void) +void shell_fds_destroy(void) { t_data *data; int i; diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 5397a51c..b3336442 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/27 16:04:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 18:06:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -89,10 +89,10 @@ int shell_init(int ac, char **av, char **env) if (data_init(ac, av, env) < 0) return (-1); if (cliopts_get(av, g_opts, data)) - return (ft_perror(NULL) - && SH_ERR("%s", SHELL_USAGE1) - && SH_ERR("%s", SHELL_USAGE2) - && SH_ERR("%s", SHELL_USAGE3)); + { + return (ft_perror(NULL) && SH_ERR("%s", SHELL_USAGE1) + && SH_ERR("%s", SHELL_USAGE2) && SH_ERR("%s", SHELL_USAGE3)); + } if (!isatty(STDIN) || *data->av_data) data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); if ((data->fd = get_input_fd(data, NULL)) < 0)