push
This commit is contained in:
124
libft/Makefile
Normal file
124
libft/Makefile
Normal file
@@ -0,0 +1,124 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2018/11/14 20:22:58 by jfleury #+# #+# #
|
||||
# Updated: 2019/07/17 11:13:16 by jfleury ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = libft.a
|
||||
AR = ar rc
|
||||
CC = gcc
|
||||
RL = ranlib
|
||||
RM = rm -f
|
||||
INCLUDE = -I ./include
|
||||
CFLAGS = -Wall -Werror -Wextra -c $(INCLUDE)
|
||||
|
||||
SRC_LIBFT = libft/ft_memset.c \
|
||||
libft/ft_bzero.c \
|
||||
libft/ft_memcpy.c \
|
||||
libft/ft_memccpy.c \
|
||||
libft/ft_memmove.c \
|
||||
libft/ft_memchr.c \
|
||||
libft/ft_memcmp.c \
|
||||
libft/ft_strlen.c \
|
||||
libft/ft_strcmp.c \
|
||||
libft/ft_strdup.c \
|
||||
libft/ft_strcpy.c \
|
||||
libft/ft_strncpy.c \
|
||||
libft/ft_strcat.c \
|
||||
libft/ft_strncat.c \
|
||||
libft/ft_strlcat.c \
|
||||
libft/ft_strchr.c \
|
||||
libft/ft_strrchr.c \
|
||||
libft/ft_atoi.c \
|
||||
libft/ft_atoi_bin.c \
|
||||
libft/ft_atoi_long.c \
|
||||
libft/ft_isalpha.c \
|
||||
libft/ft_isdigit.c \
|
||||
libft/ft_isalnum.c \
|
||||
libft/ft_strstr.c \
|
||||
libft/ft_strnstr.c \
|
||||
libft/ft_strncmp.c \
|
||||
libft/ft_strnequ.c \
|
||||
libft/ft_isascii.c \
|
||||
libft/ft_isprint.c \
|
||||
libft/ft_toupper.c \
|
||||
libft/ft_tolower.c \
|
||||
libft/ft_memalloc.c \
|
||||
libft/ft_memdel.c \
|
||||
libft/ft_strnew.c \
|
||||
libft/ft_strdel.c \
|
||||
libft/ft_strclr.c \
|
||||
libft/ft_striter.c \
|
||||
libft/ft_striteri.c \
|
||||
libft/ft_strmap.c \
|
||||
libft/ft_strmapi.c \
|
||||
libft/ft_strequ.c \
|
||||
libft/ft_strsub.c \
|
||||
libft/ft_strtrim.c \
|
||||
libft/ft_strsplit.c \
|
||||
libft/ft_itoa.c \
|
||||
libft/ft_strjoin.c \
|
||||
libft/ft_putchar.c \
|
||||
libft/ft_putstr.c \
|
||||
libft/ft_putendl.c \
|
||||
libft/ft_putnbr.c \
|
||||
libft/ft_putchar_fd.c \
|
||||
libft/ft_putstr_fd.c \
|
||||
libft/ft_putendl_fd.c \
|
||||
libft/ft_putnbr_fd.c \
|
||||
libft/ft_lstnew.c \
|
||||
libft/ft_lstdelone.c \
|
||||
libft/ft_lstdel.c \
|
||||
libft/ft_lstadd.c \
|
||||
libft/ft_lstadd_end.c \
|
||||
libft/ft_lstiter.c \
|
||||
libft/ft_lstmap.c \
|
||||
libft/ft_strextend.c \
|
||||
libft/ft_strnextend.c \
|
||||
libft/ft_sstrnew.c \
|
||||
libft/ft_sstrcpy.c \
|
||||
libft/ft_sstrdel.c \
|
||||
libft/get_next_line.c \
|
||||
libft/ft_memtab.c \
|
||||
libft/ft_memint_tab.c \
|
||||
libft/ft_sstrprint.c \
|
||||
libft/ft_bubble_sort.c \
|
||||
libft/ft_char_replace.c \
|
||||
libft/ft_itoa_base.c \
|
||||
libft/ft_itoa_double.c \
|
||||
libft/ft_strnchr.c \
|
||||
libft/ft_strrnchr.c \
|
||||
libft/ft_strupcase.c \
|
||||
libft/ft_strndup.c \
|
||||
libft/ft_power.c \
|
||||
libft/ft_itoa_base_int.c \
|
||||
libft/ft_itoa_base_short.c \
|
||||
libft/ft_strrev.c \
|
||||
libft/ft_isnumb.c \
|
||||
libft/ft_atois.c \
|
||||
libft/ft_mod.c \
|
||||
libft/ft_iswhitespace.c
|
||||
|
||||
OBJ_LIBFT = $(SRC_LIBFT:.c=.o)
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ_LIBFT)
|
||||
$(AR) $(NAME) $(OBJ_LIBFT)
|
||||
$(RL) $(NAME)
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ_LIBFT)
|
||||
|
||||
fclean: clean
|
||||
$(RM) $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.SILENT: $(OBJ_LIBFT) $(NAME) all clean fclean re
|
199
libft/include/libft.h
Normal file
199
libft/include/libft.h
Normal file
@@ -0,0 +1,199 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 15:35:42 by jfleury #+# #+# */
|
||||
/* Updated: 2019/07/15 19:15:18 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
|
||||
# define BUFF_SIZE 32
|
||||
# define CONV_ID_NB 13
|
||||
# define FLAGS_NB 5
|
||||
# define PRECI_GROUPS 3
|
||||
# define RED "\x1B[31m"
|
||||
# define GRN "\x1B[32m"
|
||||
# define YEL "\x1B[33m"
|
||||
# define BLU "\x1B[34m"
|
||||
# define MAG "\x1B[35m"
|
||||
# define CYN "\x1B[36m"
|
||||
# define WHT "\x1B[37m"
|
||||
# define RESET "\x1B[0m"
|
||||
# define STRONG "\033[1m"
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
size_t content_size;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
typedef struct s_conv_spec
|
||||
{
|
||||
char conv_id;
|
||||
int *flags;
|
||||
int *modifier;
|
||||
int field_width;
|
||||
int precision;
|
||||
char *converted;
|
||||
} t_conv_spec;
|
||||
|
||||
typedef struct s_fptr_id
|
||||
{
|
||||
char *conv_id_tab;
|
||||
char *(*fptr[CONV_ID_NB])(t_conv_spec c_s, va_list *list);
|
||||
} t_fptr_id;
|
||||
|
||||
typedef struct s_fptr_flag
|
||||
{
|
||||
int *flags;
|
||||
char *(*fptr[FLAGS_NB])(t_conv_spec c_s, char *str);
|
||||
} t_fptr_flag;
|
||||
|
||||
typedef struct s_fptr_preci
|
||||
{
|
||||
char **preci_group;
|
||||
char *(*fptr[PRECI_GROUPS])(t_conv_spec c_s, char *str);
|
||||
} t_fptr_preci;
|
||||
|
||||
int ft_atoi(const char *str);
|
||||
int ft_atoi_bin(char *str);
|
||||
long long ft_atoi_long(const char *str);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isprint(int c);
|
||||
char *ft_itoa(int n);
|
||||
void *ft_memalloc(size_t size);
|
||||
void *ft_memccpy(void *dest, const void *src, int c, size_t n);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||
void ft_memdel(void **ap);
|
||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
void ft_putchar(char c);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putendl(char const *s);
|
||||
void ft_putendl_fd(char const *s, int fd);
|
||||
void ft_putnbr(int n);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
void ft_putstr(char const *s);
|
||||
void ft_putstr_fd(char const *s, int fd);
|
||||
char *ft_strcat(char *dest, const char *src);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
void ft_strclr(char *s);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
char *ft_strcpy(char *dest, const char *src);
|
||||
void ft_strdel(char **as);
|
||||
char *ft_strdup(const char *src);
|
||||
int ft_strequ(char const *s1, char const *s2);
|
||||
void ft_striter(char *s, void (*f)(char*));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
size_t ft_strlcat(char *dest, const char *src, size_t n);
|
||||
size_t ft_strlen(const char *str);
|
||||
char *ft_strmap(char const *s, char (*f)(char));
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
char *ft_strncat(char *dest, const char *src, size_t n);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
char *ft_strncpy(char *dest, const char *src, size_t n);
|
||||
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
||||
char *ft_strnew(size_t size);
|
||||
char *ft_strnstr(const char *s1, const char *s2, size_t n);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char **ft_strsplit(char const *s, char c);
|
||||
char *ft_strstr(const char *str, const char *to_find);
|
||||
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strtrim(char const *s);
|
||||
int ft_tolower(int c);
|
||||
char *ft_itoa_base_int(unsigned int nb, int base);
|
||||
char *ft_itoa_base_short(unsigned short nb, int base);
|
||||
int ft_toupper(int c);
|
||||
char *ft_strextend(char *s1, char const *s2);
|
||||
char *ft_strnextend(char *s1, char const *s2, size_t len);
|
||||
char **ft_sstrnew(size_t row, size_t col);
|
||||
char **ft_sstrcpy(char **dest, char const **src);
|
||||
char **ft_memtab(size_t y, size_t x);
|
||||
int **ft_memint_tab(size_t y, size_t x);
|
||||
void ft_sstrprint(char **str);
|
||||
int *ft_bubble_sort(int *tab, int size);
|
||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void*, size_t));
|
||||
void ft_lstdel(t_list **alst, void (*del)(void*, size_t));
|
||||
void ft_lstadd(t_list **alst, t_list *new);
|
||||
int ft_lstadd_end(t_list **alst, t_list *elem);
|
||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
||||
void ft_lstprint_str(t_list *lst);
|
||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
||||
int ft_sstrdel(char **str, int size);
|
||||
int get_next_line(const int fd, char **line, char **tmp);
|
||||
unsigned long long ft_power(unsigned long long nb, unsigned long long power);
|
||||
char *ft_char_replace(char *str, char c, char r);
|
||||
char *ft_strupcase(char *str);
|
||||
char *ft_strnchr(const char *s, int c, int n);
|
||||
char *ft_strrnchr(const char *s, int c, int n);
|
||||
char *ft_strndup(const char *src, size_t n);
|
||||
char *ft_itoa_base(unsigned long long n, int base);
|
||||
char *ft_itoa_double(t_conv_spec conv_spec, long double nb);
|
||||
char *ft_strrev(char *str);
|
||||
char *ft_data_conv_id(void);
|
||||
int ft_store_conv_id(t_conv_spec *c_s, char *format, int i);
|
||||
void ft_store_modifier(t_conv_spec *c_s, char *f, int i, int l);
|
||||
void ft_store_flag(t_conv_spec *c_s, char *format, int i, int l);
|
||||
void ft_store_wc_field_width(t_conv_spec *c_s, va_list *ap);
|
||||
void ft_store_wc_precision(t_conv_spec *c_s, va_list *ap);
|
||||
void ft_store_field_width
|
||||
(t_conv_spec *c_s, char *format, int i, int len);
|
||||
void ft_store_precision(t_conv_spec *c_s, char *f, int i, int l);
|
||||
void ft_struct_init(t_conv_spec *c_s);
|
||||
void ft_struct_del(t_conv_spec *c_s);
|
||||
char *ft_data_conv_ids(void);
|
||||
char *ft_process_c(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_s(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_p(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_di(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_o(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_u(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_x(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_xx(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_f(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_b(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_dd(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_percent(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_id(t_conv_spec c_s, va_list *ap);
|
||||
char *ft_process_flags(t_conv_spec c_s, char *str);
|
||||
char *ft_process_hash(t_conv_spec c_s, char *str);
|
||||
char *ft_hash_xx_preci(char *str, int i);
|
||||
char *ft_hash_xx_zero(char *str, int i);
|
||||
char *ft_hash_x_preci(char *str, int i);
|
||||
char *ft_hash_x_zero(char *str, int i);
|
||||
char *ft_process_plus(t_conv_spec c_s, char *str);
|
||||
char *ft_process_zero(t_conv_spec c_s, char *str);
|
||||
char *ft_process_minus(t_conv_spec c_s, char *str);
|
||||
char *ft_process_space(t_conv_spec c_s, char *str);
|
||||
char *ft_process_min_width(t_conv_spec c_s, char *str);
|
||||
char *ft_precision_diouxx(t_conv_spec c_s, char *str);
|
||||
char *ft_precision_s(t_conv_spec c_s, char *str);
|
||||
char *ft_precision_p(t_conv_spec c_s, char *str);
|
||||
char *ft_process_preci(t_conv_spec c_s, char *str);
|
||||
|
||||
int ft_atois(const char *str, int *nb);
|
||||
int ft_isnumb(char *str);
|
||||
int ft_mod(unsigned int val, unsigned int div);
|
||||
int ft_iswhitespace(char c);
|
||||
|
||||
#endif
|
39
libft/libft/ft_atoi.c
Normal file
39
libft/libft/ft_atoi.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:46:25 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/07 13:38:37 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
int number;
|
||||
int c;
|
||||
int signe;
|
||||
|
||||
number = 0;
|
||||
c = 0;
|
||||
signe = 0;
|
||||
while (str[c] != '\0' && (str[c] == '\t' || str[c] == '\n'
|
||||
|| str[c] == '\v' || str[c] == '\f' || str[c] == '\r' || str[c] == ' '))
|
||||
c++;
|
||||
if (str[c] == '-' || str[c] == '+')
|
||||
{
|
||||
if (str[c] == '-')
|
||||
signe = 1;
|
||||
c++;
|
||||
}
|
||||
while (str[c] != '\0' && (str[c] >= '0' && str[c] <= '9'))
|
||||
{
|
||||
number = ((number * 10) + (str[c] - 48));
|
||||
c++;
|
||||
}
|
||||
if (signe == 1)
|
||||
number = -number;
|
||||
return (number);
|
||||
}
|
32
libft/libft/ft_atoi_bin.c
Normal file
32
libft/libft/ft_atoi_bin.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi_bin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/07/01 15:48:50 by jfleury #+# #+# */
|
||||
/* Updated: 2019/07/04 12:07:25 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi_bin(char *str)
|
||||
{
|
||||
int j;
|
||||
int bin;
|
||||
int result;
|
||||
|
||||
j = ft_strlen(str) - 1;
|
||||
result = 0;
|
||||
bin = 1;
|
||||
while (j >= 0)
|
||||
{
|
||||
if (str[j] == '1')
|
||||
result = result + bin;
|
||||
bin = bin * 2;
|
||||
j--;
|
||||
}
|
||||
return (result);
|
||||
}
|
39
libft/libft/ft_atoi_long.c
Normal file
39
libft/libft/ft_atoi_long.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi_long.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/04 17:51:43 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/05 19:48:52 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
long long ft_atoi_long(const char *str)
|
||||
{
|
||||
long long number;
|
||||
long long c;
|
||||
long long signe;
|
||||
|
||||
number = 0;
|
||||
c = 0;
|
||||
signe = 0;
|
||||
while (str[c] != '\0' && (str[c] == '\t' || str[c] == '\n'
|
||||
|| str[c] == '\v' || str[c] == '\f' || str[c] == '\r' || str[c] == ' '))
|
||||
c++;
|
||||
if (str[c] == '-' || str[c] == '+')
|
||||
{
|
||||
if (str[c] == '-')
|
||||
signe = 1;
|
||||
c++;
|
||||
}
|
||||
while (str[c] != '\0' && (str[c] >= '0' && str[c] <= '9'))
|
||||
{
|
||||
number = ((number * 10) + (str[c] - 48));
|
||||
c++;
|
||||
}
|
||||
if (signe == 1)
|
||||
number = -number;
|
||||
return (number);
|
||||
}
|
32
libft/libft/ft_atois.c
Normal file
32
libft/libft/ft_atois.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atois.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/27 11:58:44 by tmaze #+# #+# */
|
||||
/* Updated: 2019/06/19 15:23:42 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atois(const char *str, int *nb)
|
||||
{
|
||||
int num;
|
||||
|
||||
num = 0;
|
||||
while (ft_iswhitespace(str[num]))
|
||||
num++;
|
||||
if (str[num] == '+' || str[num] == '-')
|
||||
num++;
|
||||
if (ft_strlen(&(str[num])) < 10 || (num > 0 && str[num - 1] == '-'
|
||||
&& ft_strcmp("2147483648", &(str[num])) >= 0)
|
||||
|| ft_strcmp("2147483647", &(str[num])) >= 0)
|
||||
{
|
||||
*nb = ft_atoi(str);
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
38
libft/libft/ft_bubble_sort.c
Normal file
38
libft/libft/ft_bubble_sort.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bubble_sort.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/28 13:37:01 by jfleury #+# #+# */
|
||||
/* Updated: 2019/02/28 13:41:41 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int *ft_bubble_sort(int *tab, int size)
|
||||
{
|
||||
int temp;
|
||||
int c;
|
||||
int check;
|
||||
|
||||
c = 0;
|
||||
check = 0;
|
||||
while (check == 0)
|
||||
{
|
||||
check = 1;
|
||||
while (c < size - 1)
|
||||
{
|
||||
if (tab[c] > tab[c + 1])
|
||||
{
|
||||
temp = tab[c];
|
||||
tab[c] = tab[c + 1];
|
||||
tab[c + 1] = temp;
|
||||
check = 0;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
c = 0;
|
||||
}
|
||||
return (tab);
|
||||
}
|
19
libft/libft/ft_bzero.c
Normal file
19
libft/libft/ft_bzero.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 17:45:47 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:51 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
ft_memset(s, 0, n);
|
||||
}
|
25
libft/libft/ft_char_replace.c
Normal file
25
libft/libft/ft_char_replace.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_char_replace.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/16 18:50:02 by jfleury #+# #+# */
|
||||
/* Updated: 2019/01/16 18:54:31 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_char_replace(char *str, char c, char r)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
if (str[i] == c)
|
||||
str[i] = r;
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
23
libft/libft/ft_isalnum.c
Normal file
23
libft/libft/ft_isalnum.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 15:55:08 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:50 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (1);
|
||||
else if (c >= 'A' && c <= 'Z')
|
||||
return (1);
|
||||
else if (c >= 'a' && c <= 'z')
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
19
libft/libft/ft_isalpha.c
Normal file
19
libft/libft/ft_isalpha.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 16:07:58 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:50 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
19
libft/libft/ft_isascii.c
Normal file
19
libft/libft/ft_isascii.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 16:19:58 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:49 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
19
libft/libft/ft_isdigit.c
Normal file
19
libft/libft/ft_isdigit.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 16:22:16 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:48 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
28
libft/libft/ft_isnumb.c
Normal file
28
libft/libft/ft_isnumb.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isnumb.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/06/17 15:00:23 by tmaze #+# #+# */
|
||||
/* Updated: 2019/07/12 12:09:41 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isnumb(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
if ((i == 0 && str[i] != '-' && str[i] != '+' && !ft_isdigit(str[i]))
|
||||
|| (i != 0 && !ft_isdigit(str[i])))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
19
libft/libft/ft_isprint.c
Normal file
19
libft/libft/ft_isprint.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 16:25:39 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:47 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
19
libft/libft/ft_iswhitespace.c
Normal file
19
libft/libft/ft_iswhitespace.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_iswhitespace.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/25 16:11:19 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/25 16:13:25 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_iswhitespace(char c)
|
||||
{
|
||||
return (c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f'
|
||||
|| c == '\r');
|
||||
}
|
62
libft/libft/ft_itoa.c
Normal file
62
libft/libft/ft_itoa.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 11:06:12 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:48:02 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static int ft_isneg(int n)
|
||||
{
|
||||
if (n >= 0)
|
||||
return (0);
|
||||
else
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int ft_nbrlen(int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (n / 10 != 0)
|
||||
{
|
||||
i++;
|
||||
n = n / 10;
|
||||
}
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *str;
|
||||
int len;
|
||||
int nb;
|
||||
|
||||
if (n == -2147483648)
|
||||
return (ft_strdup("-2147483648"));
|
||||
nb = n;
|
||||
len = ft_nbrlen(n) + ft_isneg(n);
|
||||
if (!(str = (char*)malloc(sizeof(char) * len + 1)))
|
||||
return (NULL);
|
||||
str[len] = '\0';
|
||||
if (n < 0)
|
||||
n = -n;
|
||||
while (len > ft_isneg(nb))
|
||||
{
|
||||
len--;
|
||||
str[len] = (n % 10) + 48;
|
||||
n = n / 10;
|
||||
}
|
||||
if (ft_isneg(nb) == 1)
|
||||
str[0] = '-';
|
||||
return (str);
|
||||
}
|
57
libft/libft/ft_itoa_base.c
Normal file
57
libft/libft/ft_itoa_base.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa_base.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/23 15:05:04 by allefebv #+# #+# */
|
||||
/* Updated: 2019/07/08 17:26:58 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int ft_malloc_len(unsigned long long nb, int base)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (nb != 0)
|
||||
{
|
||||
nb = nb / base;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_itoa_base(unsigned long long nb, int base)
|
||||
{
|
||||
unsigned long long result;
|
||||
int i;
|
||||
char *str;
|
||||
char *tab;
|
||||
|
||||
tab = ft_strdup("0123456789abcdef");
|
||||
if (base < 2 || base > 16)
|
||||
return (NULL);
|
||||
i = ft_malloc_len(nb, base);
|
||||
if (nb == 0)
|
||||
i++;
|
||||
if (!(str = (char*)malloc(sizeof(char*) * i + 1)))
|
||||
return (NULL);
|
||||
str[i] = '\0';
|
||||
if (nb == 0)
|
||||
str[0] = '0';
|
||||
while (nb != 0)
|
||||
{
|
||||
i--;
|
||||
result = nb % base;
|
||||
str[i] = tab[result];
|
||||
nb = nb / base;
|
||||
}
|
||||
free(tab);
|
||||
return (str);
|
||||
}
|
57
libft/libft/ft_itoa_base_int.c
Normal file
57
libft/libft/ft_itoa_base_int.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa_base_int.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/23 15:05:04 by allefebv #+# #+# */
|
||||
/* Updated: 2019/07/09 15:26:17 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int ft_malloc_len(unsigned int nb, int base)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (nb != 0)
|
||||
{
|
||||
nb = nb / base;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_itoa_base_int(unsigned int nb, int base)
|
||||
{
|
||||
unsigned int result;
|
||||
int i;
|
||||
char *str;
|
||||
char *tab;
|
||||
|
||||
tab = ft_strdup("0123456789abcdef");
|
||||
if (base < 2 || base > 16)
|
||||
return (NULL);
|
||||
i = ft_malloc_len(nb, base);
|
||||
if (nb == 0)
|
||||
i++;
|
||||
if (!(str = (char*)malloc(sizeof(char*) * i + 1)))
|
||||
return (NULL);
|
||||
str[i] = '\0';
|
||||
if (nb == 0)
|
||||
str[0] = '0';
|
||||
while (nb != 0)
|
||||
{
|
||||
i--;
|
||||
result = nb % base;
|
||||
str[i] = tab[result];
|
||||
nb = nb / base;
|
||||
}
|
||||
free(tab);
|
||||
return (str);
|
||||
}
|
57
libft/libft/ft_itoa_base_short.c
Normal file
57
libft/libft/ft_itoa_base_short.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa_base_short.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/23 15:05:04 by allefebv #+# #+# */
|
||||
/* Updated: 2019/07/13 17:27:38 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int ft_malloc_len(unsigned short nb, int base)
|
||||
{
|
||||
short i;
|
||||
|
||||
i = 0;
|
||||
while (nb != 0)
|
||||
{
|
||||
nb = nb / base;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_itoa_base_short(unsigned short nb, int base)
|
||||
{
|
||||
unsigned short result;
|
||||
short i;
|
||||
char *str;
|
||||
char *tab;
|
||||
|
||||
tab = ft_strdup("0123456789abcdef");
|
||||
if (base < 2 || base > 16)
|
||||
return (NULL);
|
||||
i = ft_malloc_len(nb, base);
|
||||
if (nb == 0)
|
||||
i++;
|
||||
if (!(str = (char*)malloc(sizeof(char*) * i + 1)))
|
||||
return (NULL);
|
||||
str[i] = '\0';
|
||||
if (nb == 0)
|
||||
str[0] = '0';
|
||||
while (nb != 0)
|
||||
{
|
||||
i--;
|
||||
result = nb % base;
|
||||
str[i] = tab[result];
|
||||
nb = nb / base;
|
||||
}
|
||||
free(tab);
|
||||
return (str);
|
||||
}
|
88
libft/libft/ft_itoa_double.c
Normal file
88
libft/libft/ft_itoa_double.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa_double.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/21 16:36:44 by jfleury #+# #+# */
|
||||
/* Updated: 2019/04/02 12:07:30 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static char *ft_zero(t_conv_spec conv_spec, char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 2;
|
||||
str = ft_strnew(conv_spec.precision + 2);
|
||||
str[0] = '0';
|
||||
str[1] = '.';
|
||||
while (conv_spec.precision > 0)
|
||||
{
|
||||
str[i] = '0';
|
||||
conv_spec.precision--;
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
static char *ft_place_point(t_conv_spec conv_spec, char *str)
|
||||
{
|
||||
char *final_str;
|
||||
int i;
|
||||
|
||||
if ((i = ft_strlen(str) - conv_spec.precision) <= 0)
|
||||
{
|
||||
free(str);
|
||||
return (ft_strdup("(error)"));
|
||||
}
|
||||
final_str = ft_strnew(ft_strlen(str) + 1);
|
||||
ft_strncpy(final_str, str, i);
|
||||
final_str[i] = '.';
|
||||
ft_strcat(final_str, str + i);
|
||||
free(str);
|
||||
return (final_str);
|
||||
}
|
||||
|
||||
static char *ft_process(t_conv_spec conv_spec, char *str, int flag,
|
||||
long double nb)
|
||||
{
|
||||
long long result;
|
||||
unsigned long long power;
|
||||
|
||||
if (conv_spec.precision > 16)
|
||||
conv_spec.precision = 16;
|
||||
power = ft_power(10, conv_spec.precision);
|
||||
result = nb * power;
|
||||
if (((nb * power * 10) - (result * 10)) > 5)
|
||||
result++;
|
||||
if (flag == 1)
|
||||
result = -result;
|
||||
str = ft_itoa(result);
|
||||
str = ft_place_point(conv_spec, str);
|
||||
return (str);
|
||||
}
|
||||
|
||||
char *ft_itoa_double(t_conv_spec conv_spec, long double nb)
|
||||
{
|
||||
char *str;
|
||||
int flag;
|
||||
|
||||
flag = 0;
|
||||
str = NULL;
|
||||
if (conv_spec.precision == -1)
|
||||
conv_spec.precision = 6;
|
||||
if (nb < 0)
|
||||
{
|
||||
flag = 1;
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb == 0)
|
||||
str = ft_zero(conv_spec, str);
|
||||
else
|
||||
str = ft_process(conv_spec, str, flag, nb);
|
||||
return (str);
|
||||
}
|
21
libft/libft/ft_lstadd.c
Normal file
21
libft/libft/ft_lstadd.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 16:31:08 by jfleury #+# #+# */
|
||||
/* Updated: 2019/05/15 19:49:23 by allefebv ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd(t_list **alst, t_list *new)
|
||||
{
|
||||
if (new == NULL)
|
||||
return ;
|
||||
new->next = *alst;
|
||||
*alst = new;
|
||||
}
|
32
libft/libft/ft_lstadd_end.c
Normal file
32
libft/libft/ft_lstadd_end.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_end.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: allefebv <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/15 17:26:04 by allefebv #+# #+# */
|
||||
/* Updated: 2019/05/15 19:49:43 by allefebv ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstadd_end(t_list **alst, t_list *elem)
|
||||
{
|
||||
t_list *end;
|
||||
|
||||
if (elem == NULL)
|
||||
return (0);
|
||||
if (*alst == NULL)
|
||||
ft_lstadd(alst, elem);
|
||||
else
|
||||
{
|
||||
end = *alst;
|
||||
while (end->next != NULL)
|
||||
end = end->next;
|
||||
end->next = elem;
|
||||
elem->next = NULL;
|
||||
}
|
||||
return (1);
|
||||
}
|
30
libft/libft/ft_lstdel.c
Normal file
30
libft/libft/ft_lstdel.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 15:54:50 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/15 18:31:58 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void ft_lstdel(t_list **alst, void (*del)(void*, size_t))
|
||||
{
|
||||
t_list *temp_alst;
|
||||
t_list *temp_next;
|
||||
|
||||
temp_alst = *alst;
|
||||
while (temp_alst)
|
||||
{
|
||||
temp_next = temp_alst->next;
|
||||
del(temp_alst->content, temp_alst->content_size);
|
||||
free(temp_alst);
|
||||
temp_alst = temp_next;
|
||||
}
|
||||
*alst = NULL;
|
||||
}
|
22
libft/libft/ft_lstdelone.c
Normal file
22
libft/libft/ft_lstdelone.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 14:59:45 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/14 16:02:18 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void*, size_t))
|
||||
{
|
||||
del((*alst)->content, (*alst)->content_size);
|
||||
free(*alst);
|
||||
*alst = NULL;
|
||||
}
|
27
libft/libft/ft_lstiter.c
Normal file
27
libft/libft/ft_lstiter.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 17:11:41 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/16 14:37:53 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem))
|
||||
{
|
||||
t_list *temp_lst;
|
||||
t_list *temp_next;
|
||||
|
||||
temp_lst = lst;
|
||||
while (temp_lst)
|
||||
{
|
||||
temp_next = temp_lst->next;
|
||||
f(temp_lst);
|
||||
temp_lst = temp_next;
|
||||
}
|
||||
}
|
38
libft/libft/ft_lstmap.c
Normal file
38
libft/libft/ft_lstmap.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 18:20:50 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/15 18:30:30 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
||||
{
|
||||
t_list *final_lst;
|
||||
t_list *temp_lst;
|
||||
t_list *new;
|
||||
|
||||
if (lst == NULL || f == NULL)
|
||||
return (NULL);
|
||||
temp_lst = f(lst);
|
||||
if (!(new = ft_lstnew(temp_lst->content, temp_lst->content_size)))
|
||||
return (NULL);
|
||||
final_lst = new;
|
||||
lst = lst->next;
|
||||
while (lst)
|
||||
{
|
||||
temp_lst = f(lst);
|
||||
if (!(new->next = ft_lstnew(temp_lst->content, temp_lst->content_size)))
|
||||
return (NULL);
|
||||
new = new->next;
|
||||
lst = lst->next;
|
||||
}
|
||||
return (final_lst);
|
||||
}
|
36
libft/libft/ft_lstnew.c
Normal file
36
libft/libft/ft_lstnew.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/12 13:54:39 by jfleury #+# #+# */
|
||||
/* Updated: 2019/04/23 14:13:31 by allefebv ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size)
|
||||
{
|
||||
t_list *newlst;
|
||||
|
||||
if (!(newlst = (t_list*)malloc(sizeof(t_list))))
|
||||
return (NULL);
|
||||
if (content == NULL)
|
||||
{
|
||||
newlst->content = NULL;
|
||||
newlst->content_size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(newlst->content = (void*)malloc(sizeof(content) * content_size)))
|
||||
return (NULL);
|
||||
ft_memcpy((newlst->content), content, content_size);
|
||||
newlst->content_size = content_size;
|
||||
}
|
||||
newlst->next = NULL;
|
||||
return (newlst);
|
||||
}
|
22
libft/libft/ft_lstprint_str.c
Normal file
22
libft/libft/ft_lstprint_str.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstprint_char.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: allefebv <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/02 12:18:10 by allefebv #+# #+# */
|
||||
/* Updated: 2019/04/23 13:53:16 by allefebv ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstprint_str(t_list *lst)
|
||||
{
|
||||
while (lst != NULL)
|
||||
{
|
||||
ft_printf("%s\n", (char*)(lst->content));
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
24
libft/libft/ft_memalloc.c
Normal file
24
libft/libft/ft_memalloc.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memalloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 09:59:49 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:41:04 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void *ft_memalloc(size_t size)
|
||||
{
|
||||
void *temp;
|
||||
|
||||
if (!(temp = (void*)malloc(size)))
|
||||
return (NULL);
|
||||
ft_memset(temp, 0, size);
|
||||
return (temp);
|
||||
}
|
33
libft/libft/ft_memccpy.c
Normal file
33
libft/libft/ft_memccpy.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memccpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/08 11:09:19 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:00:31 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *ft_memccpy(void *dest, const void *src, int c, size_t n)
|
||||
{
|
||||
char *temp_dest;
|
||||
char *temp_src;
|
||||
int i;
|
||||
|
||||
temp_dest = (char*)dest;
|
||||
temp_src = (char*)src;
|
||||
i = 0;
|
||||
while (n > 0)
|
||||
{
|
||||
temp_dest[i] = temp_src[i];
|
||||
if (temp_src[i] == (char)c)
|
||||
return (dest + i + 1);
|
||||
i++;
|
||||
n--;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
32
libft/libft/ft_memchr.c
Normal file
32
libft/libft/ft_memchr.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/08 11:09:29 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:00:43 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *temp_s;
|
||||
unsigned char temp_c;
|
||||
int i;
|
||||
|
||||
temp_s = (unsigned char*)s;
|
||||
temp_c = (unsigned char)c;
|
||||
i = 0;
|
||||
while (n > 0)
|
||||
{
|
||||
if (temp_s[i] == temp_c)
|
||||
return (temp_s + i);
|
||||
i++;
|
||||
n--;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
35
libft/libft/ft_memcmp.c
Normal file
35
libft/libft/ft_memcmp.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/08 11:09:06 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/02 12:55:38 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
unsigned char *temp_s1;
|
||||
unsigned char *temp_s2;
|
||||
int i;
|
||||
|
||||
temp_s1 = (unsigned char*)s1;
|
||||
temp_s2 = (unsigned char*)s2;
|
||||
i = 0;
|
||||
while (n > 0)
|
||||
{
|
||||
if (temp_s1[i] != temp_s2[i])
|
||||
return (temp_s1[i] - temp_s2[i]);
|
||||
else
|
||||
{
|
||||
i++;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
31
libft/libft/ft_memcpy.c
Normal file
31
libft/libft/ft_memcpy.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/08 11:11:11 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:47 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *temp_dest;
|
||||
char *temp_src;
|
||||
int i;
|
||||
|
||||
temp_dest = (char*)dest;
|
||||
temp_src = (char*)src;
|
||||
i = 0;
|
||||
while (n > 0)
|
||||
{
|
||||
temp_dest[i] = temp_src[i];
|
||||
i++;
|
||||
n--;
|
||||
}
|
||||
return (dest);
|
||||
}
|
22
libft/libft/ft_memdel.c
Normal file
22
libft/libft/ft_memdel.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 09:59:57 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 20:49:47 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void ft_memdel(void **ap)
|
||||
{
|
||||
if (ap != NULL && *ap != NULL)
|
||||
{
|
||||
free(*ap);
|
||||
*ap = NULL;
|
||||
}
|
||||
}
|
40
libft/libft/ft_memint_tab.c
Normal file
40
libft/libft/ft_memint_tab.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memint_tab.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/12 13:54:49 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/12 13:54:54 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int **ft_memint_tab(size_t y, size_t x)
|
||||
{
|
||||
int **tab;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!(tab = (int**)ft_memalloc(sizeof(int*) * (y))))
|
||||
return (NULL);
|
||||
while (i < y)
|
||||
{
|
||||
if (!(tab[i] = (int*)ft_memalloc(sizeof(int) * x)))
|
||||
{
|
||||
i++;
|
||||
while (i > 0)
|
||||
{
|
||||
free(tab[i - 2]);
|
||||
i--;
|
||||
}
|
||||
free(tab);
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (tab);
|
||||
}
|
34
libft/libft/ft_memmove.c
Normal file
34
libft/libft/ft_memmove.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 09:55:12 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:45:16 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
unsigned char *temp_dest;
|
||||
unsigned char *temp_src;
|
||||
size_t i;
|
||||
|
||||
temp_dest = (unsigned char*)dest;
|
||||
temp_src = (unsigned char*)src;
|
||||
i = n;
|
||||
if (temp_dest > temp_src)
|
||||
while (n)
|
||||
{
|
||||
temp_dest[n - 1] = temp_src[n - 1];
|
||||
n--;
|
||||
}
|
||||
else
|
||||
ft_memcpy(temp_dest, temp_src, i);
|
||||
return (dest);
|
||||
}
|
29
libft/libft/ft_memset.c
Normal file
29
libft/libft/ft_memset.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/06 15:17:24 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:45 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *temp;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
temp = (unsigned char*)s;
|
||||
while (n > 0)
|
||||
{
|
||||
temp[i] = c;
|
||||
i++;
|
||||
n--;
|
||||
}
|
||||
return (s);
|
||||
}
|
41
libft/libft/ft_memtab.c
Normal file
41
libft/libft/ft_memtab.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memtab.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/12 13:55:02 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/12 13:55:07 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char **ft_memtab(size_t y, size_t x)
|
||||
{
|
||||
char **tab;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!(tab = (char**)ft_memalloc(sizeof(char*) * (y + 1))))
|
||||
return (NULL);
|
||||
while (i < y)
|
||||
{
|
||||
if (!(tab[i] = ft_strnew(x)))
|
||||
{
|
||||
i++;
|
||||
while (i > 0)
|
||||
{
|
||||
free(tab[i - 1]);
|
||||
i--;
|
||||
}
|
||||
free(tab);
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
tab[y] = 0;
|
||||
return (tab);
|
||||
}
|
21
libft/libft/ft_mod.c
Normal file
21
libft/libft/ft_mod.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_mod.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/06/21 00:51:09 by tmaze #+# #+# */
|
||||
/* Updated: 2019/06/24 15:27:43 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_mod(unsigned int val, unsigned int div)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = val % div;
|
||||
return ((r < 0) ? r + div : r);
|
||||
}
|
23
libft/libft/ft_power.c
Normal file
23
libft/libft/ft_power.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_power.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/21 17:34:08 by jfleury #+# #+# */
|
||||
/* Updated: 2019/01/23 15:07:35 by allefebv ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
unsigned long long ft_power(unsigned long long nb, int power)
|
||||
{
|
||||
if (power == 0)
|
||||
return (1);
|
||||
if (power == 1)
|
||||
return (nb);
|
||||
if (power > 0)
|
||||
return (nb * ft_power(nb, power - 1));
|
||||
else
|
||||
return (0);
|
||||
}
|
18
libft/libft/ft_putchar.c
Normal file
18
libft/libft/ft_putchar.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:46:36 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:57:28 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
18
libft/libft/ft_putchar_fd.c
Normal file
18
libft/libft/ft_putchar_fd.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:03:58 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:49:12 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
19
libft/libft/ft_putendl.c
Normal file
19
libft/libft/ft_putendl.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:03:39 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:43 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl(char const *s)
|
||||
{
|
||||
ft_putstr(s);
|
||||
ft_putchar('\n');
|
||||
}
|
19
libft/libft/ft_putendl_fd.c
Normal file
19
libft/libft/ft_putendl_fd.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:03:45 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:51:53 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char const *s, int fd)
|
||||
{
|
||||
ft_putstr_fd(s, fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
35
libft/libft/ft_putnbr.c
Normal file
35
libft/libft/ft_putnbr.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:47:14 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:42 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr(int n)
|
||||
{
|
||||
if (n == -2147483648)
|
||||
{
|
||||
ft_putchar('-');
|
||||
ft_putchar('2');
|
||||
n = 147483648;
|
||||
}
|
||||
if (n < 0)
|
||||
{
|
||||
ft_putchar('-');
|
||||
n = -n;
|
||||
}
|
||||
if (n < 10)
|
||||
ft_putchar(n + 48);
|
||||
if (n > 9)
|
||||
{
|
||||
ft_putnbr(n / 10);
|
||||
ft_putnbr(n % 10);
|
||||
}
|
||||
}
|
35
libft/libft/ft_putnbr_fd.c
Normal file
35
libft/libft/ft_putnbr_fd.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:47:14 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/06 09:47:31 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
if (n == -2147483648)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
ft_putchar_fd('2', fd);
|
||||
n = 147483648;
|
||||
}
|
||||
if (n < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
n = -n;
|
||||
}
|
||||
if (n < 10)
|
||||
ft_putchar_fd(n + 48, fd);
|
||||
if (n > 9)
|
||||
{
|
||||
ft_putnbr_fd(n / 10, fd);
|
||||
ft_putnbr_fd(n % 10, fd);
|
||||
}
|
||||
}
|
28
libft/libft/ft_putstr.c
Normal file
28
libft/libft/ft_putstr.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:47:33 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 20:26:16 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr(char const *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (s != NULL)
|
||||
{
|
||||
while (s[i] != 0)
|
||||
{
|
||||
ft_putchar(s[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
29
libft/libft/ft_putstr_fd.c
Normal file
29
libft/libft/ft_putstr_fd.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:04:05 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 20:26:36 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
|
||||
void ft_putstr_fd(char const *s, int fd)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (s != NULL)
|
||||
{
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
ft_putchar_fd(s[i], fd);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
25
libft/libft/ft_sstrcpy.c
Normal file
25
libft/libft/ft_sstrcpy.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sstrcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/12 13:55:16 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/12 13:55:19 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
|
||||
char **ft_sstrcpy(char **dest, char const **src)
|
||||
{
|
||||
while (*src != 0 && *dest != 0)
|
||||
{
|
||||
ft_strcpy(*dest, *src);
|
||||
src++;
|
||||
dest++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
26
libft/libft/ft_sstrdel.c
Normal file
26
libft/libft/ft_sstrdel.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sstrdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/12 13:50:51 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/12 13:50:53 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_sstrdel(char **str, int size)
|
||||
{
|
||||
while (size >= 0)
|
||||
{
|
||||
free(str[size]);
|
||||
size--;
|
||||
}
|
||||
free(str);
|
||||
str = NULL;
|
||||
return (0);
|
||||
}
|
30
libft/libft/ft_sstrnew.c
Normal file
30
libft/libft/ft_sstrnew.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sstrnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/12 13:51:04 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/12 13:51:06 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char **ft_sstrnew(size_t y, size_t x)
|
||||
{
|
||||
char **str;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!(str = (char**)ft_memalloc(y + 1)))
|
||||
return (NULL);
|
||||
while (i < y)
|
||||
{
|
||||
str[i] = ft_strnew(x);
|
||||
i++;
|
||||
}
|
||||
str[y] = 0;
|
||||
return (str);
|
||||
}
|
26
libft/libft/ft_sstrprint.c
Normal file
26
libft/libft/ft_sstrprint.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sstrprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/12 13:51:14 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/12 13:51:16 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_sstrprint(char **str)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
ft_putstr(str[i]);
|
||||
ft_putchar('\n');
|
||||
i++;
|
||||
}
|
||||
}
|
30
libft/libft/ft_strcat.c
Normal file
30
libft/libft/ft_strcat.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:47:58 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:46:03 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcat(char *dest, const char *src)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
j = 0;
|
||||
i = ft_strlen(dest);
|
||||
while (src[j] != '\0')
|
||||
{
|
||||
dest[i] = src[j];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
23
libft/libft/ft_strchr.c
Normal file
23
libft/libft/ft_strchr.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/08 10:47:52 by jfleury #+# #+# */
|
||||
/* Updated: 2019/06/07 13:49:03 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
while (*s != (char)c && *s != '\0')
|
||||
s++;
|
||||
if (*s == (char)c)
|
||||
return ((char *)s);
|
||||
return (NULL);
|
||||
}
|
24
libft/libft/ft_strclr.c
Normal file
24
libft/libft/ft_strclr.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strclr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:00:22 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/14 12:24:47 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_strclr(char *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (s != NULL)
|
||||
{
|
||||
i = ft_strlen(s);
|
||||
ft_bzero(s, i);
|
||||
}
|
||||
}
|
26
libft/libft/ft_strcmp.c
Normal file
26
libft/libft/ft_strcmp.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:48:13 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/04 14:38:51 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = ft_strlen(s1);
|
||||
j = ft_strlen(s2);
|
||||
if (i > j)
|
||||
return (ft_memcmp(s1, s2, i));
|
||||
else
|
||||
return (ft_memcmp(s1, s2, j));
|
||||
}
|
25
libft/libft/ft_strcpy.c
Normal file
25
libft/libft/ft_strcpy.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:48:33 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:19:06 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strcpy(char *dest, const char *src)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
while (src[i] != '\0')
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
23
libft/libft/ft_strdel.c
Normal file
23
libft/libft/ft_strdel.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:07:18 by jfleury #+# #+# */
|
||||
/* Updated: 2019/05/23 12:22:31 by allefebv ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void ft_strdel(char **as)
|
||||
{
|
||||
if (as != NULL && *as != NULL)
|
||||
{
|
||||
free(*as);
|
||||
*as = NULL;
|
||||
}
|
||||
}
|
36
libft/libft/ft_strdup.c
Normal file
36
libft/libft/ft_strdup.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:48:56 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:45:44 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *ft_strdup(const char *src)
|
||||
{
|
||||
char *str;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (src[j] != '\0')
|
||||
j++;
|
||||
str = (char*)malloc(sizeof(*str) * (j + 1));
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
while (src[i] != '\0')
|
||||
{
|
||||
str[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
22
libft/libft/ft_strequ.c
Normal file
22
libft/libft/ft_strequ.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strequ.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:01:11 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/02 12:56:54 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strequ(char const *s1, char const *s2)
|
||||
{
|
||||
if (!(s1) || !(s2))
|
||||
return (0);
|
||||
if (!(ft_strcmp(s1, s2)))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
31
libft/libft/ft_strextend.c
Normal file
31
libft/libft/ft_strextend.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strextend.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/21 11:15:30 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/21 11:41:42 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strextend(char *s1, char const *s2)
|
||||
{
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
if (s1 == NULL || s2 == NULL)
|
||||
return (NULL);
|
||||
i = ft_strlen(s1) + ft_strlen(s2);
|
||||
str = s1;
|
||||
if (!(s1 = (char*)malloc(sizeof(s1) * i + 1)))
|
||||
return (NULL);
|
||||
ft_strcpy(s1, str);
|
||||
ft_strcat(s1, s2);
|
||||
free(str);
|
||||
return (s1);
|
||||
}
|
25
libft/libft/ft_striter.c
Normal file
25
libft/libft/ft_striter.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:00:32 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/15 17:25:51 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void ft_striter(char *s, void (*f)(char*))
|
||||
{
|
||||
if (s != NULL && f != NULL)
|
||||
{
|
||||
while (*s != '\0')
|
||||
{
|
||||
f(s);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
}
|
29
libft/libft/ft_striteri.c
Normal file
29
libft/libft/ft_striteri.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:00:37 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/15 17:26:01 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
if (s != NULL && f != NULL)
|
||||
{
|
||||
while (*s != '\0')
|
||||
{
|
||||
f(i, s);
|
||||
i++;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
}
|
30
libft/libft/ft_strjoin.c
Normal file
30
libft/libft/ft_strjoin.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:01:42 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:48:27 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
if (s1 == NULL || s2 == NULL)
|
||||
return (NULL);
|
||||
i = ft_strlen(s1) + ft_strlen(s2);
|
||||
if (!(str = (char*)malloc(sizeof(str) * i + 1)))
|
||||
return (NULL);
|
||||
ft_strcpy(str, s1);
|
||||
ft_strcat(str, s2);
|
||||
return (str);
|
||||
}
|
35
libft/libft/ft_strlcat.c
Normal file
35
libft/libft/ft_strlcat.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 09:55:24 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:30 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
|
||||
size_t ft_strlcat(char *dest, const char *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
if (n == 0)
|
||||
return (ft_strlen(src));
|
||||
while (dest[i] && i < n)
|
||||
i++;
|
||||
j = i;
|
||||
while (src[i - j] && i < n - 1)
|
||||
{
|
||||
dest[i] = src[i - j];
|
||||
i++;
|
||||
}
|
||||
if (j < n)
|
||||
dest[i] = '\0';
|
||||
return (j + ft_strlen(src));
|
||||
}
|
23
libft/libft/ft_strlen.c
Normal file
23
libft/libft/ft_strlen.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:49:21 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:25:34 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != 0)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
37
libft/libft/ft_strmap.c
Normal file
37
libft/libft/ft_strmap.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:00:49 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 20:55:38 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmap(char const *s, char (*f)(char))
|
||||
{
|
||||
char *str;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
if (!(s))
|
||||
return (NULL);
|
||||
len = ft_strlen((char*)s);
|
||||
if (!(str = (char*)malloc(sizeof(char) * len + 1)))
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
if (!(str[i] = f(s[i])))
|
||||
return (NULL);
|
||||
i++;
|
||||
}
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
37
libft/libft/ft_strmapi.c
Normal file
37
libft/libft/ft_strmapi.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:00:59 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 20:57:38 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
char *str;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
if (!(s))
|
||||
return (NULL);
|
||||
len = ft_strlen((char*)s);
|
||||
if (!(str = (char*)malloc(sizeof(char) * len + 1)))
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
if (!(str[i] = f(i, s[i])))
|
||||
return (NULL);
|
||||
i++;
|
||||
}
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
31
libft/libft/ft_strncat.c
Normal file
31
libft/libft/ft_strncat.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:49:31 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:26:56 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
|
||||
char *ft_strncat(char *dest, const char *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
j = 0;
|
||||
i = ft_strlen(dest);
|
||||
while (src[j] != '\0' && j < n)
|
||||
{
|
||||
dest[i] = src[j];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
27
libft/libft/ft_strnchr.c
Normal file
27
libft/libft/ft_strnchr.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/07 17:53:03 by jfleury #+# #+# */
|
||||
/* Updated: 2019/04/02 12:08:05 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnchr(const char *s, int c, int n)
|
||||
{
|
||||
while (*s != (char)c && *s != '\0')
|
||||
{
|
||||
s++;
|
||||
n--;
|
||||
if (n == 0)
|
||||
return (NULL);
|
||||
}
|
||||
if (*s == (char)c)
|
||||
return ((char *)s);
|
||||
return (NULL);
|
||||
}
|
31
libft/libft/ft_strncmp.c
Normal file
31
libft/libft/ft_strncmp.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:49:43 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/15 16:46:42 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (n > 0 && (s1[i] != '\0' || s2[i] != '\0'))
|
||||
{
|
||||
if (s1[i] != s2[i])
|
||||
return ((unsigned char)s1[i] - s2[i]);
|
||||
else
|
||||
{
|
||||
i++;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
31
libft/libft/ft_strncpy.c
Normal file
31
libft/libft/ft_strncpy.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:49:53 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:27:16 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *ft_strncpy(char *dest, const char *src, size_t n)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
while (i < n && src[i] != '\0')
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
while (i < n)
|
||||
{
|
||||
dest[i] = '\0';
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
31
libft/libft/ft_strndup.c
Normal file
31
libft/libft/ft_strndup.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strndup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/15 17:33:47 by allefebv #+# #+# */
|
||||
/* Updated: 2019/04/02 12:09:00 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strndup(const char *s, size_t len)
|
||||
{
|
||||
char *strcpy;
|
||||
|
||||
if (ft_strlen(s) > len)
|
||||
{
|
||||
if (!(strcpy = (char*)malloc(sizeof(char) * (len + 1))))
|
||||
return (NULL);
|
||||
ft_strncpy(strcpy, s, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(strcpy = ft_strdup(s)))
|
||||
return (NULL);
|
||||
}
|
||||
return (strcpy);
|
||||
}
|
23
libft/libft/ft_strnequ.c
Normal file
23
libft/libft/ft_strnequ.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnequ.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:01:20 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/15 17:23:25 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
|
||||
int ft_strnequ(char const *s1, char const *s2, size_t n)
|
||||
{
|
||||
if (!(s1) || !(s2))
|
||||
return (0);
|
||||
if (!(ft_strncmp(s1, s2, (int)n)))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
25
libft/libft/ft_strnew.c
Normal file
25
libft/libft/ft_strnew.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:00:08 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:28:06 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnew(size_t size)
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (!(str = (char*)malloc(sizeof(char) * size + 1)))
|
||||
return (NULL);
|
||||
ft_bzero(str, size + 1);
|
||||
return (str);
|
||||
}
|
34
libft/libft/ft_strnextend.c
Normal file
34
libft/libft/ft_strnextend.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnextend.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/21 11:16:19 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/21 11:42:05 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strnextend(char *s1, char const *s2, size_t len)
|
||||
{
|
||||
char *tmp;
|
||||
int i;
|
||||
|
||||
if (!(s1) || !(s2))
|
||||
return (NULL);
|
||||
if (len < ft_strlen(s2))
|
||||
i = ft_strlen(s1) + len;
|
||||
else
|
||||
i = ft_strlen(s1) + ft_strlen(s2);
|
||||
tmp = s1;
|
||||
if (!(s1 = (char*)malloc(sizeof(s1) * (i + 1))))
|
||||
return (NULL);
|
||||
ft_strcpy(s1, tmp);
|
||||
ft_strncat(s1, s2, len);
|
||||
free(tmp);
|
||||
return (s1);
|
||||
}
|
38
libft/libft/ft_strnstr.c
Normal file
38
libft/libft/ft_strnstr.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/08 17:44:35 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/15 17:19:56 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *ft_strnstr(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s1[i] != '\0' && i < n)
|
||||
{
|
||||
j = 0;
|
||||
while (s1[i] == s2[j] && s2[j] != 0 && s1[i] != 0 && i < n)
|
||||
{
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
if (s2[j] == 0)
|
||||
return ((char*)s1 + i - j);
|
||||
if (j == 0)
|
||||
i++;
|
||||
else
|
||||
i = i - j + 1;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
28
libft/libft/ft_strrchr.c
Normal file
28
libft/libft/ft_strrchr.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/08 14:47:08 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:28:35 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = ft_strlen((char *)s);
|
||||
while (i >= 0)
|
||||
{
|
||||
if (s[i] == c)
|
||||
return ((char *)s + i);
|
||||
i--;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
33
libft/libft/ft_strrev.c
Normal file
33
libft/libft/ft_strrev.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrev.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/09 17:12:12 by jfleury #+# #+# */
|
||||
/* Updated: 2019/04/02 12:09:13 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrev(char *str)
|
||||
{
|
||||
char stra;
|
||||
int start;
|
||||
int end;
|
||||
|
||||
start = 0;
|
||||
end = ft_strlen(str);
|
||||
end--;
|
||||
while (start < end)
|
||||
{
|
||||
stra = str[end];
|
||||
str[end] = str[start];
|
||||
str[start] = stra;
|
||||
start++;
|
||||
end--;
|
||||
}
|
||||
return (str);
|
||||
}
|
23
libft/libft/ft_strrnchr.c
Normal file
23
libft/libft/ft_strrnchr.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrnchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/09 10:33:56 by allefebv #+# #+# */
|
||||
/* Updated: 2019/04/02 12:08:23 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrnchr(const char *s, int c, int n)
|
||||
{
|
||||
while (s[n] != c)
|
||||
n--;
|
||||
if (s[n] == c)
|
||||
return ((char*)s + n);
|
||||
else
|
||||
return (NULL);
|
||||
}
|
80
libft/libft/ft_strsplit.c
Normal file
80
libft/libft/ft_strsplit.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strsplit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:02:06 by jfleury #+# #+# */
|
||||
/* Updated: 2019/03/02 12:36:51 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *ft_strdup_split(char const *s, char c, int *i)
|
||||
{
|
||||
int j;
|
||||
char *new;
|
||||
|
||||
j = 0;
|
||||
while (s[j] != c && s[j] != '\0')
|
||||
j++;
|
||||
if (!(new = (char*)malloc(sizeof(char) * (j + 1))))
|
||||
return (NULL);
|
||||
j = 0;
|
||||
while (s[j] != c && s[j] != '\0')
|
||||
{
|
||||
new[j] = s[j];
|
||||
j++;
|
||||
}
|
||||
new[j] = '\0';
|
||||
*i = *i + j;
|
||||
return (new);
|
||||
}
|
||||
|
||||
static int ft_size(char const *s, char c)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
if (s[i] != c && (s[i + 1] == c || s[i + 1] == '\0'))
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
return (j);
|
||||
}
|
||||
|
||||
char **ft_strsplit(char const *s, char c)
|
||||
{
|
||||
char **s_str;
|
||||
int size_s_str;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
if (s == NULL)
|
||||
return (NULL);
|
||||
size_s_str = ft_size(s, c);
|
||||
if (!(s_str = (char**)malloc(sizeof(char*) * (size_s_str + 1))))
|
||||
return (NULL);
|
||||
s_str[size_s_str] = 0;
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
while (s[i] == c && s[i] != '\0')
|
||||
i++;
|
||||
if (s[i] == '\0')
|
||||
return (s_str);
|
||||
if (!(s_str[j] = ft_strdup_split((s + i), c, &i)))
|
||||
return (NULL);
|
||||
else
|
||||
j++;
|
||||
}
|
||||
return (s_str);
|
||||
}
|
38
libft/libft/ft_strstr.c
Normal file
38
libft/libft/ft_strstr.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 14:50:07 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 19:37:48 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *ft_strstr(const char *str, const char *to_find)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (to_find[0] == '\0')
|
||||
return ((char *)str);
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
j = 0;
|
||||
while (str[i + j] == to_find[j])
|
||||
{
|
||||
if (to_find[j + 1] == '\0')
|
||||
{
|
||||
return ((char *)str + i);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
35
libft/libft/ft_strsub.c
Normal file
35
libft/libft/ft_strsub.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strsub.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:01:30 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:47:30 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strsub(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *str;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (s == NULL || ft_strlen(s) < start)
|
||||
return (NULL);
|
||||
if (!(str = (char*)malloc(sizeof(char) * (len + 1))))
|
||||
return (NULL);
|
||||
while (len > i && s[start] != 0)
|
||||
{
|
||||
str[i] = s[start];
|
||||
start++;
|
||||
i++;
|
||||
}
|
||||
str[i] = 0;
|
||||
return (str);
|
||||
}
|
34
libft/libft/ft_strtrim.c
Normal file
34
libft/libft/ft_strtrim.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/13 10:01:56 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 20:45:52 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <string.h>
|
||||
|
||||
char *ft_strtrim(char const *s)
|
||||
{
|
||||
char *str;
|
||||
int i;
|
||||
int len;
|
||||
|
||||
if (s == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
len = ft_strlen(s) - 1;
|
||||
while ((s[i] == ' ' || s[i] == '\n' || s[i] == '\t'))
|
||||
i++;
|
||||
if (s[i] == 0)
|
||||
return (ft_strdup(s + i));
|
||||
while ((s[len] == ' ' || s[len] == '\n' || s[len] == '\t') && len > 0)
|
||||
len--;
|
||||
str = (ft_strsub(s, i, len - i + 1));
|
||||
return (str);
|
||||
}
|
27
libft/libft/ft_strupcase.c
Normal file
27
libft/libft/ft_strupcase.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strupcase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/14 17:23:47 by jfleury #+# #+# */
|
||||
/* Updated: 2019/04/02 12:08:35 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strupcase(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] >= 'a' && str[i] <= 'z')
|
||||
str[i] = str[i] - 32;
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
22
libft/libft/ft_tolower.c
Normal file
22
libft/libft/ft_tolower.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 17:31:11 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:29:39 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
{
|
||||
c = c + 32;
|
||||
return (c);
|
||||
}
|
||||
else
|
||||
return (c);
|
||||
}
|
22
libft/libft/ft_toupper.c
Normal file
22
libft/libft/ft_toupper.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/05 17:37:05 by jfleury #+# #+# */
|
||||
/* Updated: 2018/11/13 18:29:41 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
{
|
||||
c = c - 32;
|
||||
return (c);
|
||||
}
|
||||
else
|
||||
return (c);
|
||||
}
|
91
libft/libft/get_next_line.c
Normal file
91
libft/libft/get_next_line.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/12 13:50:20 by jfleury #+# #+# */
|
||||
/* Updated: 2019/07/01 15:23:57 by jfleury ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_read(char *tmp, char **line, int fd, int *check_end)
|
||||
{
|
||||
char buf[BUFF_SIZE + 1];
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
while ((ret = read(fd, buf, BUFF_SIZE)) != 0)
|
||||
{
|
||||
i = 0;
|
||||
buf[ret] = '\0';
|
||||
while (buf[i] != '\0' && buf[i] != '\n')
|
||||
i++;
|
||||
if (buf[i] == '\n')
|
||||
{
|
||||
if (!(*line = ft_strnextend(*line, buf, i)))
|
||||
return (NULL);
|
||||
ft_strcpy(tmp, buf + i + 1);
|
||||
return (tmp);
|
||||
}
|
||||
if (!(*line = ft_strextend(*line, buf)))
|
||||
return (NULL);
|
||||
ft_bzero(buf, BUFF_SIZE + 1);
|
||||
}
|
||||
if (!ret && **line == '\0')
|
||||
*check_end = 1;
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
char *ft_checktmp(char *tmp, char **line, int *check_n)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
if (tmp == NULL)
|
||||
{
|
||||
if (!(tmp = ft_strnew(BUFF_SIZE)))
|
||||
return (NULL);
|
||||
}
|
||||
while (tmp[i] != '\0' && tmp[i] != '\n')
|
||||
{
|
||||
line[0][i] = tmp[i];
|
||||
i++;
|
||||
}
|
||||
if (tmp[i] == '\n')
|
||||
*check_n = 1;
|
||||
j = 0;
|
||||
while (tmp[i + j] != '\0')
|
||||
j++;
|
||||
ft_memmove(tmp, tmp + i + 1, j);
|
||||
ft_bzero(tmp + j, i + 1);
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
int get_next_line(const int fd, char **line, char **tmp)
|
||||
{
|
||||
char buf[1];
|
||||
int check_n;
|
||||
int check_end;
|
||||
|
||||
if (line == NULL || fd < 0 || read(fd, buf, 0) < 0)
|
||||
return (-1);
|
||||
if (!(*line = ft_strnew(BUFF_SIZE)))
|
||||
*line = NULL;
|
||||
check_n = 0;
|
||||
check_end = 0;
|
||||
if (!(*tmp = ft_checktmp(*tmp, line, &check_n)))
|
||||
return (-1);
|
||||
if (check_n == 1)
|
||||
return (1);
|
||||
if (!(*tmp = ft_read(*tmp, line, fd, &check_end)))
|
||||
return (-1);
|
||||
if (check_end == 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
81
libft/printf/Makefile
Normal file
81
libft/printf/Makefile
Normal file
@@ -0,0 +1,81 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: jfleury <jfleury@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2018/12/14 16:59:10 by igarbuz #+# #+# #
|
||||
# Updated: 2019/07/17 11:14:14 by jfleury ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = libftprintf.a
|
||||
|
||||
SRC = buf_cnt.c \
|
||||
ft_argcast.c \
|
||||
ft_arglen_f.c \
|
||||
ft_arglen_oct.c \
|
||||
ft_arglen.c \
|
||||
ft_buf_print_db.c \
|
||||
ft_buf_print_ldb.c \
|
||||
ft_error.c \
|
||||
ft_exp_dec.c \
|
||||
ft_init_param.c \
|
||||
ft_nd_div.c \
|
||||
ft_nd_long_div.c \
|
||||
ft_nd_long_mul.c \
|
||||
ft_nd_long_round.c \
|
||||
ft_nd_mul.c \
|
||||
ft_nd_round.c \
|
||||
ft_null.c \
|
||||
ft_parse.c \
|
||||
ft_printf_db.c \
|
||||
ft_printf_ldb.c \
|
||||
ft_printf.c \
|
||||
ft_unicode.c \
|
||||
libft_printf.c \
|
||||
pow10.c \
|
||||
print_buf_bit_float.c \
|
||||
print_buf_num.c \
|
||||
print_buf_prefix.c \
|
||||
print_buf_unicode.c \
|
||||
print_buf.c \
|
||||
print_cs_pad.c \
|
||||
print_num_pad.c
|
||||
|
||||
HEAD = ft_printf.h
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra -O3
|
||||
|
||||
CPPFLAGS = -I .
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
ar rcs $(NAME) $(OBJ) *.o
|
||||
ranlib $(NAME)
|
||||
|
||||
%.o : %.c $(HEAD)
|
||||
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
|
||||
|
||||
norm:
|
||||
norminette $(SRC) $(HEAD) | grep -B1 "Error*"
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
|
||||
debug: CFLAGS += -g
|
||||
debug: re
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re norm debug
|
||||
.SILENT: $(OBJ) $(NAME) all clean fclean re
|
13
libft/printf/buf_cnt.c
Normal file
13
libft/printf/buf_cnt.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* buf_cnt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/24 13:03:33 by igarbuz #+# #+# */
|
||||
/* Updated: 2019/01/24 13:03:39 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int g_bcn = 0;
|
66
libft/printf/ft_argcast.c
Normal file
66
libft/printf/ft_argcast.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_argcast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/24 13:03:50 by igarbuz #+# #+# */
|
||||
/* Updated: 2019/01/24 13:03:56 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
static intmax_t ft_arg_cast_c(va_list valist)
|
||||
{
|
||||
return (va_arg(valist, int));
|
||||
}
|
||||
|
||||
static intmax_t ft_arg_cast_s(va_list valist)
|
||||
{
|
||||
return (va_arg(valist, intptr_t));
|
||||
}
|
||||
|
||||
static intmax_t ft_arg_cast_i(va_list valist, int p)
|
||||
{
|
||||
if (p >> 8 & 1)
|
||||
return (va_arg(valist, long long int));
|
||||
else if (p >> 7 & 1)
|
||||
return (va_arg(valist, long int));
|
||||
else if (p >> 6 & 1)
|
||||
return ((short int)va_arg(valist, int));
|
||||
else if (p >> 5 & 1)
|
||||
return ((signed char)va_arg(valist, int));
|
||||
else
|
||||
return (va_arg(valist, int));
|
||||
}
|
||||
|
||||
static intmax_t ft_arg_cast_u(va_list valist, int p)
|
||||
{
|
||||
if (p >> 8 & 1)
|
||||
return (va_arg(valist, unsigned long long int));
|
||||
else if (p >> 7 & 1)
|
||||
return (va_arg(valist, unsigned long int));
|
||||
else if (p >> 6 & 1)
|
||||
return ((unsigned short int)va_arg(valist, int));
|
||||
else if (p >> 5 & 1)
|
||||
return ((unsigned char)va_arg(valist, int));
|
||||
else
|
||||
return (va_arg(valist, unsigned int));
|
||||
}
|
||||
|
||||
intmax_t ft_arg_cast(va_list valist, int p, const char c)
|
||||
{
|
||||
if (c == 'c')
|
||||
return (ft_arg_cast_c(valist));
|
||||
else if (c == 's')
|
||||
return (ft_arg_cast_s(valist));
|
||||
else if (c == 'd' || c == 'i')
|
||||
return (ft_arg_cast_i(valist, p));
|
||||
else if (c == 'u' || c == 'o' || c == 'x' || c == 'X')
|
||||
return (ft_arg_cast_u(valist, p));
|
||||
else if (c == 'p')
|
||||
return (ft_arg_cast_u(valist, 0x100));
|
||||
return (0);
|
||||
}
|
74
libft/printf/ft_arglen.c
Normal file
74
libft/printf/ft_arglen.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_arglen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/24 13:04:12 by igarbuz #+# #+# */
|
||||
/* Updated: 2019/01/24 13:04:16 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
static int ft_unbrlen(uintmax_t n)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
while (n && n > 9)
|
||||
{
|
||||
n = n / 10;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
static int ft_snbrlen(intmax_t n)
|
||||
{
|
||||
if (n < 0)
|
||||
return (ft_unbrlen(-n));
|
||||
return (ft_unbrlen(n));
|
||||
}
|
||||
|
||||
static int ft_hexlen(uintmax_t x)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
while (x > 15)
|
||||
{
|
||||
x = (x >> 4);
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
/*
|
||||
** For string length, if an argument is an integer Zero, "(null)" is printed
|
||||
** that corresponds to below returned precision of 6;
|
||||
*/
|
||||
|
||||
int ft_arg_len(intmax_t arg, char c, t_param *prm)
|
||||
{
|
||||
if (c == 'c' || c == '%')
|
||||
return (1);
|
||||
else if (!arg && !prm->prc && c != 'o')
|
||||
return (0);
|
||||
else if (c == 'd' || c == 'i')
|
||||
return (ft_snbrlen((intmax_t)arg));
|
||||
else if (c == 'u')
|
||||
return (ft_unbrlen((uintmax_t)arg));
|
||||
else if (c == 'o')
|
||||
return (ft_arg_len_oct(arg, prm));
|
||||
else if (c == 'x' || c == 'X')
|
||||
return (ft_hexlen((uintmax_t)arg));
|
||||
else if (c == 'p')
|
||||
return (ft_hexlen((uintmax_t)arg));
|
||||
else if (c == 's' && prm->p >> 7 & 1)
|
||||
return (ft_strlen_unicode((wchar_t *)arg));
|
||||
else if (c == 's')
|
||||
return (ft_strlen_printf((char *)arg));
|
||||
return (0);
|
||||
}
|
62
libft/printf/ft_arglen_f.c
Normal file
62
libft/printf/ft_arglen_f.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_arglen_f.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/24 13:04:25 by igarbuz #+# #+# */
|
||||
/* Updated: 2019/01/24 13:04:30 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
int ft_fract_len(const char *f)
|
||||
{
|
||||
const char *t;
|
||||
|
||||
t = f;
|
||||
while (*t && *t != '.')
|
||||
t++;
|
||||
f = t + 1;
|
||||
while (*t)
|
||||
t++;
|
||||
return (t - f);
|
||||
}
|
||||
|
||||
int ft_arg_db_len(const char *s, int p, double *arg)
|
||||
{
|
||||
int len;
|
||||
uintmax_t *ptr;
|
||||
|
||||
ptr = (uintmax_t *)arg;
|
||||
len = ft_strlen_printf(s);
|
||||
if ((p & 1) || (p >> 3 & 1) || (*ptr >> 63))
|
||||
len += 1;
|
||||
return (len);
|
||||
}
|
||||
|
||||
int ft_arg_long_db_len(const char *s, int p, long double *arg)
|
||||
{
|
||||
int len;
|
||||
uintmax_t *ptr;
|
||||
|
||||
ptr = (uintmax_t *)arg;
|
||||
len = ft_strlen_printf(s);
|
||||
if ((p & 1) || (p >> 3 & 1) || (ptr[1] >> 15) & 1)
|
||||
len += 1;
|
||||
return (len);
|
||||
}
|
||||
|
||||
int ft_arg_flen(intmax_t arg, char c, int p, int len)
|
||||
{
|
||||
if ((c == 'i' || c == 'd')
|
||||
&& (arg < 0 || (arg >= 0 && (p & 1 || p >> 3 & 1))))
|
||||
return (len + 1);
|
||||
if ((c == 'x' || c == 'X') && (p >> 2 & 1) && arg)
|
||||
return (len + 2);
|
||||
else if (c == 'p')
|
||||
return (len + 2);
|
||||
return (len);
|
||||
}
|
35
libft/printf/ft_arglen_oct.c
Normal file
35
libft/printf/ft_arglen_oct.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_arglen_oct.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/29 19:52:21 by igarbuz #+# #+# */
|
||||
/* Updated: 2019/01/29 19:52:25 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
static int ft_octlen(uintmax_t o)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
while (o > 7)
|
||||
{
|
||||
o = (o >> 3);
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
int ft_arg_len_oct(intmax_t arg, t_param *prm)
|
||||
{
|
||||
if (arg && prm->prc)
|
||||
return (ft_octlen((uintmax_t)arg) + (prm->p >> 2 & 1));
|
||||
else if (!arg && !prm->prc && !(prm->p >> 2 & 1))
|
||||
return (0);
|
||||
return (ft_octlen((uintmax_t)arg));
|
||||
}
|
58
libft/printf/ft_buf_print_db.c
Normal file
58
libft/printf/ft_buf_print_db.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_buf_print_db.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/29 20:37:10 by igarbuz #+# #+# */
|
||||
/* Updated: 2019/01/29 20:37:15 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
static void ft_sprint(int up, char **p, uint32_t u, int r)
|
||||
{
|
||||
while (up >= r)
|
||||
{
|
||||
**p = (u / g_pow10[up]) % 10 + 48U;
|
||||
(*p)++;
|
||||
up--;
|
||||
}
|
||||
}
|
||||
|
||||
static void ft_print_hi(t_nd *nd, char **p)
|
||||
{
|
||||
ft_sprint(ft_exp_dec(nd->n[nd->hi]), p, nd->n[nd->hi & 127], 0);
|
||||
while (--(nd->hi) >= 0)
|
||||
ft_sprint(8, p, nd->n[nd->hi & 127], 0);
|
||||
}
|
||||
|
||||
static void ft_print_lo(t_nd *nd, char **p, int r)
|
||||
{
|
||||
int rloc;
|
||||
|
||||
rloc = r % 9;
|
||||
while (nd->hi > nd->lo || (!rloc && nd->hi >= nd->lo))
|
||||
{
|
||||
ft_sprint(8, p, nd->n[nd->hi & 127], 0);
|
||||
nd->hi--;
|
||||
}
|
||||
if (rloc && -nd->lo * 9 >= r)
|
||||
ft_sprint(8, p, nd->n[nd->hi & 127], 9 - rloc);
|
||||
}
|
||||
|
||||
char *ft_buf_print_db(t_nd *nd, int r, char *tbl)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = tbl;
|
||||
if (nd->hi && !nd->n[nd->hi])
|
||||
nd->hi--;
|
||||
ft_print_hi(nd, &p);
|
||||
*p++ = '.';
|
||||
ft_print_lo(nd, &p, r);
|
||||
*p = '\0';
|
||||
return (tbl);
|
||||
}
|
58
libft/printf/ft_buf_print_ldb.c
Normal file
58
libft/printf/ft_buf_print_ldb.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_buf_print_ldb.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/29 20:08:18 by igarbuz #+# #+# */
|
||||
/* Updated: 2019/01/29 20:08:21 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
static void ft_sprint(int up, char **p, uint32_t u, int r)
|
||||
{
|
||||
while (up >= r)
|
||||
{
|
||||
**p = (u / g_pow10[up]) % 10 + 48U;
|
||||
(*p)++;
|
||||
up--;
|
||||
}
|
||||
}
|
||||
|
||||
static void ft_print_hi(t_nd_long *nd, char **p)
|
||||
{
|
||||
ft_sprint(ft_exp_dec(nd->n[nd->hi]), p, nd->n[nd->hi & 2047], 0);
|
||||
while (--(nd->hi) >= 0)
|
||||
ft_sprint(8, p, nd->n[nd->hi & 2047], 0);
|
||||
}
|
||||
|
||||
static void ft_print_lo(t_nd_long *nd, char **p, int r)
|
||||
{
|
||||
int rloc;
|
||||
|
||||
rloc = r % 9;
|
||||
while (nd->hi > nd->lo || (!rloc && nd->hi >= nd->lo))
|
||||
{
|
||||
ft_sprint(8, p, nd->n[nd->hi & 2047], 0);
|
||||
nd->hi--;
|
||||
}
|
||||
if (rloc && -nd->lo * 9 >= r)
|
||||
ft_sprint(8, p, nd->n[nd->hi & 2047], 9 - rloc);
|
||||
}
|
||||
|
||||
char *ft_buf_print_ldb(t_nd_long *nd, int r, char *tbl)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = tbl;
|
||||
while (nd->hi && !nd->n[nd->hi])
|
||||
nd->hi--;
|
||||
ft_print_hi(nd, &p);
|
||||
*p++ = '.';
|
||||
ft_print_lo(nd, &p, r);
|
||||
*p = '\0';
|
||||
return (tbl);
|
||||
}
|
25
libft/printf/ft_error.c
Normal file
25
libft/printf/ft_error.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pf_error.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/24 13:04:44 by igarbuz #+# #+# */
|
||||
/* Updated: 2019/01/24 13:04:48 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
void pf_error(int er)
|
||||
{
|
||||
if (er < 0)
|
||||
{
|
||||
if (er == -1)
|
||||
;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
write(1, "usage : pf_error(int er), er < 0\n", 33);
|
||||
}
|
27
libft/printf/ft_exp_dec.c
Normal file
27
libft/printf/ft_exp_dec.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_exp_dec.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/24 13:04:55 by igarbuz #+# #+# */
|
||||
/* Updated: 2019/01/24 13:04:59 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_exp_dec(unsigned int value)
|
||||
{
|
||||
int exponent;
|
||||
|
||||
exponent = 0;
|
||||
if (value >= 10000 && (value /= 10000))
|
||||
exponent += 4;
|
||||
if (value >= 1000 && (value /= 1000))
|
||||
exponent += 3;
|
||||
if (value >= 100 && (value /= 100))
|
||||
exponent += 2;
|
||||
if (value >= 10 && (value /= 10))
|
||||
exponent += 1;
|
||||
return (exponent);
|
||||
}
|
26
libft/printf/ft_init_param.c
Normal file
26
libft/printf/ft_init_param.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_init_param.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/24 13:05:18 by igarbuz #+# #+# */
|
||||
/* Updated: 2019/01/24 13:05:20 by igarbuz ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
void ft_init_param(t_param *prm)
|
||||
{
|
||||
prm->p = 0;
|
||||
prm->prc = -1;
|
||||
prm->wdt = -1;
|
||||
}
|
||||
|
||||
void ft_init_nd(t_nd *nd)
|
||||
{
|
||||
nd->hi = 0;
|
||||
nd->lo = 0;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user