|
@ -12,26 +12,6 @@ |
|
|
|
|
|
|
|
|
#include "minishell.h" |
|
|
#include "minishell.h" |
|
|
|
|
|
|
|
|
char *expend_str(t_datas *datas, char *line) |
|
|
|
|
|
{ |
|
|
|
|
|
char *tmp; |
|
|
|
|
|
int tmp_i; |
|
|
|
|
|
|
|
|
|
|
|
tmp = ft_calloc(1024, sizeof *tmp); |
|
|
|
|
|
if (!tmp) |
|
|
|
|
|
free(tmp); |
|
|
|
|
|
tmp_i = 0; |
|
|
|
|
|
while (*line) |
|
|
|
|
|
{ |
|
|
|
|
|
if (*line == '$') |
|
|
|
|
|
tmp_i = replace_var(datas, &line, tmp, tmp_i); |
|
|
|
|
|
tmp[tmp_i] = *line; |
|
|
|
|
|
line++; |
|
|
|
|
|
tmp_i++; |
|
|
|
|
|
} |
|
|
|
|
|
return (tmp); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int push_heredoc(t_datas *datas, char *str) |
|
|
int push_heredoc(t_datas *datas, char *str) |
|
|
{ |
|
|
{ |
|
|
char *line; |
|
|
char *line; |
|
@ -92,34 +72,34 @@ void update_redir(t_datas *datas, t_command *cmd, t_token *tok) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
t_token *parse_cmd(t_datas *datas, t_token *tok, t_command *cmd) |
|
|
|
|
|
{ |
|
|
|
|
|
t_token *prev_tok; |
|
|
|
|
|
|
|
|
|
|
|
if (tok->type) |
|
|
|
|
|
update_redir(datas, cmd, tok); |
|
|
|
|
|
else |
|
|
|
|
|
cmd->argv[cmd->argc++] = ft_strdup(tok->value); |
|
|
|
|
|
prev_tok = tok; |
|
|
|
|
|
tok = tok->next; |
|
|
|
|
|
free(prev_tok->value); |
|
|
|
|
|
free(prev_tok); |
|
|
|
|
|
return (tok); |
|
|
|
|
|
} |
|
|
t_command *parser(t_datas *datas, t_token *tok, t_command *prev) |
|
|
t_command *parser(t_datas *datas, t_token *tok, t_command *prev) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
|
|
|
t_command *cmd; |
|
|
t_command *cmd; |
|
|
t_token *prev_tok; |
|
|
|
|
|
|
|
|
|
|
|
if (!tok) |
|
|
if (!tok) |
|
|
return (NULL); |
|
|
return (NULL); |
|
|
cmd = ft_calloc(1, sizeof(t_command)); |
|
|
cmd = ft_calloc(1, sizeof(t_command)); |
|
|
if (prev) |
|
|
if (prev) |
|
|
cmd->prev = prev; |
|
|
cmd->prev = prev; |
|
|
i = 0; |
|
|
|
|
|
cmd->argv = ft_calloc(count_arguments(tok) + 1, sizeof(char *)); |
|
|
cmd->argv = ft_calloc(count_arguments(tok) + 1, sizeof(char *)); |
|
|
|
|
|
cmd->argc = 0; |
|
|
while(tok && tok->type != PIPE) |
|
|
while(tok && tok->type != PIPE) |
|
|
{ |
|
|
tok = parse_cmd(datas, tok, cmd); |
|
|
if (tok->type) |
|
|
cmd->argv[cmd->argc] = NULL; |
|
|
update_redir(datas, cmd, tok); |
|
|
|
|
|
else |
|
|
|
|
|
cmd->argv[i++] = ft_strdup(tok->value); |
|
|
|
|
|
prev_tok = tok; |
|
|
|
|
|
tok = tok->next; |
|
|
|
|
|
free(prev_tok->value); |
|
|
|
|
|
free(prev_tok); |
|
|
|
|
|
} |
|
|
|
|
|
if (DEBUG) |
|
|
|
|
|
printf("######\n->cmd : %s, in_fd : %d, out_fd : %d\n", \ |
|
|
|
|
|
cmd->argv[0], cmd->fd[0], cmd->fd[1]); |
|
|
|
|
|
cmd->argv[i] = NULL; |
|
|
|
|
|
if (tok && tok->type == PIPE) |
|
|
if (tok && tok->type == PIPE) |
|
|
{ |
|
|
{ |
|
|
cmd->next = parser(datas, tok->next, cmd); |
|
|
cmd->next = parser(datas, tok->next, cmd); |
|
|