Add flags to makefile and fix some compile error

This commit is contained in:
2026-01-08 16:09:37 +00:00
parent 38eae5ab16
commit 9a20072f36
8 changed files with 37 additions and 26 deletions

View File

@@ -28,7 +28,7 @@ SRC = main.c test_one.c ft_putnbr.c secure_write.c
INSERTION = insertion.c
FLAGS_FILES = algorithms_sort.c flag.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
@@ -46,7 +46,8 @@ ALGO_UTILS = check_order.c compare.c iterate.c pre_sort.c
ALL_FILES = $(SRC) $(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)
$(INSERT_DIR)/$(INSERTION) $(ALGO_DIR)/$(COMPLEX_DIR)/$(COMPLEX_ALGO) \
$(FLAGS_DIR)/$(FLAGS_FILES)
OBJ_DIR = obj
@@ -69,9 +70,6 @@ $(NAME): $(OBJ)
@echo "======= PUSH SWAP COMPILED ========="
@echo "===================================="
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(OBJ_DIR)/%.o: $(PARS_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
@@ -93,6 +91,12 @@ $(OBJ_DIR)/%.o: $(ALGO_DIR)/$(COMPLEX_DIR)/%.c | $(OBJ_DIR)
$(OBJ_DIR)/%.o: $(ALGO_UTILS_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(OBJ_DIR)/%.o: $(FLAGS_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(OBJ_DIR):
@mkdir -p $(OBJ_DIR)

View File

@@ -6,12 +6,12 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/07 12:15:02 by mteriier #+# #+# */
/* Updated: 2026/01/07 12:15:05 by mteriier ### ########lyon.fr */
/* Updated: 2026/01/08 16:07:00 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include "medium_algo.h"
#include "medium_headers.h"
void simple(t_stacks *piles)
{
@@ -33,10 +33,13 @@ void medium(t_stacks *piles)
void complex(t_stacks *piles)
{
(void)piles;
return ;
}
void adaptive(t_stacks *piles)
{
(void)piles;
return ;
}

View File

@@ -6,11 +6,12 @@
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/08 13:59:52 by dgaillet #+# #+# */
/* Updated: 2026/01/08 15:26:30 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/08 16:09:11 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swaps.h"
#include "push_swap.h"
#include "parsing.h"
#include <unistd.h>
#include <stdlib.h>
@@ -34,10 +35,10 @@ static void print_disorder(t_stacks *stacks)
free(str);
}
static void print_strategy(t_stacks *stacks)
static void print_algo(t_stacks *stacks)
{
secure_write(2, "[bench] strategy: ", 18);
if (stacks->strategy == 0)
secure_write(2, "[bench] algo: ", 18);
if (stacks->algo == 0)
{
secure_write(2, "Adaptative", 10);
if (stacks->disorder < 0.2)
@@ -47,11 +48,11 @@ static void print_strategy(t_stacks *stacks)
else
secure_write(2, " / O(nlogn)\n", 12);
}
else if (stacks->strategy == 1)
else if (stacks->algo == 1)
secure_write(2, "Simple / O(n2n)\n", 16);
else if (stacks->strategy == 2)
else if (stacks->algo == 2)
secure_write(2, "Medium / O(nlogn)\n", 18);
else if (stacks->strategy == 3)
else if (stacks->algo == 3)
secure_write(2, "Complex / O(n√n)\n", 17);
}
@@ -73,7 +74,7 @@ static void print_total_ops(t_stacks *stacks)
total_ops += stacks->rrr;
secure_write(2, "[bench] total_ops: ", 18);
ft_putnbr_fd((int) total_ops, 2);
secure_write(2, "\n");
secure_write(2, "\n", 1);
}
static void print_ops(t_stacks *stacks)
@@ -104,11 +105,10 @@ static void print_ops(t_stacks *stacks)
secure_write(2, "\n", 1);
}
void bench(t_stacks *stacks)
void print_bench(t_stacks *stacks)
{
print_disorder(stacks)
print_strategy(stacks);
print_disorder(stacks);
print_algo(stacks);
print_total_ops(stacks);
print_ops(stacks);
}

View File

@@ -6,12 +6,13 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/07 12:39:29 by mteriier #+# #+# */
/* Updated: 2026/01/07 12:39:31 by mteriier ### ########lyon.fr */
/* Updated: 2026/01/08 16:07:29 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include "parsing.h"
#include "flags.h"
void flags(int pos, char **argv, t_stacks *piles)
{

View File

@@ -6,7 +6,7 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/07 13:05:52 by mteriier #+# #+# */
/* Updated: 2026/01/07 13:05:53 by mteriier ### ########lyon.fr */
/* Updated: 2026/01/08 15:32:54 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
@@ -19,4 +19,6 @@ void complex(t_stacks *piles);
void adaptive(t_stacks *piles);
void flags(int pos, char **argv, t_stacks *piles);
void print_bench(t_stacks *stacks);
#endif

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 14:18:06 by dgaillet #+# #+# */
/* Updated: 2026/01/08 15:20:03 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/08 15:32:04 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */

3
main.c
View File

@@ -6,7 +6,7 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 18:32:35 by mteriier #+# #+# */
/* Updated: 2026/01/08 12:57:04 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/08 15:34:59 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
@@ -21,7 +21,6 @@ int main(int argc, char **argv)
write(2, "Error !\n", 8);
return (1);
}
if (argc > 1)
test1(argc, argv);
return (0);

View File

@@ -6,11 +6,12 @@
/* By: mteriier <mteriier@student.lyon42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/22 12:33:58 by mteriier #+# #+# */
/* Updated: 2026/01/08 12:57:57 by dgaillet ### ########lyon.fr */
/* Updated: 2026/01/08 15:35:43 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include "flags.h"
#include "parsing.h"
#include "medium_headers.h"
#include <stdio.h>
@@ -25,6 +26,7 @@ int test1(int argc, char **argv)
if (argc > 1)
{
piles = init_piles(argc, argv, 0);
print_bench(piles);
preset = get_tabs(piles->a, range_bucket(piles->a));
bucket_algo(piles, preset, range_bucket(piles->a));
}