ft_printfd_fd -> fprintf

This commit is contained in:
2024-04-18 17:57:17 +02:00
parent be46825893
commit 9053276342
11 changed files with 49 additions and 49 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */ /* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */
/* Updated: 2024/04/02 00:43:31 by tomoron ### ########.fr */ /* Updated: 2024/04/18 17:56:04 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@ int cd(t_token *args)
if (args->next && args->next->next) if (args->next && args->next->next)
{ {
ft_printf_fd(2, "minishell: cd: too many arguments\n"); fprintf(stderr, "minishell: cd: too many arguments\n");
g_return_code = 1; g_return_code = 1;
return (1); return (1);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
/* Updated: 2024/04/17 18:29:30 by tomoron ### ########.fr */ /* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -77,7 +77,7 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
perror("minishell: pipe"); perror("minishell: pipe");
ft_exit(msh, 1); ft_exit(msh, 1);
} }
ft_printf_fd(2, "pipe: msh->fds[%d][0]: %d, msh->fds[%d][1]: %d\n", i, msh->fds[i][0], i, msh->fds[i][1]); fprintf(stderr, "pipe: msh->fds[%d][0]: %d, msh->fds[%d][1]: %d\n", i, msh->fds[i][0], i, msh->fds[i][1]);
} }
pid = fork(); pid = fork();
if (pid == -1) if (pid == -1)
@ -161,7 +161,7 @@ void exec_commands(t_msh *msh)
while (i < cmd_count) while (i < cmd_count)
{ {
get_redirections(msh, msh->cmds); get_redirections(msh, msh->cmds);
ft_printf_fd(2, "command: %s, in_type: %d, out_type: %d\n", msh->cmds->value, msh->in_type, msh->out_type); fprintf(stderr, "command: %s, in_type: %d, out_type: %d\n", msh->cmds->value, msh->in_type, msh->out_type);
exec_command(msh, i, cmd_count); exec_command(msh, i, cmd_count);
free(msh->fds[i]); free(msh->fds[i]);
i++; i++;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */ /* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */
/* Updated: 2024/04/13 12:58:01 by tomoron ### ########.fr */ /* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,8 +24,8 @@ void get_here_doc_input(t_msh *msh, char *eof)
line = readline("> "); line = readline("> ");
if (!line) if (!line)
{ {
ft_printf_fd(2, "\nminishell: warning: here-document delimited by"); fprintf(stderr, "\nminishell: warning: here-document delimited by");
ft_printf_fd(2, " end-of-file, wanted %s", eof); fprintf(stderr, " end-of-file, wanted %s", eof);
break ; break ;
} }
if (line && !ft_strncmp(line, eof, ft_strlen(eof))) if (line && !ft_strncmp(line, eof, ft_strlen(eof)))

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
/* Updated: 2024/04/18 17:22:28 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,15 +16,15 @@ void redirect_input(t_msh *msh, int i)
{ {
if (msh->in_type != PIPE) if (msh->in_type != PIPE)
{ {
ft_printf_fd(2, "redirecting input\n"); fprintf(stderr, "redirecting input\n");
if (dup2(msh->in_fd, 0) < 0) if (dup2(msh->in_fd, 0) < 0)
ft_exit(msh, 1); ft_exit(msh, 1);
close(msh->in_fd); close(msh->in_fd);
} }
else else
{ {
ft_printf_fd(2, "redirecting pipe input\n"); fprintf(stderr, "redirecting pipe input\n");
ft_printf_fd(2, "input of cmd %d: 0 -> %d\n", i, msh->fds[i - 1][0]); fprintf(stderr, "input of cmd %d: 0 -> %d\n", i, msh->fds[i - 1][0]);
if (dup2(msh->fds[i - 1][0], 0) < 0) if (dup2(msh->fds[i - 1][0], 0) < 0)
{ {
perror("dup2"); //debug perror("dup2"); //debug
@ -50,7 +50,7 @@ void open_input_file(t_msh *msh, t_cmd **cur_token)
free_token(filename); free_token(filename);
if (msh->in_fd == -1 && !g_return_code) if (msh->in_fd == -1 && !g_return_code)
{ {
ft_printf_fd(2, "minishell: %s: ", (*cur_token)->next->value); fprintf(stderr, "minishell: %s: ", (*cur_token)->next->value);
perror(""); perror("");
g_return_code = 1; g_return_code = 1;
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 17:31:53 by marde-vr #+# #+# */ /* Created: 2024/03/05 17:31:53 by marde-vr #+# #+# */
/* Updated: 2024/03/05 17:35:39 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,9 +16,9 @@ int is_fd_open(int fd)
{ {
if (fcntl(fd, F_GETFL) == -1) if (fcntl(fd, F_GETFL) == -1)
{ {
ft_printf_fd(2, "%d:closed\n", fd); fprintf(stderr, "%d:closed\n", fd);
return (0); return (0);
} }
ft_printf_fd(2, "%d:open\n", fd); fprintf(stderr, "%d:open\n", fd);
return (1); return (1);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */ /* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */
/* Updated: 2024/04/18 17:23:18 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,18 +17,18 @@ void redirect_output(t_msh *msh, int i)
{ {
if (msh->out_type != PIPE) if (msh->out_type != PIPE)
{ {
ft_printf_fd(2, "redirecting output\n"); fprintf(stderr, "redirecting output\n");
if (dup2(msh->out_fd, 1) < 0) if (dup2(msh->out_fd, 1) < 0)
ft_exit(msh, 1); ft_exit(msh, 1);
} }
else else
{ {
ft_printf_fd(2, "redirecting pipe output\n"); fprintf(stderr, "redirecting pipe output\n");
//sleep(1); //sleep(1);
if (dup2(msh->fds[i][1], 1) < 0) if (dup2(msh->fds[i][1], 1) < 0)
{ {
perror("dup2"); perror("dup2");
ft_printf_fd(2, "exiting\n"); fprintf(stderr, "exiting\n");
//ft_exit(msh, 1); //ft_exit(msh, 1);
} }
} }
@ -68,11 +68,11 @@ void get_out_type(t_msh *msh, t_cmd *cmds)
cur_cmd = cur_cmd->next; cur_cmd = cur_cmd->next;
while (cur_cmd && cur_cmd->next && !is_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE) while (cur_cmd && cur_cmd->next && !is_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE)
{ {
ft_printf_fd(2, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type); fprintf(stderr, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type);
cur_cmd = cur_cmd->next; cur_cmd = cur_cmd->next;
} }
if (cur_cmd) if (cur_cmd)
ft_printf_fd(2, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type); fprintf(stderr, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type);
if (cur_cmd->cmd_type == CMD || cur_cmd->cmd_type == PAREN) if (cur_cmd->cmd_type == CMD || cur_cmd->cmd_type == PAREN)
msh->out_type = 0; msh->out_type = 0;
else if(cur_cmd && is_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE) else if(cur_cmd && is_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE)

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */ /* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */
/* Updated: 2024/04/03 15:00:00 by tomoron ### ########.fr */ /* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -130,14 +130,14 @@ void print_syntax_error_bonus(t_cmd *cmd)
{ {
if (cmd->cmd_type == CMD || cmd->cmd_type == PAREN) if (cmd->cmd_type == CMD || cmd->cmd_type == PAREN)
return ; return ;
ft_printf_fd(2, "minishell : syntax error near unexpected token `"); fprintf(stderr, "minishell : syntax error near unexpected token `");
if (cmd->cmd_type == AND) if (cmd->cmd_type == AND)
ft_printf_fd(2, "&&"); fprintf(stderr, "&&");
if (cmd->cmd_type == OR) if (cmd->cmd_type == OR)
ft_printf_fd(2, "||"); fprintf(stderr, "||");
if (cmd->cmd_type == PIPE) if (cmd->cmd_type == PIPE)
ft_printf_fd(2, "|"); fprintf(stderr, "|");
ft_printf_fd(2, "'\n"); fprintf(stderr, "'\n");
} }
int check_tokens_syntax(t_cmd *cmd, t_cmd *last) int check_tokens_syntax(t_cmd *cmd, t_cmd *last)

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */ /* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */
/* Updated: 2024/04/03 15:46:04 by tomoron ### ########.fr */ /* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -90,7 +90,7 @@ void get_cmd_path(t_msh *msh)
get_path(msh, &found); get_path(msh, &found);
if (!found) if (!found)
{ {
ft_printf_fd(2, "%s: command not found\n", msh->tokens->value); fprintf(stderr, "%s: command not found\n", msh->tokens->value);
free(msh->tokens->value); free(msh->tokens->value);
msh->tokens->value = 0; msh->tokens->value = 0;
g_return_code = 127; g_return_code = 127;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
/* Updated: 2024/04/18 17:37:19 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,23 +18,23 @@ void close_pipe_fds(t_msh *msh, int i)
{ {
if (msh->fds[i - 1][0] > 2) if (msh->fds[i - 1][0] > 2)
{ {
ft_printf_fd(2, "closing fd %d in child\n", msh->fds[i-1][0]); fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][0]);
close(msh->fds[i - 1][0]); close(msh->fds[i - 1][0]);
} }
if (msh->fds[i - 1][1] > 2) if (msh->fds[i - 1][1] > 2)
{ {
ft_printf_fd(2, "closing fd %d in child\n", msh->fds[i-1][1]); fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][1]);
close(msh->fds[i - 1][1]); close(msh->fds[i - 1][1]);
} }
} }
if (msh->fds[i][0] > 2) if (msh->fds[i][0] > 2)
{ {
ft_printf_fd(2, "closing fd %d in child\n", msh->fds[i][0]); fprintf(stderr, "closing fd %d in child\n", msh->fds[i][0]);
close(msh->fds[i][0]); close(msh->fds[i][0]);
} }
if (msh->fds[i][1] > 2) if (msh->fds[i][1] > 2)
{ {
ft_printf_fd(2, "closing fd %d in child\n", msh->fds[i][1]); fprintf(stderr, "closing fd %d in child\n", msh->fds[i][1]);
close(msh->fds[i][1]); close(msh->fds[i][1]);
} }
} }
@ -55,7 +55,7 @@ void execute_command(t_msh *msh, char **cmd_args)
env = env_to_char_tab(msh->env); env = env_to_char_tab(msh->env);
if(env) if(env)
{ {
ft_printf_fd(2, "execveing %s\n", msh->tokens->value); fprintf(stderr, "execveing %s\n", msh->tokens->value);
execve(msh->tokens->value, cmd_args, env); execve(msh->tokens->value, cmd_args, env);
} }
ft_free_str_arr(env); ft_free_str_arr(env);
@ -71,7 +71,7 @@ void child(t_msh *msh, char **cmd_args, int i)
if (msh->out_type == PIPE || msh->out_type == RED_O if (msh->out_type == PIPE || msh->out_type == RED_O
|| msh->out_type == RED_O_APP) || msh->out_type == RED_O_APP)
redirect_output(msh, i); redirect_output(msh, i);
ft_printf_fd(2, "closing fds\n"); fprintf(stderr, "closing fds\n");
close_pipe_fds(msh, i); close_pipe_fds(msh, i);
execute_command(msh, cmd_args); execute_command(msh, cmd_args);
close(0); close(0);
@ -89,12 +89,12 @@ void parent(t_msh *msh, int i, int cmd_count)
{ {
if (msh->fds[i - 1][0] > 2) if (msh->fds[i - 1][0] > 2)
{ {
ft_printf_fd(2, "closing fd %d in parent\n", msh->fds[i - 1][0]); fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][0]);
close(msh->fds[i - 1][0]); close(msh->fds[i - 1][0]);
} }
if (msh->fds[i - 1][1] > 2) if (msh->fds[i - 1][1] > 2)
{ {
ft_printf_fd(2, "closing fd %d in parent\n", msh->fds[i - 1][1]); fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][1]);
close(msh->fds[i - 1][1]); close(msh->fds[i - 1][1]);
} }
} }
@ -102,23 +102,23 @@ void parent(t_msh *msh, int i, int cmd_count)
{ {
if (msh->fds[i][0] > 2) if (msh->fds[i][0] > 2)
{ {
ft_printf_fd(2, "closing fd %d in parent\n", msh->fds[i][0]); fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][0]);
close(msh->fds[i][0]); close(msh->fds[i][0]);
} }
if (msh->fds[i][1] > 2) if (msh->fds[i][1] > 2)
{ {
ft_printf_fd(2, "closing fd %d in parent\n", msh->fds[i][1]); fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][1]);
close(msh->fds[i][1]); close(msh->fds[i][1]);
} }
} }
if (msh->in_fd > 2) if (msh->in_fd > 2)
{ {
ft_printf_fd(2, "closing in_fd %d in parent\n", msh->in_fd); fprintf(stderr, "closing in_fd %d in parent\n", msh->in_fd);
close(msh->in_fd); close(msh->in_fd);
} }
if (msh->out_fd > 2) if (msh->out_fd > 2)
{ {
ft_printf_fd(2, "closing in_fd %d in parent\n", msh->out_fd); fprintf(stderr, "closing in_fd %d in parent\n", msh->out_fd);
close(msh->out_fd); close(msh->out_fd);
} }
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */ /* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
/* Updated: 2024/04/14 11:41:06 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -60,7 +60,7 @@ int set_echoctl(int value)
//ft_printf("echoctl value : %d\n",value); //ft_printf("echoctl value : %d\n",value);
if (tcgetattr(1, &t_p)) if (tcgetattr(1, &t_p))
{ {
ft_printf_fd(2, "minishell: an error occured while getting the local fl\ fprintf(stderr, "minishell: an error occured while getting the local fl\
ags\n"); ags\n");
return (1); return (1);
} }
@ -73,7 +73,7 @@ ags\n");
t_p.c_lflag = t_p.c_lflag & (~ECHOCTL); t_p.c_lflag = t_p.c_lflag & (~ECHOCTL);
if (tcsetattr(1, TCSANOW, &t_p)) if (tcsetattr(1, TCSANOW, &t_p))
{ {
ft_printf_fd(2, "minishell: an error occured while setting the local fl\ fprintf(stderr, "minishell: an error occured while setting the local fl\
ags\n"); ags\n");
return (1); return (1);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
/* Updated: 2024/04/14 11:29:02 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -68,7 +68,7 @@ int file_access(t_msh *msh, int *found)
if (fd != -1) if (fd != -1)
{ {
close(fd); close(fd);
ft_printf_fd(2, "minishell: %s: Is a directory\n", msh->tokens->value); fprintf(stderr, "minishell: %s: Is a directory\n", msh->tokens->value);
g_return_code = 126; g_return_code = 126;
return (0); return (0);
} }
@ -76,7 +76,7 @@ int file_access(t_msh *msh, int *found)
*found = 1; *found = 1;
else else
{ {
ft_printf_fd(2, "minishell: %s: ", msh->tokens->value); fprintf(stderr, "minishell: %s: ", msh->tokens->value);
perror(""); perror("");
g_return_code = 127; g_return_code = 127;
if (access(msh->tokens->value, F_OK) != -1) if (access(msh->tokens->value, F_OK) != -1)