Skip to content

Commit 9a73043

Browse files
author
Loic Lord
committed
finised project
1 parent 7da5ba9 commit 9a73043

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1777
-0
lines changed

Makefile

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# **************************************************************************** #
2+
# #
3+
# ::: :::::::: #
4+
# Makefile :+: :+: :+: #
5+
# +:+ +:+ +:+ #
6+
# By: llord <llord@student.42.fr> +#+ +:+ +#+ #
7+
# +#+#+#+#+#+ +#+ #
8+
# Created: 2021/09/22 12:48:17 by llord #+# #+# #
9+
# Updated: 2022/04/23 11:28:27 by llord ### ########.fr #
10+
# #
11+
# **************************************************************************** #
12+
13+
#Standard
14+
15+
NAME = libft.a
16+
#INCLUDES = ../include
17+
SRCS_DIR = ./
18+
OBJS_DIR = obj/
19+
CC = gcc
20+
CFLAGS = -Wall -Werror -Wextra -I
21+
RM = rm -f
22+
AR = ar rc
23+
24+
#Colors
25+
26+
DEF_COLOR = \033[0;39m
27+
GRAY = \033[0;90m
28+
RED = \033[0;91m
29+
GREEN = \033[0;92m
30+
YELLOW = \033[0;93m
31+
BLUE = \033[0;94m
32+
MAGENTA = \033[0;95m
33+
CYAN = \033[0;96m
34+
WHITE = \033[0;97m
35+
36+
#Sources
37+
38+
FTFD_DIR = ft_fd/
39+
FTFD = ft_putchar_fd ft_putendl_fd ft_putnbr_fd ft_putstr_fd
40+
41+
FTIS_DIR = ft_is/
42+
FTIS = ft_isalnum ft_isalpha ft_isascii ft_isdigit ft_isprint
43+
44+
FTLST_DIR = ft_lst/
45+
FTLST = ft_lstadd_back ft_lstadd_front ft_lstclear ft_lstdelone \
46+
ft_lstiter ft_lstlast ft_lstmap ft_lstnew ft_lstsize
47+
48+
FTMEM_DIR = ft_mem/
49+
FTMEM = ft_bzero ft_calloc ft_memchr ft_memcmp ft_memcpy ft_memmove ft_memset
50+
51+
FTPUT_DIR = ft_put/
52+
FTPUT = ft_putbase ft_putnbr ft_putstr
53+
54+
FTSTR_DIR = ft_str/
55+
FTSTR = ft_split ft_strchr ft_strdup ft_striteri ft_strjoin \
56+
ft_strlcat ft_strlcpy ft_strlen ft_strmapi ft_strncmp \
57+
ft_strnstr ft_strrchr ft_strtrim ft_substr
58+
59+
FTTO_DIR = ft_to/
60+
FTTO = ft_atoi ft_itoa ft_tolower ft_toupper
61+
62+
SRC_FILES+=$(addprefix $(FTFD_DIR),$(FTFD))
63+
SRC_FILES+=$(addprefix $(FTIS_DIR),$(FTIS))
64+
SRC_FILES+=$(addprefix $(FTLST_DIR),$(FTLST))
65+
SRC_FILES+=$(addprefix $(FTMEM_DIR),$(FTMEM))
66+
SRC_FILES+=$(addprefix $(FTPUT_DIR),$(FTPUT))
67+
SRC_FILES+=$(addprefix $(FTSTR_DIR),$(FTSTR))
68+
SRC_FILES+=$(addprefix $(FTTO_DIR),$(FTTO))
69+
70+
SRCS = $(addprefix $(SRCS_DIR), $(addsuffix .c, $(SRC_FILES)))
71+
OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(SRC_FILES)))
72+
73+
###
74+
75+
OBJSF = .cache_exists
76+
77+
all: $(NAME)
78+
79+
$(NAME): $(OBJS)
80+
@$(AR) $(NAME) $(OBJS)
81+
@echo "$(GREEN)Libft compiled!$(DEF_COLOR)"
82+
83+
$(OBJS_DIR)%.o : $(SRCS_DIR)%.c | $(OBJSF)
84+
@echo "$(YELLOW)Compiling: $< $(DEF_COLOR)"
85+
@$(CC) $(CFLAGS) $(SRCS_DIR) -c $< -o $@
86+
#@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
87+
88+
$(OBJSF):
89+
@mkdir -p $(OBJS_DIR)
90+
@mkdir -p $(OBJS_DIR)$(FTFD_DIR)
91+
@mkdir -p $(OBJS_DIR)$(FTIS_DIR)
92+
@mkdir -p $(OBJS_DIR)$(FTLST_DIR)
93+
@mkdir -p $(OBJS_DIR)$(FTMEM_DIR)
94+
@mkdir -p $(OBJS_DIR)$(FTPUT_DIR)
95+
@mkdir -p $(OBJS_DIR)$(FTSTR_DIR)
96+
@mkdir -p $(OBJS_DIR)$(FTTO_DIR)
97+
98+
clean:
99+
@$(RM) -rf $(OBJS_DIR)
100+
@$(RM) -f $(OBJSF)
101+
@echo "$(BLUE)libft objects files cleaned!$(DEF_COLOR)"
102+
103+
fclean: clean
104+
@$(RM) -f $(NAME)
105+
@echo "$(CYAN)libft executable files cleaned!$(DEF_COLOR)"
106+
107+
re: fclean all
108+
@echo "$(GREEN)Cleaned and rebuilt everything for libft!$(DEF_COLOR)"
109+
110+
norm:
111+
@norminette $(SRCS) | grep -v Norme -B1 || true
112+
# @norminette $(INCLUDES) | grep -v Norme -B1 || true
113+
114+
115+
.PHONY: all clean fclean re norm

ft_fd/ft_putchar_fd.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_putchar_fd.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/01/21 11:38:41 by llord #+# #+# */
9+
/* Updated: 2022/04/07 12:12:34 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//writes a char onto a file
16+
17+
void ft_putchar_fd(char c, int fd)
18+
{
19+
write(fd, &c, 1);
20+
}

ft_fd/ft_putendl_fd.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_putendl_fd.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/01/24 21:28:54 by llord #+# #+# */
9+
/* Updated: 2022/04/07 12:12:21 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//writes a string onto a file and changes line
16+
17+
void ft_putendl_fd(char *s, int fd)
18+
{
19+
int i;
20+
21+
i = 0;
22+
while (s[i] != '\0')
23+
{
24+
write (fd, &s[i], 1);
25+
++i;
26+
}
27+
write (fd, "\n", 1);
28+
}

ft_fd/ft_putnbr_fd.c

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_putnbr_fd.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/01/24 15:05:48 by llord #+# #+# */
9+
/* Updated: 2022/04/19 14:03:16 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//writes a number onto a file
16+
17+
static char digitfinder(int number, int position)
18+
{
19+
int digit;
20+
21+
while (position > 1)
22+
{
23+
number = number / 10;
24+
--position;
25+
}
26+
digit = number % 10;
27+
return ('0' + digit);
28+
}
29+
30+
static int lenghtfinder(int number)
31+
{
32+
int lenght;
33+
34+
lenght = 0;
35+
while (number > 0)
36+
{
37+
number = number / 10;
38+
++lenght;
39+
}
40+
return (lenght);
41+
}
42+
43+
void ft_putnbr_fd(int n, int fd)
44+
{
45+
int lenght;
46+
char digit;
47+
48+
if (n == 0)
49+
write (fd, "0", 1);
50+
if (n < 0 && n != -2147483648)
51+
{
52+
n = 0 - n;
53+
write (fd, "-", 1);
54+
}
55+
if (n == -2147483648)
56+
{
57+
n += 2000000000;
58+
n = 0 - n;
59+
write (fd, "-", 1);
60+
write(fd, "2", 1);
61+
}
62+
lenght = lenghtfinder(n);
63+
while (lenght > 0)
64+
{
65+
digit = digitfinder(n, lenght);
66+
--lenght;
67+
write(fd, &digit, 1);
68+
}
69+
}

ft_fd/ft_putstr_fd.c

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_putstr_fd.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/01/24 21:28:54 by llord #+# #+# */
9+
/* Updated: 2022/04/07 12:12:00 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//writes a string onto a file
16+
17+
void ft_putstr_fd(char *s, int fd)
18+
{
19+
int i;
20+
21+
i = 0;
22+
while (s[i] != '\0')
23+
{
24+
write (fd, &s[i], 1);
25+
++i;
26+
}
27+
}

ft_is/ft_isalnum.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isalnum.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/28 13:07:44 by llord #+# #+# */
9+
/* Updated: 2022/04/07 15:44:43 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//checks is a char is alphanumeric
16+
17+
int ft_isalnum(int c)
18+
{
19+
if (('A' <= c && c <= 'Z')
20+
|| ('a' <= c && c <= 'z')
21+
|| ('0' <= c && c <= '9'))
22+
return (1);
23+
return (0);
24+
}

ft_is/ft_isalpha.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isalpha.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/28 13:07:47 by llord #+# #+# */
9+
/* Updated: 2022/04/07 15:44:52 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//checks is a char is alphabetic
16+
17+
int ft_isalpha(int c)
18+
{
19+
if ('A' <= c && c <= 'Z')
20+
return (1);
21+
if ('a' <= c && c <= 'z')
22+
return (2);
23+
return (0);
24+
}

ft_is/ft_isascii.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isascii.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/28 13:07:56 by llord #+# #+# */
9+
/* Updated: 2022/04/07 15:44:56 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//checks is a char is in the ascii set
16+
17+
int ft_isascii(int c)
18+
{
19+
if (0 <= c && c <= 127)
20+
return (1);
21+
return (0);
22+
}

ft_is/ft_isdigit.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isdigit.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/28 13:07:53 by llord #+# #+# */
9+
/* Updated: 2022/04/07 15:45:05 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//checks is a char is numeric
16+
17+
int ft_isdigit(int c)
18+
{
19+
if ('0' <= c && c <= '9')
20+
return (1);
21+
return (0);
22+
}

ft_is/ft_isprint.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isprint.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/03/28 13:07:56 by llord #+# #+# */
9+
/* Updated: 2022/04/07 15:45:08 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//checks is a char is printable
16+
17+
int ft_isprint(int c)
18+
{
19+
if (32 <= c && c <= 126)
20+
return (1);
21+
return (0);
22+
}

0 commit comments

Comments
 (0)