-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps_utils.c
69 lines (61 loc) · 1.59 KB
/
ps_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ps_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/03 01:19:19 by zwalad #+# #+# */
/* Updated: 2022/03/23 21:40:17 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void herror(int i)
{
write(2, "Error\n", 5);
write(2, "\n", 1);
exit(i);
}
void check_dup(char *argv[], int j)
{
int i;
int k;
i = j;
while (argv[i])
{
k = j;
while (argv[k])
{
if ((ps_atoi(argv[i]) - ps_atoi(argv[k]) == 0) && i != k)
herror(1);
k++;
}
i++;
}
}
int le_len(t_swap *a)
{
int i;
i = 0;
while (a != NULL)
{
a = a->next;
i++;
}
return (i);
}
t_stacks *mini_main(t_stacks *p, int argc, char *argv[])
{
int i;
t_swap *tmp;
i = 1;
p->arg = argc - 1;
check_dup(argv, 1);
p = stack_init(p, argv, argc, 1);
while (argv[i] != NULL)
ps_lstadd_back(p->a, ps_lstnew(ps_atoi(argv[i++])));
tmp = p->a;
p->a = p->a->next;
free(tmp);
return (p);
}