diff --git a/nm-otool/Makefile b/nm-otool/Makefile index 34a63eea..d6794abb 100644 --- a/nm-otool/Makefile +++ b/nm-otool/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/31 21:05:56 by jhalford ### ########.fr # +# Updated: 2017/10/07 17:50:04 by jhalford ### ########.fr # # # # **************************************************************************** # diff --git a/nm-otool/libft2/.gitignore b/nm-otool/libft/.gitignore similarity index 100% rename from nm-otool/libft2/.gitignore rename to nm-otool/libft/.gitignore diff --git a/nm-otool/libft2/Makefile b/nm-otool/libft/Makefile similarity index 96% rename from nm-otool/libft2/Makefile rename to nm-otool/libft/Makefile index 3fdf2b03..893f7397 100644 --- a/nm-otool/libft2/Makefile +++ b/nm-otool/libft/Makefile @@ -23,7 +23,6 @@ INC_DIR = includes/ OBJ_DIR = objs/ SRC_BASE = \ -rs/rs.c\ btree/btree_apply_by_level.c\ btree/btree_apply_infix.c\ btree/btree_apply_prefix.c\ @@ -75,6 +74,7 @@ ft_printf/lib_pad.c\ ft_printf/lib_pad_sharp.c\ get_next_line/get_next_line.c\ lst/ft_id.c\ +lst/ft_lst2str.c\ lst/ft_lst_at.c\ lst/ft_lst_bfree.c\ lst/ft_lst_cfree.c\ @@ -85,6 +85,7 @@ lst/ft_lst_filterout.c\ lst/ft_lst_find.c\ lst/ft_lst_merge.c\ lst/ft_lst_order_delsub.c\ +lst/ft_lst_pop.c\ lst/ft_lst_print.c\ lst/ft_lst_print2.c\ lst/ft_lst_removeif.c\ @@ -104,11 +105,9 @@ lst/ft_lstnew.c\ lst/ft_lstnew_range.c\ lst/ft_lstsort.c\ lst/lst_insert_sort.c\ -lst/ft_lst_pop.c\ lst/pop.c\ lst/push.c\ lst/top.c\ -lst/ft_lst2str.c\ math/ft_addrcmp.c\ math/ft_ilen.c\ math/ft_ilen_base.c\ @@ -134,10 +133,10 @@ mem/ft_memset.c\ mem/ft_realloc.c\ net/create_client.c\ net/create_server.c\ +net/forge_ip.c\ +net/forge_tcp.c\ net/net_get.c\ net/net_send.c\ -net/forge_tcp.c\ -net/forge_ip.c\ net/reserve_port.c\ path/ft_path_notdir.c\ printing/ft_putchar.c\ @@ -145,6 +144,7 @@ printing/ft_putendl.c\ printing/ft_putnbr.c\ printing/ft_putstr.c\ printing/hexdump.c\ +rs/rs.c\ sstr/ft_sstradd.c\ sstr/ft_sstrcat.c\ sstr/ft_sstrdel.c\ @@ -155,7 +155,6 @@ sstr/ft_sstrprint.c\ sstr/ft_sstrprint_fd.c\ sstr/ft_sstrsort.c\ sstr/ft_sstrstr.c\ -str/ft_strsepjoin.c\ str/ft_atoi.c\ str/ft_convert_base.c\ str/ft_putaddr_fd.c\ @@ -174,7 +173,6 @@ str/ft_strcspn.c\ str/ft_strcut.c\ str/ft_strdel.c\ str/ft_strdup.c\ -str/ft_strndup.c\ str/ft_strdupchr.c\ str/ft_strduptr.c\ str/ft_strequ.c\ @@ -191,31 +189,24 @@ str/ft_strmapi.c\ str/ft_strncat.c\ str/ft_strncmp.c\ str/ft_strncpy.c\ +str/ft_strndup.c\ str/ft_strnequ.c\ str/ft_strnew.c\ str/ft_strnstr.c\ str/ft_strrchr.c\ str/ft_strreplace.c\ str/ft_strrev.c\ +str/ft_strsepjoin.c\ str/ft_strsplit.c\ str/ft_strstr.c\ str/ft_strsub.c\ str/ft_strtok.c\ str/ft_strtrim.c\ +sys/open_new.c\ +time/epoch.c\ time/ft_mytime_free.c\ time/ft_mytime_get.c\ -time/ft_time_isrecent.c\ -time/epoch.c\ -sys/open_new.c\ -htb/ft_hash_string.c\ -htb/hashtab_init.c\ -htb/hashtab_insert.c\ -htb/hashtab_lookup.c\ -htb/hashtab_remove.c\ -htb/hashtab_destroy.c\ -htb/hashtab_print.c\ -htb/hashtab_generator.c\ -htb/hashtab_del.c\ +time/ft_time_isrecent.c SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o)) @@ -241,7 +232,7 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR) @$(eval COLOR=$(shell list=(160 196 202 208 215 221 226 227 190 154 118 82 46); index=$$(($(PERCENT) * $${#list[@]} / 100)); echo "$${list[$$index]}")) @printf "\r\033[38;5;%dm⌛ [%s]: %2d%% `printf '█%.0s' {0..$(DONE)}`%*s❙%*.*s\033[0m\033[K" $(COLOR) $(NAME) $(PERCENT) $(TO_DO) "" $(DELTA) $(DELTA) "$(shell echo "$@" | sed 's/^.*\///')" @$(CC) $(FLAGS) -MMD -c $< -o $@\ - -I $(INC_DIR) -lm + -I $(INC_DIR) @$(eval INDEX=$(shell echo $$(($(INDEX)+1)))) clean : diff --git a/nm-otool/libft2/README.md b/nm-otool/libft/README.md similarity index 100% rename from nm-otool/libft2/README.md rename to nm-otool/libft/README.md diff --git a/nm-otool/libft2/includes/btree.h b/nm-otool/libft/includes/btree.h similarity index 100% rename from nm-otool/libft2/includes/btree.h rename to nm-otool/libft/includes/btree.h diff --git a/nm-otool/libft2/includes/cliopts.h b/nm-otool/libft/includes/cliopts.h similarity index 86% rename from nm-otool/libft2/includes/cliopts.h rename to nm-otool/libft/includes/cliopts.h index 9ea82890..31eecca6 100644 --- a/nm-otool/libft2/includes/cliopts.h +++ b/nm-otool/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/10/07 18:04:53 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,15 @@ 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); +int cliopts_has(char **av, char c); #endif diff --git a/nm-otool/libft2/includes/color.h b/nm-otool/libft/includes/color.h similarity index 100% rename from nm-otool/libft2/includes/color.h rename to nm-otool/libft/includes/color.h diff --git a/nm-otool/libft2/includes/dlst.h b/nm-otool/libft/includes/dlst.h similarity index 100% rename from nm-otool/libft2/includes/dlst.h rename to nm-otool/libft/includes/dlst.h diff --git a/nm-otool/libft2/includes/error.h b/nm-otool/libft/includes/error.h similarity index 100% rename from nm-otool/libft2/includes/error.h rename to nm-otool/libft/includes/error.h diff --git a/nm-otool/libft2/includes/ft_printf.h b/nm-otool/libft/includes/ft_printf.h similarity index 100% rename from nm-otool/libft2/includes/ft_printf.h rename to nm-otool/libft/includes/ft_printf.h diff --git a/nm-otool/libft2/includes/ft_types.h b/nm-otool/libft/includes/ft_types.h similarity index 100% rename from nm-otool/libft2/includes/ft_types.h rename to nm-otool/libft/includes/ft_types.h diff --git a/nm-otool/libft2/includes/get_next_line.h b/nm-otool/libft/includes/get_next_line.h similarity index 100% rename from nm-otool/libft2/includes/get_next_line.h rename to nm-otool/libft/includes/get_next_line.h diff --git a/nm-otool/libft2/includes/libft.h b/nm-otool/libft/includes/libft.h similarity index 95% rename from nm-otool/libft2/includes/libft.h rename to nm-otool/libft/includes/libft.h index 27c04598..1b4b5402 100644 --- a/nm-otool/libft2/includes/libft.h +++ b/nm-otool/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2017/05/16 17:47:18 by ariard ### ########.fr */ +/* Updated: 2017/10/07 18:07:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,6 @@ # include "lst.h" # include "dlst.h" # include "btree.h" -# include "hashtab.h" # include "str.h" # include "sstr.h" @@ -90,7 +89,7 @@ int ft_putendl_fd(char const *s, int fd); int ft_putnbr_fd(long n, int fd); int ft_putnbr_hex_fd(long n, int fd); -void hexdump(void *pAddressIn, long lSize); +void *hexdump(void *addr, unsigned int offset, unsigned int size); void *ft_realloc(void *data, int size); diff --git a/nm-otool/libft2/includes/lst.h b/nm-otool/libft/includes/lst.h similarity index 100% rename from nm-otool/libft2/includes/lst.h rename to nm-otool/libft/includes/lst.h diff --git a/nm-otool/libft2/includes/math.h b/nm-otool/libft/includes/math.h similarity index 100% rename from nm-otool/libft2/includes/math.h rename to nm-otool/libft/includes/math.h diff --git a/nm-otool/libft2/includes/mytime.h b/nm-otool/libft/includes/mytime.h similarity index 100% rename from nm-otool/libft2/includes/mytime.h rename to nm-otool/libft/includes/mytime.h diff --git a/nm-otool/libft/includes/net.h b/nm-otool/libft/includes/net.h new file mode 100644 index 00000000..768ac0cd --- /dev/null +++ b/nm-otool/libft/includes/net.h @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* net.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:06:12 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:14:42 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef NET_H +# define NET_H + +# define ACK 2 +# define NACK 3 +# define NET_MAXSIZE 512 + +# include +# include +# include +# include +# include +# include +# include +# include + +# include "mytime.h" + +int create_server(int port, int backlog, char *protoname); +int create_client(char *addr, int port, char *protoname); +void listener(int domain, int sock, int proto, + void (*handler)(void *buf, int bytes, struct sockaddr_in *addr)); + +int net_send(int sock, char *msg, int size); +int net_send_large(int sock, char *msg, int size); +int net_get(int sock, char *msg, int size); +int net_get_fd(int sock, int fd, int size); +int net_get_large(int sock, int fd); + +int reserve_port(int *port); + +void tcphdr_init(struct tcphdr *header); +void iphdr_init(struct ip *header); + +#endif diff --git a/nm-otool/libft/includes/rs.h b/nm-otool/libft/includes/rs.h new file mode 100644 index 00000000..279ba4e8 --- /dev/null +++ b/nm-otool/libft/includes/rs.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:05:30 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:18:16 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_RS_H +# define LIBFT_RS_H + +# include +# include +# include + +extern struct s_stats { + int count; + double min; + double max; + double avg; + double m; + double stdev; + double var; +} g_rs; + +void rs_clear(); +void rs_push(double n); +void rs_calcmore(); + +#endif diff --git a/nm-otool/libft2/includes/sstr.h b/nm-otool/libft/includes/sstr.h similarity index 100% rename from nm-otool/libft2/includes/sstr.h rename to nm-otool/libft/includes/sstr.h diff --git a/nm-otool/libft2/includes/str.h b/nm-otool/libft/includes/str.h similarity index 100% rename from nm-otool/libft2/includes/str.h rename to nm-otool/libft/includes/str.h diff --git a/nm-otool/libft2/includes/sys.h b/nm-otool/libft/includes/sys.h similarity index 68% rename from nm-otool/libft2/includes/sys.h rename to nm-otool/libft/includes/sys.h index c945ead7..4cb977e8 100644 --- a/nm-otool/libft2/includes/sys.h +++ b/nm-otool/libft/includes/sys.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */ -/* Updated: 2017/05/16 17:30:50 by ariard ### ########.fr */ +/* Updated: 2017/10/07 18:10:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,23 +24,9 @@ # include # include -/* # if HAVE_SYS_ACL_H */ -/* # include */ -/* # endif */ # include # include -/* int ft_xattr_print(char *path); */ -/* int ft_xattr_count(char *path); */ - -/* char *ft_getenv(char **env, char *key); */ - -/* int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm); */ int open_new(char *filename, int oflag); -/* int is_directory(const char *path); */ -/* char *create_directory(const char *path, const char *old_pathnames); */ - -/* int dup2_close(int fd1, int fd2); */ -/* int fd_replace(int fd1, int fd2); */ #endif diff --git a/nm-otool/libft2/pdf/ft_printf.pdf b/nm-otool/libft/pdf/ft_printf.pdf similarity index 100% rename from nm-otool/libft2/pdf/ft_printf.pdf rename to nm-otool/libft/pdf/ft_printf.pdf diff --git a/nm-otool/libft2/pdf/get_next_line.fr.pdf b/nm-otool/libft/pdf/get_next_line.fr.pdf similarity index 100% rename from nm-otool/libft2/pdf/get_next_line.fr.pdf rename to nm-otool/libft/pdf/get_next_line.fr.pdf diff --git a/nm-otool/libft2/pdf/libft.fr.pdf b/nm-otool/libft/pdf/libft.fr.pdf similarity index 100% rename from nm-otool/libft2/pdf/libft.fr.pdf rename to nm-otool/libft/pdf/libft.fr.pdf diff --git a/nm-otool/libft/srcs/btree/btree_apply_by_level.c b/nm-otool/libft/srcs/btree/btree_apply_by_level.c new file mode 100644 index 00000000..14e537f7 --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_apply_by_level.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_by_level.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/19 12:06:15 by jhalford #+# #+# */ +/* Updated: 2017/03/14 17:25:46 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +int g_level = 0; + +static void btree_apply_to_level( + t_btree *root, + int level, + int is_first_elem, + void (*applyf)(void *item, int current_level, int is_first_elem)) +{ + if (level == g_level) + { + (*applyf)(root->item, level, is_first_elem); + return ; + } + if (root->left) + btree_apply_to_level(root->left, level + 1, is_first_elem, applyf); + if (root->right) + btree_apply_to_level(root->right, level + 1, 0, applyf); +} + +void btree_apply_by_level( + t_btree *root, + void (*applyf)(void *item, int current_level, int is_first_elem)) +{ + int height; + + height = btree_level_count(root); + while (g_level < height) + { + btree_apply_to_level(root, 0, 1, applyf); + g_level++; + } +} diff --git a/nm-otool/libft/srcs/btree/btree_apply_infix.c b/nm-otool/libft/srcs/btree/btree_apply_infix.c new file mode 100644 index 00000000..93a18b7d --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_apply_infix.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2017/03/06 18:22:31 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_apply_infix(t_btree *root, void (*applyf)(void *)) +{ + if (root->left) + btree_apply_infix(root->left, applyf); + (*applyf)(root->item); + if (root->right) + btree_apply_infix(root->right, applyf); + return ; +} diff --git a/nm-otool/libft/srcs/btree/btree_apply_prefix.c b/nm-otool/libft/srcs/btree/btree_apply_prefix.c new file mode 100644 index 00000000..e7e4332c --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_apply_prefix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/08/18 21:06:44 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)) +{ + (*applyf)(root->item); + if (root->left) + btree_apply_prefix(root->left, applyf); + if (root->right) + btree_apply_prefix(root->right, applyf); +} diff --git a/nm-otool/libft/srcs/btree/btree_apply_suffix.c b/nm-otool/libft/srcs/btree/btree_apply_suffix.c new file mode 100644 index 00000000..ae103242 --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_apply_suffix.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_suffix.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/05 11:43:08 by jhalford #+# #+# */ +/* Updated: 2016/12/05 11:43:13 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)) +{ + if (root->left) + btree_apply_suffix(root->left, applyf); + if (root->right) + btree_apply_suffix(root->right, applyf); + (*applyf)(root->item); + return ; +} diff --git a/nm-otool/libft/srcs/btree/btree_create_node.c b/nm-otool/libft/srcs/btree/btree_create_node.c new file mode 100644 index 00000000..cc365537 --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_create_node.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2017/03/21 15:43:50 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +t_btree *btree_create_node(void const *item, size_t content_size) +{ + t_btree *new; + + if (!(new = (t_btree *)ft_malloc(sizeof(t_btree)))) + return (NULL); + new->left = 0; + new->right = 0; + if (!item) + { + new->content_size = 0; + new->item = NULL; + } + else + { + new->content_size = content_size; + new->item = ft_memalloc(content_size + 1); + ft_memcpy(new->item, item, content_size); + } + return (new); +} diff --git a/nm-otool/libft/srcs/btree/btree_del.c b/nm-otool/libft/srcs/btree/btree_del.c new file mode 100644 index 00000000..8b72f78a --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_del.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_del.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/05 11:43:03 by jhalford #+# #+# */ +/* Updated: 2017/03/21 19:43:51 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_del(t_btree **root, void (*del)(void *, size_t)) +{ + if (root && *root && del) + { + btree_del(&(*root)->left, del); + btree_del(&(*root)->right, del); + btree_delone(root, del); + } +} diff --git a/nm-otool/libft/srcs/btree/btree_delone.c b/nm-otool/libft/srcs/btree/btree_delone.c new file mode 100644 index 00000000..17ce1c4a --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_delone.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_delone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/05 11:45:51 by jhalford #+# #+# */ +/* Updated: 2016/12/15 12:48:55 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_delone(t_btree **root, void (*del)(void *, size_t)) +{ + if (root && *root) + { + if (del) + (*del)((*root)->item, (*root)->content_size); + free(*root); + *root = NULL; + } +} diff --git a/nm-otool/libft/srcs/btree/btree_insert_data.c b/nm-otool/libft/srcs/btree/btree_insert_data.c new file mode 100644 index 00000000..a6e262fc --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_insert_data.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/11/14 16:12:47 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_insert_data( + t_btree **root, + void *item, + size_t content_size, + int (*cmpf)(void *, void *)) +{ + t_btree *node; + + if (!*root) + { + *root = btree_create_node(item, content_size); + return ; + } + node = *root; + if ((*cmpf)(item, node->item) < 0) + { + if (node->left) + btree_insert_data(&node->left, item, content_size, cmpf); + else + node->left = btree_create_node(item, content_size); + } + else + { + if (node->right) + btree_insert_data(&node->right, item, content_size, cmpf); + else + node->right = btree_create_node(item, content_size); + } +} diff --git a/nm-otool/libft/srcs/btree/btree_level_count.c b/nm-otool/libft/srcs/btree/btree_level_count.c new file mode 100644 index 00000000..41248654 --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_level_count.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/08/25 17:46:00 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +int btree_level_count(t_btree *root) +{ + return (root + ? 1 + FT_MAX(btree_level_count(root->left), + btree_level_count(root->right)) + : 0); +} diff --git a/nm-otool/libft/srcs/btree/btree_map.c b/nm-otool/libft/srcs/btree/btree_map.c new file mode 100644 index 00000000..47b92852 --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_map.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 11:50:46 by jhalford #+# #+# */ +/* Updated: 2017/03/24 15:49:42 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +t_btree *btree_map(t_btree *root, void *(*f)(void *)) +{ + t_btree *new; + + if (!root) + return (NULL); + if (!(new = (t_btree *)ft_malloc(sizeof(*new)))) + return (NULL); + new->item = (*f)(root->item); + new->left = btree_map(root->left, f); + new->right = btree_map(root->right, f); + return (new); +} diff --git a/nm-otool/libft/srcs/btree/btree_print.c b/nm-otool/libft/srcs/btree/btree_print.c new file mode 100644 index 00000000..10b46735 --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_print.c @@ -0,0 +1,82 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */ +/* Updated: 2017/05/15 19:08:35 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +static int print_t2(t_printdata data, char s[20][255], char b[20]) +{ + int width; + int i; + + width = 5; + i = -1; + while (++i < width) + s[2 * data.depth][data.offset + data.left + i] = b[i]; + i = -1; + if (data.depth && data.is_left) + { + while (++i < width + data.right) + s[2 * data.depth - 1] + [data.offset + data.left + width / 2 + i] = '-'; + s[2 * data.depth - 1][data.offset + data.left + width / 2] = '+'; + s[2 * data.depth - 1] + [data.offset + data.left + data.right + 3 * width / 2] = '+'; + } + else if (data.depth && !data.is_left) + { + while (++i < width + data.left) + s[2 * data.depth - 1][data.offset - width / 2 + i] = '-'; + s[2 * data.depth - 1][data.offset + data.left + width / 2] = '+'; + s[2 * data.depth - 1][data.offset - width / 2 - 1] = '+'; + } + return (data.left + width + data.right); +} + +static int print_t(t_btree *tree, + t_printdata data, char s[20][255], char *(*printer)(void *)) +{ + char b[20]; + int width; + + width = 5; + if (!tree) + return (0); + sprintf(b, "%5s", printer(tree->item)); + data.left = print_t(tree->left, (t_printdata){ + 1, data.offset, data.depth + 1, data.left, data.right}, s, printer); + data.right = print_t(tree->right, (t_printdata){ + 0, data.offset + data.left + width, data.depth + 1, + data.left, data.right}, s, printer); + return (print_t2(data, s, b)); +} + +void btree_print(int fd, t_btree *tree, char *(*printer)(void *)) +{ + char s[20][255]; + char empty[255]; + int i; + + i = -1; + while (++i < 20) + sprintf(s[i], "%80s", " "); + sprintf(empty, "%80s", " "); + print_t(tree, (t_printdata){0, 0, 0, 0, 0}, s, printer); + i = -1; + while (++i < 20) + { + if (ft_strcmp(s[i], empty) == 0) + break ; + if (i == 0 && ft_strcmp(s[1], empty) == 0) + break ; + ft_dprintf(fd, "%s\n", s[i]); + } +} diff --git a/nm-otool/libft/srcs/btree/btree_search_item.c b/nm-otool/libft/srcs/btree/btree_search_item.c new file mode 100644 index 00000000..a7a1eb68 --- /dev/null +++ b/nm-otool/libft/srcs/btree/btree_search_item.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/08/23 19:04:56 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void *btree_search_item(t_btree *root, + void *data_ref, int (*cmpf)(void *, void *)) +{ + void *out; + + out = NULL; + if (root) + { + out = btree_search_item(root->left, data_ref, cmpf); + if (!out && ((*cmpf)(root->item, data_ref) == 0)) + out = root->item; + if (!out) + out = btree_search_item(root->right, data_ref, cmpf); + } + return (out); +} diff --git a/nm-otool/libft2/srcs/char/ft_isalnum.c b/nm-otool/libft/srcs/char/ft_isalnum.c similarity index 100% rename from nm-otool/libft2/srcs/char/ft_isalnum.c rename to nm-otool/libft/srcs/char/ft_isalnum.c diff --git a/nm-otool/libft2/srcs/char/ft_isalpha.c b/nm-otool/libft/srcs/char/ft_isalpha.c similarity index 100% rename from nm-otool/libft2/srcs/char/ft_isalpha.c rename to nm-otool/libft/srcs/char/ft_isalpha.c diff --git a/nm-otool/libft2/srcs/char/ft_isascii.c b/nm-otool/libft/srcs/char/ft_isascii.c similarity index 100% rename from nm-otool/libft2/srcs/char/ft_isascii.c rename to nm-otool/libft/srcs/char/ft_isascii.c diff --git a/nm-otool/libft2/srcs/char/ft_isdigit.c b/nm-otool/libft/srcs/char/ft_isdigit.c similarity index 100% rename from nm-otool/libft2/srcs/char/ft_isdigit.c rename to nm-otool/libft/srcs/char/ft_isdigit.c diff --git a/nm-otool/libft2/srcs/char/ft_isprint.c b/nm-otool/libft/srcs/char/ft_isprint.c similarity index 100% rename from nm-otool/libft2/srcs/char/ft_isprint.c rename to nm-otool/libft/srcs/char/ft_isprint.c diff --git a/nm-otool/libft2/srcs/char/ft_tolower.c b/nm-otool/libft/srcs/char/ft_tolower.c similarity index 100% rename from nm-otool/libft2/srcs/char/ft_tolower.c rename to nm-otool/libft/srcs/char/ft_tolower.c diff --git a/nm-otool/libft2/srcs/char/ft_toupper.c b/nm-otool/libft/srcs/char/ft_toupper.c similarity index 100% rename from nm-otool/libft2/srcs/char/ft_toupper.c rename to nm-otool/libft/srcs/char/ft_toupper.c diff --git a/nm-otool/libft2/srcs/cliopts/cliopts_get.c b/nm-otool/libft/srcs/cliopts/cliopts_get.c similarity index 100% rename from nm-otool/libft2/srcs/cliopts/cliopts_get.c rename to nm-otool/libft/srcs/cliopts/cliopts_get.c diff --git a/nm-otool/libft2/srcs/cliopts/cliopts_getmap.c b/nm-otool/libft/srcs/cliopts/cliopts_getmap.c similarity index 100% rename from nm-otool/libft2/srcs/cliopts/cliopts_getmap.c rename to nm-otool/libft/srcs/cliopts/cliopts_getmap.c diff --git a/nm-otool/libft/srcs/color/ft_color_mk.c b/nm-otool/libft/srcs/color/ft_color_mk.c new file mode 100644 index 00000000..db75d7cc --- /dev/null +++ b/nm-otool/libft/srcs/color/ft_color_mk.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_color_mk.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/27 11:35:18 by jhalford #+# #+# */ +/* Updated: 2016/12/12 11:54:49 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_color_mk(t_color *color, char fg[7], char bg[7]) +{ + ft_strcpy(color->fg, fg); + ft_strcpy(color->bg, bg); +} diff --git a/nm-otool/libft/srcs/color/ft_color_mkif.c b/nm-otool/libft/srcs/color/ft_color_mkif.c new file mode 100644 index 00000000..707a5c8c --- /dev/null +++ b/nm-otool/libft/srcs/color/ft_color_mkif.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_color_mk.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/27 11:35:18 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:17:14 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_color_mkif(t_color *color, int cond, char fg[7], char bg[7]) +{ + if (cond) + ft_color_mk(color, fg, bg); +} diff --git a/nm-otool/libft/srcs/color/ft_color_reset.c b/nm-otool/libft/srcs/color/ft_color_reset.c new file mode 100644 index 00000000..4b557bff --- /dev/null +++ b/nm-otool/libft/srcs/color/ft_color_reset.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_color_reset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/25 13:48:05 by jhalford #+# #+# */ +/* Updated: 2016/11/25 14:06:26 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_color_reset(void) +{ + ft_putstr(FG_DEFAULT); + ft_putstr(BG_DEFAULT); +} diff --git a/nm-otool/libft/srcs/color/ft_color_set.c b/nm-otool/libft/srcs/color/ft_color_set.c new file mode 100644 index 00000000..99d9c0d0 --- /dev/null +++ b/nm-otool/libft/srcs/color/ft_color_set.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_color_set.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/25 13:53:46 by jhalford #+# #+# */ +/* Updated: 2016/12/12 11:55:03 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_color_set(t_color color) +{ + char out[20]; + + ft_strcpy(out, color.fg); + ft_strcat(out, color.bg); + ft_putstr(out); +} diff --git a/nm-otool/libft/srcs/dlst/ft_dlstadd_after.c b/nm-otool/libft/srcs/dlst/ft_dlstadd_after.c new file mode 100644 index 00000000..19dc852a --- /dev/null +++ b/nm-otool/libft/srcs/dlst/ft_dlstadd_after.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlst_add_after.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:27:04 by jhalford #+# #+# */ +/* Updated: 2016/11/07 13:27:36 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_dlstadd_after(t_dlist **alst, t_dlist *new) +{ + if (new) + { + new->prev = (*alst); + if (*alst) + new->next = (*alst)->next; + else + new->next = NULL; + if (new->next) + new->next->prev = new; + if (new->prev) + new->prev->next = new; + *alst = new; + } +} diff --git a/nm-otool/libft/srcs/dlst/ft_dlstadd_before.c b/nm-otool/libft/srcs/dlst/ft_dlstadd_before.c new file mode 100644 index 00000000..e2d6b2e8 --- /dev/null +++ b/nm-otool/libft/srcs/dlst/ft_dlstadd_before.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlst_add_before.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:27:09 by jhalford #+# #+# */ +/* Updated: 2016/11/07 13:27:10 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_dlstadd_before(t_dlist **alst, t_dlist *new) +{ + if (new) + { + new->next = (*alst); + if (*alst) + new->prev = (*alst)->prev; + if (new->next) + new->next->prev = new; + if (new->prev) + new->prev->next = new; + *alst = new; + } +} diff --git a/nm-otool/libft/srcs/dlst/ft_dlstdel.c b/nm-otool/libft/srcs/dlst/ft_dlstdel.c new file mode 100644 index 00000000..94b43f6b --- /dev/null +++ b/nm-otool/libft/srcs/dlst/ft_dlstdel.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlstdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/14 17:55:40 by jhalford #+# #+# */ +/* Updated: 2016/12/07 17:29:54 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static void ft_dlstdelback(t_dlist **alst, void (*del)(void *, size_t)) +{ + if (alst && *alst && del) + { + ft_dlstdelback(&(*alst)->prev, del); + ft_dlstdelone(alst, del); + } +} + +static void ft_dlstdelfront(t_dlist **alst, void (*del)(void *, size_t)) +{ + if (alst && *alst && del) + { + ft_dlstdelfront(&(*alst)->next, del); + ft_dlstdelone(alst, del); + } +} + +void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t)) +{ + if (alst && *alst && del) + { + ft_dlstdelback(&(*alst)->prev, del); + ft_dlstdelfront(&(*alst)->next, del); + ft_dlstdelone(alst, del); + } +} diff --git a/nm-otool/libft/srcs/dlst/ft_dlstdelone.c b/nm-otool/libft/srcs/dlst/ft_dlstdelone.c new file mode 100644 index 00000000..55826853 --- /dev/null +++ b/nm-otool/libft/srcs/dlst/ft_dlstdelone.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlst_delone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:27:13 by jhalford #+# #+# */ +/* Updated: 2016/11/14 17:52:58 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t)) +{ + t_dlist *tmp; + + tmp = *alst; + if (tmp) + { + if (del) + (*del)(tmp->content, tmp->content_size); + if (tmp->next) + tmp->next->prev = tmp->prev; + if (tmp->prev) + tmp->prev->next = tmp->next; + if (tmp->prev) + *alst = tmp->prev; + else + *alst = tmp->next; + free(tmp); + } +} diff --git a/nm-otool/libft/srcs/dlst/ft_dlstlast.c b/nm-otool/libft/srcs/dlst/ft_dlstlast.c new file mode 100644 index 00000000..1286c32c --- /dev/null +++ b/nm-otool/libft/srcs/dlst/ft_dlstlast.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlst_last.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:27:15 by jhalford #+# #+# */ +/* Updated: 2016/11/07 13:27:15 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_dlist *ft_dlstlast(t_dlist *list) +{ + while (list && list->next) + list = list->next; + return (list); +} diff --git a/nm-otool/libft/srcs/dlst/ft_dlstnew.c b/nm-otool/libft/srcs/dlst/ft_dlstnew.c new file mode 100644 index 00000000..411bffca --- /dev/null +++ b/nm-otool/libft/srcs/dlst/ft_dlstnew.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlst_new.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:27:20 by jhalford #+# #+# */ +/* Updated: 2017/03/21 15:43:50 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_dlist *ft_dlstnew(void const *content, size_t content_size) +{ + t_dlist *new; + + if (!content) + { + new = ft_malloc(sizeof(*new)); + if (!new) + return (NULL); + new->content_size = 0; + new->content = NULL; + } + else + { + new = (t_dlist *)ft_malloc(sizeof(*new)); + if (!new) + return (NULL); + new->content_size = content_size; + new->content = ft_memalloc(content_size + 1); + ft_memcpy(new->content, content, content_size); + } + new->next = NULL; + new->prev = NULL; + return (new); +} diff --git a/nm-otool/libft/srcs/dlst/ft_dlstrtostr.c b/nm-otool/libft/srcs/dlst/ft_dlstrtostr.c new file mode 100644 index 00000000..e92e4d8a --- /dev/null +++ b/nm-otool/libft/srcs/dlst/ft_dlstrtostr.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlstrtostr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:27:29 by jhalford #+# #+# */ +/* Updated: 2016/11/14 16:13:24 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_dlsttostr(t_dlist *list) +{ + char *str; + + if (!list) + return (NULL); + while (list->prev) + list = list->prev; + str = (char *)ft_strnew(sizeof(char) * (ft_dlstsize(list) + 2)); + while (list) + { + ft_strcat(str, (char *)list->content); + list = list->next; + } + return (str); +} diff --git a/nm-otool/libft/srcs/dlst/ft_dlstsize.c b/nm-otool/libft/srcs/dlst/ft_dlstsize.c new file mode 100644 index 00000000..b536efa2 --- /dev/null +++ b/nm-otool/libft/srcs/dlst/ft_dlstsize.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlst_size.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:27:23 by jhalford #+# #+# */ +/* Updated: 2016/11/07 13:27:23 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_dlstsize(t_dlist *list) +{ + int size; + t_dlist *tmp; + + size = 0; + if (list) + size++; + tmp = list; + while (tmp->next) + { + size++; + tmp = tmp->next; + } + tmp = list; + while (tmp->prev) + { + size++; + tmp = tmp->prev; + } + return (size); +} diff --git a/nm-otool/libft2/srcs/error/error.c b/nm-otool/libft/srcs/error/error.c similarity index 100% rename from nm-otool/libft2/srcs/error/error.c rename to nm-otool/libft/srcs/error/error.c diff --git a/nm-otool/libft2/srcs/error/ft_usage.c b/nm-otool/libft/srcs/error/ft_usage.c similarity index 100% rename from nm-otool/libft2/srcs/error/ft_usage.c rename to nm-otool/libft/srcs/error/ft_usage.c diff --git a/nm-otool/libft2/srcs/ft_printf/ft_conversion.c b/nm-otool/libft/srcs/ft_printf/ft_conversion.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/ft_conversion.c rename to nm-otool/libft/srcs/ft_printf/ft_conversion.c diff --git a/nm-otool/libft2/srcs/ft_printf/ft_fmt_simplify.c b/nm-otool/libft/srcs/ft_printf/ft_fmt_simplify.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/ft_fmt_simplify.c rename to nm-otool/libft/srcs/ft_printf/ft_fmt_simplify.c diff --git a/nm-otool/libft2/srcs/ft_printf/ft_fmt_validate_conv.c b/nm-otool/libft/srcs/ft_printf/ft_fmt_validate_conv.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/ft_fmt_validate_conv.c rename to nm-otool/libft/srcs/ft_printf/ft_fmt_validate_conv.c diff --git a/nm-otool/libft2/srcs/ft_printf/ft_fmt_validate_flags.c b/nm-otool/libft/srcs/ft_printf/ft_fmt_validate_flags.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/ft_fmt_validate_flags.c rename to nm-otool/libft/srcs/ft_printf/ft_fmt_validate_flags.c diff --git a/nm-otool/libft2/srcs/ft_printf/ft_fmt_validate_mod.c b/nm-otool/libft/srcs/ft_printf/ft_fmt_validate_mod.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/ft_fmt_validate_mod.c rename to nm-otool/libft/srcs/ft_printf/ft_fmt_validate_mod.c diff --git a/nm-otool/libft2/srcs/ft_printf/ft_printf.c b/nm-otool/libft/srcs/ft_printf/ft_printf.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/ft_printf.c rename to nm-otool/libft/srcs/ft_printf/ft_printf.c diff --git a/nm-otool/libft2/srcs/ft_printf/ft_printf_color.c b/nm-otool/libft/srcs/ft_printf/ft_printf_color.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/ft_printf_color.c rename to nm-otool/libft/srcs/ft_printf/ft_printf_color.c diff --git a/nm-otool/libft2/srcs/ft_printf/ft_printf_parse.c b/nm-otool/libft/srcs/ft_printf/ft_printf_parse.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/ft_printf_parse.c rename to nm-otool/libft/srcs/ft_printf/ft_printf_parse.c diff --git a/nm-otool/libft2/srcs/ft_printf/ft_transform.c b/nm-otool/libft/srcs/ft_printf/ft_transform.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/ft_transform.c rename to nm-otool/libft/srcs/ft_printf/ft_transform.c diff --git a/nm-otool/libft2/srcs/ft_printf/ft_vprintf.c b/nm-otool/libft/srcs/ft_printf/ft_vprintf.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/ft_vprintf.c rename to nm-otool/libft/srcs/ft_printf/ft_vprintf.c diff --git a/nm-otool/libft2/srcs/ft_printf/lib_fmt.c b/nm-otool/libft/srcs/ft_printf/lib_fmt.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/lib_fmt.c rename to nm-otool/libft/srcs/ft_printf/lib_fmt.c diff --git a/nm-otool/libft2/srcs/ft_printf/lib_fmt_error.c b/nm-otool/libft/srcs/ft_printf/lib_fmt_error.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/lib_fmt_error.c rename to nm-otool/libft/srcs/ft_printf/lib_fmt_error.c diff --git a/nm-otool/libft2/srcs/ft_printf/lib_pad.c b/nm-otool/libft/srcs/ft_printf/lib_pad.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/lib_pad.c rename to nm-otool/libft/srcs/ft_printf/lib_pad.c diff --git a/nm-otool/libft2/srcs/ft_printf/lib_pad_sharp.c b/nm-otool/libft/srcs/ft_printf/lib_pad_sharp.c similarity index 100% rename from nm-otool/libft2/srcs/ft_printf/lib_pad_sharp.c rename to nm-otool/libft/srcs/ft_printf/lib_pad_sharp.c diff --git a/nm-otool/libft/srcs/get_next_line/get_next_line.c b/nm-otool/libft/srcs/get_next_line/get_next_line.c new file mode 100644 index 00000000..3eed0dee --- /dev/null +++ b/nm-otool/libft/srcs/get_next_line/get_next_line.c @@ -0,0 +1,89 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/15 13:12:06 by jhalford #+# #+# */ +/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "get_next_line.h" + +static int ft_fdcmp(t_save *a, int *b) +{ + return (a->fd - *b); +} + +static void ft_gnlfree(void *a, size_t size) +{ + (void)size; + ft_strdel(&((t_save*)a)->str); + free(a); +} + +static t_list *ft_newfd(t_list **head, int fd) +{ + t_save new; + + new.fd = fd; + new.str = ft_memalloc((BUFF_SIZE > 0 ? BUFF_SIZE : 0) + 1); + ft_lstadd(head, ft_lstnew(&new, sizeof(t_save))); + return (*head); +} + +static int ft_loop_read(int fd, char **line, char *save) +{ + char buf[BUFF_SIZE + 1]; + char *pos; + char *tmp; + int ret; + + while ((ret = read(fd, buf, BUFF_SIZE)) > 0) + { + buf[ret] = 0; + tmp = *line; + if ((pos = ft_strchr(buf, '\n'))) + { + ft_strcpy(save, pos + 1); + *pos = 0; + } + if (!(*line = ft_strjoin(*line, buf))) + return (-1); + ft_strdel(&tmp); + if (pos) + return (1); + } + if (ret < 0) + return (-1); + return (**line ? 1 : 0); +} + +int get_next_line(int const fd, char **line) +{ + static t_list *head; + t_list *tmp; + char *pos; + char *save; + int ret; + + if (fd < 0 || !line) + return (-1); + if (!(tmp = ft_lst_find(head, (void *)&fd, &ft_fdcmp))) + tmp = ft_newfd(&head, fd); + save = ((t_save*)tmp->content)->str; + if (!(*line = ft_strdup(save))) + return (-1); + ft_bzero(save, BUFF_SIZE + 1); + if ((pos = ft_strchr(*line, '\n'))) + { + ft_strcpy(save, pos + 1); + *pos = 0; + return (1); + } + if (!(ret = ft_loop_read(fd, line, save))) + ft_lst_delif(&head, (int *)&fd, ft_fdcmp, &ft_gnlfree); + return (ret); +} diff --git a/nm-otool/libft2/srcs/lst/ft_id.c b/nm-otool/libft/srcs/lst/ft_id.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_id.c rename to nm-otool/libft/srcs/lst/ft_id.c diff --git a/nm-otool/libft/srcs/lst/ft_lst2str.c b/nm-otool/libft/srcs/lst/ft_lst2str.c new file mode 100644 index 00000000..b985083d --- /dev/null +++ b/nm-otool/libft/srcs/lst/ft_lst2str.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst2str.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:53:18 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:53:19 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_lst2str(t_list *list) +{ + size_t size; + t_list *tmp; + char *new; + + size = 0; + tmp = list; + while (tmp) + { + size += ft_strlen((char *)tmp->content) + 1; + tmp = tmp->next; + } + new = ft_memalloc(size); + while (list) + { + ft_strcat(new, (char *)list->content); + if (list->next) + ft_strcat(new, " "); + list = list->next; + } + return (new); +} diff --git a/nm-otool/libft2/srcs/lst/ft_lst_at.c b/nm-otool/libft/srcs/lst/ft_lst_at.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_at.c rename to nm-otool/libft/srcs/lst/ft_lst_at.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_bfree.c b/nm-otool/libft/srcs/lst/ft_lst_bfree.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_bfree.c rename to nm-otool/libft/srcs/lst/ft_lst_bfree.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_cfree.c b/nm-otool/libft/srcs/lst/ft_lst_cfree.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_cfree.c rename to nm-otool/libft/srcs/lst/ft_lst_cfree.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_delif.c b/nm-otool/libft/srcs/lst/ft_lst_delif.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_delif.c rename to nm-otool/libft/srcs/lst/ft_lst_delif.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_delsub.c b/nm-otool/libft/srcs/lst/ft_lst_delsub.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_delsub.c rename to nm-otool/libft/srcs/lst/ft_lst_delsub.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_filter.c b/nm-otool/libft/srcs/lst/ft_lst_filter.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_filter.c rename to nm-otool/libft/srcs/lst/ft_lst_filter.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_filterout.c b/nm-otool/libft/srcs/lst/ft_lst_filterout.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_filterout.c rename to nm-otool/libft/srcs/lst/ft_lst_filterout.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_find.c b/nm-otool/libft/srcs/lst/ft_lst_find.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_find.c rename to nm-otool/libft/srcs/lst/ft_lst_find.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_merge.c b/nm-otool/libft/srcs/lst/ft_lst_merge.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_merge.c rename to nm-otool/libft/srcs/lst/ft_lst_merge.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_order_delsub.c b/nm-otool/libft/srcs/lst/ft_lst_order_delsub.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_order_delsub.c rename to nm-otool/libft/srcs/lst/ft_lst_order_delsub.c diff --git a/nm-otool/libft/srcs/lst/ft_lst_pop.c b/nm-otool/libft/srcs/lst/ft_lst_pop.c new file mode 100644 index 00000000..1e22b0d7 --- /dev/null +++ b/nm-otool/libft/srcs/lst/ft_lst_pop.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst_pop.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:53:30 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:53:31 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lst_pop(t_list **lst) +{ + t_list *top; + + top = *lst; + if (lst && *lst) + *lst = (*lst)->next; + return (top); +} diff --git a/nm-otool/libft2/srcs/lst/ft_lst_print.c b/nm-otool/libft/srcs/lst/ft_lst_print.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_print.c rename to nm-otool/libft/srcs/lst/ft_lst_print.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_print2.c b/nm-otool/libft/srcs/lst/ft_lst_print2.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_print2.c rename to nm-otool/libft/srcs/lst/ft_lst_print2.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_removeif.c b/nm-otool/libft/srcs/lst/ft_lst_removeif.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_removeif.c rename to nm-otool/libft/srcs/lst/ft_lst_removeif.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_reverse.c b/nm-otool/libft/srcs/lst/ft_lst_reverse.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_reverse.c rename to nm-otool/libft/srcs/lst/ft_lst_reverse.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_size.c b/nm-otool/libft/srcs/lst/ft_lst_size.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_size.c rename to nm-otool/libft/srcs/lst/ft_lst_size.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_sorted_insert.c b/nm-otool/libft/srcs/lst/ft_lst_sorted_insert.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_sorted_insert.c rename to nm-otool/libft/srcs/lst/ft_lst_sorted_insert.c diff --git a/nm-otool/libft2/srcs/lst/ft_lst_sorted_merge.c b/nm-otool/libft/srcs/lst/ft_lst_sorted_merge.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lst_sorted_merge.c rename to nm-otool/libft/srcs/lst/ft_lst_sorted_merge.c diff --git a/nm-otool/libft2/srcs/lst/ft_lstadd.c b/nm-otool/libft/srcs/lst/ft_lstadd.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lstadd.c rename to nm-otool/libft/srcs/lst/ft_lstadd.c diff --git a/nm-otool/libft2/srcs/lst/ft_lstdel.c b/nm-otool/libft/srcs/lst/ft_lstdel.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lstdel.c rename to nm-otool/libft/srcs/lst/ft_lstdel.c diff --git a/nm-otool/libft2/srcs/lst/ft_lstdelone.c b/nm-otool/libft/srcs/lst/ft_lstdelone.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lstdelone.c rename to nm-otool/libft/srcs/lst/ft_lstdelone.c diff --git a/nm-otool/libft2/srcs/lst/ft_lsteadd.c b/nm-otool/libft/srcs/lst/ft_lsteadd.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lsteadd.c rename to nm-otool/libft/srcs/lst/ft_lsteadd.c diff --git a/nm-otool/libft2/srcs/lst/ft_lstiter.c b/nm-otool/libft/srcs/lst/ft_lstiter.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lstiter.c rename to nm-otool/libft/srcs/lst/ft_lstiter.c diff --git a/nm-otool/libft2/srcs/lst/ft_lstlast.c b/nm-otool/libft/srcs/lst/ft_lstlast.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lstlast.c rename to nm-otool/libft/srcs/lst/ft_lstlast.c diff --git a/nm-otool/libft2/srcs/lst/ft_lstmap.c b/nm-otool/libft/srcs/lst/ft_lstmap.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lstmap.c rename to nm-otool/libft/srcs/lst/ft_lstmap.c diff --git a/nm-otool/libft2/srcs/lst/ft_lstnadd.c b/nm-otool/libft/srcs/lst/ft_lstnadd.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lstnadd.c rename to nm-otool/libft/srcs/lst/ft_lstnadd.c diff --git a/nm-otool/libft2/srcs/lst/ft_lstnew.c b/nm-otool/libft/srcs/lst/ft_lstnew.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lstnew.c rename to nm-otool/libft/srcs/lst/ft_lstnew.c diff --git a/nm-otool/libft2/srcs/lst/ft_lstnew_range.c b/nm-otool/libft/srcs/lst/ft_lstnew_range.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lstnew_range.c rename to nm-otool/libft/srcs/lst/ft_lstnew_range.c diff --git a/nm-otool/libft2/srcs/lst/ft_lstsort.c b/nm-otool/libft/srcs/lst/ft_lstsort.c similarity index 100% rename from nm-otool/libft2/srcs/lst/ft_lstsort.c rename to nm-otool/libft/srcs/lst/ft_lstsort.c diff --git a/nm-otool/libft2/srcs/lst/lst_insert_sort.c b/nm-otool/libft/srcs/lst/lst_insert_sort.c similarity index 100% rename from nm-otool/libft2/srcs/lst/lst_insert_sort.c rename to nm-otool/libft/srcs/lst/lst_insert_sort.c diff --git a/nm-otool/libft2/srcs/lst/pop.c b/nm-otool/libft/srcs/lst/pop.c similarity index 100% rename from nm-otool/libft2/srcs/lst/pop.c rename to nm-otool/libft/srcs/lst/pop.c diff --git a/nm-otool/libft2/srcs/lst/push.c b/nm-otool/libft/srcs/lst/push.c similarity index 100% rename from nm-otool/libft2/srcs/lst/push.c rename to nm-otool/libft/srcs/lst/push.c diff --git a/nm-otool/libft2/srcs/lst/top.c b/nm-otool/libft/srcs/lst/top.c similarity index 100% rename from nm-otool/libft2/srcs/lst/top.c rename to nm-otool/libft/srcs/lst/top.c diff --git a/nm-otool/libft2/srcs/math/ft_addrcmp.c b/nm-otool/libft/srcs/math/ft_addrcmp.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_addrcmp.c rename to nm-otool/libft/srcs/math/ft_addrcmp.c diff --git a/nm-otool/libft2/srcs/math/ft_ilen.c b/nm-otool/libft/srcs/math/ft_ilen.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_ilen.c rename to nm-otool/libft/srcs/math/ft_ilen.c diff --git a/nm-otool/libft2/srcs/math/ft_ilen_base.c b/nm-otool/libft/srcs/math/ft_ilen_base.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_ilen_base.c rename to nm-otool/libft/srcs/math/ft_ilen_base.c diff --git a/nm-otool/libft2/srcs/math/ft_itoa.c b/nm-otool/libft/srcs/math/ft_itoa.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_itoa.c rename to nm-otool/libft/srcs/math/ft_itoa.c diff --git a/nm-otool/libft2/srcs/math/ft_itoa_base.c b/nm-otool/libft/srcs/math/ft_itoa_base.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_itoa_base.c rename to nm-otool/libft/srcs/math/ft_itoa_base.c diff --git a/nm-otool/libft2/srcs/math/ft_lllen.c b/nm-otool/libft/srcs/math/ft_lllen.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_lllen.c rename to nm-otool/libft/srcs/math/ft_lllen.c diff --git a/nm-otool/libft2/srcs/math/ft_lllen_base.c b/nm-otool/libft/srcs/math/ft_lllen_base.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_lllen_base.c rename to nm-otool/libft/srcs/math/ft_lllen_base.c diff --git a/nm-otool/libft2/srcs/math/ft_lltoa_base.c b/nm-otool/libft/srcs/math/ft_lltoa_base.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_lltoa_base.c rename to nm-otool/libft/srcs/math/ft_lltoa_base.c diff --git a/nm-otool/libft2/srcs/math/ft_uilen.c b/nm-otool/libft/srcs/math/ft_uilen.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_uilen.c rename to nm-otool/libft/srcs/math/ft_uilen.c diff --git a/nm-otool/libft2/srcs/math/ft_uitoa_base.c b/nm-otool/libft/srcs/math/ft_uitoa_base.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_uitoa_base.c rename to nm-otool/libft/srcs/math/ft_uitoa_base.c diff --git a/nm-otool/libft2/srcs/math/ft_ulltoa_base.c b/nm-otool/libft/srcs/math/ft_ulltoa_base.c similarity index 100% rename from nm-otool/libft2/srcs/math/ft_ulltoa_base.c rename to nm-otool/libft/srcs/math/ft_ulltoa_base.c diff --git a/nm-otool/libft2/srcs/math/id.c b/nm-otool/libft/srcs/math/id.c similarity index 100% rename from nm-otool/libft2/srcs/math/id.c rename to nm-otool/libft/srcs/math/id.c diff --git a/nm-otool/libft2/srcs/mem/ft_bzero.c b/nm-otool/libft/srcs/mem/ft_bzero.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_bzero.c rename to nm-otool/libft/srcs/mem/ft_bzero.c diff --git a/nm-otool/libft2/srcs/mem/ft_malloc.c b/nm-otool/libft/srcs/mem/ft_malloc.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_malloc.c rename to nm-otool/libft/srcs/mem/ft_malloc.c diff --git a/nm-otool/libft2/srcs/mem/ft_memalloc.c b/nm-otool/libft/srcs/mem/ft_memalloc.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_memalloc.c rename to nm-otool/libft/srcs/mem/ft_memalloc.c diff --git a/nm-otool/libft2/srcs/mem/ft_memccpy.c b/nm-otool/libft/srcs/mem/ft_memccpy.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_memccpy.c rename to nm-otool/libft/srcs/mem/ft_memccpy.c diff --git a/nm-otool/libft2/srcs/mem/ft_memchr.c b/nm-otool/libft/srcs/mem/ft_memchr.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_memchr.c rename to nm-otool/libft/srcs/mem/ft_memchr.c diff --git a/nm-otool/libft2/srcs/mem/ft_memcmp.c b/nm-otool/libft/srcs/mem/ft_memcmp.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_memcmp.c rename to nm-otool/libft/srcs/mem/ft_memcmp.c diff --git a/nm-otool/libft2/srcs/mem/ft_memcpy.c b/nm-otool/libft/srcs/mem/ft_memcpy.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_memcpy.c rename to nm-otool/libft/srcs/mem/ft_memcpy.c diff --git a/nm-otool/libft2/srcs/mem/ft_memdel.c b/nm-otool/libft/srcs/mem/ft_memdel.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_memdel.c rename to nm-otool/libft/srcs/mem/ft_memdel.c diff --git a/nm-otool/libft2/srcs/mem/ft_memmove.c b/nm-otool/libft/srcs/mem/ft_memmove.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_memmove.c rename to nm-otool/libft/srcs/mem/ft_memmove.c diff --git a/nm-otool/libft2/srcs/mem/ft_memset.c b/nm-otool/libft/srcs/mem/ft_memset.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_memset.c rename to nm-otool/libft/srcs/mem/ft_memset.c diff --git a/nm-otool/libft2/srcs/mem/ft_realloc.c b/nm-otool/libft/srcs/mem/ft_realloc.c similarity index 100% rename from nm-otool/libft2/srcs/mem/ft_realloc.c rename to nm-otool/libft/srcs/mem/ft_realloc.c diff --git a/nm-otool/libft/srcs/net/create_client.c b/nm-otool/libft/srcs/net/create_client.c new file mode 100644 index 00000000..3cbd1730 --- /dev/null +++ b/nm-otool/libft/srcs/net/create_client.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* create_client.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:59:28 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:02:25 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int create_client(char *addr, int port, char *protoname) +{ + int sock; + struct protoent *proto; + struct sockaddr_in sin; + + if (!(proto = getprotobyname(protoname))) + return (-1); + sock = socket(PF_INET, SOCK_STREAM, proto->p_proto); + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + sin.sin_addr.s_addr = inet_addr(addr); + if (connect(sock, (const struct sockaddr *)&sin, sizeof(sin)) < 0) + return (-1); + return (sock); +} + +void listener(int domain, int sock, int proto, + void (*handler)(void *buf, int bytes, struct sockaddr_in *addr)) +{ + int sd; + struct sockaddr_in addr; + unsigned char buf[1024]; + int bytes; + socklen_t len; + + len = sizeof(addr); + sd = socket(domain, sock, proto); + if (sd < 0) + { + perror("listener socket"); + exit(0); + } + while (1) + { + bzero(buf, sizeof(buf)); + bytes = recvfrom(sd, buf, sizeof(buf), 0, + (struct sockaddr*)&addr, &len); + if (bytes > 0 && handler) + handler(buf, bytes, &addr); + else + perror("recvfrom"); + } + exit(0); +} diff --git a/nm-otool/libft/srcs/net/create_server.c b/nm-otool/libft/srcs/net/create_server.c new file mode 100644 index 00000000..ffba3385 --- /dev/null +++ b/nm-otool/libft/srcs/net/create_server.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* create_server.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:02:51 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:02:51 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int create_server(int port, int backlog, char *protoname) +{ + int sock; + struct protoent *proto; + struct sockaddr_in sin; + + if (!(proto = getprotobyname(protoname))) + return (-1); + sock = socket(PF_INET, SOCK_STREAM, proto->p_proto); + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + sin.sin_addr.s_addr = htonl(INADDR_ANY); + if (bind(sock, (const struct sockaddr *)&sin, sizeof(sin)) < 0) + return (-1); + listen(sock, backlog); + return (sock); +} diff --git a/nm-otool/libft/srcs/net/forge_ip.c b/nm-otool/libft/srcs/net/forge_ip.c new file mode 100644 index 00000000..c40ceeac --- /dev/null +++ b/nm-otool/libft/srcs/net/forge_ip.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* forge_ip.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:02:39 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:18:07 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "net.h" + +void iphdr_init(struct ip *header) +{ + memset(header, 0, sizeof(*header)); + header->ip_v = 4; + header->ip_hl = 5; + header->ip_tos = 0; + header->ip_len = 0; + header->ip_id = ntohl(epoch_micro()); + header->ip_off = 0; + header->ip_ttl = 255; + header->ip_p = 0; + header->ip_sum = 0; + memset(&header->ip_src, 0, sizeof(struct in_addr)); + memset(&header->ip_dst, 0, sizeof(struct in_addr)); +} diff --git a/nm-otool/libft/srcs/net/forge_tcp.c b/nm-otool/libft/srcs/net/forge_tcp.c new file mode 100644 index 00000000..b0c84dcb --- /dev/null +++ b/nm-otool/libft/srcs/net/forge_tcp.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* forge_tcp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:02:34 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:17:04 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "net.h" + +void tcphdr_init(struct tcphdr *header) +{ + memset(header, 0, sizeof(*header)); + header->th_sport = htons(0); + header->th_dport = htons(0); + header->th_seq = epoch_micro(); + header->th_ack = 0; + header->th_off = 5; + header->th_flags = 0; + header->th_win = htons(1024); + header->th_sum = 0; + header->th_urp = 0; +} diff --git a/nm-otool/libft/srcs/net/net_get.c b/nm-otool/libft/srcs/net/net_get.c new file mode 100644 index 00000000..e75b58ad --- /dev/null +++ b/nm-otool/libft/srcs/net/net_get.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* net_get.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:59:19 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:59:20 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int net_get(int sock, char *msg, int size) +{ + int ack; + + ack = htons(ACK); + if (read(sock, msg, size) < 0) + return (-1); + if (write(sock, (char*)&ack, sizeof(ack)) < 0) + return (-1); + return (0); +} + +int net_get_fd(int sock, int fd, int size) +{ + int ack; + char msg[size]; + + ack = htons(ACK); + if (read(sock, msg, size) < 0) + return (-1); + if (write(sock, (char*)&ack, sizeof(ack)) < 0) + return (-1); + if (write(fd, msg, size) < 0) + return (-1); + return (0); +} + +int net_get_large(int sock, int fd) +{ + int i; + int num_blks; + int num_last_blk; + + net_get(sock, (char*)&num_blks, sizeof(num_blks)); + net_get(sock, (char*)&num_last_blk, sizeof(num_last_blk)); + num_blks = ntohs(num_blks); + num_last_blk = ntohs(num_last_blk); + i = -1; + while (++i < num_blks - 1) + net_get_fd(sock, fd, NET_MAXSIZE); + if (num_last_blk) + net_get_fd(sock, fd, num_last_blk); + return (0); +} diff --git a/nm-otool/libft/srcs/net/net_send.c b/nm-otool/libft/srcs/net/net_send.c new file mode 100644 index 00000000..c9a026a1 --- /dev/null +++ b/nm-otool/libft/srcs/net/net_send.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* net_send.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:03:19 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:03:31 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int net_send(int sock, char *msg, int size) +{ + int ack; + + if (write(sock, msg, size) < 0) + return (-1); + if (read(sock, (char*)&ack, sizeof(ack)) < 0) + return (-1); + if (ntohs(ack) != ACK) + return (1); + return (0); +} + +int net_send_large(int sock, char *msg, int size) +{ + int i; + int num_blks; + int num_last_blk; + + num_blks = htons(size / NET_MAXSIZE + 1); + num_last_blk = htons(size % NET_MAXSIZE); + if (net_send(sock, (char*)&num_blks, sizeof(num_blks))) + return (1); + if (net_send(sock, (char*)&num_last_blk, sizeof(num_blks))) + return (1); + num_blks = ntohs(num_blks); + num_last_blk = ntohs(num_last_blk); + i = -1; + while (++i < num_blks - 1) + net_send(sock, msg + i * NET_MAXSIZE, NET_MAXSIZE); + if (num_last_blk) + net_send(sock, msg + i * NET_MAXSIZE, num_last_blk); + return (0); +} diff --git a/nm-otool/libft/srcs/net/reserve_port.c b/nm-otool/libft/srcs/net/reserve_port.c new file mode 100644 index 00000000..53ebf566 --- /dev/null +++ b/nm-otool/libft/srcs/net/reserve_port.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* reserve_port.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:02:55 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:03:15 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "net.h" + +int reserve_port(int *port) +{ + struct sockaddr_in sa; + int sockfd; + unsigned short i; + + if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) + return (1); + sa.sin_family = AF_INET; + sa.sin_addr.s_addr = INADDR_ANY; + i = 49152; + while (i < 65535) + { + sa.sin_port = htons(i); + if (bind(sockfd, (struct sockaddr*)&sa, sizeof(sa)) == 0) + { + *port = i; + return (0); + } + ++i; + } + return (1); +} diff --git a/nm-otool/libft2/srcs/path/ft_path_notdir.c b/nm-otool/libft/srcs/path/ft_path_notdir.c similarity index 100% rename from nm-otool/libft2/srcs/path/ft_path_notdir.c rename to nm-otool/libft/srcs/path/ft_path_notdir.c diff --git a/nm-otool/libft2/srcs/printing/ft_putchar.c b/nm-otool/libft/srcs/printing/ft_putchar.c similarity index 100% rename from nm-otool/libft2/srcs/printing/ft_putchar.c rename to nm-otool/libft/srcs/printing/ft_putchar.c diff --git a/nm-otool/libft2/srcs/printing/ft_putendl.c b/nm-otool/libft/srcs/printing/ft_putendl.c similarity index 100% rename from nm-otool/libft2/srcs/printing/ft_putendl.c rename to nm-otool/libft/srcs/printing/ft_putendl.c diff --git a/nm-otool/libft2/srcs/printing/ft_putnbr.c b/nm-otool/libft/srcs/printing/ft_putnbr.c similarity index 100% rename from nm-otool/libft2/srcs/printing/ft_putnbr.c rename to nm-otool/libft/srcs/printing/ft_putnbr.c diff --git a/nm-otool/libft2/srcs/printing/ft_putstr.c b/nm-otool/libft/srcs/printing/ft_putstr.c similarity index 100% rename from nm-otool/libft2/srcs/printing/ft_putstr.c rename to nm-otool/libft/srcs/printing/ft_putstr.c diff --git a/nm-otool/libft/srcs/printing/hexdump.c b/nm-otool/libft/srcs/printing/hexdump.c new file mode 100644 index 00000000..de933085 --- /dev/null +++ b/nm-otool/libft/srcs/printing/hexdump.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hexdump.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:56:14 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:56:40 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static void print_hex_contents(void *addr, unsigned int size) +{ + void *a; + + a = addr; + while (a - addr < 16) + { + if ((a - addr) >= size) + break ; + else + ft_printf("%02x", *(unsigned char*)a); + ft_putchar(' '); + a++; + } +} + +void *hexdump(void *addr, unsigned int offset, unsigned int size) +{ + void *a; + + addr += offset; + a = addr; + if (addr == NULL) + return (addr); + while ((a - addr) < size) + { + ft_printf("%0*llx\t", 16, (a - addr) + (unsigned long)offset); + print_hex_contents(a, (size - (a - addr))); + ft_putchar('\n'); + a += 16; + } + return (addr); +} diff --git a/nm-otool/libft/srcs/rs/rs.c b/nm-otool/libft/srcs/rs/rs.c new file mode 100644 index 00000000..7e83bdff --- /dev/null +++ b/nm-otool/libft/srcs/rs/rs.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rs.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:57:54 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:19:47 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +struct s_stats g_rs = {0, 0, 0, 0, 0, 0, 0}; + +double sqrt(double x); + +void rs_clear(void) +{ + g_rs.count = 0; + g_rs.min = DBL_MAX; + g_rs.max = -DBL_MAX; +} + +void rs_push(double n) +{ + double delta; + + g_rs.count++; + n < g_rs.min ? g_rs.min = n : (0); + n > g_rs.max ? g_rs.max = n : (0); + if (g_rs.count == 1) + { + g_rs.avg = n; + g_rs.m = 0; + } + else + { + delta = n - g_rs.avg; + g_rs.avg += delta / g_rs.count; + g_rs.m += delta * (n - g_rs.avg); + } +} + +void rs_calcmore(void) +{ + if (g_rs.count == 0) + { + g_rs.min = 0; + g_rs.max = 0; + } + if (g_rs.count < 2) + { + g_rs.var = 0; + g_rs.stdev = 0; + return ; + } + g_rs.var = g_rs.m / (g_rs.count - 1); + g_rs.stdev = sqrt(g_rs.var); +} diff --git a/nm-otool/libft/srcs/sstr/ft_sstradd.c b/nm-otool/libft/srcs/sstr/ft_sstradd.c new file mode 100644 index 00000000..c81a256d --- /dev/null +++ b/nm-otool/libft/srcs/sstr/ft_sstradd.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstradd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */ +/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char **ft_sstradd(char **sstr, char *new) +{ + int size; + char **newlist; + + size = 0; + if (sstr) + while (sstr[size]) + size++; + if (!(newlist = (char **)ft_memalloc(sizeof(char *) * (size + 2)))) + return (NULL); + if (sstr) + ft_memcpy(newlist, sstr, sizeof(char*) * size); + newlist[size] = ft_strdup(new); + newlist[size + 1] = NULL; + free(sstr); + return (newlist); +} diff --git a/nm-otool/libft/srcs/sstr/ft_sstrcat.c b/nm-otool/libft/srcs/sstr/ft_sstrcat.c new file mode 100644 index 00000000..313fc24d --- /dev/null +++ b/nm-otool/libft/srcs/sstr/ft_sstrcat.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/10 16:58:06 by jhalford #+# #+# */ +/* Updated: 2016/12/10 17:03:27 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_sstrcat(char **sstr, char sep) +{ + int len; + int i; + char *out; + + i = 0; + len = 0; + if (!sstr) + return (NULL); + while (sstr[i]) + len += ft_strlen(sstr[i++]); + if (!(out = ft_strnew(sizeof(char) * (len + i + 1)))) + return (NULL); + ft_strcpy(out, sstr[0]); + i = 1; + while (sstr[i]) + { + ft_strcat(out, (char[]){sep, 0}); + ft_strcat(out, sstr[i++]); + } + return (out); +} diff --git a/nm-otool/libft/srcs/sstr/ft_sstrdel.c b/nm-otool/libft/srcs/sstr/ft_sstrdel.c new file mode 100644 index 00000000..403fcf00 --- /dev/null +++ b/nm-otool/libft/srcs/sstr/ft_sstrdel.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 18:04:07 by jhalford #+# #+# */ +/* Updated: 2017/03/25 01:38:51 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_sstrdel(char **sstr, int index) +{ + int i; + + i = index; + ft_strdel(&sstr[index]); + while (i == index || sstr[i]) + { + sstr[i] = sstr[i + 1]; + ++i; + } +} diff --git a/nm-otool/libft/srcs/sstr/ft_sstrdup.c b/nm-otool/libft/srcs/sstr/ft_sstrdup.c new file mode 100644 index 00000000..8517a125 --- /dev/null +++ b/nm-otool/libft/srcs/sstr/ft_sstrdup.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/07 14:25:45 by jhalford #+# #+# */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char **ft_sstrdup(char **list) +{ + int i; + int size; + char **cpy; + + i = 0; + size = 0; + while (list[size]) + size++; + cpy = (char **)ft_malloc(sizeof(char *) * (size + 1)); + while (*list) + { + cpy[i++] = ft_strdup(*list); + list++; + } + cpy[i] = NULL; + return (cpy); +} diff --git a/nm-otool/libft/srcs/sstr/ft_sstrfree.c b/nm-otool/libft/srcs/sstr/ft_sstrfree.c new file mode 100644 index 00000000..7855228d --- /dev/null +++ b/nm-otool/libft/srcs/sstr/ft_sstrfree.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrfree.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/05 11:53:36 by jhalford #+# #+# */ +/* Updated: 2017/03/22 23:19:24 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_sstrfree(char **sstr) +{ + int i; + + i = 0; + if (sstr) + { + while (sstr[i]) + { + ft_strdel(sstr + i); + i++; + } + ft_strdel(sstr + i); + free(sstr); + } +} diff --git a/nm-otool/libft/srcs/sstr/ft_sstrmerge.c b/nm-otool/libft/srcs/sstr/ft_sstrmerge.c new file mode 100644 index 00000000..2705a285 --- /dev/null +++ b/nm-otool/libft/srcs/sstr/ft_sstrmerge.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrmerge.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/24 17:40:50 by jhalford #+# #+# */ +/* Updated: 2017/03/24 18:05:08 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char **ft_sstrmerge(char **s1, char **s2) +{ + char **out; + + out = ft_sstrdup(s1); + if (!s2) + return (out); + while (*s2) + { + out = ft_sstradd(out, *s2); + s2++; + } + return (out); +} diff --git a/nm-otool/libft/srcs/sstr/ft_sstrprint.c b/nm-otool/libft/srcs/sstr/ft_sstrprint.c new file mode 100644 index 00000000..1ebc0f5e --- /dev/null +++ b/nm-otool/libft/srcs/sstr/ft_sstrprint.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/28 15:17:33 by jhalford #+# #+# */ +/* Updated: 2016/11/28 15:18:12 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_sstrprint(char **list, char sep) +{ + ft_sstrprint_fd(STDOUT, list, sep); +} diff --git a/nm-otool/libft/srcs/sstr/ft_sstrprint_fd.c b/nm-otool/libft/srcs/sstr/ft_sstrprint_fd.c new file mode 100644 index 00000000..42225b7c --- /dev/null +++ b/nm-otool/libft/srcs/sstr/ft_sstrprint_fd.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrprint_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/28 15:17:29 by jhalford #+# #+# */ +/* Updated: 2017/03/18 03:37:16 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_sstrprint_fd(int fd, char **list, char sep) +{ + int i; + + i = 0; + if (!list || !*list) + return ; + while (list[i]) + { + ft_putstr_fd(list[i++], fd); + if (list[i]) + ft_putchar_fd(sep, fd); + } +} diff --git a/nm-otool/libft/srcs/sstr/ft_sstrsort.c b/nm-otool/libft/srcs/sstr/ft_sstrsort.c new file mode 100644 index 00000000..25cf4134 --- /dev/null +++ b/nm-otool/libft/srcs/sstr/ft_sstrsort.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrsort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 18:03:37 by jhalford #+# #+# */ +/* Updated: 2017/03/23 14:40:25 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_sstrsort(char **list, int (*cmp)()) +{ + int i; + char *tmp; + + i = 0; + while (list[i] && list[i + 1]) + { + if ((*cmp)(list[i], list[i + 1]) > 0) + { + tmp = list[i]; + list[i] = list[i + 1]; + list[i + 1] = tmp; + i = 0; + } + else + i++; + } +} diff --git a/nm-otool/libft/srcs/sstr/ft_sstrstr.c b/nm-otool/libft/srcs/sstr/ft_sstrstr.c new file mode 100644 index 00000000..d6618563 --- /dev/null +++ b/nm-otool/libft/srcs/sstr/ft_sstrstr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/07 11:29:54 by ariard #+# #+# */ +/* Updated: 2017/03/22 21:54:40 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_sstrstr(char **sstr, char *find) +{ + int size; + + if (!sstr) + return (NULL); + size = ft_strlen(find); + while ((*sstr)) + { + if (ft_strncmp(*sstr, find, size) == 0) + return (*sstr); + sstr++; + } + return (NULL); +} diff --git a/nm-otool/libft2/srcs/str/ft_atoi.c b/nm-otool/libft/srcs/str/ft_atoi.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_atoi.c rename to nm-otool/libft/srcs/str/ft_atoi.c diff --git a/nm-otool/libft2/srcs/str/ft_convert_base.c b/nm-otool/libft/srcs/str/ft_convert_base.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_convert_base.c rename to nm-otool/libft/srcs/str/ft_convert_base.c diff --git a/nm-otool/libft2/srcs/str/ft_putaddr_fd.c b/nm-otool/libft/srcs/str/ft_putaddr_fd.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_putaddr_fd.c rename to nm-otool/libft/srcs/str/ft_putaddr_fd.c diff --git a/nm-otool/libft2/srcs/str/ft_split_whitespaces.c b/nm-otool/libft/srcs/str/ft_split_whitespaces.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_split_whitespaces.c rename to nm-otool/libft/srcs/str/ft_split_whitespaces.c diff --git a/nm-otool/libft2/srcs/str/ft_str3join.c b/nm-otool/libft/srcs/str/ft_str3join.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_str3join.c rename to nm-otool/libft/srcs/str/ft_str3join.c diff --git a/nm-otool/libft2/srcs/str/ft_strappend.c b/nm-otool/libft/srcs/str/ft_strappend.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strappend.c rename to nm-otool/libft/srcs/str/ft_strappend.c diff --git a/nm-otool/libft2/srcs/str/ft_strbetween.c b/nm-otool/libft/srcs/str/ft_strbetween.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strbetween.c rename to nm-otool/libft/srcs/str/ft_strbetween.c diff --git a/nm-otool/libft2/srcs/str/ft_strcat.c b/nm-otool/libft/srcs/str/ft_strcat.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strcat.c rename to nm-otool/libft/srcs/str/ft_strcat.c diff --git a/nm-otool/libft2/srcs/str/ft_strcatf.c b/nm-otool/libft/srcs/str/ft_strcatf.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strcatf.c rename to nm-otool/libft/srcs/str/ft_strcatf.c diff --git a/nm-otool/libft2/srcs/str/ft_strchr.c b/nm-otool/libft/srcs/str/ft_strchr.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strchr.c rename to nm-otool/libft/srcs/str/ft_strchr.c diff --git a/nm-otool/libft2/srcs/str/ft_strchrcpy.c b/nm-otool/libft/srcs/str/ft_strchrcpy.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strchrcpy.c rename to nm-otool/libft/srcs/str/ft_strchrcpy.c diff --git a/nm-otool/libft2/srcs/str/ft_strclr.c b/nm-otool/libft/srcs/str/ft_strclr.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strclr.c rename to nm-otool/libft/srcs/str/ft_strclr.c diff --git a/nm-otool/libft2/srcs/str/ft_strcmp.c b/nm-otool/libft/srcs/str/ft_strcmp.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strcmp.c rename to nm-otool/libft/srcs/str/ft_strcmp.c diff --git a/nm-otool/libft2/srcs/str/ft_strcpy.c b/nm-otool/libft/srcs/str/ft_strcpy.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strcpy.c rename to nm-otool/libft/srcs/str/ft_strcpy.c diff --git a/nm-otool/libft2/srcs/str/ft_strcspn.c b/nm-otool/libft/srcs/str/ft_strcspn.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strcspn.c rename to nm-otool/libft/srcs/str/ft_strcspn.c diff --git a/nm-otool/libft2/srcs/str/ft_strcut.c b/nm-otool/libft/srcs/str/ft_strcut.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strcut.c rename to nm-otool/libft/srcs/str/ft_strcut.c diff --git a/nm-otool/libft2/srcs/str/ft_strdel.c b/nm-otool/libft/srcs/str/ft_strdel.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strdel.c rename to nm-otool/libft/srcs/str/ft_strdel.c diff --git a/nm-otool/libft2/srcs/str/ft_strdup.c b/nm-otool/libft/srcs/str/ft_strdup.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strdup.c rename to nm-otool/libft/srcs/str/ft_strdup.c diff --git a/nm-otool/libft2/srcs/str/ft_strdupchr.c b/nm-otool/libft/srcs/str/ft_strdupchr.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strdupchr.c rename to nm-otool/libft/srcs/str/ft_strdupchr.c diff --git a/nm-otool/libft2/srcs/str/ft_strduptr.c b/nm-otool/libft/srcs/str/ft_strduptr.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strduptr.c rename to nm-otool/libft/srcs/str/ft_strduptr.c diff --git a/nm-otool/libft2/srcs/str/ft_strequ.c b/nm-otool/libft/srcs/str/ft_strequ.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strequ.c rename to nm-otool/libft/srcs/str/ft_strequ.c diff --git a/nm-otool/libft2/srcs/str/ft_strinsert.c b/nm-otool/libft/srcs/str/ft_strinsert.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strinsert.c rename to nm-otool/libft/srcs/str/ft_strinsert.c diff --git a/nm-otool/libft2/srcs/str/ft_stris.c b/nm-otool/libft/srcs/str/ft_stris.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_stris.c rename to nm-otool/libft/srcs/str/ft_stris.c diff --git a/nm-otool/libft2/srcs/str/ft_striter.c b/nm-otool/libft/srcs/str/ft_striter.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_striter.c rename to nm-otool/libft/srcs/str/ft_striter.c diff --git a/nm-otool/libft2/srcs/str/ft_striteri.c b/nm-otool/libft/srcs/str/ft_striteri.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_striteri.c rename to nm-otool/libft/srcs/str/ft_striteri.c diff --git a/nm-otool/libft2/srcs/str/ft_strjoin.c b/nm-otool/libft/srcs/str/ft_strjoin.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strjoin.c rename to nm-otool/libft/srcs/str/ft_strjoin.c diff --git a/nm-otool/libft2/srcs/str/ft_strlcat.c b/nm-otool/libft/srcs/str/ft_strlcat.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strlcat.c rename to nm-otool/libft/srcs/str/ft_strlcat.c diff --git a/nm-otool/libft2/srcs/str/ft_strlen.c b/nm-otool/libft/srcs/str/ft_strlen.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strlen.c rename to nm-otool/libft/srcs/str/ft_strlen.c diff --git a/nm-otool/libft2/srcs/str/ft_strlenchr.c b/nm-otool/libft/srcs/str/ft_strlenchr.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strlenchr.c rename to nm-otool/libft/srcs/str/ft_strlenchr.c diff --git a/nm-otool/libft2/srcs/str/ft_strmap.c b/nm-otool/libft/srcs/str/ft_strmap.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strmap.c rename to nm-otool/libft/srcs/str/ft_strmap.c diff --git a/nm-otool/libft2/srcs/str/ft_strmapi.c b/nm-otool/libft/srcs/str/ft_strmapi.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strmapi.c rename to nm-otool/libft/srcs/str/ft_strmapi.c diff --git a/nm-otool/libft2/srcs/str/ft_strncat.c b/nm-otool/libft/srcs/str/ft_strncat.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strncat.c rename to nm-otool/libft/srcs/str/ft_strncat.c diff --git a/nm-otool/libft2/srcs/str/ft_strncmp.c b/nm-otool/libft/srcs/str/ft_strncmp.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strncmp.c rename to nm-otool/libft/srcs/str/ft_strncmp.c diff --git a/nm-otool/libft2/srcs/str/ft_strncpy.c b/nm-otool/libft/srcs/str/ft_strncpy.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strncpy.c rename to nm-otool/libft/srcs/str/ft_strncpy.c diff --git a/nm-otool/libft/srcs/str/ft_strndup.c b/nm-otool/libft/srcs/str/ft_strndup.c new file mode 100644 index 00000000..ee942d34 --- /dev/null +++ b/nm-otool/libft/srcs/str/ft_strndup.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strndup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:53:55 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:54:30 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strndup(const char *s1, size_t n) +{ + char *dup; + + if (!(dup = ft_memalloc(n))) + return (NULL); + ft_strncpy(dup, s1, n); + return (dup); +} diff --git a/nm-otool/libft2/srcs/str/ft_strnequ.c b/nm-otool/libft/srcs/str/ft_strnequ.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strnequ.c rename to nm-otool/libft/srcs/str/ft_strnequ.c diff --git a/nm-otool/libft2/srcs/str/ft_strnew.c b/nm-otool/libft/srcs/str/ft_strnew.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strnew.c rename to nm-otool/libft/srcs/str/ft_strnew.c diff --git a/nm-otool/libft2/srcs/str/ft_strnstr.c b/nm-otool/libft/srcs/str/ft_strnstr.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strnstr.c rename to nm-otool/libft/srcs/str/ft_strnstr.c diff --git a/nm-otool/libft2/srcs/str/ft_strrchr.c b/nm-otool/libft/srcs/str/ft_strrchr.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strrchr.c rename to nm-otool/libft/srcs/str/ft_strrchr.c diff --git a/nm-otool/libft2/srcs/str/ft_strreplace.c b/nm-otool/libft/srcs/str/ft_strreplace.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strreplace.c rename to nm-otool/libft/srcs/str/ft_strreplace.c diff --git a/nm-otool/libft2/srcs/str/ft_strrev.c b/nm-otool/libft/srcs/str/ft_strrev.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strrev.c rename to nm-otool/libft/srcs/str/ft_strrev.c diff --git a/nm-otool/libft/srcs/str/ft_strsepjoin.c b/nm-otool/libft/srcs/str/ft_strsepjoin.c new file mode 100644 index 00000000..054e4061 --- /dev/null +++ b/nm-otool/libft/srcs/str/ft_strsepjoin.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsepjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:54:06 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:54:07 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strsepjoin(char **tab, char sep) +{ + char *join; + char **p; + int len; + + len = 0; + if (!(p = tab)) + return (NULL); + while (*p) + len += ft_strlen(*p++) + 1; + if (!(join = ft_strnew(len))) + return (NULL); + *join = 0; + p = tab; + while (*p) + { + ft_strcat(join, *p++); + ft_strcat(join, &sep); + } + join[len - 1] = 0; + return (join); +} diff --git a/nm-otool/libft2/srcs/str/ft_strsplit.c b/nm-otool/libft/srcs/str/ft_strsplit.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strsplit.c rename to nm-otool/libft/srcs/str/ft_strsplit.c diff --git a/nm-otool/libft2/srcs/str/ft_strstr.c b/nm-otool/libft/srcs/str/ft_strstr.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strstr.c rename to nm-otool/libft/srcs/str/ft_strstr.c diff --git a/nm-otool/libft2/srcs/str/ft_strsub.c b/nm-otool/libft/srcs/str/ft_strsub.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strsub.c rename to nm-otool/libft/srcs/str/ft_strsub.c diff --git a/nm-otool/libft2/srcs/str/ft_strtok.c b/nm-otool/libft/srcs/str/ft_strtok.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strtok.c rename to nm-otool/libft/srcs/str/ft_strtok.c diff --git a/nm-otool/libft2/srcs/str/ft_strtrim.c b/nm-otool/libft/srcs/str/ft_strtrim.c similarity index 100% rename from nm-otool/libft2/srcs/str/ft_strtrim.c rename to nm-otool/libft/srcs/str/ft_strtrim.c diff --git a/nm-otool/libft/srcs/sys/open_new.c b/nm-otool/libft/srcs/sys/open_new.c new file mode 100644 index 00000000..2b5e24df --- /dev/null +++ b/nm-otool/libft/srcs/sys/open_new.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* open_new.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:56:58 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:57:28 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* +** If file already exists, create xxx(1) instead, etc up to 9 +*/ + +int open_new(char *filename, int oflag) +{ + char *fname; + int fd; + int i; + int len; + + len = ft_strlen(filename); + fname = ft_strnew(len + 4); + ft_strcpy(fname, filename); + i = 0; + while (i < 10 && (fd = open(fname, oflag | O_CREAT | O_EXCL, 0644)) < 0 + && errno == EEXIST) + { + fname[len] = '('; + fname[len + 1] = ++i + '0'; + fname[len + 2] = ')'; + } + ft_strdel(&fname); + return (fd); +} diff --git a/nm-otool/libft/srcs/time/epoch.c b/nm-otool/libft/srcs/time/epoch.c new file mode 100644 index 00000000..b6d68119 --- /dev/null +++ b/nm-otool/libft/srcs/time/epoch.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* epoch.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:58:42 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:58:43 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "mytime.h" + +size_t epoch_micro(void) +{ + struct timeval tv; + + if (gettimeofday(&tv, NULL)) + return (0); + return (tv.tv_sec * 1000000 + tv.tv_usec); +} diff --git a/nm-otool/libft/srcs/time/ft_mytime_free.c b/nm-otool/libft/srcs/time/ft_mytime_free.c new file mode 100644 index 00000000..c8a89efc --- /dev/null +++ b/nm-otool/libft/srcs/time/ft_mytime_free.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_mytime_free.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/25 11:45:29 by jhalford #+# #+# */ +/* Updated: 2017/02/18 13:11:33 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_mytime_free(t_mytime **time) +{ + ft_strdel(&(*time)->year); + ft_strdel(&(*time)->month); + ft_strdel(&(*time)->day); + ft_strdel(&(*time)->hour); + ft_strdel(&(*time)->min); + ft_strdel(&(*time)->sec); + ft_memdel((void **)time); +} diff --git a/nm-otool/libft/srcs/time/ft_mytime_get.c b/nm-otool/libft/srcs/time/ft_mytime_get.c new file mode 100644 index 00000000..ab8f25b3 --- /dev/null +++ b/nm-otool/libft/srcs/time/ft_mytime_get.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_getstrtime.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/25 11:34:56 by jhalford #+# #+# */ +/* Updated: 2017/03/21 15:42:19 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_mytime *ft_mytime_get(time_t epoch) +{ + char *date; + t_mytime *time; + + time = (t_mytime*)ft_malloc(sizeof(*time)); + date = ctime(&epoch); + date[ft_strlen(date) - 1] = 0; + time->year = ft_isdigit(date[20]) ? + ft_strsub(date, 20, 4) : ft_strsub(date, 24, 5); + time->month = ft_strsub(date, 4, 3); + time->day = ft_strsub(date, 8, 2); + time->hour = ft_strsub(date, 11, 2); + time->min = ft_strsub(date, 14, 2); + time->sec = ft_strsub(date, 17, 2); + return (time); +} diff --git a/nm-otool/libft/srcs/time/ft_time_isrecent.c b/nm-otool/libft/srcs/time/ft_time_isrecent.c new file mode 100644 index 00000000..ec195653 --- /dev/null +++ b/nm-otool/libft/srcs/time/ft_time_isrecent.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_time_isrecent.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 18:01:04 by jhalford #+# #+# */ +/* Updated: 2017/03/21 15:44:24 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_time_isrecent(time_t event) +{ + time_t now; + + now = time(&now); + if (now - event >= 0 && now - event <= 6 * 365 / 12 * 24 * 60 * 60) + return (1); + else + return (0); +} diff --git a/nm-otool/libft2/includes/hashtab.h b/nm-otool/libft2/includes/hashtab.h deleted file mode 100644 index 0cb7c7a7..00000000 --- a/nm-otool/libft2/includes/hashtab.h +++ /dev/null @@ -1,52 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hashtab.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/05/15 19:16:49 by ariard #+# #+# */ -/* Updated: 2017/06/22 20:25:20 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef HASHTAB_H -# define HASHTAB_H - -# include "libft.h" - -struct s_hashtab -{ - int capacity; - int size; - int (*hashfunc)(const void *key, int capacity); - struct s_list **head; -}; - -typedef struct s_hashtab t_hashtab; - -void hashtab_init(t_hashtab *htb, int capacity, - int (*hashfunc)(const void *key, int size)); - -int hashtab_insert(t_hashtab *htb, struct s_list *new, void *key, - int (*match)(const void *data_ref, const void *key)); - -struct s_list *hashtab_lookup(t_hashtab *htb, void *key, - int (*match)(const void *data_ref, const void *key)); - -struct s_list *hashtab_remove(t_hashtab *htb, void *key, - int (*match)(const void *data_ref, const void *key)); - -void hashtab_destroy(t_hashtab *htb, void (*destroy)()); - -void hashtab_print(t_hashtab *htb, int (*printer)()); - -int ft_hash_string(const void *key, int size); - -struct s_list *hashtab_iterator(t_hashtab *htb, char init); - -void hashtab_del(t_hashtab *htb, void *key, - int (*match)(const void *, const void *), - void (*del)(void *, size_t)); - -#endif diff --git a/nm-otool/libft2/includes/net.h b/nm-otool/libft2/includes/net.h deleted file mode 100644 index 284db344..00000000 --- a/nm-otool/libft2/includes/net.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef NET_H -# define NET_H - -# define ACK 2 -# define NACK 3 -# define NET_MAXSIZE 512 - -# include -# include -# include -# include -# include -# include - -#include "mytime.h" - -int create_server(int port, int backlog, char *protoname); -int create_client(char *addr, int port, char *protoname); -void listener(int domain, int sock, int proto, void (*handler)(void *buf, int bytes, struct sockaddr_in *addr)); - -int net_send(int sock, char *msg, int size); -int net_send_large(int sock, char *msg, int size); -int net_get(int sock, char *msg, int size); -int net_get_fd(int sock, int fd, int size); -int net_get_large(int sock, int fd); - -int reserve_port(int *port); - -void tcphdr_init(struct tcphdr *header); -void iphdr_init(struct iphdr *header); - - -#endif diff --git a/nm-otool/libft2/includes/rs.h b/nm-otool/libft2/includes/rs.h deleted file mode 100644 index c5b716e4..00000000 --- a/nm-otool/libft2/includes/rs.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef LIBFT_RS_H -# define LIBFT_RS_H - -#include -#include - -extern struct s_stats { - int count; - double min; - double max; - double avg; - double m; - double stdev; - double var; -} g_rs; - -void rs_clear(); -void rs_push(double n); -void rs_calcmore(); - -#endif diff --git a/nm-otool/libft2/srcs/lst/ft_lst2str.c b/nm-otool/libft2/srcs/lst/ft_lst2str.c deleted file mode 100644 index 4654dc7f..00000000 --- a/nm-otool/libft2/srcs/lst/ft_lst2str.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "libft.h" - -char *ft_lst2str(t_list *list) -{ - size_t size; - t_list *tmp; - char *new; - - size = 0; - tmp = list; - while (tmp) - { - size += ft_strlen((char *)tmp->content) + 1; - tmp = tmp->next; - } - new = ft_memalloc(size); - while (list) - { - ft_strcat(new, (char *)list->content); - if (list->next) - ft_strcat(new, " "); - list = list->next; - } - return (new); -} diff --git a/nm-otool/libft2/srcs/lst/ft_lst_pop.c b/nm-otool/libft2/srcs/lst/ft_lst_pop.c deleted file mode 100644 index 47d8f606..00000000 --- a/nm-otool/libft2/srcs/lst/ft_lst_pop.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "libft.h" - -t_list *ft_lst_pop(t_list **lst) -{ - t_list *top; - - top = *lst; - if (lst && *lst) - *lst = (*lst)->next; - return (top); -} diff --git a/nm-otool/libft2/srcs/printing/hexdump.c b/nm-otool/libft2/srcs/printing/hexdump.c deleted file mode 100644 index 2a51dc6c..00000000 --- a/nm-otool/libft2/srcs/printing/hexdump.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -#include "libft.h" - -void hexdump(void *pAddressIn, long lSize) -{ - char szBuf[100]; - long lIndent = 1; - long lOutLen, lIndex, lIndex2, lOutLen2; - long lRelPos; - struct { char *pData; unsigned long lSize; } buf; - unsigned char *pTmp,ucTmp; - unsigned char *pAddress = (unsigned char *)pAddressIn; - - buf.pData = (char *)pAddress; - buf.lSize = lSize; - - while (buf.lSize > 0) - { - pTmp = (unsigned char *)buf.pData; - lOutLen = (int)buf.lSize; - if (lOutLen > 16) - lOutLen = 16; - - // create a 64-character formatted output line: - sprintf(szBuf, " > " - " " - " %08lX", pTmp-pAddress); - lOutLen2 = lOutLen; - - for(lIndex = 1+lIndent, lIndex2 = 53-15+lIndent, lRelPos = 0; - lOutLen2; - lOutLen2--, lIndex += 2, lIndex2++ - ) - { - ucTmp = *pTmp++; - - sprintf(szBuf + lIndex, "%02x ", (unsigned short)ucTmp); - if(!isprint(ucTmp)) ucTmp = '.'; // nonprintable char - szBuf[lIndex2] = ucTmp; - - if (!(++lRelPos & 3)) // extra blank after 4 bytes - { lIndex++; szBuf[lIndex+2] = ' '; } - } - - if (!(lRelPos & 3)) lIndex--; - - szBuf[lIndex ] = '<'; - szBuf[lIndex+1] = ' '; - - printf("%s\n", szBuf); - - buf.pData += lOutLen; - buf.lSize -= lOutLen; - } -} diff --git a/nm-otool/libft2/srcs/str/ft_strndup.c b/nm-otool/libft2/srcs/str/ft_strndup.c deleted file mode 100644 index ff3ed5be..00000000 --- a/nm-otool/libft2/srcs/str/ft_strndup.c +++ /dev/null @@ -1,12 +0,0 @@ - -#include "libft.h" - -char *ft_strndup(const char *s1, size_t n) -{ - char *dup; - - if (!(dup = ft_memalloc(n))) - return (NULL); - ft_strncpy(dup, s1, n); - return (dup); -} diff --git a/nm-otool/libft2/srcs/str/ft_strsepjoin.c b/nm-otool/libft2/srcs/str/ft_strsepjoin.c deleted file mode 100644 index 8fbb0ee3..00000000 --- a/nm-otool/libft2/srcs/str/ft_strsepjoin.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "libft.h" - -char *ft_strsepjoin(char **tab, char sep) -{ - char *join; - char **p; - int len; - - len = 0; - if (!(p = tab)) - return (NULL); - while (*p) - len += ft_strlen(*p++) + 1; - if (!(join = ft_strnew(len))) - return (NULL); - *join = 0; - p = tab; - while (*p) - { - ft_strcat(join, *p++); - ft_strcat(join, &sep); - } - join[len - 1] = 0; - return (join); -} diff --git a/nm-otool/libft2/srcs/sys/open_new.c b/nm-otool/libft2/srcs/sys/open_new.c deleted file mode 100644 index 49491cce..00000000 --- a/nm-otool/libft2/srcs/sys/open_new.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "libft.h" - -/* -** If file already exists, create xxx(1) instead, etc up to 9 -*/ - -int open_new(char *filename, int oflag) -{ - char *fname; - int fd; - int i; - int len; - - len = ft_strlen(filename); - fname = ft_strnew(len + 4); - ft_strcpy(fname, filename); - i = 0; - while (i < 10 && (fd = open(fname, oflag | O_CREAT | O_EXCL, 0644)) < 0 - && errno == EEXIST) - { - fname[len] = '('; - fname[len + 1] = ++i + '0'; - fname[len + 2] = ')'; - } - ft_strdel(&fname); - return (fd); -}