here_doc bugfix

This commit is contained in:
LuckyLaszlo
2021-12-09 05:32:20 +01:00
parent 73feaf0230
commit f7d37fadb6
2 changed files with 5 additions and 33 deletions

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
/* Updated: 2021/11/29 12:38:58 by lperrey ### ########.fr */
/* Updated: 2021/12/09 05:31:16 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,9 +25,6 @@ int here_doc(char *delimiter)
and the here-document lines shall not be expanded.
Otherwise, the delimiter shall be the word itself. */
// TODO : A voir si on fait les expansions de variables dans le here_doc.
// implementer une gestion des signaux pour here_doc (verifier comportement bash et doc POSIX).
// Peut-être remplacer gnl() par readline() pour avoir une gestion correct
// du terminal (actuellement l'affichage lors du changement de ligne est foireux).
int here_doc;
int ret;
@@ -102,7 +99,7 @@ static int here_doc_write(char *delimiter, int doc_fd)
ft_putstr_fd(" delimited by end-of-file (wanted `", 2);
ft_putstr_fd(delimiter, 2);
ft_putstr_fd("')\n", 2);
return (-1);
return (0);
}
if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0) // Ou ft_strlen(delimiter) + 1 ? Ça devrais être identique et ça peux se calculer une seul fois.
break ;
@@ -117,31 +114,3 @@ static int here_doc_write(char *delimiter, int doc_fd)
sigaction(SIGINT, &signal_action, NULL);
return (0);
}
/*
static int here_doc_write(char *delimiter, int doc_fd)
{
char *line;
int ret;
line = NULL;
ret = 1;
while (ret)
{
ret = gnl(STDIN_FILENO, &line, 0);
if (ret == -1)
return (ft_reti_perror_free(0, line, free, "gnl() STDIN"));
if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0) // Ou ft_strlen(delimiter) + 1 ? Ça devrais être identique et ça peux se calculer une seul fois.
break ;
if (write(doc_fd, line, ft_strlen(line)) == -1)
return (ft_reti_perror_free(0, line, free, "write() "TMP_HERE_DOC));
if (write(doc_fd, "\n", 1) == -1)
return (ft_reti_perror_free(0, line, free, "write() "TMP_HERE_DOC));
free(line);
line = NULL;
}
free(line);
gnl(STDIN_FILENO, NULL, 1);
return (1);
}
*/

View File

@@ -72,7 +72,10 @@ static int redirect_cmd_input(t_token *t, t_cmd *cmd)
cmd->error = EXIT_REDIRECTION;
}
else if (cmd->fd_in > EXIT_SIGNAL)
{
cmd->fd_in = 0;
return (0);
}
}
return (1);
}