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> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/21 14:13:53 by tmaze #+# #+# */ /* 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 <unistd.h>
# include "libft.h" # include "libft.h"
#include <stdio.h> # include <stdio.h>
typedef struct s_stack 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> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */ /* 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++; i++;
while (in[i] && ft_isdigit(in[i])) while (in[i] && ft_isdigit(in[i]))
i++; i++;
if (in[i] == '\0' && ft_hasdigit(in)) if (in[i] == '\0' && ft_hasdigit(in) && ft_atois(in, ret))
*ret = ft_atoi(in); return (1);
return (in[i] == '\0' && ft_hasdigit(in)); return (0);
} }
int main(int ac, char **av) int get_params(t_psdata *data, int ac, char **av)
{ {
int i; t_stack *new;
int nb; char **tab;
t_stack *new; int nb;
t_psdata data; int i;
char **tab; int j;
int j;
i = ac; i = ac;
nb = 0; nb = 0;
ps_initdata(&data); while (--i > 0 && !(j = 0))
while (--i > 0) if ((tab = ft_strsplitwhitespace(av[i])) != NULL)
{
if ((tab = ft_strsplitwhitespace(av[i])) != NULL && !(j = 0))
{ {
while (tab[j]) while (tab[j])
j++; j++;
while (--j >= 0) while (--j >= 0)
{
if (check_input(tab[j], &nb) && (new = ps_stknew(nb)) != NULL) if (check_input(tab[j], &nb) && (new = ps_stknew(nb)) != NULL)
ps_stkpsh(&data, 'a', new); ps_stkpsh(data, 'a', new);
else else
{ {
ft_putendl_fd("Error", 2); ft_putendl_fd("Error", 2);
ps_stkclean(&data); ps_stkclean(data);
return (2); return (0);
} }
}
ft_del_words_tables(&tab); 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; new = data.a;
if (new == NULL) if (new == NULL)
ft_putendl("Empty"); ft_putendl("Empty");
while (new != NULL) else
{ while ((ret = read(1, buff, 4)) > 0)
ft_putnbr(new->nb); {
ft_putchar('\n'); buff[ft_strlen(buff) - 1] = '\0';
new = new->next; 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); ps_stkclean(&data);
return (0);
} }