-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
38 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/09 14:14:40 by zhabri #+# #+# */ | ||
/* Updated: 2022/12/26 16:51:36 by zhabri ### ########.fr */ | ||
/* Updated: 2022/12/27 14:46:35 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -73,7 +73,10 @@ void find_cmd_infile(t_token *token, t_cmd *node, bool *pb) | |
token->file = remove_quotes(file); | ||
else | ||
free(file); | ||
*pb = ft_open_in(node, token); | ||
if (!g_glob->sig_int) | ||
*pb = ft_open_in(node, token); | ||
else | ||
*pb = false; | ||
} | ||
|
||
void find_cmd_outfile(t_token *token, t_cmd *node, bool *pb) | ||
|
@@ -97,7 +100,10 @@ void find_cmd_outfile(t_token *token, t_cmd *node, bool *pb) | |
" \t"); | ||
free(cmd); | ||
token->file = remove_quotes(file); | ||
*pb = ft_open_out(node, token); | ||
if (!g_glob->sig_int) | ||
*pb = ft_open_out(node, token); | ||
else | ||
*pb = false; | ||
} | ||
|
||
void get_cmd(void) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,13 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/20 12:33:11 by zhabri #+# #+# */ | ||
/* Updated: 2022/12/27 12:17:13 by zhabri ### ########.fr */ | ||
/* Updated: 2022/12/27 13:59:47 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft/includes/libft.h" | ||
#include "minishell.h" | ||
#include <unistd.h> | ||
|
||
static char *name_generator(void) | ||
{ | ||
|
@@ -63,11 +64,13 @@ static char *get_limiter(t_token *token) | |
static void handle_here_doc(t_token *token) | ||
{ | ||
int fd; | ||
int stdin_cpy; | ||
char *here_doc_entry; | ||
char *file_name; | ||
char *limiter; | ||
|
||
file_name = name_generator(); | ||
stdin_cpy = dup(0); | ||
fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC, 0644); | ||
if (fd == -1) | ||
{ | ||
|
@@ -76,24 +79,22 @@ static void handle_here_doc(t_token *token) | |
} | ||
here_doc_entry = NULL; | ||
limiter = get_limiter(token); | ||
while (1) | ||
g_glob->here_doc = true; | ||
while (!g_glob->sig_int) | ||
{ | ||
here_doc_entry = readline("> "); | ||
printf("%s\n", here_doc_entry); | ||
if (!here_doc_entry || g_glob->sig_int \ | ||
|| !strncmp(limiter, here_doc_entry, ft_strlen(limiter) + 1)) | ||
{ | ||
if (g_glob->sig_int) | ||
g_glob->input = here_doc_entry; | ||
break ; | ||
} | ||
ft_putendl_fd(here_doc_entry, fd); | ||
free(here_doc_entry); | ||
} | ||
eof_limiter_not_found(here_doc_entry, limiter); | ||
g_glob->here_doc = false; | ||
if (!g_glob->sig_int) | ||
eof_limiter_not_found(here_doc_entry, limiter); | ||
close(fd); | ||
dup2(stdin_cpy, 0); | ||
token->file = file_name; | ||
g_glob->sig_int = false; | ||
} | ||
|
||
void scan_heredocs(void) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/01 11:49:37 by zhabri #+# #+# */ | ||
/* Updated: 2022/12/27 12:13:57 by zhabri ### ########.fr */ | ||
/* Updated: 2022/12/27 14:43:50 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -40,7 +40,8 @@ void events(t_list **head) | |
{ | ||
scan_heredocs(); | ||
get_cmd(); | ||
pipex(); | ||
if (!g_glob->sig_int) | ||
pipex(); | ||
unlink_heredocs(); | ||
clear_cmds(); | ||
if (g_glob->cmds) | ||
|
@@ -60,6 +61,7 @@ void event_loop(void) | |
{ | ||
g_glob->in_child = false; | ||
g_glob->sig_int = false; | ||
g_glob->here_doc = false; | ||
input = readline("minishell> "); | ||
if (input == NULL) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/11/27 20:30:45 by zhabri #+# #+# */ | ||
/* Updated: 2022/12/27 12:13:00 by zhabri ### ########.fr */ | ||
/* Updated: 2022/12/27 13:06:46 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -67,6 +67,7 @@ typedef struct s_glob | |
unsigned char exit_ret; | ||
bool in_child; | ||
bool sig_int; | ||
bool here_doc; | ||
} t_glob; | ||
|
||
extern t_glob *g_glob; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/23 10:32:29 by zhabri #+# #+# */ | ||
/* Updated: 2022/12/27 12:13:30 by zhabri ### ########.fr */ | ||
/* Updated: 2022/12/27 13:57:43 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -20,10 +20,18 @@ static void handler(int sig) | |
if (sig == SIGINT && !g_glob->in_child) | ||
{ | ||
g_glob->sig_int = true; | ||
ft_putchar_fd('\n', 1); | ||
rl_on_new_line(); | ||
rl_replace_line("", 0); | ||
rl_redisplay(); | ||
if (g_glob->here_doc) | ||
{ | ||
close(STDIN_FILENO); | ||
printf("\n"); | ||
} | ||
else | ||
{ | ||
ft_putchar_fd('\n', 1); | ||
rl_on_new_line(); | ||
rl_replace_line("", 0); | ||
rl_redisplay(); | ||
} | ||
g_glob->exit_ret = 130; | ||
} | ||
else if (sig == SIGINT && g_glob->in_child) | ||
|