Refactor stack functions from checker.c
authorLukas Jiriste <ljiriste@student.42prague.com>
Tue, 6 Feb 2024 13:55:32 +0000 (14:55 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Tue, 6 Feb 2024 13:55:32 +0000 (14:55 +0100)
Makefile
src/checker.c
src/checker.h
src/stacks_mem.c [new file with mode: 0644]

index d39cbd0ca30628bed40a5772071d43940463034a..80d1055ade43cd533f680d26f880bd1b1cfef8a2 100644 (file)
--- 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))
 
index f54db04f249e6597f68b688efb2e3bc57015ddb0..77b61526c4f07a36cc0d67717650168ab4982c4e 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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;
index 5776dae0cff5a16572e026d8d5967f5fdb4ccbfd..e03b18fcd524ddde201cfe7042f3d8e2b324df06 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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 (file)
index 0000000..dac4dc1
--- /dev/null
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   stacks_mem.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   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 ;
+}