-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.c
72 lines (65 loc) · 1.89 KB
/
parse.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: daxferna <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/21 19:19:36 by daxferna #+# #+# */
/* Updated: 2024/12/23 06:11:35 by daxferna ### ########.fr */
/* */
/* ************************************************************************** */
#include "../push_swap.h"
void index_list(t_num **stack_a)
{
t_num *tmp1;
t_num *tmp2;
tmp1 = *stack_a;
while (tmp1)
{
tmp2 = *stack_a;
while (tmp2)
{
if (tmp1->content > tmp2->content)
tmp1->index++;
tmp2 = tmp2->next;
}
tmp1 = tmp1->next;
}
}
bool addtolist(t_num **stack_a, char *num)
{
t_num *new_node;
int *numint;
numint = malloc(sizeof(int));
if (!numint)
return (false);
if (imprvatoi(num, numint) == 0)
return (free(numint), false);
new_node = lstnew(*numint);
free(numint);
if (!new_node)
return (false);
lstadd_back(stack_a, new_node);
return (true);
}
bool parse(int argc, char **argv, t_num **stack_a)
{
char **splitted_args;
int i;
int j;
i = 1;
while (i < argc)
{
splitted_args = ft_split(argv[i++], ' ');
if (splitted_args == NULL || splitted_args[0] == NULL)
return (0);
j = 0;
while (splitted_args[j])
if (!addtolist(stack_a, splitted_args[j++]))
return (freesplit(splitted_args), 0);
freesplit(splitted_args);
}
index_list(stack_a);
return (1);
}