merging conflicts
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
|
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/20 14:58:00 by hulamy ### ########.fr */
|
/* Updated: 2021/12/20 15:07:39 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
|
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/16 05:57:42 by lperrey ### ########.fr */
|
/* Updated: 2021/12/20 14:23:40 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -18,12 +18,15 @@ static t_builtin_f search_builtin(char *cmd_name);
|
|||||||
static int handle_access_error(char *file_name);
|
static int handle_access_error(char *file_name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
2.8.2 Exit Status for Commands
|
* 2.8.2 Exit Status for Commands
|
||||||
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
|
* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
|
||||||
#tag_18_08_02
|
* #tag_18_08_02
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO : faire des test sur la valeur de errno selon les cas (if directory, if pathname invalid, ...)
|
/*
|
||||||
|
* TODO : faire des test sur la valeur de errno selon les cas (if directory, if
|
||||||
|
* pathname invalid, ...)
|
||||||
|
*/
|
||||||
|
|
||||||
int cmd_find_access(t_cmd *cmd, char *path[])
|
int cmd_find_access(t_cmd *cmd, char *path[])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/20 14:57:48 by hulamy ### ########.fr */
|
/* Updated: 2021/12/20 15:07:31 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -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/16 03:03:27 by lperrey ### ########.fr */
|
/* Updated: 2021/12/20 14:47:04 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ t_list *expand_token(char *content)
|
|||||||
expand->next = content_copy(content, &i, "es_state);
|
expand->next = content_copy(content, &i, "es_state);
|
||||||
expand = expand->next;
|
expand = expand->next;
|
||||||
if (!expand)
|
if (!expand)
|
||||||
{//todo wrap
|
{
|
||||||
perror("expand_token() error");
|
perror("expand_token() error");
|
||||||
return (ft_lstclear(&head.next, free));
|
return (ft_lstclear(&head.next, free));
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ static char *env_var_expansion(char *content, int *i)
|
|||||||
{
|
{
|
||||||
char *expansion;
|
char *expansion;
|
||||||
|
|
||||||
(*i)++; // skip '$'
|
(*i)++;
|
||||||
if (content[*i] == '?')
|
if (content[*i] == '?')
|
||||||
{
|
{
|
||||||
(*i)++;
|
(*i)++;
|
||||||
@@ -112,7 +112,7 @@ static char *retrieve_var(char *content, int *i)
|
|||||||
char *tmp;
|
char *tmp;
|
||||||
int i_exp;
|
int i_exp;
|
||||||
|
|
||||||
expansion = ft_calloc(ft_strlen(&content[*i - 1]) + 1, 1); // *i - 1 for '$' skip
|
expansion = ft_calloc(ft_strlen(&content[*i - 1]) + 1, 1);
|
||||||
if (!expansion)
|
if (!expansion)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
i_exp = 0;
|
i_exp = 0;
|
||||||
|
|||||||
@@ -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/10 19:11:52 by lperrey ### ########.fr */
|
/* Updated: 2021/12/20 14:56:05 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ int new_token_for_each_field(char **fields, t_token *t)
|
|||||||
insert_lst->next = ft_lstnew_generic(sizeof(t_token), 0);
|
insert_lst->next = ft_lstnew_generic(sizeof(t_token), 0);
|
||||||
insert_lst = insert_lst->next;
|
insert_lst = insert_lst->next;
|
||||||
if (!insert_lst)
|
if (!insert_lst)
|
||||||
{//todo wrap
|
{
|
||||||
perror("insert_token_for_each_field() error");
|
perror("insert_token_for_each_field() error");
|
||||||
ft_free_2d_arr(fields);
|
ft_free_2d_arr(fields);
|
||||||
return ((int)ft_lstclear((t_list **)&head.next, NULL));
|
return ((int)ft_lstclear((t_list **)&head.next, NULL));
|
||||||
@@ -51,11 +51,8 @@ static void insert_tokens(t_token *t, t_token *insert_lst)
|
|||||||
ft_free_null(&t->content);
|
ft_free_null(&t->content);
|
||||||
if (!insert_lst)
|
if (!insert_lst)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
tmp = t->next;
|
tmp = t->next;
|
||||||
t->next = insert_lst;
|
t->next = insert_lst;
|
||||||
insert_lst_last = (t_token *)ft_lstlast((t_list *)insert_lst);
|
insert_lst_last = (t_token *)ft_lstlast((t_list *)insert_lst);
|
||||||
insert_lst_last->next = tmp;
|
insert_lst_last->next = tmp;
|
||||||
|
|
||||||
//return (insert_lst_last); // return inutile pour reusinage
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/11/07 04:03:02 by lperrey ### ########.fr */
|
/* Updated: 2021/12/20 14:55:03 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ char *rejoin_after_expand(t_list *expand_lst)
|
|||||||
{
|
{
|
||||||
result = ft_strjoinfree_s1(result, expand_lst->content);
|
result = ft_strjoinfree_s1(result, expand_lst->content);
|
||||||
if (!result)
|
if (!result)
|
||||||
{//todo wrap
|
{
|
||||||
perror("rejoin_after_expand() error");
|
perror("rejoin_after_expand() error");
|
||||||
return (ft_lstclear(&head, free));
|
return (ft_lstclear(&head, free));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/18 15:24:25 by lperrey ### ########.fr */
|
/* Updated: 2021/12/20 14:24:51 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ static int here_doc_write_interactive(char *delimiter, int doc_fd)
|
|||||||
return (set_last_exit_status(EXIT_SIGNAL + SIGINT));
|
return (set_last_exit_status(EXIT_SIGNAL + SIGINT));
|
||||||
if (!line)
|
if (!line)
|
||||||
return (shell_error(WARNING_EOF, delimiter, "')", 0));
|
return (shell_error(WARNING_EOF, delimiter, "')", 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.
|
if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0)
|
||||||
break ;
|
break ;
|
||||||
if (write(doc_fd, line, ft_strlen(line)) == -1)
|
if (write(doc_fd, line, ft_strlen(line)) == -1)
|
||||||
return (ft_reti_perror_free(-1, line, free, "write "TMP_HERE_DOC));
|
return (ft_reti_perror_free(-1, line, free, "write "TMP_HERE_DOC));
|
||||||
@@ -109,7 +109,7 @@ static int here_doc_write_script(char *delimiter, int doc_fd)
|
|||||||
ret = gnl(STDIN_FILENO, &line, 0);
|
ret = gnl(STDIN_FILENO, &line, 0);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
return (ft_reti_perror_free(-1, line, free, "gnl() STDIN"));
|
return (ft_reti_perror_free(-1, 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.
|
if (ft_strncmp(line, delimiter, ft_strlen(line) + 1) == 0)
|
||||||
break ;
|
break ;
|
||||||
if (write(doc_fd, line, ft_strlen(line)) == -1)
|
if (write(doc_fd, line, ft_strlen(line)) == -1)
|
||||||
return (ft_reti_perror_free(-1, line, free, "write "TMP_HERE_DOC));
|
return (ft_reti_perror_free(-1, line, free, "write "TMP_HERE_DOC));
|
||||||
|
|||||||
@@ -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/11 21:32:31 by lperrey ### ########.fr */
|
/* Updated: 2021/12/20 14:53:12 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
int here_doc(char *delimiter);
|
int here_doc(char *delimiter);
|
||||||
|
|
||||||
static int redirect_cmd_input(t_token *t, t_cmd *cmd);
|
static int redirect_cmd_less(t_token *t, t_cmd *cmd);
|
||||||
|
static int redirect_cmd_dless(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);
|
||||||
|
|
||||||
@@ -29,11 +30,10 @@ int redirections(t_token *t, t_cmd **pipeline)
|
|||||||
i++;
|
i++;
|
||||||
if (!pipeline[i]->error)
|
if (!pipeline[i]->error)
|
||||||
{
|
{
|
||||||
if (t->id == '<' || t->id == T_DLESS)
|
if (t->id == '<' && !redirect_cmd_less(t, pipeline[i]))
|
||||||
{
|
return (0);
|
||||||
if (!redirect_cmd_input(t, pipeline[i]))
|
else if (t->id == T_DLESS && !redirect_cmd_dless(t, pipeline[i]))
|
||||||
return (0);
|
return (0);
|
||||||
}
|
|
||||||
else if (t->id == '>' || t->id == T_DGREAT)
|
else if (t->id == '>' || t->id == T_DGREAT)
|
||||||
{
|
{
|
||||||
if (!redirect_cmd_output(t, pipeline[i]))
|
if (!redirect_cmd_output(t, pipeline[i]))
|
||||||
@@ -45,7 +45,7 @@ int redirections(t_token *t, t_cmd **pipeline)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int redirect_cmd_input(t_token *t, t_cmd *cmd)
|
static int redirect_cmd_less(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)
|
||||||
@@ -64,6 +64,14 @@ static int redirect_cmd_input(t_token *t, t_cmd *cmd)
|
|||||||
cmd->error = EXIT_REDIRECTION;
|
cmd->error = EXIT_REDIRECTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int redirect_cmd_dless(t_token *t, t_cmd *cmd)
|
||||||
|
{
|
||||||
|
if (cmd->fd_in != STDIN_FILENO)
|
||||||
|
if (close(cmd->fd_in) == -1)
|
||||||
|
perror("close()");
|
||||||
else if (t->id == T_DLESS)
|
else if (t->id == T_DLESS)
|
||||||
{
|
{
|
||||||
cmd->fd_in = here_doc(t->next->content);
|
cmd->fd_in = here_doc(t->next->content);
|
||||||
@@ -110,7 +118,7 @@ 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)
|
||||||
{
|
{
|
||||||
t_token *head;
|
t_token *head;
|
||||||
t_token *next_token;
|
t_token *next_token;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
@@ -126,7 +134,7 @@ static int expand_redirection(t_token *t)
|
|||||||
head->next = t->next;
|
head->next = t->next;
|
||||||
free(t);
|
free(t);
|
||||||
if (head->next)
|
if (head->next)
|
||||||
head->next->id = T_REDIRECTION_WORD; // Eventuellement a integrer dans token_expansions()
|
head->next->id = T_REDIRECTION_WORD;
|
||||||
if (ft_lstsize((t_list *)head->next) != 1)
|
if (ft_lstsize((t_list *)head->next) != 1)
|
||||||
{
|
{
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user