From 91e9df5721175e37ec87f8a5c996626d7f43148c Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sat, 25 Mar 2017 15:08:08 +0100 Subject: [PATCH] libft norme --- 42sh/libft/Makefile | 2 +- 42sh/libft/includes/cliopts.h | 4 +- 42sh/libft/src/cliopts/cliopts_get.c | 28 ++---------- .../{cliopts_has.c => cliopts_getmap.c} | 44 +++++++++---------- 42sh/libft/src/path/ft_path_notdir.c | 2 +- 42sh/libft/src/sys/create_directory.c | 4 +- 42sh/libft/src/sys/open_access.c | 4 +- 7 files changed, 34 insertions(+), 54 deletions(-) rename 42sh/libft/src/cliopts/{cliopts_has.c => cliopts_getmap.c} (56%) diff --git a/42sh/libft/Makefile b/42sh/libft/Makefile index 27ef1a47..7d483cd1 100644 --- a/42sh/libft/Makefile +++ b/42sh/libft/Makefile @@ -49,7 +49,7 @@ char/ft_isprint.c\ char/ft_tolower.c\ char/ft_toupper.c\ cliopts/cliopts_get.c\ -cliopts/cliopts_has.c\ +cliopts/cliopts_getmap.c\ color/ft_color_mk.c\ color/ft_color_mkif.c\ color/ft_color_reset.c\ diff --git a/42sh/libft/includes/cliopts.h b/42sh/libft/includes/cliopts.h index 0271655d..9ea82890 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 01:18:54 by wescande ### ########.fr */ +/* Updated: 2017/03/25 14:59:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,6 +37,8 @@ struct s_data_template }; 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/libft/src/cliopts/cliopts_get.c b/42sh/libft/src/cliopts/cliopts_get.c index aaa3b889..05e8a3f8 100644 --- a/42sh/libft/src/cliopts/cliopts_get.c +++ b/42sh/libft/src/cliopts/cliopts_get.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */ -/* Updated: 2017/03/25 04:06:39 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 15:00:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,28 +29,6 @@ static char *check_required(char ***av, char *arg) return (ret); } -static t_cliopts *get_map_long(t_cliopts opt_map[], char *arg) -{ - int i; - - i = -1; - while (opt_map[++i].c) - if (!ft_strcmp(opt_map[i].str, arg)) - return (&opt_map[i]); - return (NULL); -} - -static t_cliopts *get_map_short(t_cliopts opt_map[], char arg) -{ - int i; - - i = -1; - while (opt_map[++i].c) - if (opt_map[i].c == arg) - return (&opt_map[i]); - return (NULL); -} - static int cliopts_parse_short( char ***av, t_cliopts opt_map[], void *data) { @@ -63,7 +41,7 @@ static int cliopts_parse_short( i = -1; while (arg[++i] && !(tmp = NULL)) { - if (!(map = get_map_short(opt_map, arg[i]))) + if (!(map = cliopts_getmap_short(opt_map, arg[i]))) return (ERR_SET(E_CO_INV, arg[i])); ((t_data_template*)data)->flag |= map->flag_on; ((t_data_template*)data)->flag &= ~map->flag_off; @@ -90,7 +68,7 @@ static int cliopts_parse_long( arg = **av + 2; tmp = NULL; - if (!(map = get_map_long(opt_map, arg))) + if (!(map = cliopts_getmap_long(opt_map, arg))) return (ERR_SET(E_CO_INVL, arg)); ((t_data_template*)data)->flag |= map->flag_on; ((t_data_template*)data)->flag &= ~map->flag_off; diff --git a/42sh/libft/src/cliopts/cliopts_has.c b/42sh/libft/src/cliopts/cliopts_getmap.c similarity index 56% rename from 42sh/libft/src/cliopts/cliopts_has.c rename to 42sh/libft/src/cliopts/cliopts_getmap.c index 9cc120b8..189e22ba 100644 --- a/42sh/libft/src/cliopts/cliopts_has.c +++ b/42sh/libft/src/cliopts/cliopts_getmap.c @@ -1,35 +1,35 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* cliopts_has.c :+: :+: :+: */ +/* cliopts_getmap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/14 20:03:18 by jhalford #+# #+# */ -/* Updated: 2017/03/20 15:48:57 by jhalford ### ########.fr */ +/* Created: 2017/03/25 14:59:03 by jhalford #+# #+# */ +/* Updated: 2017/03/25 15:01:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "cliopts.h" -int cliopts_has(char **av, char c) +t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg) { - if (!av) - return (0); - while (*av) - { - if (ft_strcmp(*av, "--") == 0) - return (0); - else if ((*av)[0] == '-' && (*av)[1] == '-') - av++; - else if ((*av)[0] == '-') - { - if (ft_strchr(*av + 1, c)) - return (1); - av++; - } - else - return (0); - } - return (0); + int i; + + i = -1; + while (opt_map[++i].c) + if (!ft_strcmp(opt_map[i].str, arg)) + return (&opt_map[i]); + return (NULL); +} + +t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg) +{ + int i; + + i = -1; + while (opt_map[++i].c) + if (opt_map[i].c == arg) + return (&opt_map[i]); + return (NULL); } diff --git a/42sh/libft/src/path/ft_path_notdir.c b/42sh/libft/src/path/ft_path_notdir.c index e02c836e..b59044f3 100644 --- a/42sh/libft/src/path/ft_path_notdir.c +++ b/42sh/libft/src/path/ft_path_notdir.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */ -/* Updated: 2016/12/07 15:22:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 15:03:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/sys/create_directory.c b/42sh/libft/src/sys/create_directory.c index 10b4bdbe..bf2b0e44 100644 --- a/42sh/libft/src/sys/create_directory.c +++ b/42sh/libft/src/sys/create_directory.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 03:18:18 by ariard #+# #+# */ -/* Updated: 2017/03/25 04:13:15 by ariard ### ########.fr */ +/* Updated: 2017/03/25 15:03:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ char *create_directory(const char *path, const char *old_pathnames) if (!is_directory(newdir = ft_str3join(new_pathnames, "/", path))) ft_strdel(&newdir); else - break; + break ; new_pathnames += ft_strlen(new_pathnames) + 1; } ft_strdel(&temp); diff --git a/42sh/libft/src/sys/open_access.c b/42sh/libft/src/sys/open_access.c index 0d77b423..40811fe7 100644 --- a/42sh/libft/src/sys/open_access.c +++ b/42sh/libft/src/sys/open_access.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */ -/* Updated: 2017/03/25 02:26:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 15:07:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm) { int fd; - if (a_flag & F_OK && access(file, F_OK) != 0) + if (a_flag & F_OK && access(file, F_OK) != 0) return (-ERR_SET(E_SYS_NOFILE, file)); if (is_directory(file)) return (-ERR_SET(E_SYS_ISDIR, file));