definitely closer to TGIF :HYPE:
update libft (normed) added command parsing to checker
This commit is contained in:
parent
7a2037c046
commit
f8c0e70d9d
@ -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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
2
libft
2
libft
@ -1 +1 @@
|
|||||||
Subproject commit 2dfcdd29fd74f3c1f3176190bacc20c663001c42
|
Subproject commit e6970465e98cdfdc3abd999e29121da8a736686e
|
@ -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;
|
|
||||||
int nb;
|
|
||||||
t_stack *new;
|
t_stack *new;
|
||||||
t_psdata data;
|
|
||||||
char **tab;
|
char **tab;
|
||||||
|
int nb;
|
||||||
|
int i;
|
||||||
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);
|
buff[ft_strlen(buff) - 1] = '\0';
|
||||||
ft_putchar('\n');
|
if (ret > 4 || !is_op(buff) || (nop = ft_lstnew(buff, 4)) == NULL)
|
||||||
new = new->next;
|
{
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user