Skip to content

Commit

Permalink
merge libft.a with libftprintf.a
Browse files Browse the repository at this point in the history
  • Loading branch information
grcenneat committed Jun 22, 2020
1 parent 21842be commit 12841d0
Show file tree
Hide file tree
Showing 49 changed files with 1,623 additions and 0 deletions.
53 changes: 53 additions & 0 deletions ft_printf/Libft/Makefile
@@ -0,0 +1,53 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: hysimok <hysimok@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/02/28 20:00:06 by hjung #+# #+# #
# Updated: 2020/06/22 12:40:19 by hysimok ### ########.fr #
# #
# **************************************************************************** #

NAME = libft.a
SRCS = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_memmove.c ft_memchr.c ft_memcmp.c\
ft_strlen.c ft_strlcpy.c ft_strlcat.c ft_strchr.c ft_strrchr.c ft_strnstr.c ft_strncmp.c\
ft_atoi.c ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c ft_toupper.c ft_tolower.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_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr.c\

OBJS = ft_memset.o ft_bzero.o ft_memcpy.o ft_memccpy.o ft_memmove.o ft_memchr.o ft_memcmp.o\
ft_strlen.o ft_strlcpy.o ft_strlcat.o ft_strchr.o ft_strrchr.o ft_strnstr.o ft_strncmp.o\
ft_atoi.o ft_isalpha.o ft_isdigit.o ft_isalnum.o ft_isascii.o ft_isprint.o ft_toupper.o ft_tolower.o\
ft_calloc.o ft_strdup.o\
ft_substr.o ft_strjoin.o ft_strtrim.o ft_split.o ft_itoa.o ft_strmapi.o ft_putchar_fd.o ft_putstr_fd.o ft_putendl_fd.o ft_putnbr_fd.o\

B_SRCS = 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
B_OBJS = ft_lstnew.o ft_lstadd_front.o ft_lstsize.o ft_lstlast.o ft_lstadd_back.o ft_lstdelone.o ft_lstclear.o ft_lstiter.o ft_lstmap.o

CC = gcc
CFLAGS = -Wall -Wextra -Werror

RM = rm -f

.c.o:
${CC} ${CFLAGS} -c $< -o ${<:.c=.o}

all: $(NAME)

$(NAME): ${OBJS}
ar rsc $(NAME) ${OBJS}

bonus: ${OBJS} ${B_OBJS}
ar rsc $(NAME) ${OBJS} ${B_OBJS}

clean:
${RM} ${OBJS} ${B_OBJS}

fclean: clean
${RM} $(NAME)

re: fclean all

.PHONY: all clean fclean re
37 changes: 37 additions & 0 deletions ft_printf/Libft/ft_atoi.c
@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/03 18:31:33 by hjung #+# #+# */
/* Updated: 2020/03/03 18:40:32 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_atoi(const char *str)
{
int cnt_minus;
int res;

cnt_minus = 1;
res = 0;
while (*str == '\t' || *str == '\n' || *str == '\v' ||
*str == '\f' || *str == '\r' || *str == ' ')
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
cnt_minus *= (-1);
str++;
}
while (*str >= '0' && *str <= '9')
{
res = (res * 10) + (*str - '0');
str++;
}
return (res * cnt_minus);
}
28 changes: 28 additions & 0 deletions ft_printf/Libft/ft_bzero.c
@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 19:07:20 by hjung #+# #+# */
/* Updated: 2020/04/05 20:00:50 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

void ft_bzero(void *s, size_t n)
{
size_t i;

i = 0;
if (n != 0)
{
while (i < n)
{
((char *)s)[i] = '\0';
i++;
}
}
}
32 changes: 32 additions & 0 deletions ft_printf/Libft/ft_calloc.c
@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/05 15:42:35 by hjung #+# #+# */
/* Updated: 2020/04/05 20:01:25 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

void *ft_calloc(size_t count, size_t size)
{
size_t total_size;
size_t i;
unsigned char *ptr;

i = 0;
total_size = count * size;
ptr = (unsigned char *)malloc(total_size);
if (!ptr)
return (void *)(NULL);
while (i < total_size)
{
ptr[i] = '\0';
i++;
}
return (void *)(ptr);
}
20 changes: 20 additions & 0 deletions ft_printf/Libft/ft_isalnum.c
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/03 22:19:36 by hjung #+# #+# */
/* Updated: 2020/03/03 22:20:31 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isalnum(int c)
{
if (ft_isalpha(c) || ft_isdigit(c))
return (1);
return (0);
}
20 changes: 20 additions & 0 deletions ft_printf/Libft/ft_isalpha.c
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/03 18:49:16 by hjung #+# #+# */
/* Updated: 2020/03/03 22:08:59 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isalpha(int c)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return (1);
return (0);
}
20 changes: 20 additions & 0 deletions ft_printf/Libft/ft_isascii.c
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/03 22:21:32 by hjung #+# #+# */
/* Updated: 2020/03/03 22:23:26 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
return (0);
}
20 changes: 20 additions & 0 deletions ft_printf/Libft/ft_isdigit.c
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/03 22:11:12 by hjung #+# #+# */
/* Updated: 2020/03/03 22:14:29 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (1);
return (0);
}
20 changes: 20 additions & 0 deletions ft_printf/Libft/ft_isprint.c
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/03 22:26:16 by hjung #+# #+# */
/* Updated: 2020/03/03 22:27:48 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isprint(int c)
{
if (c >= 32 && c < 127)
return (1);
return (0);
}
63 changes: 63 additions & 0 deletions ft_printf/Libft/ft_itoa.c
@@ -0,0 +1,63 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/08 21:55:36 by hjung #+# #+# */
/* Updated: 2020/04/06 00:21:50 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_num_len(int n)
{
int len;

len = 0;
while (n != 0)
{
n /= 10;
len++;
}
return (len);
}

char *ft_minus(char *res, int n, int len)
{
while (n < 0)
{
res[--len] = '0' + ((n % 10) * (-1));
n /= 10;
}
res[--len] = '-';
return (res);
}

char *ft_itoa(int n)
{
char *res;
int len;

len = ft_num_len(n) + 2;
res = (char *)malloc(len);
if (!res)
return (NULL);
res[--len] = '\0';
if (n < 0)
res = ft_minus(res, n, len);
else if (n == 0)
res[--len] = '0';
else
{
res[--len] = '\0';
while (n > 0)
{
res[--len] = '0' + (n % 10);
n /= 10;
}
}
return (res);
}
28 changes: 28 additions & 0 deletions ft_printf/Libft/ft_lstadd_back.c
@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/19 13:46:34 by hjung #+# #+# */
/* Updated: 2020/04/14 21:23:18 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *pnode;

pnode = (*lst);
if (pnode == NULL)
(*lst) = new;
else
{
while (pnode->next != NULL)
pnode = pnode->next;
pnode->next = new;
}
}
19 changes: 19 additions & 0 deletions ft_printf/Libft/ft_lstadd_front.c
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hjung <hjung@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/19 11:19:45 by hjung #+# #+# */
/* Updated: 2020/03/19 11:53:56 by hjung ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

void ft_lstadd_front(t_list **lst, t_list *new)
{
new->next = *lst;
*lst = new;
}

0 comments on commit 12841d0

Please sign in to comment.