Skip to content

Commit

Permalink
Merge pull request #34 from facetint/facetint
Browse files Browse the repository at this point in the history
Facetint
  • Loading branch information
facetint authored Mar 8, 2024
2 parents 10847ff + 6aecd50 commit 3c539cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
31 changes: 13 additions & 18 deletions execute/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: facetint <facetint@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/17 17:34:07 by facetint #+# #+# */
/* Updated: 2024/03/08 19:26:30 by facetint ### ########.fr */
/* Updated: 2024/03/08 20:17:30 by hcoskun42 ### ########.tr */
/* */
/* ************************************************************************** */

Expand All @@ -19,6 +19,8 @@
#include "../memory-allocator/allocator.h"
#include "../get_next_line/get_next_line.h"
#include "../includes/env.h"
#include <errno.h>


t_envList *get_global_env()
{
Expand All @@ -38,19 +40,6 @@ void print_and_close(int fd)
}
close(fd);
}
void read_and_close(t_command *before)
{
char *line;

while (1)
{
line = get_next_line(before->fd);
if (line == NULL)
break;
safe_free(line);
}
close(before->fd);
}
char **new_arr(char *new, char **arr)
{
int counter;
Expand Down Expand Up @@ -93,6 +82,7 @@ void execute_command(t_command *cmd, t_command *before, int fd[2])
void execute(t_command *cmds)
{
handle_command(NULL, cmds, cmds);
while (wait(NULL) > 0 || (wait(NULL) == -1 && errno != ECHILD));
}
void writeFd(int fd[2], char *str)
{
Expand All @@ -116,8 +106,10 @@ void handle_command(t_command *before, t_command *cmd, t_command *first_cmd)
handle_heredocs(cmd);
if (before)
{
char buff[512];
read(before->fd, buff, 512);
close(before->fd);
int newfd[2];
read_and_close(before);
pipe(newfd);
//writeFd(newfd, buff);
writeFd(newfd, cmd->redirections[0].redirected);
Expand All @@ -127,9 +119,12 @@ void handle_command(t_command *before, t_command *cmd, t_command *first_cmd)
}
else
{
write(STDOUT_FILENO, cmd->redirections[0].redirected, ft_strlen(cmd->redirections[0].redirected));
write (STDOUT_FILENO, "\n", 1);
exit(0);
int newfd[2];
pipe(newfd);
close(newfd[0]);
write(STDIN_FILENO, cmd->redirections[0].redirected, ft_strlen(cmd->redirections[0].redirected));
close(newfd[1]);
cmd->fd = newfd[0];
}
}
if (isbuiltin(cmd->name))
Expand Down
3 changes: 1 addition & 2 deletions handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@ void handle_input(char *input)
expand(&lexer_data);
unquote(lexer_data);
parser_data = parse(lexer_data);
// handle_heredocs(parser_data);
handle_heredocs(parser_data);

//debug(lexer_data, parser_data);
execute(parser_data);
while (wait(NULL) > 0 || (wait(NULL) == -1 && errno != ECHILD));
uninit_tokens(lexer_data);
}

Expand Down
3 changes: 2 additions & 1 deletion libft/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ BONUS_OBJECTS = $(BONUS_SOURCES:.c=.o)
all: $(OBJECTS)
@sleep 0.2
@echo "$(PURPLE_COLOR)$(CLEAN_CAR)Libft Compiled!$(BLUE_COLOR)"
@ar -rcs $(NAME) $(OBJECTS)

%.o : %.c
@printf "$(PURPLE_COLOR)$(CLEAN_CAR)[libft Compiling] $(BLUE_COLOR):$(BLUE_COLOR) $<$(BLUE_COLOR)"
Expand All @@ -34,4 +35,4 @@ CLEAN_CAR = \033[2K\r

OK_STRING = $(PURPLE_COLOR)[OK]$(BLUE_COLOR)
ERROR_STRING = $(ERROR_COLOR)[ERRORS]$(BLUE_COLOR)
WARN_STRING = $(BLUE_COLOR)[WARNINGS]$(BLUE_COLOR)
WARN_STRING = $(BLUE_COLOR)[WARNINGS]$(BLUE_COLOR)

0 comments on commit 3c539cb

Please sign in to comment.