debug sucess

This commit is contained in:
Hugo LAMY
2019-12-29 17:57:37 +01:00
parent e52b51200f
commit 1b7527eb31
2 changed files with 97 additions and 107 deletions

View File

@@ -13,32 +13,32 @@
** **
** #include <stdio.h> //for printf ** #include <stdio.h> //for printf
** #include <fcntl.h> //for open ** #include <fcntl.h> //for open
*/ **
void ft_putchar(char c){ ** void ft_putchar(char c){
write(1, &c, 1); ** write(1, &c, 1);
} ** }
**
void ft_putstr(char *s) ** void ft_putstr(char *s)
{ ** {
while (s && *s) ** while (s && *s)
ft_putchar(*s++); ** ft_putchar(*s++);
} ** }
**
void ft_putnbr(int n) ** void ft_putnbr(int n)
{ ** {
long l; ** long l;
**
l = n; ** l = n;
if (l < 0) ** if (l < 0)
{ ** {
ft_putchar('-'); ** ft_putchar('-');
l *= -1; ** l *= -1;
} ** }
if (l >= 10) ** if (l >= 10)
ft_putnbr(l / 10); ** ft_putnbr(l / 10);
ft_putchar((l % 10) + '0'); ** ft_putchar((l % 10) + '0');
} ** }
/* **
** int main(int ac, char **av) ** int main(int ac, char **av)
** { ** {
** int *fd; ** int *fd;
@@ -47,19 +47,6 @@
** int ret; ** int ret;
** char *line; ** 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; ** line = NULL;
** i = 0; ** i = 0;
** if (!(fd = (int *)malloc(sizeof(int) * ac))) ** if (!(fd = (int *)malloc(sizeof(int) * ac)))
@@ -68,20 +55,25 @@
** fd[i - 1] = open(av[i], O_RDONLY); ** fd[i - 1] = open(av[i], O_RDONLY);
** i = 0; ** i = 0;
** j = 0; ** j = 0;
** ret = 1;
** while (j < ac - 1) ** while (j < ac - 1)
** { ** {
** if ((ret = get_next_line(fd[i], &line)) > 0) ** if (ret > 0)
** { ** {
** //printf("[fd%i-%i] %s\n", fd[i], ret, line); ** ret = get_next_line(fd[i], &line);
** ft_putstr("[fd");ft_putnbr(fd[i]);ft_putchar('-');ft_putnbr(ret);ft_putstr("]\n"); ** // soit afficher le contenu de line
** printf("[fd%i-%i] %s\n", fd[i], ret, line);
** // soit afficher en direct les fd ouverts simultanements
** //ft_putstr("[fd");ft_putnbr(fd[i]);ft_putchar('-');ft_putnbr(ret);ft_putstr("]\n");
** free(line); ** free(line);
** j = 0; ** j = 0;
** } ** }
** else ** else
** { ** {
** free(line); ** // soit afficher le contenu de line
** //printf("[fd%i-%i]*FINI*\n", fd[i], ret); ** 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"); ** // soit afficher en direct les fd ouverts simultanements
** //ft_putstr("[fd");ft_putnbr(fd[i]);ft_putchar('-');ft_putnbr(ret);ft_putstr("]*FINI*\n");
** j++; ** j++;
** } ** }
** i++; ** i++;
@@ -89,7 +81,7 @@
** i = 0; ** i = 0;
** } ** }
** free(fd); ** free(fd);
** // while (1); ** while (1);
** return (0); ** return (0);
** } ** }
*/ */
@@ -99,37 +91,38 @@ int free_lst(t_gnlist **lst, int ret)
t_gnlist *tmp; t_gnlist *tmp;
tmp = *lst; tmp = *lst;
////////////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////////////
int debug; // // int debug; //
t_gnlist *tmp2; // // t_gnlist *tmp2; //
if (tmp->next != tmp) // // if (tmp->next != tmp) //
tmp2 = tmp->next; // // tmp2 = tmp->next; //
else // // else //
tmp2 = NULL; // // tmp2 = NULL; //
debug = tmp->lfd; // // debug = tmp->lfd; //
////////////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////////////
while ((*lst)->next != tmp) while ((*lst)->next != tmp)
(*lst) = (*lst)->next; (*lst) = (*lst)->next;
(*lst)->next = (*lst)->next->next; (*lst)->next = (*lst)->next->next;
free(tmp->str); free(tmp->str);
free(tmp); free(tmp);
tmp = NULL; tmp = NULL;
*lst = tmp;
////////////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////////////
if (tmp2) // // if (tmp2) //
{ // // { //
tmp = tmp2; // // tmp = tmp2; //
ft_putstr("\nDEL ");debug>9 ? ft_putstr(" "):ft_putstr(" ");ft_putchar('-'); // // ft_putstr("\nDEL ");debug>9 ? ft_putstr(" "):ft_putstr(" ");ft_putchar('-'); //
while (tmp != *lst) // // while (tmp != *lst) //
{ // // { //
ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next; // // ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next; //
} // // } //
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"); // // ft_putchar('('); ft_putnbr(tmp->lfd); ft_putstr(")\n"); //
} // // } //
else // // else //
ft_putstr("DEL\n"); // // ft_putstr("DEL\n"); //
////////////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////////////
return (ret); return (ret);
} }
@@ -139,33 +132,31 @@ int multi_fd(int fd, t_gnlist **lst)
t_gnlist *tmp; t_gnlist *tmp;
tmp = *lst; tmp = *lst;
//while (*lst && (*lst)->lfd != fd && (*lst)->next != tmp) while (*lst && (*lst)->lfd != fd && (*lst)->next != tmp)
// *lst = (*lst)->next; *lst = (*lst)->next;
// //////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////// // ft_putnbr(fd); ft_putstr("-"); //
ft_putnbr(fd); ft_putstr("-"); // // int j = 1; //
int j = 1; // // while (j) //
while (j) // // { //
{ // // if (*lst) //
if (*lst) // // { //
{ // // if ((*lst)->lfd != fd) //
if ((*lst)->lfd != fd) // // { //
{ // // if ((*lst)->next != tmp) //
if ((*lst)->next != tmp) // // { //
{ // // *lst = (*lst)->next; //
*lst = (*lst)->next; // // } //
} // // else //
else // // j = 0; //
j = 0; // // } //
} // // else //
else // // j = 0; //
j = 0; // // } //
} // // else //
else // // j = 0; //
j = 0; // // } //
} // // //////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
if (!tmp || ((*lst)->next == tmp && (*lst)->lfd != fd)) if (!tmp || ((*lst)->next == tmp && (*lst)->lfd != fd))
{ {
if (!(tmp = (t_gnlist*)malloc(sizeof(*tmp)))) if (!(tmp = (t_gnlist*)malloc(sizeof(*tmp))))
@@ -183,15 +174,15 @@ int multi_fd(int fd, t_gnlist **lst)
*lst = tmp; *lst = tmp;
} }
////////////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////////////
tmp = *lst; // // tmp = *lst; //
ft_putstr("LST ");ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next; // // ft_putstr("LST ");ft_putnbr(tmp->lfd); ft_putchar('-'); tmp = tmp->next; //
while (tmp != *lst) // // 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"); // // ft_putchar('('); ft_putnbr(tmp->lfd); ft_putstr(")\n"); //
////////////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////////////
return (1); return (1);
} }
@@ -220,6 +211,5 @@ int get_next_line(const int fd, char **line)
return (free_lst(&lst, -1)); return (free_lst(&lst, -1));
if (str != NULL) if (str != NULL)
return(ft_memmove(lst->str, str + 1, ft_strlen(str + 1) + 1) != NULL); return(ft_memmove(lst->str, str + 1, ft_strlen(str + 1) + 1) != NULL);
// return (0);
return (free_lst(&lst, 0)); return (free_lst(&lst, 0));
} }