norme en cours...
This commit is contained in:
Submodule minishell_tests updated: 863e48a4fa...c2e0c0bdcb
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/15 00:20:47 by lperrey ### ########.fr */
|
/* Updated: 2021/12/20 15:51:18 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -16,19 +16,24 @@ t_list *expand_token(char *content);
|
|||||||
char *rejoin_after_expand(t_list *expand_lst);
|
char *rejoin_after_expand(t_list *expand_lst);
|
||||||
int new_token_for_each_field(char **fields, t_token *t);
|
int new_token_for_each_field(char **fields, t_token *t);
|
||||||
|
|
||||||
// 1 - chaque bout dans un element d'une t_list
|
/*
|
||||||
// (telle quelle si non expand, ou VARIABLE de env)
|
* 1 - chaque bout dans un element d'une t_list
|
||||||
// 2 - strjoin() le tout
|
* (telle quelle si non expand, ou VARIABLE de env)
|
||||||
// 3 - split avec un ft_strplit() modifié (ne splitant pas dans les quotes)
|
* 2 - strjoin() le tout
|
||||||
// 4 - quotes removal, ft_strdup_quotes() le tableau split
|
* 3 - split avec un ft_strplit() modifié (ne splitant pas dans les quotes)
|
||||||
// 5 - creer un token T_WORD pour chaque *string du **split_arr
|
* 4 - quotes removal, ft_strdup_quotes() le tableau split
|
||||||
// (ft_lstadd_front() sur le token original, puis set le token orignal à :
|
* 5 - creer un token T_WORD pour chaque *string du **split_arr
|
||||||
// t->id = 0 ; free(t->content) ; t->content = NULL ; pour qu'il soit ignoré sur la suite du parsing)
|
* (ft_lstadd_front() sur le token original, puis set le token orignal à :
|
||||||
|
* t->id = 0 ;
|
||||||
|
* free(t->content) ;
|
||||||
|
* t->content = NULL ;
|
||||||
|
* pour qu'il soit ignoré sur la suite du parsing)
|
||||||
|
*/
|
||||||
|
|
||||||
int expansions(t_token *t, t_cmd **pipeline)
|
int expansions(t_token *t, t_cmd **pipeline)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
t_token *next_token;
|
t_token *next_token;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (t)
|
while (t)
|
||||||
@@ -56,26 +61,21 @@ int token_expansions(t_token *t)
|
|||||||
void *tmp;
|
void *tmp;
|
||||||
char **tmp_split;
|
char **tmp_split;
|
||||||
|
|
||||||
// 1
|
tmp = (t_list *)expand_token(t->content);
|
||||||
tmp = (t_list*)expand_token(t->content);
|
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
return (0);
|
return (0);
|
||||||
// 2
|
tmp = (char *)rejoin_after_expand(tmp);
|
||||||
tmp = (char*)rejoin_after_expand(tmp);
|
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
return (0);
|
return (0);
|
||||||
// 3
|
|
||||||
tmp_split = ft_split_quotes(tmp, ' ');
|
tmp_split = ft_split_quotes(tmp, ' ');
|
||||||
free(tmp);
|
free(tmp);
|
||||||
if (!tmp_split)
|
if (!tmp_split)
|
||||||
return (0);
|
return (0);
|
||||||
// 4
|
|
||||||
tmp = tmp_split;
|
tmp = tmp_split;
|
||||||
tmp_split = ft_dup_2d_arr(tmp_split, (t_dup_f)ft_strdup_quotes);
|
tmp_split = ft_dup_2d_arr(tmp_split, (t_dup_f)ft_strdup_quotes);
|
||||||
ft_free_2d_arr(tmp);
|
ft_free_2d_arr(tmp);
|
||||||
if (!tmp_split)
|
if (!tmp_split)
|
||||||
return (0);
|
return (0);
|
||||||
// 5
|
|
||||||
if (!new_token_for_each_field(tmp_split, t))
|
if (!new_token_for_each_field(tmp_split, t))
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
|
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/20 14:53:12 by hulamy ### ########.fr */
|
/* Updated: 2021/12/20 15:25:16 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
int here_doc(char *delimiter);
|
int here_doc(char *delimiter);
|
||||||
|
|
||||||
static int redirect_cmd_less(t_token *t, t_cmd *cmd);
|
static int redirect_cmd_input(t_token *t, t_cmd *cmd);
|
||||||
static int redirect_cmd_dless(t_token *t, t_cmd *cmd);
|
static int redirect_cmd_heredoc(t_token *t, t_cmd *cmd);
|
||||||
static int redirect_cmd_output(t_token *t, t_cmd *cmd);
|
static int redirect_cmd_output(t_token *t, t_cmd *cmd);
|
||||||
static int expand_redirection(t_token *t);
|
static int expand_redirection(t_token *t);
|
||||||
|
|
||||||
@@ -30,9 +30,9 @@ int redirections(t_token *t, t_cmd **pipeline)
|
|||||||
i++;
|
i++;
|
||||||
if (!pipeline[i]->error)
|
if (!pipeline[i]->error)
|
||||||
{
|
{
|
||||||
if (t->id == '<' && !redirect_cmd_less(t, pipeline[i]))
|
if (t->id == '<' && !redirect_cmd_input(t, pipeline[i]))
|
||||||
return (0);
|
return (0);
|
||||||
else if (t->id == T_DLESS && !redirect_cmd_dless(t, pipeline[i]))
|
else if (t->id == T_DLESS && !redirect_cmd_heredoc(t, pipeline[i]))
|
||||||
return (0);
|
return (0);
|
||||||
else if (t->id == '>' || t->id == T_DGREAT)
|
else if (t->id == '>' || t->id == T_DGREAT)
|
||||||
{
|
{
|
||||||
@@ -45,46 +45,40 @@ int redirections(t_token *t, t_cmd **pipeline)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int redirect_cmd_less(t_token *t, t_cmd *cmd)
|
static int redirect_cmd_input(t_token *t, t_cmd *cmd)
|
||||||
{
|
{
|
||||||
if (cmd->fd_in != STDIN_FILENO)
|
if (cmd->fd_in != STDIN_FILENO)
|
||||||
if (close(cmd->fd_in) == -1)
|
if (close(cmd->fd_in) == -1)
|
||||||
perror("close()");
|
perror("close()");
|
||||||
if (t->id == '<')
|
if (!expand_redirection(t))
|
||||||
{
|
{
|
||||||
if (!expand_redirection(t))
|
cmd->error = EXIT_REDIRECTION;
|
||||||
{
|
return (1);
|
||||||
cmd->error = EXIT_REDIRECTION;
|
}
|
||||||
return (1);
|
cmd->fd_in = open(t->next->content, O_RDONLY);
|
||||||
}
|
if (cmd->fd_in == -1)
|
||||||
cmd->fd_in = open(t->next->content, O_RDONLY);
|
{
|
||||||
if (cmd->fd_in == -1)
|
shell_perror(t->next->content, ": ", "", 0);
|
||||||
{
|
cmd->error = EXIT_REDIRECTION;
|
||||||
shell_perror(t->next->content, ": ", "", 0);
|
|
||||||
cmd->error = EXIT_REDIRECTION;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int redirect_cmd_dless(t_token *t, t_cmd *cmd)
|
static int redirect_cmd_heredoc(t_token *t, t_cmd *cmd)
|
||||||
{
|
{
|
||||||
if (cmd->fd_in != STDIN_FILENO)
|
if (cmd->fd_in != STDIN_FILENO)
|
||||||
if (close(cmd->fd_in) == -1)
|
if (close(cmd->fd_in) == -1)
|
||||||
perror("close()");
|
perror("close()");
|
||||||
else if (t->id == T_DLESS)
|
cmd->fd_in = here_doc(t->next->content);
|
||||||
|
if (cmd->fd_in == -1)
|
||||||
{
|
{
|
||||||
cmd->fd_in = here_doc(t->next->content);
|
shell_error("heredoc error", ": ", "", 0);
|
||||||
if (cmd->fd_in == -1)
|
cmd->error = EXIT_REDIRECTION;
|
||||||
{
|
}
|
||||||
shell_error("heredoc error", ": ", "", 0);
|
else if (cmd->fd_in > EXIT_SIGNAL)
|
||||||
cmd->error = EXIT_REDIRECTION;
|
{
|
||||||
}
|
cmd->fd_in = 0;
|
||||||
else if (cmd->fd_in > EXIT_SIGNAL)
|
return (0);
|
||||||
{
|
|
||||||
cmd->fd_in = 0;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user