Browse Source

fixed HD - expend_str added

master
Michael Ea 3 years ago
parent
commit
fc34ef9dcc
  1. 10
      minishell.c
  2. 7
      minishell.h
  3. 10
      parser.c

10
minishell.c

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 12:14:09 by narnaud #+# #+# */
/* Updated: 2022/05/05 14:02:48 by mea ### ########.fr */
/* Updated: 2022/05/05 14:18:16 by mea ### ########.fr */
/* */
/* ************************************************************************** */
@ -64,7 +64,7 @@ int caller(t_datas *datas, t_command *cmd)
return (1);
}
t_command *parser(t_token *tok, t_command *prev)
t_command *parser(t_datas *datas, t_token *tok, t_command *prev)
{
int i;
t_command *cmd;
@ -79,7 +79,7 @@ t_command *parser(t_token *tok, t_command *prev)
while(tok && tok->type != PIPE)
{
if (tok->type)
update_redir(cmd, tok);
update_redir(datas, cmd, tok);
else
cmd->argv[i++] = tok->value;
tok = tok->next;
@ -89,7 +89,7 @@ t_command *parser(t_token *tok, t_command *prev)
cmd->argv[0], cmd->fd[0], cmd->fd[1]);
cmd->argv[i] = NULL;
if (tok && tok->type == PIPE)
cmd->next = parser(tok->next, cmd);
cmd->next = parser(datas, tok->next, cmd);
return(cmd);
}
@ -150,7 +150,7 @@ int main(int argc, char **argv, char **envp)
halt(EXIT_FAILURE);
if (is_empty(line))
continue ;
caller(&datas, parser(lexer(&datas, line), NULL));
caller(&datas, parser(&datas, lexer(&datas, line), NULL));
add_history(line);
}
clear_history();

7
minishell.h

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */
/* Updated: 2022/05/05 12:34:17 by mea ### ########.fr */
/* Updated: 2022/05/05 14:18:56 by mea ### ########.fr */
/* */
/* ************************************************************************** */
@ -70,8 +70,6 @@ int command_call(t_datas *datas, t_command *cmd);
// ----------------------------------Parser.c
char *expend_str(t_datas *datas, char *line);
typedef enum e_type
{
WORD,
@ -90,7 +88,7 @@ typedef struct s_token
} t_token;
size_t count_arguments(t_token *tok);
void update_redir(t_command *cmd, t_token *tok);
void update_redir(t_datas *datas, t_command *cmd, t_token *tok);
// ----------------------------------Lexer.c
@ -115,5 +113,6 @@ int create_token(t_lexer *lex, char str[]);
int check_register(t_lexer *lex, char **line, char *tmp);
int replace_var(t_datas *datas, char **line, char *tmp, int tmp_i);
int check_state(t_lexer *lex, char **line);
char *expend_str(t_datas *datas, char *line);
#endif

10
parser.c

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 16:09:25 by narnaud #+# #+# */
/* Updated: 2022/05/05 13:02:33 by mea ### ########.fr */
/* Updated: 2022/05/05 14:30:11 by mea ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,7 +32,7 @@ char *expend_str(t_datas *datas, char *line)
return (tmp);
}
int push_heredoc(char *str)
int push_heredoc(t_datas *datas, char *str)
{
char *line;
int pip[2];
@ -43,7 +43,7 @@ int push_heredoc(char *str)
line = readline(">");
if (!ft_strncmp(line, str, ft_strlen(str) + 1))
break;
ft_putstr_fd(line, pip[1]);
ft_putstr_fd(expend_str(datas, line), pip[1]);
write(pip[1], "\n", 1);
}
close(pip[1]);
@ -64,7 +64,7 @@ size_t count_arguments(t_token *tok)
return (ret);
}
void update_redir(t_command *cmd, t_token *tok)
void update_redir(t_datas *datas, t_command *cmd, t_token *tok)
{
if (tok->type == OUT)
{
@ -88,7 +88,7 @@ void update_redir(t_command *cmd, t_token *tok)
{
if (cmd->fd[0])
close(cmd->fd[0]);
cmd->fd[0] = push_heredoc(tok->value);
cmd->fd[0] = push_heredoc(datas, tok->value);
}
}

Loading…
Cancel
Save