diff --git a/libftasm/Makefile b/libftasm/Makefile index c4f01753..1401d302 100644 --- a/libftasm/Makefile +++ b/libftasm/Makefile @@ -23,6 +23,7 @@ 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\ @@ -102,6 +103,7 @@ lst/ft_lstnadd.c\ lst/ft_lstnew.c\ lst/ft_lstnew_range.c\ lst/ft_lstsort.c\ +lst/lst_insert_sort.c\ lst/pop.c\ lst/push.c\ lst/top.c\ @@ -137,6 +139,7 @@ printing/ft_putchar.c\ printing/ft_putendl.c\ printing/ft_putnbr.c\ printing/ft_putstr.c\ +printing/hexdump.c\ sstr/ft_sstradd.c\ sstr/ft_sstrcat.c\ sstr/ft_sstrdel.c\ @@ -196,6 +199,13 @@ time/ft_mytime_free.c\ time/ft_mytime_get.c\ time/ft_time_isrecent.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\ SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o)) diff --git a/libftasm/includes/btree.h b/libftasm/includes/btree.h index dd0b2c97..eede027a 100644 --- a/libftasm/includes/btree.h +++ b/libftasm/includes/btree.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */ -/* Updated: 2017/03/14 17:40:20 by jhalford ### ########.fr */ +/* Updated: 2017/05/16 17:31:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/includes/dlst.h b/libftasm/includes/dlst.h index a269909e..79470a87 100644 --- a/libftasm/includes/dlst.h +++ b/libftasm/includes/dlst.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:21:04 by jhalford #+# #+# */ -/* Updated: 2017/03/07 17:25:50 by jhalford ### ########.fr */ +/* Updated: 2017/05/16 17:30:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/includes/error.h b/libftasm/includes/error.h index ce1e812b..64f16559 100644 --- a/libftasm/includes/error.h +++ b/libftasm/includes/error.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */ -/* Updated: 2017/04/02 20:45:00 by jhalford ### ########.fr */ +/* Updated: 2017/05/15 17:37:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/includes/hashtab.h b/libftasm/includes/hashtab.h new file mode 100644 index 00000000..0e84bf70 --- /dev/null +++ b/libftasm/includes/hashtab.h @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hashtab.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/05/15 19:16:49 by ariard #+# #+# */ +/* Updated: 2017/05/16 21:03:50 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); + +#endif diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index d65698f6..27c04598 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -6,13 +6,15 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2017/04/03 16:51:25 by jhalford ### ########.fr */ +/* Updated: 2017/05/16 17:47:18 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef LIBFT_H # define LIBFT_H +# define FT_TRY(a,b) ((a) ? (a) : (b)) + # include # include # include @@ -24,10 +26,12 @@ # include "error.h" # include "color.h" # include "cliopts.h" +# include "rs.h" # include "lst.h" # include "dlst.h" # include "btree.h" +# include "hashtab.h" # include "str.h" # include "sstr.h" @@ -86,6 +90,8 @@ 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 *ft_realloc(void *data, int size); #endif diff --git a/libftasm/includes/lst.h b/libftasm/includes/lst.h index 4b5eb5c0..3f4adb6a 100644 --- a/libftasm/includes/lst.h +++ b/libftasm/includes/lst.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ -/* Updated: 2017/03/28 20:34:27 by jhalford ### ########.fr */ +/* Updated: 2017/05/20 20:01:20 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,4 +85,7 @@ int ft_diff(void *a, void *b); t_list *ft_id(t_list *a); t_list *ft_lst_at(t_list *list, unsigned int nbr); +void lst_insert_sort(t_list **head, + int (cmp)()); + #endif diff --git a/libftasm/includes/math.h b/libftasm/includes/math.h index 2a54ae68..4b87935e 100644 --- a/libftasm/includes/math.h +++ b/libftasm/includes/math.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */ -/* Updated: 2017/03/20 15:42:13 by jhalford ### ########.fr */ +/* Updated: 2017/05/16 17:30:35 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/includes/rs.h b/libftasm/includes/rs.h new file mode 100644 index 00000000..c5b716e4 --- /dev/null +++ b/libftasm/includes/rs.h @@ -0,0 +1,21 @@ +#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/libftasm/includes/sys.h b/libftasm/includes/sys.h index 326e37b3..5ec44d42 100644 --- a/libftasm/includes/sys.h +++ b/libftasm/includes/sys.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */ -/* Updated: 2017/03/25 15:12:52 by jhalford ### ########.fr */ +/* Updated: 2017/05/16 17:30:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/btree/btree_print.c b/libftasm/srcs/btree/btree_print.c index bc1961dc..10b46735 100644 --- a/libftasm/srcs/btree/btree_print.c +++ b/libftasm/srcs/btree/btree_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */ -/* Updated: 2017/03/20 21:06:28 by jhalford ### ########.fr */ +/* Updated: 2017/05/15 19:08:35 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/htb/ft_hash_string.c b/libftasm/srcs/htb/ft_hash_string.c new file mode 100644 index 00000000..55640299 --- /dev/null +++ b/libftasm/srcs/htb/ft_hash_string.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hash.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/02 16:35:24 by ariard #+# #+# */ +/* Updated: 2017/05/16 17:33:47 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "hashtab.h" + +int ft_hash_string(const void *key, int size) +{ + const char *ptr; + unsigned int tmp; + unsigned int val; + + val = 0; + ptr = key; + while (*ptr != '\0') + { + val = (val << 4) + (*ptr); + if ((tmp = (val & 0xf0000000))) + { + val = val ^ (tmp >> 24); + val = val ^ tmp; + } + ptr++; + } + return (val % size); +} diff --git a/libftasm/srcs/htb/hashtab_destroy.c b/libftasm/srcs/htb/hashtab_destroy.c new file mode 100644 index 00000000..0ab4bfc2 --- /dev/null +++ b/libftasm/srcs/htb/hashtab_destroy.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hashtab_destroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/05/15 21:35:07 by ariard #+# #+# */ +/* Updated: 2017/05/16 20:42:05 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "hashtab.h" + +void hashtab_destroy(t_hashtab *htb, void (*destroy)()) +{ + int bucket; + + bucket = -1; + while (++bucket < htb->capacity) + ft_lstdel(&htb->head[bucket], destroy); +} diff --git a/libftasm/srcs/htb/hashtab_init.c b/libftasm/srcs/htb/hashtab_init.c new file mode 100644 index 00000000..1f6b6db7 --- /dev/null +++ b/libftasm/srcs/htb/hashtab_init.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hashtab_init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/05/15 19:13:06 by ariard #+# #+# */ +/* Updated: 2017/05/16 18:46:03 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "hashtab.h" + +void hashtab_init(t_hashtab *htb, int capacity, + int (*hashfunc)(const void *key, int capacity)) +{ + htb->head = (t_list **)ft_memalloc(capacity * sizeof(*htb->head)); + htb->capacity = capacity; + htb->size = 0; + htb->hashfunc = hashfunc; +} diff --git a/libftasm/srcs/htb/hashtab_insert.c b/libftasm/srcs/htb/hashtab_insert.c new file mode 100644 index 00000000..45d6e1a4 --- /dev/null +++ b/libftasm/srcs/htb/hashtab_insert.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hashtab_insert.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/05/15 19:30:39 by ariard #+# #+# */ +/* Updated: 2017/05/16 21:05:19 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "hashtab.h" + +int hashtab_insert(t_hashtab *htb, t_list *new, void *key, + int (*match)(const void *data_ref, const void *key)) +{ + int bucket; + + if (hashtab_lookup(htb, key, match)) + return (-1); + bucket = htb->hashfunc(key, htb->capacity); + ft_lsteadd(&htb->head[bucket], new); + htb->size++; + return (bucket); +} diff --git a/libftasm/srcs/htb/hashtab_lookup.c b/libftasm/srcs/htb/hashtab_lookup.c new file mode 100644 index 00000000..99b6eb5f --- /dev/null +++ b/libftasm/srcs/htb/hashtab_lookup.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hashtab_lookup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/05/15 19:38:41 by ariard #+# #+# */ +/* Updated: 2017/05/16 21:34:20 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *hashtab_lookup(t_hashtab *htb, void *key, + int (*match)(const void *data_ref, const void *key)) + +{ + int bucket; + + if ((bucket = htb->hashfunc(key, htb->capacity))) + return (ft_lst_find(htb->head[bucket], key, match)); + return (NULL); +} diff --git a/libftasm/srcs/htb/hashtab_print.c b/libftasm/srcs/htb/hashtab_print.c new file mode 100644 index 00000000..c6d5498b --- /dev/null +++ b/libftasm/srcs/htb/hashtab_print.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hashtab_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/05/16 20:38:14 by ariard #+# #+# */ +/* Updated: 2017/05/16 21:03:23 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void hashtab_print(t_hashtab *htb, int (*printer)()) +{ + int bucket; + + bucket = -1; + while (++bucket != htb->capacity) + ft_lstiter(htb->head[bucket], printer, NULL); +} diff --git a/libftasm/srcs/htb/hashtab_remove.c b/libftasm/srcs/htb/hashtab_remove.c new file mode 100644 index 00000000..d21679b7 --- /dev/null +++ b/libftasm/srcs/htb/hashtab_remove.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hashtab_remove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/05/15 19:46:48 by ariard #+# #+# */ +/* Updated: 2017/05/16 17:34:56 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *hashtab_remove(t_hashtab *htb, void *key, + int (*match)(const void *data_ref, const void *key)) +{ + t_list *data; + + if ((data = hashtab_lookup(htb, key, match))) + return(ft_lst_removeif(&data, key, match)); + return (NULL); +} diff --git a/libftasm/srcs/lst/ft_lst_bfree.c b/libftasm/srcs/lst/ft_lst_bfree.c index 67a308ae..82c6dec4 100644 --- a/libftasm/srcs/lst/ft_lst_bfree.c +++ b/libftasm/srcs/lst/ft_lst_bfree.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 16:55:04 by jhalford #+# #+# */ -/* Updated: 2016/12/07 18:07:31 by jhalford ### ########.fr */ +/* Updated: 2017/05/15 21:35:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/lst/ft_lst_cfree.c b/libftasm/srcs/lst/ft_lst_cfree.c index e9b8b1dc..d70068ac 100644 --- a/libftasm/srcs/lst/ft_lst_cfree.c +++ b/libftasm/srcs/lst/ft_lst_cfree.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:10 by jhalford #+# #+# */ -/* Updated: 2016/12/07 16:55:43 by jhalford ### ########.fr */ +/* Updated: 2017/05/15 21:36:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/lst/ft_lst_filter.c b/libftasm/srcs/lst/ft_lst_filter.c index f0004126..cc528142 100644 --- a/libftasm/srcs/lst/ft_lst_filter.c +++ b/libftasm/srcs/lst/ft_lst_filter.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */ -/* Updated: 2017/03/02 17:47:26 by jhalford ### ########.fr */ +/* Updated: 2017/05/16 17:34:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/lst/ft_lst_find.c b/libftasm/srcs/lst/ft_lst_find.c index 3163d3af..420c8725 100644 --- a/libftasm/srcs/lst/ft_lst_find.c +++ b/libftasm/srcs/lst/ft_lst_find.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:20 by jhalford #+# #+# */ -/* Updated: 2017/01/10 11:07:37 by jhalford ### ########.fr */ +/* Updated: 2017/05/16 21:27:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/lst/ft_lst_print.c b/libftasm/srcs/lst/ft_lst_print.c index 94e5f315..18493eb3 100644 --- a/libftasm/srcs/lst/ft_lst_print.c +++ b/libftasm/srcs/lst/ft_lst_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:27 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:28 by jhalford ### ########.fr */ +/* Updated: 2017/05/16 21:00:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/lst/ft_lst_print2.c b/libftasm/srcs/lst/ft_lst_print2.c index 875167d1..2016c78c 100644 --- a/libftasm/srcs/lst/ft_lst_print2.c +++ b/libftasm/srcs/lst/ft_lst_print2.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:29 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:29 by jhalford ### ########.fr */ +/* Updated: 2017/05/16 21:00:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/lst/ft_lst_removeif.c b/libftasm/srcs/lst/ft_lst_removeif.c index b82f57c2..5abf3726 100644 --- a/libftasm/srcs/lst/ft_lst_removeif.c +++ b/libftasm/srcs/lst/ft_lst_removeif.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */ -/* Updated: 2017/03/13 15:31:13 by jhalford ### ########.fr */ +/* Updated: 2017/05/15 19:49:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/lst/ft_lstadd.c b/libftasm/srcs/lst/ft_lstadd.c index 1d465dd1..94d32d0d 100644 --- a/libftasm/srcs/lst/ft_lstadd.c +++ b/libftasm/srcs/lst/ft_lstadd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:13 by jhalford #+# #+# */ -/* Updated: 2017/03/08 00:19:43 by ariard ### ########.fr */ +/* Updated: 2017/05/15 19:31:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/lst/ft_lstiter.c b/libftasm/srcs/lst/ft_lstiter.c index 49a96476..40ebc9c3 100644 --- a/libftasm/srcs/lst/ft_lstiter.c +++ b/libftasm/srcs/lst/ft_lstiter.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */ -/* Updated: 2017/03/28 11:27:45 by jhalford ### ########.fr */ +/* Updated: 2017/05/16 17:18:12 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/srcs/lst/lst_insert_sort.c b/libftasm/srcs/lst/lst_insert_sort.c new file mode 100644 index 00000000..d1a62412 --- /dev/null +++ b/libftasm/srcs/lst/lst_insert_sort.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lst_insert_sort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/05/20 19:59:41 by ariard #+# #+# */ +/* Updated: 2017/05/20 20:05:32 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void lst_insert_sort(t_list **head, + int (cmp)()) +{ + t_list *new; + t_list *ptr; + + new = NULL; + while (*head) + { + ptr = *head; + *head = (*head)->next; + ft_lst_sorted_insert(&new, ptr, cmp); + } + *head = new; +} diff --git a/libftasm/srcs/printing/hexdump.c b/libftasm/srcs/printing/hexdump.c new file mode 100644 index 00000000..924e2004 --- /dev/null +++ b/libftasm/srcs/printing/hexdump.c @@ -0,0 +1,57 @@ +#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/libftasm/srcs/rs/rs.c b/libftasm/srcs/rs/rs.c new file mode 100644 index 00000000..3f738785 --- /dev/null +++ b/libftasm/srcs/rs/rs.c @@ -0,0 +1,56 @@ +#include "libft.h" +#include + +struct s_stats g_rs = {0, 0, 0, 0, 0, 0, 0}; + +void rs_clear() +{ + 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 *libm; + double (*sqrt)(double); + + 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); + if ((libm = dlopen("libm.dylib", 0)) == NULL) + printf("%s\n", dlerror()); + else if ((sqrt = dlsym(libm, "sqrt")) == NULL) + printf("%s\n", dlerror()); + else + g_rs.stdev = sqrt(g_rs.var); +} diff --git a/libftasm/srcs/sys/open_new.c b/libftasm/srcs/sys/open_new.c index 0dc5529e..49491cce 100644 --- a/libftasm/srcs/sys/open_new.c +++ b/libftasm/srcs/sys/open_new.c @@ -1,5 +1,9 @@ #include "libft.h" +/* +** If file already exists, create xxx(1) instead, etc up to 9 +*/ + int open_new(char *filename, int oflag) { char *fname;