-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
61 changed files
with
1,792 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,80 @@ | ||
NAME = libft.a | ||
CC = gcc | ||
FLAGS = -Wall -Wextra -Werror | ||
OBJ = $(SRC:.c=.o) | ||
SRC = ft_atoi_base.c \ | ||
ft_atoi.c \ | ||
ft_bzero.c \ | ||
ft_calloc.c \ | ||
ft_convert_base.c \ | ||
ft_csplit.c \ | ||
ft_free_strs.c \ | ||
ft_isalnum.c \ | ||
ft_isalpha.c \ | ||
ft_isascii.c \ | ||
ft_ischarset.c \ | ||
ft_isdigit.c \ | ||
ft_islower.c \ | ||
ft_isprint.c \ | ||
ft_isspace.c \ | ||
ft_isupper.c \ | ||
ft_itoa_base.c \ | ||
ft_itoa.c \ | ||
ft_lstadd_back.c \ | ||
ft_lstadd_front.c \ | ||
ft_lstclear.c \ | ||
ft_lstdelone.c \ | ||
ft_lstiter.c \ | ||
ft_lstlast.c \ | ||
ft_lstmap.c \ | ||
ft_lstnew.c \ | ||
ft_lstsize.c \ | ||
ft_memccpy.c \ | ||
ft_memchr.c \ | ||
ft_memcmp.c \ | ||
ft_memcpy.c \ | ||
ft_memmove.c \ | ||
ft_memset.c \ | ||
ft_nbrlen_base.c \ | ||
ft_nbrlen.c \ | ||
ft_putchar_fd.c \ | ||
ft_putendl_fd.c \ | ||
ft_putnbr_fd.c \ | ||
ft_putstr_fd.c \ | ||
ft_split.c \ | ||
ft_strcat.c \ | ||
ft_strchr.c \ | ||
ft_strclen.c \ | ||
ft_strcmp.c \ | ||
ft_strcpy.c \ | ||
ft_strdup.c \ | ||
ft_strjoin.c \ | ||
ft_strlcat.c \ | ||
ft_strlcpy.c \ | ||
ft_strlen.c \ | ||
ft_strmapi.c \ | ||
ft_strncmp.c \ | ||
ft_strnstr.c \ | ||
ft_strrchr.c \ | ||
ft_strtrim.c \ | ||
ft_substr.c \ | ||
ft_tolower.c \ | ||
ft_toupper.c | ||
|
||
all: $(NAME) | ||
|
||
$(NAME): $(OBJ) | ||
ar rcs $@ $^ | ||
|
||
%.o: %.c | ||
$(CC) $(FLAGS) -o $@ -c $< | ||
|
||
clean: | ||
rm -rf $(OBJ) | ||
|
||
fclean: clean | ||
rm -rf $(NAME) | ||
|
||
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,29 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_atoi.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/04/15 21:13:50 by gamarcha #+# #+# */ | ||
/* Updated: 2021/04/15 21:13:50 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int ft_atoi(const char *nptr) | ||
{ | ||
int result; | ||
int sign; | ||
int i; | ||
|
||
i = 0; | ||
while (nptr[i] == ' ' || (nptr[i] >= 9 && nptr[i] <= 13)) | ||
i++; | ||
sign = 1; | ||
if (nptr[i] == '+' || nptr[i] == '-') | ||
sign *= (nptr[i++] & 2) - 1; | ||
result = 0; | ||
while (nptr[i] >= '0' && nptr[i] <= '9') | ||
result = result * 10 + nptr[i++] - 48; | ||
return (result * sign); | ||
} |
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,40 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_atoi_base.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/05/04 22:57:12 by gamarcha #+# #+# */ | ||
/* Updated: 2021/06/03 13:22:10 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
static size_t get_num(int c, const char *base) | ||
{ | ||
size_t i; | ||
|
||
i = 0; | ||
while (base[i]) | ||
if (c == base[i++]) | ||
break ; | ||
return (i - 1); | ||
} | ||
|
||
int ft_atoi_base(const char *str, const char *base, size_t len_base) | ||
{ | ||
int result; | ||
int sign; | ||
|
||
while (*str == 32 || (*str > 8 && *str < 14)) | ||
str++; | ||
sign = 1; | ||
if (*str == 43 || *str == 45) | ||
sign *= (*str++ & 2) - 1; | ||
result = 0; | ||
while (*str && ft_ischarset(*str, base)) | ||
result = result * len_base + get_num(*str++, base); | ||
return (result * sign); | ||
} |
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_bzero.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/04/15 21:14:38 by gamarcha #+# #+# */ | ||
/* Updated: 2021/04/15 21:14:38 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
void ft_bzero(void *s, size_t n) | ||
{ | ||
ft_memset(s, 0, n); | ||
} |
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,25 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_calloc.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/04/15 21:14:47 by gamarcha #+# #+# */ | ||
/* Updated: 2021/04/15 21:14:47 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
void *ft_calloc(size_t nmemb, size_t size) | ||
{ | ||
void *s; | ||
size_t n; | ||
|
||
n = nmemb * size; | ||
s = malloc(n); | ||
if (s == 0) | ||
return (0); | ||
return (ft_memset(s, 0, n)); | ||
} |
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_convert_base.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/05/04 23:12:59 by gamarcha #+# #+# */ | ||
/* Updated: 2021/06/03 13:18:35 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
char *ft_convert_base( | ||
const char *str, const char *base_from, const char *base_to) | ||
{ | ||
int nb; | ||
|
||
nb = ft_atoi_base(str, base_from, ft_strlen(base_from)); | ||
return (ft_itoa_base(nb, base_to, ft_strlen(base_to))); | ||
} |
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,66 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_csplit.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/05/04 22:26:51 by gamarcha #+# #+# */ | ||
/* Updated: 2021/06/03 13:24:39 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
static size_t count_word(const char *str, size_t len, const char *charset) | ||
{ | ||
size_t count; | ||
size_t i; | ||
|
||
count = 0; | ||
if (*str && !ft_ischarset(*str, charset)) | ||
count++; | ||
i = 0; | ||
while (++i < len) | ||
if (ft_ischarset(str[i - 1], charset) && !ft_ischarset(str[i], charset)) | ||
count++; | ||
return (count); | ||
} | ||
|
||
static char *get_word(const char **str, const char *charset) | ||
{ | ||
char *word; | ||
size_t len; | ||
|
||
while (**str && ft_ischarset(**str, charset)) | ||
(*str)++; | ||
len = ft_strclen(*str, charset); | ||
word = (char *)malloc(len + 1); | ||
if (word == 0) | ||
return (0); | ||
ft_strlcpy(word, *str, len + 1); | ||
*str += len; | ||
return (word); | ||
} | ||
|
||
char **ft_csplit(const char *str, const char *charset) | ||
{ | ||
char **strs; | ||
size_t size; | ||
size_t i; | ||
|
||
size = count_word(str, ft_strlen(str), charset); | ||
strs = (char **)malloc(sizeof(char *) * (size + 1)); | ||
if (strs == 0) | ||
return (0); | ||
i = 0; | ||
while (i < size) | ||
{ | ||
strs[i] = get_word(&str, charset); | ||
if (strs[i] == 0) | ||
return (ft_free_strs(strs, i)); | ||
i++; | ||
} | ||
strs[i] = 0; | ||
return (strs); | ||
} |
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,24 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_free_strs.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/06/02 14:40:46 by gamarcha #+# #+# */ | ||
/* Updated: 2021/06/05 18:29:12 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
void *ft_free_strs(char **strs, int size) | ||
{ | ||
int i; | ||
|
||
i = 0; | ||
while (i < size) | ||
free(strs[i++]); | ||
free(strs); | ||
return (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,18 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_isalnum.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/04/15 21:15:00 by gamarcha #+# #+# */ | ||
/* Updated: 2021/04/15 21:15:00 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
int ft_isalnum(int c) | ||
{ | ||
return (ft_isdigit(c) || ft_isalpha(c)); | ||
} |
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_isalpha.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/04/15 21:15:13 by gamarcha #+# #+# */ | ||
/* Updated: 2021/04/15 21:15:13 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
int ft_isalpha(int c) | ||
{ | ||
return (ft_islower(c) || ft_isupper(c)); | ||
} |
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_isascii.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/04/15 21:16:15 by gamarcha #+# #+# */ | ||
/* Updated: 2021/04/15 21:16:15 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int ft_isascii(int c) | ||
{ | ||
return (c >= 0 && c <= 127); | ||
} |
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,19 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_ischarset.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/06/02 12:04:22 by gamarcha #+# #+# */ | ||
/* Updated: 2021/06/02 12:04:46 by gamarcha ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int ft_ischarset(int c, const char *charset) | ||
{ | ||
while (*charset) | ||
if (c == *charset++) | ||
return (1); | ||
return (0); | ||
} |
Oops, something went wrong.