Skip to content

Commit

Permalink
libft
Browse files Browse the repository at this point in the history
  • Loading branch information
o4eredko committed Jan 11, 2019
1 parent c92d40d commit ea40c61
Show file tree
Hide file tree
Showing 83 changed files with 3,303 additions and 2,004 deletions.
89 changes: 48 additions & 41 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: yochered <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/10/26 13:59:12 by yochered #+# #+# #
# Updated: 2018/11/30 15:03:04 by yochered ### ########.fr #
# #
# **************************************************************************** #

NAME = libft.a
SRC = 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_strdup.c ft_strcpy.c ft_strncpy.c ft_strcat.c\
ft_strncat.c ft_strlcat.c ft_strchr.c ft_strrchr.c ft_strstr.c ft_strnstr.c\
ft_strcmp.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_memalloc.c\
ft_memdel.c ft_strnew.c ft_strdel.c ft_strclr.c ft_striter.c ft_striteri.c\
ft_strmap.c ft_strmapi.c ft_strequ.c ft_strnequ.c ft_strsub.c ft_strjoin.c\
ft_strtrim.c ft_strsplit.c ft_itoa.c ft_putchar.c ft_putstr.c ft_putendl.c\
ft_putnbr.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c\
ft_lstnew.c ft_lstdelone.c ft_lstdel.c ft_lstadd.c ft_lstiter.c ft_lstmap.c\
ft_itoa_base.c ft_lstrev.c ft_cycle_detector.c ft_print_memory.c
BINARY = $(SRC:.c=.o)

all: $(NAME)

$(NAME): $(BINARY)
ar rc $(NAME) $(BINARY)

%.o: %.c
gcc -Wall -W -Werror -c -o $@ $<

clean:
/bin/rm -f $(BINARY)

fclean: clean
/bin/rm -f $(NAME)

re: fclean all
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: yochered <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/10/26 13:59:12 by yochered #+# #+# #
# Updated: 2018/12/14 10:04:18 by yochered ### ########.fr #
# #
# **************************************************************************** #

NAME = libft.a

SRC = 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_strdup.c ft_strcpy.c ft_strncpy.c ft_strcat.c\
ft_strncat.c ft_strlcat.c ft_strchr.c ft_strrchr.c ft_strstr.c ft_strnstr.c\
ft_strcmp.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_memalloc.c\
ft_memdel.c ft_strnew.c ft_strdel.c ft_strclr.c ft_striter.c ft_striteri.c\
ft_strmap.c ft_strmapi.c ft_strequ.c ft_strnequ.c ft_strsub.c ft_strjoin.c\
ft_strtrim.c ft_strsplit.c ft_count_digits.c ft_itoa.c ft_putchar.c ft_putstr.c\
ft_putendl.c ft_putnbr.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c\
ft_putnbr_fd.c ft_lstnew.c ft_lstdelone.c ft_lstdel.c ft_lstadd.c ft_lstiter.c\
ft_lstmap.c ft_itoa_base.c ft_lstrev.c ft_cycle_detector.c ft_print_memory.c\
get_next_line.c ft_printf.c $(addprefix ./printf_src/, $(PRINTF))

PRINTF = convert_to_str.c handlers.c function_array.c print_int.c\
print_pointer.c print_str.c str_functions.c mem_funcs.c allowed_symbols.c\
print_uint.c print_float.c bonus_types.c print_funcs.c

BINARY = $(SRC:.c=.o)

all: $(NAME)

$(NAME): $(BINARY)
ar rc $(NAME) $(BINARY)

%.o: %.c
gcc -Wall -W -Werror -c -o $@ $< -I ./includes/

clean:
/bin/rm -f $(BINARY)

fclean: clean
/bin/rm -f $(NAME)

re: fclean all
2 changes: 1 addition & 1 deletion author
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yochered
yochered
93 changes: 44 additions & 49 deletions ft_atoi.c
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/26 11:42:06 by yochered #+# #+# */
/* Updated: 2018/10/26 11:42:07 by yochered ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

static int ft_isspace(int c)
{
unsigned char s;

s = (unsigned char)c;
if (c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f'
|| c == '\r')
return (1);
return (0);
}

int ft_atoi(const char *str)
{
int sign;
long res;

sign = 1;
res = 0;
while (ft_isspace(*str) == 1)
str++;
if (*str == '+' || *str == '-')
{
if (*str == '-')
sign = -1;
str++;
}
while (ft_isdigit(*str) == 1)
{
if (9223372036854775807 - res < *str - 48)
return (sign == -1 ? 0 : -1);
res = res * 10 + (*str - 48);
str++;
}
return (res * sign);
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/26 11:42:06 by yochered #+# #+# */
/* Updated: 2018/10/26 11:42:07 by yochered ### ########.fr */
/* */
/* ************************************************************************** */

#include <libft.h>

static int ft_isspace(int c)
{
return (c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f'
|| c == '\r');
}

int ft_atoi(const char *str)
{
int sign;
long res;

sign = 1;
res = 0;
while (ft_isspace(*str) == 1)
str++;
if (*str == '+' || *str == '-')
{
if (*str == '-')
sign = -1;
str++;
}
while (ft_isdigit(*str) == 1)
{
if (9223372036854775807 - res < *str - 48)
return (sign == -1 ? 0 : -1);
res = res * 10 + (*str - 48);
str++;
}
return (res * sign);
}
36 changes: 18 additions & 18 deletions ft_bzero.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/25 12:30:01 by yochered #+# #+# */
/* Updated: 2018/10/25 12:30:04 by yochered ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

void ft_bzero(void *s, size_t n)
{
ft_memset(s, 0, n);
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/25 12:30:01 by yochered #+# #+# */
/* Updated: 2018/10/25 12:30:04 by yochered ### ########.fr */
/* */
/* ************************************************************************** */

#include <libft.h>

void ft_bzero(void *s, size_t n)
{
ft_memset(s, 0, n);
}
26 changes: 26 additions & 0 deletions ft_count_digits.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_count_digits.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/14 10:49:32 by yochered #+# #+# */
/* Updated: 2018/12/14 10:49:33 by yochered ### ########.fr */
/* */
/* ************************************************************************** */

int ft_count_digits(int nbr, int base)
{
int digits;

digits = 0;
if (nbr <= 0)
digits++;
while (nbr)
{
digits++;
nbr /= base;
}
return (digits);
}
72 changes: 36 additions & 36 deletions ft_cycle_detector.c
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cycle_detector.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/29 17:47:52 by yochered #+# #+# */
/* Updated: 2018/10/29 17:47:53 by yochered ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_cycle_detector(t_list *list)
{
t_list *hare;
t_list *tortoise;

if (!list)
return (1);
tortoise = list;
hare = list;
while (1)
{
tortoise = tortoise->next;
if (hare->next != NULL)
hare = hare->next->next;
else
return (0);
if (!hare || !tortoise)
return (0);
if (hare == tortoise)
return (1);
}
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cycle_detector.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/29 17:47:52 by yochered #+# #+# */
/* Updated: 2018/10/29 17:47:53 by yochered ### ########.fr */
/* */
/* ************************************************************************** */

#include <libft.h>

int ft_cycle_detector(t_list *list)
{
t_list *hare;
t_list *tortoise;

if (!list)
return (1);
tortoise = list;
hare = list;
while (1)
{
tortoise = tortoise->next;
if (hare->next != NULL)
hare = hare->next->next;
else
return (0);
if (!hare || !tortoise)
return (0);
if (hare == tortoise)
return (1);
}
}
40 changes: 20 additions & 20 deletions ft_isalnum.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/26 12:02:27 by yochered #+# #+# */
/* Updated: 2018/10/26 12:02:28 by yochered ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isalnum(int c)
{
if (ft_isalpha(c) == 1 || ft_isdigit(c) == 1)
return (1);
return (0);
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yochered <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/26 12:02:27 by yochered #+# #+# */
/* Updated: 2018/10/26 12:02:28 by yochered ### ########.fr */
/* */
/* ************************************************************************** */

#include <libft.h>

int ft_isalnum(int c)
{
if (ft_isalpha(c) == 1 || ft_isdigit(c) == 1)
return (1);
return (0);
}
Loading

0 comments on commit ea40c61

Please sign in to comment.