Skip to content

Commit

Permalink
init libft, Makefile, headerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsunghao-C committed Aug 14, 2024
1 parent 2e5abc3 commit 87992f2
Show file tree
Hide file tree
Showing 86 changed files with 5,192 additions and 0 deletions.
80 changes: 80 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: okoca <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/07/08 11:20:19 by okoca #+# #+# #
# Updated: 2024/08/15 00:49:16 by tsuchen ### ########.fr #
# #
# **************************************************************************** #

NAME = cub3d

SRCS_M = main.c

SRCS_REPO1 =

SRCS_REPO2 =

SRC = srcs/

REPO1_PATH = srcs/repo1/
REPO2_PATH = srcs/repo2/

SRCS = $(addprefix $(SRC), $(SRCS_M)) \
$(addprefix $(REPO1_PATH), $(SRCS_REPO1)) \
$(addprefix $(REPO2_PATH), $(SRCS_REPO2)) \

HEADERS = cub3d.h

OBJS = $(SRCS:.c=.o)

HEAD = includes/

CFLAGS = -Wall -Wextra -Werror # -g

CC = cc

H_DEPS = $(addprefix $(HEAD), $(HEADERS))

LIBFT_PATH = libft/
LIBFT_H_PATH = libft/includes/
LIBFT = $(LIBFT_PATH)libft.a

MLX = mlx_linux
MLXFLAGS = -lmlx_Linux -lXext -lX11 -lm -lz

all: $(NAME)

$(LIBFT):
$(MAKE) -C $(LIBFT_PATH)

$(NAME): $(LIBFT) $(OBJS) $(H_DEPS)
$(CC) $(CFLAGS) $(OBJS) -L$(MLX) -I$(MLX) $(MLXFLAGS) $(LIBFT) -o $(NAME)

bonus: $(NAME)

%.o: %.c
$(CC) $(CFLAGS) -I$(HEAD) -I$(LIBFT_H_PATH) -I$(MLX) -c $< -o $@

clean: libft-clean root-clean

libft-clean:
$(MAKE) -C $(LIBFT_PATH) clean

root-clean:
rm -f $(OBJS)

fclean: libft-fclean root-fclean

libft-fclean:
$(MAKE) -C $(LIBFT_PATH) fclean

root-fclean: root-clean
rm -f $(NAME)

re: fclean all

.PHONY: all clean fclean re bonus libft libft-clean libft-fclean root-clean root-fclean
43 changes: 43 additions & 0 deletions includes/cub3d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */
/* Updated: 2024/08/15 00:34:12 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef CUB3D_H
# define CUB3D_H

# include <stdlib.h>
# include <stdio.h>
# include <unistd.h>
# include <string.h>
# include <errno.h>
# include <limits.h>
# include <fcntl.h>
# include <sys/time.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <math.h>

# include "mlx.h"
# include "libft.h"
# include "ft_printf.h"
# include "get_next_line_bonus.h"

# define OUT STDOUT_FILENO
# define IN STDIN_FILENO
# define ER STDERR_FILENO
# define P_NAME "cub3d"

# define KEY_PRESS 2
# define MOUSE_PRESS 4
# define MOUSE_MOVE 6
# define CLOSE_BUTTON 17

#endif
86 changes: 86 additions & 0 deletions libft/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: okoca <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/06/15 10:05:55 by tsuchen #+# #+# #
# Updated: 2024/08/15 00:48:25 by tsuchen ### ########.fr #
# #
# **************************************************************************** #

NAME = libft.a

SRCS_LIBC = ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c \
ft_strlen.c ft_memset.c ft_bzero.c ft_memcpy.c ft_memmove.c \
ft_strlcpy.c ft_strlcat.c ft_toupper.c ft_tolower.c ft_strchr.c \
ft_strrchr.c ft_strncmp.c ft_memchr.c ft_memcmp.c ft_strnstr.c \
ft_atoi.c ft_calloc.c ft_strdup.c ft_strcmp.c ft_atof.c ft_strndup.c \
ft_atol.c

SRCS_ARRAY = ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c \
ft_strmapi.c ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c \
ft_putnbr_fd.c ft_split_quote.c ft_advanced_sort_string_tab.c \
ft_arr_size.c ft_free_all.c ft_split2.c ft_ltoa.c

SRCS_LIST = ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c \
ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c \
ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c

SRCS_PRINTF = ft_print_char.c ft_print_digit.c ft_printf.c ft_print_mem.c \
ft_print_spec.c ft_print_str.c ft_is_spec.c ft_is_left_bonus.c \
ft_gen_wid_pre_bonus.c ft_dgt_cnt_abs_bonus.c ft_have_zero_bonus.c \
ft_have_alt_bonus.c ft_have_space_bonus.c ft_have_plus_bonus.c \
ft_print_char_f_bonus.c ft_print_str_f_bonus.c ft_print_mem_f_bonus.c \
ft_print_spec_f_bonus.c ft_print_uint_f_bonus.c ft_print_sint_f_bonus.c \
ft_print_sign_bonus.c ft_print_alt_bonus.c ft_procs_flag_bonus.c \
ft_rm_plus_space_bonus.c ft_rm_alt_bonus.c

SRCS_GNL = get_next_line_bonus.c get_next_line_utils_bonus.c

HEADERS = ft_printf.h get_next_line_bonus.h libft.h

LIBC_PATH = srcs/libc/
ARRAY_PATH = srcs/array/
LIST_PATH = srcs/list/
PRINTF_PATH = srcs/ft_printf/
GNL_PATH = srcs/gnl/

SRCS = $(addprefix $(LIBC_PATH), $(SRCS_LIBC)) \
$(addprefix $(ARRAY_PATH), $(SRCS_ARRAY)) \
$(addprefix $(LIST_PATH), $(SRCS_LIST)) \
$(addprefix $(PRINTF_PATH), $(SRCS_PRINTF)) \
$(addprefix $(GNL_PATH), $(SRCS_GNL))

OBJS = $(SRCS:.c=.o)

HEAD = includes/

HDRS_DEPS = $(addprefix $(HEAD), $(HEADERS))

CFLAGS = -Wall -Wextra -Werror

ARC = ar rcs

CC = cc

all: $(NAME)

$(NAME): $(OBJS) $(HDRS_DEPS)
@$(ARC) $(NAME) $(OBJS)

bonus: $(NAME)

.c.o:
@$(CC) $(CFLAGS) -c $< -o $@ -I$(HEAD)

clean:
@rm -f $(OBJS)

fclean: clean
@rm -f $(NAME)

re: fclean all

.PHONY: all clean fclean re bonus
51 changes: 51 additions & 0 deletions libft/includes/ft_printf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/16 10:42:50 by tsuchen #+# #+# */
/* Updated: 2024/06/15 12:37:03 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef FT_PRINTF_H
# define FT_PRINTF_H

# include "libft.h"
# include <stdarg.h>
# define ER STDERR_FILENO
# define AD_SIZE 16
# define HEX_SIZE 16
# define DEC_TAB "0123456789"
# define HEX_TAB "0123456789abcdef"
# define HEX_TAB_U "0123456789ABCDEF"

int ft_print_spec(char c, va_list *ap);
int ft_print_spec_f(char c, va_list *ap, char *flags, char **wid_pre);
int ft_print_char(char c);
int ft_print_char_f(char c, char *flags, char **wid_pre);
int ft_print_str(char *s);
int ft_print_str_f(char *s, char *flags, char **wid_pre);
int ft_print_mem(void *addr);
int ft_print_mem_f(void *addr, char *flags, char **wid_pre);
int ft_print_digit(long nbr, char *base);
int ft_print_uint_f(long nbr, char *base, char *flags, char **wid_pre);
int ft_print_sint_f(long nbr, char *base, char *flags, char **wid_pre);
int ft_print_sign(long *nbr, char *flags);
int ft_print_alt(char *base);
int ft_printf(const char *fmt, ...);
int ft_dgt_cnt_abs(long nbr, char *base);
int ft_is_spec(char c);
int ft_is_left(char *str);
int ft_have_zero(char *str);
int ft_have_alt(char *str);
int ft_have_space(char *str);
int ft_have_plus(char *str);
const char *ft_procs_flag(const char *fmt, va_list *ap, int *count);
void ft_gen_wid_pre(const char *fmt, size_t len, char **wid_pre);
void ft_rm_plus_space(char *str);
void ft_rm_alt(char *str);

#endif
43 changes: 43 additions & 0 deletions libft/includes/get_next_line_bonus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_bonus.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 17:54:22 by tsuchen #+# #+# */
/* Updated: 2024/06/15 13:59:19 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef GET_NEXT_LINE_BONUS_H
# define GET_NEXT_LINE_BONUS_H

# include "libft.h"
# include <stdlib.h>
# include <unistd.h>
# include <fcntl.h>
# include <limits.h>
# include <stdint.h>
# include <errno.h>
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 42
# endif
# define MAX_FD 1024
# define ER STDERR_FILENO

typedef struct s_list_gnl
{
char *str;
struct s_list_gnl *next;
} t_list_gnl;
void ft_lst_append(t_list_gnl **lst, char *str);
void ft_update_list(t_list_gnl **lst);
void ft_delone(t_list_gnl *lst);
int ft_have_nl_lst(t_list_gnl *bgn_lst);
int ft_line_size(t_list_gnl *lst);
char *get_next_line(int fd);
char *ft_gen_nl(t_list_gnl *lst);
void ft_fetch_nl(int fd, t_list_gnl **bgn_lst);

#endif
89 changes: 89 additions & 0 deletions libft/includes/libft.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: okoca <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/16 10:42:50 by tsuchen #+# #+# */
/* Updated: 2024/07/17 17:31:35 by okoca ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef LIBFT_H
# define LIBFT_H

# include <unistd.h>
# include <stdlib.h>
# include <limits.h>
# include <stdint.h>
# include <errno.h>

/* libc functions */
int ft_atoi(const char *nptr);
double ft_atof(const char *nptr);
long ft_atol(const char *nptr);
void ft_bzero(void *s, size_t n);
void *ft_calloc(size_t nmemb, size_t size);
int ft_isalnum(int c);
int ft_isalpha(int c);
int ft_isascii(int c);
int ft_isdigit(int c);
int ft_isprint(int c);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void *ft_memmove(void *dest, const void *src, size_t n);
void *ft_memset(void *s, int c, size_t n);
char *ft_strchr(const char *s, int c);
char *ft_strdup(const char *s);
char *ft_strndup(const char *str, int nb);
size_t ft_strlcat(char *dst, const char *src, size_t siz);
size_t ft_strlcpy(char *dst, const char *src, size_t siz);
size_t ft_strlen(const char *s);
int ft_strcmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2, size_t n);
char *ft_strnstr(const char *big, const char *little, size_t len);
char *ft_strrchr(const char *s, int c);
int ft_tolower(int c);
int ft_toupper(int c);

/* array functions */
char *ft_itoa(int n);
char *ft_ltoa(long n);
void ft_putchar_fd(char c, int fd);
void ft_putendl_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);
void ft_putstr_fd(char *s, int fd);
char **ft_split(char const *s, char c);
char **ft_split2(char const *s, char *set);
char **ft_split_quote(char const *s, char c);
void ft_striteri(char *s, void (*f)(unsigned int, char*));
char *ft_strjoin(char const *s1, char const *s2);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
char *ft_strtrim(char const *s1, char const *set);
char *ft_substr(char const *s, unsigned int start, size_t len);
void ft_advanced_sort_string_tab(char **tab,
int (*cmp)(const char *, const char *));
int ft_arr_size(char **arr);
void ft_free_all(char **arr);

/* linked list functions */
typedef struct s_list
{
void *content;
struct s_list *next;
struct s_list *prev;
} t_list;

void ft_lstadd_back(t_list **lst, t_list *new);
void ft_lstadd_front(t_list **lst, t_list *new);
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstlast(t_list *lst);
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
t_list *ft_lstnew(void *content);
int ft_lstsize(t_list *lst);

#endif
Loading

0 comments on commit 87992f2

Please sign in to comment.