diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-09-10 10:54:12 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-09-10 10:54:12 +0200 |
| commit | 7a6533373ab9b0dd075f995c98dcf332a7876fac (patch) | |
| tree | a9fc5df9ab01c11a24e780dab47039504f122ef3 /src/common | |
| parent | c0124777afcbbb0d5ca7d841360434f25235fb0f (diff) | |
| download | push_swap-7a6533373ab9b0dd075f995c98dcf332a7876fac.tar.gz push_swap-7a6533373ab9b0dd075f995c98dcf332a7876fac.tar.bz2 push_swap-7a6533373ab9b0dd075f995c98dcf332a7876fac.zip | |
Updated to norm v3
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/common.h | 15 | ||||
| -rw-r--r-- | src/common/parse.c | 19 | ||||
| -rw-r--r-- | src/common/stack_core.c | 17 | ||||
| -rw-r--r-- | src/common/stack_helper.c | 10 | ||||
| -rw-r--r-- | src/common/stack_op.c | 8 |
5 files changed, 38 insertions, 31 deletions
diff --git a/src/common/common.h b/src/common/common.h index 87c4655..c4efad8 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/18 11:20:54 by cacharle #+# #+# */ -/* Updated: 2020/01/22 10:25:47 by cacharle ### ########.fr */ +/* Updated: 2021/09/10 10:33:19 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,24 +14,25 @@ # define COMMON_H # include <stdlib.h> +# include <stdbool.h> # include "libft.h" -typedef enum +typedef enum e_status { - STATUS_SUCCESS, - STATUS_FAILURE, + STATUS_FAILURE = false, + STATUS_SUCCESS = true, STATUS_ERROR, STATUS_EOF, } t_status; -typedef enum +typedef enum e_stack_tag { STACK_NO_TAG, STACK_A, STACK_B } t_stack_tag; -typedef struct s_stack +typedef struct s_stack { int *elements; t_stack_tag tag; @@ -43,7 +44,7 @@ typedef struct s_stack */ t_stack *stack_new(int size); -void stack_destroy(t_stack *stack); +int stack_destroy(t_stack *stack); void stack_push(t_stack *stack, int n); void stack_pop(t_stack *stack); int stack_peek(t_stack *stack); diff --git a/src/common/parse.c b/src/common/parse.c index b0415cd..34f0749 100644 --- a/src/common/parse.c +++ b/src/common/parse.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/19 09:03:28 by cacharle #+# #+# */ -/* Updated: 2020/01/19 13:33:17 by cacharle ### ########.fr */ +/* Updated: 2021/09/09 10:02:15 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,19 +14,22 @@ static t_status has_dup(int *xs, size_t size) { - int *tmp; - t_status ret; + int *tmp; + t_bool is_set; - if ((tmp = (int*)malloc(size * sizeof(int))) == NULL) + tmp = (int *)malloc(size * sizeof(int)); + if (tmp == NULL) return (STATUS_ERROR); ft_memcpy(tmp, xs, size * sizeof(int)); - ret = ft_is_set(tmp, size, sizeof(int), &ft_compar_int) ? - STATUS_SUCCESS : STATUS_FAILURE; + is_set = ft_is_set(tmp, size, sizeof(int), &ft_compar_int); free(tmp); - return (ret); + if (is_set) + return (STATUS_SUCCESS); + else + return (STATUS_FAILURE); } -t_status parse(int argc, char **argv, t_stack *a) +t_status parse(int argc, char **argv, t_stack *a) { while (--argc >= 1) { diff --git a/src/common/stack_core.c b/src/common/stack_core.c index adab5b1..68f74ca 100644 --- a/src/common/stack_core.c +++ b/src/common/stack_core.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/19 06:37:45 by cacharle #+# #+# */ -/* Updated: 2020/01/22 10:23:18 by cacharle ### ########.fr */ +/* Updated: 2021/09/10 10:32:43 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,11 +14,13 @@ t_stack *stack_new(int size) { - t_stack *stack; + t_stack *stack; - if ((stack = (t_stack*)malloc(sizeof(t_stack))) == NULL) + stack = (t_stack *)malloc(sizeof(t_stack)); + if (stack == NULL) return (NULL); - if ((stack->elements = (int*)malloc(sizeof(int) * size)) == NULL) + stack->elements = (int *)malloc(sizeof(int) * size); + if (stack->elements == NULL) { free(stack); return (NULL); @@ -28,12 +30,13 @@ t_stack *stack_new(int size) return (stack); } -void stack_destroy(t_stack *stack) +int stack_destroy(t_stack *stack) { if (stack == NULL) - return ; + return (1); free(stack->elements); free(stack); + return (1); } void stack_push(t_stack *stack, int n) @@ -49,7 +52,7 @@ void stack_pop(t_stack *stack) stack->top--; } -int stack_peek(t_stack *stack) +int stack_peek(t_stack *stack) { if (stack_empty(stack)) return (0); diff --git a/src/common/stack_helper.c b/src/common/stack_helper.c index 968060f..fd6f0c5 100644 --- a/src/common/stack_helper.c +++ b/src/common/stack_helper.c @@ -6,25 +6,25 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/19 06:40:18 by cacharle #+# #+# */ -/* Updated: 2020/01/22 10:22:54 by cacharle ### ########.fr */ +/* Updated: 2021/09/09 09:53:59 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "common.h" -inline void stack_swap_2(t_stack *stack_a, t_stack *stack_b) +inline void stack_swap_2(t_stack *stack_a, t_stack *stack_b) { stack_swap(stack_a); stack_swap(stack_b); } -inline void stack_rotate_2(t_stack *stack_a, t_stack *stack_b) +inline void stack_rotate_2(t_stack *stack_a, t_stack *stack_b) { stack_rotate(stack_a); stack_rotate(stack_b); } -inline void stack_reverse_rotate_2(t_stack *stack_a, t_stack *stack_b) +inline void stack_reverse_rotate_2(t_stack *stack_a, t_stack *stack_b) { stack_reverse_rotate(stack_a); stack_reverse_rotate(stack_b); @@ -35,7 +35,7 @@ inline t_bool stack_empty(t_stack *stack) return (stack->top == -1); } -inline int stack_length(t_stack *stack) +inline int stack_length(t_stack *stack) { return (stack->top + 1); } diff --git a/src/common/stack_op.c b/src/common/stack_op.c index e1c095b..bb5a854 100644 --- a/src/common/stack_op.c +++ b/src/common/stack_op.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* stack.c :+: :+: :+: */ +/* stack_op.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/19 06:37:44 by cacharle #+# #+# */ -/* Updated: 2020/01/19 07:06:58 by cacharle ### ########.fr */ +/* Updated: 2021/09/09 09:53:03 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,7 +46,7 @@ void stack_rotate(t_stack *stack) return ; tmp = stack_peek(stack); ft_memmove(stack->elements + 1, stack->elements, - (stack_length(stack) - 1) * sizeof(int)); + (stack_length(stack) - 1) * sizeof(int)); stack->elements[0] = tmp; } @@ -58,6 +58,6 @@ void stack_reverse_rotate(t_stack *stack) return ; tmp = stack->elements[0]; ft_memmove(stack->elements, stack->elements + 1, - (stack_length(stack) - 1) * sizeof(int)); + (stack_length(stack) - 1) * sizeof(int)); stack->elements[stack->top] = tmp; } |
