52 lines
906 B
C
52 lines
906 B
C
|
|
#include "pushswap.h"
|
|
|
|
void is_valid(int ac, char **av)
|
|
{
|
|
if (ac < 2)
|
|
ps_stop(NULL, NULL, NULL, 1);
|
|
(void)av;
|
|
// check more error
|
|
}
|
|
|
|
int check_flag(int *ac, char ***av)
|
|
{
|
|
if (ft_strcmp((*av)[1], "-p") != 0)
|
|
return (0);
|
|
(*av)++;;
|
|
(*ac)--;
|
|
return (1);
|
|
}
|
|
|
|
t_stack *init_stack(int ac, char **av)
|
|
{
|
|
t_stack *start;
|
|
t_stack *tmp;
|
|
|
|
tmp = NULL;
|
|
while (--ac)
|
|
{
|
|
if (!(start = ft_calloc(1, sizeof(t_stack))))
|
|
ps_stop(start, NULL, NULL, 2);
|
|
start->n = ft_atoi(av[ac]);
|
|
start->next = tmp;
|
|
tmp = start;
|
|
}
|
|
return (start);
|
|
}
|
|
|
|
int main(int ac, char **av)
|
|
{
|
|
t_stack *stack;
|
|
t_list *result;
|
|
int flag;
|
|
|
|
is_valid(ac, av); // check if usage and list are correct
|
|
flag = check_flag(&ac, &av); //check for flag, like print
|
|
stack = init_stack(ac, av); // create the list from av[]
|
|
result = sort_algo(stack, flag);
|
|
// print_result(result);
|
|
ps_stop(stack, NULL, result, 0);
|
|
return(0);
|
|
}
|