mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8b2a90dc1 | ||
|
|
68dbe33733 | ||
|
|
fe69eeb821 | ||
| 929d7d4da5 | |||
| 319ed2521e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -59,6 +59,7 @@ dkms.conf
|
|||||||
|
|
||||||
# Executable
|
# Executable
|
||||||
push_swap
|
push_swap
|
||||||
|
checker
|
||||||
|
|
||||||
# File obj
|
# File obj
|
||||||
obj/
|
obj/
|
||||||
|
|||||||
50
Makefile
50
Makefile
@@ -18,7 +18,7 @@ COMPLEX_DIR = radix
|
|||||||
|
|
||||||
FLAGS_DIR = flags
|
FLAGS_DIR = flags
|
||||||
|
|
||||||
CHECKER_DIR = checker
|
CHECKER_DIR = check_error
|
||||||
|
|
||||||
INCLUDES = includes
|
INCLUDES = includes
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ INSERTION = insertion.c
|
|||||||
|
|
||||||
FLAGS_FILES = algorithms_sort.c flag.c bench.c
|
FLAGS_FILES = algorithms_sort.c flag.c bench.c
|
||||||
|
|
||||||
PARSING = ft_atoi.c parsing.c ft_strncmp.c ft_split.c ft_strlen.c ft_substr.c checker.c ft_itoa.c ft_isdigit.c \
|
PARSING = ft_atoi.c parsing.c ft_strncmp.c ft_split.c ft_strlen.c ft_substr.c ft_itoa.c ft_isdigit.c \
|
||||||
ft_strjoin.c ft_strlcat.c ft_strlcpy.c parsing_2.c disorder.c
|
ft_strjoin.c ft_strlcat.c ft_strlcpy.c parsing_2.c disorder.c
|
||||||
|
|
||||||
CHECKER_FILES = check_error.c verif_flag.c verif_is_digit.c verif_overflow.c verif_double.c
|
CHECKER_FILES = check_error.c verif_flag.c verif_is_digit.c verif_overflow.c verif_double.c
|
||||||
@@ -65,7 +65,33 @@ NAME = push_swap
|
|||||||
OBJ = $(addprefix $(OBJ_DIR)/, $(notdir $(ALL_FILES:.c=.o)))
|
OBJ = $(addprefix $(OBJ_DIR)/, $(notdir $(ALL_FILES:.c=.o)))
|
||||||
DEP = $(OBJ:.o=.d)
|
DEP = $(OBJ:.o=.d)
|
||||||
|
|
||||||
.PHONY: all clean fclean re
|
#============================
|
||||||
|
# BONUS CONFIG
|
||||||
|
#============================
|
||||||
|
|
||||||
|
BONUS_DIR = bonus
|
||||||
|
|
||||||
|
GNL_D = GNL
|
||||||
|
|
||||||
|
GNL_DIR = bonus/GNL
|
||||||
|
|
||||||
|
BONUS_FILES = checker_bonus.c
|
||||||
|
|
||||||
|
GNL_FILES = get_next_line.c get_next_line_utils.c
|
||||||
|
|
||||||
|
SRC_FOR_BONUS = ft_putnbr.c secure_write.c
|
||||||
|
|
||||||
|
ALL_BONUS_FILES = $(SRC_FOR_BONUS) $(BONUS_DIR)/$(BONUS_FILES) $(BONUS_DIR)/$(GNL_D)/$(GNL_FILES) \
|
||||||
|
$(STACK_UTILS_DIR)/$(STACK_UTILS) $(PARS_DIR)/$(PARSING) \
|
||||||
|
$(ALGO_DIR)/$(MEDIUM_DIR)/$(MEDIUM_ALGO) $(ALGO_UTILS_DIR)/$(ALGO_UTILS) \
|
||||||
|
$(INSERT_DIR)/$(INSERTION) $(ALGO_DIR)/$(COMPLEX_DIR)/$(COMPLEX_ALGO) \
|
||||||
|
$(FLAGS_DIR)/$(FLAGS_FILES) $(CHECKER_DIR)/$(CHECKER_FILES)
|
||||||
|
|
||||||
|
BONUS_OBJ = $(addprefix $(OBJ_DIR)/, $(notdir $(ALL_BONUS_FILES:.c=.o)))
|
||||||
|
|
||||||
|
NAME_BONUS = checker
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re bonus
|
||||||
|
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
@@ -75,6 +101,12 @@ $(NAME): $(OBJ)
|
|||||||
@echo "======= PUSH SWAP COMPILED ========="
|
@echo "======= PUSH SWAP COMPILED ========="
|
||||||
@echo "===================================="
|
@echo "===================================="
|
||||||
|
|
||||||
|
$(NAME_BONUS): $(BONUS_OBJ)
|
||||||
|
@$(CC) $(CFLAGS) $(BONUS_OBJ) -o $(NAME_BONUS)
|
||||||
|
@echo "===================================="
|
||||||
|
@echo "======= PUSH SWAP COMPILED ========="
|
||||||
|
@echo "===================================="
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: $(PARS_DIR)/%.c | $(OBJ_DIR)
|
$(OBJ_DIR)/%.o: $(PARS_DIR)/%.c | $(OBJ_DIR)
|
||||||
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
@@ -102,9 +134,18 @@ $(OBJ_DIR)/%.o: $(FLAGS_DIR)/%.c | $(OBJ_DIR)
|
|||||||
$(OBJ_DIR)/%.o: $(CHECKER_DIR)/%.c | $(OBJ_DIR)
|
$(OBJ_DIR)/%.o: $(CHECKER_DIR)/%.c | $(OBJ_DIR)
|
||||||
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(BONUS_DIR)/%.c | $(OBJ_DIR)
|
||||||
|
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(BONUS_DIR)/$(GNL_D)/%.c | $(OBJ_DIR)
|
||||||
|
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR)
|
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR)
|
||||||
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR_BONUS)/%.o: %.c | $(OBJ_DIR_BONUS)
|
||||||
|
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
$(OBJ_DIR):
|
$(OBJ_DIR):
|
||||||
@mkdir -p $(OBJ_DIR)
|
@mkdir -p $(OBJ_DIR)
|
||||||
|
|
||||||
@@ -116,9 +157,12 @@ clean:
|
|||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
@rm -f $(NAME)
|
@rm -f $(NAME)
|
||||||
|
@rm -f $(NAME_BONUS)
|
||||||
@echo "========== EXEC DELETED ============"
|
@echo "========== EXEC DELETED ============"
|
||||||
@echo "===================================="
|
@echo "===================================="
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
|
bonus: $(NAME_BONUS)
|
||||||
|
|
||||||
-include $(DEP)
|
-include $(DEP)
|
||||||
|
|||||||
112
bonus/GNL/get_next_line.c
Normal file
112
bonus/GNL/get_next_line.c
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* get_next_line.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/11/21 17:20:41 by dgaillet #+# #+# */
|
||||||
|
/* Updated: 2025/11/28 13:47:15 by dgaillet ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "get_next_line.h"
|
||||||
|
#include "parsing.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static int del_before_nl(char buf[BUFFER_SIZE])
|
||||||
|
{
|
||||||
|
int nl_i;
|
||||||
|
int i;
|
||||||
|
char *temp;
|
||||||
|
|
||||||
|
nl_i = index_of_nl(buf, BUFFER_SIZE);
|
||||||
|
if (nl_i >= 0)
|
||||||
|
{
|
||||||
|
temp = ft_substr_gnl(buf, nl_i + 1, BUFFER_SIZE - nl_i);
|
||||||
|
if (!temp)
|
||||||
|
return (-1);
|
||||||
|
ft_bzero(buf, BUFFER_SIZE);
|
||||||
|
i = 0;
|
||||||
|
while (temp[i])
|
||||||
|
{
|
||||||
|
buf[i] = temp[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *ft_read_one(char buf[BUFFER_SIZE], int fd, char *str)
|
||||||
|
{
|
||||||
|
int temp;
|
||||||
|
|
||||||
|
str = ft_strjoin_new(str, buf, BUFFER_SIZE);
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
ft_bzero(buf, BUFFER_SIZE);
|
||||||
|
temp = read(fd, buf, BUFFER_SIZE);
|
||||||
|
if (temp < 0)
|
||||||
|
{
|
||||||
|
free(str);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if ((!str || ft_strlen_1(str) == 0) && temp == 0)
|
||||||
|
{
|
||||||
|
free(str);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (temp == 0)
|
||||||
|
return (str);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *extract_all_nl(char buf[BUFFER_SIZE], int fd, char *str, int nl_i)
|
||||||
|
{
|
||||||
|
int temp;
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
while (nl_i < 0)
|
||||||
|
{
|
||||||
|
str = ft_read_one(buf, fd, str);
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
nl_i = index_of_nl(buf, BUFFER_SIZE);
|
||||||
|
if (nl_i < 0 && !ft_strlen_1(buf))
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
str = ft_strjoin_new(str, buf, nl_i);
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
temp = del_before_nl(buf);
|
||||||
|
if (temp < 0)
|
||||||
|
{
|
||||||
|
free(str);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_next_line(int fd)
|
||||||
|
{
|
||||||
|
static char buf[BUFFER_SIZE + 1];
|
||||||
|
int nl_i;
|
||||||
|
int temp;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (fd < 0 || BUFFER_SIZE <= 0)
|
||||||
|
return (NULL);
|
||||||
|
nl_i = index_of_nl(buf, BUFFER_SIZE);
|
||||||
|
if (nl_i >= 0)
|
||||||
|
{
|
||||||
|
str = ft_substr_gnl(buf, 0, nl_i + 1);
|
||||||
|
temp = del_before_nl(buf);
|
||||||
|
if (temp < 0)
|
||||||
|
return (free(str), NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
str = extract_all_nl(buf, fd, ft_substr_gnl("", 0, 1), nl_i);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
102
bonus/GNL/get_next_line_utils.c
Normal file
102
bonus/GNL/get_next_line_utils.c
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* get_next_line_utils.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/11/21 17:21:38 by dgaillet #+# #+# */
|
||||||
|
/* Updated: 2025/11/27 18:06:51 by dgaillet ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "get_next_line.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
int index_of_nl(char *str, int limit)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return (-1);
|
||||||
|
i = 0;
|
||||||
|
while (i < limit && str[i])
|
||||||
|
{
|
||||||
|
if (str[i] == '\n')
|
||||||
|
return (i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ft_strlen_1(const char *s)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_strjoin_new(char const *s1, char const *s2, size_t limit)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
|
||||||
|
str = malloc(sizeof(char) * (ft_strlen_1(s1) + ft_strlen_1(s2) + 1));
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
while (s1[i])
|
||||||
|
{
|
||||||
|
str[i] = s1[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (j <= limit && s2[j])
|
||||||
|
{
|
||||||
|
str[i + j] = s2[j];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
str[i + j] = '\0';
|
||||||
|
free((void *) s1);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_substr_gnl(char const *s, unsigned int start, size_t len)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
char *sub_str;
|
||||||
|
size_t s_len;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return (NULL);
|
||||||
|
s_len = ft_strlen_1(s);
|
||||||
|
if (start > s_len)
|
||||||
|
len = 0;
|
||||||
|
else if (s_len < (start + len))
|
||||||
|
len = s_len - start;
|
||||||
|
sub_str = malloc(sizeof(char) * (len + 1));
|
||||||
|
if (!sub_str)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
while (i < len)
|
||||||
|
{
|
||||||
|
sub_str[i] = s[start + i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
sub_str[i] = '\0';
|
||||||
|
return (sub_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_bzero(void *s, size_t n)
|
||||||
|
{
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
*((unsigned char *) s) = '\0';
|
||||||
|
s++;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
}
|
||||||
104
bonus/checker_bonus.c
Normal file
104
bonus/checker_bonus.c
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* checker_bonus.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/01/09 11:46:36 by dgaillet #+# #+# */
|
||||||
|
/* Updated: 2026/01/09 14:51:32 by dgaillet ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
#include "parsing.h"
|
||||||
|
#include "get_next_line.h"
|
||||||
|
#include "check_error.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static int apply_operation(t_stacks *stacks, char buf[1024])
|
||||||
|
{
|
||||||
|
if (!ft_strncmp("sa", buf, ft_strlen(buf)))
|
||||||
|
return (sa(stacks), 1);
|
||||||
|
if (!ft_strncmp("sb", buf, ft_strlen(buf)))
|
||||||
|
return (sb(stacks), 1);
|
||||||
|
if (!ft_strncmp("ss", buf, ft_strlen(buf)))
|
||||||
|
return (ss(stacks), 1);
|
||||||
|
if (!ft_strncmp("pa", buf, ft_strlen(buf)))
|
||||||
|
return (pa(stacks), 1);
|
||||||
|
if (!ft_strncmp("pb", buf, ft_strlen(buf)))
|
||||||
|
return (pb(stacks), 1);
|
||||||
|
if (!ft_strncmp("ra", buf, ft_strlen(buf)))
|
||||||
|
return (ra(stacks), 1);
|
||||||
|
if (!ft_strncmp("rb", buf, ft_strlen(buf)))
|
||||||
|
return (rb(stacks), 1);
|
||||||
|
if (!ft_strncmp("rr", buf, ft_strlen(buf)))
|
||||||
|
return (rr(stacks), 1);
|
||||||
|
if (!ft_strncmp("rra", buf, ft_strlen(buf)))
|
||||||
|
return (rra(stacks), 1);
|
||||||
|
if (!ft_strncmp("rrb", buf, ft_strlen(buf)))
|
||||||
|
return (rrb(stacks), 1);
|
||||||
|
if (!ft_strncmp("rrr", buf, ft_strlen(buf)))
|
||||||
|
return (rrr(stacks), 1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_stacks_b_empty(t_stacks *stacks)
|
||||||
|
{
|
||||||
|
if (stacks->b != NULL)
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tester(t_stacks *stacks)
|
||||||
|
{
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
buf = get_next_line(0);
|
||||||
|
while (buf)
|
||||||
|
{
|
||||||
|
if (!apply_operation(stacks, buf))
|
||||||
|
break ;
|
||||||
|
free(buf);
|
||||||
|
buf = get_next_line(0);
|
||||||
|
}
|
||||||
|
if (!is_stacks_b_empty(stacks))
|
||||||
|
return (write(1, "KO\n", 3));
|
||||||
|
if (!check_order(stacks->a))
|
||||||
|
return (write(1, "KO\n", 3));
|
||||||
|
write(1, "OK\n", 3);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bonus(char **tab)
|
||||||
|
{
|
||||||
|
t_stacks *stacks;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
stacks = NULL;
|
||||||
|
len = len_split(tab);
|
||||||
|
stacks = init_stacks(len, tab, 0);
|
||||||
|
stacks->print = 0;
|
||||||
|
if (!stacks)
|
||||||
|
return (0);
|
||||||
|
tester(stacks);
|
||||||
|
free_all(stacks);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char **tab;
|
||||||
|
|
||||||
|
if (argc < 2)
|
||||||
|
return (write(2, "Error\n", 7));
|
||||||
|
tab = split_all(join_all(argc, argv));
|
||||||
|
if (!tab)
|
||||||
|
return (0);
|
||||||
|
if (!check_error_bonus(tab))
|
||||||
|
write(2, "Error\n", 7);
|
||||||
|
else
|
||||||
|
bonus(tab);
|
||||||
|
free_tab(tab);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -23,6 +23,17 @@ int verif_is_number(char **tab)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int check_error_bonus(char **tab)
|
||||||
|
{
|
||||||
|
if (!verif_is_digit(tab, 0))
|
||||||
|
return (0);
|
||||||
|
if (!verif_overflow(tab, 0))
|
||||||
|
return (0);
|
||||||
|
if (!verif_double(tab, 0))
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
int check_error(char **tab, int mod)
|
int check_error(char **tab, int mod)
|
||||||
{
|
{
|
||||||
if (!verif_flag(tab, mod))
|
if (!verif_flag(tab, mod))
|
||||||
@@ -19,5 +19,6 @@ int verif_is_digit(char **tab, int mod);
|
|||||||
int verif_overflow(char **tab, int mod);
|
int verif_overflow(char **tab, int mod);
|
||||||
int verif_double(char **tab, int mod);
|
int verif_double(char **tab, int mod);
|
||||||
int scan_str_is_digit(char *tab);
|
int scan_str_is_digit(char *tab);
|
||||||
|
int check_error_bonus(char **tab);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
30
includes/get_next_line.h
Normal file
30
includes/get_next_line.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* get_next_line.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/11/21 17:22:03 by dgaillet #+# #+# */
|
||||||
|
/* Updated: 2025/11/27 18:05:13 by dgaillet ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef GET_NEXT_LINE_H
|
||||||
|
# define GET_NEXT_LINE_H
|
||||||
|
|
||||||
|
# ifndef BUFFER_SIZE
|
||||||
|
# define BUFFER_SIZE 42
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
char *get_next_line(int fd);
|
||||||
|
|
||||||
|
size_t ft_strlen_1(const char *s);
|
||||||
|
char *ft_strjoin_new(char const *s1, char const *s2, size_t limit);
|
||||||
|
void ft_bzero(void *s, size_t n);
|
||||||
|
int index_of_nl(char *str, int limit);
|
||||||
|
char *ft_substr_gnl(char const *s, unsigned int start, size_t len);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -26,6 +26,7 @@ typedef struct s_stacks
|
|||||||
t_stack *b;
|
t_stack *b;
|
||||||
int algo;
|
int algo;
|
||||||
int bench;
|
int bench;
|
||||||
|
int print;
|
||||||
float disorder;
|
float disorder;
|
||||||
unsigned int ra;
|
unsigned int ra;
|
||||||
unsigned int rb;
|
unsigned int rb;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ static void set_t_stacks(t_stacks *stacks)
|
|||||||
stacks->algo = 0;
|
stacks->algo = 0;
|
||||||
stacks->bench = 0;
|
stacks->bench = 0;
|
||||||
stacks->disorder = 0;
|
stacks->disorder = 0;
|
||||||
|
stacks->print = 1;
|
||||||
stacks->sa = 0;
|
stacks->sa = 0;
|
||||||
stacks->sb = 0;
|
stacks->sb = 0;
|
||||||
stacks->ss = 0;
|
stacks->ss = 0;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ void pa(t_stacks *stacks)
|
|||||||
}
|
}
|
||||||
stack_add_front(&(stacks->a), b_push);
|
stack_add_front(&(stacks->a), b_push);
|
||||||
stacks->pa++;
|
stacks->pa++;
|
||||||
|
if (stacks->print)
|
||||||
write(1, "pa\n", 3);
|
write(1, "pa\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,5 +52,6 @@ void pb(t_stacks *stacks)
|
|||||||
}
|
}
|
||||||
stack_add_front(&(stacks->b), a_push);
|
stack_add_front(&(stacks->b), a_push);
|
||||||
stacks->pb++;
|
stacks->pb++;
|
||||||
|
if (stacks->print)
|
||||||
write(1, "pb\n", 3);
|
write(1, "pb\n", 3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ void rrb(t_stacks *stacks)
|
|||||||
if (stacks && stacks->b && stacks->b->previous)
|
if (stacks && stacks->b && stacks->b->previous)
|
||||||
stacks->b = stacks->b->previous;
|
stacks->b = stacks->b->previous;
|
||||||
stacks->rrb++;
|
stacks->rrb++;
|
||||||
|
if (stacks->print)
|
||||||
write(1, "rrb\n", 4);
|
write(1, "rrb\n", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,5 +37,6 @@ void rrr(t_stacks *stacks)
|
|||||||
if (stacks && stacks->a && stacks->a->previous)
|
if (stacks && stacks->a && stacks->a->previous)
|
||||||
stacks->a = stacks->a->previous;
|
stacks->a = stacks->a->previous;
|
||||||
stacks->rrr++;
|
stacks->rrr++;
|
||||||
|
if (stacks->print)
|
||||||
write(1, "rrr\n", 4);
|
write(1, "rrr\n", 4);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ void ra(t_stacks *stacks)
|
|||||||
if (stacks && stacks->a && stacks->a->next)
|
if (stacks && stacks->a && stacks->a->next)
|
||||||
stacks->a = stacks->a->next;
|
stacks->a = stacks->a->next;
|
||||||
stacks->ra++;
|
stacks->ra++;
|
||||||
|
if (stacks->print)
|
||||||
write(1, "ra\n", 3);
|
write(1, "ra\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ void rb(t_stacks *stacks)
|
|||||||
if (stacks && stacks->b && stacks->b->next)
|
if (stacks && stacks->b && stacks->b->next)
|
||||||
stacks->b = stacks->b->next;
|
stacks->b = stacks->b->next;
|
||||||
stacks->rb++;
|
stacks->rb++;
|
||||||
|
if (stacks->print)
|
||||||
write(1, "rb\n", 3);
|
write(1, "rb\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,5 +38,6 @@ void rr(t_stacks *stacks)
|
|||||||
if (stacks && stacks->b && stacks->b->next)
|
if (stacks && stacks->b && stacks->b->next)
|
||||||
stacks->b = stacks->b->next;
|
stacks->b = stacks->b->next;
|
||||||
stacks->rr++;
|
stacks->rr++;
|
||||||
|
if (stacks->print)
|
||||||
write(1, "rr\n", 3);
|
write(1, "rr\n", 3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ void sa(t_stacks *stacks)
|
|||||||
a->value = a->next->value;
|
a->value = a->next->value;
|
||||||
a->next->value = stock;
|
a->next->value = stock;
|
||||||
stacks->sa++;
|
stacks->sa++;
|
||||||
|
if (stacks->print)
|
||||||
write(1, "sa\n", 3);
|
write(1, "sa\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +41,7 @@ void sb(t_stacks *stacks)
|
|||||||
b->value = b->next->value;
|
b->value = b->next->value;
|
||||||
b->next->value = stock;
|
b->next->value = stock;
|
||||||
stacks->sb++;
|
stacks->sb++;
|
||||||
|
if (stacks->print)
|
||||||
write(1, "sb\n", 3);
|
write(1, "sb\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,5 +68,6 @@ void ss(t_stacks *stacks)
|
|||||||
a->next->value = stock;
|
a->next->value = stock;
|
||||||
}
|
}
|
||||||
stacks->ss++;
|
stacks->ss++;
|
||||||
|
if (stacks->print)
|
||||||
write(1, "ss\n", 3);
|
write(1, "ss\n", 3);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user