diff --git a/mecstd b/mecstd index e9c4ce8..60b9db4 160000 --- a/mecstd +++ b/mecstd @@ -1 +1 @@ -Subproject commit e9c4ce89ea79ba399f8995f3c14e66e78555661d +Subproject commit 60b9db4c20aa957cff32ae58dfc8a2124f9b35d5 diff --git a/src/app/main.c b/src/app/main.c index e3fb7cd..3bc4a32 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:00:12 by maiboyer #+# #+# */ -/* Updated: 2024/02/08 18:44:58 by maiboyer ### ########.fr */ +/* Updated: 2024/02/08 18:53:49 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,32 +19,28 @@ #include "me/vec/vec_i64_bool.h" #include -#define TESTER_ERROR(s) "" +void sort_3(t_state *state); +void sort_2(t_state *state); +void sort_5(t_state *state); -// #define TESTER_ERROR(s) s +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); - -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); @@ -59,11 +55,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); @@ -72,33 +68,31 @@ t_state parses_arguments(t_usize count, t_str nums[]) while (i < count) { if (str_to_i32(nums[i], 10, &atoi)) - (free_state(state), - me_eprintf("Error\n" TESTER_ERROR("Invalid Number\n")), exit(1)); + (free_state(state), me_eprintf("Error:\nInvalid Number\n"), + 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); if (duplicate_check(&state)) - (free_state(state), - me_eprintf("Error\n" TESTER_ERROR("Duplicate Number\n")), exit(1)); + (free_state(state), me_eprintf("Error:\nDuplicate Number\n"), exit(1)); return (state); } -bool is_sorted(t_vec_i64 *v); +bool is_sorted(t_vec_i64 *v); -int main(t_i32 argc, t_str argv[]) +int main(t_i32 argc, t_str argv[]) { - t_state state; + t_state state; (void)(argc--, argv++); state = parses_arguments(argc, argv); if (is_sorted(&state.stack_a)) return (free_state(state), 0); if (state.stack_a.len == 0) - (free_state(state), me_eprintf("Error\n" TESTER_ERROR("No Input\n")), - exit(1)); + (free_state(state), me_eprintf("Error:\nNo Input\n"), exit(1)); if (state.stack_a.len == 2) sort_2(&state); else if (state.stack_a.len == 3)