-
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
1 parent
9be7269
commit d6be919
Showing
5 changed files
with
301 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,85 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: ivanderw <marvin@42.fr> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2023/03/08 12:14:15 by ivanderw #+# #+# # | ||
# Updated: 2023/03/20 20:31:31 by ivanderw ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
FLAG = -Wextra -Werror -Wall | ||
|
||
CC = gcc | ||
|
||
NAME = libft.a | ||
|
||
source = ft_isalpha.c \ | ||
ft_isdigit.c \ | ||
ft_isalnum.c \ | ||
ft_toupper.c \ | ||
ft_tolower.c \ | ||
ft_isascii.c \ | ||
ft_memchr.c \ | ||
ft_isprint.c \ | ||
ft_strlen.c \ | ||
ft_strchr.c \ | ||
ft_strrchr.c \ | ||
ft_strncmp.c \ | ||
ft_memset.c \ | ||
ft_memmove.c \ | ||
ft_bzero.c \ | ||
ft_memcpy.c \ | ||
ft_strlcpy.c \ | ||
ft_strlcat.c \ | ||
ft_memcmp.c \ | ||
ft_strnstr.c \ | ||
ft_atoi.c \ | ||
ft_calloc.c \ | ||
ft_strdup.c \ | ||
ft_substr.c \ | ||
ft_strjoin.c \ | ||
ft_strtrim.c \ | ||
ft_split.c \ | ||
ft_itoa.c \ | ||
ft_strmapi.c \ | ||
ft_striteri.c \ | ||
ft_putchar_fd.c \ | ||
ft_putstr_fd.c \ | ||
ft_putendl_fd.c \ | ||
ft_putnbr_fd.c | ||
|
||
OBJECTS = $(source:%.c=%.o) | ||
|
||
BONUS = ft_lstnew.c \ | ||
ft_lstadd_front.c \ | ||
ft_lstsize.c \ | ||
ft_lstlast.c \ | ||
ft_lstadd_back.c \ | ||
ft_lstdelone.c \ | ||
ft_lstclear.c \ | ||
ft_lstiter.c \ | ||
ft_lstmap.c | ||
|
||
BONUS_OBJECTS = $(BONUS:%.c=%.o) | ||
|
||
all: $(NAME) | ||
|
||
%.o: %.c | ||
$(CC) $(FLAG) -o $@ -c $< | ||
|
||
$(NAME): $(OBJECTS) | ||
ar src $(NAME) $(OBJECTS) | ||
|
||
bonus: $(OBJECT) $(BONUS_OBJECTS) | ||
ar src $(NAME) $(OBJECT) $(BONUS_OBJECTS) | ||
|
||
clean: | ||
rm -f $(OBJECTS) | ||
|
||
fclean: clean | ||
rm -f $(NAME) | ||
|
||
re: fclean all |
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,64 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_substr.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/15 14:53:59 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/16 11:35:42 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
Function name: | ||
ft_substr | ||
Prototype: | ||
char *ft_substr(char const *s, unsigned int start, size_t len); | ||
Parameters | ||
s: The string from which to create the substring. | ||
start: The start index of the substring in the string ’s’. | ||
len: The maximum length of the substring. | ||
Return value: | ||
The substring. | ||
NULL if the allocation fails. | ||
External functs. | ||
malloc | ||
Description: | ||
Allocates (with malloc(3)) and returns a substring from the string ’s’. | ||
The substring begins at index ’start’ and is of maximum size ’len’ | ||
*/ | ||
#include "libft.h" | ||
|
||
char *ft_substr(const char *s, unsigned int start, size_t len) | ||
{ | ||
char *output; | ||
size_t i; | ||
size_t s_len; | ||
|
||
if (!s) | ||
return ((char *)s); | ||
s_len = ft_strlen(s); | ||
if (start > s_len) | ||
return (ft_strdup("")); | ||
if (len > s_len - start) | ||
len = s_len - start; | ||
output = (char *) malloc(len + 1); | ||
if (!(output)) | ||
return (NULL); | ||
i = 0; | ||
while (i < len) | ||
{ | ||
output[i] = s[i + start]; | ||
i++; | ||
} | ||
output[i] = '\0'; | ||
return (output); | ||
} |
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,45 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_tolower.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/06 15:38:35 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/14 17:49:39 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
SYNOPSIS | ||
#include <ctype.h> | ||
int | ||
tolower(int c); | ||
#include <ctype.h> | ||
#include <xlocale.h> | ||
int | ||
tolower_l(int c, locale_t loc); | ||
DESCRIPTION | ||
The tolower() function converts an upper-case letter to the corresponding | ||
lower-case letter. The argument must be representable as an unsigned char | ||
or the value of EOF. | ||
Although the tolower() function uses the current locale, the tolower_l() | ||
function may be passed a locale directly. See xlocale(3) for more informa- | ||
tion. | ||
RETURN VALUES | ||
If the argument is an upper-case letter, the tolower() function returns | ||
the corresponding lower-case letter if there is one; otherwise, the argu- | ||
ment is returned unchanged. | ||
*/ | ||
|
||
int ft_tolower(int c) | ||
{ | ||
if (c >= 65 && c <= 90) | ||
c = c + 32; | ||
return (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,39 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_toupper.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/06 15:31:04 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/14 17:50:24 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
SYNOPSIS | ||
#include <ctype.h> | ||
int | ||
toupper(int c); | ||
DESCRIPTION | ||
The toupper() function converts a lower-case letter to the corresponding | ||
upper-case letter. The argument must be representable as an unsigned char | ||
or the value of EOF. | ||
Although the toupper() function uses the current locale, the toupper_l() | ||
function may be passed a locale directly. See xlocale(3) for more informa- | ||
tion. | ||
RETURN VALUES | ||
If the argument is a lower-case letter, the toupper() function returns the | ||
corresponding upper-case letter if there is one; otherwise, the argument | ||
is returned unchanged. | ||
*/ | ||
|
||
int ft_toupper(int c) | ||
{ | ||
if (c >= 97 && c <= 122) | ||
c = c - 32; | ||
return (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,68 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* libft.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/07 11:36:34 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/20 20:55:09 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef LIBFT_H | ||
# define LIBFT_H | ||
# include <stdlib.h> | ||
# include <unistd.h> | ||
|
||
typedef struct s_list | ||
{ | ||
void *content; | ||
struct s_list *next; | ||
} t_list; | ||
|
||
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_toupper(int c); | ||
int ft_tolower(int c); | ||
size_t ft_strlen(const char *s); | ||
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize); | ||
char *ft_strchr(const char *s, int c); | ||
char *ft_strrchr(const char *s, int c); | ||
int ft_strncmp(const char *s1, const char *s2, size_t n); | ||
void *ft_memchr(const void *s, int c, size_t n); | ||
void *ft_memset(void *b, int c, size_t len); | ||
void ft_bzero(void *s, 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); | ||
size_t ft_strlcat(char *dst, const char *src, size_t dstsize); | ||
int ft_memcmp(const void *s1, const void *s2, size_t n); | ||
char *ft_strnstr(const char *haystack, const char *needle, size_t len); | ||
int ft_atoi(const char *str); | ||
void *ft_calloc(size_t count, size_t size); | ||
char *ft_strdup(char *src); | ||
char *ft_substr(char const *s, unsigned int start, size_t len); | ||
char *ft_strjoin(char const *s1, char const *s2); | ||
char *ft_strtrim(char const *s1, char const *set); | ||
char **ft_split(char const *s, char c); | ||
char *ft_itoa(int n); | ||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); | ||
void ft_striteri(char *s, void (*f)(unsigned int, char *)); | ||
void ft_putchar_fd(char c, int fd); | ||
void ft_putstr_fd(char *s, int fd); | ||
void ft_putendl_fd(char *s, int fd); | ||
void ft_putnbr_fd(int n, int fd); | ||
t_list *ft_lstnew(void *content); | ||
void ft_lstadd_front(t_list **lst, t_list *new); | ||
int ft_lstsize(t_list *lst); | ||
t_list *ft_lstlast(t_list *lst); | ||
void ft_lstadd_back(t_list **lst, t_list *new); | ||
void ft_lstdelone(t_list *lst, void (*del)(void *)); | ||
void ft_lstclear(t_list **lst, void (*del)(void *)); | ||
void ft_lstiter(t_list *lst, void (*f)(void *)); | ||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); | ||
|
||
#endif |