This repository has been archived by the owner on Jun 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kilian BOTREL
committed
Jul 11, 2019
1 parent
7415c53
commit 2e2cbcb
Showing
65 changed files
with
1,901 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "libft"] | ||
path = libft | ||
url = https://github.com/kibotrel/42-Libft.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
objs | ||
a.out | ||
*.dSYM | ||
.DS_Store | ||
*.a | ||
*.o | ||
*.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Kilian | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: kibotrel <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2018/11/07 14:35:03 by kibotrel #+# #+# # | ||
# Updated: 2019/07/08 11:14:21 by kibotrel ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
# Executable's name (Can be changed) | ||
|
||
NAME = libft.a | ||
|
||
# Color codes | ||
|
||
RESET = \033[0m | ||
GREEN = \033[32m | ||
YELLOW = \033[33m | ||
|
||
# All the directories needed to know where files should be (Can be changed) | ||
|
||
OBJDIR = objs/ | ||
SRCDIR = srcs/ | ||
INCDIR = incs/ | ||
INCS = libft.h | ||
OBJSUBDIRS = control conversion display file memory string | ||
|
||
# Source files (Can be changed) | ||
|
||
SRC = display/ft_putchar.c display/ft_putchar_fd.c \ | ||
display/ft_putstr.c display/ft_putstr_fd.c \ | ||
display/ft_putnbr.c display/ft_putnbr_fd.c \ | ||
display/ft_putendl.c display/ft_putendl_fd.c \ | ||
display/ft_print_error.c \ | ||
\ | ||
control/ft_isalpha.c control/ft_isdigit.c \ | ||
control/ft_isalnum.c control/ft_isascii.c \ | ||
control/ft_isprint.c control/ft_isspace.c \ | ||
control/ft_charrcount.c control/ft_charcount.c \ | ||
control/ft_str_is_uppercase.c control/ft_str_is_lowercase.c \ | ||
control/ft_strequ.c control/ft_strnequ.c \ | ||
control/ft_strcmp.c control/ft_strncmp.c \ | ||
control/ft_strstr.c control/ft_strnstr.c \ | ||
control/ft_wordcount.c control/ft_wordlength.c \ | ||
control/ft_strlen.c control/ft_numlen.c \ | ||
control/ft_memcmp.c control/ft_isvalidname.c \ | ||
\ | ||
string/ft_strdup.c string/ft_strrev.c \ | ||
string/ft_strtrim.c string/ft_strchr.c \ | ||
string/ft_strsplit.c string/ft_strjoin.c \ | ||
string/ft_strcat.c string/ft_strncat.c \ | ||
string/ft_strcpy.c string/ft_strncpy.c \ | ||
string/ft_strsub.c \ | ||
\ | ||
conversion/ft_strupcase.c conversion/ft_strlowcase.c \ | ||
conversion/ft_toupper.c conversion/ft_tolower.c \ | ||
conversion/ft_itoa.c conversion/ft_itoa_base.c \ | ||
conversion/ft_atoi.c \ | ||
\ | ||
memory/ft_memalloc.c memory/ft_bzero.c \ | ||
memory/ft_memchr.c memory/ft_memcpy.c \ | ||
memory/ft_memccpy.c memory/ft_memmove.c \ | ||
memory/ft_memset.c memory/ft_strnew.c \ | ||
\ | ||
file/ft_get_next_line.c | ||
|
||
# Some tricks in order to get the makefile doing his job the way I want (Can't be changed) | ||
|
||
CSRC = $(addprefix $(SRCDIR), $(SRC)) | ||
COBJ = $(addprefix $(OBJDIR), $(OBJ)) | ||
HEADERS = $(foreach header, $(INCS), $(INCDIR)$(header)) | ||
SUBDIRS = $(foreach dir, $(OBJSUBDIRS), $(OBJDIR)$(dir)) | ||
INCLUDES = $(foreach include, $(INCDIR), -I./$(include)) | ||
|
||
# How files should be compiled with set flags (Can be changed) | ||
|
||
CC = gcc | ||
OBJ = $(SRC:.c=.o) | ||
CFLAGS = $(INCLUDES) -Wall -Wextra -Werror | ||
|
||
# Rule called upon 'make' | ||
|
||
all: $(SUBDIRS) $(NAME) | ||
|
||
# Tries to create all subdirectories in objs | ||
|
||
$(SUBDIRS): | ||
@mkdir -p $(SUBDIRS) | ||
|
||
# Build the library when all .c files are compiled into .o files and then indexing it | ||
|
||
$(NAME): $(OBJDIR) $(COBJ) | ||
@echo "$(YELLOW)\n - Building $(RESET)$(NAME) $(YELLOW)...\n$(RESET)" | ||
@ar rcs $(NAME) $(COBJ) | ||
@echo "$(GREEN)*** Project $(NAME) successfully compiled ***\n$(RESET)" | ||
|
||
# Tries to create objs directory | ||
|
||
$(OBJDIR): | ||
@mkdir -p $(OBJDIR) | ||
|
||
# Redefinition of implicit compilation rule to prompt some colors and file names during the said compilation | ||
|
||
$(OBJDIR)%.o: $(SRCDIR)%.c $(HEADERS) | ||
@echo "$(YELLOW) - Compiling :$(RESET)" $< | ||
@$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
# Deleting all .o files and then the directory where they were located | ||
|
||
clean: | ||
@echo "$(GREEN)*** Deleting all object from $(NAME) ... ***\n$(RESET)" | ||
@$(RM) $(COBJ) | ||
|
||
# Deleting the library after cleaning up all .o files | ||
|
||
fclean: clean | ||
@echo "$(GREEN)*** Deleting executable file from $(NAME) ... ***\n$(RESET)" | ||
@$(RM) $(NAME) | ||
|
||
# Delete all .o files then the library and rebuild the whole thing again | ||
|
||
re: fclean all | ||
|
||
.PHONY: all clean fclean re |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# 42-Libft | ||
The very first school project at 42. This repository contains most of the project **libft** and all the function that I thought useful at some point in the cursus. | ||
|
||
## Install | ||
This project works on any **macOS X** and **Debian Stretch 9.8** for sure and should everywhere else (not sure). To compile the library, simply run : | ||
``` | ||
$> make | ||
``` | ||
|
||
You'll get a static library called **libft.a** at repository's root. In order to use it afterwards you may have to include it to the compilation when you call any function of the library in another project. | ||
``` | ||
$> gcc -I./LIB_FOLDER/incs -L./LIB_FOLDER/ -lft [...] | ||
``` | ||
|
||
## Breakdown | ||
All functions in this repository is organised in different categories. | ||
|
||
Category | Number of functions | ||
:---: | :---: | ||
Display | 9 | ||
Control | 22 | ||
String manipulation | 11 | ||
Conversion | 7 | ||
Memory manipulation | 8 | ||
File manipulation | 1 | ||
Total | 57 | ||
|
||
Every function is documented in the [**wiki**](https://github.com/kibotrel/42-Libft/wiki), check it out for more informations ! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kibotrel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* libft.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: kibotrel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/11/07 14:59:01 by kibotrel #+# #+# */ | ||
/* Updated: 2019/05/01 12:06:21 by kibotrel ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef LIBFT_H | ||
# define LIBFT_H | ||
|
||
# include <string.h> | ||
|
||
/* | ||
** Useful Structures | ||
*/ | ||
|
||
typedef struct s_gnlist | ||
{ | ||
struct s_gnlist *next; | ||
struct s_gnlist *prev; | ||
int fd; | ||
char *save; | ||
} t_gnlist; | ||
|
||
/* | ||
** Useful Macros | ||
*/ | ||
|
||
# define LLMAX 9223372036854775807ull | ||
# define BUFF_SIZE 4096 | ||
|
||
/* | ||
** Display functions | ||
*/ | ||
|
||
void ft_putnbr(int nb); | ||
void ft_putchar(char c); | ||
void ft_putstr(char const *s); | ||
void ft_putendl(char const *s); | ||
void ft_putnbr_fd(int n, int fd); | ||
void ft_putchar_fd(char c, int fd); | ||
void ft_putstr_fd(char const *s, int fd); | ||
void ft_putendl_fd(char const *s, int fd); | ||
void ft_print_error(char *desc, int error); | ||
|
||
/* | ||
** Control functions | ||
*/ | ||
int ft_isalpha(int c); | ||
int ft_isdigit(int c); | ||
int ft_isalnum(int c); | ||
int ft_isascii(int c); | ||
int ft_isprint(int c); | ||
int ft_isspace(int c); | ||
int ft_str_is_lowercase(char *str); | ||
int ft_str_is_uppercase(char *str); | ||
int ft_charcount(char const *s, char c); | ||
int ft_wordcount(char const *s, char c); | ||
int ft_charrcount(char const *s, char c); | ||
int ft_strequ(char const *s1, char const *s2); | ||
int ft_strcmp(const char *s1, const char *s2); | ||
int ft_wordlength(char const *s, int i, char c); | ||
int ft_isvalidname(char *filename, char *reference); | ||
int ft_memcmp(const void *s1, const void *s2, size_t n); | ||
int ft_strncmp(const char *s1, const char *s2, size_t n); | ||
int ft_strnequ(char const *s1, char const *s2, size_t n); | ||
char *ft_strstr(const char *haystack, const char *needle); | ||
char *ft_strnstr(const char *s1, const char *s2, size_t len); | ||
size_t ft_strlen(const char *s); | ||
unsigned int ft_numlen(long nb, int base); | ||
|
||
/* | ||
** String manipulation functions | ||
*/ | ||
|
||
char *ft_strrev(char *str); | ||
char *ft_strdup(const char *s1); | ||
char *ft_strtrim(char const *s); | ||
char *ft_strchr(const char *s, int c); | ||
char *ft_strcat(char *s1, const char *s2); | ||
char **ft_strsplit(char const *s, char c); | ||
char *ft_strcpy(char *dst, const char *src); | ||
char *ft_strjoin(char const *s1, char const *s2); | ||
char *ft_strncat(char *s1, const char *s2, size_t n); | ||
char *ft_strncpy(char *dst, const char *src, size_t len); | ||
char *ft_strsub(char const *s, unsigned int start, size_t len); | ||
|
||
/* | ||
** Conversion functions | ||
*/ | ||
|
||
int ft_toupper(int c); | ||
int ft_tolower(int c); | ||
int ft_atoi(const char *str); | ||
char *ft_itoa(int n); | ||
char *ft_strupcase(char *str); | ||
char *ft_strlowcase(char *str); | ||
char *ft_itoa_base(int value, int base); | ||
|
||
/* | ||
** Memory manipulation functions | ||
*/ | ||
|
||
char *ft_strnew(size_t size); | ||
void *ft_memalloc(size_t size); | ||
void ft_bzero(void *s, size_t n); | ||
void *ft_memset(void *b, int c, size_t len); | ||
void *ft_memchr(const void *s, int c, size_t n); | ||
void *ft_memcpy(void *dst, const void *src, size_t n); | ||
void *ft_memmove(void *dst, const void *src, size_t len); | ||
void *ft_memccpy(void *dst, const void *src, int c, size_t n); | ||
|
||
/* | ||
** File manipulation functions | ||
*/ | ||
|
||
int ft_get_next_line(const int fd, char **line); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_charcount.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: kibotrel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/03/29 17:19:22 by kibotrel #+# #+# */ | ||
/* Updated: 2019/04/23 16:23:05 by kibotrel ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int ft_charcount(char *str, char c) | ||
{ | ||
int counter; | ||
|
||
counter = 0; | ||
while (str && *str) | ||
if (*str++ == c) | ||
counter++; | ||
return (counter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_charrcount.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: kibotrel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/03/29 17:20:13 by kibotrel #+# #+# */ | ||
/* Updated: 2019/04/23 16:23:10 by kibotrel ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int ft_charrcount(char *str, char c) | ||
{ | ||
int counter; | ||
|
||
counter = 0; | ||
while (str && *str) | ||
if (*str++ != c) | ||
counter++; | ||
return (counter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_isalnum.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: kibotrel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/11/08 13:24:04 by kibotrel #+# #+# */ | ||
/* Updated: 2018/11/25 14:22:29 by kibotrel ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
int ft_isalnum(int c) | ||
{ | ||
return ((ft_isalpha(c) == 1 || ft_isdigit(c) == 1) ? 1 : 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_isalpha.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: kibotrel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/11/08 12:49:03 by kibotrel #+# #+# */ | ||
/* Updated: 2018/11/25 14:35:02 by kibotrel ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int ft_isalpha(int c) | ||
{ | ||
return (((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) ? 1 : 0); | ||
} |
Oops, something went wrong.