merge
This commit is contained in:
4
Makefile
4
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||||
# Updated: 2024/04/15 16:41:54 by tomoron ### ########.fr #
|
# Updated: 2024/04/15 18:58:21 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ all:
|
|||||||
$(NAME) : $(LIBFT) $(OBJS)
|
$(NAME) : $(LIBFT) $(OBJS)
|
||||||
@$(CC) $(FLAGS) $(OBJS) $(LIBFT) -lreadline -o $(NAME)
|
@$(CC) $(FLAGS) $(OBJS) $(LIBFT) -lreadline -o $(NAME)
|
||||||
@echo project ready
|
@echo project ready
|
||||||
@timeout 2 bash -c 'while :; do r=$$(echo "scale=2;($$RANDOM / 16384) + 0.01" | bc -l);g=$$(echo "scale=2;($$RANDOM / 16384) + 0.01" | bc -l); b=$$(echo "scale=2;($$RANDOM / 16384) + 0.01" | bc -l);xrandr --output "HDMI-1-2" --gamma $$r:$$g:$$b;sleep 0.05;done' || true && xrandr --output HDMI-1-2 --brightness 1&
|
@timeout 2 bash -c 'if [ "$$USER" == marde-vr ];then exit;fi;while :; do r=$$(echo "scale=2;($$RANDOM / 16384) + 0.01" | bc -l);g=$$(echo "scale=2;($$RANDOM / 16384) + 0.01" | bc -l); b=$$(echo "scale=2;($$RANDOM / 16384) + 0.01" | bc -l);xrandr --output "HDMI-1-2" --gamma $$r:$$g:$$b;sleep 0.05;done' || true && xrandr --output HDMI-1-2 --brightness 1&
|
||||||
|
|
||||||
$(LIBFT):
|
$(LIBFT):
|
||||||
@echo compiling libft...
|
@echo compiling libft...
|
||||||
|
@ -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/13 16:22:58 by babonnet ### ########.fr */
|
/* Updated: 2024/04/15 16:54:53 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -53,8 +53,8 @@ void exec_command_bonus(t_msh *msh, char *cmd_str)
|
|||||||
msh->tokens = parse_command(cmds->value, msh->env);
|
msh->tokens = parse_command(cmds->value, msh->env);
|
||||||
msh->cmds = cmds;
|
msh->cmds = cmds;
|
||||||
get_redirections(msh, cmds);
|
get_redirections(msh, cmds);
|
||||||
print_msh_struct(msh); // debug
|
//print_msh_struct(msh); // debug
|
||||||
print_parsed_token(msh->tokens); // debug
|
//print_parsed_token(msh->tokens); // debug
|
||||||
exec_commands(msh);
|
exec_commands(msh);
|
||||||
msh->in_fd = 0;
|
msh->in_fd = 0;
|
||||||
msh->out_fd = 0;
|
msh->out_fd = 0;
|
||||||
@ -71,13 +71,12 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
|
|||||||
|
|
||||||
if (i != cmd_count - 1)
|
if (i != cmd_count - 1)
|
||||||
{
|
{
|
||||||
printf("pipe\n");
|
|
||||||
if (pipe(msh->fds[i]) == -1)
|
if (pipe(msh->fds[i]) == -1)
|
||||||
{
|
{
|
||||||
perror("minishell: pipe");
|
perror("minishell: pipe");
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
}
|
}
|
||||||
ft_printf_fd(2, "msh->fds[%d][0]: %d, msh->fds[%d][1]: %d\n", i, msh->fds[i][0], i, msh->fds[i][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]);
|
||||||
}
|
}
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
@ -160,8 +159,8 @@ void exec_commands(t_msh *msh)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (i < cmd_count)
|
while (i < cmd_count)
|
||||||
{
|
{
|
||||||
if (i != 0)
|
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);
|
||||||
exec_command(msh, i, cmd_count);
|
exec_command(msh, i, cmd_count);
|
||||||
free(msh->fds[i]);
|
free(msh->fds[i]);
|
||||||
i++;
|
i++;
|
||||||
|
@ -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/13 15:58:27 by babonnet ### ########.fr */
|
/* Updated: 2024/04/15 17:13:30 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -59,8 +59,14 @@ void get_in_type(t_msh *msh, t_cmd *tokens)
|
|||||||
t_cmd *cur_token;
|
t_cmd *cur_token;
|
||||||
|
|
||||||
cur_token = tokens;
|
cur_token = tokens;
|
||||||
|
//if (cur_token->cmd_type == PIPE)
|
||||||
while (cur_token && (cur_token->cmd_type == CMD || cur_token->cmd_type == PAREN))
|
while (cur_token && (cur_token->cmd_type == CMD || cur_token->cmd_type == PAREN))
|
||||||
|
{
|
||||||
|
ft_printf_fd(2, "%s: %d\n", cur_token->value, cur_token->cmd_type);
|
||||||
cur_token = cur_token->next;
|
cur_token = cur_token->next;
|
||||||
|
}
|
||||||
|
if (cur_token)
|
||||||
|
ft_printf_fd(2, "%s: %d\n", cur_token->value, cur_token->cmd_type);
|
||||||
if (cur_token && (is_input_type(cur_token) || cur_token->cmd_type == PIPE))
|
if (cur_token && (is_input_type(cur_token) || cur_token->cmd_type == PIPE))
|
||||||
{
|
{
|
||||||
msh->in_type = cur_token->cmd_type;
|
msh->in_type = cur_token->cmd_type;
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
/* 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/13 21:25:23 by babonnet ### ########.fr */
|
/* Updated: 2024/04/15 17:02:17 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
void redirect_output(t_msh *msh, int i)
|
void redirect_output(t_msh *msh, int i)
|
||||||
{
|
{
|
||||||
@ -22,10 +23,19 @@ void redirect_output(t_msh *msh, int i)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_printf_fd(0, "redirecting pipe output\n");
|
ft_printf_fd(2, "redirecting pipe output\n");
|
||||||
ft_printf_fd(0, "output of cmd %d: 1 -> %d\n", i, msh->fds[i - 1][1]);
|
ft_printf_fd(2, "%p\n", msh->fds[i]);
|
||||||
|
//ft_printf_fd(2, "output of cmd %d: 1 -> %d\n", i, msh->fds[i - 1][1]);
|
||||||
|
ft_printf_fd(2, "yes\n");
|
||||||
|
//sleep(1);
|
||||||
if (dup2(msh->fds[i][1], 1) < 0)
|
if (dup2(msh->fds[i][1], 1) < 0)
|
||||||
ft_exit(msh, 1);
|
{
|
||||||
|
perror("dup2");
|
||||||
|
ft_printf_fd(2, "exiting\n");
|
||||||
|
//ft_exit(msh, 1);
|
||||||
|
}
|
||||||
|
ft_printf_fd(2,"help pls\n");
|
||||||
|
fflush(stdout); // Flush stdout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +70,12 @@ void get_out_type(t_msh *msh, t_cmd *cmds)
|
|||||||
msh->out_fd = 0;
|
msh->out_fd = 0;
|
||||||
cur_cmd = cmds;
|
cur_cmd = cmds;
|
||||||
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);
|
||||||
cur_cmd = cur_cmd->next;
|
cur_cmd = cur_cmd->next;
|
||||||
|
}
|
||||||
|
if (cur_cmd)
|
||||||
|
ft_printf_fd(2, "%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)
|
||||||
|
@ -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/13 15:39:50 by babonnet ### ########.fr */
|
/* Updated: 2024/04/14 11:34:47 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -56,6 +56,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");
|
||||||
close_pipe_fds(msh, i);
|
close_pipe_fds(msh, i);
|
||||||
execute_command(msh, cmd_args);
|
execute_command(msh, cmd_args);
|
||||||
close(0);
|
close(0);
|
||||||
|
@ -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/03 19:23:33 by tomoron ### ########.fr */
|
/* Updated: 2024/04/14 11:41:06 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ int set_echoctl(int value)
|
|||||||
{
|
{
|
||||||
struct termios t_p;
|
struct termios t_p;
|
||||||
|
|
||||||
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\
|
ft_printf_fd(2, "minishell: an error occured while getting the local fl\
|
||||||
|
@ -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/03 15:46:38 by tomoron ### ########.fr */
|
/* Updated: 2024/04/14 11:29:02 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,6 +26,7 @@ void free_msh(t_msh *msh)
|
|||||||
|
|
||||||
void ft_exit(t_msh *msh, int exit_code)
|
void ft_exit(t_msh *msh, int exit_code)
|
||||||
{
|
{
|
||||||
|
ft_printf("exiting");
|
||||||
free_msh(msh);
|
free_msh(msh);
|
||||||
exit(exit_code);
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user