i hate mondays
rework of checker parser to accomodate for string arguments update of libft debuged push & pop functions still need to check for overflow arg
This commit is contained in:
parent
62764dc5e7
commit
7a2037c046
4
Makefile
4
Makefile
@ -6,7 +6,7 @@
|
||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2019/02/23 14:30:57 by tmaze #+# #+# #
|
||||
# Updated: 2019/02/24 14:17:55 by tmaze ### ########.fr #
|
||||
# Updated: 2019/02/25 15:55:49 by tmaze ### ########.fr #
|
||||
# #
|
||||
#******************************************************************************#
|
||||
|
||||
@ -42,6 +42,8 @@ SRC = ps_push.c \
|
||||
ps_rerot.c \
|
||||
ps_swap.c \
|
||||
ps_stktools.c \
|
||||
ps_stktools2.c \
|
||||
ft_strsplitwhitespace.c\
|
||||
\
|
||||
checker.c
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/21 14:13:53 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/24 14:56:19 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/02/25 15:57:11 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -34,10 +34,14 @@ typedef struct s_psdata
|
||||
t_list *op;
|
||||
} t_psdata;
|
||||
|
||||
char **ft_strsplitwhitespace(char *s);
|
||||
int ft_iswhitespace(char c);
|
||||
|
||||
t_stack *ps_stknew(int nb);
|
||||
void ps_stkpsh(t_psdata *data, char c, t_stack *new);
|
||||
t_stack *ps_stkpop(t_psdata *data, char c);
|
||||
void ps_stkclean(t_psdata *data);
|
||||
void ps_initdata(t_psdata *data);
|
||||
|
||||
void ps_swap(t_psdata *data, char c);
|
||||
void ps_sswap(t_psdata *data);
|
||||
|
2
libft
2
libft
@ -1 +1 @@
|
||||
Subproject commit 4b44c49fc6caa15379cd821f967e53462d4dc837
|
||||
Subproject commit 2dfcdd29fd74f3c1f3176190bacc20c663001c42
|
@ -6,48 +6,21 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/24 15:38:10 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/02/25 17:04:05 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
int ft_issign(char c)
|
||||
{
|
||||
return (c == '+' || c == '-');
|
||||
}
|
||||
|
||||
int ft_iswhitespace(char c)
|
||||
{
|
||||
return (c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f'
|
||||
|| c == '\r');
|
||||
}
|
||||
|
||||
int ft_hasdigit(char *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s[i] && !ft_isdigit(s[i]))
|
||||
i++;
|
||||
return (ft_isdigit(s[i]));
|
||||
}
|
||||
|
||||
int check_input(char *in, int *ret)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (in[i] && ft_iswhitespace(in[i]))
|
||||
i++;
|
||||
if (in[i] && ft_issign(in[i]))
|
||||
i++;
|
||||
while (in[i] && ft_iswhitespace(in[i]))
|
||||
i++;
|
||||
while (in[i] && ft_isdigit(in[i]))
|
||||
i++;
|
||||
while (in[i] && ft_iswhitespace(in[i]))
|
||||
i++;
|
||||
if (in[i] == '\0' && ft_hasdigit(in))
|
||||
*ret = ft_atoi(in);
|
||||
return (in[i] == '\0' && ft_hasdigit(in));
|
||||
@ -59,18 +32,40 @@ int main(int ac, char **av)
|
||||
int nb;
|
||||
t_stack *new;
|
||||
t_psdata data;
|
||||
char **tab;
|
||||
int j;
|
||||
|
||||
i = ac;
|
||||
nb = 0;
|
||||
ps_initdata(&data);
|
||||
while (--i > 0)
|
||||
{
|
||||
if (check_input(av[i], &nb) && (new = ps_stknew(nb)) != NULL)
|
||||
ps_stkpsh(&data, 'a', new);
|
||||
else
|
||||
if ((tab = ft_strsplitwhitespace(av[i])) != NULL && !(j = 0))
|
||||
{
|
||||
ft_putendl_fd("Error", 2);
|
||||
ps_stkclean(&data);
|
||||
return (2);
|
||||
while (tab[j])
|
||||
j++;
|
||||
while (--j >= 0)
|
||||
{
|
||||
if (check_input(tab[j], &nb) && (new = ps_stknew(nb)) != NULL)
|
||||
ps_stkpsh(&data, 'a', new);
|
||||
else
|
||||
{
|
||||
ft_putendl_fd("Error", 2);
|
||||
ps_stkclean(&data);
|
||||
return (2);
|
||||
}
|
||||
}
|
||||
ft_del_words_tables(&tab);
|
||||
}
|
||||
}
|
||||
new = data.a;
|
||||
if (new == NULL)
|
||||
ft_putendl("Empty");
|
||||
while (new != NULL)
|
||||
{
|
||||
ft_putnbr(new->nb);
|
||||
ft_putchar('\n');
|
||||
new = new->next;
|
||||
}
|
||||
ps_stkclean(&data);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/22 14:41:27 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/24 17:41:40 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/02/25 15:11:44 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -41,9 +41,7 @@ void ps_stkpsh(t_psdata *data, char c, t_stack *new)
|
||||
s = &(data->b);
|
||||
if (c == 'b')
|
||||
size = data->size_b;
|
||||
if (s != NULL && *s == NULL && (size++))
|
||||
*s = new;
|
||||
else if (s != NULL && *s != NULL)
|
||||
if (s != NULL)
|
||||
{
|
||||
ind = *s;
|
||||
*s = new;
|
||||
@ -89,21 +87,9 @@ void ps_stkclean(t_psdata *data)
|
||||
{
|
||||
t_stack *tmp;
|
||||
|
||||
tmp = data->a;
|
||||
while (data->a != NULL)
|
||||
{
|
||||
tmp = data->a;
|
||||
data->a = data->a->next;
|
||||
while ((tmp = ps_stkpop(data, 'a')) != NULL)
|
||||
ft_memdel((void**)&tmp);
|
||||
data->size_a--;
|
||||
}
|
||||
tmp = data->b;
|
||||
while (data->b != NULL)
|
||||
{
|
||||
tmp = data->b;
|
||||
data->b = data->b->next;
|
||||
while ((tmp = ps_stkpop(data, 'b')) != NULL)
|
||||
ft_memdel((void**)&tmp);
|
||||
data->size_b--;
|
||||
}
|
||||
ft_lstdel(&(data->op), &ft_lstdelstr);
|
||||
}
|
||||
|
22
srcs/ps_stktools2.c
Normal file
22
srcs/ps_stktools2.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ps_stktools2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/25 12:44:08 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/25 12:48:34 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void ps_initdata(t_psdata *data)
|
||||
{
|
||||
data->a = NULL;
|
||||
data->b = NULL;
|
||||
data->size_a = 0;
|
||||
data->size_b = 0;
|
||||
data->op = NULL;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user