├── .gitignore ├── Makefile ├── Makefile-sample ├── README.md ├── additional-funcs ├── ft_itoa.c ├── ft_memalloc.c ├── ft_memdel.c ├── ft_putchar.c ├── ft_putchar_fd.c ├── ft_putendl.c ├── ft_putendl_fd.c ├── ft_putnbr.c ├── ft_putnbr_fd.c ├── ft_putstr.c ├── ft_putstr_fd.c ├── ft_strclr.c ├── ft_strdel.c ├── ft_strequ.c ├── ft_striter.c ├── ft_striteri.c ├── ft_strjoin.c ├── ft_strmap.c ├── ft_strmapi.c ├── ft_strnequ.c ├── ft_strnew.c ├── ft_strsplit.c ├── ft_strsub.c └── ft_strtrim.c ├── bonus-funcs ├── ft_lstadd.c ├── ft_lstdel.c ├── ft_lstdelone.c ├── ft_lstiter.c ├── ft_lstmap.c └── ft_lstnew.c ├── example.c ├── libc-funcs ├── ft_atoi.c ├── ft_bzero.c ├── ft_isalnum.c ├── ft_isalpha.c ├── ft_isascii.c ├── ft_isdigit.c ├── ft_isprint.c ├── ft_memccpy.c ├── ft_memchr.c ├── ft_memcmp.c ├── ft_memcpy.c ├── ft_memmove.c ├── ft_memset.c ├── ft_strcat.c ├── ft_strchr.c ├── ft_strcmp.c ├── ft_strcpy.c ├── ft_strdup.c ├── ft_strlcat.c ├── ft_strlen.c ├── ft_strncat.c ├── ft_strncmp.c ├── ft_strncpy.c ├── ft_strndup.c ├── ft_strnstr.c ├── ft_strrchr.c ├── ft_strstr.c ├── ft_tolower.c └── ft_toupper.c ├── libft.en.pdf ├── libft.h └── personal-funcs ├── ft_capitalize.c ├── ft_copyuntil.c ├── ft_count2darray.c ├── ft_countwords.c ├── ft_countwordsall.c ├── ft_freestrarr.c ├── ft_get_parent_path.c ├── ft_intlen.c ├── ft_isemptystr.c ├── ft_islower.c ├── ft_isupper.c ├── ft_lst_reverse.c ├── ft_lstaddback.c ├── ft_pathjoin.c ├── ft_putnstr.c ├── ft_realloc.c ├── ft_strarrmax.c ├── ft_strendswith.c ├── ft_strjoinch.c ├── ft_strjoinchcl.c ├── ft_strjoincl.c ├── ft_strnchr.c ├── ft_strndup.c ├── ft_strreplace.c ├── ft_strsplitall.c ├── ft_strstartswith.c └── get_next_line.c /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: jrameau +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2016/09/21 14:58:27 by jrameau #+# #+# # 9 | # Updated: 2017/04/24 03:49:23 by jrameau ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = libft.a 14 | CFLAGS = -Wall -Werror -Wextra -I. -c 15 | FILES = ft_memset.c \ 16 | ft_bzero.c \ 17 | ft_memcpy.c \ 18 | ft_memccpy.c \ 19 | ft_strlen.c \ 20 | ft_memmove.c \ 21 | ft_memchr.c \ 22 | ft_memcmp.c \ 23 | ft_strcpy.c \ 24 | ft_strdup.c \ 25 | ft_strcat.c \ 26 | ft_strncat.c \ 27 | ft_strlcat.c \ 28 | ft_strchr.c \ 29 | ft_strrchr.c \ 30 | ft_strstr.c \ 31 | ft_strnstr.c \ 32 | ft_strcmp.c \ 33 | ft_strncmp.c \ 34 | ft_atoi.c \ 35 | ft_islower.c \ 36 | ft_isupper.c \ 37 | ft_isalpha.c \ 38 | ft_isdigit.c \ 39 | ft_isalnum.c \ 40 | ft_isprint.c \ 41 | ft_toupper.c \ 42 | ft_tolower.c \ 43 | ft_strncpy.c \ 44 | ft_isascii.c \ 45 | ft_memalloc.c \ 46 | ft_memdel.c \ 47 | ft_strnew.c \ 48 | ft_strdel.c \ 49 | ft_strclr.c \ 50 | ft_striter.c \ 51 | ft_striteri.c \ 52 | ft_strmap.c \ 53 | ft_strmapi.c \ 54 | ft_strequ.c \ 55 | ft_strnequ.c \ 56 | ft_strsub.c \ 57 | ft_strjoin.c \ 58 | ft_strtrim.c \ 59 | ft_strsplit.c \ 60 | ft_itoa.c \ 61 | ft_putchar.c \ 62 | ft_putchar_fd.c \ 63 | ft_countwords.c \ 64 | ft_putstr.c \ 65 | ft_putendl.c \ 66 | ft_putnbr.c \ 67 | ft_putnbr_fd.c \ 68 | ft_putstr_fd.c \ 69 | ft_putendl_fd.c \ 70 | ft_lstnew.c \ 71 | ft_lstdelone.c \ 72 | ft_lstdel.c \ 73 | ft_lstadd.c \ 74 | ft_lstiter.c \ 75 | ft_lstmap.c \ 76 | ft_strndup.c \ 77 | ft_capitalize.c \ 78 | ft_lst_reverse.c \ 79 | ft_realloc.c \ 80 | ft_strjoinch.c \ 81 | ft_strnchr.c \ 82 | ft_copyuntil.c \ 83 | ft_strstartswith.c \ 84 | ft_intlen.c \ 85 | ft_strendswith.c \ 86 | ft_pathjoin.c \ 87 | ft_lstaddback.c \ 88 | get_next_line.c \ 89 | ft_putnstr.c \ 90 | ft_strreplace.c \ 91 | ft_isemptystr.c \ 92 | ft_strsplitall.c \ 93 | ft_countwordsall.c \ 94 | ft_freestrarr.c \ 95 | ft_strjoincl.c \ 96 | ft_strjoinchcl.c \ 97 | ft_count2darray.c \ 98 | ft_strarrmax.c \ 99 | ft_get_parent_path.c 100 | OBJ = $(FILES:%.c=%.o) 101 | 102 | all: $(NAME) 103 | 104 | copy: 105 | cp -f libc-funcs/*.c . 106 | cp -f additional-funcs/*.c . 107 | cp -f bonus-funcs/*.c . 108 | cp -f personal-funcs/*.c . 109 | 110 | # This won't run if the .o files don't exist or are not modified 111 | $(NAME): $(OBJ) 112 | ar rcs $(NAME) $(OBJ) 113 | 114 | # This won't run if the source files don't exist or are not modified 115 | $(OBJ): $(FILES) 116 | gcc $(CFLAGS) $(FILES) 117 | 118 | clean: 119 | rm -f $(OBJ) 120 | rm -f $(FILES) # comment this line if you don't want it to remove the source files from the root 121 | 122 | fclean: clean 123 | rm -f $(NAME) 124 | 125 | re: fclean all 126 | 127 | # I use .PHONY to make sure that gnu make will still run even if files called 128 | # clean / fclean / all and re already exist in the directory 129 | .PHONY: clean fclean all re 130 | -------------------------------------------------------------------------------- /Makefile-sample: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile-sample :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: jrameau +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2016/09/21 14:58:27 by jrameau #+# #+# # 9 | # Updated: 2017/04/24 03:50:03 by jrameau ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = libft.a 14 | CFLAGS = -Wall -Werror -Wextra -I. -c 15 | #FILES = ft_memset.c \ 16 | ft_bzero.c \ 17 | ft_memcpy.c \ 18 | ft_memccpy.c \ 19 | ft_strlen.c \ 20 | ft_memmove.c \ 21 | ft_memchr.c \ 22 | ft_memcmp.c \ 23 | ft_strcpy.c \ 24 | ft_strdup.c \ 25 | ft_strcat.c \ 26 | ft_strncat.c \ 27 | ft_strlcat.c \ 28 | ft_strchr.c \ 29 | ft_strrchr.c \ 30 | ft_strstr.c \ 31 | ft_strnstr.c \ 32 | ft_strcmp.c \ 33 | ft_strncmp.c \ 34 | ft_atoi.c \ 35 | ft_islower.c \ 36 | ft_isupper.c \ 37 | ft_isalpha.c \ 38 | ft_isdigit.c \ 39 | ft_isalnum.c \ 40 | ft_isprint.c \ 41 | ft_toupper.c \ 42 | ft_tolower.c \ 43 | ft_strncpy.c \ 44 | ft_isascii.c \ 45 | ft_memalloc.c \ 46 | ft_memdel.c \ 47 | ft_strnew.c \ 48 | ft_strdel.c \ 49 | ft_strclr.c \ 50 | ft_striter.c \ 51 | ft_striteri.c \ 52 | ft_strmap.c \ 53 | ft_strmapi.c \ 54 | ft_strequ.c \ 55 | ft_strnequ.c \ 56 | ft_strsub.c \ 57 | ft_strjoin.c \ 58 | ft_strtrim.c \ 59 | ft_strsplit.c \ 60 | ft_itoa.c \ 61 | ft_putchar.c \ 62 | ft_putchar_fd.c \ 63 | ft_countwords.c \ 64 | ft_putstr.c \ 65 | ft_putendl.c \ 66 | ft_putnbr.c \ 67 | ft_putnbr_fd.c \ 68 | ft_putstr_fd.c \ 69 | ft_putendl_fd.c \ 70 | ft_lstnew.c \ 71 | ft_lstdelone.c \ 72 | ft_lstdel.c \ 73 | ft_lstadd.c \ 74 | ft_lstiter.c \ 75 | ft_lstmap.c \ 76 | ft_strndup.c \ 77 | ft_capitalize.c \ 78 | ft_lst_reverse.c \ 79 | ft_realloc.c \ 80 | ft_strjoinch.c \ 81 | ft_strnchr.c \ 82 | ft_copyuntil.c \ 83 | ft_strstartswith.c \ 84 | ft_intlen.c \ 85 | ft_strendswith.c \ 86 | ft_pathjoin.c \ 87 | ft_lstaddback.c 88 | OBJ = $(FILES:%.c=%.o) 89 | 90 | all: $(NAME) 91 | 92 | # This won't run if the .o files don't exist or are not modified 93 | $(NAME): $(OBJ) 94 | ar rcs $(NAME) $(OBJ) 95 | 96 | # This won't run if the source files don't exist or are not modified 97 | $(OBJ): $(FILES) 98 | gcc $(CFLAGS) $(FILES) 99 | 100 | clean: 101 | rm -f $(OBJ) 102 | 103 | fclean: clean 104 | rm -f $(NAME) 105 | 106 | re: fclean all 107 | 108 | # I use .PHONY to make sure that gnu make will still run even if files called 109 | # clean / fclean / all and re already exist in the directory 110 | .PHONY: clean fclean all re 111 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Libft - @42Born2Code 2 | My implementation of some of the Standard C Library functions including some additional ones. 3 | 4 | ### TOC 5 | * [What is libft?](#what-is-libft) 6 | * [What's in it?](#whats-in-it) 7 | * [How does it work?](#how-does-it-work) 8 | * [How do I use the library?](#how-do-i-use-the-library) 9 | * [How do I test it? How do I test my own implementations?](#how-do-i-test-it-how-do-i-test-my-own-implementations) 10 | 1. [To test the code in this repo](#1-to-test-the-code-in-this-repo) 11 | 2. [To test your own code](#2-to-test-your-own-code) 12 | * [Example usage](#example-usage) 13 | 14 | ### What is libft? 15 | [Libft][1] is an individual project at [42][2] that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program. 16 | 17 | Disclaimer: *Reinventing the wheel is bad, 42 makes us do this just so we can have a deeper understanding of data structures and basic algorithms. At 42 we're not allowed to use some standard libraries on our projects, so we have to keep growing this library with our own functions as we go farther in the program.* 18 | 19 | ### What's in it? 20 | 21 | As you can see from the [Project instructions][1], there are 4 sections: 22 | 23 | 1. **Libc Functions:** Some of the standard C functions 24 | 2. **Additional functions:** Functions 42 deems will be useful for later projects 25 | 3. **Bonus Functions:** Functions 42 deems will be useful for linked list manipulation 26 | 4. **Personal Functions:** Functions I believe will be useful later. [Documented here][3]. 27 | 28 | Libc functions | Additional functions | Bonus Functions | Personal Functions 29 | :----------- | :-----------: | :-----------: | -----------: 30 | memset | ft_memalloc | ft_lstnew | ft_capitalize 31 | bzero | ft_memdel | ft_lstdelone | ft_countwords 32 | memcpy | ft_strnew | ft_lstdel | ft_islower 33 | memccpy | ft_strdel | ft_lstadd | ft_isupper 34 | memmove | ft_strclr | ft_lstiter | ft_strndup 35 | memchr | ft_striter | ft_lstmap | ft_lst_reverse 36 | memcmp | ft_striteri | | ft_realloc 37 | strlen | ft_strmap | | ft_strjoinch 38 | strdup | ft_strmapi | | ft_strnchr 39 | strcpy | ft_strequ | | ft_copyuntil 40 | strncpy | ft_strnequ | | ft_strstartswith 41 | strcat | ft_strsub | | ft_intlen 42 | strlcat | ft_strjoin | | ft_strendswith 43 | strchr | ft_strtrim | | ft_pathjoin 44 | strrchr | ft_strsplit | | ft_lstaddback 45 | strstr | ft_itoa | | get_next_line 46 | strnstr | ft_putchar | | ft_putnstr 47 | strcmp | ft_putstr | | ft_strreplace 48 | strncmp | ft_putendl | | ft_isemptystr 49 | atoi | ft_putnbr | | ft_strsplitall 50 | isalpha | ft_putchar_fd | | ft_countwordsall 51 | isdigit | ft_putstr_fd | | ft_freestrarr 52 | isalnum | ft_putendl_fd | | ft_strjoincl 53 | isascii | ft_putnbr_fd | | ft_strjoinchcl 54 | isprint || | ft_count2darray 55 | toupper | | | ft_strarrmax 56 | tolower | | | ft_get_parent_path 57 | 58 | 59 | Notes: 60 | 61 | - Most of the the files and function names are namespaced with an **ft** in front. It stands for Fourty Two 62 | - The project instructions require that we put all the source files in the root directory but for the sake of this Github repo, I separate them into sub folders. 63 | - I update this list almost every month with new personal functions. If you don't know what a function does, refer to the [Wiki][3], where I document all my personal functions. 64 | 65 | My code is not the best, but it passed all the 42 tests successfully. 66 | 67 | ### How does it work? 68 | 69 | The goal is to create a library called libft.a from the source files so I can later use that library from other projects at 42. 70 | 71 | To create that library, after downloading/cloning this project, **cd** into the project, copy all the files from the sub folders to the root directory and finally, call make: 72 | 73 | git clone https://github.com/R4meau/libft 74 | cd libft 75 | make copy 76 | make 77 | 78 | You should see a *libft.a* file and some object files (.o). 79 | 80 | 81 | Now to clean up (removing the .o files and the .c files from the root), call `make clean` 82 | 83 | **WARNING:** `make clean` will delete all your files from your root directory. Do not run it if you're using the `Makefile` file. This is why I added the `Makefile-sample` file. 84 | 85 | ### How do I use the library? 86 | 87 | I added an example file called **example.c**, it's using the function **ft_putstr** to print "DON'T PANIC" to the screen. 88 | 89 | If you try to compile it with gcc using `gcc example.c` you will get an *undefined symbol* error for ft_putstr. 90 | 91 | You have to tell the file where your library resides and which library it is using: 92 | 93 | `gcc example.c -L. -lft` 94 | 95 | -L takes the path to your library. `.` in this case
96 | -l takes the name of your library. This is the set of characters that come after `lib` in your library name. 97 | 98 | That's it. Now run it using `./a.out` 99 | 100 | ### How do I test it? How do I test my own implementations? 101 | 102 | To test the code we're going to be using @alelievr's [Libft Unit Test][4]. There are [some][5] [good][6] [others][7] but I'll only be covering this one. 103 | 104 | #### 1. To test the code in this repo 105 | 106 | 1. Clone this repo and cd into it, make sure it's called `libft`: 107 | 108 | git clone https://github.com/R4meau/libft 109 | cd libft/ 110 | 2. Copy all the source files to the root directory: 111 | 112 | make copy 113 | 3. Run Make so you can build the library: 114 | 115 | make 116 | 4. Go back to the root directory and download @alelievr's Libft Unit Test: 117 | 118 | cd .. 119 | git clone https://github.com/alelievr/libft-unit-test 120 | 5. Go into the test folder and run the test: 121 | 122 | cd libft-unit-test/ 123 | make f 124 | 125 | If you did everything correctly you should get a cool list of tests showing you the function names and if they passed or not. 126 | 127 | #### 2. To test your own code 128 | 129 | You might want to have a go at this project too. If you've never heard of Makefiles, don't worry, you don't have to learn about it now. So go ahead and follow those steps: 130 | 131 | 1. Create a directory for your project, make sure you call it `libft`: 132 | 133 | mkdir libft 134 | 2. Clone this repo (don't name it libft) and copy the Makefile-sample as Makefile and libft.h to your own project: 135 | 136 | git clone https://github.com/R4meau/libft r4-libft 137 | cp r4-libft/Makefile-sample libft/Makefile 138 | cp r4-libft/libft.h libft/ 139 | 3. Go to your project, [read the instructions][1] for the function you want to create, code it and uncomment it from the Makefile: 140 | 141 | cd libft 142 | vim ft_memset.c 143 | vim Makefile 144 | 145 | As an example, after creating ft_memset as your first function, you go into the Makefile, remove the `#` in front of `FILES`, remove the `\` at the end of `ft_memset` and add a `#` in front of `ft_bzero`. 146 | 147 | If it still looks complicated, **DON'T PANIC**, [just ask me][8] :) 148 | 4. Run Make so you can build the library: 149 | 150 | make 151 | 5. Go back to the root directory and download @alelievr's Libft Unit Test: 152 | 153 | cd .. 154 | git clone https://github.com/alelievr/libft-unit-test 155 | 6. Go into the test folder and run the test: 156 | 157 | cd libft-unit-test/ 158 | make f 159 | 160 | That's it! If you're having some problems, just [send me a tweet][8]. If you think your problem is due to my code or this README, [create a new issue][9]. I'll definitely check it out. 161 | 162 | ## Example usage 163 | 164 | This is a list of my projects that use Libft extensively: 165 | 166 | * [get_next_line](https://github.com/r4meau/get_next_line) 167 | * [ft_ls](https://github.com/r4meau/ft_ls) 168 | * [ft_contrast](https://github.com/R4meau/ft_contrast) 169 | * [minishell](https://github.com/R4meau/minishell) 170 | * [ft_select](https://github.com/R4meau/ft_select) 171 | 172 | ## Sponsors 173 | 174 | Sponsor 175 | 176 | Enjoy. 177 | 178 | [1]: https://github.com/R4meau/libft/blob/master/libft.en.pdf "Libft PDF" 179 | [2]: http://42.us.org "42 USA" 180 | [3]: https://github.com/R4meau/libft/wiki/Personal-Functions-Documentation 181 | [4]: https://github.com/alelievr/libft-unit-test 182 | [5]: https://github.com/yyang42/moulitest 183 | [6]: https://github.com/QuentinPerez/Maintest/tree/master/libft 184 | [7]: https://github.com/Kant1-0/libft-test 185 | [8]: https://twitter.com/r4meau 186 | [9]: https://github.com/R4meau/libft/issues 187 | -------------------------------------------------------------------------------- /additional-funcs/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 02:04:57 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 02:04:59 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static size_t get_str_len(int n) 16 | { 17 | size_t i; 18 | 19 | i = 1; 20 | while (n /= 10) 21 | i++; 22 | return (i); 23 | } 24 | 25 | char *ft_itoa(int n) 26 | { 27 | char *str; 28 | size_t str_len; 29 | unsigned int n_cpy; 30 | 31 | str_len = get_str_len(n); 32 | n_cpy = n; 33 | if (n < 0) 34 | { 35 | n_cpy = -n; 36 | str_len++; 37 | } 38 | if (!(str = ft_strnew(str_len))) 39 | return (NULL); 40 | str[--str_len] = n_cpy % 10 + '0'; 41 | while (n_cpy /= 10) 42 | str[--str_len] = n_cpy % 10 + '0'; 43 | if (n < 0) 44 | *(str + 0) = '-'; 45 | return (str); 46 | } 47 | -------------------------------------------------------------------------------- /additional-funcs/ft_memalloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memalloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/24 03:37:39 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/24 03:55:50 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memalloc(size_t size) 16 | { 17 | void *mem; 18 | 19 | mem = malloc(size); 20 | if (!mem) 21 | return (NULL); 22 | ft_bzero(mem, size); 23 | return (mem); 24 | } 25 | -------------------------------------------------------------------------------- /additional-funcs/ft_memdel.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memdel.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 20:09:07 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 20:09:08 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_memdel(void **ap) 16 | { 17 | if (!ap || !*ap) 18 | return ; 19 | free(*ap); 20 | *ap = 0; 21 | } 22 | -------------------------------------------------------------------------------- /additional-funcs/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/08/17 17:45:18 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 21:44:04 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | ft_putchar_fd(c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /additional-funcs/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 17:49:11 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 17:49:13 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar_fd(char c, int fd) 16 | { 17 | write(fd, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /additional-funcs/ft_putendl.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 22:04:25 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 22:04:26 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putendl(char const *s) 16 | { 17 | ft_putendl_fd(s, 1); 18 | } 19 | -------------------------------------------------------------------------------- /additional-funcs/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 22:26:34 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 22:26:34 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putendl_fd(char const *s, int fd) 16 | { 17 | ft_putstr_fd(ft_strjoin(s, "\n"), fd); 18 | } 19 | -------------------------------------------------------------------------------- /additional-funcs/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 22:10:39 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 22:10:40 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putnbr(int n) 16 | { 17 | ft_putnbr_fd(n, 1); 18 | } 19 | -------------------------------------------------------------------------------- /additional-funcs/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 22:18:35 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 22:18:36 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putnbr_fd(int n, int fd) 16 | { 17 | if (n < 0) 18 | { 19 | ft_putchar_fd('-', fd); 20 | n = -n; 21 | } 22 | if (n == -2147483648) 23 | { 24 | ft_putchar_fd('2', fd); 25 | n %= 1000000000; 26 | n = -n; 27 | } 28 | if (n >= 10) 29 | { 30 | ft_putnbr_fd(n / 10, fd); 31 | ft_putnbr_fd(n % 10, fd); 32 | } 33 | else 34 | ft_putchar_fd(n + '0', fd); 35 | } 36 | -------------------------------------------------------------------------------- /additional-funcs/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/08/17 17:47:31 by jrameau #+# #+# */ 9 | /* Updated: 2016/08/17 17:47:34 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char const *s) 16 | { 17 | ft_putstr_fd(s, 1); 18 | } 19 | -------------------------------------------------------------------------------- /additional-funcs/ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 22:23:42 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 22:23:43 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr_fd(char const *s, int fd) 16 | { 17 | while (s && *s) 18 | ft_putchar_fd(*s++, fd); 19 | } 20 | -------------------------------------------------------------------------------- /additional-funcs/ft_strclr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strclr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 23:07:51 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 23:07:53 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_strclr(char *s) 16 | { 17 | if (s) 18 | ft_bzero(s, ft_strlen(s)); 19 | } 20 | -------------------------------------------------------------------------------- /additional-funcs/ft_strdel.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdel.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 23:03:47 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 23:03:48 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_strdel(char **as) 16 | { 17 | if (!as || !*as) 18 | return ; 19 | free(*as); 20 | *as = 0; 21 | } 22 | -------------------------------------------------------------------------------- /additional-funcs/ft_strequ.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strequ.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 23:42:03 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 23:42:04 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strequ(char const *s1, char const *s2) 16 | { 17 | if (!s1 || !s2) 18 | return (0); 19 | return (ft_strcmp(s1, s2) ? 0 : 1); 20 | } 21 | -------------------------------------------------------------------------------- /additional-funcs/ft_striter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_striter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 23:12:58 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 23:12:59 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_striter(char *s, void (*f)(char *)) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | if (s && f) 21 | while (*(s + i)) 22 | f(s + i++); 23 | } 24 | -------------------------------------------------------------------------------- /additional-funcs/ft_striteri.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_striteri.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 23:22:13 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 23:22:15 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_striteri(char *s, void (*f)(unsigned int, char *)) 16 | { 17 | int i; 18 | 19 | i = -1; 20 | if (s && f) 21 | while (*(s + ++i)) 22 | f(i, s + i); 23 | } 24 | -------------------------------------------------------------------------------- /additional-funcs/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/27 00:08:20 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/27 00:08:21 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strjoin(char const *s1, char const *s2) 16 | { 17 | char *new_str; 18 | size_t i; 19 | size_t j; 20 | size_t s1_len; 21 | size_t s2_len; 22 | 23 | if (!s1 || !s2) 24 | return (NULL); 25 | s1_len = ft_strlen(s1); 26 | s2_len = ft_strlen(s2); 27 | new_str = ft_strnew(s1_len + s2_len); 28 | if (!new_str) 29 | return (NULL); 30 | i = -1; 31 | j = -1; 32 | while (++i < s1_len) 33 | *(new_str + i) = *(s1 + i); 34 | while (++j < s2_len) 35 | *(new_str + i++) = *(s2 + j); 36 | return (new_str); 37 | } 38 | -------------------------------------------------------------------------------- /additional-funcs/ft_strmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 23:27:07 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 23:27:08 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strmap(char const *s, char (*f)(char)) 16 | { 17 | char *new_str; 18 | int i; 19 | 20 | if (!s) 21 | return (NULL); 22 | new_str = ft_strnew(ft_strlen(s)); 23 | if (!new_str) 24 | return (NULL); 25 | i = -1; 26 | while (*(s + ++i)) 27 | *(new_str + i) = f(*(s + i)); 28 | return (new_str); 29 | } 30 | -------------------------------------------------------------------------------- /additional-funcs/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 23:39:35 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 23:39:43 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 16 | { 17 | char *new_str; 18 | int i; 19 | 20 | if (!s) 21 | return (NULL); 22 | new_str = ft_strnew(ft_strlen(s)); 23 | if (!new_str) 24 | return (NULL); 25 | i = -1; 26 | while (*(s + ++i)) 27 | *(new_str + i) = f(i, *(s + i)); 28 | return (new_str); 29 | } 30 | -------------------------------------------------------------------------------- /additional-funcs/ft_strnequ.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnequ.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 23:47:31 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 23:47:36 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strnequ(char const *s1, char const *s2, size_t n) 16 | { 17 | if (!s1 || !s2) 18 | return (0); 19 | return (ft_strncmp(s1, s2, n) ? 0 : 1); 20 | } 21 | -------------------------------------------------------------------------------- /additional-funcs/ft_strnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 22:53:09 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 22:53:10 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strnew(size_t size) 16 | { 17 | char *str; 18 | 19 | str = (char *)malloc(sizeof(char) * size + 1); 20 | if (!str) 21 | return (NULL); 22 | ft_bzero(str, size + 1); 23 | return (str); 24 | } 25 | -------------------------------------------------------------------------------- /additional-funcs/ft_strsplit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strsplit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/27 13:18:35 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/27 13:18:36 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static int get_word_len(char const *str, char c) 16 | { 17 | int i; 18 | int len; 19 | 20 | i = 0; 21 | len = 0; 22 | while (str[i] == c) 23 | i++; 24 | while (str[i] != c && str[i] != '\0') 25 | { 26 | i++; 27 | len++; 28 | } 29 | return (len); 30 | } 31 | 32 | char **ft_strsplit(char const *s, char c) 33 | { 34 | int i; 35 | int j; 36 | int k; 37 | char **str2; 38 | 39 | if (!s || !(str2 = (char **)malloc(sizeof(*str2) * 40 | (ft_countwords(s, c) + 1)))) 41 | return (NULL); 42 | i = -1; 43 | j = 0; 44 | while (++i < ft_countwords(s, c)) 45 | { 46 | k = 0; 47 | if (!(str2[i] = ft_strnew(get_word_len(&s[j], c) + 1))) 48 | str2[i] = NULL; 49 | while (s[j] == c) 50 | j++; 51 | while (s[j] != c && s[j]) 52 | str2[i][k++] = s[j++]; 53 | str2[i][k] = '\0'; 54 | } 55 | str2[i] = 0; 56 | return (str2); 57 | } 58 | -------------------------------------------------------------------------------- /additional-funcs/ft_strsub.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strsub.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/26 23:50:07 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/26 23:50:08 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strsub(char const *s, unsigned int start, size_t len) 16 | { 17 | char *new_str; 18 | size_t i; 19 | 20 | if (!s) 21 | return (NULL); 22 | new_str = ft_strnew(len); 23 | if (!new_str) 24 | return (NULL); 25 | i = 0; 26 | while (i < len) 27 | *(new_str + i++) = *(s + start++); 28 | return (new_str); 29 | } 30 | -------------------------------------------------------------------------------- /additional-funcs/ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/27 00:50:46 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/27 00:50:47 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static int has_whitespaces(char *str, int *i, size_t *j) 16 | { 17 | while (IS_SPACE(*(str + *i))) 18 | (*i)++; 19 | while (IS_SPACE(*(str + *j))) 20 | (*j)--; 21 | if (*i || *j < ft_strlen(str)) 22 | return (1); 23 | return (0); 24 | } 25 | 26 | char *ft_strtrim(char const *s) 27 | { 28 | int i; 29 | size_t j; 30 | int k; 31 | char *new_str; 32 | size_t new_size; 33 | 34 | if (!s) 35 | return (NULL); 36 | i = 0; 37 | k = 0; 38 | j = ft_strlen(s) - 1; 39 | if (!has_whitespaces((char *)s, &i, &j) || !ft_strlen(s)) 40 | return ((char *)s); 41 | new_size = (i == (int)ft_strlen(s)) ? 0 : ft_strlen(s) - (size_t)i - \ 42 | (ft_strlen(s) - j); 43 | new_str = ft_strnew(new_size + 1); 44 | if (!new_str) 45 | return (NULL); 46 | while (i <= (int)j) 47 | *(new_str + k++) = *(s + i++); 48 | return (new_str); 49 | } 50 | -------------------------------------------------------------------------------- /bonus-funcs/ft_lstadd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/29 00:01:01 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/29 00:01:03 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_lstadd(t_list **alst, t_list *new) 16 | { 17 | new->next = *alst; 18 | *alst = new; 19 | } 20 | -------------------------------------------------------------------------------- /bonus-funcs/ft_lstdel.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdel.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 23:58:22 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 23:58:27 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) 16 | { 17 | if ((*alst)->next) 18 | ft_lstdel(&(*alst)->next, del); 19 | ft_lstdelone(&(*alst), del); 20 | } 21 | -------------------------------------------------------------------------------- /bonus-funcs/ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 23:17:34 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 23:17:35 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)) 16 | { 17 | del((*alst)->content, (*alst)->content_size); 18 | free(*alst); 19 | *alst = NULL; 20 | } 21 | -------------------------------------------------------------------------------- /bonus-funcs/ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/29 00:16:06 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/29 00:16:08 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(t_list *elem)) 16 | { 17 | if (!lst) 18 | return ; 19 | if (lst->next) 20 | ft_lstiter(lst->next, f); 21 | f(lst); 22 | } 23 | -------------------------------------------------------------------------------- /bonus-funcs/ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/29 00:20:40 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/29 00:20:41 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) 16 | { 17 | t_list *new; 18 | t_list *list; 19 | 20 | if (!lst) 21 | return (NULL); 22 | list = f(lst); 23 | new = list; 24 | while (lst->next) 25 | { 26 | lst = lst->next; 27 | if (!(list->next = f(lst))) 28 | { 29 | free(list->next); 30 | return (NULL); 31 | } 32 | list = list->next; 33 | } 34 | return (new); 35 | } 36 | -------------------------------------------------------------------------------- /bonus-funcs/ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 22:49:15 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 22:49:16 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | t_list *ft_lstnew(void const *content, size_t content_size) 16 | { 17 | t_list *list; 18 | 19 | if (!(list = (t_list *)malloc(sizeof(*list)))) 20 | return (NULL); 21 | if (!content) 22 | { 23 | list->content = NULL; 24 | list->content_size = 0; 25 | } 26 | else 27 | { 28 | if (!(list->content = malloc(content_size))) 29 | return (NULL); 30 | ft_memcpy(list->content, content, content_size); 31 | list->content_size = content_size; 32 | } 33 | list->next = NULL; 34 | return (list); 35 | } 36 | -------------------------------------------------------------------------------- /example.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* example.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/10/07 14:33:37 by jrameau #+# #+# */ 9 | /* Updated: 2016/10/07 14:33:39 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int main(void) 16 | { 17 | ft_putstr("DON'T PANIC"); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /libc-funcs/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 04:34:26 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 04:34:27 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_atoi(const char *str) 16 | { 17 | int i; 18 | int num; 19 | int sign; 20 | 21 | i = 0; 22 | num = 0; 23 | sign = 1; 24 | while (*(str + i) == '\n' || 25 | *(str + i) == '\t' || 26 | *(str + i) == '\r' || 27 | *(str + i) == '\v' || 28 | *(str + i) == '\f' || 29 | *(str + i) == ' ') 30 | i++; 31 | if (*(str + i) == '-') 32 | sign = -1; 33 | if (*(str + i) == '-' || *(str + i) == '+') 34 | i++; 35 | while (*(str + i) && *(str + i) >= '0' && *(str + i) <= '9') 36 | num = num * 10 + (*(str + i++) - '0'); 37 | return (num * sign); 38 | } 39 | -------------------------------------------------------------------------------- /libc-funcs/ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/21 15:52:51 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/21 15:52:53 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_bzero(void *s, size_t n) 16 | { 17 | char *ptr; 18 | size_t i; 19 | 20 | if (!n) 21 | return ; 22 | ptr = s; 23 | i = 0; 24 | while (i < n) 25 | *(ptr + i++) = 0; 26 | } 27 | -------------------------------------------------------------------------------- /libc-funcs/ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 20:54:25 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 20:54:26 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_isalnum(int c) 16 | { 17 | return (ft_isalpha(c) || ft_isdigit(c)); 18 | } 19 | -------------------------------------------------------------------------------- /libc-funcs/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 12:39:45 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 12:39:46 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_isalpha(int c) 16 | { 17 | return (ft_islower(c) || ft_isupper(c)); 18 | } 19 | -------------------------------------------------------------------------------- /libc-funcs/ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 21:10:58 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/24 03:25:02 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_isascii(int c) 16 | { 17 | return (c >= 0 && c <= 127); 18 | } 19 | -------------------------------------------------------------------------------- /libc-funcs/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 17:00:15 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 23:43:14 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_isdigit(int c) 16 | { 17 | return (c <= '9' && c >= '0'); 18 | } 19 | -------------------------------------------------------------------------------- /libc-funcs/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 21:21:53 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 23:40:59 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_isprint(int c) 16 | { 17 | return (c >= 32 && c < 127); 18 | } 19 | -------------------------------------------------------------------------------- /libc-funcs/ft_memccpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memccpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/21 21:34:36 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/21 21:34:37 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memccpy(void *dst, const void *src, int c, size_t n) 16 | { 17 | char *ptr; 18 | size_t i; 19 | 20 | i = -1; 21 | ptr = dst; 22 | while (++i < n) 23 | { 24 | *(ptr + i) = *((unsigned char *)src + i); 25 | if (*((unsigned char *)src + i) == (unsigned char)c) 26 | return (dst + i + 1); 27 | } 28 | return (NULL); 29 | } 30 | -------------------------------------------------------------------------------- /libc-funcs/ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/22 13:54:41 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/24 17:55:42 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memchr(const void *s, int c, size_t n) 16 | { 17 | const char *sc; 18 | size_t i; 19 | 20 | sc = (const char *)s; 21 | i = -1; 22 | while (++i < n) 23 | if (*(sc + i) == (char)c) 24 | return ((void *)sc + i); 25 | return (NULL); 26 | } 27 | -------------------------------------------------------------------------------- /libc-funcs/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/22 14:18:12 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/22 14:18:14 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_memcmp(const void *s1, const void *s2, size_t n) 16 | { 17 | unsigned char *s1c; 18 | unsigned char *s2c; 19 | size_t i; 20 | 21 | i = -1; 22 | s1c = (unsigned char *)s1; 23 | s2c = (unsigned char *)s2; 24 | while (++i < n && *(s1c + i) == *(s2c + i)) 25 | ; 26 | if (i == n) 27 | return (0); 28 | return (*(s1c + i) - *(s2c + i)); 29 | } 30 | -------------------------------------------------------------------------------- /libc-funcs/ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/21 16:54:04 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/21 16:54:05 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memcpy(void *dst, const void *src, size_t n) 16 | { 17 | size_t i; 18 | char *ptr; 19 | char *ptr2; 20 | 21 | ptr = dst; 22 | ptr2 = (char *)src; 23 | i = -1; 24 | while (++i < n) 25 | *(ptr + i) = *(ptr2 + i); 26 | return (dst); 27 | } 28 | -------------------------------------------------------------------------------- /libc-funcs/ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/22 12:41:41 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/24 17:15:13 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memmove(void *dst, const void *src, size_t len) 16 | { 17 | char *srcc; 18 | char *dstc; 19 | size_t i; 20 | 21 | i = -1; 22 | srcc = (char *)src; 23 | dstc = (char *)dst; 24 | if (srcc < dstc) 25 | while ((int)(--len) >= 0) 26 | *(dstc + len) = *(srcc + len); 27 | else 28 | while (++i < len) 29 | *(dstc + i) = *(srcc + i); 30 | return (dst); 31 | } 32 | -------------------------------------------------------------------------------- /libc-funcs/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/21 13:13:13 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/21 13:13:16 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memset(void *b, int c, size_t len) 16 | { 17 | char *ptr; 18 | size_t i; 19 | 20 | ptr = b; 21 | i = 0; 22 | while (i < len) 23 | *(ptr + i++) = c; 24 | return (b); 25 | } 26 | -------------------------------------------------------------------------------- /libc-funcs/ft_strcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/22 18:07:43 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/22 18:07:44 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strcat(char *s1, const char *s2) 16 | { 17 | int i; 18 | int j; 19 | 20 | i = -1; 21 | j = (int)ft_strlen(s1); 22 | while (*(s2 + ++i)) 23 | *(s1 + j++) = *(s2 + i); 24 | *(s1 + j) = '\0'; 25 | return (s1); 26 | } 27 | -------------------------------------------------------------------------------- /libc-funcs/ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 00:41:20 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 00:41:21 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strchr(const char *s, int c) 16 | { 17 | int i; 18 | 19 | i = -1; 20 | while (++i < (int)ft_strlen(s) + 1) 21 | if (*(s + i) == (char)c) 22 | return ((char *)s + i); 23 | return (NULL); 24 | } 25 | -------------------------------------------------------------------------------- /libc-funcs/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 03:51:36 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 03:51:37 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strcmp(const char *s1, const char *s2) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (*(s1 + i) && *(s1 + i) == *(s2 + i)) 21 | i++; 22 | return (*((unsigned char *)s1 + i) - *((unsigned char *)s2 + i)); 23 | } 24 | -------------------------------------------------------------------------------- /libc-funcs/ft_strcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/22 15:25:07 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/24 02:49:18 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strcpy(char *dst, const char *src) 16 | { 17 | int i; 18 | 19 | i = -1; 20 | while (*(src + ++i)) 21 | *(dst + i) = *(src + i); 22 | *(dst + i) = '\0'; 23 | return (dst); 24 | } 25 | -------------------------------------------------------------------------------- /libc-funcs/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/22 14:52:14 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/22 14:52:15 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strdup(const char *s1) 16 | { 17 | return (ft_strndup(s1, ft_strlen(s1))); 18 | } 19 | -------------------------------------------------------------------------------- /libc-funcs/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/22 19:27:25 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/24 22:41:08 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | size_t ft_strlcat(char *dst, const char *src, size_t size) 16 | { 17 | size_t i; 18 | int j; 19 | size_t dst_len; 20 | size_t src_len; 21 | 22 | i = ft_strlen(dst); 23 | j = 0; 24 | dst_len = ft_strlen(dst); 25 | src_len = ft_strlen(src); 26 | if (size < dst_len + 1) 27 | return (src_len + size); 28 | if (size > dst_len + 1) 29 | { 30 | while (i < size - 1) 31 | *(dst + i++) = *(src + j++); 32 | *(dst + i) = '\0'; 33 | } 34 | return (dst_len + src_len); 35 | } 36 | -------------------------------------------------------------------------------- /libc-funcs/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/22 12:43:37 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/22 12:43:39 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | size_t ft_strlen(const char *s) 16 | { 17 | size_t i; 18 | 19 | i = -1; 20 | while (*(s + ++i)) 21 | ; 22 | return (i); 23 | } 24 | -------------------------------------------------------------------------------- /libc-funcs/ft_strncat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/22 18:58:25 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/24 03:16:42 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strncat(char *s1, const char *s2, size_t n) 16 | { 17 | int i; 18 | int j; 19 | 20 | i = -1; 21 | j = (int)ft_strlen(s1); 22 | while (*(s2 + ++i) && i < (int)n) 23 | *(s1 + j++) = *(s2 + i); 24 | *(s1 + j) = '\0'; 25 | return (s1); 26 | } 27 | -------------------------------------------------------------------------------- /libc-funcs/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 04:22:10 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 04:22:11 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strncmp(const char *s1, const char *s2, size_t n) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (*(s1 + i) && *(s1 + i) == *(s2 + i) && i < (int)n - 1) 21 | i++; 22 | if (n) 23 | return (*((unsigned char *)s1 + i) - *((unsigned char *)s2 + i)); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /libc-funcs/ft_strncpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/24 02:48:43 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/24 03:25:13 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strncpy(char *dst, const char *src, size_t len) 16 | { 17 | size_t i; 18 | 19 | i = -1; 20 | while (++i < len) 21 | if (*(src + i)) 22 | *(dst + i) = *(src + i); 23 | else 24 | while (i < len) 25 | *(dst + i++) = '\0'; 26 | return (dst); 27 | } 28 | -------------------------------------------------------------------------------- /libc-funcs/ft_strndup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strndup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/29 15:20:20 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/29 15:20:23 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strndup(const char *s1, size_t n) 16 | { 17 | char *tmp; 18 | 19 | if (!(tmp = ft_strnew(n))) 20 | return (NULL); 21 | ft_strncpy(tmp, s1, n); 22 | return (tmp); 23 | } 24 | -------------------------------------------------------------------------------- /libc-funcs/ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 03:19:21 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/25 02:15:51 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strnstr(const char *big, const char *little, size_t len) 16 | { 17 | size_t i; 18 | size_t j; 19 | size_t k; 20 | int found; 21 | 22 | i = -1; 23 | found = 1; 24 | if (!ft_strlen(little)) 25 | return ((char *)big); 26 | while (*(big + ++i) && i < len) 27 | { 28 | j = 0; 29 | if (*(big + i) == *(little + 0)) 30 | { 31 | k = i; 32 | found = 1; 33 | while (*(big + k) && *(little + j) && j < len && k < len) 34 | if (*(big + k++) != *(little + j++)) 35 | found = 0; 36 | if (found && !*(little + j)) 37 | return ((char *)big + i); 38 | } 39 | } 40 | return (NULL); 41 | } 42 | -------------------------------------------------------------------------------- /libc-funcs/ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/29 15:25:57 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/29 15:25:59 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strrchr(const char *s, int c) 16 | { 17 | int i; 18 | 19 | i = (int)ft_strlen(s) + 1; 20 | while (i--) 21 | if (*(s + i) == (char)c) 22 | return ((char *)s + i); 23 | return (NULL); 24 | } 25 | -------------------------------------------------------------------------------- /libc-funcs/ft_strstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 01:39:09 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 01:39:10 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strstr(const char *big, const char *little) 16 | { 17 | int i; 18 | int j; 19 | int k; 20 | int good; 21 | 22 | if (!ft_strlen(little)) 23 | return ((char *)big); 24 | i = -1; 25 | good = 0; 26 | while (*(big + ++i) && !good) 27 | { 28 | if (*(big + i) == *(little + 0)) 29 | { 30 | j = 0; 31 | k = i; 32 | good = 1; 33 | while (*(little + j)) 34 | if (*(little + j++) != *(big + k++)) 35 | good = 0; 36 | if (good) 37 | return ((char *)big + i); 38 | } 39 | } 40 | return (NULL); 41 | } 42 | -------------------------------------------------------------------------------- /libc-funcs/ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 23:44:33 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/24 03:24:45 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_tolower(int c) 16 | { 17 | if (ft_isupper(c)) 18 | return (c + 32); 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libc-funcs/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 22:57:01 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/24 03:25:25 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_toupper(int c) 16 | { 17 | if (ft_islower(c)) 18 | return (c - 32); 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libft.en.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickdotht/libft/b4be694c86b86121ca37487b82af52e38133da84/libft.en.pdf -------------------------------------------------------------------------------- /libft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/21 21:30:24 by jrameau #+# #+# */ 9 | /* Updated: 2017/07/01 16:44:48 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT_H 14 | # define LIBFT_H 15 | # include 16 | # include 17 | # include 18 | 19 | # define BUFF_SIZE 100 20 | # define MALLCHECK(x) if (!x) return (-1); 21 | # define IS_SPACE(x) (x == ' ' || x == '\t' || x == '\r' || x == '\f') 22 | 23 | void ft_putchar(char c); 24 | void ft_putstr(char const *str); 25 | void ft_putendl(char const *str); 26 | void ft_putnbr(int nbr); 27 | void ft_putchar_fd(char c, int fd); 28 | void ft_putstr_fd(char const *s, int fd); 29 | void ft_putendl_fd(char const *s, int fd); 30 | void ft_putnbr_fd(int n, int fd); 31 | 32 | char *ft_itoa(int n); 33 | int ft_atoi(const char *str); 34 | 35 | void *ft_memalloc(size_t size); 36 | void ft_memdel(void **ap); 37 | char *ft_strnew(size_t size); 38 | void ft_strdel(char **as); 39 | void ft_strclr(char *s); 40 | void ft_striter(char *s, void (*f)(char *)); 41 | void ft_striteri(char *s, void (*f)(unsigned int, char *)); 42 | char *ft_strmap(char const *s, char (*f)(char)); 43 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); 44 | 45 | int ft_strequ(char const *s1, char const *s2); 46 | int ft_strnequ(char const *s1, char const *s2, size_t n); 47 | char *ft_strsub(char const *s, unsigned int start, size_t len); 48 | char *ft_strjoin(char const *s1, char const *s2); 49 | char *ft_strtrim(char const *s); 50 | char **ft_strsplit(char const *s, char c); 51 | 52 | void *ft_memset(void *b, int c, size_t len); 53 | void ft_bzero(void *s, size_t n); 54 | void *ft_memcpy(void *dst, const void *src, size_t n); 55 | void *ft_memccpy(void *dst, const void *restrict src, 56 | int c, size_t n); 57 | void *ft_memmove(void *dst, const void *src, size_t len); 58 | void *ft_memchr(const void *s, int c, size_t n); 59 | int ft_memcmp(const void *s1, const void *s2, size_t n); 60 | 61 | size_t ft_strlen(const char *str); 62 | char *ft_strdup(const char *s1); 63 | char *ft_strndup(const char *s1, size_t n); 64 | char *ft_strcpy(char *dst, const char *src); 65 | char *ft_strncpy(char *dst, const char *src, size_t len); 66 | char *ft_strcat(char *s1, const char *s2); 67 | char *ft_strncat(char *s1, const char *s2, size_t n); 68 | size_t ft_strlcat(char *dst, const char *src, size_t size); 69 | char *ft_strchr(const char *s, int c); 70 | char *ft_strrchr(const char *s, int c); 71 | char *ft_strstr(const char *big, const char *little); 72 | char *ft_strnstr(const char *big, 73 | const char *little, size_t len); 74 | int ft_strcmp(const char *s1, const char *s2); 75 | int ft_strncmp(const char *s1, const char *s2, size_t n); 76 | 77 | int ft_isalpha(int c); 78 | int ft_isdigit(int c); 79 | int ft_isalnum(int c); 80 | int ft_isascii(int c); 81 | int ft_isprint(int c); 82 | int ft_toupper(int c); 83 | int ft_tolower(int c); 84 | 85 | # ifndef IS_SPACE 86 | # define IS_SPACE(x) (x==' '||x=='\n'||x=='\t') 87 | # endif 88 | 89 | typedef struct s_list 90 | { 91 | void *content; 92 | size_t content_size; 93 | struct s_list *next; 94 | } t_list; 95 | 96 | t_list *ft_lstnew(const void *content, size_t content_size); 97 | void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)); 98 | void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); 99 | void ft_lstadd(t_list **alst, t_list *n); 100 | void ft_lstiter(t_list *lst, void (*f)(t_list *elem)); 101 | t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); 102 | 103 | /* 104 | ** Extra functions 105 | */ 106 | 107 | int ft_isupper(int c); 108 | int ft_islower(int c); 109 | int ft_countwords(char const *str, char c); 110 | char *ft_strndup(const char *s1, size_t n); 111 | char *ft_capitalize(char *s); 112 | t_list *ft_lst_reverse(t_list *alst); 113 | void *ft_realloc(void *ptr, size_t prev_size, size_t new_size); 114 | char *ft_strjoinch(char const *s1, char c); 115 | char *ft_strnchr(char *s, char c, int offset); 116 | int ft_copyuntil(char **dst, char *src, char c); 117 | int ft_strstartswith(char *s1, char *s2); 118 | int ft_intlen(int num); 119 | int ft_strendswith(char *s1, char *s2); 120 | char *ft_pathjoin(char *p1, char *p2); 121 | void ft_lstaddback(t_list **alst, t_list *new); 122 | int get_next_line(const int fd, char **line); 123 | void ft_putnstr(char *str, int n); 124 | char *ft_strreplace(char *str, char *term, char *replace_by); 125 | int ft_isemptystr(char *str, int consider_space); 126 | char **ft_strsplitall(char const *s); 127 | int ft_countwordsall(char const *str); 128 | void ft_freestrarr(char **arr); 129 | char *ft_strjoincl(char *s1, char *s2, int free_both); 130 | char *ft_strjoinchcl(char *s1, char c); 131 | int ft_count2darray(char **arr); 132 | int ft_strarrmax(char **arr); 133 | char *ft_get_parent_path(char *path); 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /personal-funcs/ft_capitalize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_capitalize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/29 15:51:24 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/29 15:51:26 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_capitalize(char *s) 16 | { 17 | char *new; 18 | int i; 19 | 20 | if (!s) 21 | return (NULL); 22 | new = ft_strnew(ft_strlen(s)); 23 | new[0] = ft_toupper(s[0]); 24 | i = 0; 25 | while (*(s + ++i)) 26 | if (!ft_isalnum(s[i - 1]) && ft_isalnum(s[i])) 27 | new[i] = ft_toupper(s[i]); 28 | else 29 | new[i] = s[i]; 30 | return (new); 31 | } 32 | -------------------------------------------------------------------------------- /personal-funcs/ft_copyuntil.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* copyuntil.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/11/26 05:49:22 by jrameau #+# #+# */ 9 | /* Updated: 2016/11/26 05:52:26 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_copyuntil(char **dst, char *src, char c) 16 | { 17 | int i; 18 | int count; 19 | int pos; 20 | 21 | i = -1; 22 | count = 0; 23 | while (src[++i]) 24 | if (src[i] == c) 25 | break ; 26 | pos = i; 27 | if (!(*dst = ft_strnew(i))) 28 | return (0); 29 | while (src[count] && count < i) 30 | { 31 | if (!(*dst = ft_strjoinch(*dst, src[count]))) 32 | return (0); 33 | count++; 34 | } 35 | return (pos); 36 | } 37 | -------------------------------------------------------------------------------- /personal-funcs/ft_count2darray.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_count2darray.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/06/27 21:52:38 by jrameau #+# #+# */ 9 | /* Updated: 2017/07/02 17:56:03 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_count2darray(char **arr) 16 | { 17 | int i; 18 | int count; 19 | 20 | i = -1; 21 | count = 0; 22 | while (arr[++i]) 23 | count++; 24 | return (count); 25 | } 26 | -------------------------------------------------------------------------------- /personal-funcs/ft_countwords.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_countwords.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 15:17:40 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/28 15:17:41 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_countwords(char const *str, char c) 16 | { 17 | int count; 18 | int i; 19 | 20 | i = 0; 21 | count = 0; 22 | while (str[i]) 23 | { 24 | while (str[i] == c) 25 | i++; 26 | if (str[i] != c && str[i] != '\0') 27 | count++; 28 | while (str[i] != c && str[i] != '\0') 29 | i++; 30 | } 31 | return (count); 32 | } 33 | -------------------------------------------------------------------------------- /personal-funcs/ft_countwordsall.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_countwordsall.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/28 15:17:40 by jrameau #+# #+# */ 9 | /* Updated: 2017/05/11 00:23:19 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_countwordsall(char const *str) 16 | { 17 | int count; 18 | int i; 19 | 20 | i = 0; 21 | count = 0; 22 | while (str[i]) 23 | { 24 | while (IS_SPACE(str[i])) 25 | i++; 26 | if (!IS_SPACE(str[i]) && str[i] != '\0') 27 | count++; 28 | while (!IS_SPACE(str[i]) && str[i] != '\0') 29 | i++; 30 | } 31 | return (count); 32 | } 33 | -------------------------------------------------------------------------------- /personal-funcs/ft_freestrarr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_freestrarr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/05/18 16:00:12 by jrameau #+# #+# */ 9 | /* Updated: 2017/05/18 16:36:33 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_freestrarr(char **arr) 16 | { 17 | int i; 18 | 19 | if (!arr) 20 | return ; 21 | i = -1; 22 | while (arr[++i]) 23 | { 24 | free(arr[i]); 25 | } 26 | free(arr); 27 | arr = NULL; 28 | } 29 | -------------------------------------------------------------------------------- /personal-funcs/ft_get_parent_path.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_get_parent_path.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/07/01 16:43:14 by jrameau #+# #+# */ 9 | /* Updated: 2017/07/02 17:56:28 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_get_parent_path(char *path) 16 | { 17 | char *last_slash; 18 | char *parent; 19 | 20 | last_slash = strrchr(path, '/'); 21 | parent = strndup(path, last_slash - path); 22 | return (parent); 23 | } 24 | -------------------------------------------------------------------------------- /personal-funcs/ft_intlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_intlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/12/22 13:09:38 by jrameau #+# #+# */ 9 | /* Updated: 2017/04/19 22:47:25 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int higher_nums(int num) 14 | { 15 | if (num >= 10000000) 16 | { 17 | if (num >= 1000000000) 18 | return (10); 19 | if (num >= 100000000) 20 | return (9); 21 | return (8); 22 | } 23 | if (num >= 1000000) 24 | return (7); 25 | return (6); 26 | } 27 | 28 | int ft_intlen(int num) 29 | { 30 | if (num >= 100000) 31 | return (higher_nums(num)); 32 | else 33 | { 34 | if (num >= 1000) 35 | { 36 | if (num >= 10000) 37 | return (5); 38 | return (4); 39 | } 40 | else 41 | { 42 | if (num >= 100) 43 | return (3); 44 | if (num >= 10) 45 | return (2); 46 | } 47 | return (1); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /personal-funcs/ft_isemptystr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isemptystr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/05/11 00:03:25 by jrameau #+# #+# */ 9 | /* Updated: 2017/05/21 01:09:11 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isemptystr(char *str, int consider_space) 16 | { 17 | int i; 18 | int min; 19 | int max; 20 | 21 | i = -1; 22 | min = 32 + consider_space; 23 | max = 126; 24 | while (str[++i]) 25 | { 26 | if (str[i] >= min && str[i] <= max) 27 | return (0); 28 | } 29 | return (1); 30 | } 31 | -------------------------------------------------------------------------------- /personal-funcs/ft_islower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_islower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 12:45:32 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 12:45:33 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_islower(int c) 16 | { 17 | return (c <= 'z' && c >= 'a'); 18 | } 19 | -------------------------------------------------------------------------------- /personal-funcs/ft_isupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/23 12:42:09 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/23 12:42:11 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_isupper(int c) 16 | { 17 | return (c <= 'Z' && c >= 'A'); 18 | } 19 | -------------------------------------------------------------------------------- /personal-funcs/ft_lst_reverse.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lst_reverse.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/10/15 16:09:31 by jrameau #+# #+# */ 9 | /* Updated: 2016/10/15 16:09:37 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lst_reverse(t_list *alst) 16 | { 17 | t_list *prev; 18 | t_list *cur; 19 | t_list *next; 20 | 21 | prev = NULL; 22 | cur = alst; 23 | while (cur != NULL) 24 | { 25 | next = cur->next; 26 | cur->next = prev; 27 | prev = cur; 28 | cur = next; 29 | } 30 | alst = prev; 31 | return (alst); 32 | } 33 | -------------------------------------------------------------------------------- /personal-funcs/ft_lstaddback.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstaddback.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/29 00:01:01 by jrameau #+# #+# */ 9 | /* Updated: 2017/04/19 22:49:40 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstaddback(t_list **alst, t_list *new) 16 | { 17 | t_list *tmp; 18 | t_list *head; 19 | 20 | tmp = *alst; 21 | head = tmp; 22 | while (tmp->next) 23 | tmp = tmp->next; 24 | tmp->next = new; 25 | *alst = head; 26 | } 27 | -------------------------------------------------------------------------------- /personal-funcs/ft_pathjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_pathjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/04/19 22:50:00 by jrameau #+# #+# */ 9 | /* Updated: 2017/04/19 22:50:27 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_pathjoin(char *p1, char *p2) 16 | { 17 | if (!ft_strendswith(p1, "/")) 18 | return (ft_strjoin(ft_strjoinch(p1, '/'), p2)); 19 | return (ft_strjoin(p1, p2)); 20 | } 21 | -------------------------------------------------------------------------------- /personal-funcs/ft_putnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/04/29 13:50:34 by jrameau #+# #+# */ 9 | /* Updated: 2017/05/21 01:10:08 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putnstr(char *str, int n) 16 | { 17 | int i; 18 | 19 | i = -1; 20 | if (n < 0) 21 | { 22 | while (str[++i] && i < (int)ft_strlen(str) + n) 23 | ft_putchar(str[i]); 24 | } 25 | else 26 | { 27 | while (str[++i] && i < n) 28 | ft_putchar(str[i]); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /personal-funcs/ft_realloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_realloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/10/21 01:11:53 by jrameau #+# #+# */ 9 | /* Updated: 2017/05/20 21:46:33 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_realloc(void *ptr, size_t prev_size, size_t new_size) 16 | { 17 | void *new; 18 | 19 | if (!ptr) 20 | return (NULL); 21 | if (!(new = ft_memalloc(new_size))) 22 | { 23 | free(ptr); 24 | return (NULL); 25 | } 26 | ft_memcpy(new, ptr, prev_size < new_size ? prev_size : new_size); 27 | free(ptr); 28 | return (new); 29 | } 30 | -------------------------------------------------------------------------------- /personal-funcs/ft_strarrmax.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strarrmax.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/06/27 22:04:11 by jrameau #+# #+# */ 9 | /* Updated: 2017/07/02 17:56:40 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strarrmax(char **arr) 16 | { 17 | int i; 18 | int max; 19 | int curr_len; 20 | 21 | i = -1; 22 | max = 0; 23 | while (arr[++i]) 24 | { 25 | curr_len = ft_strlen(arr[i]); 26 | if (curr_len > max) 27 | max = curr_len; 28 | } 29 | return (max); 30 | } 31 | -------------------------------------------------------------------------------- /personal-funcs/ft_strendswith.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strendswith.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/01/17 20:56:49 by jrameau #+# #+# */ 9 | /* Updated: 2017/04/19 22:54:50 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strendswith(char *s1, char *s2) 16 | { 17 | int i; 18 | 19 | i = -1; 20 | while (s1[++i]) 21 | if (s1[i] == s2[0]) 22 | if (ft_strcmp(s1 + i, s2) == 0) 23 | return (1); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /personal-funcs/ft_strjoinch.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/27 00:08:20 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/27 00:08:21 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strjoinch(char const *s1, char c) 16 | { 17 | char *new_str; 18 | size_t i; 19 | size_t s1_len; 20 | 21 | if (!s1 || !c) 22 | return (NULL); 23 | s1_len = ft_strlen(s1); 24 | new_str = ft_strnew(s1_len + 1); 25 | if (!new_str) 26 | return (NULL); 27 | i = -1; 28 | while (++i < s1_len) 29 | *(new_str + i) = *(s1 + i); 30 | *(new_str + i) = c; 31 | return (new_str); 32 | } 33 | -------------------------------------------------------------------------------- /personal-funcs/ft_strjoinchcl.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoinchcl.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/05/18 19:30:53 by jrameau #+# #+# */ 9 | /* Updated: 2017/05/19 20:57:44 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strjoinchcl(char *s1, char c) 16 | { 17 | char *new; 18 | 19 | if (!(new = ft_strjoinch(s1, c))) 20 | return (NULL); 21 | free(s1); 22 | s1 = NULL; 23 | return (new); 24 | } 25 | -------------------------------------------------------------------------------- /personal-funcs/ft_strjoincl.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoincl.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/05/18 19:30:53 by jrameau #+# #+# */ 9 | /* Updated: 2017/05/19 10:59:24 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strjoincl(char *s1, char *s2, int free_both) 16 | { 17 | char *new; 18 | 19 | if (!(new = ft_strjoin(s1, s2))) 20 | return (NULL); 21 | free(s1); 22 | s1 = NULL; 23 | if (free_both) 24 | { 25 | free(s2); 26 | s2 = NULL; 27 | } 28 | return (new); 29 | } 30 | -------------------------------------------------------------------------------- /personal-funcs/ft_strnchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/11/26 05:38:48 by jrameau #+# #+# */ 9 | /* Updated: 2016/11/26 05:39:55 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strnchr(char *s, char c, int offset) 16 | { 17 | int i; 18 | 19 | i = -1; 20 | while (s[++i]) 21 | if (s[i] == c) 22 | return (s + i + offset); 23 | return (NULL); 24 | } 25 | -------------------------------------------------------------------------------- /personal-funcs/ft_strndup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strndup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/29 15:20:20 by jrameau #+# #+# */ 9 | /* Updated: 2016/09/29 15:20:23 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strndup(const char *s1, size_t n) 16 | { 17 | char *tmp; 18 | 19 | if (!(tmp = ft_strnew(n))) 20 | return (NULL); 21 | ft_strncpy(tmp, s1, n); 22 | return (tmp); 23 | } 24 | -------------------------------------------------------------------------------- /personal-funcs/ft_strreplace.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strreplace.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2017/05/09 20:14:03 by jrameau #+# #+# */ 9 | /* Updated: 2017/05/21 01:15:53 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strreplace(char *str, char *term, char *replace_by) 16 | { 17 | int i; 18 | char *new_path; 19 | int done; 20 | 21 | if (!ft_strstr(str, term)) 22 | return (NULL); 23 | new_path = ft_strnew(1); 24 | i = -1; 25 | done = 0; 26 | while (str[++i]) 27 | { 28 | if (ft_strstartswith(str + i, term) && !done) 29 | { 30 | new_path = ft_strjoincl(new_path, replace_by, 0); 31 | i += ft_strlen(term); 32 | if (!str[i]) 33 | break ; 34 | new_path = ft_strjoinchcl(new_path, str[i]); 35 | done = 1; 36 | } 37 | else 38 | new_path = ft_strjoinchcl(new_path, str[i]); 39 | } 40 | return (new_path); 41 | } 42 | -------------------------------------------------------------------------------- /personal-funcs/ft_strsplitall.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strsplitall.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/27 13:18:35 by jrameau #+# #+# */ 9 | /* Updated: 2017/05/11 00:24:28 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static int get_word_len(char const *str) 16 | { 17 | int i; 18 | int len; 19 | 20 | i = 0; 21 | len = 0; 22 | while (IS_SPACE(str[i])) 23 | i++; 24 | while (!IS_SPACE(str[i]) && str[i] != '\0') 25 | { 26 | i++; 27 | len++; 28 | } 29 | return (len); 30 | } 31 | 32 | char **ft_strsplitall(char const *s) 33 | { 34 | int i; 35 | int j; 36 | int k; 37 | char **str2; 38 | 39 | if (!s || !(str2 = (char **)malloc(sizeof(*str2) * 40 | (ft_countwordsall(s) + 1)))) 41 | return (NULL); 42 | i = -1; 43 | j = 0; 44 | while (++i < ft_countwordsall(s)) 45 | { 46 | k = 0; 47 | if (!(str2[i] = ft_strnew(get_word_len(&s[j]) + 1))) 48 | str2[i] = NULL; 49 | while (IS_SPACE(s[j])) 50 | j++; 51 | while (!IS_SPACE(s[j]) && s[j]) 52 | str2[i][k++] = s[j++]; 53 | str2[i][k] = '\0'; 54 | } 55 | str2[i] = 0; 56 | return (str2); 57 | } 58 | -------------------------------------------------------------------------------- /personal-funcs/ft_strstartswith.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strstartswith.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/12/14 17:33:27 by jrameau #+# #+# */ 9 | /* Updated: 2017/04/19 22:52:24 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strstartswith(char *s1, char *s2) 14 | { 15 | int i; 16 | 17 | i = -1; 18 | while (s2[++i]) 19 | if (s1[i] != s2[i]) 20 | return (0); 21 | return (1); 22 | } 23 | -------------------------------------------------------------------------------- /personal-funcs/get_next_line.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/29 22:52:30 by jrameau #+# #+# */ 9 | /* Updated: 2017/04/24 19:07:49 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static t_list *get_correct_file(t_list **file, int fd) 16 | { 17 | t_list *tmp; 18 | 19 | tmp = *file; 20 | while (tmp) 21 | { 22 | if ((int)tmp->content_size == fd) 23 | return (tmp); 24 | tmp = tmp->next; 25 | } 26 | tmp = ft_lstnew("\0", fd); 27 | ft_lstadd(file, tmp); 28 | tmp = *file; 29 | return (tmp); 30 | } 31 | 32 | int get_next_line(const int fd, char **line) 33 | { 34 | char buf[BUFF_SIZE + 1]; 35 | static t_list *file; 36 | int i; 37 | int ret; 38 | t_list *curr; 39 | 40 | if ((fd < 0 || line == NULL || read(fd, buf, 0) < 0)) 41 | return (-1); 42 | curr = get_correct_file(&file, fd); 43 | MALLCHECK((*line = ft_strnew(1))); 44 | while ((ret = read(fd, buf, BUFF_SIZE))) 45 | { 46 | buf[ret] = '\0'; 47 | MALLCHECK((curr->content = ft_strjoin(curr->content, buf))); 48 | if (ft_strchr(buf, '\n')) 49 | break ; 50 | } 51 | if (ret < BUFF_SIZE && !ft_strlen(curr->content)) 52 | return (0); 53 | i = ft_copyuntil(line, curr->content, '\n'); 54 | (i < (int)ft_strlen(curr->content)) 55 | ? curr->content += (i + 1) 56 | : ft_strclr(curr->content); 57 | return (1); 58 | } 59 | --------------------------------------------------------------------------------