Skip to content

Commit 31f61a4

Browse files
committed
init: add project files
0 parents  commit 31f61a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1683
-0
lines changed

Makefile

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
NAME = fdf
2+
3+
INC_DIR = inc
4+
LIB_DIR = lib
5+
LIBFT_DIR = $(LIB_DIR)/libft
6+
GNL_DIR = $(LIB_DIR)/get_next_line
7+
MLX_DIR = $(LIB_DIR)/minilibx
8+
LIBFT = $(LIBFT_DIR)/libft.a
9+
GNL = $(GNL_DIR)/libgnl.a
10+
MLX = $(MLX_DIR)/libmlx.a
11+
BUILD_DIR = build
12+
13+
SRCS = fdf.c
14+
OBJS = $(addprefix $(BUILD_DIR)/,$(SRCS:.c=.o))
15+
CFLAGS = -Wall -Wextra -Werror -I$(INC_DIR) -I$(LIBFT_DIR) -I$(GNL_DIR) -I$(MLX_DIR)
16+
LDFLAGS = -L$(LIBFT_DIR) -L$(GNL_DIR) -L$(MLX_DIR)
17+
LDLIBS = -lmlx -lft -lgnl -lXext -lX11 -lm
18+
19+
RM = rm -rf
20+
21+
all: $(NAME)
22+
23+
$(NAME): $(OBJS) $(LIBFT) $(MLX) $(GNL)
24+
$(CC) $(CFLAGS) $(OBJS) -o $(NAME) $(LDFLAGS) $(LDLIBS)
25+
26+
$(BUILD_DIR):
27+
mkdir -p $@
28+
29+
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
30+
$(CC) $(CFLAGS) -c $^ -o $@
31+
32+
$(LIBFT):
33+
@make -C $(LIBFT_DIR)
34+
35+
$(GNL):
36+
@make -C $(GNL_DIR)
37+
38+
$(MLX):
39+
@make -C $(MLX_DIR)
40+
41+
clean:
42+
$(RM) $(BUILD_DIR)
43+
@make -C $(LIBFT_DIR) clean
44+
@make -C $(GNL_DIR) clean
45+
@make -C $(MLX_DIR) clean
46+
47+
fclean: clean
48+
$(RM) $(NAME)
49+
@make -C $(LIBFT_DIR) fclean
50+
@make -C $(GNL_DIR) fclean
51+
52+
re: fclean all

fdf.c

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* fdf.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ebabaogl <[email protected] +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2025/01/02 11:39:32 by ebabaogl #+# #+# */
9+
/* Updated: 2025/01/02 11:58:41 by ebabaogl ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "mlx.h"
14+
#include "fdf.h"
15+
16+
int main()
17+
{
18+
t_data data;
19+
20+
data.mlx_ptr = mlx_init();
21+
data.win_ptr = mlx_new_window(data.mlx_ptr, WIDTH, HEIGHT, "FdF!!1!!!1");
22+
mlx_loop(data.mlx_ptr);
23+
}

inc/fdf.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* fdf.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ebabaogl <[email protected] +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2025/01/02 11:39:37 by ebabaogl #+# #+# */
9+
/* Updated: 2025/01/02 12:15:22 by ebabaogl ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#ifndef FDF_H
14+
# define FDF_H
15+
16+
# define WIDTH 1920
17+
# define HEIGHT 1080
18+
19+
typedef struct s_data
20+
{
21+
void *mlx_ptr;
22+
void *win_ptr;
23+
} t_data;
24+
25+
#endif

lib/get_next_line/Makefile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
NAME = libgnl.a
2+
3+
CFLAGS = -Wall -Wextra -Werror
4+
ARFLAGS = rcs
5+
RM = rm -rf
6+
7+
BUILD_DIR = build
8+
SRCS = get_next_line.c get_next_line_utils.c
9+
OBJS = $(addprefix $(BUILD_DIR)/,$(SRCS:.c=.o))
10+
11+
all: $(NAME)
12+
13+
$(BUILD_DIR):
14+
mkdir -p $@
15+
16+
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
17+
$(CC) $(CFLAGS) -c $^ -o $@
18+
19+
$(NAME): $(OBJS)
20+
$(AR) $(ARFLAGS) $@ $^
21+
22+
clean:
23+
$(RM) $(BUILD_DIR)
24+
25+
fclean: clean
26+
$(RM) $(NAME)
27+
28+
re: fclean all
29+
30+
.PHONY: all clean fclean re

lib/get_next_line/get_next_line.c

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* get_next_line.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ebabaogl <[email protected] +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2024/11/03 11:09:56 by ebabaogl #+# #+# */
9+
/* Updated: 2024/11/04 14:18:47 by ebabaogl ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "get_next_line.h"
14+
#include <stdlib.h>
15+
#include <unistd.h>
16+
17+
static char *update_buffer(char *buf, int index)
18+
{
19+
size_t i;
20+
21+
i = 0;
22+
while (buf[index] && buf[index + 1] != '\0')
23+
{
24+
buf[i] = buf[index + 1];
25+
index++;
26+
i++;
27+
}
28+
while (buf[i])
29+
buf[i++] = '\0';
30+
return (buf);
31+
}
32+
33+
static char *get_line(char *buf)
34+
{
35+
char *line;
36+
size_t i;
37+
38+
i = 0;
39+
if (!*buf)
40+
return (NULL);
41+
while (buf[i] && buf[i] != '\n')
42+
i++;
43+
if (buf[i] == '\n')
44+
i++;
45+
line = ft_calloc(i + 1, sizeof(char));
46+
if (!line)
47+
return (NULL);
48+
i = 0;
49+
while (buf[i] && buf[i] != '\n')
50+
{
51+
line[i] = buf[i];
52+
i++;
53+
}
54+
if (!buf[i])
55+
line[i] = '\0';
56+
else if (buf[i] == '\n')
57+
line[i] = '\n';
58+
buf = update_buffer(buf, i);
59+
return (line);
60+
}
61+
62+
static char *read_file(int fd, char *buf)
63+
{
64+
char *tmp_str;
65+
char *tmp_buf;
66+
ssize_t r_bytes;
67+
68+
tmp_str = ft_calloc(BUFFER_SIZE + 1, sizeof(char));
69+
if (!tmp_str)
70+
return (free(tmp_str), free(buf), NULL);
71+
while (1)
72+
{
73+
r_bytes = read(fd, tmp_str, BUFFER_SIZE);
74+
if (r_bytes == -1)
75+
return (free(tmp_str), NULL);
76+
if (r_bytes == 0)
77+
return (free(tmp_str), buf);
78+
tmp_buf = ft_strjoin(buf, tmp_str);
79+
if (!tmp_buf)
80+
return (free(tmp_str), free(buf), NULL);
81+
free(buf);
82+
buf = tmp_buf;
83+
ft_memset(tmp_str, 0, BUFFER_SIZE + 1);
84+
if (ft_strchr(buf, '\n'))
85+
break ;
86+
}
87+
return (free(tmp_str), buf);
88+
}
89+
90+
char *get_next_line(int fd)
91+
{
92+
static char *buf;
93+
char *line;
94+
95+
if (fd < 0 || BUFFER_SIZE <= 0 || read(fd, 0, 0) == -1)
96+
return (free(buf), buf = NULL, NULL);
97+
if (!buf)
98+
{
99+
buf = ft_calloc(1, 1);
100+
if (!buf)
101+
return (NULL);
102+
}
103+
buf = read_file(fd, buf);
104+
if (!buf)
105+
return (NULL);
106+
line = get_line(buf);
107+
if (!line)
108+
{
109+
free(buf);
110+
buf = NULL;
111+
}
112+
return (line);
113+
}

lib/get_next_line/get_next_line.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* get_next_line.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ebabaogl <[email protected] +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2024/11/03 11:09:46 by ebabaogl #+# #+# */
9+
/* Updated: 2024/11/03 14:40:10 by ebabaogl ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#ifndef GET_NEXT_LINE_H
14+
# define GET_NEXT_LINE_H
15+
16+
# ifndef BUFFER_SIZE
17+
# define BUFFER_SIZE 5
18+
# endif
19+
20+
# include <stddef.h>
21+
22+
char *get_next_line(int fd);
23+
24+
size_t ft_strlen(char *s);
25+
void *ft_memset(void *b, int c, size_t len);
26+
void *ft_calloc(size_t count, size_t size);
27+
char *ft_strchr(char *s, int c);
28+
char *ft_strjoin(char *s1, char *s2);
29+
30+
#endif
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* get_next_line_utils.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ebabaogl <[email protected] +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2024/11/03 11:09:52 by ebabaogl #+# #+# */
9+
/* Updated: 2024/11/03 14:08:40 by ebabaogl ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include <stdlib.h>
14+
15+
void *ft_memset(void *b, int c, size_t len)
16+
{
17+
unsigned char *ptr;
18+
19+
ptr = (unsigned char *)b;
20+
while (len--)
21+
*ptr++ = (unsigned char)c;
22+
return (b);
23+
}
24+
25+
void *ft_calloc(size_t count, size_t size)
26+
{
27+
unsigned char *ptr;
28+
size_t i;
29+
30+
ptr = malloc(size * count);
31+
if (!ptr)
32+
return (NULL);
33+
i = 0;
34+
while (i < size * count)
35+
ptr[i++] = 0;
36+
return (ptr);
37+
}
38+
39+
size_t ft_strlen(char *s)
40+
{
41+
const char *c;
42+
43+
if (!s)
44+
return (0);
45+
c = s;
46+
while (*c)
47+
c++;
48+
return (c - s);
49+
}
50+
51+
char *ft_strchr(char *s, int c)
52+
{
53+
unsigned char uc;
54+
55+
uc = (unsigned char)c;
56+
while (*s && *s != uc)
57+
s++;
58+
if (*s == uc || !uc)
59+
return ((char *)s);
60+
return (NULL);
61+
}
62+
63+
char *ft_strjoin(char *s1, char *s2)
64+
{
65+
char *str;
66+
char *ptr;
67+
68+
str = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
69+
if (!str || !s1 || !s2)
70+
return (NULL);
71+
ptr = str;
72+
while (*s1)
73+
*str++ = *s1++;
74+
while (*s2)
75+
*str++ = *s2++;
76+
return (ptr);
77+
}

0 commit comments

Comments
 (0)