libft norme

This commit is contained in:
Jack Halford 2017-03-25 15:08:08 +01:00
parent e4e0630c42
commit 91e9df5721
7 changed files with 34 additions and 54 deletions

View file

@ -49,7 +49,7 @@ char/ft_isprint.c\
char/ft_tolower.c\ char/ft_tolower.c\
char/ft_toupper.c\ char/ft_toupper.c\
cliopts/cliopts_get.c\ cliopts/cliopts_get.c\
cliopts/cliopts_has.c\ cliopts/cliopts_getmap.c\
color/ft_color_mk.c\ color/ft_color_mk.c\
color/ft_color_mkif.c\ color/ft_color_mkif.c\
color/ft_color_reset.c\ color/ft_color_reset.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:22:56 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); 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); int cliopts_has(char **av, char c);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:04:04 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); 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( static int cliopts_parse_short(
char ***av, t_cliopts opt_map[], void *data) char ***av, t_cliopts opt_map[], void *data)
{ {
@ -63,7 +41,7 @@ static int cliopts_parse_short(
i = -1; i = -1;
while (arg[++i] && !(tmp = NULL)) 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])); return (ERR_SET(E_CO_INV, arg[i]));
((t_data_template*)data)->flag |= map->flag_on; ((t_data_template*)data)->flag |= map->flag_on;
((t_data_template*)data)->flag &= ~map->flag_off; ((t_data_template*)data)->flag &= ~map->flag_off;
@ -90,7 +68,7 @@ static int cliopts_parse_long(
arg = **av + 2; arg = **av + 2;
tmp = NULL; 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)); return (ERR_SET(E_CO_INVL, arg));
((t_data_template*)data)->flag |= map->flag_on; ((t_data_template*)data)->flag |= map->flag_on;
((t_data_template*)data)->flag &= ~map->flag_off; ((t_data_template*)data)->flag &= ~map->flag_off;

View file

@ -1,35 +1,35 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* cliopts_has.c :+: :+: :+: */ /* cliopts_getmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:03:18 by jhalford #+# #+# */ /* Created: 2017/03/25 14:59:03 by jhalford #+# #+# */
/* Updated: 2017/03/20 15:48:57 by jhalford ### ########.fr */ /* Updated: 2017/03/25 15:01:10 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cliopts.h" #include "cliopts.h"
int cliopts_has(char **av, char c) t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg)
{ {
if (!av) int i;
return (0);
while (*av) i = -1;
{ while (opt_map[++i].c)
if (ft_strcmp(*av, "--") == 0) if (!ft_strcmp(opt_map[i].str, arg))
return (0); return (&opt_map[i]);
else if ((*av)[0] == '-' && (*av)[1] == '-') return (NULL);
av++; }
else if ((*av)[0] == '-')
{ t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg)
if (ft_strchr(*av + 1, c)) {
return (1); int i;
av++;
} i = -1;
else while (opt_map[++i].c)
return (0); if (opt_map[i].c == arg)
} return (&opt_map[i]);
return (0); return (NULL);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:45:07 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 03:18:18 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))) if (!is_directory(newdir = ft_str3join(new_pathnames, "/", path)))
ft_strdel(&newdir); ft_strdel(&newdir);
else else
break; break ;
new_pathnames += ft_strlen(new_pathnames) + 1; new_pathnames += ft_strlen(new_pathnames) + 1;
} }
ft_strdel(&temp); ft_strdel(&temp);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 01:10:56 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; 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)); return (-ERR_SET(E_SYS_NOFILE, file));
if (is_directory(file)) if (is_directory(file))
return (-ERR_SET(E_SYS_ISDIR, file)); return (-ERR_SET(E_SYS_ISDIR, file));