From 602ebf070d0c857022e4704ab1139da70908061e Mon Sep 17 00:00:00 2001 From: pia Lepetit Date: Mon, 3 Jun 2019 08:16:18 +0200 Subject: [PATCH] ajout de l'effacement selectif lors de l'opti, pas ouf ouf --- .gitignore | 4 - Makefile | 29 ++-- f_bonus_opti.c | 24 ++-- f_bonus_print.c | 6 +- f_parse_input.c | 1 + f_search_map.c | 34 ++++- fillit.dSYM/Contents/Info.plist | 20 +++ fillit.h | 25 ++-- libft/Makefile | 223 +++++++++++++++++++++++++++++++ libft/includes/libft.h | 101 ++++++++++++++ libft/libft.a | Bin 0 -> 63720 bytes libft/src/is/ft_isalnum.c | 18 +++ libft/src/is/ft_isalpha.c | 18 +++ libft/src/is/ft_isascii.c | 18 +++ libft/src/is/ft_isdigit.c | 18 +++ libft/src/is/ft_isprint.c | 18 +++ libft/src/is/ft_issort.c | 26 ++++ libft/src/lst/ft_lstadd.c | 19 +++ libft/src/lst/ft_lstdel.c | 20 +++ libft/src/lst/ft_lstdelone.c | 20 +++ libft/src/lst/ft_lstiter.c | 22 +++ libft/src/lst/ft_lstmap.c | 35 +++++ libft/src/lst/ft_lstnew.c | 35 +++++ libft/src/mem/ft_memalloc.c | 27 ++++ libft/src/mem/ft_memccpy.c | 36 +++++ libft/src/mem/ft_memchr.c | 30 +++++ libft/src/mem/ft_memcmp.c | 32 +++++ libft/src/mem/ft_memcpy.c | 31 +++++ libft/src/mem/ft_memdel.c | 26 ++++ libft/src/mem/ft_memmove.c | 35 +++++ libft/src/mem/ft_memset.c | 29 ++++ libft/src/put/ft_putchar.c | 18 +++ libft/src/put/ft_putchar_fd.c | 18 +++ libft/src/put/ft_putendl.c | 19 +++ libft/src/put/ft_putendl_fd.c | 19 +++ libft/src/put/ft_putnbr.c | 18 +++ libft/src/put/ft_putnbr_fd.c | 28 ++++ libft/src/put/ft_putnbrbase.c | 59 ++++++++ libft/src/put/ft_putnbrendl.c | 18 +++ libft/src/put/ft_putnbrendl_fd.c | 29 ++++ libft/src/put/ft_putstr.c | 22 +++ libft/src/put/ft_putstr_fd.c | 19 +++ libft/src/str/ft_strcat.c | 32 +++++ libft/src/str/ft_strchr.c | 33 +++++ libft/src/str/ft_strclr.c | 23 ++++ libft/src/str/ft_strcmp.c | 28 ++++ libft/src/str/ft_strcpy.c | 28 ++++ libft/src/str/ft_strdel.c | 26 ++++ libft/src/str/ft_strdup.c | 32 +++++ libft/src/str/ft_strequ.c | 24 ++++ libft/src/str/ft_striter.c | 23 ++++ libft/src/str/ft_striteri.c | 26 ++++ libft/src/str/ft_strjoin.c | 54 ++++++++ libft/src/str/ft_strjoinfree.c | 28 ++++ libft/src/str/ft_strlcat.c | 38 ++++++ libft/src/str/ft_strlen.c | 27 ++++ libft/src/str/ft_strmap.c | 32 +++++ libft/src/str/ft_strmapi.c | 33 +++++ libft/src/str/ft_strmultisplit.c | 83 ++++++++++++ libft/src/str/ft_strncat.c | 32 +++++ libft/src/str/ft_strncmp.c | 32 +++++ libft/src/str/ft_strncpy.c | 30 +++++ libft/src/str/ft_strnequ.c | 25 ++++ libft/src/str/ft_strnew.c | 27 ++++ libft/src/str/ft_strnstr.c | 42 ++++++ libft/src/str/ft_strrchr.c | 32 +++++ libft/src/str/ft_strsplit.c | 62 +++++++++ libft/src/str/ft_strstr.c | 42 ++++++ libft/src/str/ft_strsub.c | 32 +++++ libft/src/str/ft_strtrim.c | 35 +++++ libft/src/tab/ft_any.c | 26 ++++ libft/src/tab/ft_arraymap.c | 28 ++++ libft/src/tab/ft_foreach.c | 22 +++ libft/src/trsf/ft_atoi.c | 39 ++++++ libft/src/trsf/ft_atoibase.c | 75 +++++++++++ libft/src/trsf/ft_bzero.c | 27 ++++ libft/src/trsf/ft_convertbase.c | 86 ++++++++++++ libft/src/trsf/ft_itoa.c | 35 +++++ libft/src/trsf/ft_tolower.c | 20 +++ libft/src/trsf/ft_toupper.c | 20 +++ samples/debug/jdugoudrdiff | 74 ++++++++++ 81 files changed, 2615 insertions(+), 45 deletions(-) create mode 100644 fillit.dSYM/Contents/Info.plist create mode 100644 libft/Makefile create mode 100644 libft/includes/libft.h create mode 100644 libft/libft.a create mode 100644 libft/src/is/ft_isalnum.c create mode 100644 libft/src/is/ft_isalpha.c create mode 100644 libft/src/is/ft_isascii.c create mode 100644 libft/src/is/ft_isdigit.c create mode 100644 libft/src/is/ft_isprint.c create mode 100644 libft/src/is/ft_issort.c create mode 100644 libft/src/lst/ft_lstadd.c create mode 100644 libft/src/lst/ft_lstdel.c create mode 100644 libft/src/lst/ft_lstdelone.c create mode 100644 libft/src/lst/ft_lstiter.c create mode 100644 libft/src/lst/ft_lstmap.c create mode 100644 libft/src/lst/ft_lstnew.c create mode 100644 libft/src/mem/ft_memalloc.c create mode 100644 libft/src/mem/ft_memccpy.c create mode 100644 libft/src/mem/ft_memchr.c create mode 100644 libft/src/mem/ft_memcmp.c create mode 100644 libft/src/mem/ft_memcpy.c create mode 100644 libft/src/mem/ft_memdel.c create mode 100644 libft/src/mem/ft_memmove.c create mode 100644 libft/src/mem/ft_memset.c create mode 100644 libft/src/put/ft_putchar.c create mode 100644 libft/src/put/ft_putchar_fd.c create mode 100644 libft/src/put/ft_putendl.c create mode 100644 libft/src/put/ft_putendl_fd.c create mode 100644 libft/src/put/ft_putnbr.c create mode 100644 libft/src/put/ft_putnbr_fd.c create mode 100644 libft/src/put/ft_putnbrbase.c create mode 100644 libft/src/put/ft_putnbrendl.c create mode 100644 libft/src/put/ft_putnbrendl_fd.c create mode 100644 libft/src/put/ft_putstr.c create mode 100644 libft/src/put/ft_putstr_fd.c create mode 100644 libft/src/str/ft_strcat.c create mode 100644 libft/src/str/ft_strchr.c create mode 100644 libft/src/str/ft_strclr.c create mode 100644 libft/src/str/ft_strcmp.c create mode 100644 libft/src/str/ft_strcpy.c create mode 100644 libft/src/str/ft_strdel.c create mode 100644 libft/src/str/ft_strdup.c create mode 100644 libft/src/str/ft_strequ.c create mode 100644 libft/src/str/ft_striter.c create mode 100644 libft/src/str/ft_striteri.c create mode 100644 libft/src/str/ft_strjoin.c create mode 100644 libft/src/str/ft_strjoinfree.c create mode 100644 libft/src/str/ft_strlcat.c create mode 100644 libft/src/str/ft_strlen.c create mode 100644 libft/src/str/ft_strmap.c create mode 100644 libft/src/str/ft_strmapi.c create mode 100644 libft/src/str/ft_strmultisplit.c create mode 100644 libft/src/str/ft_strncat.c create mode 100644 libft/src/str/ft_strncmp.c create mode 100644 libft/src/str/ft_strncpy.c create mode 100644 libft/src/str/ft_strnequ.c create mode 100644 libft/src/str/ft_strnew.c create mode 100644 libft/src/str/ft_strnstr.c create mode 100644 libft/src/str/ft_strrchr.c create mode 100644 libft/src/str/ft_strsplit.c create mode 100644 libft/src/str/ft_strstr.c create mode 100644 libft/src/str/ft_strsub.c create mode 100644 libft/src/str/ft_strtrim.c create mode 100644 libft/src/tab/ft_any.c create mode 100644 libft/src/tab/ft_arraymap.c create mode 100644 libft/src/tab/ft_foreach.c create mode 100644 libft/src/trsf/ft_atoi.c create mode 100644 libft/src/trsf/ft_atoibase.c create mode 100644 libft/src/trsf/ft_bzero.c create mode 100644 libft/src/trsf/ft_convertbase.c create mode 100644 libft/src/trsf/ft_itoa.c create mode 100644 libft/src/trsf/ft_tolower.c create mode 100644 libft/src/trsf/ft_toupper.c create mode 100644 samples/debug/jdugoudrdiff diff --git a/.gitignore b/.gitignore index 00f9052..03fa952 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,4 @@ a\.out fillit -test_fillit\.c - -libft - \.DS_Store diff --git a/Makefile b/Makefile index 66bc864..e760aa6 100644 --- a/Makefile +++ b/Makefile @@ -23,17 +23,13 @@ CFLAGS += -Wall -Wextra -Werror LDFLAGS = -L./libft/ LDLIBS = -lft -SRCS = main.c \ - f_bonus_opti.c \ - f_bonus_print.c \ - f_handle_errors.c \ - f_parse_input.c \ - f_print.c \ - f_print_map_with_colors.c \ - f_read_file.c \ - f_search_map.c +SRCS = $(shell find . -depth 1 -type f -not -name '.*' -not -name 'test*' -name '*.c') -OBJS = $(SRCS:.c=.o) +TRASH = $(shell find . -depth 1 -name '*.dSYM') +TRASH += $(shell find . -depth 1 -type f -name '*.o') +TRASH += $(shell find . -depth 1 -type f -name '*.swp') +TRASH += $(shell find . -depth 1 -type f -name '*.swo') +TRASH += $(shell find . -depth 1 -type f -name '*.swn') # - - - - - - - - - - - - - - - # # RULES # @@ -41,16 +37,19 @@ OBJS = $(SRCS:.c=.o) all: $(NAME) -$(NAME): $(OBJS) - make -C ./libft/ +$(NAME): $(SRCS) $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME) +debug: $(SRCS) + $(CC) -g $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME) + +lib: + make -C ./libft/ + clean: - make clean -C libft/ - /bin/rm -rf $(OBJS) + /bin/rm -rf $(TRASH) fclean: clean - make fclean -C libft/ /bin/rm -rf $(NAME) re: fclean all diff --git a/f_bonus_opti.c b/f_bonus_opti.c index 66520d7..1279d4e 100644 --- a/f_bonus_opti.c +++ b/f_bonus_opti.c @@ -23,12 +23,14 @@ int check_tetri_memory(t_fillist *list, int pos) tetri = list; mask = 1 << ((pos % 32) - 1); + if (!tetri->same && !tetri->memory) + return(1); if (tetri->same) { if (!(tetri->same->memory[pos / 32] & mask)) return (tetri->same->memory[pos / 32] |= mask); } - else + else if (tetri->memory) { if (!(tetri->memory[pos / 32] & mask)) return (tetri->memory[pos / 32] |= mask); @@ -42,6 +44,8 @@ int check_tetri_memory(t_fillist *list, int pos) int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b) { + if (tetri_a->same) + return (0); if (tetri_a->tetribit != tetri_b->tetribit) return (0); if (tetri_a->width != tetri_b->width) @@ -79,20 +83,22 @@ int check_same_tetri(t_fillist *list, int num) curr_tetri = clean_list_memory(list, list); while (curr_tetri != NULL) { - i = 0; - if (!(curr_tetri->memory = - (unsigned int *)malloc(sizeof(*curr_tetri->memory) * num))) - return (0); - while (i < num) - curr_tetri->memory[i++] = 0; next_tetri = curr_tetri->next; while (next_tetri != NULL) { if (compare_tetri(curr_tetri, next_tetri)) - if (next_tetri->same == NULL) - next_tetri->same = curr_tetri; + { + i = 0; + if (!(curr_tetri->memory = + (unsigned int *)malloc(sizeof(*curr_tetri->memory) * num))) + return (0); + while (i < num) + curr_tetri->memory[i++] = 0; + next_tetri->same = curr_tetri; + } next_tetri = next_tetri->next; } + curr_tetri->position = 0; curr_tetri->total_num = num; curr_tetri = curr_tetri->next; } diff --git a/f_bonus_print.c b/f_bonus_print.c index efc4223..ccb310c 100644 --- a/f_bonus_print.c +++ b/f_bonus_print.c @@ -24,20 +24,20 @@ t_fillist *print_tetri(t_fillist *list) tmp = list; if (list->dope[2]) { + check_same_tetri(list, 1); while (tmp) { - check_same_tetri(list, 1); print = tmp->tetribit; print <<= 16; print_sized_map(&print, tmp->width, tmp->height, tmp->letter); if (tmp->same && list->dope[1]) { - print = tmp->same->tetribit; - print <<= 16; ft_putstr("same --> "); ft_put_tetri_color(tmp->same->letter); ft_putchar('\n'); } + if (list->dope[1] && tmp->memory) + ft_putendl("have a copy"); ft_putchar('\n'); tmp = tmp->next; } diff --git a/f_parse_input.c b/f_parse_input.c index 5b90a63..fc13b1b 100644 --- a/f_parse_input.c +++ b/f_parse_input.c @@ -121,6 +121,7 @@ int add_to_list(char *line, t_fillist **lst, char letter, int *dope) tmp->letter = letter; tmp->dope = dope; tmp->start = *lst; + tmp->memory = NULL; return (1); } diff --git a/f_search_map.c b/f_search_map.c index 2904444..140fcea 100644 --- a/f_search_map.c +++ b/f_search_map.c @@ -52,7 +52,7 @@ unsigned int fit_in_place(unsigned int *map, t_fillist *lst, int sze, int i) int find_place(unsigned int *map, t_fillist *list, int size) { int limit; - int pos; + int pos; pos = list->position; list->place = pos % size; @@ -103,17 +103,44 @@ void add_remove(unsigned int *map, t_fillist *list, int size) } } +void clean_memory(t_fillist *list, int pos, int mem) +{ + t_fillist *tmp; + unsigned int mask; + + tmp = list->start; + while (tmp) + { + if (tmp->memory) + { + pos = mem; + while (pos >= list->position) + { + mask = ~(1 << ((pos % 32) - 1)); + tmp->memory[pos / 32] &= mask; + pos--; + } + } + tmp = tmp->next; + } +} + /* ** Function that recursively try to fill the map with the tetris */ int fill_map(unsigned int *map, t_fillist *list, int size) { + int pos; + if (!list) return (1); + pos = list->position; list->position = 0; while (find_place(map, list, size)) { +// if (list->position < pos) +// clean_memory(list, pos, pos); add_remove(map, list, size); list->test = 1; if (list->dope[0]) @@ -149,7 +176,8 @@ int search_map(t_fillist *list) size = 2; tmp = print_tetri(list); - init_num_and_size(1, &size, tmp); +// init_num_and_size(1, &size, tmp); + size = 10; i = 0; while (!i) { @@ -157,6 +185,8 @@ int search_map(t_fillist *list) if (!(map = (unsigned int *)malloc(sizeof(*map) * num))) return (0); check_same_tetri(list, num); + if (list->dope[2]) + ft_putnbrendl(size); while (num--) map[num] = 0; i = fill_map(map, list, size++); diff --git a/fillit.dSYM/Contents/Info.plist b/fillit.dSYM/Contents/Info.plist new file mode 100644 index 0000000..96bfe2d --- /dev/null +++ b/fillit.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.fillit + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/fillit.h b/fillit.h index 1f61ed3..e293f40 100644 --- a/fillit.h +++ b/fillit.h @@ -37,19 +37,20 @@ /* ** STRUCTURE ** tetribit : tetri ecrit en binaire dans un short de 16 bits -** width : largeur du tetri -** height : hauteur du tetri +** width : largeur du tetri +** height : hauteur du tetri ** position : memorise la position d tetri bit a bit -** place : position sur l'axe des abscisses de la map (position % size) -** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32) -** num : memorise dans quel int du tableau on se trouve (position / 32) -** test : -** letter : letter of the tetrimino for printing final map -** dope : flags for details, optimisation, printing and error -** memory : positions already tested by a tetrimino in bitwise -** same : pointer to previous identical tetrimino -** next : pointer to next tetrimino -** start : pointer to first tetrimino of input file +** place : position sur l'axe des abscisses de la map (position % size) +** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32) +** num : memorise dans quel int du tableau on se trouve (position / 32) +** total_num: memorise le nombre d'int dans le tableau +** test : +** letter : letter of the tetrimino for printing final map +** dope : flags for details, optimisation, printing and error +** memory : positions already tested by a tetrimino in bitwise +** same : pointer to previous identical tetrimino +** next : pointer to next tetrimino +** start : pointer to first tetrimino of input file */ typedef struct s_fillist { diff --git a/libft/Makefile b/libft/Makefile new file mode 100644 index 0000000..2a5736b --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,223 @@ +## +# # ------------------------------------------------------ +# # utiliser le makefile pour creer une librairie statique +# # ------------------------------------------------------ +## +## +## - - - - - - - - +## compiler des .o +## - - - - - - - - +## +## +## quand on ecrit un programme il contient un main et les +## fonctions dont le main a besoin (ex ft_putchar) : +## +### #include +### +### void ft_putchar(char c) +### { +### write(1, &c, 1); +### } +### +### int main() +### { +### ft_putchar('0'); +### return (0); +### } +## +## on peut compiler ce fichier avec gcc en faisant : +## gcc file.c +## et ca sort un executable a.out +## si on l'execute "./a.out" ca ecrit 0 dans la console +## +## mais pour ne pas reecrire a chaque fois ft_putchar +## on peut la mettre dans une librairie qu'on inclue dans +## le fichier qui l'utilise... +## si on sort ft_putchar du fichier : +## +### int main() +### { +### ft_putchar('0'); +### return (0); +### } +## +## et qu'on l'execute "gcc file.c" on va avoir une erreur +## car file.c utilise ft_putchar mais gcc ne sait pas ce +## que c'est, donc il faut qu'on le rajoute a la compilation +## on peut par exemple l'ecrire dans un fichier ft_putchar.c +## +### #include +### +### void ft_putchar(char c) +### { +### write(1, &c, 1); +### } +## +## et compiler les deux : +## gcc file.c ft_putchar.c +## +## ca fonctionne mais gcc doit a chaque fois recompiler +## ft_putchar.c alors qu'il n'est pas modifie, donc on peut +## le compiler une bonne fois pour toute et le rajouter a la +## compilation finale quand on en a besoin sans que l'ordi +## ait a tout retraduire dans son langage +## +## mais si on essaye de compiler ft_putchar seul +## gcc ft_putchar.c +## ca nous donne une erreur car pour compiler, gcc a besoin +## de trouver un main ! +## +## on va donc utiliser l'option -c pour +## creer une fichier objet .o qui est deja traduit en langue +## d'ordinateur et pret a etre rajoute a la compilation : +## gcc -c ft_putchar.c --> donne ft_putchar.o +## qu'on peut compiler avec le fichier qui contient le main : +## +## gcc file.c ft_putchar.o +## +## on a nos bouts de codes comme ft_putchar.o dans des fichiers +## objets prets a etre ajoutes a la compilation du main +## +## on va maintenant voir comment faire une libraire qui contien +## tous nos fichiers objets +## +## +## - - - - - - - - +## creer une lib.a +## - - - - - - - - +## +## +## pour mettre tous les fichiers .o dans un seul fichier .a +## on utilise un programme d'archive ar avec les options rc +## r indique d'inserer les .o en remplacant si necessaire +## c de creer une nouvelle archive +## le nom de l'archive doit commencer par lib et finir en .a : +## ar rc nom_de_l'archive fichier_1.o fichier_2.o etc +## +## ar rc libtest.a ft_putchar.o +## +## on obtient un fichier libtest.a qui contient les fichiers +## objets .o +## +## on peut l'utiliser a la compilation de cette manniere : +## +## gcc file.c -L. -ltest +## +## -L indique ou est la librairie (ici elle est dans le +## dossier courant .) +## -l indique son nom ("test" car on n'indique pas lib et .a) +## +## +# # ----------------------------------------------- +# # ecrire un make file pour aider a la compilation +# # ----------------------------------------------- +## +## +## exemple d'un makefilede basic +## +### NAME = libtest.h +### CC = gcc +### CFLAGS = -I. -c +### SRCS = example01.c \ +### example02.c +### OBJ = $(SRCS:.c=.o) |ecrit les fichiers .c en .o +### +### all: $(NAME) |make execute sa premiere regle NAME +### $(NAME): $(OBJ) |NAME execute d'abord OBJ +### ar -rc $@ $< | +## +## Make a des built-in pattern rules : +## https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html +## par exemple pour construire des .o a partir de .c +## qui sont utilisees par défaut si les variables +## sont bien nomee (genre CC ou CFLAGS) +## +## cependant si on veut mettre les fichiers .o dans un +## sous-fichier BUILDS il n'y a pas de built-in pattern +## il faut donc l'ecrire nous-meme : +## +### NAME = libtest.h +### CC = gcc +### CFLAGS = -I. +### SRCS = example01.c \ +### example02.c +### ODIR = ./builds +### OBJS = $(addprefix $(ODIR)/, $(SRCS:.c=.o)) +### +### all: $(NAME) +### $(NAME): $(OBJS) +### ar -rc $@ $< +### +### $(ODIR)/%.o : %.c +### $(COMPILE.c) -o $@ $< +## +## cette regle est appellee par $(OBJS) puisque +## cette variable appelle la regle $(ODIR/file.o) +## +## COMPILE est une built-in variable qui execute +## les regles CC et CFLAGS avec l'option -c +## +## % = "tout" +## $@ = "la valeur a gauche de :" +## $< = "la premiere valeur a droite de :" +## $^ = "toutes les valeurs a droite de :" +## +## + + +# ----------------------------------------------------------- # +# # +# variables modifiables # +# # +# ----------------------------------------------------------- # + +NAME = libft.a + +DEPS = libft.h + +SDIR = ./src +ODIR = ./build +IDIR = ./includes + +CC = gcc +CFLAGS = -Wall -Wextra -Werror -I$(IDIR) + + +# ----------------------------------------------------------- # +# # +# ne pas modifier en dessous # +# # +# ----------------------------------------------------------- # + +## SUB_SDIR sera utilise pour creer les sous dossiers : +## avec mkdir -p ODIR/subdir1 ODIR/subdir2 ODIR/subdir3 etc... +## find $(SDIR) cherche recursivement tous le contenu de SDIR +## -type d ne trouve que les dossiers, pas les fichiers +## -mindepth 1 ne liste pas le dossier SDIR +## subst transform arg1 en arg2 dans arg3 + +SUB_SDIR = $(shell find $(SDIR) -mindepth 1 -type d) +SRC = $(shell find $(SDIR) -type f -not -name '.*' -name '*.c') +OBJ = $(subst $(SDIR), $(ODIR), $(SRC:.c=.o)) + +all: $(ODIR) $(NAME) + +$(ODIR): + mkdir -p $(subst $(SDIR), $(ODIR), $(SUB_SDIR)) + +$(ODIR)/%.o: $(SDIR)/%.c + $(COMPILE.c) -o $@ $< + +$(NAME): $(OBJ) + ar -rc $@ $^ + @ranlib $@ + +clean: + /bin/rm -rf $(ODIR) + +fclean: clean + /bin/rm -f $(NAME) + +re: fclean all + +.PHONY: clean diff --git a/libft/includes/libft.h b/libft/includes/libft.h new file mode 100644 index 0000000..89918a8 --- /dev/null +++ b/libft/includes/libft.h @@ -0,0 +1,101 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:22:07 by hulamy #+# #+# */ +/* Updated: 2019/04/07 14:22:04 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H +# include +# include +# include + +int ft_atoi(const char *str); +void ft_bzero(void *s, size_t n); +int ft_isalnum(int c); +int ft_isalpha(int c); +int ft_isascii(int c); +int ft_isdigit(int c); +int ft_isprint(int c); +void *ft_memccpy(void *dst, const void *restrict src, + int c, size_t n); +void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +void *ft_memcpy(void *dst, const void *src, size_t n); +void *ft_memmove(void *dst, const void *src, size_t len); +void *ft_memset(void *b, int c, size_t len); +char *ft_strcat(char *s1, const char *s2); +char *ft_strchr(const char *s, int c); +int ft_strcmp(const char *s1, const char *s2); +char *ft_strcpy(char *dst, const char *src); +char *ft_strdup(const char *s1); +size_t ft_strlcat(char *dst, const char *src, size_t size); +size_t ft_strlen(const char *str); +char *ft_strncat(char *s1, const char *s2, size_t n); +int ft_strncmp(const char *s1, const char *s2, size_t n); +char *ft_strncpy(char *dst, const char *src, size_t len); +char *ft_strnstr(const char *big, const char *little, + size_t len); +char *ft_strrchr(const char *s, int c); +char *ft_strstr(const char *big, const char *little); +int ft_tolower(int c); +int ft_toupper(int c); + +char *ft_itoa(int n); +void *ft_memalloc(size_t size); +void ft_memdel(void **ap); +void ft_putchar(char c); +void ft_putchar_fd(char c, int fd); +void ft_putendl(char const *str); +void ft_putendl_fd(char const *s, int fd); +void ft_putnbr(int nbr); +void ft_putnbr_fd(int n, int fd); +void ft_putstr(char const *str); +void ft_putstr_fd(char const *s, int fd); +void ft_strclr(char *s); +void ft_strdel(char **as); +int ft_strequ(char const *s1, char const *s2); +void ft_striter(char *s, void (*f)(char *)); +void ft_striteri(char *s, void (*f)(unsigned int, char *)); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strjoinfree(char *s1, char *s2); +char *ft_strmap(char const *s, char (*f)(char)); +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); +int ft_strnequ(char const *s1, char const *s2, size_t n); +char *ft_strnew(size_t size); +char **ft_strsplit(char const *s, char c); +char *ft_strsub(char const *s, unsigned int start, size_t len); +char *ft_strtrim(char const *s); + +typedef struct s_list +{ + void *content; + size_t content_size; + struct s_list *next; +} t_list; + +t_list *ft_lstnew(const void *content, size_t content_size); +void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)); +void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); +void ft_lstadd(t_list **alst, t_list *n); +void ft_lstiter(t_list *lst, void (*f)(t_list *elem)); +t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); + +void ft_putnbrbase(int nbr, char *base); +int ft_atoibase(char *str, char *base); +char *ft_convertbase(char *nbr, char *base_from, char *base_to); +char **ft_strmultisplit(char *str, char *charset); +int ft_any(char **tab, int (*f)(char*)); +void ft_foreach(int *tab, int length, void (*f)(int)); +int ft_issort(int *tab, int length, int (*f)(int, int)); +int *ft_arraymap(int *tab, int length, int(*f)(int)); +void ft_putnbrendl(int n); +void ft_putnbrendl_fd(int n, int fd); + +#endif diff --git a/libft/libft.a b/libft/libft.a new file mode 100644 index 0000000000000000000000000000000000000000..4c900aae8e664f14f4a8a9fb4f286cf9225884ca GIT binary patch literal 63720 zcmeHw4|H5tdFOR(g2;x9vWHSbyPL@$7MCC@IgTwiUOEBKGAvQ?0-`QkDk+MLRBTDL zC2Vq5MeW#hMzVv$CdFCUBHI09_CV`yX^ttZkpqoP2#E+jiMlADE-uV0+Km8jqZl{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0UxZH{(1X_YrQyoJC9e4F~_hBWVJ?B;g zb{y!toBOnL?;}s6*|^-xWX_26mJn9dpIbIp-Vbp5Hd#jK=J)gs4Ri&~$GZI{6Y|ii zKQ$g#f4(um5AV?oLZR4G5%p(E_$2u*5E{XUy6KSei)cS~3cnPYA?SP|7qfb>SC2_= z!vAu9lTqYP2u^@*1P$s>L~USJ`Y)$yCaOPAlfmbiQ-0*)_{hcVl1bbFZz7vVj(*IX zX15THHs`xNz?KWGksVPy9QMAl&2`Lhu%xNczTs|oDDQxdn1-rA6ilJdoazL(keyn}kD!oGVN;}Q%Wn0`$nIO&)yj;D{~cw|j$A}TPr<}P z7alfEBq%6Mh4MMJB8T$Ukw!wb_Hk6&DV5_=J2?wJVCs!`Qtt%Yk+S#BHUg9TbRS;= zm_?~Lesk;ccJ$V5q5WZo2KEjd>{-S2#3xuN1Z@X29=9FX;@Ek1v_#psk9x;As5Z~9 zRc=lSZ2%+yJ<|&+FP9+kLbZP6Zn-lhbd&H?2EcPo?ZBYqKMKlrVx@LKc}Jma2Vg>D z5cBrL(TzxnqxU2};;_A#olJ6I0X94>F6YV%TOd;ZQbm5w)#N|NRsuoaU#a|)6PPYP tJ}FYkd+L_&;laTd<(oBW)r~#i&p$r-?(*dOZeP9&Kc(_*rIPRA{{yK_iWL9= literal 0 HcmV?d00001 diff --git a/libft/src/is/ft_isalnum.c b/libft/src/is/ft_isalnum.c new file mode 100644 index 0000000..21bfad0 --- /dev/null +++ b/libft/src/is/ft_isalnum.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:09:33 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:09:37 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + return (ft_isalpha(c) || ft_isdigit(c)); +} diff --git a/libft/src/is/ft_isalpha.c b/libft/src/is/ft_isalpha.c new file mode 100644 index 0000000..b754b0b --- /dev/null +++ b/libft/src/is/ft_isalpha.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:09:44 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:09:46 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalpha(int c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); +} diff --git a/libft/src/is/ft_isascii.c b/libft/src/is/ft_isascii.c new file mode 100644 index 0000000..054f504 --- /dev/null +++ b/libft/src/is/ft_isascii.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:09:53 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:09:55 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isascii(int c) +{ + return (c >= 0 && c <= 127); +} diff --git a/libft/src/is/ft_isdigit.c b/libft/src/is/ft_isdigit.c new file mode 100644 index 0000000..1dd5840 --- /dev/null +++ b/libft/src/is/ft_isdigit.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:10:01 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:10:05 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/libft/src/is/ft_isprint.c b/libft/src/is/ft_isprint.c new file mode 100644 index 0000000..f45cbaf --- /dev/null +++ b/libft/src/is/ft_isprint.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:10:19 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:10:20 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isprint(int c) +{ + return (c >= 32 && c < 127); +} diff --git a/libft/src/is/ft_issort.c b/libft/src/is/ft_issort.c new file mode 100644 index 0000000..842195b --- /dev/null +++ b/libft/src/is/ft_issort.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_issort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/16 15:18:14 by hulamy #+# #+# */ +/* Updated: 2018/11/16 15:18:15 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_issort(int *tab, int length, int (*f)(int, int)) +{ + int i; + + i = -1; + if (!tab) + return (0); + while (++i < length - 1) + if (f(tab[i], tab[i + 1]) > 0) + return (0); + return (1); +} diff --git a/libft/src/lst/ft_lstadd.c b/libft/src/lst/ft_lstadd.c new file mode 100644 index 0000000..d0bed31 --- /dev/null +++ b/libft/src/lst/ft_lstadd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:10:33 by hulamy #+# #+# */ +/* Updated: 2018/11/16 13:58:54 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd(t_list **alst, t_list *new) +{ + new->next = *alst; + *alst = new; +} diff --git a/libft/src/lst/ft_lstdel.c b/libft/src/lst/ft_lstdel.c new file mode 100644 index 0000000..bbe792d --- /dev/null +++ b/libft/src/lst/ft_lstdel.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:10:49 by hulamy #+# #+# */ +/* Updated: 2018/11/16 13:59:10 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) +{ + if ((*alst)->next) + ft_lstdel(&(*alst)->next, del); + ft_lstdelone(alst, del); +} diff --git a/libft/src/lst/ft_lstdelone.c b/libft/src/lst/ft_lstdelone.c new file mode 100644 index 0000000..e2b85c2 --- /dev/null +++ b/libft/src/lst/ft_lstdelone.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:10:59 by hulamy #+# #+# */ +/* Updated: 2018/11/16 13:59:22 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)) +{ + del((*alst)->content, (*alst)->content_size); + free(*alst); + *alst = NULL; +} diff --git a/libft/src/lst/ft_lstiter.c b/libft/src/lst/ft_lstiter.c new file mode 100644 index 0000000..0f791be --- /dev/null +++ b/libft/src/lst/ft_lstiter.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:11:14 by hulamy #+# #+# */ +/* Updated: 2018/11/16 14:01:10 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(t_list *elem)) +{ + if (!lst) + return ; + if (lst->next) + ft_lstiter(lst->next, f); + f(lst); +} diff --git a/libft/src/lst/ft_lstmap.c b/libft/src/lst/ft_lstmap.c new file mode 100644 index 0000000..6b9a2c8 --- /dev/null +++ b/libft/src/lst/ft_lstmap.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:11:20 by hulamy #+# #+# */ +/* Updated: 2018/11/16 14:01:23 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) +{ + t_list *new; + t_list *tmp; + + if (!lst) + return (NULL); + tmp = f(lst); + new = tmp; + while (lst->next) + { + lst = lst->next; + if (!(tmp->next = f(lst))) + { + free(tmp->next); + return (NULL); + } + tmp = tmp->next; + } + return (new); +} diff --git a/libft/src/lst/ft_lstnew.c b/libft/src/lst/ft_lstnew.c new file mode 100644 index 0000000..6d00337 --- /dev/null +++ b/libft/src/lst/ft_lstnew.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:11:42 by hulamy #+# #+# */ +/* Updated: 2018/11/16 14:01:36 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstnew(void const *content, size_t content_size) +{ + t_list *lst; + + if (!(lst = (t_list *)malloc(sizeof(*lst)))) + return (NULL); + if (!content) + { + lst->content = NULL; + lst->content_size = 0; + } + else + { + if (!(lst->content = malloc(content_size))) + return (NULL); + ft_memcpy(lst->content, content, content_size); + lst->content_size = content_size; + } + lst->next = NULL; + return (lst); +} diff --git a/libft/src/mem/ft_memalloc.c b/libft/src/mem/ft_memalloc.c new file mode 100644 index 0000000..13f7ad3 --- /dev/null +++ b/libft/src/mem/ft_memalloc.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memalloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:11:58 by hulamy #+# #+# */ +/* Updated: 2019/04/03 15:42:06 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** allocate size byte of memory and return a pointer to the allocated memory +*/ + +#include "libft.h" + +void *ft_memalloc(size_t size) +{ + void *tmp; + + if (!(tmp = malloc(size))) + return (NULL); + ft_bzero(tmp, size); + return (tmp); +} diff --git a/libft/src/mem/ft_memccpy.c b/libft/src/mem/ft_memccpy.c new file mode 100644 index 0000000..a8bf1ee --- /dev/null +++ b/libft/src/mem/ft_memccpy.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memccpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:12:10 by hulamy #+# #+# */ +/* Updated: 2019/04/03 15:42:41 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** copy string until character is found and place cursor in dst +** after last byte copied +*/ + +#include "libft.h" + +void *ft_memccpy(void *dst, const void *src, int c, size_t n) +{ + unsigned char *dest; + unsigned char *sourc; + size_t i; + + i = -1; + dest = (unsigned char *)dst; + sourc = (unsigned char *)src; + while (++i < n) + { + dest[i] = sourc[i]; + if (sourc[i] == (unsigned char)c) + return (dst + i + 1); + } + return (NULL); +} diff --git a/libft/src/mem/ft_memchr.c b/libft/src/mem/ft_memchr.c new file mode 100644 index 0000000..f6254ed --- /dev/null +++ b/libft/src/mem/ft_memchr.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:12:32 by hulamy #+# #+# */ +/* Updated: 2019/04/03 15:43:14 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** locate character in string and return its position +*/ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + unsigned char *sbis; + size_t i; + + sbis = (unsigned char *)s; + i = -1; + while (++i < n) + if (sbis[i] == (unsigned char)c) + return ((void *)sbis + i); + return (NULL); +} diff --git a/libft/src/mem/ft_memcmp.c b/libft/src/mem/ft_memcmp.c new file mode 100644 index 0000000..d881cba --- /dev/null +++ b/libft/src/mem/ft_memcmp.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:13:04 by hulamy #+# #+# */ +/* Updated: 2019/04/03 15:43:41 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** compare two bytes strings (doesnt recognize a null terminated string) +** and return value of difference between first two different character +*/ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + unsigned char *frst; + unsigned char *scnd; + size_t i; + + i = 0; + frst = (unsigned char *)s1; + scnd = (unsigned char *)s2; + while (i < n && frst[i] == scnd[i]) + i++; + return ((i == n) ? 0 : frst[i] - scnd[i]); +} diff --git a/libft/src/mem/ft_memcpy.c b/libft/src/mem/ft_memcpy.c new file mode 100644 index 0000000..d21a57c --- /dev/null +++ b/libft/src/mem/ft_memcpy.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:13:17 by hulamy #+# #+# */ +/* Updated: 2019/04/03 15:43:56 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** copy n characters from src to dst and return dst +*/ + +#include "libft.h" + +void *ft_memcpy(void *dst, const void *src, size_t n) +{ + size_t i; + char *ptr; + char *ptr2; + + ptr = (char *)dst; + ptr2 = (char *)src; + i = -1; + while (++i < n) + ptr[i] = ptr2[i]; + return (dst); +} diff --git a/libft/src/mem/ft_memdel.c b/libft/src/mem/ft_memdel.c new file mode 100644 index 0000000..f057043 --- /dev/null +++ b/libft/src/mem/ft_memdel.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:13:26 by hulamy #+# #+# */ +/* Updated: 2019/04/03 15:44:12 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** free memory +*/ + +#include "libft.h" + +void ft_memdel(void **ap) +{ + if (ap && *ap) + { + free(*ap); + *ap = 0; + } +} diff --git a/libft/src/mem/ft_memmove.c b/libft/src/mem/ft_memmove.c new file mode 100644 index 0000000..51af09b --- /dev/null +++ b/libft/src/mem/ft_memmove.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:13:34 by hulamy #+# #+# */ +/* Updated: 2019/04/03 15:44:28 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** copy n characters from src to dst in a non destructive way and return dst +*/ + +#include "libft.h" + +void *ft_memmove(void *dst, const void *src, size_t len) +{ + int i; + char *source; + char *dest; + + i = -1; + source = (char *)src; + dest = (char *)dst; + if (source < dest) + while ((int)(--len) >= 0) + dest[len] = source[len]; + else + while (++i < (int)len) + dest[i] = source[i]; + return (dst); +} diff --git a/libft/src/mem/ft_memset.c b/libft/src/mem/ft_memset.c new file mode 100644 index 0000000..b3df393 --- /dev/null +++ b/libft/src/mem/ft_memset.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:13:41 by hulamy #+# #+# */ +/* Updated: 2019/04/03 15:44:44 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** copy n time a character in a string and return the string +*/ + +#include "libft.h" + +void *ft_memset(void *b, int c, size_t len) +{ + char *ptr; + size_t i; + + ptr = (char *)b; + i = 0; + while (i < len) + ptr[i++] = c; + return (b); +} diff --git a/libft/src/put/ft_putchar.c b/libft/src/put/ft_putchar.c new file mode 100644 index 0000000..b0aa9cb --- /dev/null +++ b/libft/src/put/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:14:00 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:14:01 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/libft/src/put/ft_putchar_fd.c b/libft/src/put/ft_putchar_fd.c new file mode 100644 index 0000000..e12e154 --- /dev/null +++ b/libft/src/put/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:14:14 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:14:15 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/libft/src/put/ft_putendl.c b/libft/src/put/ft_putendl.c new file mode 100644 index 0000000..c1d9a6a --- /dev/null +++ b/libft/src/put/ft_putendl.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:14:32 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:14:33 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl(char const *s) +{ + ft_putstr(s); + ft_putchar('\n'); +} diff --git a/libft/src/put/ft_putendl_fd.c b/libft/src/put/ft_putendl_fd.c new file mode 100644 index 0000000..73b5dec --- /dev/null +++ b/libft/src/put/ft_putendl_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:14:47 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:14:48 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char const *s, int fd) +{ + ft_putstr_fd(s, fd); + ft_putchar_fd('\n', fd); +} diff --git a/libft/src/put/ft_putnbr.c b/libft/src/put/ft_putnbr.c new file mode 100644 index 0000000..bb8e2d7 --- /dev/null +++ b/libft/src/put/ft_putnbr.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:14:57 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:14:58 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr(int n) +{ + ft_putnbr_fd(n, 1); +} diff --git a/libft/src/put/ft_putnbr_fd.c b/libft/src/put/ft_putnbr_fd.c new file mode 100644 index 0000000..66a4a9d --- /dev/null +++ b/libft/src/put/ft_putnbr_fd.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:15:09 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:15:10 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr_fd(int n, int fd) +{ + long l; + + l = n; + if (l < 0) + { + ft_putchar_fd('-', fd); + l *= -1; + } + if (l >= 10) + ft_putnbr_fd(l / 10, fd); + ft_putchar_fd((l % 10) + '0', fd); +} diff --git a/libft/src/put/ft_putnbrbase.c b/libft/src/put/ft_putnbrbase.c new file mode 100644 index 0000000..bf0d627 --- /dev/null +++ b/libft/src/put/ft_putnbrbase.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbrbase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/16 15:17:00 by hulamy #+# #+# */ +/* Updated: 2018/11/16 15:23:43 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int check(char *base) +{ + int i; + int j; + + i = 0; + while (base[i]) + { + j = i + 1; + while (base[j]) + { + if (base[i] == base[j]) + return (0); + j++; + } + if (base[i] == '-' || base[i] == '+') + return (0); + i++; + } + if (i >= 2) + return (1); + return (0); +} + +void ft_putnbrbase(int nbr, char *base) +{ + int i; + long n; + + i = 0; + n = nbr; + if (check(base)) + { + if (n < 0) + { + ft_putchar('-'); + n = -n; + } + while (base[i]) + i++; + if (n >= i) + ft_putnbrbase(n / i, base); + ft_putchar(base[n % i]); + } +} diff --git a/libft/src/put/ft_putnbrendl.c b/libft/src/put/ft_putnbrendl.c new file mode 100644 index 0000000..ddd05f6 --- /dev/null +++ b/libft/src/put/ft_putnbrendl.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbrendl.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/02/19 10:38:07 by hulamy #+# #+# */ +/* Updated: 2019/02/19 10:42:46 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbrendl(int n) +{ + ft_putnbrendl_fd(n, 1); +} diff --git a/libft/src/put/ft_putnbrendl_fd.c b/libft/src/put/ft_putnbrendl_fd.c new file mode 100644 index 0000000..266dc55 --- /dev/null +++ b/libft/src/put/ft_putnbrendl_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbrendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/02/19 10:37:58 by hulamy #+# #+# */ +/* Updated: 2019/02/19 10:42:48 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbrendl_fd(int n, int fd) +{ + long l; + + l = n; + if (l < 0) + { + ft_putchar_fd('-', fd); + l *= -1; + } + if (l >= 10) + ft_putnbr_fd(l / 10, fd); + ft_putchar_fd((l % 10) + '0', fd); + ft_putchar_fd('\n', fd); +} diff --git a/libft/src/put/ft_putstr.c b/libft/src/put/ft_putstr.c new file mode 100644 index 0000000..78617eb --- /dev/null +++ b/libft/src/put/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:15:19 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:15:19 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr(char const *s) +{ + int i; + + i = 0; + while (s && s[i]) + ft_putchar(s[i++]); +} diff --git a/libft/src/put/ft_putstr_fd.c b/libft/src/put/ft_putstr_fd.c new file mode 100644 index 0000000..65607b1 --- /dev/null +++ b/libft/src/put/ft_putstr_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:15:31 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:15:32 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char const *s, int fd) +{ + while (s && *s) + ft_putchar_fd(*s++, fd); +} diff --git a/libft/src/str/ft_strcat.c b/libft/src/str/ft_strcat.c new file mode 100644 index 0000000..d78543c --- /dev/null +++ b/libft/src/str/ft_strcat.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:15:40 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:12:58 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** append src to dest (dest must have sufficient space) and return dest +*/ + +#include "libft.h" + +char *ft_strcat(char *dest, const char *src) +{ + int i; + int j; + + i = 0; + j = 0; + while (dest[i]) + i++; + while (src[j]) + dest[i++] = src[j++]; + dest[i] = '\0'; + return (dest); +} diff --git a/libft/src/str/ft_strchr.c b/libft/src/str/ft_strchr.c new file mode 100644 index 0000000..095c87e --- /dev/null +++ b/libft/src/str/ft_strchr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:15:48 by hulamy #+# #+# */ +/* Updated: 2019/04/16 17:28:46 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** locate the first occurence of character c in string s +** and return pointer to its location +*/ + +#include "libft.h" + +char *ft_strchr(const char *s, int c) +{ + int i; + int j; + + i = 0; + j = -1; + while (s[i]) + i++; + while (++j < i + 1) + if (s[j] == c) + return ((char *)s + j); + return (NULL); +} diff --git a/libft/src/str/ft_strclr.c b/libft/src/str/ft_strclr.c new file mode 100644 index 0000000..5e3952c --- /dev/null +++ b/libft/src/str/ft_strclr.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strclr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:15:58 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:17:42 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** fill string with zeros +*/ + +#include "libft.h" + +void ft_strclr(char *s) +{ + if (s) + ft_bzero(s, ft_strlen(s)); +} diff --git a/libft/src/str/ft_strcmp.c b/libft/src/str/ft_strcmp.c new file mode 100644 index 0000000..f6603c3 --- /dev/null +++ b/libft/src/str/ft_strcmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:16:08 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:18:30 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** compare two null terminated strings and return value +** of difference between first two different character +*/ + +#include "libft.h" + +int ft_strcmp(const char *s1, const char *s2) +{ + int i; + + i = 0; + while (s1[i] && s1[i] == s2[i]) + i++; + return ((unsigned char)s1[i] - (unsigned char)s2[i]); +} diff --git a/libft/src/str/ft_strcpy.c b/libft/src/str/ft_strcpy.c new file mode 100644 index 0000000..7d2a45b --- /dev/null +++ b/libft/src/str/ft_strcpy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:16:17 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:19:19 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** copy string src to dst including '\0' and return dst +*/ + +#include "libft.h" + +char *ft_strcpy(char *dest, const char *src) +{ + int i; + + i = -1; + while (src[++i]) + dest[i] = src[i]; + dest[i] = '\0'; + return (dest); +} diff --git a/libft/src/str/ft_strdel.c b/libft/src/str/ft_strdel.c new file mode 100644 index 0000000..82cbc2e --- /dev/null +++ b/libft/src/str/ft_strdel.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:16:25 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:19:54 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** free memory +*/ + +#include "libft.h" + +void ft_strdel(char **as) +{ + if (as && *as) + { + free(*as); + *as = 0; + } +} diff --git a/libft/src/str/ft_strdup.c b/libft/src/str/ft_strdup.c new file mode 100644 index 0000000..6fc8594 --- /dev/null +++ b/libft/src/str/ft_strdup.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:16:32 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:20:22 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** save a copy of string src by allocating memory and return pointer to copy +*/ + +#include "libft.h" + +char *ft_strdup(const char *src) +{ + int i; + char *str; + + i = 0; + while (src[i] != '\0') + i++; + if (!(str = (char*)malloc(sizeof(*str) * (i + 1)))) + return (NULL); + while (i-- >= 0) + str[i + 1] = src[i + 1]; + return (str); +} diff --git a/libft/src/str/ft_strequ.c b/libft/src/str/ft_strequ.c new file mode 100644 index 0000000..fa4d4e4 --- /dev/null +++ b/libft/src/str/ft_strequ.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strequ.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:16:44 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:21:02 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** return 0 if strings s1 and s2 are identical and 1 if not +*/ + +#include "libft.h" + +int ft_strequ(char const *s1, char const *s2) +{ + if (!s1 || !s2) + return (0); + return (ft_strcmp(s1, s2) == 0); +} diff --git a/libft/src/str/ft_striter.c b/libft/src/str/ft_striter.c new file mode 100644 index 0000000..9d3b21f --- /dev/null +++ b/libft/src/str/ft_striter.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:16:53 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:21:14 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** apply function f to each element of string s +*/ + +#include "libft.h" + +void ft_striter(char *s, void (*f)(char *)) +{ + while (s && *s && f) + f(s++); +} diff --git a/libft/src/str/ft_striteri.c b/libft/src/str/ft_striteri.c new file mode 100644 index 0000000..60fd7f6 --- /dev/null +++ b/libft/src/str/ft_striteri.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:17:04 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:21:27 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** apply function f to each element of string s with index specified +*/ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char *)) +{ + int i; + + i = 0; + while (s && *s && f) + f(i++, s++); +} diff --git a/libft/src/str/ft_strjoin.c b/libft/src/str/ft_strjoin.c new file mode 100644 index 0000000..48f95a1 --- /dev/null +++ b/libft/src/str/ft_strjoin.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:17:12 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:31:03 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** create a new string by concatenating the two strings s1 and s2 +*/ + +#include "libft.h" + +static char *ft_doit(char const *s1, char const *s2, char *dest) +{ + int j; + int i; + + j = 0; + i = 0; + while (s1[j] != '\0') + { + dest[i] = s1[j]; + i++; + j++; + } + j = 0; + while (s2[j] != '\0') + { + dest[i] = s2[j]; + i++; + j++; + } + dest[i] = '\0'; + return (dest); +} + +char *ft_strjoin(char const *s1, char const *s2) +{ + char *str; + + if (!s1 || !s2) + return (NULL); + if (!(str = (char *)malloc(sizeof(char) * + (ft_strlen(s1) + ft_strlen(s2) + 1)))) + return (NULL); + str = ft_doit(s1, s2, str); + return (str); +} diff --git a/libft/src/str/ft_strjoinfree.c b/libft/src/str/ft_strjoinfree.c new file mode 100644 index 0000000..8e0247b --- /dev/null +++ b/libft/src/str/ft_strjoinfree.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoinfree.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/03/05 15:05:28 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:22:28 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** create a new string by concatenating the two strings s1 +** and s2 then freeing them +*/ + +#include "libft.h" + +char *ft_strjoinfree(char *s1, char *s2) +{ + char *str; + + if (!(str = ft_strjoin(s1, s2))) + return (NULL); + free(s1); + return (str); +} diff --git a/libft/src/str/ft_strlcat.c b/libft/src/str/ft_strlcat.c new file mode 100644 index 0000000..941a1d0 --- /dev/null +++ b/libft/src/str/ft_strlcat.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:17:22 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:22:42 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** append src to sized dest and return size of final dest +*/ + +#include "libft.h" + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t i; + size_t j; + + i = 0; + j = 0; + while (dest[i] && i < size) + i++; + while (src[j]) + { + if (j + i < size - 1 && size) + { + dest[i + j] = src[j]; + dest[i + j + 1] = '\0'; + } + j++; + } + return (i + j); +} diff --git a/libft/src/str/ft_strlen.c b/libft/src/str/ft_strlen.c new file mode 100644 index 0000000..59cc818 --- /dev/null +++ b/libft/src/str/ft_strlen.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:17:32 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:23:00 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** return length of of string +*/ + +#include "libft.h" + +size_t ft_strlen(const char *str) +{ + size_t i; + + i = 0; + while (str[i]) + i++; + return (i); +} diff --git a/libft/src/str/ft_strmap.c b/libft/src/str/ft_strmap.c new file mode 100644 index 0000000..ef82f97 --- /dev/null +++ b/libft/src/str/ft_strmap.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:17:49 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:23:12 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** create a new array with the result of function f on every element of s +*/ + +#include "libft.h" + +char *ft_strmap(char const *s, char (*f)(char)) +{ + char *str; + int i; + + if (!s) + return (NULL); + if (!(str = ft_strnew(ft_strlen(s)))) + return (NULL); + i = -1; + while (s[++i]) + str[i] = f(s[i]); + return (str); +} diff --git a/libft/src/str/ft_strmapi.c b/libft/src/str/ft_strmapi.c new file mode 100644 index 0000000..d9fb527 --- /dev/null +++ b/libft/src/str/ft_strmapi.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:18:03 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:28:21 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** create a new array with the result of function f +** on every element of s by index i +*/ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *str; + int i; + + if (!s) + return (NULL); + if (!(str = ft_strnew(ft_strlen(s)))) + return (NULL); + i = -1; + while (s[++i]) + str[i] = f(i, s[i]); + return (str); +} diff --git a/libft/src/str/ft_strmultisplit.c b/libft/src/str/ft_strmultisplit.c new file mode 100644 index 0000000..ed2ed98 --- /dev/null +++ b/libft/src/str/ft_strmultisplit.c @@ -0,0 +1,83 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmultisplit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/16 15:18:29 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:23:57 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** return an array of string with each word found in str +** with any character of charset difining a separator +*/ + +#include "libft.h" + +static int ft_is_separator(char c, char *charset, int i) +{ + while (charset[i]) + { + if (c == charset[i]) + return (1); + i++; + } + c = charset[i]; + return (0); +} + +static int ft_count(char *str, int word, char **tab, char *charset) +{ + int i; + int j; + int k; + + k = 0; + i = 0; + while (ft_is_separator(str[k], charset, 0) == 1) + k++; + while (str[k] != '\0' && i != word) + { + j = 0; + while (!ft_is_separator(str[k + j], charset, 0) && str[k + j] != '\0') + { + if (word == -2) + tab[i][j] = str[k + j]; + j++; + } + k += j; + while (ft_is_separator(str[k], charset, 0)) + k++; + i++; + } + if (word == -1) + return (i); + return (j); +} + +char **ft_strmultisplit(char *str, char *charset) +{ + char **tab; + int i; + int j; + int k; + + k = 0; + tab = 0; + i = ft_count(str, -1, tab, charset); + if (!(tab = (char**)malloc(sizeof(tab) * (i + 1)))) + return (NULL); + tab[i] = 0; + while (k < i) + { + j = ft_count(str, k + 1, tab, charset); + tab[k] = (char*)malloc(sizeof(*tab) * (j + 1)); + tab[k][j] = '\0'; + k++; + } + ft_count(str, -2, tab, charset); + return (tab); +} diff --git a/libft/src/str/ft_strncat.c b/libft/src/str/ft_strncat.c new file mode 100644 index 0000000..cf52aae --- /dev/null +++ b/libft/src/str/ft_strncat.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:18:24 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:24:11 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** append n character of src to dest and return dest +*/ + +#include "libft.h" + +char *ft_strncat(char *dest, const char *src, size_t nb) +{ + size_t i; + size_t j; + + i = 0; + j = 0; + while (dest[i]) + i++; + while (src[j] && j < nb) + dest[i++] = src[j++]; + dest[i] = '\0'; + return (dest); +} diff --git a/libft/src/str/ft_strncmp.c b/libft/src/str/ft_strncmp.c new file mode 100644 index 0000000..5d51c2d --- /dev/null +++ b/libft/src/str/ft_strncmp.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:18:34 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:24:35 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** compare size first character of two null terminated strings +** and return value of difference between first two different character +*/ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t i; + int res; + + i = 0; + res = 0; + while (s1[i] && s1[i] == s2[i] && i < n - 1) + i++; + if (n != 0) + res = (unsigned char)s1[i] - (unsigned char)s2[i]; + return (res); +} diff --git a/libft/src/str/ft_strncpy.c b/libft/src/str/ft_strncpy.c new file mode 100644 index 0000000..91ea1b3 --- /dev/null +++ b/libft/src/str/ft_strncpy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:18:44 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:24:59 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** copy n characters from string src to dst including '\0' +** if space remain it's filled zith '\0', and return dst +*/ + +#include "libft.h" + +char *ft_strncpy(char *dest, const char *src, size_t n) +{ + size_t i; + + i = -1; + while (++i < n && src[i]) + dest[i] = src[i]; + while (i < n) + dest[i++] = '\0'; + return (dest); +} diff --git a/libft/src/str/ft_strnequ.c b/libft/src/str/ft_strnequ.c new file mode 100644 index 0000000..668f3fa --- /dev/null +++ b/libft/src/str/ft_strnequ.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnequ.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:18:55 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:25:20 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** return 0 if n first character of strings s1 and s2 are identical +** and 1 if not +*/ + +#include "libft.h" + +int ft_strnequ(char const *s1, char const *s2, size_t n) +{ + if (!s1 || !s2) + return (0); + return (ft_strncmp(s1, s2, n) == 0); +} diff --git a/libft/src/str/ft_strnew.c b/libft/src/str/ft_strnew.c new file mode 100644 index 0000000..c7855ad --- /dev/null +++ b/libft/src/str/ft_strnew.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:19:08 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:25:38 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** create a new string of length size, fill with zero, and return pointer to it +*/ + +#include "libft.h" + +char *ft_strnew(size_t size) +{ + char *str; + + if (!(str = (char *)malloc(sizeof(char) * (size + 1)))) + return (NULL); + ft_bzero(str, size + 1); + return (str); +} diff --git a/libft/src/str/ft_strnstr.c b/libft/src/str/ft_strnstr.c new file mode 100644 index 0000000..5dbb8c0 --- /dev/null +++ b/libft/src/str/ft_strnstr.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:19:16 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:25:57 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** locate the first occurence of the string little in len first characters +** of big and return a pointer to this occurence if found +*/ + +#include "libft.h" + +char *ft_strnstr(const char *big, const char *little, size_t len) +{ + size_t i; + size_t j; + + j = 0; + i = 0; + if (!ft_strlen(little)) + return ((char *)big); + while (i == 0 && j <= len) + { + while (little[i] == big[j + i] && little[i] && j + i <= len) + i++; + if (little[i]) + { + j++; + if (!big[j] || j >= len) + return (0); + i = 0; + } + } + return ((char *)big + j); +} diff --git a/libft/src/str/ft_strrchr.c b/libft/src/str/ft_strrchr.c new file mode 100644 index 0000000..b512fe7 --- /dev/null +++ b/libft/src/str/ft_strrchr.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:19:23 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:26:21 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** locate the last occurence of character c in string s +** and return pointer to its location +*/ + +#include "libft.h" + +char *ft_strrchr(const char *s, int c) +{ + int i; + + i = 0; + while (s[i]) + i++; + i++; + while (i--) + if (s[i] == c) + return ((char *)s + i); + return (NULL); +} diff --git a/libft/src/str/ft_strsplit.c b/libft/src/str/ft_strsplit.c new file mode 100644 index 0000000..bcdba85 --- /dev/null +++ b/libft/src/str/ft_strsplit.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsplit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:19:36 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:26:39 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** return an array of string with each word found in str, with c as separator +*/ + +#include "libft.h" + +static int ft_count_word(char const *s, char c) +{ + int i; + int len; + + i = -1; + len = 0; + while (s[++i]) + if (s[i] != c) + { + len++; + while (s[i] && s[i] != c) + i++; + } + return (len); +} + +char **ft_strsplit(char const *s, char c) +{ + char **array; + int i; + int j; + int len; + + i = -1; + j = 0; + if (!s || !c) + return (0); + if (!(array = (char **)malloc(sizeof(char *) * (ft_count_word(s, c) + 1)))) + return (NULL); + while (s[++i]) + { + if (s[i] != c) + { + len = 0; + while (s[i + len] && s[i + len] != c) + len++; + array[j++] = ft_strsub(s, i, len); + i = i + len - 1; + } + } + array[j] = 0; + return (array); +} diff --git a/libft/src/str/ft_strstr.c b/libft/src/str/ft_strstr.c new file mode 100644 index 0000000..c7a3535 --- /dev/null +++ b/libft/src/str/ft_strstr.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:19:45 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:26:59 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** locate the first occurence of the string little in big +** and return a pointer to this occurence if found +*/ + +#include "libft.h" + +char *ft_strstr(const char *str, const char *to_find) +{ + int i; + int j; + + j = 0; + i = 0; + if (!ft_strlen(to_find)) + return ((char *)str); + while (i == 0) + { + while (to_find[i] && to_find[i] == str[j + i]) + i++; + if (to_find[i]) + { + j++; + if (str[j] == '\0' && to_find[i]) + return (0); + i = 0; + } + } + return ((char *)str + j); +} diff --git a/libft/src/str/ft_strsub.c b/libft/src/str/ft_strsub.c new file mode 100644 index 0000000..74fc38a --- /dev/null +++ b/libft/src/str/ft_strsub.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsub.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:19:52 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:27:14 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** create a copy of a portion of s, begining at start and of length len +*/ + +#include "libft.h" + +char *ft_strsub(char const *s, unsigned int start, size_t len) +{ + char *str; + size_t i; + + if (!s) + return (NULL); + if (!(str = ft_strnew(len))) + return (NULL); + i = 0; + while (i < len) + str[i++] = s[start++]; + return (str); +} diff --git a/libft/src/str/ft_strtrim.c b/libft/src/str/ft_strtrim.c new file mode 100644 index 0000000..7133c7e --- /dev/null +++ b/libft/src/str/ft_strtrim.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:20:09 by hulamy #+# #+# */ +/* Updated: 2019/03/25 15:12:04 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** create a copy of s without the firsts and lasts empty characters +*/ + +#include "libft.h" + +char *ft_strtrim(char const *s) +{ + int len; + char *str; + + if (!s) + return (NULL); + while (*s == ' ' || *s == '\t' || *s == '\n') + s++; + len = ft_strlen(s) - 1; + while (len >= 0 && (s[len] == ' ' || s[len] == '\t' || s[len] == '\n')) + len--; + len++; + if (!(str = ft_strsub(s, 0, len))) + return (NULL); + return (str); +} diff --git a/libft/src/tab/ft_any.c b/libft/src/tab/ft_any.c new file mode 100644 index 0000000..349e3a9 --- /dev/null +++ b/libft/src/tab/ft_any.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_any.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/16 15:14:49 by hulamy #+# #+# */ +/* Updated: 2018/11/16 15:14:53 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_any(char **tab, int (*f)(char*)) +{ + int i; + + i = -1; + if (!tab) + return (0); + while (tab[++i]) + if (f(tab[i]) == 1) + return (1); + return (0); +} diff --git a/libft/src/tab/ft_arraymap.c b/libft/src/tab/ft_arraymap.c new file mode 100644 index 0000000..267510a --- /dev/null +++ b/libft/src/tab/ft_arraymap.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_arraymap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/16 15:17:24 by hulamy #+# #+# */ +/* Updated: 2018/11/16 15:17:27 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int *ft_arraymap(int *tab, int length, int (*f)(int)) +{ + int i; + int *newtab; + + i = -1; + if (!tab) + return (NULL); + if (!(newtab = (int*)malloc(sizeof(*newtab) * (length + 1)))) + return (NULL); + while (++i < length) + newtab[i] = (*f)(tab[i]); + return (newtab); +} diff --git a/libft/src/tab/ft_foreach.c b/libft/src/tab/ft_foreach.c new file mode 100644 index 0000000..aaf7649 --- /dev/null +++ b/libft/src/tab/ft_foreach.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_foreach.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/16 15:16:10 by hulamy #+# #+# */ +/* Updated: 2018/11/16 15:16:11 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_foreach(int *tab, int length, void (*f)(int)) +{ + int i; + + i = 0; + while (i < length && tab && tab[i]) + (*f)(tab[i++]); +} diff --git a/libft/src/trsf/ft_atoi.c b/libft/src/trsf/ft_atoi.c new file mode 100644 index 0000000..5c10b59 --- /dev/null +++ b/libft/src/trsf/ft_atoi.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:09:04 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:38:12 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_atoi(const char *str) +{ + long long nbr; + int i; + int n; + + i = 0; + n = 1; + nbr = 0; + while ((str[i] == 32) || (str[i] > 8 && str[i] < 14)) + i++; + if (str[i] == '-') + n = -1; + if (str[i] == '+' || str[i] == '-') + i++; + while (str[i] >= '0' && str[i] <= '9') + { + if ((nbr >= 922337203685477580 + && ((str[i] > 8 && n < 0) || (str[i] > 7 && n > 0)))) + return ((n > 0) ? -1 : 0); + else + nbr = nbr * 10 + (str[i++] - '0'); + } + return (nbr * n); +} diff --git a/libft/src/trsf/ft_atoibase.c b/libft/src/trsf/ft_atoibase.c new file mode 100644 index 0000000..fdb92d1 --- /dev/null +++ b/libft/src/trsf/ft_atoibase.c @@ -0,0 +1,75 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoibase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/16 15:15:31 by hulamy #+# #+# */ +/* Updated: 2018/11/16 15:22:34 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int is_valid_base(char *base, int i, int j) +{ + while (base[i]) + { + j = i + 1; + while (base[j]) + { + if (base[i] == base[j]) + return (0); + j++; + } + if (base[i] == '-' || base[i] == '+') + return (0); + i++; + } + if (i >= 2) + return (1); + return (0); +} + +static int skip(int i, char *str, int *n) +{ + while ((str[i] == 32) || (str[i] > 8 && str[i] < 14)) + i++; + if (str[i] == '+' || str[i] == '-') + { + if (str[i] == '-') + *n = -1; + i++; + } + return (i); +} + +int ft_atoibase(char *str, char *base) +{ + int i; + int j; + int length; + int res; + int n; + + length = 0; + res = 0; + n = 1; + if (!is_valid_base(base, 0, 0)) + return (0); + while (base[length]) + length++; + i = skip(0, str, &n); + while (str[i] && str[i] > 32 && str[i] != '-' && str[i] != '+') + { + j = 0; + while (str[i] != base[j] && base[j]) + j++; + if (base[j] == '\0') + return (0); + res = (res * length) + j; + i++; + } + return (res * n); +} diff --git a/libft/src/trsf/ft_bzero.c b/libft/src/trsf/ft_bzero.c new file mode 100644 index 0000000..ed2c7eb --- /dev/null +++ b/libft/src/trsf/ft_bzero.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:09:19 by hulamy #+# #+# */ +/* Updated: 2018/11/15 21:43:05 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + size_t i; + unsigned char *ptr; + + if (n) + { + ptr = (unsigned char *)s; + i = 0; + while (i < n) + ptr[i++] = '\0'; + } +} diff --git a/libft/src/trsf/ft_convertbase.c b/libft/src/trsf/ft_convertbase.c new file mode 100644 index 0000000..7fe9bad --- /dev/null +++ b/libft/src/trsf/ft_convertbase.c @@ -0,0 +1,86 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_convertbase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/16 15:15:55 by hulamy #+# #+# */ +/* Updated: 2019/04/17 17:09:35 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_malloc_size(int decimal, int length, int i) +{ + if (decimal <= 0) + i++; + while (decimal) + { + decimal /= length; + i++; + } + return (i); +} + +static char *ft_decimal_to_base(int decimal, char *base, char *res, int size) +{ + long nb; + int i; + + nb = decimal; + i = 0; + while (base[i]) + i++; + if (nb < 0) + nb = -nb; + while (--size >= 0) + { + res[size] = base[nb % i]; + nb /= i; + } + return (res); +} + +static int ft_base_to_decimal(char *nbr, char *base, int length, int i) +{ + long decimal; + int j; + + decimal = 0; + if (nbr[i] == '-') + i++; + while (nbr[i]) + { + j = 0; + while (nbr[i] != base[j] && base[j]) + j++; + decimal = (decimal * length) + j; + i++; + } + if (nbr[0] == '-') + decimal = -decimal; + return (decimal); +} + +char *ft_convertbase(char *nbr, char *base_from, char *base_to) +{ + int length; + int size; + int decimal; + char *res; + + res = 0; + length = 0; + while (base_from[length]) + length++; + decimal = ft_base_to_decimal(nbr, base_from, length, 0); + length = 0; + while (base_to[length]) + length++; + size = ft_malloc_size(decimal, length, 0); + res = (char *)malloc(sizeof(char) * (size + 1)); + res[size] = '\0'; + return (ft_decimal_to_base(decimal, base_to, res, size)); +} diff --git a/libft/src/trsf/ft_itoa.c b/libft/src/trsf/ft_itoa.c new file mode 100644 index 0000000..65fbfa7 --- /dev/null +++ b/libft/src/trsf/ft_itoa.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:10:25 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:36:38 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_itoa(int n) +{ + char *str; + int len; + long int nbis; + + len = (n < 0) ? 2 : 1; + nbis = n; + while (nbis /= 10) + len++; + nbis = n; + nbis *= (nbis < 0) ? -1 : 1; + if (!(str = ft_strnew(len))) + return (NULL); + str[--len] = nbis % 10 + '0'; + while (nbis /= 10) + str[--len] = nbis % 10 + '0'; + if (n < 0) + str[0] = '-'; + return (str); +} diff --git a/libft/src/trsf/ft_tolower.c b/libft/src/trsf/ft_tolower.c new file mode 100644 index 0000000..e8f2b0f --- /dev/null +++ b/libft/src/trsf/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:20:19 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:20:20 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c + 32); + return (c); +} diff --git a/libft/src/trsf/ft_toupper.c b/libft/src/trsf/ft_toupper.c new file mode 100644 index 0000000..e0e0271 --- /dev/null +++ b/libft/src/trsf/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hulamy +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/14 21:20:26 by hulamy #+# #+# */ +/* Updated: 2018/11/14 21:20:27 by hulamy ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c - 32); + return (c); +} diff --git a/samples/debug/jdugoudrdiff b/samples/debug/jdugoudrdiff new file mode 100644 index 0000000..098bda4 --- /dev/null +++ b/samples/debug/jdugoudrdiff @@ -0,0 +1,74 @@ +...# +...# +...# +...# + +#... +##.. +.#.. +.... + +.... +###. +#... +.... + +#### +.... +.... +.... + +.##. +##.. +.... +.... + +##.. +.##. +.... +.... + +#... +##.. +.#.. +.... + +.... +###. +#... +.... + +#... +##.. +.#.. +.... + +.... +###. +#... +.... + +#### +.... +.... +.... + +.##. +##.. +.... +.... + +##.. +.##. +.... +.... + +#... +##.. +.#.. +.... + +.... +###. +#... +....