From 40ad9bfe202f72a5b52eed8ff38da9b27de12adb Mon Sep 17 00:00:00 2001 From: yctct Date: Thu, 16 Apr 2026 18:25:12 +0200 Subject: First commit --- src/errors.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/errors.c (limited to 'src/errors.c') diff --git a/src/errors.c b/src/errors.c new file mode 100644 index 0000000..63e661e --- /dev/null +++ b/src/errors.c @@ -0,0 +1,89 @@ +/* +sort_stack Copyright (C) 2026 yctct + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "../include/push_swap.h" +#include + +void puterror(t_list *src) +{ + if (src) + free_stack(src); + write(1, "Error\n", 6); + exit(1); +} + +int is_dup(t_list *stack) +{ + t_list *first; + t_list *second; + + first = stack; + second = stack->next; + while (first) + { + second = first->next; + while (second) + { + if (first->value == second->value) + return (1); + second = second->next; + } + first = first->next; + } + return (0); +} + +int is_limit_int(t_list *stack) +{ + while (stack) + { + if (stack->value > INT_MAX || stack->value < INT_MIN) + return (1); + stack = stack->next; + } + return (0); +} + +int is_valid_int(char **array) +{ + int j; + int i; + + j = 0; + while (array[j]) + { + i = 0; + while (array[j][i]) + { + if (array[j][i] == '-' && i == 0) + i++; + if (array[j][i] < '0' || array[j][i] > '9') + return (0); + i++; + } + j++; + } + return (1); +} + +void check_errors(t_list *src) +{ + if (is_dup(src)) + puterror(src); + if (is_limit_int(src)) + puterror(src); +} -- cgit v1.2.3