new structure to pass to 42filechecker
This commit is contained in:
parent
7edaabc3a1
commit
995261de4e
79 changed files with 1935 additions and 109 deletions
1
fillit/.gitignore
vendored
1
fillit/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
|||
fillit
|
||||
23
fillit/.tags
23
fillit/.tags
|
|
@ -1,23 +0,0 @@
|
|||
Mmain src/main.c /^int main(int ac, char **av)$/
|
||||
ft_board_add src/lib_board2.c /^int ft_board_add(char **board, t_ttmn ttmn, int i/
|
||||
ft_board_copy src/lib_board.c /^char **ft_board_copy(char **board)$/
|
||||
ft_board_fill src/lib_board.c /^void ft_board_fill(char **dst, char **src)$/
|
||||
ft_board_free src/lib_board2.c /^void ft_board_free(char ***board)$/
|
||||
ft_board_init src/lib_board.c /^char **ft_board_init(size_t size)$/
|
||||
ft_board_print src/lib_board.c /^void ft_board_print(char **board)$/
|
||||
ft_board_remove src/lib_board2.c /^void ft_board_remove(char **board, char c)$/
|
||||
ft_board_replace src/lib_board2.c /^void ft_board_replace(char **board, char a, char b/
|
||||
ft_check_waste src/fillit_check_waste.c /^int ft_check_waste(char **board, t_list *lttmn, i/
|
||||
ft_fit_blob src/fillit_fit_blob.c /^int ft_fit_blob(char **board, t_list *lttmn, int /
|
||||
ft_floodfill_recursive src/floodfill.c /^int ft_floodfill_recursive(char **board, int size/
|
||||
ft_floodfill_stack src/floodfill.c /^int ft_floodfill_stack(char **board, int size, in/
|
||||
ft_parse src/fillit_parser.c /^t_list *ft_parse(char *filename)$/
|
||||
ft_parse_addttmn src/fillit_parser.c /^int ft_parse_addttmn(int *j, int *k, t_ttmn ttmn,/
|
||||
ft_parse_line src/fillit_parser.c /^int ft_parse_line(char *line, int linenumber, t_l/
|
||||
ft_parse_sharp src/fillit_parser.c /^int ft_parse_sharp(int *j, int *k, t_ttmn *ttmn)$/
|
||||
ft_solved src/fillit_solver.c /^int ft_solved(char **board)$/
|
||||
ft_solver src/fillit_solver.c /^int ft_solver(char **board, t_list *lttmn, int sp/
|
||||
ft_ttmn_print src/lib_ttmn.c /^void ft_ttmn_print(t_ttmn ttmn)$/
|
||||
ft_ttmn_reset src/lib_ttmn.c /^void ft_ttmn_reset(t_list *ttmn)$/
|
||||
ft_ttmn_validate src/lib_ttmn.c /^int ft_ttmn_validate(t_ttmn ttmn)$/
|
||||
ft_usage src/main.c /^void ft_usage(void)$/
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
language: C
|
||||
script: make
|
||||
|
|
@ -1,16 +1,14 @@
|
|||
NAME = fillit
|
||||
CC = gcc
|
||||
TAGFILE = .tags
|
||||
|
||||
D_SRC = src
|
||||
F_SRC := $(shell ls -1 $(D_SRC) | grep "\.c$$")
|
||||
DF_SRC := $(addprefix $(D_SRC)/, $(F_SRC))
|
||||
F_SRC := $(shell find $(D_SRC) -type f -regex ".*\.c$$")
|
||||
|
||||
D_OBJ = obj
|
||||
F_OBJ = $(F_SRC:.c=.o)
|
||||
F_OBJ = $(notdir $(F_SRC:.c=.o))
|
||||
DF_OBJ := $(addprefix $(D_OBJ)/, $(F_OBJ))
|
||||
|
||||
D_INC = includes libft/includes
|
||||
D_INC = includes
|
||||
O_INC = $(addprefix -I, $(D_INC))
|
||||
|
||||
W_FLAGS = -Wall -Wextra -Werror
|
||||
|
|
@ -19,27 +17,17 @@ D_FLAGS =
|
|||
MKDIR = mkdir -p
|
||||
RM = /bin/rm -rf
|
||||
|
||||
.PHONY: all clean fclean re tags test
|
||||
.PHONY: all clean fclean re
|
||||
|
||||
all: libft/libft.a $(NAME) $(TAGFILE)
|
||||
all: $(NAME)
|
||||
|
||||
test: all
|
||||
cd fillit-tests && ./test 2
|
||||
|
||||
$(TAGFILE): $(D_SRC)/*.c
|
||||
@ctags -f $(TAGFILE) $(addprefix $(D_SRC)/, $(F_SRC))
|
||||
@echo "Making tags..."
|
||||
|
||||
$(D_OBJ)/%.o: $(D_SRC)/%.c $(D_INC)
|
||||
$(D_OBJ)/%.o: $(D_SRC)/*/%.c $(D_INC)
|
||||
@$(MKDIR) $(D_OBJ)
|
||||
@$(CC) $(O_INC) $(W_FLAGS) -c $< -o $@ $(D_FLAGS)
|
||||
@echo "Compiling "$<"..."
|
||||
|
||||
libft/libft.a:
|
||||
@$(MAKE) -C libft/ 2>/dev/null
|
||||
|
||||
$(NAME): $(DF_OBJ)
|
||||
$(CC) $(O_INC) -Llibft -lft $(W_FLAGS) $(DF_OBJ) -o $@ $(D_FLAGS)
|
||||
$(CC) $(O_INC) $(W_FLAGS) $(DF_OBJ) -o $@ $(D_FLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(D_OBJ)
|
||||
|
|
|
|||
BIN
fillit/fillit
Executable file
BIN
fillit/fillit
Executable file
Binary file not shown.
Binary file not shown.
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:38:16 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:39:41 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/04 14:07:38 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ char **ft_board_copy(char **board);
|
|||
void ft_board_fill(char **dst, char **src);
|
||||
void ft_board_free(char ***board);
|
||||
void ft_board_replace(char **board, char a, char b);
|
||||
void ft_board_remove(char **board, char c);
|
||||
void ft_board_remove(char **board, char *s);
|
||||
int ft_board_add(char **board, t_ttmn ttmn, int i, int size);
|
||||
|
||||
int ft_ttmn_validate(t_ttmn ttmn);
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
../libft/libft.h
|
||||
100
fillit/includes/libft.h
Normal file
100
fillit/includes/libft.h
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 15:00:29 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 13:35:02 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# define FT_SEP(x) (x == ' ' || x == '\t' || x == '\n')
|
||||
# define FT_ABS(x) (((x) < 0) ? -(x) : (x))
|
||||
# define FT_NEG(x) (((x) < 0) ? 1 : 0)
|
||||
# define FT_POS(x) (((x) > 0) ? 1 : 0)
|
||||
# define FT_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
# define FT_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
# define FT_DIST(a, b) (FT_ABS((a) - (b)))
|
||||
|
||||
struct s_list
|
||||
{
|
||||
void *content;
|
||||
size_t content_size;
|
||||
struct s_list *next;
|
||||
};
|
||||
|
||||
typedef struct s_list t_list;
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_memcpy(void *dst, const void *src, size_t n);
|
||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
|
||||
void *ft_memmove(void *dst, const void *src, size_t len);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
size_t ft_strlen(const char *s);
|
||||
char *ft_strdup(const char *s1);
|
||||
char *ft_strcpy(char *dst, const char *src);
|
||||
char *ft_strncpy(char *dst, const char *src, size_t len);
|
||||
char *ft_strcat(char *s1, const char *s2);
|
||||
char *ft_strncat(char *s1, const char *s2, size_t n);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char *ft_strstr(const char *big, const char *little);
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
int ft_atoi(const char *str);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_toupper(int c);
|
||||
int ft_tolower(int c);
|
||||
|
||||
void *ft_memalloc(size_t size);
|
||||
void ft_memdel(void **ap);
|
||||
char *ft_strnew(size_t size);
|
||||
void ft_strdel(char **as);
|
||||
void ft_strclr(char *s);
|
||||
void ft_striter(char *s, void (*f)(char *));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
||||
char *ft_strmap(char const *s, char (*f)(char));
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
int ft_strequ(char const *s1, char const *s2);
|
||||
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
||||
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strtrim(char const *s);
|
||||
char **ft_strsplit(char const *s, char c);
|
||||
char *ft_itoa(int n);
|
||||
void ft_putchar(char c);
|
||||
void ft_putstr(char const *s);
|
||||
void ft_putendl(char const *s);
|
||||
void ft_putnbr(int n);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char const *s, int fd);
|
||||
void ft_putendl_fd(char const *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
|
||||
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);
|
||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
||||
|
||||
void ft_lsteadd(t_list **alst, t_list *new);
|
||||
int ft_lstsize(t_list *lst);
|
||||
int get_next_line(int const fd, char **line);
|
||||
#endif
|
||||
54
fillit/src/fillit/fillit_check_waste.c
Normal file
54
fillit/src/fillit/fillit_check_waste.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fillit_check_waste.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 13:24:35 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 13:30:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
int ft_check_waste(char **board, t_list *lttmn, int space, int size)
|
||||
{
|
||||
t_ttmn *ttmn;
|
||||
int i;
|
||||
int blob_size;
|
||||
|
||||
if (!lttmn)
|
||||
return (ft_solved(board));
|
||||
ttmn = (t_ttmn *)lttmn->content;
|
||||
if (ttmn->placed)
|
||||
return (ft_solver(board, lttmn->next, space, size));
|
||||
space = size * size - 4 * g_ttmn;
|
||||
i = -1;
|
||||
while (++i < size * size)
|
||||
{
|
||||
if (board[i / size][i % size] != '.')
|
||||
continue ;
|
||||
ft_board_replace(board, '*', '^');
|
||||
blob_size = ft_floodfill_recursive(board, size, i, '*');
|
||||
space -= blob_size % 4;
|
||||
if (space < 0)
|
||||
{
|
||||
ft_board_remove(board, "^*");
|
||||
return (0);
|
||||
}
|
||||
if (blob_size / 4 == 1)
|
||||
{
|
||||
if (ft_fit_blob(board, lttmn, space, size, blob_size, i))
|
||||
return (1);
|
||||
space -= 4;
|
||||
if (space < 0)
|
||||
{
|
||||
ft_board_remove(board, "^*");
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
ft_board_remove(board, "^*");
|
||||
return (ft_solver(board, lttmn, space, size));
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:29:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:31:00 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/04 13:48:55 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ t_list *ft_parse(char *filename)
|
|||
}
|
||||
if (ft_parse_line("", linenumber, &list))
|
||||
return (0);
|
||||
g_target = 4;
|
||||
g_target = 3;
|
||||
g_ttmn = ft_lstsize(list);
|
||||
while ((g_ttmn * 4) > (g_target) * (g_target))
|
||||
g_target++;
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:36:27 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:38:05 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/04 13:49:41 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
int ft_solved(char **board)
|
||||
{
|
||||
ft_board_remove(board, '^');
|
||||
ft_board_remove(board, '*');
|
||||
ft_board_remove(board, "^*");
|
||||
g_sol = ft_board_copy(board);
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -37,7 +36,7 @@ int ft_solver(char **board, t_list *lttmn, int space, int size)
|
|||
continue ;
|
||||
if (ft_check_waste(board, lttmn->next, space, size))
|
||||
return (1);
|
||||
ft_board_remove(board, ttmn->id);
|
||||
ft_board_remove(board, &ttmn->id);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:34:39 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:35:39 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/04 13:25:08 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:31:46 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:31:51 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/04 13:38:18 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -71,19 +71,23 @@ void ft_board_replace(char **board, char a, char b)
|
|||
}
|
||||
}
|
||||
|
||||
void ft_board_remove(char **board, char c)
|
||||
void ft_board_remove(char **board, char *s)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = -1;
|
||||
while (board[++i])
|
||||
while (*s)
|
||||
{
|
||||
j = -1;
|
||||
while (board[i][++j])
|
||||
i = -1;
|
||||
while (board[++i])
|
||||
{
|
||||
if (board[i][j] == c)
|
||||
board[i][j] = '.';
|
||||
j = -1;
|
||||
while (board[i][++j])
|
||||
{
|
||||
if (board[i][j] == *s)
|
||||
board[i][j] = '.';
|
||||
}
|
||||
}
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:31:13 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:37:59 by jhalford ### ########.fr */
|
||||
/* Updated: 2016/11/04 13:48:23 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
#include "fillit.h"
|
||||
|
||||
int ft_check_waste(char **board, t_list *lttmn, int space, int size)
|
||||
{
|
||||
t_ttmn *ttmn;
|
||||
int i;
|
||||
int blob_size;
|
||||
|
||||
if (!lttmn)
|
||||
return (ft_solved(board));
|
||||
ttmn = (t_ttmn *)lttmn->content;
|
||||
if (ttmn->placed)
|
||||
return (ft_solver(board, lttmn->next, space, size));
|
||||
space = size * size - 4 * g_ttmn;
|
||||
i = -1;
|
||||
while (++i < size * size)
|
||||
{
|
||||
if (board[i / size][i % size] != '.')
|
||||
continue ;
|
||||
ft_board_replace(board, '*', '^');
|
||||
blob_size = ft_floodfill_recursive(board, size, i, '*');
|
||||
space -= blob_size % 4;
|
||||
if (space < 0)
|
||||
{
|
||||
ft_board_remove(board, '^');
|
||||
ft_board_remove(board, '*');
|
||||
return (0);
|
||||
}
|
||||
if (blob_size / 4 == 1)
|
||||
{
|
||||
if (ft_fit_blob(board, lttmn, space, size, blob_size, i))
|
||||
return (1);
|
||||
space -= 4;
|
||||
if (space < 0)
|
||||
{
|
||||
ft_board_remove(board, '^');
|
||||
ft_board_remove(board, '*');
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
ft_board_remove(board, '^');
|
||||
ft_board_remove(board, '*');
|
||||
return (ft_solver(board, lttmn, space, size));
|
||||
}
|
||||
49
fillit/src/libft/ft_atoi.c
Normal file
49
fillit/src/libft/ft_atoi.c
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:13:04 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_iswhitespace(char c)
|
||||
{
|
||||
if (c == ' ' || c == '\t' || c == '\n')
|
||||
return (1);
|
||||
else if (c == '\v' || c == '\f' || c == '\r')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
int i;
|
||||
int res;
|
||||
int sign;
|
||||
|
||||
i = 0;
|
||||
res = 0;
|
||||
sign = 1;
|
||||
while (ft_iswhitespace(str[i]))
|
||||
i++;
|
||||
if (str[i] == '-' || str[i] == '+')
|
||||
{
|
||||
if (str[i + 1] >= '0' && str[i + 1] <= '9')
|
||||
{
|
||||
sign = (str[i] == '+') ? 1 : -1;
|
||||
i++;
|
||||
}
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
res = res * 10 + str[i++] - '0';
|
||||
res *= sign;
|
||||
return (res);
|
||||
}
|
||||
22
fillit/src/libft/ft_bzero.c
Normal file
22
fillit/src/libft/ft_bzero.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:56:08 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:56:09 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = -1;
|
||||
while (++i < n)
|
||||
*(char *)s++ = 0;
|
||||
}
|
||||
22
fillit/src/libft/ft_isalnum.c
Normal file
22
fillit/src/libft/ft_isalnum.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:56:18 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:31:33 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z')
|
||||
|| (c >= 'A' && c <= 'Z')
|
||||
|| (c >= '0' && c <= '9'))
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
20
fillit/src/libft/ft_isalpha.c
Normal file
20
fillit/src/libft/ft_isalpha.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:56:24 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:32:00 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
20
fillit/src/libft/ft_isascii.c
Normal file
20
fillit/src/libft/ft_isascii.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:56:28 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:35:42 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
23
fillit/src/libft/ft_isdigit.c
Normal file
23
fillit/src/libft/ft_isdigit.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:56:33 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:56:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
unsigned char a;
|
||||
|
||||
a = (unsigned char)c;
|
||||
if (a >= '0' && a <= '9')
|
||||
return (a);
|
||||
return (0);
|
||||
}
|
||||
20
fillit/src/libft/ft_isprint.c
Normal file
20
fillit/src/libft/ft_isprint.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:56:38 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:32:40 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
69
fillit/src/libft/ft_itoa.c
Normal file
69
fillit/src/libft/ft_itoa.c
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:10 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:27:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static char *ft_strrev(char *str)
|
||||
{
|
||||
int len;
|
||||
char tmp;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
len = 0;
|
||||
while (str[len] != '\0')
|
||||
len++;
|
||||
while (i < len / 2)
|
||||
{
|
||||
tmp = str[len - (i + 1)];
|
||||
str[len - (i + 1)] = str[i];
|
||||
str[i] = tmp;
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
static size_t ft_size(int n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 1;
|
||||
while (n /= 10)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
int neg;
|
||||
|
||||
i = 0;
|
||||
str = ft_strnew(ft_size(n) + 1);
|
||||
neg = FT_NEG(n) ? 1 : 0;
|
||||
if (n == 0)
|
||||
{
|
||||
str[i++] = '0';
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
||||
while (n)
|
||||
{
|
||||
str[i++] = FT_ABS(n % 10) + '0';
|
||||
n /= 10;
|
||||
}
|
||||
if (neg)
|
||||
str[i++] = '-';
|
||||
str[i] = '\0';
|
||||
return (ft_strrev(str));
|
||||
}
|
||||
22
fillit/src/libft/ft_lstadd.c
Normal file
22
fillit/src/libft/ft_lstadd.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:13 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 11:09:44 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd(t_list **alst, t_list *new)
|
||||
{
|
||||
if (new)
|
||||
{
|
||||
new->next = *alst;
|
||||
*alst = new;
|
||||
}
|
||||
}
|
||||
20
fillit/src/libft/ft_lstdel.c
Normal file
20
fillit/src/libft/ft_lstdel.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 16:40:21 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
if ((*alst)->next)
|
||||
ft_lstdel(&(*alst)->next, del);
|
||||
ft_lstdelone(&(*alst), del);
|
||||
}
|
||||
24
fillit/src/libft/ft_lstdelone.c
Normal file
24
fillit/src/libft/ft_lstdelone.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:15:51 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
if (*alst)
|
||||
{
|
||||
if (del)
|
||||
(*del)((*alst)->content, (*alst)->content_size);
|
||||
free(*alst);
|
||||
}
|
||||
*alst = NULL;
|
||||
}
|
||||
28
fillit/src/libft/ft_lsteadd.c
Normal file
28
fillit/src/libft/ft_lsteadd.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lsteadd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:17 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 13:18:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lsteadd(t_list **alst, t_list *new)
|
||||
{
|
||||
t_list *lst;
|
||||
|
||||
lst = *alst;
|
||||
if (lst)
|
||||
{
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
lst->next = new;
|
||||
}
|
||||
else
|
||||
*alst = new;
|
||||
}
|
||||
22
fillit/src/libft/ft_lstiter.c
Normal file
22
fillit/src/libft/ft_lstiter.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:19 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem))
|
||||
{
|
||||
while (lst)
|
||||
{
|
||||
(*f)(lst);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
29
fillit/src/libft/ft_lstmap.c
Normal file
29
fillit/src/libft/ft_lstmap.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 13:20:12 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
||||
{
|
||||
t_list *out;
|
||||
t_list *elem;
|
||||
|
||||
out = NULL;
|
||||
while (lst)
|
||||
{
|
||||
elem = (*f)(lst);
|
||||
elem = ft_lstnew(elem->content, elem->content_size);
|
||||
ft_lsteadd(&out, elem);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (out);
|
||||
}
|
||||
38
fillit/src/libft/ft_lstnew.c
Normal file
38
fillit/src/libft/ft_lstnew.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:24 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size)
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
if (!content)
|
||||
{
|
||||
new = malloc(sizeof(*new));
|
||||
if (!new)
|
||||
return (NULL);
|
||||
new->content_size = 0;
|
||||
new->content = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
new = (t_list *)malloc(sizeof(*new));
|
||||
if (!new)
|
||||
return (NULL);
|
||||
new->content_size = content_size;
|
||||
new->content = ft_memalloc(content_size + 1);
|
||||
ft_memcpy(new->content, content, content_size);
|
||||
}
|
||||
new->next = NULL;
|
||||
return (new);
|
||||
}
|
||||
30
fillit/src/libft/ft_lstsize.c
Normal file
30
fillit/src/libft/ft_lstsize.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lst_size.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 11:09:35 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 13:18:17 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (lst)
|
||||
{
|
||||
i = 1;
|
||||
while (lst->next)
|
||||
{
|
||||
lst = lst->next;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
27
fillit/src/libft/ft_memalloc.c
Normal file
27
fillit/src/libft/ft_memalloc.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memalloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:25 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memalloc(size_t size)
|
||||
{
|
||||
void *addr;
|
||||
size_t i;
|
||||
|
||||
addr = malloc(size);
|
||||
if (addr == NULL)
|
||||
return (NULL);
|
||||
i = -1;
|
||||
while (++i < size)
|
||||
((char *)addr)[i] = 0;
|
||||
return (addr);
|
||||
}
|
||||
27
fillit/src/libft/ft_memccpy.c
Normal file
27
fillit/src/libft/ft_memccpy.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memccpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:26 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:36:05 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = -1;
|
||||
while (++i < n)
|
||||
{
|
||||
*(char *)dst++ = *(char *)src;
|
||||
if (*(char *)src++ == c)
|
||||
return (dst);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
29
fillit/src/libft/ft_memchr.c
Normal file
29
fillit/src/libft/ft_memchr.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:28 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
void *a;
|
||||
size_t i;
|
||||
|
||||
i = -1;
|
||||
a = (unsigned char *)s;
|
||||
while (++i < n)
|
||||
{
|
||||
if (*(unsigned char *)a == (unsigned char)c)
|
||||
return (a);
|
||||
a++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
28
fillit/src/libft/ft_memcmp.c
Normal file
28
fillit/src/libft/ft_memcmp.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:30 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:44:21 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
int cmp;
|
||||
|
||||
i = -1;
|
||||
while (++i < n)
|
||||
{
|
||||
cmp = *(unsigned char *)s1++ - *(unsigned char *)s2++;
|
||||
if (cmp)
|
||||
return (cmp);
|
||||
}
|
||||
return (cmp);
|
||||
}
|
||||
28
fillit/src/libft/ft_memcpy.c
Normal file
28
fillit/src/libft/ft_memcpy.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:31 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:32 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
char *c1;
|
||||
char *c2;
|
||||
|
||||
if (n == 0 || dst == src)
|
||||
return (dst);
|
||||
c1 = (char *)dst;
|
||||
c2 = (char *)src;
|
||||
while (--n)
|
||||
*c1++ = *c2++;
|
||||
*c1 = *c2;
|
||||
return (dst);
|
||||
}
|
||||
19
fillit/src/libft/ft_memdel.c
Normal file
19
fillit/src/libft/ft_memdel.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:33 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_memdel(void **ap)
|
||||
{
|
||||
free(*ap);
|
||||
*ap = NULL;
|
||||
}
|
||||
31
fillit/src/libft/ft_memmove.c
Normal file
31
fillit/src/libft/ft_memmove.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:34 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:53:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dst, const void *src, size_t len)
|
||||
{
|
||||
char *srcc;
|
||||
char *dstc;
|
||||
size_t i;
|
||||
|
||||
i = -1;
|
||||
srcc = (char *)src;
|
||||
dstc = (char *)dst;
|
||||
if (srcc < dstc)
|
||||
while ((int)(--len) >= 0)
|
||||
*(dstc + len) = *(srcc + len);
|
||||
else
|
||||
while (++i < len)
|
||||
*(dstc + i) = *(srcc + i);
|
||||
return (dst);
|
||||
}
|
||||
23
fillit/src/libft/ft_memset.c
Normal file
23
fillit/src/libft/ft_memset.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:36 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:36 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = -1;
|
||||
while (++i < len)
|
||||
((unsigned char *)b)[i] = (unsigned char)c;
|
||||
return (b);
|
||||
}
|
||||
18
fillit/src/libft/ft_putchar.c
Normal file
18
fillit/src/libft/ft_putchar.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:37 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:38 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
18
fillit/src/libft/ft_putchar_fd.c
Normal file
18
fillit/src/libft/ft_putchar_fd.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:39 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:39 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
22
fillit/src/libft/ft_putendl.c
Normal file
22
fillit/src/libft/ft_putendl.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:40 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:41 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl(char const *s)
|
||||
{
|
||||
char nl;
|
||||
|
||||
nl = '\n';
|
||||
write(1, s, ft_strlen(s));
|
||||
write(1, &nl, 1);
|
||||
}
|
||||
22
fillit/src/libft/ft_putendl_fd.c
Normal file
22
fillit/src/libft/ft_putendl_fd.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:42 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:42 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char const *s, int fd)
|
||||
{
|
||||
char nl;
|
||||
|
||||
nl = '\n';
|
||||
write(fd, s, ft_strlen(s));
|
||||
write(fd, &nl, 1);
|
||||
}
|
||||
30
fillit/src/libft/ft_putnbr.c
Normal file
30
fillit/src/libft/ft_putnbr.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/02 21:25:03 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/04 21:28:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr(int n)
|
||||
{
|
||||
if (n == -2147483648)
|
||||
{
|
||||
ft_putchar('-');
|
||||
ft_putchar('2');
|
||||
ft_putnbr(147483648);
|
||||
return ;
|
||||
}
|
||||
else if (n < 0)
|
||||
ft_putchar('-');
|
||||
n = FT_ABS(n);
|
||||
if (n >= 10)
|
||||
ft_putnbr(n / 10);
|
||||
ft_putchar(n % 10 + '0');
|
||||
}
|
||||
30
fillit/src/libft/ft_putnbr_fd.c
Normal file
30
fillit/src/libft/ft_putnbr_fd.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/02 21:25:03 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/04 21:28:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
if (n == -2147483648)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
ft_putchar_fd('2', fd);
|
||||
ft_putnbr_fd(147483648, fd);
|
||||
return ;
|
||||
}
|
||||
else if (n < 0)
|
||||
ft_putchar_fd('-', fd);
|
||||
n = FT_ABS(n);
|
||||
if (n >= 10)
|
||||
ft_putnbr_fd(n / 10, fd);
|
||||
ft_putchar_fd(n % 10 + '0', fd);
|
||||
}
|
||||
18
fillit/src/libft/ft_putstr.c
Normal file
18
fillit/src/libft/ft_putstr.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/03 16:13:07 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/25 17:03:59 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr(char const *s)
|
||||
{
|
||||
write(1, s, ft_strlen(s));
|
||||
}
|
||||
18
fillit/src/libft/ft_putstr_fd.c
Normal file
18
fillit/src/libft/ft_putstr_fd.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:48 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:49 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char const *s, int fd)
|
||||
{
|
||||
write(fd, s, ft_strlen(s));
|
||||
}
|
||||
29
fillit/src/libft/ft_strcat.c
Normal file
29
fillit/src/libft/ft_strcat.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 10:56:53 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/20 23:16:44 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcat(char *s1, const char *s2)
|
||||
{
|
||||
size_t size;
|
||||
size_t j;
|
||||
|
||||
size = ft_strlen(s1);
|
||||
j = 0;
|
||||
while (s2[j] != '\0')
|
||||
{
|
||||
s1[size + j] = s2[j];
|
||||
j++;
|
||||
}
|
||||
s1[size + j] = '\0';
|
||||
return (s1);
|
||||
}
|
||||
29
fillit/src/libft/ft_strchr.c
Normal file
29
fillit/src/libft/ft_strchr.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:53 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:07:30 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
char *a;
|
||||
|
||||
a = (char *)s;
|
||||
while (*a)
|
||||
{
|
||||
if (*a == (char)c)
|
||||
return (a);
|
||||
a++;
|
||||
}
|
||||
if (*a == (char)c)
|
||||
return (a);
|
||||
return (NULL);
|
||||
}
|
||||
24
fillit/src/libft/ft_strclr.c
Normal file
24
fillit/src/libft/ft_strclr.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strclr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:57:54 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:57:55 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_strclr(char *s)
|
||||
{
|
||||
size_t size;
|
||||
size_t i;
|
||||
|
||||
size = ft_strlen(s);
|
||||
i = -1;
|
||||
while (++i < size)
|
||||
s[i] = 0;
|
||||
}
|
||||
25
fillit/src/libft/ft_strcmp.c
Normal file
25
fillit/src/libft/ft_strcmp.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 10:49:02 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:13:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!s1 || !s2)
|
||||
return (0);
|
||||
while (*(s1 + i) && *(s1 + i) == *(s2 + i))
|
||||
i++;
|
||||
return (*((unsigned char*)s1 + i) - *((unsigned char*)s2 + i));
|
||||
}
|
||||
27
fillit/src/libft/ft_strcpy.c
Normal file
27
fillit/src/libft/ft_strcpy.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 10:48:12 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/20 23:37:18 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcpy(char *dst, const char *src)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (src[i] != '\0')
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[i] = '\0';
|
||||
return (dst);
|
||||
}
|
||||
21
fillit/src/libft/ft_strdel.c
Normal file
21
fillit/src/libft/ft_strdel.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:00 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:17:56 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_strdel(char **as)
|
||||
{
|
||||
if (!as || !*as)
|
||||
return ;
|
||||
free(*as);
|
||||
*as = NULL;
|
||||
}
|
||||
31
fillit/src/libft/ft_strdup.c
Normal file
31
fillit/src/libft/ft_strdup.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:01 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:58:02 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s1)
|
||||
{
|
||||
char *dup;
|
||||
int size;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
size = ft_strlen(s1);
|
||||
dup = (char*)malloc(sizeof(*dup) * (size + 1));
|
||||
while (s1[i] != '\0')
|
||||
{
|
||||
dup[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
dup[i] = '\0';
|
||||
return (dup);
|
||||
}
|
||||
18
fillit/src/libft/ft_strequ.c
Normal file
18
fillit/src/libft/ft_strequ.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strequ.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:04 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:13:27 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strequ(char const *s1, char const *s2)
|
||||
{
|
||||
return (ft_strcmp(s1, s2) == 0);
|
||||
}
|
||||
26
fillit/src/libft/ft_striter.c
Normal file
26
fillit/src/libft/ft_striter.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:13 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:29:17 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striter(char *s, void (*f)(char *))
|
||||
{
|
||||
size_t size;
|
||||
size_t i;
|
||||
|
||||
if (!s || !f || !*f)
|
||||
return ;
|
||||
size = ft_strlen(s);
|
||||
i = -1;
|
||||
while (++i < size && *(s + i))
|
||||
(*f)(s + i);
|
||||
}
|
||||
26
fillit/src/libft/ft_striteri.c
Normal file
26
fillit/src/libft/ft_striteri.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:15 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:29:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *))
|
||||
{
|
||||
size_t size;
|
||||
size_t i;
|
||||
|
||||
if (!s || !f || !*f)
|
||||
return ;
|
||||
size = ft_strlen(s);
|
||||
i = -1;
|
||||
while (++i < size && *(s + i))
|
||||
(*f)(i, s + i);
|
||||
}
|
||||
25
fillit/src/libft/ft_strjoin.c
Normal file
25
fillit/src/libft/ft_strjoin.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:18 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:15:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *join;
|
||||
|
||||
if (!s1 || !s2)
|
||||
return (NULL);
|
||||
join = ft_strnew(ft_strlen(s1) + ft_strlen(s2) + 1);
|
||||
ft_strcpy(join, s1);
|
||||
ft_strcat(join, s2);
|
||||
return (join);
|
||||
}
|
||||
31
fillit/src/libft/ft_strlcat.c
Normal file
31
fillit/src/libft/ft_strlcat.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 10:57:16 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/07 21:44:13 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t dst_size;
|
||||
size_t src_size;
|
||||
|
||||
dst_size = ft_strlen(dst);
|
||||
src_size = ft_strlen(src);
|
||||
i = 0;
|
||||
while (src[i] != '\0' && ((dst_size + i) < (size - 1)))
|
||||
{
|
||||
dst[dst_size + i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[dst_size + i] = '\0';
|
||||
return (src_size + ((dst_size < size) ? dst_size : size));
|
||||
}
|
||||
25
fillit/src/libft/ft_strlen.c
Normal file
25
fillit/src/libft/ft_strlen.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:22 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:39:15 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
char *a;
|
||||
|
||||
if (!s || !*s)
|
||||
return (0);
|
||||
a = (char *)s;
|
||||
while (*a)
|
||||
a++;
|
||||
return (a - s);
|
||||
}
|
||||
29
fillit/src/libft/ft_strmap.c
Normal file
29
fillit/src/libft/ft_strmap.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:24 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:58:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmap(char const *s, char (*f)(char))
|
||||
{
|
||||
size_t size;
|
||||
size_t i;
|
||||
char *out;
|
||||
|
||||
size = ft_strlen(s);
|
||||
out = (char *)malloc(sizeof(char) * (size + 1));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = -1;
|
||||
while (++i < size)
|
||||
out[i] = (*f)(s[i]);
|
||||
return (out);
|
||||
}
|
||||
29
fillit/src/libft/ft_strmapi.c
Normal file
29
fillit/src/libft/ft_strmapi.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:28 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:58:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
size_t size;
|
||||
size_t i;
|
||||
char *out;
|
||||
|
||||
size = ft_strlen(s);
|
||||
out = (char *)malloc(sizeof(char) * (size + 1));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = -1;
|
||||
while (++i < size)
|
||||
out[i] = (*f)(i, s[i]);
|
||||
return (out);
|
||||
}
|
||||
29
fillit/src/libft/ft_strncat.c
Normal file
29
fillit/src/libft/ft_strncat.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 10:57:07 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:02:27 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strncat(char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t size;
|
||||
size_t j;
|
||||
|
||||
size = ft_strlen(s1);
|
||||
j = 0;
|
||||
while (s2[j] != '\0' && j < n)
|
||||
{
|
||||
s1[size + j] = s2[j];
|
||||
j++;
|
||||
}
|
||||
s1[size + j] = '\0';
|
||||
return (s1);
|
||||
}
|
||||
28
fillit/src/libft/ft_strncmp.c
Normal file
28
fillit/src/libft/ft_strncmp.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 10:49:12 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:14:09 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!s1 || !s2)
|
||||
return (0);
|
||||
while (*(s1 + i) && *(s1 + i) == *(s2 + i) && i < (int)n)
|
||||
i++;
|
||||
if (i < (int)n)
|
||||
return (*((unsigned char*)s1 + i) - *((unsigned char*)s2 + i));
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
31
fillit/src/libft/ft_strncpy.c
Normal file
31
fillit/src/libft/ft_strncpy.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 10:48:21 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/07 10:48:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strncpy(char *dst, const char *src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (src[i] != '\0' && i < len)
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
while (i < len)
|
||||
{
|
||||
dst[i] = '\0';
|
||||
i++;
|
||||
}
|
||||
return (dst);
|
||||
}
|
||||
18
fillit/src/libft/ft_strnequ.c
Normal file
18
fillit/src/libft/ft_strnequ.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnequ.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:32 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:13:55 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strnequ(char const *s1, char const *s2, size_t n)
|
||||
{
|
||||
return (ft_strncmp(s1, s2, n) == 0);
|
||||
}
|
||||
27
fillit/src/libft/ft_strnew.c
Normal file
27
fillit/src/libft/ft_strnew.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:34 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 14:58:35 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnew(size_t size)
|
||||
{
|
||||
char *addr;
|
||||
size_t i;
|
||||
|
||||
addr = (char *)malloc(size + 1);
|
||||
if (addr == NULL)
|
||||
return (NULL);
|
||||
i = -1;
|
||||
while (++i <= size)
|
||||
addr[i] = '\0';
|
||||
return (addr);
|
||||
}
|
||||
34
fillit/src/libft/ft_strnstr.c
Normal file
34
fillit/src/libft/ft_strnstr.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:36 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 16:34:42 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
int j;
|
||||
|
||||
i = -1;
|
||||
if (!*little)
|
||||
return ((char *)big);
|
||||
while (big[++i] && i < len)
|
||||
{
|
||||
j = 0;
|
||||
while (big[i + j] == little[j] && i + j < len)
|
||||
{
|
||||
j++;
|
||||
if (!little[j])
|
||||
return ((char *)big + i);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
29
fillit/src/libft/ft_strrchr.c
Normal file
29
fillit/src/libft/ft_strrchr.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:38 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:08:33 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
char *a;
|
||||
int i;
|
||||
|
||||
a = (char *)s;
|
||||
i = ft_strlen(a);
|
||||
while (i >= 0)
|
||||
{
|
||||
if (a[i] == (char)c)
|
||||
return (a + i);
|
||||
i--;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
107
fillit/src/libft/ft_strsplit.c
Normal file
107
fillit/src/libft/ft_strsplit.c
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strsplit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:15:58 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static char **alloc_table(char **table, const char *str, char c)
|
||||
{
|
||||
int i;
|
||||
int n_words;
|
||||
|
||||
i = 0;
|
||||
n_words = 0;
|
||||
while (str[i] == c)
|
||||
i++;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
if (str[i] == c)
|
||||
{
|
||||
n_words++;
|
||||
while (str[i] == c)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (str[i - 1] != c)
|
||||
n_words++;
|
||||
table = (char**)malloc(sizeof(*table) * (n_words + 10));
|
||||
table[n_words] = 0;
|
||||
return (table);
|
||||
}
|
||||
|
||||
static char **alloc_words(char **table, const char *str, char c)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
k = 0;
|
||||
while (str[i] == c)
|
||||
i++;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
if (str[i] == c || !str[i])
|
||||
{
|
||||
table[j] = (char*)malloc(sizeof(**table) * (k + 10));
|
||||
j++;
|
||||
k = 0;
|
||||
while (str[i] == c)
|
||||
i++;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
return (table);
|
||||
}
|
||||
|
||||
static char **fill_table(char **table, const char *str, char c)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
k = 0;
|
||||
while (str[i] == c)
|
||||
i++;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
table[j][k] = str[i];
|
||||
i++;
|
||||
k++;
|
||||
if (str[i] == c || !str[i])
|
||||
{
|
||||
table[j][k] = '\0';
|
||||
j++;
|
||||
k = 0;
|
||||
while (str[i] == c)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (table);
|
||||
}
|
||||
|
||||
char **ft_strsplit(char const *s, char c)
|
||||
{
|
||||
char **table;
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
table = 0;
|
||||
table = alloc_table(table, s, c);
|
||||
table = alloc_words(table, s, c);
|
||||
table = fill_table(table, s, c);
|
||||
return (table);
|
||||
}
|
||||
37
fillit/src/libft/ft_strstr.c
Normal file
37
fillit/src/libft/ft_strstr.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 10:48:35 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 16:28:05 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strstr(const char *big, const char *little)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *a;
|
||||
|
||||
a = (char *)big;
|
||||
i = 0;
|
||||
if (!*little)
|
||||
return (a);
|
||||
while (a[i])
|
||||
{
|
||||
j = 0;
|
||||
while (a[i + j] == little[j])
|
||||
{
|
||||
j++;
|
||||
if (!little[j])
|
||||
return (a + i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
33
fillit/src/libft/ft_strsub.c
Normal file
33
fillit/src/libft/ft_strsub.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strsub.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:43 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:15:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strsub(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *out;
|
||||
size_t i;
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
out = (char *)malloc(sizeof(char) * (len + 1));
|
||||
if (!out)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (i < len && s[i + start])
|
||||
{
|
||||
out[i] = s[i + start];
|
||||
i++;
|
||||
}
|
||||
out[i] = '\0';
|
||||
return (out);
|
||||
}
|
||||
34
fillit/src/libft/ft_strtrim.c
Normal file
34
fillit/src/libft/ft_strtrim.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 19:45:38 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strtrim(char const *s)
|
||||
{
|
||||
char *out;
|
||||
int size;
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
out = ft_strdup(s);
|
||||
while (*out && FT_SEP(*out))
|
||||
out++;
|
||||
if (!out)
|
||||
return (NULL);
|
||||
size = ft_strlen(out) - 1;
|
||||
while (size >= 0 && FT_SEP(out[size]))
|
||||
{
|
||||
out[size] = '\0';
|
||||
size--;
|
||||
}
|
||||
return (out);
|
||||
}
|
||||
20
fillit/src/libft/ft_tolower.c
Normal file
20
fillit/src/libft/ft_tolower.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:58:46 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:24:09 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (c + 32);
|
||||
return (c);
|
||||
}
|
||||
20
fillit/src/libft/ft_toupper.c
Normal file
20
fillit/src/libft/ft_toupper.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 14:53:58 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 15:24:40 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c - 32);
|
||||
return (c);
|
||||
}
|
||||
65
fillit/src/libft/get_next_line.c
Normal file
65
fillit/src/libft/get_next_line.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 12:45:02 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/04 13:43:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#define BUFF_SIZE 32
|
||||
|
||||
static char *ft_realloc(char *line, int size)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = (char *)malloc(sizeof(char) * (ft_strlen(line) + size + 1));
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
str = ft_strcpy(str, line);
|
||||
free(line);
|
||||
return (str);
|
||||
}
|
||||
|
||||
static int ft_loop_read(int fd, char **line, char (*save)[])
|
||||
{
|
||||
char buf[BUFF_SIZE + 1];
|
||||
char *pos;
|
||||
int ret;
|
||||
|
||||
while ((ret = read(fd, buf, BUFF_SIZE)) > 0)
|
||||
{
|
||||
buf[ret] = '\0';
|
||||
if ((pos = ft_strchr(buf, '\n')))
|
||||
{
|
||||
ft_strcpy(*save, pos + 1);
|
||||
*pos = '\0';
|
||||
ft_strcat(*line, buf);
|
||||
return (1);
|
||||
}
|
||||
if ((*line = ft_realloc(*line, ret)) == NULL)
|
||||
return (-1);
|
||||
ft_strcat(*line, buf);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int get_next_line(int const fd, char **line)
|
||||
{
|
||||
static char save[BUFF_SIZE] = "";
|
||||
char *pos;
|
||||
|
||||
*line = (char *)malloc(sizeof(char *) * (BUFF_SIZE + ft_strlen(save) + 1));
|
||||
*line = ft_strcpy(*line, save);
|
||||
if ((pos = ft_strchr(*line, '\n')))
|
||||
{
|
||||
ft_strcpy(save, pos + 1);
|
||||
*pos = '\0';
|
||||
return (1);
|
||||
}
|
||||
return (ft_loop_read(fd, line, &save));
|
||||
}
|
||||
Loading…
Reference in a new issue