diff --git a/include/app/state.h b/include/app/state.h index 2703d0e..2261e43 100644 --- a/include/app/state.h +++ b/include/app/state.h @@ -17,9 +17,9 @@ # include "me/vec/vec_i64.h" # include "me/vec/vec_i64_bool.h" -#ifndef BONUS -#define BONUS 0 -#endif +# ifndef BONUS +# define BONUS 0 +# endif typedef struct s_state { diff --git a/mecstd b/mecstd index caed78a..07ea967 160000 --- a/mecstd +++ b/mecstd @@ -1 +1 @@ -Subproject commit caed78a6223582e876f0fc748ca18350f572f34e +Subproject commit 07ea9679e2413366502a73ea9391d89847d6b3c2 diff --git a/src/app/actual_main.c b/src/app/actual_main.c index c0f79ce..6804f8b 100644 --- a/src/app/actual_main.c +++ b/src/app/actual_main.c @@ -15,10 +15,10 @@ #include "me/string/str_n_compare.h" #include "me/types.h" -int main_normal(t_i32 argc, t_str argv[]); -int main_checker(t_i32 argc, t_str argv[]); +int main_normal(t_i32 argc, t_str argv[]); +int main_checker(t_i32 argc, t_str argv[]); -int main(t_i32 argc, t_str argv[]) +int main(t_i32 argc, t_str argv[]) { if (BONUS) return (main_checker(argc, argv)); diff --git a/src/app/main.c b/src/app/main.c index 53d09c1..f6c0d0f 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -26,10 +26,10 @@ # define ERR_INVALID_NUM "Error\n" //:\nInvalid Number\n" # define ERR_DUPLICATE "Error\n" // :\nDuplicate Number\n" -t_usize print_error(t_const_str fmt, ...) +t_usize print_error(t_const_str fmt, ...) { - va_list args; - t_usize ret; + va_list args; + t_usize ret; va_start(args, fmt); ret = me_veprintf(fmt, &args); @@ -42,12 +42,12 @@ t_usize print_error(t_const_str fmt, ...) // # define ERR_DUPLICATE "Error:\nDuplicate Number\n" # define ERR_INVALID_NUM "Error\n" //:\nInvalid Number\n" -# define ERR_DUPLICATE "Error\n" // :\nDuplicate Number\n" +# define ERR_DUPLICATE "Error\n" // :\nDuplicate Number\n" -t_usize print_error(t_const_str fmt, ...) +t_usize print_error(t_const_str fmt, ...) { - va_list args; - t_usize ret; + va_list args; + t_usize ret; va_start(args, fmt); ret = me_veprintf(fmt, &args); @@ -57,28 +57,28 @@ t_usize print_error(t_const_str fmt, ...) #endif -void sort_3(t_state *state); -void sort_2(t_state *state); -void sort_5(t_state *state); -bool is_sorted(t_vec_i64 *v); -void run_with_items(t_state *state); +void sort_3(t_state *state); +void sort_2(t_state *state); +void sort_5(t_state *state); +bool is_sorted(t_vec_i64 *v); +void run_with_items(t_state *state); -bool sort_i64_bool(t_i64_bool *lhs, t_i64_bool *rhs) +bool sort_i64_bool(t_i64_bool *lhs, t_i64_bool *rhs) { return (lhs->value <= rhs->value); } -void free_state(t_state state) +void free_state(t_state state) { vec_i64_free(state.stack_a); vec_i64_free(state.stack_b); vec_i64_bool_free(state.sorted); } -bool duplicate_check(t_state *state) +bool duplicate_check(t_state *state) { t_i64 last; - t_usize index; + t_usize index; if (state->sorted.len == 0) return (false); @@ -93,11 +93,11 @@ bool duplicate_check(t_state *state) return (false); } -t_state parses_arguments(t_usize count, t_str nums[]) +t_state parses_arguments(t_usize count, t_str nums[]) { - t_state state; + t_state state; t_i32 atoi; - t_usize i; + t_usize i; state.stack_a = vec_i64_new(count, NULL); state.stack_b = vec_i64_new(count, NULL); @@ -108,8 +108,8 @@ t_state parses_arguments(t_usize count, t_str nums[]) if (str_to_i32(nums[i], 10, &atoi)) (free_state(state), me_eprintf(ERR_INVALID_NUM), exit(1)); vec_i64_push(&state.stack_a, atoi); - vec_i64_bool_push(&state.sorted, - (t_i64_bool){.value = atoi, .active = false}); + vec_i64_bool_push(&state.sorted, (t_i64_bool){.value = atoi, + .active = false}); i++; } vec_i64_bool_sort(&state.sorted, sort_i64_bool); @@ -118,9 +118,9 @@ t_state parses_arguments(t_usize count, t_str nums[]) return (state); } -int main_normal(t_i32 argc, t_str argv[]) +int main_normal(t_i32 argc, t_str argv[]) { - t_state state; + t_state state; (void)(argc--, argv++); state = parses_arguments(argc, argv); diff --git a/src/app/main_bonus.c b/src/app/main_bonus.c index 305ef73..3968e34 100644 --- a/src/app/main_bonus.c +++ b/src/app/main_bonus.c @@ -21,16 +21,16 @@ #define BONUS 1 #if BONUS -void push_inner(t_vec_i64 *to, t_vec_i64 *from, t_const_str tag, - t_const_str print); -void swap_inner(t_vec_i64 *vec, t_const_str tag, t_const_str print); -void rotate_inner(t_vec_i64 *vec, t_const_str tag, t_const_str print); -void rev_rotate_inner(t_vec_i64 *vec, t_const_str tag, t_const_str print); -bool is_sorted(t_vec_i64 *v); +void push_inner(t_vec_i64 *to, t_vec_i64 *from, t_const_str tag, + t_const_str print); +void swap_inner(t_vec_i64 *vec, t_const_str tag, t_const_str print); +void rotate_inner(t_vec_i64 *vec, t_const_str tag, t_const_str print); +void rev_rotate_inner(t_vec_i64 *vec, t_const_str tag, t_const_str print); +bool is_sorted(t_vec_i64 *v); -t_error handle_operation(t_buffer_str s, t_state *state) +t_error handle_operation(t_buffer_str s, t_state *state) { - t_usize op; + t_usize op; op = 0; if (s.buf == NULL) @@ -39,38 +39,35 @@ t_error handle_operation(t_buffer_str s, t_state *state) push_inner(&state->stack_a, &state->stack_b, NULL, (op++, NULL)); if (str_n_compare(s.buf, "pb", 2) == 0) push_inner(&state->stack_b, &state->stack_a, NULL, (op++, NULL)); - - if (str_n_compare(s.buf, "sa", 2) == 0 || - str_n_compare(s.buf, "ss", 2) == 0) + if (str_n_compare(s.buf, "sa", 2) == 0 || str_n_compare(s.buf, "ss", + 2) == 0) swap_inner(&state->stack_a, NULL, (op++, NULL)); - if (str_n_compare(s.buf, "sb", 2) == 0 || - str_n_compare(s.buf, "ss", 2) == 0) + if (str_n_compare(s.buf, "sb", 2) == 0 || str_n_compare(s.buf, "ss", + 2) == 0) swap_inner(&state->stack_b, NULL, (op++, NULL)); - - if (str_n_compare(s.buf, "ra", 2) == 0 || - str_n_compare(s.buf, "rr", 2) == 0) + if (str_n_compare(s.buf, "ra", 2) == 0 || str_n_compare(s.buf, "rr", + 2) == 0) rotate_inner(&state->stack_a, NULL, (op++, NULL)); - if (str_n_compare(s.buf, "rb", 2) == 0 || - str_n_compare(s.buf, "rr", 2) == 0) + if (str_n_compare(s.buf, "rb", 2) == 0 || str_n_compare(s.buf, "rr", + 2) == 0) rotate_inner(&state->stack_b, NULL, (op++, NULL)); - - if (str_n_compare(s.buf, "rra", 3) == 0 || - str_n_compare(s.buf, "rrr", 3) == 0) + if (str_n_compare(s.buf, "rra", 3) == 0 || str_n_compare(s.buf, "rrr", + 3) == 0) rev_rotate_inner(&state->stack_a, NULL, (op++, NULL)); - if (str_n_compare(s.buf, "rrb", 3) == 0 || - str_n_compare(s.buf, "rrr", 3) == 0) + if (str_n_compare(s.buf, "rrb", 3) == 0 || str_n_compare(s.buf, "rrr", + 3) == 0) rev_rotate_inner(&state->stack_b, NULL, (op++, NULL)); if (op == 0) return (ERROR); return (NO_ERROR); } -int main_checker(t_i32 argc, t_str argv[]) +int main_checker(t_i32 argc, t_str argv[]) { - t_state state; - t_buffer_str s; - bool err; - t_usize count; + t_state state; + t_buffer_str s; + bool err; + t_usize count; (void)(argc--, argv++); err = false; @@ -79,10 +76,9 @@ int main_checker(t_i32 argc, t_str argv[]) count = 1; while (!err && s.buf != NULL) { - if (s.len != 0 && s.buf[s.len - 1] == '\n') str_pop(&s); - //me_printf("line[%u]: '%s'\n", count, s.buf); + // me_printf("line[%u]: '%s'\n", count, s.buf); if (handle_operation(s, &state)) { me_printf("KO: error\n"); @@ -99,7 +95,6 @@ int main_checker(t_i32 argc, t_str argv[]) me_printf("OK\n"); else me_printf("KO: Not sorted\n"); - free_state(state); return (0); } diff --git a/src/app/moves/rotate.c b/src/app/moves/rotate.c index ff314ce..86cd2aa 100644 --- a/src/app/moves/rotate.c +++ b/src/app/moves/rotate.c @@ -13,30 +13,30 @@ #include "app/state.h" #include "me/printf/printf.h" -void rotate_inner(t_vec_i64 *stack, t_const_str tag, t_const_str print) +void rotate_inner(t_vec_i64 *stack, t_const_str tag, t_const_str print) { - t_i64 e; + t_i64 e; (void)(tag); if (stack->len < 2) - return; + return ; vec_i64_pop_front(stack, &e); vec_i64_push(stack, e); if (print) me_printf("%s\n", print); } -void rotate_a(t_state *s) +void rotate_a(t_state *s) { rotate_inner(&s->stack_a, "Rotate A", "ra"); } -void rotate_b(t_state *s) +void rotate_b(t_state *s) { rotate_inner(&s->stack_b, "Rotate B", "rb"); } -void rotate_both(t_state *s) +void rotate_both(t_state *s) { rotate_inner(&s->stack_a, "Rotate Both", NULL); rotate_inner(&s->stack_b, "Rotate Both", "rr"); diff --git a/src/app/moves/swap.c b/src/app/moves/swap.c index cb58326..934cedd 100644 --- a/src/app/moves/swap.c +++ b/src/app/moves/swap.c @@ -14,14 +14,14 @@ #include "me/printf/printf.h" #include "me/vec/vec_i64.h" -void swap_inner(t_vec_i64 *stack, t_const_str tag, t_const_str print) +void swap_inner(t_vec_i64 *stack, t_const_str tag, t_const_str print) { - t_i64 first; - t_i64 second; + t_i64 first; + t_i64 second; (void)(tag); if (stack->len < 2) - return; + return ; vec_i64_pop_front(stack, &first); vec_i64_pop_front(stack, &second); vec_i64_push_front(stack, first); @@ -30,17 +30,17 @@ void swap_inner(t_vec_i64 *stack, t_const_str tag, t_const_str print) me_printf("%s\n", print); } -void swap_a(t_state *s) +void swap_a(t_state *s) { swap_inner(&s->stack_a, "Swap A", "sa"); } -void swap_b(t_state *s) +void swap_b(t_state *s) { swap_inner(&s->stack_b, "Swap B", "sb"); } -void swap_both(t_state *s) +void swap_both(t_state *s) { swap_inner(&s->stack_a, "Swap Both", NULL); swap_inner(&s->stack_b, "Swap Both", "ss"); diff --git a/src/bonus/move1.c b/src/bonus/move1.c index 10ec74c..6ca0754 100644 --- a/src/bonus/move1.c +++ b/src/bonus/move1.c @@ -9,5 +9,3 @@ /* Updated: 2024/02/08 19:15:21 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ - -