diff options
Diffstat (limited to 'src/errors.c')
| -rw-r--r-- | src/errors.c | 89 |
1 files changed, 89 insertions, 0 deletions
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 <https://www.gnu.org/licenses/>. +*/ + +#include "../include/push_swap.h" +#include <limits.h> + +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); +} |
