merge
+ readline() replace gnl() in here_doc + "int error" in struct "t_cmd"
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/16 08:02:56 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/16 21:18:27 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -32,6 +32,7 @@ void save_redirections_words(t_token *t)
|
||||
t = t->next;
|
||||
}
|
||||
}
|
||||
|
||||
void print_cmd_array(t_cmd **cmd_arr)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/14 11:12:44 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/16 22:29:01 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -39,7 +39,6 @@ int here_doc(char *delimiter)
|
||||
if (!here_doc_write(delimiter, here_doc))
|
||||
{
|
||||
free(delimiter);
|
||||
gnl(STDIN_FILENO, NULL, 1);
|
||||
return (0);
|
||||
}
|
||||
free(delimiter);
|
||||
@@ -56,12 +55,24 @@ int here_doc(char *delimiter)
|
||||
static int here_doc_write(char *delimiter, int doc_fd)
|
||||
{
|
||||
char *line;
|
||||
size_t line_count;
|
||||
|
||||
line_count = 0;
|
||||
while (1)
|
||||
{
|
||||
line_count++;
|
||||
line = NULL;
|
||||
if (gnl(STDIN_FILENO, &line, 0) == -1)
|
||||
return (ft_reti_perror_free(0, line, free, "gnl() STDIN"));
|
||||
line = readline("> ");
|
||||
if (!line)
|
||||
{ // TODO : error print wrapper
|
||||
ft_putstr_fd("minishell: ", 2);
|
||||
ft_putstr_fd("warning: here-document at line ", 2);
|
||||
ft_putnbr_fd(line_count, 2);
|
||||
ft_putstr_fd(" delimited by end-of-file (wanted `", 2);
|
||||
ft_putstr_fd(delimiter, 2);
|
||||
ft_putstr_fd("')\n", 2);
|
||||
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 ;
|
||||
if (write(doc_fd, line, ft_strlen(line)) == -1)
|
||||
@@ -71,7 +82,6 @@ static int here_doc_write(char *delimiter, int doc_fd)
|
||||
free(line);
|
||||
}
|
||||
free(line);
|
||||
gnl(STDIN_FILENO, NULL, 1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/16 08:08:18 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/16 22:29:52 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -24,7 +24,7 @@ int redirections(t_token *t, t_cmd **cmd_arr)
|
||||
i = 0;
|
||||
while (t)
|
||||
{
|
||||
if (cmd_arr[i]->pid == 0) // Pid var as error mark, WIP
|
||||
if (!cmd_arr[i]->error)
|
||||
{
|
||||
if (t->id == '<' || t->id == T_DLESS)
|
||||
{
|
||||
@@ -60,7 +60,7 @@ static int redirect_cmd_input(t_token *t, t_cmd *cmd)
|
||||
if (cmd->fd_in == -1)
|
||||
{
|
||||
ft_perror_io("open() ", t->next->content); // todo error
|
||||
cmd->pid = -1; // Pid var as error mark, WIP
|
||||
cmd->error = 42; // WIP error status
|
||||
}
|
||||
}
|
||||
else if (t->id == T_DLESS)
|
||||
@@ -93,7 +93,7 @@ static int redirect_cmd_output(t_token *t, t_cmd *cmd)
|
||||
if (cmd->fd_out == -1)
|
||||
{
|
||||
ft_perror_io("open() ", t->next->content);
|
||||
cmd->pid = -1; // Pid var as error mark, WIP
|
||||
cmd->error = 42; // WIP error status
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user