-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.c
83 lines (75 loc) · 1.94 KB
/
service.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* service.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jjacobso <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/30 18:14:20 by jjacobso #+# #+# */
/* Updated: 2019/02/08 16:22:33 by jjacobso ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void error(t_stacks_state *arg, char **filename)
{
arg_destroy(arg);
ft_memdel((void**)filename);
write(2, "Error\n", ft_strlen("Error\n"));
exit(1);
}
int valid(const char *s, t_list **stack, intmax_t num)
{
size_t len;
if (!s || !*s)
return (0);
len = 0;
if (*s == '-' || *s == '+')
s++;
while (ft_isdigit(s[len]))
len++;
if (len > ft_digs(INT_MAX)
|| num > INT_MAX || num < INT_MIN
|| l_int_find(*stack, num))
return (0);
return (1);
}
void print(t_stacks_state *arg)
{
t_list *a;
t_list *b;
int len;
a = arg->a;
b = arg->b;
ft_printf(RED"a:\t\t\t"BLU"\tb:\n"RESET);
while (a || b)
{
if (a)
{
len = ft_nlen(DATA(a), 10);
ft_printf(RED"%d"RESET, DATA(a));
a = a->next;
}
else
len = 0;
if (b)
{
ft_printf(BLU"%*d\n"RESET, 34 - len, DATA(b));
b = b->next;
}
else
ft_printf("\n");
}
}
void print_ops(t_stacks_state *arg)
{
t_list *ops;
ops = arg->ops;
if (!ops)
return ;
while (ops)
{
ft_putstr((char *)ops->data);
ft_putchar('\n');
ops = ops->next;
}
}