resolve merge conflict small changes in heredoc
This commit is contained in:
@@ -1,189 +0,0 @@
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int is_redirection(enum e_token_id id)
|
||||
{
|
||||
if (id == T_LESS) // <
|
||||
return (1);
|
||||
else if (id == T_GREAT) // >
|
||||
return (1);
|
||||
else if (id == T_DLESS) // <<
|
||||
return (1);
|
||||
else if (id == T_DGREAT) // >>
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
// count nbr word in cmd, minus redirection and heredoc
|
||||
int next_cmd(t_token *token)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (token && token->id != T_PIPE)
|
||||
{
|
||||
if (is_redirection(token->id))
|
||||
i--;
|
||||
else
|
||||
i++;
|
||||
token = token->next;
|
||||
}
|
||||
if (token && token->id == T_PIPE)
|
||||
token = token->next;
|
||||
return (i);
|
||||
}
|
||||
|
||||
void handle_argv(t_token *token, t_cmd **cmd, size_t cmd_nbr)
|
||||
{
|
||||
int argc;
|
||||
int j;
|
||||
int i;
|
||||
int redirection;
|
||||
|
||||
i = 0;
|
||||
while (cmd_nbr)
|
||||
{
|
||||
argc = next_cmd(token);
|
||||
cmd[i]->argv = calloc(argc + 1, sizeof(char *));
|
||||
cmd[i]->argv[argc] = NULL;
|
||||
j = 0;
|
||||
redirection = is_redirection(token->id);
|
||||
while (token && token->id != T_PIPE)
|
||||
{
|
||||
if (!redirection && token->id == T_WORD)
|
||||
{
|
||||
cmd[i]->argv[j] = ft_strdup(token->content);
|
||||
j++;
|
||||
}
|
||||
redirection = is_redirection(token->id);
|
||||
token = token->next;
|
||||
}
|
||||
if (token && token->id == T_PIPE)
|
||||
token = token->next;
|
||||
cmd_nbr--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int fill_builtin(t_cmd *cmd, int (*builtin)(int, char **, t_all *))
|
||||
{
|
||||
cmd->builtin_command = &builtin;
|
||||
return (1);
|
||||
}
|
||||
|
||||
int handle_builtin(t_cmd *cmd)
|
||||
{ // Il faut penser à comparer un char de plus (\0 inclus)
|
||||
if (!ft_strncmp(cmd->argv[0], "echo", 4))
|
||||
return (fill_builtin(cmd, &builtin_echo));
|
||||
// else if (!ft_strncmp(cmd->argv[0], "cd", 2))
|
||||
// return (fill_builtin(cmd, &builtin_cd));
|
||||
// else if (!ft_strncmp(cmd->argv[0], "pwd", 3))
|
||||
// return (fill_builtin(cmd, &builtin_pwd));
|
||||
// else if (!ft_strncmp(cmd->argv[0], "export", 6))
|
||||
// return (fill_builtin(cmd, &builtin_export));
|
||||
// else if (!ft_strncmp(cmd->argv[0], "unset", 5))
|
||||
// return (fill_builtin(cmd, &builtin_unset));
|
||||
else if (!ft_strncmp(cmd->argv[0], "env", 3))
|
||||
return (fill_builtin(cmd, &builtin_env));
|
||||
else if (!ft_strncmp(cmd->argv[0], "exit", 4))
|
||||
return (fill_builtin(cmd, &builtin_exit));
|
||||
return (0);
|
||||
}
|
||||
|
||||
void find_path(char **argv, char **envp)
|
||||
{
|
||||
int i;
|
||||
char **path;
|
||||
char *cmd;
|
||||
|
||||
i = 0;
|
||||
while (envp[i] && ft_strncmp(envp[i], "PATH=", 5))
|
||||
i++;
|
||||
path = ft_split(envp[i] + 5, ':'); // 5 = lentgh of "PATH="
|
||||
i = -1;
|
||||
while (*path && i != 0)
|
||||
{
|
||||
cmd = ft_strjoin(path[0], "/");
|
||||
cmd = ft_strjoin(cmd, argv[0]);
|
||||
i = access(cmd, X_OK);
|
||||
path++;
|
||||
}
|
||||
if (!(*path))
|
||||
exit(0); // gerer erreur
|
||||
argv[0] = cmd;
|
||||
}
|
||||
|
||||
void handle_path(t_cmd **cmd_arr, char **envp)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (cmd_arr[i])
|
||||
{
|
||||
if (!handle_builtin(cmd_arr[i]))
|
||||
find_path(cmd_arr[i]->argv, envp);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void fd_redirection(t_token *token, t_cmd *cmd)
|
||||
{
|
||||
int flag;
|
||||
|
||||
if (token->id == T_LESS) // '<'
|
||||
{
|
||||
flag = O_RDONLY | O_CREAT; // O_CREAT ? Pourquoi donc ?
|
||||
if (cmd->fd_in != 0)
|
||||
close(cmd->fd_in);
|
||||
cmd->fd_in = open(token->next->content, flag);
|
||||
}
|
||||
else if (token->id == T_GREAT) // '>'
|
||||
{
|
||||
flag = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
cmd->fd_out = open(token->next->content, flag, S_IRWXU);
|
||||
}
|
||||
else if (token->id == T_DGREAT) // '>>'
|
||||
{
|
||||
flag = O_WRONLY | O_CREAT | O_APPEND;
|
||||
cmd->fd_out = open(token->next->content, flag, S_IRWXU);
|
||||
}
|
||||
}
|
||||
|
||||
void fd_heredoc(t_token *token, t_cmd *cmd)
|
||||
{
|
||||
(void)token;
|
||||
(void)cmd;
|
||||
}
|
||||
|
||||
void handle_fd(t_token *token, t_cmd **cmd_arr)
|
||||
{
|
||||
int *pipes_fd;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (cmd_arr[i])
|
||||
{
|
||||
cmd_arr[i]->fd_out = 1;
|
||||
while (token && token->id != T_PIPE)
|
||||
{
|
||||
if (token->id == T_DGREAT) // '<<'
|
||||
fd_heredoc(token, cmd_arr[i]);
|
||||
else
|
||||
fd_redirection(token, cmd_arr[i]);
|
||||
token = token->next;
|
||||
}
|
||||
if (token && token->id == T_PIPE)
|
||||
{
|
||||
token = token->next;
|
||||
pipes_fd = calloc(2, sizeof(int));
|
||||
pipe(pipes_fd);
|
||||
if (cmd_arr[i]->fd_out == 1)
|
||||
cmd_arr[i]->fd_out = pipes_fd[1];
|
||||
else
|
||||
close(pipes_fd[1]);
|
||||
cmd_arr[i + 1]->fd_in = pipes_fd[0];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cmd_array.c :+: :+: :+: */
|
||||
/* create_pipeline.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/02 22:46:23 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/14 12:24:39 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/29 12:29:27 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -28,47 +28,47 @@ size_t count_pipes(t_token *t)
|
||||
return (count);
|
||||
}
|
||||
|
||||
t_cmd **cmd_array_alloc(size_t cmd_nbr)
|
||||
t_cmd **pipeline_alloc(size_t cmd_nbr)
|
||||
{
|
||||
t_cmd **cmd_arr;
|
||||
t_cmd **pipeline;
|
||||
size_t i;
|
||||
|
||||
cmd_arr = ft_calloc(cmd_nbr + 1, sizeof (void *));
|
||||
if (!cmd_arr)
|
||||
return (ft_retp_perror(NULL, "cmd_array_alloc()"));
|
||||
pipeline = ft_calloc(cmd_nbr + 1, sizeof (void *));
|
||||
if (!pipeline)
|
||||
return (ft_retp_perror(NULL, "pipeline_alloc()"));
|
||||
i = 0;
|
||||
while (i < cmd_nbr)
|
||||
{
|
||||
cmd_arr[i] = ft_calloc(1, sizeof (*cmd_arr[i]));
|
||||
if (!cmd_arr[i])
|
||||
pipeline[i] = ft_calloc(1, sizeof (*pipeline[i]));
|
||||
if (!pipeline[i])
|
||||
{
|
||||
ft_free_2d_arr(cmd_arr);
|
||||
return (ft_retp_perror(NULL, "cmd_array_alloc()"));
|
||||
ft_free_2d_arr(pipeline);
|
||||
return (ft_retp_perror(NULL, "pipeline_alloc()"));
|
||||
}
|
||||
cmd_arr[i]->fd_in = STDIN_FILENO;
|
||||
cmd_arr[i]->fd_out = STDOUT_FILENO;
|
||||
pipeline[i]->fd_in = STDIN_FILENO;
|
||||
pipeline[i]->fd_out = STDOUT_FILENO;
|
||||
i++;
|
||||
}
|
||||
return (cmd_arr);
|
||||
return (pipeline);
|
||||
}
|
||||
|
||||
int cmd_array_fill_argv(t_token *t, t_cmd **cmd_arr)
|
||||
int pipeline_fill_argv(t_token *t, t_cmd **pipeline)
|
||||
{
|
||||
size_t i;
|
||||
size_t arg_i;
|
||||
|
||||
i = 0;
|
||||
while (cmd_arr[i])
|
||||
while (pipeline[i])
|
||||
{
|
||||
cmd_arr[i]->argv = ft_calloc(cmd_words_count(t) + 1, sizeof (char *));
|
||||
if (!cmd_arr[i]->argv)
|
||||
return (ft_reti_perror(0, "cmd_array_fill_argv()"));
|
||||
pipeline[i]->argv = ft_calloc(cmd_words_count(t) + 1, sizeof (char *));
|
||||
if (!pipeline[i]->argv)
|
||||
return (ft_reti_perror(0, "pipeline_fill_argv()"));
|
||||
arg_i = 0;
|
||||
while (t && t->id != '|')
|
||||
{
|
||||
if (t->id == T_WORD)
|
||||
{
|
||||
cmd_arr[i]->argv[arg_i++] = t->content;
|
||||
pipeline[i]->argv[arg_i++] = t->content;
|
||||
t->content = NULL;
|
||||
}
|
||||
t = t->next;
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/11 21:04:41 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/26 21:54:42 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -14,13 +14,6 @@
|
||||
|
||||
t_list *ft_lstnew_generic(size_t lst_sizse, size_t content_size);
|
||||
|
||||
enum e_in_quote_state
|
||||
{
|
||||
NOT_IN = 0,
|
||||
IN_QUOTES = '\'',
|
||||
IN_DQUOTES = '\"'
|
||||
};
|
||||
|
||||
static t_list *ret_parameter_expansion(char *content, int *i);
|
||||
|
||||
t_list *expand_token(char *content)
|
||||
@@ -92,7 +85,7 @@ static t_list *ret_parameter_expansion(char *content, int *i)
|
||||
if (content[*i] == '?')
|
||||
{
|
||||
(*i)++;
|
||||
expand->content = ft_itoa(g_all->last_exit_status);
|
||||
expand->content = ft_itoa(get_last_exit_status());
|
||||
return (ft_retp_free(expand, tmp, free));
|
||||
}
|
||||
else if (content[*i] != '_' && !ft_isalpha(content[*i]))
|
||||
|
||||
@@ -6,19 +6,12 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/13 07:08:40 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/13 22:35:34 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/26 21:27:10 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
enum e_in_quote_state
|
||||
{
|
||||
NOT_IN = 0,
|
||||
IN_QUOTES = '\'',
|
||||
IN_DQUOTES = '\"'
|
||||
};
|
||||
|
||||
static size_t count_word(char const *s, char c);
|
||||
static char **alloc_words(char const *s, char c, char **str_arr,
|
||||
size_t words_count);
|
||||
|
||||
@@ -6,18 +6,12 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/13 04:35:06 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/14 06:01:45 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/26 21:27:05 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
enum e_in_quote_state
|
||||
{
|
||||
NOT_IN = 0,
|
||||
IN_QUOTES = '\'',
|
||||
IN_DQUOTES = '\"'
|
||||
};
|
||||
static int quote_state_change(int *quote_state, const char *s);
|
||||
|
||||
/* Duplicate a string minus the quoting characters ['] and ["]*/
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/07 04:33:04 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/30 13:46:46 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -55,8 +55,7 @@ static t_token *insert_tokens(t_token *t, t_token *insert_lst)
|
||||
t_token *insert_lst_last;
|
||||
|
||||
t->id = 0;
|
||||
free(t->content);
|
||||
t->content = NULL; // TODO : free_null()
|
||||
ft_free_null(&t->content);
|
||||
if (!insert_lst)
|
||||
return (t);
|
||||
|
||||
|
||||
@@ -6,19 +6,12 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/16 03:45:15 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/26 21:05:01 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
enum e_in_quote_state
|
||||
{
|
||||
NOT_IN = 0,
|
||||
IN_QUOTES = '\'',
|
||||
IN_DQUOTES = '\"'
|
||||
};
|
||||
|
||||
t_list *ft_lstnew_generic(size_t lst_sizse, size_t content_size);
|
||||
t_list *expand_token(char *content);
|
||||
char *rejoin_after_expand(t_list *expand_lst);
|
||||
|
||||
@@ -6,19 +6,12 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/18 22:35:07 by hulamy ### ########.fr */
|
||||
/* Updated: 2021/11/29 12:28:07 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
// HUGO WIP
|
||||
void handle_path(t_cmd **cmd_arr, char **envp);
|
||||
void find_path(char **argv, char **envp);
|
||||
int handle_builtin(t_cmd *cmd);
|
||||
int fill_builtin(t_cmd *cmd, int (*builtin)(int, char **, t_all *));
|
||||
// HUGO WIP
|
||||
|
||||
void save_redirections_words(t_token *t)
|
||||
{
|
||||
while (t)
|
||||
@@ -33,25 +26,25 @@ void save_redirections_words(t_token *t)
|
||||
}
|
||||
}
|
||||
|
||||
void print_cmd_array(t_cmd **cmd_arr)
|
||||
void print_pipeline(t_cmd **pipeline)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (cmd_arr[i])
|
||||
while (pipeline[i])
|
||||
{
|
||||
printf("CMD %i, fd_in=%i, fd_out=%i\n", i, cmd_arr[i]->fd_in, cmd_arr[i]->fd_out);
|
||||
printf("CMD %i, fd_in=%i, fd_out=%i\n", i, pipeline[i]->fd_in, pipeline[i]->fd_out);
|
||||
ft_putstr_fd(" |", 1);
|
||||
print_matrix(cmd_arr[i]->argv, "|\n |");
|
||||
print_matrix(pipeline[i]->argv, "|\n |");
|
||||
i++;
|
||||
if (cmd_arr[i])
|
||||
if (pipeline[i])
|
||||
ft_putstr_fd("----------------\n", 1);
|
||||
}
|
||||
}
|
||||
|
||||
t_cmd **parsing(t_token *token_list)
|
||||
{
|
||||
t_cmd **cmd_arr;
|
||||
t_cmd **pipeline;
|
||||
|
||||
if (!valid_syntax(token_list))
|
||||
return (NULL);
|
||||
@@ -74,20 +67,20 @@ t_cmd **parsing(t_token *token_list)
|
||||
//ft_lstprint((t_list *)token_list, 1);
|
||||
|
||||
// Struct CMD alloc
|
||||
cmd_arr = cmd_array_alloc(1 + count_pipes(token_list));
|
||||
if (!cmd_arr)
|
||||
pipeline = pipeline_alloc(1 + count_pipes(token_list));
|
||||
if (!pipeline)
|
||||
return (NULL);
|
||||
|
||||
// 2.9.1 - 3) Redirection
|
||||
if (!redirections(token_list, cmd_arr))
|
||||
return (ft_retp_free(NULL, &cmd_arr, (t_free_f)free_pipeline));
|
||||
if (!redirections(token_list, pipeline))
|
||||
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
|
||||
|
||||
// Struct CMD fill
|
||||
if (!cmd_array_fill_argv(token_list, cmd_arr))
|
||||
return (ft_retp_free(NULL, &cmd_arr, (t_free_f)free_pipeline));
|
||||
print_cmd_array(cmd_arr);
|
||||
if (!pipeline_fill_argv(token_list, pipeline))
|
||||
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
|
||||
print_pipeline(pipeline);
|
||||
|
||||
return (cmd_arr);
|
||||
return (pipeline);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/26 15:03:37 by hulamy ### ########.fr */
|
||||
/* Updated: 2021/12/02 15:32:56 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -29,23 +29,24 @@ int here_doc(char *delimiter)
|
||||
// Peut-être remplacer gnl() par readline() pour avoir une gestion correct
|
||||
// du terminal (actuellement l'affichage lors du changement de ligne est foireux).
|
||||
int here_doc;
|
||||
int ret;
|
||||
|
||||
here_doc = open(TMP_HERE_DOC, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
if (here_doc == -1)
|
||||
return (ft_reti_perror_io(-1, "open() ", TMP_HERE_DOC));
|
||||
delimiter = ft_strdup_quotes(delimiter);
|
||||
if (!delimiter)
|
||||
return (ft_reti_perror(-1, "ft_strdup_quotes()"));
|
||||
if (!here_doc_write(delimiter, here_doc))
|
||||
{
|
||||
free(delimiter);
|
||||
if (unlink(TMP_HERE_DOC) == -1)
|
||||
return (ft_reti_perror_io(-1, "unlink() ", TMP_HERE_DOC));
|
||||
return (-1);
|
||||
}
|
||||
here_doc = open(TMP_HERE_DOC, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
if (here_doc == -1)
|
||||
return (ft_reti_perror_io(-1, "open() ", TMP_HERE_DOC));
|
||||
ret = here_doc_write(delimiter, here_doc);
|
||||
free(delimiter);
|
||||
if (close(here_doc) == -1)
|
||||
ft_perror_io("close() ", TMP_HERE_DOC);
|
||||
if (ret != 0)
|
||||
{
|
||||
if (unlink(TMP_HERE_DOC) == -1)
|
||||
return (ft_reti_perror_io(ret, "unlink() ", TMP_HERE_DOC));
|
||||
return (ret);
|
||||
}
|
||||
here_doc = open(TMP_HERE_DOC, O_RDONLY);
|
||||
if (here_doc == -1)
|
||||
ft_perror_io("open() ", TMP_HERE_DOC);
|
||||
@@ -77,11 +78,12 @@ static int here_doc_write(char *delimiter, int doc_fd)
|
||||
{
|
||||
char *line;
|
||||
size_t line_count;
|
||||
struct sigaction signal_action;
|
||||
struct sigaction signal_action;
|
||||
|
||||
ft_bzero(&signal_action, sizeof(signal_action));
|
||||
signal_action.sa_handler = sigint_handler_heredoc;
|
||||
sigaction(SIGINT, &signal_action, NULL);
|
||||
switch_heredoc_sigint = 0;
|
||||
g_switch_heredoc_sigint = 0;
|
||||
rl_event_hook = void_func_return_readline;
|
||||
//rl_signal_event_hook = void_func_return_readline;
|
||||
line_count = 0;
|
||||
@@ -90,11 +92,8 @@ static int here_doc_write(char *delimiter, int doc_fd)
|
||||
line_count++;
|
||||
line = NULL;
|
||||
line = readline("> ");
|
||||
if (switch_heredoc_sigint == 1)
|
||||
{
|
||||
// todo : gerer le statut exit 130
|
||||
return (1);
|
||||
}
|
||||
if (g_switch_heredoc_sigint == 1)
|
||||
return (set_last_exit_status(EXIT_SIGNAL + SIGINT));
|
||||
if (!line)
|
||||
{ // TODO : error print wrapper
|
||||
ft_putstr_fd("minishell: ", 2);
|
||||
@@ -103,20 +102,20 @@ static int here_doc_write(char *delimiter, int doc_fd)
|
||||
ft_putstr_fd(" delimited by end-of-file (wanted `", 2);
|
||||
ft_putstr_fd(delimiter, 2);
|
||||
ft_putstr_fd("')\n", 2);
|
||||
return (1);
|
||||
return (-1);
|
||||
}
|
||||
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)
|
||||
return (ft_reti_perror_free(0, line, free, "write() "TMP_HERE_DOC));
|
||||
return (ft_reti_perror_free(-1, line, free, "write() "TMP_HERE_DOC));
|
||||
if (write(doc_fd, "\n", 1) == -1)
|
||||
return (ft_reti_perror_free(0, line, free, "write() "TMP_HERE_DOC));
|
||||
return (ft_reti_perror_free(-1, line, free, "write() "TMP_HERE_DOC));
|
||||
free(line);
|
||||
}
|
||||
free(line);
|
||||
signal_action.sa_handler = SIG_IGN;
|
||||
sigaction(SIGINT, &signal_action, NULL);
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/18 22:17:44 by hulamy ### ########.fr */
|
||||
/* Updated: 2021/11/29 12:39:05 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,23 +17,23 @@ int here_doc(char *delimiter);
|
||||
static int redirect_cmd_input(t_token *t, t_cmd *cmd);
|
||||
static int redirect_cmd_output(t_token *t, t_cmd *cmd);
|
||||
|
||||
int redirections(t_token *t, t_cmd **cmd_arr)
|
||||
int redirections(t_token *t, t_cmd **pipeline)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (t)
|
||||
{
|
||||
if (!cmd_arr[i]->error)
|
||||
if (!pipeline[i]->error)
|
||||
{
|
||||
if (t->id == '<' || t->id == T_DLESS)
|
||||
{
|
||||
if (!redirect_cmd_input(t, cmd_arr[i]))
|
||||
if (!redirect_cmd_input(t, pipeline[i]))
|
||||
return (0);
|
||||
}
|
||||
else if (t->id == '>' || t->id == T_DGREAT)
|
||||
{
|
||||
if (!redirect_cmd_output(t, cmd_arr[i]))
|
||||
if (!redirect_cmd_output(t, pipeline[i]))
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
@@ -60,14 +60,19 @@ 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->error = 42; // WIP error status
|
||||
cmd->error = EXIT_REDIRECTION;
|
||||
}
|
||||
}
|
||||
else if (t->id == T_DLESS)
|
||||
{
|
||||
cmd->fd_in = here_doc(t->next->content);
|
||||
if (cmd->fd_in == -1)
|
||||
return (ft_reti_print(0, "minishell: heredoc error\n", 2));
|
||||
{
|
||||
ft_putstr_fd("minishell: heredoc error\n", 2);
|
||||
cmd->error = EXIT_REDIRECTION;
|
||||
}
|
||||
else if (cmd->fd_in > EXIT_SIGNAL)
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@@ -93,7 +98,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->error = 42; // WIP error status
|
||||
cmd->error = EXIT_REDIRECTION;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user