amelioration lignes debug et ajout des tests

This commit is contained in:
Hugo LAMY
2019-12-29 17:02:22 +01:00
parent 7dc605631e
commit e52b51200f
112 changed files with 4919 additions and 112 deletions

View File

@@ -1,28 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/21 00:28:33 by hulamy #+# #+# */
/* Updated: 2019/12/21 00:28:39 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
//-g -fsanitize=address
//:set noendofline binary
//https://github.com/charMstr/GNL_lover
//https://github.com/mrjvs/42cursus_gnl_tests
//https://github.com/Sherchryst/gnlkiller
//https://github.com/Hellio404/Get_Next_Line_Tester
//https://github.com/TinfoilPancakes/get-next-line-testing-tools
#include <stdio.h> //for printf
#include <fcntl.h> //for open
/*
** //-g -fsanitize=address
** //:set noendofline binary
** //https://github.com/lgrellie/gnl_tester
** //https://github.com/Mazoise/42TESTERS-GNL
** //https://github.com/charMstr/GNL_lover
** //https://github.com/mrjvs/42cursus_gnl_tests
** //https://github.com/Sherchryst/gnlkiller
** //https://github.com/Hellio404/Get_Next_Line_Tester
** //https://github.com/TinfoilPancakes/get-next-line-testing-tools
**
** #include <stdio.h> //for printf
** #include <fcntl.h> //for open
*/
void ft_putchar(char c){
write(1, &c, 1);
}
@@ -47,98 +38,98 @@
ft_putnbr(l / 10);
ft_putchar((l % 10) + '0');
}
int main(int ac, char **av)
{
int *fd;
int i;
int j;
int ret;
char *line;
// if (ac < 2)
// return (0);
// (void)i;(void)j;
// line = NULL;
// fd[0] = open(av[1], O_RDONLY);
// ret = 1;
// while (ret)
// {
// ret = get_next_line(fd[0], &line);
// printf("[%i] %s\n", ret, line);
// }
line = NULL;
i = 0;
if (!(fd = (int *)malloc(sizeof(int) * ac)))
return (0);
while (++i <= ac - 1)
fd[i - 1] = open(av[i], O_RDONLY);
i = 0;
j = 0;
while (j < ac - 1)
{
if ((ret = get_next_line(fd[i], &line)) > 0)
{
//printf("[fd%i-%i] %s\n", fd[i], ret, line);
ft_putstr("[fd");ft_putnbr(fd[i]);ft_putchar('-');ft_putnbr(ret);ft_putstr("]\n");
free(line);
j = 0;
}
else
{
free(line);
//printf("[fd%i-%i]*FINI*\n", fd[i], ret);
ft_putstr("[fd");ft_putnbr(fd[i]);ft_putchar('-');ft_putnbr(ret);ft_putstr("]*FINI*\n");
j++;
}
i++;
if (i >= ac - 1)
i = 0;
}
free(fd);
//while (1);
return (0);
}
/*
** int main(int ac, char **av)
** {
** int *fd;
** int i;
** int j;
** int ret;
** char *line;
**
** // if (ac < 2)
** // return (0);
**
** // (void)i;(void)j;
** // line = NULL;
** // fd[0] = open(av[1], O_RDONLY);
** // ret = 1;
** // while (ret)
** // {
** // ret = get_next_line(fd[0], &line);
** // printf("[%i] %s\n", ret, line);
** // }
**
** line = NULL;
** i = 0;
** if (!(fd = (int *)malloc(sizeof(int) * ac)))
** return (0);
** while (++i <= ac - 1)
** fd[i - 1] = open(av[i], O_RDONLY);
** i = 0;
** j = 0;
** while (j < ac - 1)
** {
** if ((ret = get_next_line(fd[i], &line)) > 0)
** {
** //printf("[fd%i-%i] %s\n", fd[i], ret, line);
** ft_putstr("[fd");ft_putnbr(fd[i]);ft_putchar('-');ft_putnbr(ret);ft_putstr("]\n");
** free(line);
** j = 0;
** }
** else
** {
** free(line);
** //printf("[fd%i-%i]*FINI*\n", fd[i], ret);
** ft_putstr("[fd");ft_putnbr(fd[i]);ft_putchar('-');ft_putnbr(ret);ft_putstr("]*FINI*\n");
** j++;
** }
** i++;
** if (i >= ac - 1)
** i = 0;
** }
** free(fd);
** // while (1);
** return (0);
** }
*/
int free_lst(t_gnlist **lst, int ret)
{
t_gnlist *tmp;
int debug;
tmp = *lst;
debug = tmp->lfd;
// char *s;
// s = tmp->string;
// if (ret == -1)
// while (lst->lfd != fd)
// {
// free((*lst)->string);
// *lst = (*lst)->next;
// free(tmp);
// tmp = *lst;
// }
// tmp->string = tmp->next->string;
// free(s);
// write(1, "\nIII\n", 5);
//////////////////////////////////////////////////////////////////////////////////////
int debug; //
t_gnlist *tmp2; //
if (tmp->next != tmp) //
tmp2 = tmp->next; //
else //
tmp2 = NULL; //
debug = tmp->lfd; //
//////////////////////////////////////////////////////////////////////////////////////
while ((*lst)->next != tmp)
(*lst) = (*lst)->next;
(*lst)->next = (*lst)->next->next;
free(tmp->str);
free(tmp);
tmp = NULL;
tmp = (*lst)->next;
ft_putstr("\nDEL ");debug>9 ? ft_putstr(" "):ft_putstr(" ");ft_putchar('-');
while (tmp != *lst)
{
ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next;
}
ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next;
ft_putchar('('); ft_putnbr(tmp->lfd); ft_putstr(")");
//////////////////////////////////////////////////////////////////////////////////////
if (tmp2) //
{ //
tmp = tmp2; //
ft_putstr("\nDEL ");debug>9 ? ft_putstr(" "):ft_putstr(" ");ft_putchar('-'); //
while (tmp != *lst) //
{ //
ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next; //
} //
ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next; //
ft_putchar('('); ft_putnbr(tmp->lfd); ft_putstr(")\n"); //
} //
else //
ft_putstr("DEL\n"); //
//////////////////////////////////////////////////////////////////////////////////////
return (ret);
}
@@ -148,8 +139,33 @@ int multi_fd(int fd, t_gnlist **lst)
t_gnlist *tmp;
tmp = *lst;
while (*lst && (*lst)->lfd != fd && (*lst)->next != tmp)
*lst = (*lst)->next;
//while (*lst && (*lst)->lfd != fd && (*lst)->next != tmp)
// *lst = (*lst)->next;
//////////////////////////////////////////////////////////////////////////////////////
ft_putnbr(fd); ft_putstr("-"); //
int j = 1; //
while (j) //
{ //
if (*lst) //
{ //
if ((*lst)->lfd != fd) //
{ //
if ((*lst)->next != tmp) //
{ //
*lst = (*lst)->next; //
} //
else //
j = 0; //
} //
else //
j = 0; //
} //
else //
j = 0; //
} //
//////////////////////////////////////////////////////////////////////////////////////
if (!tmp || ((*lst)->next == tmp && (*lst)->lfd != fd))
{
if (!(tmp = (t_gnlist*)malloc(sizeof(*tmp))))
@@ -167,13 +183,15 @@ int multi_fd(int fd, t_gnlist **lst)
*lst = tmp;
}
tmp = *lst;
ft_putstr("LST ");ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next;
while (tmp != *lst)
{
ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next;
}
ft_putchar('('); ft_putnbr(tmp->lfd); ft_putstr(")");
//////////////////////////////////////////////////////////////////////////////////////
tmp = *lst; //
ft_putstr("LST ");ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next; //
while (tmp != *lst) //
{ //
ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next; //
} //
ft_putchar('('); ft_putnbr(tmp->lfd); ft_putstr(")\n"); //
//////////////////////////////////////////////////////////////////////////////////////
return (1);
}