diff --git a/fillit/.gitignore b/fillit/.gitignore deleted file mode 100644 index 74cc6897..00000000 --- a/fillit/.gitignore +++ /dev/null @@ -1 +0,0 @@ -fillit diff --git a/fillit/.tags b/fillit/.tags deleted file mode 100644 index a156e29a..00000000 --- a/fillit/.tags +++ /dev/null @@ -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)$/ diff --git a/fillit/.travis.yml b/fillit/.travis.yml deleted file mode 100644 index 6c6eebfc..00000000 --- a/fillit/.travis.yml +++ /dev/null @@ -1,2 +0,0 @@ -language: C -script: make diff --git a/fillit/Makefile b/fillit/Makefile index 3cd8824a..6a858a46 100644 --- a/fillit/Makefile +++ b/fillit/Makefile @@ -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) diff --git a/fillit/fillit b/fillit/fillit new file mode 100755 index 00000000..0884ee09 Binary files /dev/null and b/fillit/fillit differ diff --git a/fillit/fillit.fr.pdf b/fillit/fillit.fr.pdf deleted file mode 100644 index b4284f76..00000000 Binary files a/fillit/fillit.fr.pdf and /dev/null differ diff --git a/fillit/includes/fillit.h b/fillit/includes/fillit.h index 9b363f59..9135afe4 100644 --- a/fillit/includes/fillit.h +++ b/fillit/includes/fillit.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/fillit/includes/libft.h b/fillit/includes/libft.h deleted file mode 120000 index 85a0928c..00000000 --- a/fillit/includes/libft.h +++ /dev/null @@ -1 +0,0 @@ -../libft/libft.h \ No newline at end of file diff --git a/fillit/includes/libft.h b/fillit/includes/libft.h new file mode 100644 index 00000000..10ea2935 --- /dev/null +++ b/fillit/includes/libft.h @@ -0,0 +1,100 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +# include +# include +# include +# 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 diff --git a/fillit/src/fillit/fillit_check_waste.c b/fillit/src/fillit/fillit_check_waste.c new file mode 100644 index 00000000..be5ef640 --- /dev/null +++ b/fillit/src/fillit/fillit_check_waste.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* fillit_check_waste.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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)); +} diff --git a/fillit/src/fillit_fit_blob.c b/fillit/src/fillit/fillit_fit_blob.c similarity index 100% rename from fillit/src/fillit_fit_blob.c rename to fillit/src/fillit/fillit_fit_blob.c diff --git a/fillit/src/fillit_parser.c b/fillit/src/fillit/fillit_parser.c similarity index 96% rename from fillit/src/fillit_parser.c rename to fillit/src/fillit/fillit_parser.c index f756ced9..2ec12a0d 100644 --- a/fillit/src/fillit_parser.c +++ b/fillit/src/fillit/fillit_parser.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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++; diff --git a/fillit/src/fillit_solver.c b/fillit/src/fillit/fillit_solver.c similarity index 89% rename from fillit/src/fillit_solver.c rename to fillit/src/fillit/fillit_solver.c index dd4b56ef..dc386230 100644 --- a/fillit/src/fillit_solver.c +++ b/fillit/src/fillit/fillit_solver.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } diff --git a/fillit/src/floodfill.c b/fillit/src/fillit/floodfill.c similarity index 100% rename from fillit/src/floodfill.c rename to fillit/src/fillit/floodfill.c diff --git a/fillit/src/lib_board.c b/fillit/src/fillit/lib_board.c similarity index 96% rename from fillit/src/lib_board.c rename to fillit/src/fillit/lib_board.c index 6031e5d1..9732d4ac 100644 --- a/fillit/src/lib_board.c +++ b/fillit/src/fillit/lib_board.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/fillit/src/lib_board2.c b/fillit/src/fillit/lib_board2.c similarity index 86% rename from fillit/src/lib_board2.c rename to fillit/src/fillit/lib_board2.c index cf5e8cf2..035fb0a2 100644 --- a/fillit/src/lib_board2.c +++ b/fillit/src/fillit/lib_board2.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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++; } } diff --git a/fillit/src/lib_ttmn.c b/fillit/src/fillit/lib_ttmn.c similarity index 100% rename from fillit/src/lib_ttmn.c rename to fillit/src/fillit/lib_ttmn.c diff --git a/fillit/src/main.c b/fillit/src/fillit/main.c similarity index 95% rename from fillit/src/main.c rename to fillit/src/fillit/main.c index 70cba697..cd590e93 100644 --- a/fillit/src/main.c +++ b/fillit/src/fillit/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/fillit/src/fillit_check_waste.c b/fillit/src/fillit_check_waste.c deleted file mode 100644 index 78e2ce64..00000000 --- a/fillit/src/fillit_check_waste.c +++ /dev/null @@ -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)); -} diff --git a/fillit/src/libft/ft_atoi.c b/fillit/src/libft/ft_atoi.c new file mode 100644 index 00000000..711e3d68 --- /dev/null +++ b/fillit/src/libft/ft_atoi.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_bzero.c b/fillit/src/libft/ft_bzero.c new file mode 100644 index 00000000..6f1834b5 --- /dev/null +++ b/fillit/src/libft/ft_bzero.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/fillit/src/libft/ft_isalnum.c b/fillit/src/libft/ft_isalnum.c new file mode 100644 index 00000000..673b6e89 --- /dev/null +++ b/fillit/src/libft/ft_isalnum.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_isalpha.c b/fillit/src/libft/ft_isalpha.c new file mode 100644 index 00000000..29f532a9 --- /dev/null +++ b/fillit/src/libft/ft_isalpha.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_isascii.c b/fillit/src/libft/ft_isascii.c new file mode 100644 index 00000000..52a85067 --- /dev/null +++ b/fillit/src/libft/ft_isascii.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_isdigit.c b/fillit/src/libft/ft_isdigit.c new file mode 100644 index 00000000..510371c2 --- /dev/null +++ b/fillit/src/libft/ft_isdigit.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_isprint.c b/fillit/src/libft/ft_isprint.c new file mode 100644 index 00000000..74a46640 --- /dev/null +++ b/fillit/src/libft/ft_isprint.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_itoa.c b/fillit/src/libft/ft_itoa.c new file mode 100644 index 00000000..94a83c8f --- /dev/null +++ b/fillit/src/libft/ft_itoa.c @@ -0,0 +1,69 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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)); +} diff --git a/fillit/src/libft/ft_lstadd.c b/fillit/src/libft/ft_lstadd.c new file mode 100644 index 00000000..f2064d9f --- /dev/null +++ b/fillit/src/libft/ft_lstadd.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; + } +} diff --git a/fillit/src/libft/ft_lstdel.c b/fillit/src/libft/ft_lstdel.c new file mode 100644 index 00000000..b8056396 --- /dev/null +++ b/fillit/src/libft/ft_lstdel.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_lstdelone.c b/fillit/src/libft/ft_lstdelone.c new file mode 100644 index 00000000..1aa876b5 --- /dev/null +++ b/fillit/src/libft/ft_lstdelone.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/fillit/src/libft/ft_lsteadd.c b/fillit/src/libft/ft_lsteadd.c new file mode 100644 index 00000000..9ef34d15 --- /dev/null +++ b/fillit/src/libft/ft_lsteadd.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lsteadd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/fillit/src/libft/ft_lstiter.c b/fillit/src/libft/ft_lstiter.c new file mode 100644 index 00000000..6bf86a06 --- /dev/null +++ b/fillit/src/libft/ft_lstiter.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; + } +} diff --git a/fillit/src/libft/ft_lstmap.c b/fillit/src/libft/ft_lstmap.c new file mode 100644 index 00000000..2f564692 --- /dev/null +++ b/fillit/src/libft/ft_lstmap.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_lstnew.c b/fillit/src/libft/ft_lstnew.c new file mode 100644 index 00000000..1ad8c10a --- /dev/null +++ b/fillit/src/libft/ft_lstnew.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_lstsize.c b/fillit/src/libft/ft_lstsize.c new file mode 100644 index 00000000..5167c0c3 --- /dev/null +++ b/fillit/src/libft/ft_lstsize.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst_size.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_memalloc.c b/fillit/src/libft/ft_memalloc.c new file mode 100644 index 00000000..a94572ed --- /dev/null +++ b/fillit/src/libft/ft_memalloc.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memalloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_memccpy.c b/fillit/src/libft/ft_memccpy.c new file mode 100644 index 00000000..699c2836 --- /dev/null +++ b/fillit/src/libft/ft_memccpy.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memccpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_memchr.c b/fillit/src/libft/ft_memchr.c new file mode 100644 index 00000000..47eccf3b --- /dev/null +++ b/fillit/src/libft/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_memcmp.c b/fillit/src/libft/ft_memcmp.c new file mode 100644 index 00000000..9dd827ee --- /dev/null +++ b/fillit/src/libft/ft_memcmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_memcpy.c b/fillit/src/libft/ft_memcpy.c new file mode 100644 index 00000000..a0711c68 --- /dev/null +++ b/fillit/src/libft/ft_memcpy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_memdel.c b/fillit/src/libft/ft_memdel.c new file mode 100644 index 00000000..7745391e --- /dev/null +++ b/fillit/src/libft/ft_memdel.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/fillit/src/libft/ft_memmove.c b/fillit/src/libft/ft_memmove.c new file mode 100644 index 00000000..952faa3d --- /dev/null +++ b/fillit/src/libft/ft_memmove.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_memset.c b/fillit/src/libft/ft_memset.c new file mode 100644 index 00000000..cae3e999 --- /dev/null +++ b/fillit/src/libft/ft_memset.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_putchar.c b/fillit/src/libft/ft_putchar.c new file mode 100644 index 00000000..bd6d350a --- /dev/null +++ b/fillit/src/libft/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_putchar_fd.c b/fillit/src/libft/ft_putchar_fd.c new file mode 100644 index 00000000..1d1e9a4b --- /dev/null +++ b/fillit/src/libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_putendl.c b/fillit/src/libft/ft_putendl.c new file mode 100644 index 00000000..a0fc0b6b --- /dev/null +++ b/fillit/src/libft/ft_putendl.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_putendl_fd.c b/fillit/src/libft/ft_putendl_fd.c new file mode 100644 index 00000000..9b33674c --- /dev/null +++ b/fillit/src/libft/ft_putendl_fd.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_putnbr.c b/fillit/src/libft/ft_putnbr.c new file mode 100644 index 00000000..d8aa57a4 --- /dev/null +++ b/fillit/src/libft/ft_putnbr.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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'); +} diff --git a/fillit/src/libft/ft_putnbr_fd.c b/fillit/src/libft/ft_putnbr_fd.c new file mode 100644 index 00000000..da7cf739 --- /dev/null +++ b/fillit/src/libft/ft_putnbr_fd.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_putstr.c b/fillit/src/libft/ft_putstr.c new file mode 100644 index 00000000..c4e16816 --- /dev/null +++ b/fillit/src/libft/ft_putstr.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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)); +} diff --git a/fillit/src/libft/ft_putstr_fd.c b/fillit/src/libft/ft_putstr_fd.c new file mode 100644 index 00000000..ee82000f --- /dev/null +++ b/fillit/src/libft/ft_putstr_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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)); +} diff --git a/fillit/src/libft/ft_strcat.c b/fillit/src/libft/ft_strcat.c new file mode 100644 index 00000000..b2947ea8 --- /dev/null +++ b/fillit/src/libft/ft_strcat.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strchr.c b/fillit/src/libft/ft_strchr.c new file mode 100644 index 00000000..7263e413 --- /dev/null +++ b/fillit/src/libft/ft_strchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strclr.c b/fillit/src/libft/ft_strclr.c new file mode 100644 index 00000000..834eb6f1 --- /dev/null +++ b/fillit/src/libft/ft_strclr.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strclr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/fillit/src/libft/ft_strcmp.c b/fillit/src/libft/ft_strcmp.c new file mode 100644 index 00000000..bc8647ae --- /dev/null +++ b/fillit/src/libft/ft_strcmp.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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)); +} diff --git a/fillit/src/libft/ft_strcpy.c b/fillit/src/libft/ft_strcpy.c new file mode 100644 index 00000000..95818fff --- /dev/null +++ b/fillit/src/libft/ft_strcpy.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strdel.c b/fillit/src/libft/ft_strdel.c new file mode 100644 index 00000000..2722466f --- /dev/null +++ b/fillit/src/libft/ft_strdel.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/fillit/src/libft/ft_strdup.c b/fillit/src/libft/ft_strdup.c new file mode 100644 index 00000000..9233b26e --- /dev/null +++ b/fillit/src/libft/ft_strdup.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strequ.c b/fillit/src/libft/ft_strequ.c new file mode 100644 index 00000000..26134cb0 --- /dev/null +++ b/fillit/src/libft/ft_strequ.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strequ.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_striter.c b/fillit/src/libft/ft_striter.c new file mode 100644 index 00000000..9e4bd828 --- /dev/null +++ b/fillit/src/libft/ft_striter.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_striteri.c b/fillit/src/libft/ft_striteri.c new file mode 100644 index 00000000..1e31285b --- /dev/null +++ b/fillit/src/libft/ft_striteri.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strjoin.c b/fillit/src/libft/ft_strjoin.c new file mode 100644 index 00000000..940068cd --- /dev/null +++ b/fillit/src/libft/ft_strjoin.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strlcat.c b/fillit/src/libft/ft_strlcat.c new file mode 100644 index 00000000..df94eea4 --- /dev/null +++ b/fillit/src/libft/ft_strlcat.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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)); +} diff --git a/fillit/src/libft/ft_strlen.c b/fillit/src/libft/ft_strlen.c new file mode 100644 index 00000000..8018de65 --- /dev/null +++ b/fillit/src/libft/ft_strlen.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strmap.c b/fillit/src/libft/ft_strmap.c new file mode 100644 index 00000000..295214f0 --- /dev/null +++ b/fillit/src/libft/ft_strmap.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strmapi.c b/fillit/src/libft/ft_strmapi.c new file mode 100644 index 00000000..0d6fab4c --- /dev/null +++ b/fillit/src/libft/ft_strmapi.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strncat.c b/fillit/src/libft/ft_strncat.c new file mode 100644 index 00000000..31ab2262 --- /dev/null +++ b/fillit/src/libft/ft_strncat.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strncmp.c b/fillit/src/libft/ft_strncmp.c new file mode 100644 index 00000000..16e0bbd6 --- /dev/null +++ b/fillit/src/libft/ft_strncmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strncpy.c b/fillit/src/libft/ft_strncpy.c new file mode 100644 index 00000000..85dd41c7 --- /dev/null +++ b/fillit/src/libft/ft_strncpy.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strnequ.c b/fillit/src/libft/ft_strnequ.c new file mode 100644 index 00000000..c77c4040 --- /dev/null +++ b/fillit/src/libft/ft_strnequ.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnequ.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strnew.c b/fillit/src/libft/ft_strnew.c new file mode 100644 index 00000000..4a60408f --- /dev/null +++ b/fillit/src/libft/ft_strnew.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strnstr.c b/fillit/src/libft/ft_strnstr.c new file mode 100644 index 00000000..efa7e54f --- /dev/null +++ b/fillit/src/libft/ft_strnstr.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strrchr.c b/fillit/src/libft/ft_strrchr.c new file mode 100644 index 00000000..e41d4566 --- /dev/null +++ b/fillit/src/libft/ft_strrchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strsplit.c b/fillit/src/libft/ft_strsplit.c new file mode 100644 index 00000000..38e50e8c --- /dev/null +++ b/fillit/src/libft/ft_strsplit.c @@ -0,0 +1,107 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsplit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strstr.c b/fillit/src/libft/ft_strstr.c new file mode 100644 index 00000000..bf8ab37a --- /dev/null +++ b/fillit/src/libft/ft_strstr.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strsub.c b/fillit/src/libft/ft_strsub.c new file mode 100644 index 00000000..3b02758d --- /dev/null +++ b/fillit/src/libft/ft_strsub.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsub.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_strtrim.c b/fillit/src/libft/ft_strtrim.c new file mode 100644 index 00000000..501174d1 --- /dev/null +++ b/fillit/src/libft/ft_strtrim.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_tolower.c b/fillit/src/libft/ft_tolower.c new file mode 100644 index 00000000..3992c4c9 --- /dev/null +++ b/fillit/src/libft/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/ft_toupper.c b/fillit/src/libft/ft_toupper.c new file mode 100644 index 00000000..3aa9ea10 --- /dev/null +++ b/fillit/src/libft/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/fillit/src/libft/get_next_line.c b/fillit/src/libft/get_next_line.c new file mode 100644 index 00000000..3263c520 --- /dev/null +++ b/fillit/src/libft/get_next_line.c @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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)); +}