-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps_main.c
61 lines (56 loc) · 1.88 KB
/
ps_main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ps_main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yongmkim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 11:38:44 by yongmkim #+# #+# */
/* Updated: 2022/03/22 12:02:42 by yongmkim ### ########seoul.kr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
static int fn_init(t_stack *stack)
{
stack->a = NULLL;
stack->b = NULLL;
stack->show = 0;
return (0);
}
static void fn_b_is_null(t_stack *stack)
{
if (stack->show & SHOW)
{
if (!(fn_issort_dlist_asc(&(stack->a), ft_dlist_size(stack->a))) \
&& stack->b == NULLL)
ft_putstr_fd("\nOK\n", STD_OUT);
else
ft_putstr_fd("\nKO\n", STD_OUT);
}
if (stack->b != NULLL)
{
fn_free(&(stack->b), SUCCESS);
}
}
int main(int argc, char *argv[])
{
t_stack stack;
if (argc <= 1)
return (0);
fn_init(&stack);
fn_is_there_option(argv[1], &argv, &stack.show, argc);
if (stack.show & SHOW && argc == 2)
exit(ft_putstr_fd("Error\n", STD_ERR));
fn_argv_to_list(argc - (stack.show & SHOW), argv, &stack.a);
if (stack.show & SHOW)
{
stack.show |= 64;
fn_listprint(&stack, stack.show);
ft_putstr_fd("start\n", STD_OUT);
}
fn_sort_atob(&stack, ft_dlist_size(stack.a));
if (stack.show & 64)
fn_op_optimize(&stack, B + B);
fn_b_is_null(&stack);
return (fn_free(&stack.a, SUCCESS));
}