├── .gitignore ├── README.md ├── author ├── get_next_line.c ├── get_next_line.en.pdf ├── get_next_line.h ├── gnl-sample ├── get_next_line.c ├── get_next_line.h ├── m83.txt └── main.c ├── libft ├── .DS_Store ├── .gitignore ├── Makefile ├── ft_atoi.c ├── ft_bzero.c ├── ft_capitalize.c ├── ft_copyuntil.c ├── ft_countwords.c ├── ft_isalnum.c ├── ft_isalpha.c ├── ft_isascii.c ├── ft_isdigit.c ├── ft_islower.c ├── ft_isprint.c ├── ft_isupper.c ├── ft_itoa.c ├── ft_lst_reverse.c ├── ft_lstadd.c ├── ft_lstdel.c ├── ft_lstdelone.c ├── ft_lstiter.c ├── ft_lstmap.c ├── ft_lstnew.c ├── ft_memalloc.c ├── ft_memccpy.c ├── ft_memchr.c ├── ft_memcmp.c ├── ft_memcpy.c ├── ft_memdel.c ├── ft_memmove.c ├── ft_memset.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_realloc.c ├── ft_strcat.c ├── ft_strchr.c ├── ft_strclr.c ├── ft_strcmp.c ├── ft_strcpy.c ├── ft_strdel.c ├── ft_strdup.c ├── ft_strequ.c ├── ft_striter.c ├── ft_striteri.c ├── ft_strjoin.c ├── ft_strjoinch.c ├── ft_strlcat.c ├── ft_strlen.c ├── ft_strmap.c ├── ft_strmapi.c ├── ft_strncat.c ├── ft_strnchr.c ├── ft_strncmp.c ├── ft_strncpy.c ├── ft_strndup.c ├── ft_strnequ.c ├── ft_strnew.c ├── ft_strnstr.c ├── ft_strrchr.c ├── ft_strsplit.c ├── ft_strstr.c ├── ft_strsub.c ├── ft_strtrim.c ├── ft_tolower.c ├── ft_toupper.c ├── includes │ └── libft.h └── search_and_replace.c ├── m83.txt └── main.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | a.out* 3 | *.a 4 | ._* 5 | gnl 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # get_next_line - @42Born2Code 2 | 3 | A C function that reads any valid file line by line until the end. 4 | 5 | ### TOC 6 | * [What is get_next_line?](#what-is-get_next_line) 7 | * [Why would I use/try it?](#why-would-i-usetry-it) 8 | * [How do I use it?](#how-do-i-use-it) 9 | * [How do I try it out?](#how-do-i-try-it-out) 10 | * [How do I test my own code?](#how-do-i-test-my-own-code) 11 | 12 | ### What is get_next_line? 13 | 14 | [get_next_line][1] is an individual project at [42][2] that basically reads a file line by line. 15 | 16 | Disclaimer: *There [are][10] [so][11] [many][12] [easier][13] methods of doing this by using standard C functions. But the goal here is to be able to do it by using any functions from my [libft][14] and only the standard functions `read`, `malloc` and `free`.* 17 | 18 | ### Why would I use/try it? 19 | 20 | You probably will never have to use this function if you are not a 42 student. The goal is to get better at C. As I said above, you can only use those three standard library functions: 21 | 22 | * read 23 | * malloc 24 | * free 25 | 26 | So it makes the project harder. But you can also use functions from your [personal library][14]. 27 | 28 | After finishing this project, you'll definitely learn some more about static variables, pointers, arrays, linked lists (if you decide to do the bonus part), dynamic memory allocation and file manipulation. 29 | 30 | My code is not the best, but it passed all the 42 tests successfully. 31 | 32 | ### How do I use it? 33 | 34 | I added a main file called **main.c**, it takes a file name as an argument, opens it and passes the file descriptor (fd) to get_next_line until get_next_line returns -1 or 0. 35 | 36 | **Note:** get_next_line returns -1, 0, 1 depending on wether an error has occurred, the reading has been completed or a line has been read respectively. 37 | 38 | Alright, so first of all, download/clone this repo: 39 | 40 | git clone https://github.com/r4meau/get_next_line 41 | 42 | Get into it and build the library: 43 | 44 | cd get_next_line 45 | make -C libft/ 46 | 47 | Give it some time to compile all the files. 48 | 49 | Build the executable: 50 | 51 | gcc -Wall -Wextra -Werror -I./libft/includes/ -L./libft -lft -o gnl get_next_line.c main.c 52 | 53 | -I tells the compiler where your library header files are. `./libft/includes/` in this case 54 | 55 | -L tells it where your library resides. `./libft` here 56 | 57 | -l takes the name of your library. This is the set of characters that come after `lib` in your library name. 58 | 59 | **NOTE:** -L and -l might look a little bit too much, you could replace those flags with `libft/libft.a` if you want. 60 | 61 | Alright, the last command created a `gnl` executable in your directory. Now test it with: 62 | 63 | ./gnl m83.txt 64 | 65 | It should read the whole file to you. Kinda like a basic `cat` implementation. 66 | 67 | **NOTE:** The lyrics in the text file are from [Claudia Lewis][15] by [M83][16] ;) 68 | 69 | ### How do I try it out? 70 | 71 | If you are a beginner to intermediate programmer and want to hone your skills in C, I highly recommend you to give this project a try. 72 | 73 | To do that, you just have to read the [project instructions][1], some stuffs on there might be confusing if you are not a 42 student, but don't mind them. Just make sure you use only `read`, `malloc`, `free` as your only available standard library functions and my/your [libft][14] functions. 74 | 75 | I created a folder named `gnl-sample` for you, it has the required files plus the testing files. 76 | 77 | All you need to do now is cd into it and clone my [Libft][14], if you already made your own Libft, perfect, use it: 78 | 79 | cd gnl-sample 80 | git clone https://github.com/r4meau/libft 81 | 82 | Build the libft library and you're done: 83 | 84 | make -C libft/ copy 85 | make -C libft/ 86 | make -C libft/ clean 87 | 88 | **NOTE:** Just a reminder, in my Libft repo, the header file `libft.h` is in the `libft/` directory, not `libft/includes/`, so when you build your project, use this instead: 89 | 90 | gcc -Wall -Wextra -Werror -I./libft/ -L./libft -lft -o gnl get_next_line.c main.c 91 | 92 | The instructions are clear enough, so I won't add anything else. If you have any questions, feel free to [ask me][8]. 93 | 94 | #### How do I test my own code? 95 | 96 | You can do as [above](#how-do-i-use-it) and use the main file I added, just make sure you use your own `get_next_line.c` file. This is a pretty rudimentary test, if you want to try some deep tests, let me introduce you to the amazing [42FileChecker][17] by [@jgigault][18]. 97 | 98 | Assuming you read the project instructions and coded your own get_next_line 99 | 100 | 1. Go back to the root directory and download @jgigault's 42FileChecker: 101 | 102 | cd .. 103 | git clone https://github.com/jgigault/42FileChecker 104 | 105 | 2. Go into the test folder and run the test: 106 | 107 | cd 42FileChecker 108 | sh 42FileChecker.sh 109 | 110 | At the time of writing, @jgigault is looking for a maintainer for 42FC, so he displays a message on startup, dismiss it with `1` or contact him if you think you can help. 111 | 112 | Then press `5` to select tests for get_next_line, press `1` to install [moulitest][5] as an external repo, then `1` to configure the tests, now you handle the path to your get_next_line and then choose which test to run on your project. 113 | 114 | 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. 115 | 116 | ## Sponsors 117 | 118 | Sponsor 119 | 120 | Enjoy. 121 | 122 | [1]: https://github.com/R4meau/get_next_line/blob/master/get_next_line.en.pdf "get_next_line PDF" 123 | [2]: http://42.us.org "42 USA" 124 | [5]: https://github.com/yyang42/moulitest 125 | [8]: https://twitter.com/r4meau 126 | [9]: https://github.com/R4meau/get_next_line/issues 127 | [10]: http://stackoverflow.com/questions/3501338/c-read-file-line-by-line 128 | [11]: http://stackoverflow.com/questions/2372813/reading-one-line-at-a-time-in-c 129 | [12]: http://stackoverflow.com/questions/9206091/going-through-a-text-file-line-by-line-in-c 130 | [13]: https://linux.die.net/man/3/getline 131 | [14]: https://github.com/R4meau/libft 132 | [15]: https://www.youtube.com/watch?v=ZdGLsMfJMy0 133 | [16]: http://ilovem83.com/ 134 | [17]: https://github.com/jgigault/42FileChecker 135 | [18]: https://github.com/jgigault 136 | -------------------------------------------------------------------------------- /author: -------------------------------------------------------------------------------- 1 | jrameau 2 | -------------------------------------------------------------------------------- /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: 2016/12/06 02:53:47 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line.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 | -------------------------------------------------------------------------------- /get_next_line.en.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickdotht/get_next_line/fa12546d64554160524ee10b674adaefd0cd4bdb/get_next_line.en.pdf -------------------------------------------------------------------------------- /get_next_line.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/09/29 22:52:40 by jrameau #+# #+# */ 9 | /* Updated: 2016/11/19 12:27:23 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef GET_NEXT_LINE_H 14 | # define GET_NEXT_LINE_H 15 | # include 16 | # include 17 | # include 18 | 19 | # define BUFF_SIZE 42 20 | 21 | # define MALLCHECK(x) if (!x) return (-1); 22 | 23 | int get_next_line(const int fd, char **line); 24 | #endif 25 | -------------------------------------------------------------------------------- /gnl-sample/get_next_line.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickdotht/get_next_line/fa12546d64554160524ee10b674adaefd0cd4bdb/gnl-sample/get_next_line.c -------------------------------------------------------------------------------- /gnl-sample/get_next_line.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickdotht/get_next_line/fa12546d64554160524ee10b674adaefd0cd4bdb/gnl-sample/get_next_line.h -------------------------------------------------------------------------------- /gnl-sample/m83.txt: -------------------------------------------------------------------------------- 1 | Alone, twenty million years from my place. 2 | A slide, on the starlight. 3 | Watch out, a new planet right on my trail! 4 | 5 | 6 | The space, oh oh it's mine! 7 | Oh oh! 8 | 9 | -------------------------------------------------------------------------------- /gnl-sample/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/12/06 05:26:42 by jrameau #+# #+# */ 9 | /* Updated: 2016/12/07 04:14:14 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line.h" 14 | #include 15 | 16 | int main(int argc, char **argv) 17 | { 18 | int fd; 19 | char *line; 20 | 21 | if (argc == 1) 22 | fd = 0; 23 | else if (argc == 2) 24 | fd = open(argv[1], O_RDONLY); 25 | else 26 | return (2); 27 | while (get_next_line(fd, &line) == 1) 28 | { 29 | ft_putendl(line); 30 | free(line); 31 | } 32 | if (argc == 2) 33 | close(fd); 34 | } 35 | -------------------------------------------------------------------------------- /libft/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickdotht/get_next_line/fa12546d64554160524ee10b674adaefd0cd4bdb/libft/.DS_Store -------------------------------------------------------------------------------- /libft/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickdotht/get_next_line/fa12546d64554160524ee10b674adaefd0cd4bdb/libft/.gitignore -------------------------------------------------------------------------------- /libft/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: jrameau +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2016/09/21 14:58:27 by jrameau #+# #+# # 9 | # Updated: 2016/09/25 19:32:38 by jrameau ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = libft.a 14 | CFLAGS = -Wall -Werror -Wextra -Iincludes -c 15 | FILES = $(shell ls | grep -E "ft_.+\.c") 16 | OBJ = $(FILES:%.c=%.o) 17 | 18 | all: $(NAME) 19 | 20 | # This won't run if the .o files don't exist or are not modified 21 | $(NAME): $(OBJ) 22 | @ar rcs $(NAME) $(OBJ) 23 | 24 | # This won't run if the source files don't exist or are not modified 25 | $(OBJ): $(FILES) 26 | @gcc $(CFLAGS) $(FILES) 27 | 28 | clean: 29 | @rm -f $(OBJ) 30 | 31 | fclean: clean 32 | @rm -f $(NAME) 33 | 34 | re: fclean all 35 | 36 | # I use .PHONY to make sure that gnu make will still run even if files called 37 | # clean / fclean / all and re already exist in the directory 38 | .PHONY: clean fclean all re 39 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | int ft_isalnum(int c) 16 | { 17 | return (ft_isalpha(c) || ft_isdigit(c)); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | int ft_isalpha(int c) 16 | { 17 | return (ft_islower(c) || ft_isupper(c)); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | int ft_isascii(int c) 16 | { 17 | return (c >= 0 && c <= 127); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | int ft_isdigit(int c) 16 | { 17 | return (c <= '9' && c >= '0'); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | int ft_islower(int c) 16 | { 17 | return (c <= 'z' && c >= 'a'); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | int ft_isprint(int c) 16 | { 17 | return (c >= 32 && c < 127); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | int ft_isupper(int c) 16 | { 17 | return (c <= 'Z' && c >= 'A'); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_lstadd(t_list **alst, t_list *new) 16 | { 17 | new->next = *alst; 18 | *alst = new; 19 | } 20 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_memdel(void **ap) 16 | { 17 | if (!ap || !*ap) 18 | return ; 19 | free(*ap); 20 | *ap = 0; 21 | } 22 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_putchar(char c) 16 | { 17 | ft_putchar_fd(c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_putchar_fd(char c, int fd) 16 | { 17 | write(fd, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_putendl(char const *s) 16 | { 17 | ft_putendl_fd(s, 1); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_putendl_fd(char const *s, int fd) 16 | { 17 | ft_putstr_fd(ft_strjoin(s, "\n"), fd); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_putnbr(int n) 16 | { 17 | ft_putnbr_fd(n, 1); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_putstr(char const *s) 16 | { 17 | ft_putstr_fd(s, 1); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_putstr_fd(char const *s, int fd) 16 | { 17 | while (s && *s) 18 | ft_putchar_fd(*s++, fd); 19 | } 20 | -------------------------------------------------------------------------------- /libft/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: 2016/10/21 01:11:56 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_realloc(void *ptr, size_t size) 16 | { 17 | void *new_ptr; 18 | 19 | if (!ptr || !size) 20 | return (NULL); 21 | if (!(new_ptr = ft_strnew(size))) 22 | return (NULL); 23 | ft_strcpy(new_ptr, ptr); 24 | return (new_ptr); 25 | } 26 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_strclr(char *s) 16 | { 17 | if (s) 18 | ft_bzero(s, ft_strlen(s)); 19 | } 20 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | void ft_strdel(char **as) 16 | { 17 | if (!as || !*as) 18 | return ; 19 | free(*as); 20 | *as = 0; 21 | } 22 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | char *ft_strdup(const char *s1) 16 | { 17 | return (ft_strndup(s1, ft_strlen(s1))); 18 | } 19 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 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 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | int ft_tolower(int c) 16 | { 17 | if (ft_isupper(c)) 18 | return (c + 32); 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libft/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 "libft.h" 14 | 15 | int ft_toupper(int c) 16 | { 17 | if (ft_islower(c)) 18 | return (c - 32); 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libft/includes/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: 2016/09/24 04:12:58 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT_H 14 | # define LIBFT_H 15 | # include 16 | # include 17 | # include 18 | 19 | void ft_putchar(char c); 20 | void ft_putstr(char const *str); 21 | void ft_putendl(char const *str); 22 | void ft_putnbr(int nbr); 23 | void ft_putchar_fd(char c, int fd); 24 | void ft_putstr_fd(char const *s, int fd); 25 | void ft_putendl_fd(char const *s, int fd); 26 | void ft_putnbr_fd(int n, int fd); 27 | 28 | char *ft_itoa(int n); 29 | int ft_atoi(const char *str); 30 | 31 | void *ft_memalloc(size_t size); 32 | void ft_memdel(void **ap); 33 | char *ft_strnew(size_t size); 34 | void ft_strdel(char **as); 35 | void ft_strclr(char *s); 36 | void ft_striter(char *s, void (*f)(char *)); 37 | void ft_striteri(char *s, void (*f)(unsigned int, char *)); 38 | char *ft_strmap(char const *s, char (*f)(char)); 39 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); 40 | 41 | int ft_strequ(char const *s1, char const *s2); 42 | int ft_strnequ(char const *s1, char const *s2, size_t n); 43 | char *ft_strsub(char const *s, unsigned int start, size_t len); 44 | char *ft_strjoin(char const *s1, char const *s2); 45 | char *ft_strtrim(char const *s); 46 | char **ft_strsplit(char const *s, char c); 47 | 48 | void *ft_memset(void *b, int c, size_t len); 49 | void ft_bzero(void *s, size_t n); 50 | void *ft_memcpy(void *dst, const void *src, size_t n); 51 | void *ft_memccpy(void *dst, const void *restrict src, 52 | int c, size_t n); 53 | void *ft_memmove(void *dst, const void *src, size_t len); 54 | void *ft_memchr(const void *s, int c, size_t n); 55 | int ft_memcmp(const void *s1, const void *s2, size_t n); 56 | 57 | size_t ft_strlen(const char *str); 58 | char *ft_strdup(const char *s1); 59 | char *ft_strndup(const char *s1, size_t n); 60 | char *ft_strcpy(char *dst, const char *src); 61 | char *ft_strncpy(char *dst, const char *src, size_t len); 62 | char *ft_strcat(char *s1, const char *s2); 63 | char *ft_strncat(char *s1, const char *s2, size_t n); 64 | size_t ft_strlcat(char *dst, const char *src, size_t size); 65 | char *ft_strchr(const char *s, int c); 66 | char *ft_strrchr(const char *s, int c); 67 | char *ft_strstr(const char *big, const char *little); 68 | char *ft_strnstr(const char *big, 69 | const char *little, size_t len); 70 | int ft_strcmp(const char *s1, const char *s2); 71 | int ft_strncmp(const char *s1, const char *s2, size_t n); 72 | 73 | int ft_isalpha(int c); 74 | int ft_isdigit(int c); 75 | int ft_isalnum(int c); 76 | int ft_isascii(int c); 77 | int ft_isprint(int c); 78 | int ft_toupper(int c); 79 | int ft_tolower(int c); 80 | 81 | # ifndef IS_SPACE 82 | # define IS_SPACE(x) (x==' '||x=='\n'||x=='\t') 83 | # endif 84 | 85 | typedef struct s_list 86 | { 87 | void *content; 88 | size_t content_size; 89 | struct s_list *next; 90 | } t_list; 91 | 92 | t_list *ft_lstnew(const void *content, size_t content_size); 93 | void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)); 94 | void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); 95 | void ft_lstadd(t_list **alst, t_list *n); 96 | void ft_lstiter(t_list *lst, void (*f)(t_list *elem)); 97 | t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); 98 | 99 | /* 100 | ** Extra functions 101 | */ 102 | 103 | int ft_isupper(int c); 104 | int ft_islower(int c); 105 | int ft_countwords(char const *str, char c); 106 | char *ft_strndup(const char *s1, size_t n); 107 | char *ft_capitalize(char *s); 108 | t_list *ft_lst_reverse(t_list *alst); 109 | void *ft_realloc(void *ptr, size_t size); 110 | char *ft_strjoinch(char const *s1, char c); 111 | char *ft_strnchr(char *s, char c, int offset); 112 | int ft_copyuntil(char **dst, char *src, char c); 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /libft/search_and_replace.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* search_and_replace.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/10/03 17:01:45 by jrameau #+# #+# */ 9 | /* Updated: 2016/10/03 17:36:39 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strlen(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (*(str++)) 21 | i++; 22 | return (i); 23 | } 24 | 25 | int main(int ac, char **av) 26 | { 27 | char *str; 28 | char c1; 29 | char c2; 30 | char *s1; 31 | 32 | if (ac != 4 || ft_strlen(av[2]) != 1 || ft_strlen(av[3]) != 1) 33 | { 34 | write(1, "\n", 1); 35 | return (0); 36 | } 37 | str = av[1]; 38 | c1 = av[2][0]; 39 | c2 = av[3][0]; 40 | s1 = str; 41 | while (*s1) 42 | { 43 | if (*s1 == c1) 44 | *s1 = c2; 45 | s1++; 46 | } 47 | while (*(str)) 48 | write(1, str++, 1); 49 | write(1, "\n", 1); 50 | return (0); 51 | } 52 | -------------------------------------------------------------------------------- /m83.txt: -------------------------------------------------------------------------------- 1 | Alone, twenty million years from my place. 2 | A slide, on the starlight. 3 | Watch out, a new planet right on my trail! 4 | 5 | 6 | The space, oh oh it's mine! 7 | Oh oh! 8 | 9 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jrameau +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2016/12/06 05:26:42 by jrameau #+# #+# */ 9 | /* Updated: 2016/12/07 04:14:14 by jrameau ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line.h" 14 | #include 15 | 16 | int main(int argc, char **argv) 17 | { 18 | int fd; 19 | char *line; 20 | 21 | if (argc == 1) 22 | fd = 0; 23 | else if (argc == 2) 24 | fd = open(argv[1], O_RDONLY); 25 | else 26 | return (2); 27 | while (get_next_line(fd, &line) == 1) 28 | { 29 | ft_putendl(line); 30 | free(line); 31 | } 32 | if (argc == 2) 33 | close(fd); 34 | } 35 | --------------------------------------------------------------------------------