From: Lukas Jiriste Date: Tue, 6 Feb 2024 13:55:32 +0000 (+0100) Subject: Refactor stack functions from checker.c X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=0cbe1548febd07244497e72990d62e873fc29aa9;p=42%2Fpush_swap.git Refactor stack functions from checker.c --- diff --git a/Makefile b/Makefile index d39cbd0..80d1055 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ CHECKSOURCES := checker.c \ actions.c \ stack_manipulation.c \ arg_parsing.c \ + stacks_mem.c \ CHECKSOURCES := $(addprefix $(CHECKSRCDIR)/, $(CHECKSOURCES)) diff --git a/src/checker.c b/src/checker.c index f54db04..77b6152 100644 --- a/src/checker.c +++ b/src/checker.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/24 10:31:06 by ljiriste #+# #+# */ -/* Updated: 2024/02/06 13:19:15 by ljiriste ### ########.fr */ +/* Updated: 2024/02/06 14:21:13 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,20 +83,6 @@ static int interpret(t_stacks *s) return (0); } -void init_stack(t_stack *s) -{ - ft_vec_init(&s->stack, sizeof(int)); - s->ind = 0; - return ; -} - -void free_stack(t_stack *s) -{ - ft_vec_free(&s->stack, NULL); - s->ind = 0; - return ; -} - int is_sorted(t_stack *s) { const size_t start_ind = s->ind; @@ -116,13 +102,6 @@ int is_sorted(t_stack *s) return (1); } -void clean_up(t_stacks *s) -{ - free_stack(&s->a); - free_stack(&s->b); - return ; -} - int main(int argc, char **argv) { t_stacks s; diff --git a/src/checker.h b/src/checker.h index 5776dae..e03b18f 100644 --- a/src/checker.h +++ b/src/checker.h @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/24 12:13:51 by ljiriste #+# #+# */ -/* Updated: 2024/01/31 09:59:33 by ljiriste ### ########.fr */ +/* Updated: 2024/02/06 14:22:08 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,6 +42,8 @@ typedef struct s_command t_target target; } t_command; +void init_stack(t_stack *s); +void clean_up(t_stacks *s); /* t_action action_push; t_action action_swap; diff --git a/src/stacks_mem.c b/src/stacks_mem.c new file mode 100644 index 0000000..dac4dc1 --- /dev/null +++ b/src/stacks_mem.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stacks_mem.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/06 14:20:04 by ljiriste #+# #+# */ +/* Updated: 2024/02/06 14:22:06 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "checker.h" +#include "libft.h" + +void init_stack(t_stack *s) +{ + ft_vec_init(&s->stack, sizeof(int)); + s->ind = 0; + return ; +} + +static void free_stack(t_stack *s) +{ + ft_vec_free(&s->stack, NULL); + s->ind = 0; + return ; +} + +void clean_up(t_stacks *s) +{ + free_stack(&s->a); + free_stack(&s->b); + return ; +}