diff --git a/libftasm/Makefile b/libftasm/Makefile index 6567e785..82bdc215 100644 --- a/libftasm/Makefile +++ b/libftasm/Makefile @@ -6,7 +6,7 @@ # By: jhalford +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2017/02/07 16:09:36 by jhalford #+# #+# # -# Updated: 2017/03/07 11:37:58 by ariard ### ########.fr # +# Updated: 2017/03/07 14:28:55 by ariard ### ########.fr # # # # **************************************************************************** # @@ -17,7 +17,7 @@ AR = ar -rc MKDIR = mkdir -p RM = /bin/rm -rf -W_FLAGS = -Wall -Wextra -Werror +W_FLAGS = -Wall -Wextra D_FLAGS = V_FLAGS = -fvisibility=hidden FLAGS = $(W_FLAGS) $(D_FLAGS) $(V_FLAGS) @@ -38,6 +38,7 @@ btree/btree_del.c\ btree/btree_delone.c\ btree/btree_insert_data.c\ btree/btree_level_count.c\ +btree/btree_map.c\ btree/btree_print.c\ btree/btree_search_item.c\ char/ft_isalnum.c\ @@ -114,6 +115,7 @@ math/ft_lltoa_base.c\ math/ft_uilen.c\ math/ft_uitoa_base.c\ math/ft_ulltoa_base.c\ +math/id.c\ mem/ft_bzero.c\ mem/ft_memalloc.c\ mem/ft_memccpy.c\ @@ -203,14 +205,14 @@ $(NAME): $(OBJ_DIR) $(OBJS) @$(AR) $(NAME) $(OBJS) @ranlib $(NAME) @strip -x $(NAME) - @printf "\r\e[48;5;15;38;5;25m✅ MAKE $(NAME)\e[0m\e[K\n" + @printf "\r\033[48;5;15;38;5;25m✅ MAKE $(NAME)\033[0m\033[K\n" $(OBJ_DIR)%.o: $(SRC_DIR)%.c | $(OBJ_DIR) @$(eval DONE=$(shell echo $$(($(INDEX)*20/$(NB))))) @$(eval PERCENT=$(shell echo $$(($(INDEX)*100/$(NB))))) @$(eval COLOR=$(shell echo $$(($(PERCENT)%35+196)))) @$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB))))) - @printf "\r\e[38;5;11m⌛ MAKE %10.10s : %2d%% \e[48;5;%dm%*s\e[0m%*s\e[48;5;255m \e[0m \e[38;5;11m %*s\e[0m\e[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) "$@" + @printf "\r\033[38;5;11m⌛ MAKE %10.10s : %2d%% \033[48;5;%dm%*s\033[0m%*s\033[48;5;255m \033[0m \033[38;5;11m %*.*s\033[0m\033[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) $(DELTA) "$@" @$(CC) $(FLAGS) -MMD -c $< -o $@\ -I $(INC_DIR) @$(eval INDEX=$(shell echo $$(($(INDEX)+1)))) @@ -221,11 +223,11 @@ $(OBJ_DIR): clean: @$(RM) $(OBJ_DIR) - @printf "\r\e[38;5;202m✖ clean $(NAME).\e[0m\e[K\n" + @printf "\r\033[38;5;202m✖ clean $(NAME).\033[0m\033[K\n" fclean: clean @$(RM) $(NAME) - @printf "\r\e[38;5;196m❌ fclean $(NAME).\e[0m\e[K\n" + @printf "\r\033[38;5;196m❌ fclean $(NAME).\033[0m\033[K\n" re: fclean all diff --git a/libftasm/includes/btree.h b/libftasm/includes/btree.h index 5839155c..0650090b 100644 --- a/libftasm/includes/btree.h +++ b/libftasm/includes/btree.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */ -/* Updated: 2016/12/05 11:53:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/07 12:16:03 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,6 +36,7 @@ typedef struct s_btree t_btree; typedef struct s_printdata t_printdata; t_btree *btree_create_node(void const *item, size_t content_size); +t_btree *btree_map(t_btree *root, void *(*f)(void *)); void btree_insert_data( t_btree **root, void *item, diff --git a/libftasm/includes/math.h b/libftasm/includes/math.h index 26c1dcd6..6b372f7d 100644 --- a/libftasm/includes/math.h +++ b/libftasm/includes/math.h @@ -1,5 +1,4 @@ -/* ************************************************************************** */ -/* */ +/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* math.h :+: :+: :+: */ /* +:+ +:+ +:+ */ @@ -33,5 +32,6 @@ size_t ft_lllen(long long n); size_t ft_lllen_base(long long n, int base); int ft_addrcmp(void *a, void *b); +void *id(void *data); #endif diff --git a/libftasm/src/btree/btree_map.c b/libftasm/src/btree/btree_map.c new file mode 100644 index 00000000..04d16491 --- /dev/null +++ b/libftasm/src/btree/btree_map.c @@ -0,0 +1,14 @@ +#include "btree.h" + +t_btree *btree_map(t_btree *root, void *(*f)(void *)) +{ + t_btree *new; + + if (!root) + return (NULL); + new = btree_create_node(root->item, root->content_size); + new->item = (*f)(new->item); + new->left = btree_map(root->left, f); + new->right = btree_map(root->right, f); + return (new); +} diff --git a/libftasm/src/ft_printf/ft_fmt_validate_flags.c b/libftasm/src/ft_printf/ft_fmt_validate_flags.c index 3f5892e1..709e3c19 100644 --- a/libftasm/src/ft_printf/ft_fmt_validate_flags.c +++ b/libftasm/src/ft_printf/ft_fmt_validate_flags.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 16:53:07 by jhalford #+# #+# */ -/* Updated: 2016/11/16 11:15:55 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:19:35 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,9 +55,6 @@ static void ft_fmt_validate_flag_conv(t_fmt *fmt) void ft_fmt_validate_flags(t_fmt *fmt) { - int i; - - i = 0; ft_fmt_validate_flag_conv(fmt); ft_fmt_validate_flag_flag(fmt); } diff --git a/libftasm/src/ft_printf/lib_pad_sharp.c b/libftasm/src/ft_printf/lib_pad_sharp.c index 526fcd1e..db6fd9c9 100644 --- a/libftasm/src/ft_printf/lib_pad_sharp.c +++ b/libftasm/src/ft_printf/lib_pad_sharp.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */ -/* Updated: 2016/12/09 19:07:55 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:19:49 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,9 +25,7 @@ void ft_pad_sharp_o(char *str, t_fmt *fmt) void ft_pad_sharp_xb(char *str, t_fmt *fmt) { char start[3] = {'0',fmt->conversion, 0}; - int i; - i = 0; if (str[0] == '0') { if (str[1] == '0') diff --git a/libftasm/src/math/id.c b/libftasm/src/math/id.c new file mode 100644 index 00000000..938cb5d1 --- /dev/null +++ b/libftasm/src/math/id.c @@ -0,0 +1,6 @@ +#include "libft.h" + +void *id(void *data) +{ + return (data); +} diff --git a/libftasm/src/sstr/ft_sstradd.c b/libftasm/src/sstr/ft_sstradd.c index 3d602b23..58aa0e32 100644 --- a/libftasm/src/sstr/ft_sstradd.c +++ b/libftasm/src/sstr/ft_sstradd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */ -/* Updated: 2017/03/07 11:32:39 by ariard ### ########.fr */ +/* Updated: 2017/03/07 14:28:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,11 +14,9 @@ char **ft_sstradd(char **sstr, char *new) { - int i; int size; char **newlist; - i = 0; size = 0; if (sstr) while (sstr[size]) diff --git a/libftasm/src/str/ft_strdup.c b/libftasm/src/str/ft_strdup.c index cbcc1a2e..429692cc 100644 --- a/libftasm/src/str/ft_strdup.c +++ b/libftasm/src/str/ft_strdup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 14:25:41 by jhalford #+# #+# */ -/* Updated: 2017/03/07 11:05:48 by ariard ### ########.fr */ +/* Updated: 2017/03/07 14:27:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,9 +15,7 @@ char *ft_strdup(const char *s1) { char *dup; - int i; - i = 0; if (!s1 || !(dup = (char*)malloc(sizeof(*dup) * (ft_strlen(s1) + 1)))) return (NULL); ft_strcpy(dup, s1); diff --git a/libftasm/src/sys/ft_xattr_count.c b/libftasm/src/sys/ft_xattr_count.c index 01b96eb5..62b274f7 100644 --- a/libftasm/src/sys/ft_xattr_count.c +++ b/libftasm/src/sys/ft_xattr_count.c @@ -6,12 +6,14 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:00:52 by jhalford #+# #+# */ -/* Updated: 2016/11/25 17:22:07 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:48:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" +#if defined __APPLE__ + int ft_xattr_count(char *path) { ssize_t listlen; @@ -32,3 +34,28 @@ int ft_xattr_count(char *path) } return (count); } + +#else + +int ft_xattr_count(char *path) +{ + ssize_t listlen; + char list[FT_XATTR_SIZE]; + int i; + int count; + + i = 0; + ft_bzero(list, FT_XATTR_SIZE); + listlen = listxattr(path, list, FT_XATTR_SIZE); + if (listlen == -1) + return (-1); + count = 0; + while (i < listlen) + { + i += ft_strlen(list) + 1; + count++; + } + return (count); +} + +#endif diff --git a/libftasm/src/sys/ft_xattr_print.c b/libftasm/src/sys/ft_xattr_print.c index de7a009f..e4d7e1a7 100644 --- a/libftasm/src/sys/ft_xattr_print.c +++ b/libftasm/src/sys/ft_xattr_print.c @@ -6,12 +6,14 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:00:43 by jhalford #+# #+# */ -/* Updated: 2016/11/03 18:00:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 16:48:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" +#if defined __APPLE__ + int ft_xattr_print(char *path) { ssize_t listlen; @@ -36,3 +38,32 @@ int ft_xattr_print(char *path) } return (0); } + +#else + +int ft_xattr_print(char *path) +{ + ssize_t listlen; + ssize_t valuelen; + char list[FT_XATTR_SIZE]; + char value[FT_XATTR_SIZE]; + int i; + + i = 0; + listlen = listxattr(path, list, FT_XATTR_SIZE); + if (listlen == -1) + return (1); + while (i < listlen) + { + valuelen = getxattr(path, list + i, value, + FT_XATTR_SIZE); + if (valuelen == -1) + ft_printf("couldn't get value\n"); + else + ft_printf("%s:\n%s\n", list + i, value); + i += ft_strlen(list) + 1; + } + return (0); +} + +#endif