definitely closer to TGIF :HYPE:

update libft (normed)
added command parsing to checker
This commit is contained in:
Tanguy MAZE 2019-02-28 17:03:14 +01:00
parent 7a2037c046
commit f8c0e70d9d
3 changed files with 59 additions and 30 deletions

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/21 14:13:53 by tmaze #+# #+# */
/* Updated: 2019/02/25 15:57:11 by tmaze ### ########.fr */
/* Updated: 2019/02/28 16:10:45 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,7 @@
# include <unistd.h>
# include "libft.h"
#include <stdio.h>
# include <stdio.h>
typedef struct s_stack
{

2
libft

@ -1 +1 @@
Subproject commit 2dfcdd29fd74f3c1f3176190bacc20c663001c42
Subproject commit e6970465e98cdfdc3abd999e29121da8a736686e

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */
/* Updated: 2019/02/25 17:04:05 by tmaze ### ########.fr */
/* Updated: 2019/02/28 17:02:28 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,51 +21,80 @@ int check_input(char *in, int *ret)
i++;
while (in[i] && ft_isdigit(in[i]))
i++;
if (in[i] == '\0' && ft_hasdigit(in))
*ret = ft_atoi(in);
return (in[i] == '\0' && ft_hasdigit(in));
if (in[i] == '\0' && ft_hasdigit(in) && ft_atois(in, ret))
return (1);
return (0);
}
int main(int ac, char **av)
int get_params(t_psdata *data, int ac, char **av)
{
int i;
int nb;
t_stack *new;
t_psdata data;
char **tab;
int nb;
int i;
int j;
i = ac;
nb = 0;
ps_initdata(&data);
while (--i > 0)
{
if ((tab = ft_strsplitwhitespace(av[i])) != NULL && !(j = 0))
while (--i > 0 && !(j = 0))
if ((tab = ft_strsplitwhitespace(av[i])) != NULL)
{
while (tab[j])
j++;
while (--j >= 0)
{
if (check_input(tab[j], &nb) && (new = ps_stknew(nb)) != NULL)
ps_stkpsh(&data, 'a', new);
ps_stkpsh(data, 'a', new);
else
{
ft_putendl_fd("Error", 2);
ps_stkclean(&data);
return (2);
}
ps_stkclean(data);
return (0);
}
ft_del_words_tables(&tab);
}
}
return (1);
}
int is_op(char *buff)
{
static char ops[11][3] = {"sa", "sb", "ss", "pa", "pb", "ra",
"rb", "rr", "rra", "rrb", "rrr"};
size_t i;
i = 0;
while (i < 11 && ft_strcmp(buff, ops[i]) != 0)
i++;
return (i < 11 && ft_strcmp(buff, ops[i]) == 0);
}
int main(int ac, char **av)
{
t_psdata data;
t_stack *new;
t_list *nop;
char buff[5];
int ret;
ps_initdata(&data);
ft_memset(buff, '\0', 5);
if (!get_params(&data, ac, av))
return (0);
new = data.a;
if (new == NULL)
ft_putendl("Empty");
while (new != NULL)
else
while ((ret = read(1, buff, 4)) > 0)
{
ft_putnbr(new->nb);
ft_putchar('\n');
new = new->next;
buff[ft_strlen(buff) - 1] = '\0';
if (ret > 4 || !is_op(buff) || (nop = ft_lstnew(buff, 4)) == NULL)
{
ft_putendl_fd("Error", 2);
ps_stkclean(&data);
return (1);
}
printf("%d\n", ret);
ft_lstaddend(&(data.op), nop);
}
ps_stkclean(&data);
return (0);
}