Compare commits
32 Commits
909bb442b6
...
master
Author | SHA1 | Date | |
---|---|---|---|
42a0cfd5b6 | |||
595d220abd | |||
9a6d7b6ed7 | |||
b1170d5b5f | |||
d4f3a72f76 | |||
a241d049c4 | |||
d6117cfb8f | |||
8b200fb8ba | |||
7d7de10b7a | |||
1efd8e1a7b | |||
b66f8d6f5a | |||
8a0b32efda | |||
91c5ef0860 | |||
750d449f6c | |||
7addabc200 | |||
c8f6b30e1b | |||
1331231004 | |||
6312ed4cdc | |||
7c7b419c1b | |||
66f7fb04b2 | |||
2a8ffb82a2 | |||
f84f98fe21 | |||
4ab400b5e4 | |||
9e4e1b8e54 | |||
1088942133 | |||
eb54b7bc0f | |||
5deb78a5cf | |||
195f7bc66a | |||
b5315e3a0a | |||
650d9b1ab5 | |||
d7256c47a5 | |||
975e0c2ef5 |
39
Makefile
39
Makefile
@ -1,6 +1,22 @@
|
||||
SRCS = draw.c main.c shape.c xpm.c
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/01/20 14:41:36 by cchauvet #+# #+# #
|
||||
# Updated: 2023/01/20 14:41:42 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
OBJ = ${SRCS:.c=.o}
|
||||
SRCS = mandatory/asset.c mandatory/draw.c mandatory/key.c mandatory/main.c mandatory/map.c mandatory/parsing2.c mandatory/parsing.c mandatory/xpm.c
|
||||
|
||||
BSRCS = bonus/asset.c bonus/draw.c bonus/key.c bonus/main.c bonus/map.c bonus/parsing2.c bonus/parsing.c bonus/xpm.c
|
||||
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
|
||||
BOBJS = ${BSRCS:.c=.o}
|
||||
|
||||
NAME = so_long
|
||||
|
||||
@ -8,20 +24,26 @@ LIBS = libftx/libftx.a minilibx-linux/libmlx.a
|
||||
|
||||
CC = clang
|
||||
|
||||
FLAG = -Wall -Wextra -Werror -g
|
||||
FLAG = -Wall -Wextra -Werror
|
||||
|
||||
%.o: %.c
|
||||
${CC} ${FLAG} -c $< -o $@
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
${NAME}: ${OBJ}
|
||||
bonus: ${BOBJS}
|
||||
make -C libftx
|
||||
make -C minilibx-linux
|
||||
${CC} ${OBJ} -o ${NAME} ${LIBS} -lXext -lX11
|
||||
${CC} ${BOBJS} -o ${NAME} ${LIBS} -lXext -lX11
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
make -C libftx
|
||||
make -C minilibx-linux
|
||||
${CC} ${OBJS} -o ${NAME} ${LIBS} -lXext -lX11
|
||||
|
||||
clean:
|
||||
rm -f OBJ
|
||||
rm -f ${OBJS} ${BOBJS}
|
||||
rm -f textures/*
|
||||
make -C libftx clean
|
||||
make -C minilibx-linux clean
|
||||
|
||||
@ -30,6 +52,7 @@ fclean: clean
|
||||
make -C libftx fclean
|
||||
make -C minilibx-linux clean
|
||||
|
||||
re: fclean all
|
||||
re: fclean
|
||||
make all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
.PHONY: all clean fclean re bonus
|
||||
|
53
README.md
Normal file
53
README.md
Normal file
@ -0,0 +1,53 @@
|
||||
# Solong
|
||||
|
||||
This is my implementation of the Solong project for the 42 school.
|
||||
## Description
|
||||
|
||||
Solong is a simple 2D game where the player has to collect all the items in a maze and reach the exit. The game is written in C using the minilibx library for the graphics.
|
||||
|
||||
The project is composed of three parts:
|
||||
|
||||
- The parsing of the map file in a format specified by the subject.
|
||||
- The rendering of the game using the graphics library.
|
||||
- The game loop and the handling of user input.
|
||||
|
||||
## Installation
|
||||
To install this project clone this repo
|
||||
``` bash
|
||||
git clone https://git.chauvet.pro/starnakin/solong
|
||||
```
|
||||
### Mandatory
|
||||
To compile the game, simply run make in the root directory of the project. This will generate an executable called solong.
|
||||
``` bash
|
||||
make
|
||||
```
|
||||
### Bonus
|
||||
To compile the game, simply run make bonus in the root directory of the project. This will generate an executable called solong.
|
||||
``` bash
|
||||
make bonus
|
||||
```
|
||||
## Launch
|
||||
|
||||
To run the game, you need to provide a valid map file as an argument. For example:
|
||||
|
||||
``` bash
|
||||
./solong maps/map.ber
|
||||
```
|
||||
The game requires the minilibx library to be installed on your system. If you're using macOS, the library should be already installed. If you're using Linux, you may need to install it manually.
|
||||
## Controls
|
||||
|
||||
The player can be moved using the arrow keys or the WASD keys. Pressing the ESC key or closing the window will exit the game.
|
||||
## Screenshots
|
||||
|
||||
Here are some screenshots of the game:
|
||||
|
||||

|
||||
|
||||
## Resources
|
||||
|
||||

|
||||

|
||||
|
||||
## Author
|
||||
|
||||
This project was created by Camille Chauvet. If you have any questions or suggestions, feel free to contact me.
|
83
bonus/asset.c
Normal file
83
bonus/asset.c
Normal file
@ -0,0 +1,83 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* asset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/19 13:32:14 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "solong.h"
|
||||
|
||||
static void *ft_gen_asset(char *color, size_t case_size, t_data *data)
|
||||
{
|
||||
t_square square;
|
||||
char *name;
|
||||
int dimmension;
|
||||
void *img;
|
||||
|
||||
square.color = color;
|
||||
square.size = case_size;
|
||||
name = ft_xpm_gen_file(square);
|
||||
if (name == NULL)
|
||||
return (NULL);
|
||||
img = mlx_xpm_file_to_image(data->mlx,
|
||||
name, &dimmension, &dimmension);
|
||||
free(name);
|
||||
return (img);
|
||||
}
|
||||
|
||||
static char **ft_color_gen(void)
|
||||
{
|
||||
size_t i;
|
||||
char **tab;
|
||||
|
||||
tab = ft_calloc(NB_COLORS + 1, sizeof(char *));
|
||||
if (tab == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (i < NB_COLORS)
|
||||
{
|
||||
tab[i] = ft_ultoa_base(((1 << 23) * i) / NB_COLORS, HEX);
|
||||
if (tab[i] == NULL)
|
||||
{
|
||||
ft_cancel(tab, i);
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
tab[i] = NULL;
|
||||
return (tab);
|
||||
}
|
||||
|
||||
int ft_gen_assets(t_data *data)
|
||||
{
|
||||
char **colors;
|
||||
size_t i;
|
||||
|
||||
colors = ft_color_gen();
|
||||
if (colors == NULL)
|
||||
return (1);
|
||||
i = 0;
|
||||
while (i < NB_COLORS)
|
||||
{
|
||||
data->assets[i] = ft_gen_asset(colors[i], CASE_SIZE, data);
|
||||
if (data->assets[i] == NULL)
|
||||
{
|
||||
ft_freer_tab_ultimate(1, colors);
|
||||
return (1);
|
||||
}
|
||||
data->assets[i + NB_COLORS] = ft_gen_asset(colors[i],
|
||||
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, data);
|
||||
if (data->assets[i + NB_COLORS] == NULL)
|
||||
ft_freer_tab_ultimate(1, colors);
|
||||
if (data->assets[i + NB_COLORS] == NULL)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
ft_freer_tab_ultimate(1, colors);
|
||||
return (0);
|
||||
}
|
79
bonus/draw.c
Normal file
79
bonus/draw.c
Normal file
@ -0,0 +1,79 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* draw.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/13 15:49:23 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/19 15:20:56 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "solong.h"
|
||||
|
||||
void ft_draw_img(t_data *data, void *img, size_t x, size_t y)
|
||||
{
|
||||
if (img != NULL)
|
||||
mlx_put_image_to_window(data->mlx, data->window, img, x, y);
|
||||
}
|
||||
|
||||
static void *ft_char2img(t_data *data, char c)
|
||||
{
|
||||
if (c == 'C')
|
||||
return (data->assets[data->nb_swaps + 1 % NB_COLORS]);
|
||||
if (c == '1')
|
||||
return (data->assets[data->nb_swaps + 2 % NB_COLORS]);
|
||||
if (c == 'E')
|
||||
return (data->assets[data->nb_swaps + 3 % NB_COLORS]);
|
||||
if (c == 'P')
|
||||
return (data->assets[data->nb_swaps + 4 % NB_COLORS]);
|
||||
if (c == 'B')
|
||||
return (data->assets[data->nb_swaps + 5 % NB_COLORS]);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void ft_draw_foots(t_data *data)
|
||||
{
|
||||
char *foots;
|
||||
|
||||
data->nb_foots++;
|
||||
foots = ft_itoa(data->nb_foots);
|
||||
if (foots == NULL)
|
||||
{
|
||||
ft_printf("Memory error\n");
|
||||
ft_exit(data);
|
||||
}
|
||||
mlx_string_put(data->mlx, data->window, 10, 10, 255, foots);
|
||||
ft_printf("\r%s", foots);
|
||||
free(foots);
|
||||
}
|
||||
|
||||
int ft_draw_map(t_data *data)
|
||||
{
|
||||
ssize_t tab[2];
|
||||
char **patern;
|
||||
void *img;
|
||||
|
||||
ft_fill_pos(data->map);
|
||||
data->nb_swaps = ft_random_generator(0, NB_COLORS - 6);
|
||||
patern = ft_get_player_map(*data->map);
|
||||
if (patern == NULL)
|
||||
return (1);
|
||||
ft_draw_img(data, data->assets[data->nb_swaps % NB_COLORS + NB_COLORS], 0,
|
||||
0);
|
||||
tab[1] = -1;
|
||||
while (patern[++tab[1]] != NULL)
|
||||
{
|
||||
tab[0] = -1;
|
||||
while (patern[tab[1]][++tab[0]] != '\0')
|
||||
{
|
||||
img = ft_char2img(data, patern[tab[1]][tab[0]]);
|
||||
if (img != NULL)
|
||||
ft_draw_img(data, img, tab[0] * CASE_SIZE, tab[1] * CASE_SIZE);
|
||||
}
|
||||
}
|
||||
ft_freer_tab_ultimate(1, patern);
|
||||
ft_draw_foots(data);
|
||||
return (0);
|
||||
}
|
77
bonus/key.c
Normal file
77
bonus/key.c
Normal file
@ -0,0 +1,77 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* key.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/09 18:35:27 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/16 12:52:02 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "solong.h"
|
||||
|
||||
static void ft_case_update(char *new_pos, char *player_pos)
|
||||
{
|
||||
*new_pos = 'P';
|
||||
*player_pos = '0';
|
||||
}
|
||||
|
||||
static void ft_epileptic_mod(t_data *data)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < NB_COLORS * 100)
|
||||
{
|
||||
ft_draw_img(data, data->assets[(i % NB_COLORS) + NB_COLORS], 0, 0);
|
||||
write(1, "\a\a\a\a\a", 5);
|
||||
i++;
|
||||
}
|
||||
ft_exit(data);
|
||||
}
|
||||
|
||||
static void ft_move(t_data *data, char direction)
|
||||
{
|
||||
size_t tab[2];
|
||||
char *new_pos;
|
||||
|
||||
tab[0] = data->map->player_pos[0];
|
||||
tab[1] = data->map->player_pos[1];
|
||||
if (direction == 'L')
|
||||
new_pos = &data->map->patern[tab[1]][tab[0] - 1];
|
||||
if (direction == 'U')
|
||||
new_pos = &data->map->patern[tab[1] - 1][tab[0]];
|
||||
if (direction == 'D')
|
||||
new_pos = &data->map->patern[tab[1] + 1][tab[0]];
|
||||
if (direction == 'R')
|
||||
new_pos = &data->map->patern[tab[1]][tab[0] + 1];
|
||||
if (*new_pos == 'C')
|
||||
data->map->nb_collectable--;
|
||||
if (*new_pos == '0' || *new_pos == 'C')
|
||||
ft_case_update(new_pos, &data->map->patern[tab[1]][tab[0]]);
|
||||
if (*new_pos == 'E')
|
||||
{
|
||||
if (data->map->nb_collectable == 0)
|
||||
ft_exit(data);
|
||||
}
|
||||
if (*new_pos == 'B')
|
||||
ft_epileptic_mod(data);
|
||||
ft_draw_map(data);
|
||||
}
|
||||
|
||||
int ft_key(int keycode, t_data *data)
|
||||
{
|
||||
if (keycode == 65361)
|
||||
ft_move(data, 'L');
|
||||
else if (keycode == 65363)
|
||||
ft_move(data, 'R');
|
||||
else if (keycode == 65362)
|
||||
ft_move(data, 'U');
|
||||
else if (keycode == 65364)
|
||||
ft_move(data, 'D');
|
||||
else if (keycode == 65307)
|
||||
ft_exit(data);
|
||||
return (0);
|
||||
}
|
81
bonus/main.c
Normal file
81
bonus/main.c
Normal file
@ -0,0 +1,81 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/19 16:54:42 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "solong.h"
|
||||
|
||||
int ft_initialised(char *path, t_data *data)
|
||||
{
|
||||
t_map *map;
|
||||
|
||||
map = ft_getmap(path);
|
||||
if (map == NULL)
|
||||
{
|
||||
ft_printf("Map error\n");
|
||||
exit(1);
|
||||
}
|
||||
data->mlx = mlx_init();
|
||||
ft_printf("Generating assets ...");
|
||||
if (ft_gen_assets(data))
|
||||
ft_exit(data);
|
||||
ft_printf("\rGenerating assets [FINISHED]\n");
|
||||
data->map = map;
|
||||
data->window = mlx_new_window(data->mlx,
|
||||
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE,
|
||||
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, "long");
|
||||
data->nb_foots = 0;
|
||||
data->nb_swaps = ft_random_generator(0, NB_COLORS - 6);
|
||||
ft_draw_map(data);
|
||||
mlx_hook(data->window, 17, (0L), ft_exit, data);
|
||||
mlx_hook(data->window, 2, (1L << 0), ft_key, data);
|
||||
mlx_loop(data->mlx);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_exit(t_data *data)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < NB_COLORS * 2)
|
||||
{
|
||||
if (data->assets[i] != NULL)
|
||||
mlx_destroy_image(data->mlx, data->assets[i]);
|
||||
i++;
|
||||
}
|
||||
if (data->map != NULL && data->map->patern != NULL)
|
||||
ft_freer_tab_ultimate(1, data->map->patern);
|
||||
if (data->window != NULL && data->mlx != NULL)
|
||||
mlx_destroy_window(data->mlx, data->window);
|
||||
if (data->mlx != NULL)
|
||||
mlx_destroy_display(data->mlx);
|
||||
if (data->mlx != NULL)
|
||||
free(data->mlx);
|
||||
if (data->map != NULL)
|
||||
free(data->map);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
t_data data;
|
||||
|
||||
if (ac != 2 || ft_strcmp(av[1] + ft_strlen(av[1]) - 4, ".ber"))
|
||||
{
|
||||
ft_printf("Map error\n");
|
||||
return (1);
|
||||
}
|
||||
data.map = NULL;
|
||||
data.window = NULL;
|
||||
if (ft_initialised(av[1], &data))
|
||||
ft_printf("Memory error");
|
||||
return (1);
|
||||
}
|
139
bonus/map.c
Normal file
139
bonus/map.c
Normal file
@ -0,0 +1,139 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/05 13:51:49 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/13 13:56:07 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "solong.h"
|
||||
|
||||
char **ft_readfile(char *path)
|
||||
{
|
||||
char **map;
|
||||
int fd;
|
||||
size_t nb_line;
|
||||
|
||||
fd = open(path, O_RDONLY);
|
||||
nb_line = 1;
|
||||
map = ft_calloc(sizeof(char *), 2);
|
||||
if (map == NULL)
|
||||
return (NULL);
|
||||
map[0] = get_next_line(fd);
|
||||
while (map[nb_line - 1] != NULL)
|
||||
{
|
||||
ft_strchr(map[nb_line - 1], '\n')[0] = '\0';
|
||||
map[nb_line] = get_next_line(fd);
|
||||
map = ft_tabrealloc(map, nb_line + 1, nb_line + 2);
|
||||
if (map == NULL)
|
||||
return (NULL);
|
||||
nb_line++;
|
||||
}
|
||||
return (map);
|
||||
}
|
||||
|
||||
void ft_fill_pos(t_map *map)
|
||||
{
|
||||
size_t x;
|
||||
size_t y;
|
||||
|
||||
y = 1;
|
||||
while (map->patern[y + 1] != NULL)
|
||||
{
|
||||
x = 0;
|
||||
while (x < ft_strlen(map->patern[y]))
|
||||
{
|
||||
if (map->patern[y][x] == 'P')
|
||||
{
|
||||
map->player_pos[0] = x;
|
||||
map->player_pos[1] = y;
|
||||
}
|
||||
if (map->patern[y][x] == 'E')
|
||||
{
|
||||
map->exit_pos[0] = x;
|
||||
map->exit_pos[1] = y;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
t_map *ft_getmap(char *path)
|
||||
{
|
||||
t_map *map;
|
||||
|
||||
map = ft_calloc(sizeof(t_map), 1);
|
||||
if (map == NULL)
|
||||
return (NULL);
|
||||
map->patern = ft_readfile(path);
|
||||
if (ft_map_is_correct(map) == 0)
|
||||
{
|
||||
ft_freer_tab_ultimate(1, map->patern);
|
||||
free(map);
|
||||
return (NULL);
|
||||
}
|
||||
return (map);
|
||||
}
|
||||
|
||||
static char *ft_get_line(const char *line, ssize_t player_x)
|
||||
{
|
||||
char *out;
|
||||
ssize_t start;
|
||||
ssize_t stop;
|
||||
ssize_t i;
|
||||
ssize_t y;
|
||||
|
||||
out = ft_strgen('0', RENDER_DISTANCE * 2 + 1);
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
start = player_x - (RENDER_DISTANCE);
|
||||
if (start < 0)
|
||||
start = 0;
|
||||
stop = player_x + RENDER_DISTANCE + 1;
|
||||
if (stop > (ssize_t) ft_strlen(line))
|
||||
stop = ft_strlen(line);
|
||||
i = 0;
|
||||
y = player_x - RENDER_DISTANCE - start;
|
||||
if (y < 0)
|
||||
y = -y;
|
||||
while (start + i < stop)
|
||||
{
|
||||
out[y + i] = line[i + start];
|
||||
i++;
|
||||
}
|
||||
return (out);
|
||||
}
|
||||
|
||||
char **ft_get_player_map(t_map map)
|
||||
{
|
||||
char **player_map;
|
||||
ssize_t y;
|
||||
ssize_t i;
|
||||
|
||||
player_map = ft_calloc(RENDER_DISTANCE * 2 + 2, sizeof(char *));
|
||||
if (player_map == NULL)
|
||||
return (NULL);
|
||||
i = map.player_pos[1] - RENDER_DISTANCE;
|
||||
if (i < 0)
|
||||
i = 0;
|
||||
y = -1;
|
||||
while (++y < RENDER_DISTANCE * 2 + 1)
|
||||
{
|
||||
if (map.player_pos[1] + y >= RENDER_DISTANCE && map.patern[i] != NULL)
|
||||
player_map[y] = ft_get_line(map.patern[i++], map.player_pos[0]);
|
||||
else
|
||||
player_map[y] = ft_strgen('0', RENDER_DISTANCE * 2 + 1);
|
||||
if (player_map[y] == NULL)
|
||||
{
|
||||
ft_cancel(player_map, y);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
player_map[y] = NULL;
|
||||
return (player_map);
|
||||
}
|
121
bonus/parsing.c
Normal file
121
bonus/parsing.c
Normal file
@ -0,0 +1,121 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/05 20:14:44 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/16 18:48:43 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "solong.h"
|
||||
|
||||
int ft_test_map_dimmention(t_map *map)
|
||||
{
|
||||
size_t i;
|
||||
size_t len;
|
||||
|
||||
len = ft_strlen(map->patern[0]);
|
||||
i = 1;
|
||||
while (map->patern[i] != NULL)
|
||||
{
|
||||
if (ft_strlen(map->patern[i]) != len)
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
map->x_len = len;
|
||||
map->y_len = i;
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_test_map_content1(t_map *map)
|
||||
{
|
||||
size_t x;
|
||||
size_t y;
|
||||
size_t nb_collectable;
|
||||
|
||||
nb_collectable = 0;
|
||||
y = 0;
|
||||
while (y < map->y_len)
|
||||
{
|
||||
x = 0;
|
||||
while (x < map->x_len)
|
||||
{
|
||||
if (ft_is_in("01CEPB", map->patern[y][x]) == 0)
|
||||
return (0);
|
||||
if (map->patern[y][x] == 'C')
|
||||
nb_collectable++;
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
if (nb_collectable == 0)
|
||||
return (0);
|
||||
map->nb_collectable = nb_collectable;
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_test_map_content2(char **patern)
|
||||
{
|
||||
size_t x;
|
||||
size_t y;
|
||||
size_t test1;
|
||||
size_t test2;
|
||||
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
y = 0;
|
||||
while (patern[y + 1] != NULL)
|
||||
{
|
||||
x = 0;
|
||||
while (x < ft_strlen(patern[y]))
|
||||
{
|
||||
if (patern[y][x] == 'E')
|
||||
test1++;
|
||||
else if (patern[y][x] == 'P')
|
||||
test2++;
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
return (test1 == 1 && test2 == 1);
|
||||
}
|
||||
|
||||
int ft_test_map_is_surronded(t_map map)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!ft_contain_only(map.patern[0], '1'))
|
||||
return (0);
|
||||
i = 1;
|
||||
while (map.patern[i + 1] != NULL)
|
||||
{
|
||||
if (map.patern[i][0] != '1')
|
||||
return (0);
|
||||
if (map.patern[i][ft_strlen(map.patern[i]) - 1] != '1')
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
if (!ft_contain_only(map.patern[i], '1'))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_map_is_correct(t_map *map)
|
||||
{
|
||||
if (!ft_test_map_dimmention(map))
|
||||
return (0);
|
||||
if (!ft_test_map_content1(map))
|
||||
return (0);
|
||||
if (!ft_test_map_content2(map->patern))
|
||||
return (0);
|
||||
if (!ft_test_map_dimmention(map))
|
||||
return (0);
|
||||
if (!ft_test_map_is_surronded(*map))
|
||||
return (0);
|
||||
if (!ft_test_map_is_finishable(map))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
73
bonus/parsing2.c
Normal file
73
bonus/parsing2.c
Normal file
@ -0,0 +1,73 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/12 16:17:20 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/16 18:48:20 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "solong.h"
|
||||
|
||||
static void ft_collector(char **patern, size_t x, size_t y)
|
||||
{
|
||||
if (ft_is_in("1B", patern[y][x]))
|
||||
return ;
|
||||
patern[y][x] = '1';
|
||||
ft_collector(patern, x, y - 1);
|
||||
ft_collector(patern, x + 1, y);
|
||||
ft_collector(patern, x, y + 1);
|
||||
ft_collector(patern, x - 1, y);
|
||||
}
|
||||
|
||||
static char **ft_patern_dup(char **patern)
|
||||
{
|
||||
char **patern2;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (patern[i] != NULL)
|
||||
i++;
|
||||
patern2 = ft_calloc(i + 1, sizeof(char *));
|
||||
if (patern2 == NULL)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (patern[i] != NULL)
|
||||
{
|
||||
patern2[i] = ft_strdup(patern[i]);
|
||||
if (patern2[i] == NULL)
|
||||
{
|
||||
ft_cancel(patern2, i);
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
patern2[i] = NULL;
|
||||
return (patern2);
|
||||
}
|
||||
|
||||
int ft_test_map_is_finishable(t_map *map)
|
||||
{
|
||||
size_t i;
|
||||
int ok;
|
||||
char **patern;
|
||||
|
||||
patern = ft_patern_dup(map->patern);
|
||||
if (patern == NULL)
|
||||
return (1);
|
||||
ft_fill_pos(map);
|
||||
ft_collector(patern, map->player_pos[0], map->player_pos[1]);
|
||||
i = 1;
|
||||
ok = 1;
|
||||
while (patern[i + 1] != NULL)
|
||||
{
|
||||
if (ft_is_in(patern[i], 'C') || ft_is_in(patern[i], 'E'))
|
||||
ok = 0;
|
||||
i++;
|
||||
}
|
||||
ft_freer_tab_ultimate(1, patern);
|
||||
return (ok);
|
||||
}
|
67
bonus/solong.h
Normal file
67
bonus/solong.h
Normal file
@ -0,0 +1,67 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* solong.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 16:20:03 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/19 13:40:52 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SOLONG_H
|
||||
# define SOLONG_H
|
||||
# include "../libftx/libftx.h"
|
||||
# define XPM_PATH "./textures/"
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include "../minilibx-linux/mlx.h"
|
||||
# define CASE_SIZE 128
|
||||
# define XPM_HEADER "\nstatic char * XFACE[] = {\""
|
||||
# define RENDER_DISTANCE 4
|
||||
# define NB_COLORS 100
|
||||
# define HEX "0123456789abcdef"
|
||||
|
||||
typedef struct s_square
|
||||
{
|
||||
char *color;
|
||||
size_t size;
|
||||
} t_square;
|
||||
|
||||
typedef struct s_map
|
||||
{
|
||||
size_t x_len;
|
||||
size_t y_len;
|
||||
size_t nb_collectable;
|
||||
char **patern;
|
||||
size_t player_pos[2];
|
||||
size_t exit_pos[2];
|
||||
} t_map;
|
||||
|
||||
typedef struct s_data
|
||||
{
|
||||
void *mlx;
|
||||
void *window;
|
||||
void *assets[NB_COLORS * 2];
|
||||
t_map *map;
|
||||
size_t nb_swaps;
|
||||
size_t nb_foots;
|
||||
} t_data;
|
||||
|
||||
int ft_test_map_is_finishable(t_map *map);
|
||||
int ft_exit(t_data *data);
|
||||
int ft_test_map_content2(char **patern);
|
||||
int ft_key(int key, t_data *data);
|
||||
void ft_fill_pos(t_map *map);
|
||||
char *name_generator(t_square square);
|
||||
t_map *ft_getmap(char *path);
|
||||
char *ft_xpm_gen_file(t_square square);
|
||||
int ft_gen_assets(t_data *data);
|
||||
char **ft_get_player_map(t_map map);
|
||||
int ft_draw_map(t_data *data);
|
||||
char *name_generator(t_square square);
|
||||
int ft_color_changer(t_data *data);
|
||||
void ft_draw_img(t_data *data, void *img, size_t x, size_t y);
|
||||
int ft_map_is_correct(t_map *map);
|
||||
#endif
|
115
bonus/xpm.c
Normal file
115
bonus/xpm.c
Normal file
@ -0,0 +1,115 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* xpm.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 13:53:03 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/19 12:34:40 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "solong.h"
|
||||
|
||||
static char *ft_square(size_t size)
|
||||
{
|
||||
char *map;
|
||||
size_t x;
|
||||
size_t y;
|
||||
|
||||
map = malloc(((size + 4) * size) * sizeof(char));
|
||||
if (map == NULL)
|
||||
return (map);
|
||||
y = 0;
|
||||
while (y < size)
|
||||
{
|
||||
map[(size + 4) * y] = '"';
|
||||
x = 0;
|
||||
while (x < size)
|
||||
{
|
||||
map[y * (size + 4) + x + 1] = 'a';
|
||||
x++;
|
||||
}
|
||||
map[(size + 4) * y + size + 1] = '"';
|
||||
map[(size + 4) * y + size + 2] = ',';
|
||||
map[(size + 4) * y + size + 3] = '\n';
|
||||
y++;
|
||||
}
|
||||
map[(size + 4) * size - 2] = '\0';
|
||||
return (map);
|
||||
}
|
||||
|
||||
char *name_generator(t_square square)
|
||||
{
|
||||
char *out;
|
||||
char *size;
|
||||
char *temp;
|
||||
|
||||
size = ft_itoa(square.size);
|
||||
if (size == NULL)
|
||||
return (NULL);
|
||||
temp = ft_strmerger(3, XPM_PATH, square.color, "_");
|
||||
if (temp == NULL)
|
||||
{
|
||||
free(size);
|
||||
return (NULL);
|
||||
}
|
||||
out = ft_strmerger(5, temp, size, "x", size, ".xpm");
|
||||
free(size);
|
||||
free(temp);
|
||||
return (out);
|
||||
}
|
||||
|
||||
static char *ft_gen_xpm_content(t_square square)
|
||||
{
|
||||
char *content;
|
||||
char *temp;
|
||||
char *map;
|
||||
|
||||
temp = ft_itoa(square.size);
|
||||
if (temp == NULL)
|
||||
return (NULL);
|
||||
content = ft_strmerger(5, XPM_HEADER, temp, " ", temp, " 1 1\",\n\"");
|
||||
free(temp);
|
||||
if (content == NULL)
|
||||
return (NULL);
|
||||
temp = ft_strmerger(5, "/* XPM */", content, "a c #", square.color, "\",\n");
|
||||
free(content);
|
||||
if (temp == NULL)
|
||||
return (NULL);
|
||||
map = ft_square(square.size);
|
||||
if (map == NULL)
|
||||
{
|
||||
free(temp);
|
||||
return (NULL);
|
||||
}
|
||||
content = ft_strmerger(3, temp, map, "};");
|
||||
free(temp);
|
||||
free(map);
|
||||
return (content);
|
||||
}
|
||||
|
||||
char *ft_xpm_gen_file(t_square square)
|
||||
{
|
||||
char *file_content;
|
||||
char *path;
|
||||
int fd;
|
||||
|
||||
path = name_generator(square);
|
||||
if (path == NULL)
|
||||
return (NULL);
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
file_content = ft_gen_xpm_content(square);
|
||||
fd = open(path, O_WRONLY | O_CREAT, 0644);
|
||||
write(fd, file_content, ft_strlen(file_content));
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
free(file_content);
|
||||
}
|
||||
else
|
||||
close(fd);
|
||||
return (path);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
:# **************************************************************************** #
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
@ -6,19 +6,19 @@
|
||||
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
||||
# Updated: 2023/01/04 20:00:03 by cchauvet ### ########.fr #
|
||||
# Updated: 2023/01/19 12:55:43 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
CC = clang
|
||||
|
||||
SRCS = ft_strcmp.c ft_strfjoin.c ft_strmerger.c
|
||||
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
NAME = extra.a
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
CFLAGS = -Wall -Werror -Wextra -g
|
||||
|
||||
%.o: %.c extra.h
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/04 19:59:10 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/19 17:37:25 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,9 +14,23 @@
|
||||
# define EXTRA_H
|
||||
# include <stdarg.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include "../libft/libft.h"
|
||||
|
||||
char *ft_ultoa_base(unsigned long long n, char *base);
|
||||
char *get_next_line(int fd);
|
||||
size_t ft_random_generator(size_t start, size_t stop);
|
||||
void ft_freer_tab_ultimate(size_t len, ...);
|
||||
void ft_freer_ultimate(size_t len, ...);
|
||||
char *ft_strgen(char c, size_t len);
|
||||
char *ft_strfjoin(char *s1, char *s2);
|
||||
char *ft_strmerger(size_t arg_len, ...);
|
||||
int ft_is_in(char *str, char c);
|
||||
char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size);
|
||||
char *ft_strndup(char *src, size_t n);
|
||||
ssize_t ft_strchri(char *str, char c);
|
||||
int ft_contain_only_str(char *str, char *to_find);
|
||||
int ft_contain_only(char *str, char c);
|
||||
int ft_strcmp(char *s1, char *s2);
|
||||
#endif
|
||||
|
@ -1,27 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* draw.c :+: :+: :+: */
|
||||
/* ft_contain_only.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/13 15:49:23 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/04 19:05:04 by cchauvet ### ########.fr */
|
||||
/* Created: 2023/01/12 16:28:20 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/12 16:31:22 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "solong.h"
|
||||
#include "extra.h"
|
||||
|
||||
void ft_draw_xpm(void *mlx, void *window, char *file, size_t *cord)
|
||||
int ft_contain_only(char *str, char c)
|
||||
{
|
||||
char *img_path;
|
||||
void *img;
|
||||
int bozo;
|
||||
size_t i;
|
||||
|
||||
img_path = ft_strmerger(2, XPM_PATH, file);
|
||||
if (img_path == NULL)
|
||||
return ;
|
||||
img = mlx_xpm_file_to_image(mlx, img_path, &bozo, &bozo);
|
||||
mlx_put_image_to_window(mlx, window, img, cord[0], cord[1]);
|
||||
mlx_destroy_image(mlx, img);
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] != c)
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_contain_only_str(char *str, char *to_find)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (!ft_is_in(to_find, str[i]))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
58
libftx/extra/ft_freer.c
Normal file
58
libftx/extra/ft_freer.c
Normal file
@ -0,0 +1,58 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_freer.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/08 15:01:40 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/09 17:57:52 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
void ft_freer_ultimate(size_t len, ...)
|
||||
{
|
||||
va_list va;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
va_start(va, len);
|
||||
while (i < len)
|
||||
{
|
||||
free(va_arg(va, char *));
|
||||
i++;
|
||||
}
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void ft_freer_tab(char **tab)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (tab == NULL)
|
||||
return ;
|
||||
i = 0;
|
||||
while (tab[i] != NULL)
|
||||
{
|
||||
free(tab[i]);
|
||||
i++;
|
||||
}
|
||||
free(tab);
|
||||
}
|
||||
|
||||
void ft_freer_tab_ultimate(size_t len, ...)
|
||||
{
|
||||
va_list va;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
va_start(va, len);
|
||||
while (i < len)
|
||||
{
|
||||
ft_freer_tab(va_arg(va, char **));
|
||||
i++;
|
||||
}
|
||||
va_end(va);
|
||||
}
|
27
libftx/extra/ft_is_in.c
Normal file
27
libftx/extra/ft_is_in.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_in.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/05 20:29:53 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/08 12:15:08 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
int ft_is_in(char *str, char c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] == c)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
38
libftx/extra/ft_random_generator.c
Normal file
38
libftx/extra/ft_random_generator.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_random_generator.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/09 18:43:27 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/09 20:09:33 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
size_t ft_random_generator(size_t start, size_t stop)
|
||||
{
|
||||
int fd;
|
||||
char *line;
|
||||
int sum;
|
||||
size_t i;
|
||||
|
||||
fd = open("/dev/random", O_RDONLY);
|
||||
if (fd == -1)
|
||||
return (0);
|
||||
line = ft_calloc(sizeof(char), 10001);
|
||||
if (line == NULL)
|
||||
return (0);
|
||||
read(fd, line, 10000);
|
||||
sum = 0;
|
||||
i = 0;
|
||||
while (i < ft_strlen(line))
|
||||
{
|
||||
sum += (unsigned int) line[i];
|
||||
i++;
|
||||
}
|
||||
free(line);
|
||||
return (sum % (stop - start));
|
||||
}
|
27
libftx/extra/ft_strchri.c
Normal file
27
libftx/extra/ft_strchri.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/05 19:22:58 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/10 18:30:35 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
ssize_t ft_strchri(char *str, char c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (str == NULL)
|
||||
return (-1);
|
||||
i = 0;
|
||||
while (str[i] != c && str[i] != '\0')
|
||||
i++;
|
||||
if (str[i] == '\0')
|
||||
return (-1);
|
||||
return (i);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 19:20:47 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/04 19:22:20 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/05 13:20:20 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,7 +14,10 @@
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
while (*s1 == *s2 && *s1 != '\0')
|
||||
s1++;
|
||||
return (*s1 - *s2);
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s1[i] == s2[i] && s1[i] != '\0')
|
||||
i++;
|
||||
return (s1[i] - s2[i]);
|
||||
}
|
||||
|
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 14:06:04 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/04 14:17:40 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/10 18:29:59 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,22 +14,28 @@
|
||||
|
||||
char *ft_strfjoin(char *s1, char *s2)
|
||||
{
|
||||
size_t i;
|
||||
size_t y;
|
||||
ssize_t i;
|
||||
ssize_t y;
|
||||
char *out;
|
||||
|
||||
out = malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char));
|
||||
out = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = -1;
|
||||
i = 0;
|
||||
if (s1 != NULL)
|
||||
{
|
||||
i = -1;
|
||||
while (s1[++i] != '\0')
|
||||
out[i] = s1[i];
|
||||
}
|
||||
free(s1);
|
||||
y = -1;
|
||||
y = 0;
|
||||
if (s2 != NULL)
|
||||
{
|
||||
y = -1;
|
||||
while (s2[++y] != '\0')
|
||||
out[i + y] = s2[y];
|
||||
}
|
||||
free(s2);
|
||||
out[i + y] = '\0';
|
||||
return (out);
|
||||
|
Binary file not shown.
31
libftx/extra/ft_strgen.c
Normal file
31
libftx/extra/ft_strgen.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strgen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/08 12:32:52 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/09 18:04:31 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
char *ft_strgen(char c, size_t len)
|
||||
{
|
||||
char *out;
|
||||
size_t i;
|
||||
|
||||
out = ft_calloc((len + 1), sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
out[i] = c;
|
||||
i++;
|
||||
}
|
||||
out[len] = '\0';
|
||||
return (out);
|
||||
}
|
Binary file not shown.
32
libftx/extra/ft_strndup.c
Normal file
32
libftx/extra/ft_strndup.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strndup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/26 00:55:44 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/05 19:27:03 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
char *ft_strndup(char *src, size_t n)
|
||||
{
|
||||
char *out;
|
||||
size_t i;
|
||||
|
||||
if (src[0] == '\0')
|
||||
return (NULL);
|
||||
out = ft_calloc(n + 1, sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (src[i] != '\0' && i < n)
|
||||
{
|
||||
out[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
return (out);
|
||||
}
|
0
libftx/extra/ft_tabrealloc-5f29f43f.o.tmp
Normal file
0
libftx/extra/ft_tabrealloc-5f29f43f.o.tmp
Normal file
31
libftx/extra/ft_tabrealloc.c
Normal file
31
libftx/extra/ft_tabrealloc.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tabrealloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/05 18:58:48 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/10 18:30:21 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size)
|
||||
{
|
||||
char **new;
|
||||
size_t i;
|
||||
|
||||
new = ft_calloc(new_size, sizeof(char *));
|
||||
if (new == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (i < current_size)
|
||||
{
|
||||
new[i] = tab[i];
|
||||
i++;
|
||||
}
|
||||
free(tab);
|
||||
return (new);
|
||||
}
|
BIN
libftx/extra/ft_ultoa.o
Normal file
BIN
libftx/extra/ft_ultoa.o
Normal file
Binary file not shown.
89
libftx/extra/ft_ultoa_base.c
Normal file
89
libftx/extra/ft_ultoa_base.c
Normal file
@ -0,0 +1,89 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultoa_base.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 13:49:45 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/19 13:01:09 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
static size_t ft_str_size(unsigned long long n, size_t base_size)
|
||||
{
|
||||
size_t size;
|
||||
|
||||
size = 1;
|
||||
if (n == 0)
|
||||
return (2);
|
||||
while (n != 0)
|
||||
{
|
||||
n = n / base_size;
|
||||
size++;
|
||||
}
|
||||
return (size);
|
||||
}
|
||||
|
||||
static int ft_isdup(char *str)
|
||||
{
|
||||
char c;
|
||||
size_t i;
|
||||
|
||||
while (*str != 0)
|
||||
{
|
||||
c = *str;
|
||||
i = 1;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
if (str[i] == c)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static size_t ft_base_size(char *base)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if (ft_isdup(base))
|
||||
return (0);
|
||||
len = ft_strlen(base);
|
||||
if (len < 2)
|
||||
return (0);
|
||||
return (len);
|
||||
}
|
||||
|
||||
char *ft_ultoa_base(unsigned long long n, char *base)
|
||||
{
|
||||
size_t base_size;
|
||||
int str_size;
|
||||
char *out;
|
||||
size_t i;
|
||||
|
||||
if (base == NULL)
|
||||
return (NULL);
|
||||
base_size = ft_base_size(base);
|
||||
if (base_size == 0)
|
||||
return (NULL);
|
||||
str_size = ft_str_size(n, base_size);
|
||||
out = ft_calloc(str_size + 1, sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
if (n == 0)
|
||||
out[0] = base[0];
|
||||
while (n != 0)
|
||||
{
|
||||
out[str_size - 2 - i] = base[n % base_size];
|
||||
n /= base_size;
|
||||
i++;
|
||||
}
|
||||
out[str_size - 1] = '\0';
|
||||
return (out);
|
||||
}
|
@ -6,17 +6,17 @@
|
||||
# By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/12/14 15:49:18 by cchauvet #+# #+# #
|
||||
# Updated: 2022/12/14 16:08:19 by cchauvet ### ########.fr #
|
||||
# Updated: 2023/01/05 19:22:40 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
SRCS = get_next_line.c get_next_line_utils.c
|
||||
SRCS = get_next_line.c
|
||||
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
|
||||
NAME = get_next_line.a
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
CFLAGS = -Wall -Werror -Wextra -g
|
||||
|
||||
CC = clang
|
||||
|
||||
|
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/26 00:52:47 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/11/14 15:37:48 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/05 13:07:10 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -36,7 +36,7 @@ char *ft_getline(int fd)
|
||||
|
||||
stash = NULL;
|
||||
buf = NULL;
|
||||
while (ft_strchr(stash, '\n') == -1)
|
||||
while (ft_strchri(stash, '\n') == -1)
|
||||
{
|
||||
buf = ft_getstash(fd);
|
||||
if (buf == NULL)
|
||||
@ -54,7 +54,7 @@ char *ft_getreturn(char *str)
|
||||
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
i = ft_strchr(str, '\n') + 1;
|
||||
i = ft_strchri(str, '\n') + 1;
|
||||
if (i == 0)
|
||||
i = ft_strlen(str);
|
||||
return (ft_strndup(str, i));
|
||||
@ -67,7 +67,7 @@ char *ft_getextra(char *str)
|
||||
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
i = ft_strchr(str, '\n') + 1;
|
||||
i = ft_strchri(str, '\n') + 1;
|
||||
if (i == 0)
|
||||
return (NULL);
|
||||
j = ft_strlen(str + i);
|
||||
@ -81,7 +81,7 @@ char *get_next_line(int fd)
|
||||
char *buf2;
|
||||
|
||||
buf2 = stash;
|
||||
if (ft_strchr(stash, '\n') == -1)
|
||||
if (ft_strchri(stash, '\n') == -1)
|
||||
{
|
||||
buf1 = ft_getline(fd);
|
||||
buf2 = ft_strfjoin(stash, buf1);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/11/14 15:38:06 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/04 20:05:54 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/10 18:26:56 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,12 +17,9 @@
|
||||
# ifndef BUFFER_SIZE
|
||||
# define BUFFER_SIZE 42
|
||||
# endif
|
||||
# include "../libft/libft.h"
|
||||
# include "../extra/extra.h"
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
void *ft_realloc(void *ptr, size_t size);
|
||||
char *ft_strfjoin(char *dst, char *src);
|
||||
char *ft_strndup(char *src, size_t n);
|
||||
size_t ft_strlen(char *str);
|
||||
ssize_t ft_strchr(char *str, char c);
|
||||
char *get_next_line(int fd);
|
||||
|
||||
#endif
|
||||
|
Binary file not shown.
@ -1,106 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/26 00:55:44 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/11/14 15:39:50 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "get_next_line.h"
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
char *tab;
|
||||
size_t i;
|
||||
|
||||
if (nmemb == 0 || size * nmemb / nmemb != size)
|
||||
return (NULL);
|
||||
tab = malloc(nmemb * size);
|
||||
if (tab == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (i < size * nmemb)
|
||||
{
|
||||
tab[i] = 0;
|
||||
i++;
|
||||
}
|
||||
return ((void *) tab);
|
||||
}
|
||||
|
||||
size_t ft_strlen(char *str)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (str == NULL)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_strfjoin(char *s1, char *s2)
|
||||
{
|
||||
ssize_t i;
|
||||
ssize_t j;
|
||||
char *out;
|
||||
|
||||
out = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
if (s1 != NULL)
|
||||
{
|
||||
while (s1[i] != '\0')
|
||||
{
|
||||
out[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
free(s1);
|
||||
j = -1;
|
||||
if (s2 != NULL)
|
||||
{
|
||||
while (s2[++j] != '\0')
|
||||
out[i + j] = s2[j];
|
||||
}
|
||||
free(s2);
|
||||
return (out);
|
||||
}
|
||||
|
||||
char *ft_strndup(char *src, size_t n)
|
||||
{
|
||||
char *out;
|
||||
size_t i;
|
||||
|
||||
if (src[0] == '\0')
|
||||
return (NULL);
|
||||
out = ft_calloc(n + 1, sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (src[i] != '\0' && i < n)
|
||||
{
|
||||
out[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
return (out);
|
||||
}
|
||||
|
||||
ssize_t ft_strchr(char *str, char c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (str == NULL)
|
||||
return (-1);
|
||||
i = 0;
|
||||
while (str[i] != c && str[i] != '\0')
|
||||
i++;
|
||||
if (str[i] == '\0')
|
||||
return (-1);
|
||||
return (i);
|
||||
}
|
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
||||
# Updated: 2023/01/04 15:35:42 by cchauvet ### ########.fr #
|
||||
# Updated: 2023/01/05 17:44:37 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -63,7 +63,7 @@ BOBJS = $(BSRCS:.c=.o)
|
||||
|
||||
NAME = libft.a
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
CFLAGS = -Wall -Werror -Wextra -g
|
||||
|
||||
%.o: %.c libft.h
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 13:49:45 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/29 18:07:15 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/09 13:51:09 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,13 +6,13 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 22:23:35 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/29 22:24:53 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/05 18:54:54 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
void ft_putchar_fd(int fd, char c)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,13 +6,13 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/05 19:04:34 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/28 19:23:45 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/06 19:33:51 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void *ft_cancel(char **tab, size_t len)
|
||||
void *ft_cancel(char **tab, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,15 +6,18 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 12:03:59 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/27 09:02:11 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/05 17:46:12 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include <stddef.h>
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t length;
|
||||
|
||||
if (s == NULL)
|
||||
return (0);
|
||||
length = 0;
|
||||
while (s[length])
|
||||
length++;
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/04 15:20:30 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/06 19:34:13 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
|
||||
void *ft_cancel(char **tab, size_t len);
|
||||
int ft_atoi(const char *nptr);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
@ -46,7 +47,7 @@ char **ft_split(char const *s, char c);
|
||||
char *ft_itoa(int n);
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putchar_fd(int fd, char c);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
|
BIN
libftx/libftx.a
BIN
libftx/libftx.a
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/04 20:07:06 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/18 19:21:40 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,13 +16,24 @@
|
||||
# include <unistd.h>
|
||||
# include <stdarg.h>
|
||||
|
||||
char *ft_ultoa_base(unsigned long long n, char *base);
|
||||
int ft_printf(const char *format, ...);
|
||||
char *get_next_line(int fd);
|
||||
|
||||
char *ft_strfjoin(char *s1, char *s2);
|
||||
char *ft_strmerger(size_t arg_len, ...);
|
||||
size_t ft_random_generator(size_t start, size_t stop);
|
||||
void ft_freer_tab_ultimate(size_t len, ...);
|
||||
void ft_freer_ultimate(size_t len, ...);
|
||||
char *ft_strgen(char c, size_t len);
|
||||
int ft_is_in(char *str, char c);
|
||||
char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size);
|
||||
int ft_contain_only_str(char *str, char *to_find);
|
||||
int ft_contain_only(char *str, char c);
|
||||
char *ft_strfjoin(char *s1, char *s2);
|
||||
char *ft_strmerger(size_t arg_len, ...);
|
||||
int ft_strcmp(char *s1, char *s2);
|
||||
ssize_t ft_strchri(char *str, char c);
|
||||
char *ft_strndup(char *src, size_t n);
|
||||
|
||||
void *ft_cancel(char **tab, size_t len);
|
||||
int ft_atoi(const char *nptr);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
@ -54,10 +65,10 @@ char **ft_split(char const *s, char c);
|
||||
char *ft_itoa(int n);
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
void ft_putchar_fd(int fd, char c);
|
||||
void ft_putstr_fd(int fd, char *s);
|
||||
void ft_putendl_fd(int fd, char *s);
|
||||
void ft_putnbr_fd(int fd, int n);
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
|
@ -6,22 +6,22 @@
|
||||
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
||||
# Updated: 2023/01/04 15:36:08 by cchauvet ### ########.fr #
|
||||
# Updated: 2023/01/05 18:25:05 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
CC = clang
|
||||
|
||||
SRCS = ft_dprintul_base.c ft_isdigit.c ft_dprintul.c ft_dprintx.c ft_dprintflag.c ft_skipflag.c ft_vdprintf.c ft_dprintl_base.c ft_dprintX.c ft_dprintptr.c ft_strlen.c ft_putstr_fd.c ft_dprintarg.c ft_printf.c ft_putchar_fd.c ft_isarg.c
|
||||
SRCS = ft_dprintarg.c ft_dprintflag.c ft_dprintl_base.c ft_dprintptr.c ft_dprintstrtab.c ft_dprintul_base.c ft_dprintul.c ft_dprintx.c ft_dprintX.c ft_isarg.c ft_isdigit.c ft_printf.c ft_putchar_fd.c ft_putstr_fd.c ft_skipflag.c ft_strlen.c ft_vdprintf.c
|
||||
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
|
||||
NAME = ft_printf.a
|
||||
|
||||
CFLAG = -Wall -Werror -Wextra
|
||||
CFLAG = -Wall -Werror -Wextra -g
|
||||
|
||||
%.o: %.c
|
||||
${CC} ${CFLAGS} -c -o $@ $<
|
||||
${CC} ${CFLAG} -c -o $@ $<
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
|
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/23 18:08:31 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/23 18:54:41 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/05 17:37:12 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -24,6 +24,8 @@ int ft_dprintarg(int fd, int arg, va_list args)
|
||||
return (ft_dprintul(fd, va_arg(args, unsigned int)));
|
||||
if (arg == 'c')
|
||||
return (ft_putchar_fd(fd, va_arg(args, int)));
|
||||
if (arg == 'S')
|
||||
return (ft_dprintstrtab(fd, va_arg(args, char **)));
|
||||
if (arg == 's')
|
||||
return (ft_putstr_fd(fd, va_arg(args, char *)));
|
||||
if (arg == '%')
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
29
libftx/printf/ft_dprintstrtab.c
Normal file
29
libftx/printf/ft_dprintstrtab.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_dprintstrtab.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/05 17:26:55 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/05 18:52:56 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
int ft_dprintstrtab(int fd, char **tab)
|
||||
{
|
||||
size_t index;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
index = 0;
|
||||
while (tab[index] != NULL)
|
||||
{
|
||||
i += ft_putstr_fd(fd, tab[index]) + 1;
|
||||
ft_putchar_fd(fd, '\n');
|
||||
index++;
|
||||
}
|
||||
return (i);
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/11 22:37:41 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/12 16:09:22 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/05 18:26:24 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,7 +18,7 @@ int ft_isarg(int c)
|
||||
|
||||
if (c == '\0')
|
||||
return (1);
|
||||
flags = "cspdiuxX%";
|
||||
flags = "cspdiuxX%S";
|
||||
while (*flags)
|
||||
{
|
||||
if (*flags == c)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/11/07 19:41:50 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/01/05 17:36:39 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -29,6 +29,7 @@ int ft_dprintx(int fd, unsigned int n);
|
||||
int ft_dprint_upperx(int fd, unsigned int n);
|
||||
int ft_dprintflag(int fd, const char *flag, va_list va);
|
||||
int ft_dprintarg(int fd, int c, va_list va);
|
||||
int ft_dprintstrtab(int fd, char **tab);
|
||||
|
||||
int ft_printf(const char *format, ...);
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user